Skip to content

add DuplicateCustomAction( #1632) #1634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Models/CustomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ public enum CustomActionControlType

public class CustomActionControl : ObservableObject
{
public CustomActionControl()
{
}

public CustomActionControl(CustomActionControl cac)
{
if (cac != null)
{
Type = cac.Type;
Description = cac.Description;
Label = cac.Label;
Description = cac.Description;
StringValue = cac.StringValue;
BoolValue = cac.BoolValue;
}
}

public CustomActionControlType Type
{
get => _type;
Expand Down Expand Up @@ -60,6 +77,24 @@ public bool BoolValue

public class CustomAction : ObservableObject
{
public CustomAction()
{
}

public CustomAction(CustomAction action)
{
if (action != null)
{
Name = action.Name;
Scope = action.Scope;
Executable = action.Executable;
Arguments = action.Arguments;
WaitForExit = action.WaitForExit;
foreach (var control in action.Controls)
Controls.Add(new CustomActionControl(control));
}
}

public string Name
{
get => _name;
Expand Down
10 changes: 10 additions & 0 deletions src/Models/RepositorySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ public CustomAction AddNewCustomAction()
return act;
}

public CustomAction DuplicateCustomAction(CustomAction baseAct)
{
var act = new CustomAction(baseAct)
{
Name = baseAct.Name + "(Duplicated)"
};
CustomActions.Add(act);
return act;
}

public void RemoveCustomAction(CustomAction act)
{
if (act != null)
Expand Down
5 changes: 5 additions & 0 deletions src/ViewModels/RepositoryConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public void RemoveSelectedCustomAction()
SelectedCustomAction = null;
}

public void DuplicateSelectedCustomAction()
{
SelectedCustomAction = _repo.Settings.DuplicateCustomAction(_selectedCustomAction);
}

public void MoveSelectedCustomActionUp()
{
if (_selectedCustomAction != null)
Expand Down
16 changes: 12 additions & 4 deletions src/Views/Preferences.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@

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

<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
<Button Grid.Column="0"
Classes="icon_button"
Width="28" Height="28"
Expand All @@ -605,17 +605,25 @@
<Button Grid.Column="1"
Classes="icon_button"
Width="28" Height="28"
Click="OnRemoveSelectedCustomAction">
Click="OnRemoveSelectedCustomAction"
IsEnabled="{Binding #ThisControl.SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Minus}"/>
</Button>
<Button Grid.Column="3"
<Button Grid.Column="2"
Classes="icon_button"
Width="28" Height="28"
Click="OnDuplicateSelectedCustomAction"
IsEnabled="{Binding #ThisControl.SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Copy}"/>
</Button>
<Button Grid.Column="4"
Classes="icon_button"
Width="28" Height="28"
Click="OnMoveSelectedCustomActionUp"
IsVisible="{Binding #ThisControl.SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
</Button>
<Button Grid.Column="4"
<Button Grid.Column="5"
Classes="icon_button"
Width="28" Height="28"
Click="OnMoveSelectedCustomActionDown"
Expand Down
16 changes: 16 additions & 0 deletions src/Views/Preferences.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,22 @@ private void OnRemoveSelectedCustomAction(object sender, RoutedEventArgs e)
e.Handled = true;
}

private void OnDuplicateSelectedCustomAction(object sender, RoutedEventArgs e)
{
if (SelectedCustomAction == null)
return;

var action = new Models.CustomAction(SelectedCustomAction)
{
Name = SelectedCustomAction.Name + "(Duplicated)"
};

ViewModels.Preferences.Instance.CustomActions.Add(action);
SelectedCustomAction = action;

e.Handled = true;
}

private void OnMoveSelectedCustomActionUp(object sender, RoutedEventArgs e)
{
if (SelectedCustomAction == null)
Expand Down
16 changes: 12 additions & 4 deletions src/Views/RepositoryConfigure.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@

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

<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
<Grid Grid.Row="2" ColumnDefinitions="Auto,Auto,Auto,*,Auto,Auto" Background="{DynamicResource Brush.ToolBar}">
<Button Grid.Column="0"
Classes="icon_button"
Width="28" Height="28"
Expand All @@ -434,17 +434,25 @@
<Button Grid.Column="1"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding RemoveSelectedCustomAction}">
Command="{Binding RemoveSelectedCustomAction}"
IsEnabled="{Binding SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Minus}"/>
</Button>
<Button Grid.Column="3"
<Button Grid.Column="2"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding DuplicateSelectedCustomAction}"
IsEnabled="{Binding SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Data="{StaticResource Icons.Copy}"/>
</Button>
<Button Grid.Column="4"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding MoveSelectedCustomActionUp}"
IsVisible="{Binding SelectedCustomAction, Converter={x:Static ObjectConverters.IsNotNull}}">
<Path Width="14" Height="14" Margin="0,6,0,0" Data="{StaticResource Icons.Up}"/>
</Button>
<Button Grid.Column="4"
<Button Grid.Column="5"
Classes="icon_button"
Width="28" Height="28"
Command="{Binding MoveSelectedCustomActionDown}"
Expand Down
Loading