feature: supports to re-order workspaces (#1261)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-30 21:38:46 +08:00
parent 61bc42612e
commit 3b0c57be84
No known key found for this signature in database
2 changed files with 59 additions and 10 deletions

View file

@ -9,7 +9,6 @@ namespace SourceGit.ViewModels
public AvaloniaList<Workspace> Workspaces
{
get;
private set;
}
public Workspace Selected
@ -51,6 +50,36 @@ namespace SourceGit.ViewModels
Workspaces.Remove(_selected);
}
public void MoveSelectedUp()
{
if (_selected == null)
return;
var idx = Workspaces.IndexOf(_selected);
if (idx == 0)
return;
Workspaces.Move(idx - 1, idx);
Preferences.Instance.Workspaces.RemoveAt(idx);
Preferences.Instance.Workspaces.Insert(idx - 1, _selected);
}
public void MoveSelectedDown()
{
if (_selected == null)
return;
var idx = Workspaces.IndexOf(_selected);
if (idx == Workspaces.Count - 1)
return;
Workspaces.Move(idx + 1, idx);
Preferences.Instance.Workspaces.RemoveAt(idx);
Preferences.Instance.Workspaces.Insert(idx + 1, _selected);
}
private Workspace _selected = null;
private bool _canDeleteSelected = false;
}

View file

@ -79,19 +79,39 @@
<Rectangle Grid.Row="1" Height="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="{DynamicResource Brush.ToolBar}">
<Button Classes="icon_button" Command="{Binding Add}">
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
<Button Grid.Column="0"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding Add}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Plus}"/>
</Button>
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
<Button Classes="icon_button" Command="{Binding Delete}" IsEnabled="{Binding CanDeleteSelected}">
<Button Grid.Column="1"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding Delete}"
IsEnabled="{Binding CanDeleteSelected}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Window.Minimize}"/>
</Button>
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
</StackPanel>
<Button Grid.Column="3"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding MoveSelectedUp}"
IsVisible="{Binding Selected, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14"
Margin="0,6,0,0"
Data="{StaticResource Icons.Up}"/>
</Button>
<Button Grid.Column="4"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding MoveSelectedDown}"
IsVisible="{Binding Selected, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14"
Margin="0,6,0,0"
Data="{StaticResource Icons.Down}"/>
</Button>
</Grid>
</Grid>
</Border>