Skip to content

Commit 3b0c57b

Browse files
committed
feature: supports to re-order workspaces (#1261)
Signed-off-by: leo <[email protected]>
1 parent 61bc426 commit 3b0c57b

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

src/ViewModels/ConfigureWorkspace.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public class ConfigureWorkspace : ObservableObject
99
public AvaloniaList<Workspace> Workspaces
1010
{
1111
get;
12-
private set;
1312
}
1413

1514
public Workspace Selected
@@ -51,6 +50,36 @@ public void Delete()
5150
Workspaces.Remove(_selected);
5251
}
5352

53+
public void MoveSelectedUp()
54+
{
55+
if (_selected == null)
56+
return;
57+
58+
var idx = Workspaces.IndexOf(_selected);
59+
if (idx == 0)
60+
return;
61+
62+
Workspaces.Move(idx - 1, idx);
63+
64+
Preferences.Instance.Workspaces.RemoveAt(idx);
65+
Preferences.Instance.Workspaces.Insert(idx - 1, _selected);
66+
}
67+
68+
public void MoveSelectedDown()
69+
{
70+
if (_selected == null)
71+
return;
72+
73+
var idx = Workspaces.IndexOf(_selected);
74+
if (idx == Workspaces.Count - 1)
75+
return;
76+
77+
Workspaces.Move(idx + 1, idx);
78+
79+
Preferences.Instance.Workspaces.RemoveAt(idx);
80+
Preferences.Instance.Workspaces.Insert(idx + 1, _selected);
81+
}
82+
5483
private Workspace _selected = null;
5584
private bool _canDeleteSelected = false;
5685
}

src/Views/ConfigureWorkspace.axaml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,39 @@
7979

8080
<Rectangle Grid.Row="1" Height="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
8181

82-
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="{DynamicResource Brush.ToolBar}">
83-
<Button Classes="icon_button" Command="{Binding Add}">
82+
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
83+
<Button Grid.Column="0"
84+
Classes="icon_button"
85+
Width="28" Height="28"
86+
Command="{Binding Add}">
8487
<Path Width="14" Height="14" Data="{StaticResource Icons.Plus}"/>
8588
</Button>
86-
87-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
88-
89-
<Button Classes="icon_button" Command="{Binding Delete}" IsEnabled="{Binding CanDeleteSelected}">
89+
<Button Grid.Column="1"
90+
Classes="icon_button"
91+
Width="28" Height="28"
92+
Command="{Binding Delete}"
93+
IsEnabled="{Binding CanDeleteSelected}">
9094
<Path Width="14" Height="14" Data="{StaticResource Icons.Window.Minimize}"/>
9195
</Button>
92-
93-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
94-
</StackPanel>
96+
<Button Grid.Column="3"
97+
Classes="icon_button"
98+
Width="28" Height="28"
99+
Command="{Binding MoveSelectedUp}"
100+
IsVisible="{Binding Selected, Converter={x:Static ObjectConverters.IsNotNull}}">
101+
<Path Width="14" Height="14"
102+
Margin="0,6,0,0"
103+
Data="{StaticResource Icons.Up}"/>
104+
</Button>
105+
<Button Grid.Column="4"
106+
Classes="icon_button"
107+
Width="28" Height="28"
108+
Command="{Binding MoveSelectedDown}"
109+
IsVisible="{Binding Selected, Converter={x:Static ObjectConverters.IsNotNull}}">
110+
<Path Width="14" Height="14"
111+
Margin="0,6,0,0"
112+
Data="{StaticResource Icons.Down}"/>
113+
</Button>
114+
</Grid>
95115
</Grid>
96116
</Border>
97117

0 commit comments

Comments
 (0)