Skip to content

Commit 98041c8

Browse files
committed
feature: supports re-order custom actions (#1346)
Signed-off-by: leo <[email protected]>
1 parent ee2e7d0 commit 98041c8

File tree

5 files changed

+98
-18
lines changed

5 files changed

+98
-18
lines changed

src/Models/RepositorySettings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,19 @@ public void RemoveCustomAction(CustomAction act)
453453
if (act != null)
454454
CustomActions.Remove(act);
455455
}
456+
457+
public void MoveCustomActionUp(CustomAction act)
458+
{
459+
var idx = CustomActions.IndexOf(act);
460+
if (idx > 0)
461+
CustomActions.Move(idx - 1, idx);
462+
}
463+
464+
public void MoveCustomActionDown(CustomAction act)
465+
{
466+
var idx = CustomActions.IndexOf(act);
467+
if (idx < CustomActions.Count - 1)
468+
CustomActions.Move(idx + 1, idx);
469+
}
456470
}
457471
}

src/ViewModels/RepositoryConfigure.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,18 @@ public void RemoveSelectedCustomAction()
304304
SelectedCustomAction = null;
305305
}
306306

307+
public void MoveSelectedCustomActionUp()
308+
{
309+
if (_selectedCustomAction != null)
310+
_repo.Settings.MoveCustomActionUp(_selectedCustomAction);
311+
}
312+
313+
public void MoveSelectedCustomActionDown()
314+
{
315+
if (_selectedCustomAction != null)
316+
_repo.Settings.MoveCustomActionDown(_selectedCustomAction);
317+
}
318+
307319
public void Save()
308320
{
309321
SetIfChanged("user.name", UserName, "");

src/Views/Preferences.axaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,19 +583,34 @@
583583

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

586-
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="{DynamicResource Brush.ToolBar}">
587-
<Button Classes="icon_button" Click="OnAddCustomAction">
586+
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
587+
<Button Grid.Column="0"
588+
Classes="icon_button"
589+
Width="28" Height="28"
590+
Click="OnAddCustomAction">
588591
<Path Width="14" Height="14" Data="{StaticResource Icons.Plus}"/>
589592
</Button>
590-
591-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
592-
593-
<Button Classes="icon_button" Click="OnRemoveSelectedCustomAction">
593+
<Button Grid.Column="1"
594+
Classes="icon_button"
595+
Width="28" Height="28"
596+
Click="OnRemoveSelectedCustomAction">
594597
<Path Width="14" Height="14" Data="{StaticResource Icons.Window.Minimize}"/>
595598
</Button>
596-
597-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
598-
</StackPanel>
599+
<Button Grid.Column="3"
600+
Classes="icon_button"
601+
Width="28" Height="28"
602+
Click="OnMoveSelectedCustomActionUp"
603+
IsVisible="{Binding #ThisControl.SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
604+
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
605+
</Button>
606+
<Button Grid.Column="4"
607+
Classes="icon_button"
608+
Width="28" Height="28"
609+
Click="OnMoveSelectedCustomActionDown"
610+
IsVisible="{Binding #ThisControl.SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
611+
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Down}"/>
612+
</Button>
613+
</Grid>
599614
</Grid>
600615
</Border>
601616

src/Views/Preferences.axaml.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,30 @@ private void OnRemoveSelectedCustomAction(object sender, RoutedEventArgs e)
415415
e.Handled = true;
416416
}
417417

418+
private void OnMoveSelectedCustomActionUp(object sender, RoutedEventArgs e)
419+
{
420+
if (SelectedCustomAction == null)
421+
return;
422+
423+
var idx = ViewModels.Preferences.Instance.CustomActions.IndexOf(SelectedCustomAction);
424+
if (idx > 0)
425+
ViewModels.Preferences.Instance.CustomActions.Move(idx - 1, idx);
426+
427+
e.Handled = true;
428+
}
429+
430+
private void OnMoveSelectedCustomActionDown(object sender, RoutedEventArgs e)
431+
{
432+
if (SelectedCustomAction == null)
433+
return;
434+
435+
var idx = ViewModels.Preferences.Instance.CustomActions.IndexOf(SelectedCustomAction);
436+
if (idx < ViewModels.Preferences.Instance.CustomActions.Count - 1)
437+
ViewModels.Preferences.Instance.CustomActions.Move(idx + 1, idx);
438+
439+
e.Handled = true;
440+
}
441+
418442
private void UpdateGitVersion()
419443
{
420444
GitVersion = Native.OS.GitVersionString;

src/Views/RepositoryConfigure.axaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,34 @@
417417

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

420-
<StackPanel Grid.Row="2" Orientation="Horizontal" Background="{DynamicResource Brush.ToolBar}">
421-
<Button Classes="icon_button" Command="{Binding AddNewCustomAction}">
420+
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
421+
<Button Grid.Column="0"
422+
Classes="icon_button"
423+
Width="28" Height="28"
424+
Command="{Binding AddNewCustomAction}">
422425
<Path Width="14" Height="14" Data="{StaticResource Icons.Plus}"/>
423426
</Button>
424-
425-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
426-
427-
<Button Classes="icon_button" Command="{Binding RemoveSelectedCustomAction}">
427+
<Button Grid.Column="1"
428+
Classes="icon_button"
429+
Width="28" Height="28"
430+
Command="{Binding RemoveSelectedCustomAction}">
428431
<Path Width="14" Height="14" Data="{StaticResource Icons.Window.Minimize}"/>
429432
</Button>
430-
431-
<Rectangle Width="1" Fill="{DynamicResource Brush.Border2}" HorizontalAlignment="Left" VerticalAlignment="Stretch"/>
432-
</StackPanel>
433+
<Button Grid.Column="3"
434+
Classes="icon_button"
435+
Width="28" Height="28"
436+
Command="{Binding MoveSelectedCustomActionUp}"
437+
IsVisible="{Binding SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
438+
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
439+
</Button>
440+
<Button Grid.Column="4"
441+
Classes="icon_button"
442+
Width="28" Height="28"
443+
Command="{Binding MoveSelectedCustomActionDown}"
444+
IsVisible="{Binding SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
445+
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Down}"/>
446+
</Button>
447+
</Grid>
433448
</Grid>
434449
</Border>
435450

0 commit comments

Comments
 (0)