Skip to content

Commit 8c296c1

Browse files
authored
Merge pull request #4381 from DavidGBrett/plugin-settings-context-menu-option
[FEATURE] Plugin settings context menu option
2 parents 6d8c35c + a9727c2 commit 8c296c1

10 files changed

Lines changed: 571 additions & 25 deletions

File tree

Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public void OpenSettingDialog()
9494
_api.OpenSettingDialog();
9595
}
9696

97+
public bool OpenPluginSettingsWindow(string pluginId)
98+
{
99+
return _api.OpenPluginSettingsWindow(pluginId);
100+
}
101+
97102
public string GetTranslation(string key)
98103
{
99104
return _api.GetTranslation(key);

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static class Constant
3333
public static readonly string LoadingImgIcon = Path.Combine(ImagesDirectory, "loading.png");
3434
public static readonly string ImageIcon = Path.Combine(ImagesDirectory, "image.png");
3535
public static readonly string HistoryIcon = Path.Combine(ImagesDirectory, "history.png");
36+
public static readonly string SettingsIcon = Path.Combine(ImagesDirectory, "settings.png");
3637

3738
public static string PythonPath;
3839
public static string NodePath;

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ public interface IPublicAPI
162162
/// </summary>
163163
void OpenSettingDialog();
164164

165+
166+
/// <summary>
167+
/// Open plugin setting window for a specific plugin.
168+
/// Reuses the existing window when that plugin's settings window is already open.
169+
/// </summary>
170+
/// <param name="pluginId">ID of the plugin whose settings window should be opened</param>
171+
/// <returns>True if the plugin settings window was successfully opened or reused; false otherwise</returns>
172+
bool OpenPluginSettingsWindow(string pluginId);
173+
165174
/// <summary>
166175
/// Get translation of current language
167176
/// You need to implement IPluginI18n if you want to support multiple languages for your plugin

Flow.Launcher/Helper/SingletonWindowOpener.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,6 @@ public static T Open<T>(params object[] args) where T : Window
1111
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetType() == typeof(T))
1212
?? (T)Activator.CreateInstance(typeof(T), args);
1313

14-
// Fix UI bug
15-
// Add `window.WindowState = WindowState.Normal`
16-
// If only use `window.Show()`, Settings-window doesn't show when minimized in taskbar
17-
// Not sure why this works tho
18-
// Probably because, when `.Show()` fails, `window.WindowState == Minimized` (not `Normal`)
19-
// https://stackoverflow.com/a/59719760/4230390
20-
// Ensure the window is not minimized before showing it
21-
if (window.WindowState == WindowState.Minimized)
22-
{
23-
window.WindowState = WindowState.Normal;
24-
}
25-
26-
// Ensure the window is visible
27-
if (!window.IsVisible)
28-
{
29-
window.Show();
30-
}
31-
else
32-
{
33-
window.Activate(); // Bring the window to the foreground if already open
34-
}
35-
36-
window.Focus();
37-
38-
return (T)window;
14+
return WindowVisibilityHelper.ShowOrActivate((T)window);
3915
}
4016
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Windows;
2+
3+
namespace Flow.Launcher.Helper;
4+
5+
public static class WindowVisibilityHelper
6+
{
7+
public static T ShowOrActivate<T>(T window) where T : Window
8+
{
9+
// Fix UI bug
10+
// Add `window.WindowState = WindowState.Normal`
11+
// If only use `window.Show()`, Settings-window doesn't show when minimized in taskbar
12+
// Not sure why this works tho
13+
// Probably because, when `.Show()` fails, `window.WindowState == Minimized` (not `Normal`)
14+
// https://stackoverflow.com/a/59719760/4230390
15+
// Ensure the window is not minimized before showing it
16+
if (window.WindowState == WindowState.Minimized)
17+
{
18+
window.WindowState = WindowState.Normal;
19+
}
20+
21+
// Ensure the window is visible
22+
if (!window.IsVisible)
23+
{
24+
window.Show();
25+
}
26+
else
27+
{
28+
window.Activate(); // Bring the window to the foreground if already open
29+
}
30+
31+
window.Focus();
32+
33+
return (T)window;
34+
}
35+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@
484484
<system:String x:Key="LogLevelDEBUG">Debug</system:String>
485485
<system:String x:Key="settingWindowFontTitle">Setting Window Font</system:String>
486486

487+
<!-- Plugin Settings Window -->
488+
<system:String x:Key="pluginSettingsWindowTitle">Settings: {0}</system:String>
489+
<system:String x:Key="pluginSettingsWindowOpenFailed">Failed to open plugin settings window</system:String>
490+
487491
<!-- Release Notes Window -->
488492
<system:String x:Key="seeMoreReleaseNotes">See more release notes on GitHub</system:String>
489493
<system:String x:Key="checkNetworkConnectionTitle">Failed to fetch release notes</system:String>

0 commit comments

Comments
 (0)