diff --git a/src/Greenshot.Addon.ExternalCommand/Entities/ExternalCommandDefinition.cs b/src/Greenshot.Addon.ExternalCommand/Entities/ExternalCommandDefinition.cs
index fdeadf5c3..d3bc80617 100644
--- a/src/Greenshot.Addon.ExternalCommand/Entities/ExternalCommandDefinition.cs
+++ b/src/Greenshot.Addon.ExternalCommand/Entities/ExternalCommandDefinition.cs
@@ -44,5 +44,10 @@ namespace Greenshot.Addon.ExternalCommand.Entities
/// The behavior or mode of the command
///
public CommandBehaviors CommandBehavior { get; set; } = CommandBehaviors.Default;
+
+ ///
+ /// Validates if this command definition is valid
+ ///
+ public bool IsValid => !string.IsNullOrEmpty(Command);
}
}
diff --git a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs
index 2e166d4d2..c72ed30ee 100644
--- a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs
+++ b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandConfigViewModel.cs
@@ -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
{
+ ///
+ /// Configuration for the external commands
+ ///
public sealed class ExternalCommandConfigViewModel : SimpleConfigScreen
{
///
@@ -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();
+ }
}
}
diff --git a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandDetailsViewModel.cs b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandDetailsViewModel.cs
index e241aed33..a4b48561d 100644
--- a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandDetailsViewModel.cs
+++ b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandDetailsViewModel.cs
@@ -36,9 +36,15 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels
///
public ExternalCommandDefinition Definition { get; }
- public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition)
+ ///
+ /// The translations
+ ///
+ public IExternalCommandLanguage ExternalCommandLanguage { get; }
+
+ public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition, IExternalCommandLanguage externalCommandLanguage)
{
Definition = definition;
+ ExternalCommandLanguage = externalCommandLanguage;
}
}
}
diff --git a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandMasterViewModel.cs b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandMasterViewModel.cs
index d663f987f..a59fbccf9 100644
--- a/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandMasterViewModel.cs
+++ b/src/Greenshot.Addon.ExternalCommand/ViewModels/ExternalCommandMasterViewModel.cs
@@ -23,21 +23,78 @@
using System.Linq;
using Caliburn.Micro;
+using Greenshot.Addon.ExternalCommand.Entities;
namespace Greenshot.Addon.ExternalCommand.ViewModels
{
///
/// This is the master view of the external command config editor
///
- public class ExternalCommandMasterViewModel : Conductor.Collection.OneActive
+ public class ExternalCommandMasterViewModel : Conductor.Collection.OneActive
{
- public ExternalCommandMasterViewModel(IExternalCommandConfiguration externalCommandConfiguration)
+ ///
+ /// Used in the view
+ ///
+ public IExternalCommandConfiguration ExternalCommandConfiguration { get; }
+
+ ///
+ /// Used in the view
+ ///
+ 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;
+ }
+
+ ///
+ 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();
+ }
+
+ ///
+ protected override void OnDeactivate(bool close)
+ {
+ Items.Clear();
+ base.OnDeactivate(close);
+ }
+
+ ///
+ /// This adds an item
+ ///
+ public void Add()
+ {
+ Items.Add(new ExternalCommandDetailsViewModel(new ExternalCommandDefinition
+ {
+ Name = "New command " + Items.Count
+ }, ExternalCommandLanguage));
+ }
+
+ ///
+ /// This stores all items
+ ///
+ public void Store()
+ {
+ foreach (var item in Items)
+ {
+ if (item.Definition?.IsValid != true)
+ {
+ continue;
+ }
+ ExternalCommandConfiguration.Write(item.Definition);
+ }
}
}
}
diff --git a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandConfigView.xaml b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandConfigView.xaml
index 53271fb4f..e3f9b98de 100644
--- a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandConfigView.xaml
+++ b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandConfigView.xaml
@@ -9,10 +9,14 @@
>
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandDetailsView.xaml b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandDetailsView.xaml
index 63befc852..49406c182 100644
--- a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandDetailsView.xaml
+++ b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandDetailsView.xaml
@@ -8,7 +8,28 @@
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
d:DataContext="{d:DesignInstance viewModels:ExternalCommandDetailsViewModel,IsDesignTimeCreatable=False}"
mc:Ignorable="d">
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandMasterView.xaml b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandMasterView.xaml
index 274b95a4d..421ae0daa 100644
--- a/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandMasterView.xaml
+++ b/src/Greenshot.Addon.ExternalCommand/Views/ExternalCommandMasterView.xaml
@@ -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">
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+