Skip to content

Commit

Permalink
fix(core): Minor FocusPlugin fix (#195)
Browse files Browse the repository at this point in the history
Tabs use short name but windows use the full name. The original FocusPlugin implementation used the short name passed in from the calling plugin forwarded to it (likely) from a notification sender. This would only succeed in focusing a popped-out window if the Short name and Full name matched. There are plugins for which this is not true (ie. Commander vs. Fleet Commander).

Update PluginCore to find the plugin instance with the corresponding short name and use pass the plugin instance to the method which can then use either the full name to find the window or the short name to find the tab.
  • Loading branch information
fredjk-gh authored Nov 30, 2024
1 parent a464dd2 commit df4bf9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 17 additions & 3 deletions ObservatoryCore/PluginManagement/PluginCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,24 @@ public JournalEventArgs DeserializeEvent(string json, bool replay = false)

public void FocusPlugin(string pluginName)
{
ExecuteOnUIThread(() =>
// pluginName here is based on "short name" whereas windows are named using full name.
// Find the plugin by short name and proceed with the full name.
IObservatoryPlugin? plugin = null;
foreach (var p in PluginManager.GetInstance.AllUIPlugins)
{
FormsManager.FocusPluginTabOrWindow(pluginName);
});
if (p.ShortName == pluginName)
{
plugin = p;
break;
}
}
if (plugin != null)
{
ExecuteOnUIThread(() =>
{
FormsManager.FocusPluginTabOrWindow(plugin);
});
}
}

internal void Shutdown()
Expand Down
6 changes: 3 additions & 3 deletions ObservatoryCore/UI/FormsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ public static void OpenPluginPopoutForm(IObservatoryPlugin plugin, TabPage? plug
}
}

public static void FocusPluginTabOrWindow(string pluginName)
public static void FocusPluginTabOrWindow(IObservatoryPlugin plugin)
{
// Check first if the plugin is popped out and activate/raise that window.
Form? pluginPopout = FormsManager.GetFormByTitle(pluginName);
Form? pluginPopout = FormsManager.GetFormByTitle(plugin.Name);
if (pluginPopout != null)
{
pluginPopout.Activate();
}
else
{
// Otherwise, switch the main window to that tab.
FindCoreForm()?.FocusPlugin(pluginName);
FindCoreForm()?.FocusPlugin(plugin.ShortName);
}
}
}
Expand Down

0 comments on commit df4bf9c

Please sign in to comment.