mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Remove unneccessary CreateSettingPanel by introducing need check
This commit is contained in:
parent
57f20aeaea
commit
4e4758677f
3 changed files with 17 additions and 7 deletions
|
|
@ -34,7 +34,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
/// Represent the plugin that using JsonPRC
|
||||
/// every JsonRPC plugin should has its own plugin instance
|
||||
/// </summary>
|
||||
internal abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISettingProvider, ISavable
|
||||
public abstract class JsonRPCPluginBase : IAsyncPlugin, IContextMenu, ISettingProvider, ISavable
|
||||
{
|
||||
protected PluginInitContext Context;
|
||||
public const string JsonRPC = "JsonRPC";
|
||||
|
|
@ -157,6 +157,11 @@ namespace Flow.Launcher.Core.Plugin
|
|||
Settings?.Save();
|
||||
}
|
||||
|
||||
public bool NeedCreateSettingPanel()
|
||||
{
|
||||
return Settings.NeedCreateSettingPanel();
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return Settings.CreateSettingPanel();
|
||||
|
|
|
|||
|
|
@ -109,10 +109,15 @@ namespace Flow.Launcher.Core.Plugin
|
|||
_storage.Save();
|
||||
}
|
||||
|
||||
public bool NeedCreateSettingPanel()
|
||||
{
|
||||
// If there are no settings or the settings configuration is empty, return null
|
||||
return Settings != null && Configuration != null && Configuration.Body.Count != 0;
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
if (Settings == null || Settings.Count == 0)
|
||||
return null;
|
||||
// No need to check if NeedCreateSettingPanel is true because CreateSettingPanel will only be called if it's true
|
||||
|
||||
var settingWindow = new UserControl();
|
||||
var mainPanel = new Grid { Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center };
|
||||
|
|
|
|||
|
|
@ -90,13 +90,13 @@ namespace Flow.Launcher.ViewModel
|
|||
private Control _bottomPart2;
|
||||
public Control BottomPart2 => IsExpanded ? _bottomPart2 ??= new InstalledPluginDisplayBottomData() : null;
|
||||
|
||||
public bool HasSettingControl => PluginPair.Plugin is ISettingProvider settingProvider && settingProvider.CreateSettingPanel() != null;
|
||||
public bool HasSettingControl => PluginPair.Plugin is ISettingProvider && (PluginPair.Plugin is not JsonRPCPluginBase jsonRPCPluginBase || jsonRPCPluginBase.NeedCreateSettingPanel());
|
||||
public Control SettingControl
|
||||
=> IsExpanded
|
||||
? _settingControl
|
||||
??= PluginPair.Plugin is not ISettingProvider settingProvider
|
||||
? null
|
||||
: settingProvider.CreateSettingPanel()
|
||||
??= HasSettingControl
|
||||
? ((ISettingProvider)PluginPair.Plugin).CreateSettingPanel()
|
||||
: null
|
||||
: null;
|
||||
private ImageSource _image = ImageLoader.MissingImage;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue