mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
Working on the external command configuration, this is WIP
This commit is contained in:
parent
fe4859817a
commit
aa80ccd5e2
7 changed files with 145 additions and 19 deletions
|
@ -44,5 +44,10 @@ namespace Greenshot.Addon.ExternalCommand.Entities
|
|||
/// The behavior or mode of the command
|
||||
/// </summary>
|
||||
public CommandBehaviors CommandBehavior { get; set; } = CommandBehaviors.Default;
|
||||
|
||||
/// <summary>
|
||||
/// Validates if this command definition is valid
|
||||
/// </summary>
|
||||
public bool IsValid => !string.IsNullOrEmpty(Command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#endregion
|
||||
|
||||
using System.Reactive.Disposables;
|
||||
using Caliburn.Micro;
|
||||
using Dapplo.CaliburnMicro.Configuration;
|
||||
using Dapplo.CaliburnMicro.Extensions;
|
||||
using Greenshot.Addons;
|
||||
|
@ -30,6 +31,9 @@ using Greenshot.Addons.ViewModels;
|
|||
|
||||
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration for the external commands
|
||||
/// </summary>
|
||||
public sealed class ExternalCommandConfigViewModel : SimpleConfigScreen
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -82,10 +86,22 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels
|
|||
base.Initialize(config);
|
||||
}
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
base.OnActivate();
|
||||
ExternalCommandMasterViewModel.ActivateWith(this);
|
||||
}
|
||||
|
||||
protected override void OnDeactivate(bool close)
|
||||
{
|
||||
_disposables.Dispose();
|
||||
base.OnDeactivate(close);
|
||||
}
|
||||
|
||||
public override void Commit()
|
||||
{
|
||||
ExternalCommandMasterViewModel.Store();
|
||||
base.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,15 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels
|
|||
/// </summary>
|
||||
public ExternalCommandDefinition Definition { get; }
|
||||
|
||||
public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition)
|
||||
/// <summary>
|
||||
/// The translations
|
||||
/// </summary>
|
||||
public IExternalCommandLanguage ExternalCommandLanguage { get; }
|
||||
|
||||
public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition, IExternalCommandLanguage externalCommandLanguage)
|
||||
{
|
||||
Definition = definition;
|
||||
ExternalCommandLanguage = externalCommandLanguage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,21 +23,78 @@
|
|||
|
||||
using System.Linq;
|
||||
using Caliburn.Micro;
|
||||
using Greenshot.Addon.ExternalCommand.Entities;
|
||||
|
||||
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the master view of the external command config editor
|
||||
/// </summary>
|
||||
public class ExternalCommandMasterViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
public class ExternalCommandMasterViewModel : Conductor<ExternalCommandDetailsViewModel>.Collection.OneActive
|
||||
{
|
||||
public ExternalCommandMasterViewModel(IExternalCommandConfiguration externalCommandConfiguration)
|
||||
/// <summary>
|
||||
/// Used in the view
|
||||
/// </summary>
|
||||
public IExternalCommandConfiguration ExternalCommandConfiguration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Used in the view
|
||||
/// </summary>
|
||||
public IExternalCommandLanguage ExternalCommandLanguage { get; }
|
||||
|
||||
public ExternalCommandMasterViewModel(
|
||||
IExternalCommandConfiguration externalCommandConfiguration,
|
||||
IExternalCommandLanguage externalCommandLanguage)
|
||||
{
|
||||
var items = externalCommandConfiguration.Commands
|
||||
.Select(externalCommandConfiguration.Read)
|
||||
.Select(definition => new ExternalCommandDetailsViewModel(definition));
|
||||
ExternalCommandConfiguration = externalCommandConfiguration;
|
||||
ExternalCommandLanguage = externalCommandLanguage;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnActivate()
|
||||
{
|
||||
Items.Clear();
|
||||
var items = ExternalCommandConfiguration.Commands
|
||||
.Select(ExternalCommandConfiguration.Read)
|
||||
.OrderBy(definition => definition.Name)
|
||||
.Select(definition => new ExternalCommandDetailsViewModel(definition, ExternalCommandLanguage));
|
||||
|
||||
Items.AddRange(items);
|
||||
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnDeactivate(bool close)
|
||||
{
|
||||
Items.Clear();
|
||||
base.OnDeactivate(close);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This adds an item
|
||||
/// </summary>
|
||||
public void Add()
|
||||
{
|
||||
Items.Add(new ExternalCommandDetailsViewModel(new ExternalCommandDefinition
|
||||
{
|
||||
Name = "New command " + Items.Count
|
||||
}, ExternalCommandLanguage));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This stores all items
|
||||
/// </summary>
|
||||
public void Store()
|
||||
{
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item.Definition?.IsValid != true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ExternalCommandConfiguration.Write(item.Definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,14 @@
|
|||
>
|
||||
<StackPanel>
|
||||
<GroupBox Header="{Binding ExternalCommandLanguage.SettingsTitle}">
|
||||
<StackPanel>
|
||||
<ContentControl x:Name="FileConfigPartViewModel"/>
|
||||
<ContentControl x:Name="ExternalCommandMasterViewModel"/>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<ContentControl x:Name="FileConfigPartViewModel" Grid.Row="0"/>
|
||||
<ContentControl x:Name="ExternalCommandMasterViewModel" Grid.Row="1" VerticalContentAlignment="Stretch"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
|
|
@ -8,7 +8,28 @@
|
|||
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
|
||||
d:DataContext="{d:DesignInstance viewModels:ExternalCommandDetailsViewModel,IsDesignTimeCreatable=False}"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<Label></Label>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="30" />
|
||||
<RowDefinition Height="30" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Content="{Binding ExternalCommandLanguage.LabelName}" Grid.Column="0" Grid.Row="0"/>
|
||||
<TextBox Text="{Binding Definition.Name}" Grid.Column="1" Grid.Row="0"/>
|
||||
|
||||
<Label Content="{Binding ExternalCommandLanguage.LabelCommand}" Grid.Column="0" Grid.Row="1"/>
|
||||
<TextBox Text="{Binding Definition.Command}" Grid.Column="1" Grid.Row="1"/>
|
||||
|
||||
<Label Content="{Binding ExternalCommandLanguage.LabelArgument}" Grid.Column="0" Grid.Row="2"/>
|
||||
<TextBox Text="{Binding Definition.Arguments}" Grid.Column="1" Grid.Row="2"/>
|
||||
|
||||
<Label Content="{Binding ExternalCommandLanguage.LabelInformation}" Grid.Column="0" Grid.Row="3"/>
|
||||
<TextBox Text="{Binding Definition.CommandBehavior}" Grid.Column="1" Grid.Row="3"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
@ -2,13 +2,30 @@
|
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Greenshot.Addon.ExternalCommand.Views"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:cal="http://www.caliburnproject.org"
|
||||
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance viewModels:ExternalCommandMasterViewModel,IsDesignTimeCreatable=False}"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<StackPanel>
|
||||
<ListBox x:Name="Items" cal:Message.Attach="[Event SelectionChanged]=[Action ActivateChildView($this.SelectedItem)]"/>
|
||||
<ContentControl Name="ActiveItem"/>
|
||||
</StackPanel>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="100" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="20" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<ListView Grid.Row="0" ItemsSource="{Binding Items}" SelectedValue="{Binding ActiveItem}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Label Content="{Binding Definition.Name}" />
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
<ContentControl Name="ActiveItem" Grid.Row="1"/>
|
||||
<Button x:Name="Add" Content="{Binding ExternalCommandLanguage.SettingsNew}" Grid.Row="2"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue