mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 22:13: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
|
/// The behavior or mode of the command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CommandBehaviors CommandBehavior { get; set; } = CommandBehaviors.Default;
|
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
|
#endregion
|
||||||
|
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
|
using Caliburn.Micro;
|
||||||
using Dapplo.CaliburnMicro.Configuration;
|
using Dapplo.CaliburnMicro.Configuration;
|
||||||
using Dapplo.CaliburnMicro.Extensions;
|
using Dapplo.CaliburnMicro.Extensions;
|
||||||
using Greenshot.Addons;
|
using Greenshot.Addons;
|
||||||
|
@ -30,6 +31,9 @@ using Greenshot.Addons.ViewModels;
|
||||||
|
|
||||||
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration for the external commands
|
||||||
|
/// </summary>
|
||||||
public sealed class ExternalCommandConfigViewModel : SimpleConfigScreen
|
public sealed class ExternalCommandConfigViewModel : SimpleConfigScreen
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -82,10 +86,22 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||||
base.Initialize(config);
|
base.Initialize(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnActivate()
|
||||||
|
{
|
||||||
|
base.OnActivate();
|
||||||
|
ExternalCommandMasterViewModel.ActivateWith(this);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDeactivate(bool close)
|
protected override void OnDeactivate(bool close)
|
||||||
{
|
{
|
||||||
_disposables.Dispose();
|
_disposables.Dispose();
|
||||||
base.OnDeactivate(close);
|
base.OnDeactivate(close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Commit()
|
||||||
|
{
|
||||||
|
ExternalCommandMasterViewModel.Store();
|
||||||
|
base.Commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,15 @@ namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ExternalCommandDefinition Definition { get; }
|
public ExternalCommandDefinition Definition { get; }
|
||||||
|
|
||||||
public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition)
|
/// <summary>
|
||||||
|
/// The translations
|
||||||
|
/// </summary>
|
||||||
|
public IExternalCommandLanguage ExternalCommandLanguage { get; }
|
||||||
|
|
||||||
|
public ExternalCommandDetailsViewModel(ExternalCommandDefinition definition, IExternalCommandLanguage externalCommandLanguage)
|
||||||
{
|
{
|
||||||
Definition = definition;
|
Definition = definition;
|
||||||
|
ExternalCommandLanguage = externalCommandLanguage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,78 @@
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
using Greenshot.Addon.ExternalCommand.Entities;
|
||||||
|
|
||||||
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
namespace Greenshot.Addon.ExternalCommand.ViewModels
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the master view of the external command config editor
|
/// This is the master view of the external command config editor
|
||||||
/// </summary>
|
/// </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
|
ExternalCommandConfiguration = externalCommandConfiguration;
|
||||||
.Select(externalCommandConfiguration.Read)
|
ExternalCommandLanguage = externalCommandLanguage;
|
||||||
.Select(definition => new ExternalCommandDetailsViewModel(definition));
|
}
|
||||||
|
|
||||||
|
/// <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);
|
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>
|
<StackPanel>
|
||||||
<GroupBox Header="{Binding ExternalCommandLanguage.SettingsTitle}">
|
<GroupBox Header="{Binding ExternalCommandLanguage.SettingsTitle}">
|
||||||
<StackPanel>
|
<Grid>
|
||||||
<ContentControl x:Name="FileConfigPartViewModel"/>
|
<Grid.RowDefinitions>
|
||||||
<ContentControl x:Name="ExternalCommandMasterViewModel"/>
|
<RowDefinition Height="*" />
|
||||||
</StackPanel>
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<ContentControl x:Name="FileConfigPartViewModel" Grid.Row="0"/>
|
||||||
|
<ContentControl x:Name="ExternalCommandMasterViewModel" Grid.Row="1" VerticalContentAlignment="Stretch"/>
|
||||||
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
@ -8,7 +8,28 @@
|
||||||
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
|
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
|
||||||
d:DataContext="{d:DesignInstance viewModels:ExternalCommandDetailsViewModel,IsDesignTimeCreatable=False}"
|
d:DataContext="{d:DesignInstance viewModels:ExternalCommandDetailsViewModel,IsDesignTimeCreatable=False}"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<StackPanel>
|
<Grid>
|
||||||
<Label></Label>
|
<Grid.RowDefinitions>
|
||||||
</StackPanel>
|
<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>
|
</UserControl>
|
||||||
|
|
|
@ -3,12 +3,29 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:Greenshot.Addon.ExternalCommand.Views"
|
|
||||||
xmlns:cal="http://www.caliburnproject.org"
|
xmlns:cal="http://www.caliburnproject.org"
|
||||||
|
xmlns:viewModels="clr-namespace:Greenshot.Addon.ExternalCommand.ViewModels"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
|
d:DataContext="{d:DesignInstance viewModels:ExternalCommandMasterViewModel,IsDesignTimeCreatable=False}"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<StackPanel>
|
<Grid>
|
||||||
<ListBox x:Name="Items" cal:Message.Attach="[Event SelectionChanged]=[Action ActivateChildView($this.SelectedItem)]"/>
|
<Grid.RowDefinitions>
|
||||||
<ContentControl Name="ActiveItem"/>
|
<RowDefinition Height="100" />
|
||||||
</StackPanel>
|
<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>
|
</UserControl>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue