forked from OpenTabletDriver/OpenTabletDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PluginSettingsEditor<T> synchronization
- Loading branch information
1 parent
8c321e6
commit 2f3d957
Showing
15 changed files
with
123 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
OpenTabletDriver.UX/Controls/Editors/PluginSettingsEditorList.cs
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
OpenTabletDriver.UX/Controls/Editors/PluginSettingsPanel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Collections.Immutable; | ||
using System.Reflection; | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using OpenTabletDriver.Desktop.Reflection; | ||
using OpenTabletDriver.UX.Components; | ||
|
||
namespace OpenTabletDriver.UX.Controls.Editors | ||
{ | ||
public abstract class PluginSettingsPanel<T> : DesktopPanel where T : class | ||
{ | ||
private readonly IPluginFactory _pluginFactory; | ||
private readonly IControlBuilder _controlBuilder; | ||
private readonly App _app; | ||
private readonly ListBox<TypeInfo> _list; | ||
private readonly Splitter _splitter; | ||
private readonly Placeholder _placeholder; | ||
|
||
protected PluginSettingsPanel( | ||
IControlBuilder controlBuilder, | ||
IPluginFactory pluginFactory, | ||
App app, | ||
IPluginManager pluginManager | ||
) | ||
{ | ||
_controlBuilder = controlBuilder; | ||
_pluginFactory = pluginFactory; | ||
_app = app; | ||
|
||
_splitter = new Splitter | ||
{ | ||
Panel1 = new Panel | ||
{ | ||
MinimumSize = new Size(250, 0), | ||
Content = _list = new ListBox<TypeInfo> | ||
{ | ||
ItemKeyBinding = Binding.Property<TypeInfo, string>(t => t.FullName!), | ||
ItemTextBinding = Binding.Property<TypeInfo, string>(t => t.GetFriendlyName() ?? t.FullName!) | ||
} | ||
}, | ||
Panel2 = _placeholder = new Placeholder("No plugin selected.") | ||
}; | ||
|
||
pluginManager.AssembliesChanged += (_, _) => Refresh(); | ||
DataContextChanged += (_, _) => UpdateContent(); | ||
_list.SelectedIndexChanged += (_, _) => UpdateContent(); | ||
|
||
Refresh(); | ||
} | ||
|
||
protected abstract PluginSettingsCollection? Settings { get; } | ||
|
||
private void Refresh() | ||
{ | ||
var items = _pluginFactory.GetMatchingTypes(typeof(T)).ToImmutableArray(); | ||
_list.DataStore = items; | ||
|
||
if (items.Any()) | ||
{ | ||
Content = _splitter; | ||
UpdateContent(); | ||
} | ||
else | ||
{ | ||
var button = new Button((_, _) => _app.ShowWindow<Windows.PluginManager>()) | ||
{ | ||
Text = "Show plugin manager..." | ||
}; | ||
|
||
Content = new Placeholder("No plugins of this type are installed.", button); | ||
} | ||
} | ||
|
||
private void UpdateContent() | ||
{ | ||
var type = _list.SelectedItem; | ||
|
||
if (Settings?.FromType(type) is PluginSettings settings) | ||
_splitter.Panel2 = _controlBuilder.Build<PluginSettingsEditor>(settings, type); | ||
else | ||
_splitter.Panel2 = _placeholder; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
using OpenTabletDriver.Desktop.Profiles; | ||
using OpenTabletDriver.Desktop.Reflection; | ||
using OpenTabletDriver.Output; | ||
using OpenTabletDriver.UX.Components; | ||
using OpenTabletDriver.UX.Controls.Editors; | ||
|
||
namespace OpenTabletDriver.UX.Controls | ||
{ | ||
public class FiltersPanel : DesktopPanel | ||
public class FiltersPanel : PluginSettingsPanel<IDevicePipelineElement> | ||
{ | ||
public FiltersPanel(IControlBuilder controlBuilder) | ||
public FiltersPanel( | ||
IControlBuilder controlBuilder, | ||
IPluginFactory pluginFactory, | ||
App app, | ||
IPluginManager pluginManager | ||
) : base(controlBuilder, pluginFactory, app, pluginManager) | ||
{ | ||
var editor = controlBuilder.Build<PluginSettingsEditorList<IDevicePipelineElement>>(); | ||
editor.DataContextBinding.BindDataContext((Profile p) => p.Filters); | ||
Content = editor; | ||
} | ||
|
||
protected override PluginSettingsCollection? Settings => (DataContext as Profile)?.Filters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.