[Qttabbar-Commit] SF.net SVN: qttabbar:[415] branches/qtservice/QTTabBar
Status: Beta
Brought to you by:
masamunexgp
From: <mas...@us...> - 2012-02-13 09:17:26
|
Revision: 415 http://qttabbar.svn.sourceforge.net/qttabbar/?rev=415&view=rev Author: masamunexgp Date: 2012-02-13 09:17:16 +0000 (Mon, 13 Feb 2012) Log Message: ----------- Rethought how plugin buttons are stored. Modified Paths: -------------- branches/qtservice/QTTabBar/Config.cs branches/qtservice/QTTabBar/MiscClasses.cs branches/qtservice/QTTabBar/OptionsDialog/Options11_ButtonBar.xaml.cs branches/qtservice/QTTabBar/OptionsDialog/Options12_Plugins.xaml.cs branches/qtservice/QTTabBar/PluginManager.cs branches/qtservice/QTTabBar/QTButtonBar.cs branches/qtservice/QTTabBar/QTUtility2.cs Modified: branches/qtservice/QTTabBar/Config.cs =================================================================== --- branches/qtservice/QTTabBar/Config.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/Config.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -440,6 +440,7 @@ [Serializable] public class _BBar { public int[] ButtonIndexes { get; set; } + public string[] ActivePluginIDs { get; set; } public bool LargeButtons { get; set; } public bool LockSearchBarWidth { get; set; } public bool LockDropDownButtons { get; set; } @@ -450,6 +451,7 @@ ButtonIndexes = QTUtility.IsXP ? new int[] {1, 2, 0, 3, 4, 5, 0, 6, 7, 0, 11, 13, 12, 14, 15, 0, 9, 20} : new int[] {3, 4, 5, 0, 6, 7, 0, 11, 13, 12, 14, 15, 0, 9, 20}; + ActivePluginIDs = new string[0]; LockDropDownButtons = false; LargeButtons = true; LockSearchBarWidth = false; @@ -680,6 +682,9 @@ // todo: check dimensions if(!wrapper.Available) Config.BBar.ImageStripPath = ""; } + List<int> blist = Config.BBar.ButtonIndexes.ToList(); + blist.RemoveAll(i => (i.HiWord() - 1) >= Config.BBar.ActivePluginIDs.Length); + Config.BBar.ButtonIndexes = blist.ToArray(); var keys = Config.Keys.Shortcuts; Array.Resize(ref keys, (int)BindAction.KEYBOARD_ACTION_COUNT); Config.Keys.Shortcuts = keys; Modified: branches/qtservice/QTTabBar/MiscClasses.cs =================================================================== --- branches/qtservice/QTTabBar/MiscClasses.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/MiscClasses.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -175,6 +175,8 @@ } } + // Normally, delegates are only serializable if they don't include any + // stack variables. But using this class, we can serialize any delegate. [Serializable] public class SerializeDelegate : ISerializable { public Delegate Delegate { get; private set; } Modified: branches/qtservice/QTTabBar/OptionsDialog/Options11_ButtonBar.xaml.cs =================================================================== --- branches/qtservice/QTTabBar/OptionsDialog/Options11_ButtonBar.xaml.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/OptionsDialog/Options11_ButtonBar.xaml.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -49,16 +49,14 @@ ButtonPool = new ObservableCollection<ButtonEntry>(); CurrentButtons = new ObservableCollection<ButtonEntry>(); - // Create a list of all the plugin buttons, and store the list - // index of the first button of each plugin in a dictionary keyed - // on plugin ID. - int pluginListPos = 0; - var dicPluginListPos = new Dictionary<string, int>(); - var lstPluginButtons = new List<ButtonEntry>(); - foreach(PluginInformation pi in PluginManager.PluginInformations.OrderBy(pi => pi.Name)) { + // Create a list of all the plugin buttons. + int order = QTButtonBar.INTERNAL_BUTTON_COUNT; + var lstPluginIDs = new List<string>(); + var dicPluginButtons = new Dictionary<string, ButtonEntry[]>(); + foreach(PluginInformation pi in PluginManager.PluginInformations.Where(pi => pi.Enabled).OrderBy(pi => pi.Name)) { if(pi.PluginType == PluginType.Interactive) { - dicPluginListPos[pi.PluginID] = pluginListPos; - lstPluginButtons.Add(new ButtonEntry(this, pluginListPos++, pi, 0)); + lstPluginIDs.Add(pi.PluginID); + dicPluginButtons[pi.PluginID] = new ButtonEntry[] { new ButtonEntry(this, order++, 0, pi) }; } else if(pi.PluginType == PluginType.BackgroundMultiple) { Plugin plugin; @@ -66,10 +64,9 @@ IBarMultipleCustomItems bmci = plugin.Instance as IBarMultipleCustomItems; try { if(bmci != null && bmci.Count > 0) { - dicPluginListPos[pi.PluginID] = pluginListPos; - for(int i = 0; i < bmci.Count; i++) { - lstPluginButtons.Add(new ButtonEntry(this, pluginListPos++, pi, i)); - } + lstPluginIDs.Add(pi.PluginID); + dicPluginButtons[pi.PluginID] = + bmci.Count.RangeSelect(i => new ButtonEntry(this, order++, i, pi)).ToArray(); } } catch { } @@ -78,33 +75,30 @@ } // Add the current buttons (right pane) - int pluginIndex = 0; foreach(int i in WorkingConfig.bbar.ButtonIndexes) { - if(i == QTButtonBar.BUTTONINDEX_PLUGIN) { - if(pluginIndex < PluginManager.ActivatedButtonsOrder.Count) { - var pluginButton = PluginManager.ActivatedButtonsOrder[pluginIndex]; - if(dicPluginListPos.ContainsKey(pluginButton.id)) { - CurrentButtons.Add(lstPluginButtons[dicPluginListPos[pluginButton.id] + pluginButton.index]); - } + int pluginIndex = i.HiWord() - 1; + if(pluginIndex >= 0) { + string id = WorkingConfig.bbar.ActivePluginIDs[pluginIndex]; + ButtonEntry[] buttons; + if(dicPluginButtons.TryGetValue(id, out buttons) && i.LoWord() < buttons.Length) { + CurrentButtons.Add(buttons[i.LoWord()]); } - pluginIndex++; } else { - CurrentButtons.Add(new ButtonEntry(this, i)); + CurrentButtons.Add(new ButtonEntry(this, i, i)); } } // Add the rest of the buttons to the button pool (left pane) - ButtonPool.Add(new ButtonEntry(this, QTButtonBar.BII_SEPARATOR)); + ButtonPool.Add(new ButtonEntry(this, 0, QTButtonBar.BII_SEPARATOR)); for(int i = 1; i < QTButtonBar.INTERNAL_BUTTON_COUNT; i++) { if(!WorkingConfig.bbar.ButtonIndexes.Contains(i)) { - ButtonPool.Add(new ButtonEntry(this, i)); + ButtonPool.Add(new ButtonEntry(this, i, i)); } } - foreach(ButtonEntry entry in lstPluginButtons) { - if(!CurrentButtons.Contains(entry)) { - ButtonPool.Add(entry); - } + + foreach(ButtonEntry entry in lstPluginIDs.SelectMany(pid => dicPluginButtons[pid]).Except(CurrentButtons)) { + ButtonPool.Add(entry); } lstButtonBarPool.ItemsSource = ButtonPool; lstButtonBarCurrent.ItemsSource = CurrentButtons; @@ -116,26 +110,20 @@ } public override void CommitConfig() { - var pluginButtons = new List<PluginManager.PluginButton>(); - for(int i = 0; i < CurrentButtons.Count; i++) { - ButtonEntry entry = CurrentButtons[i]; - if(entry.Index >= QTButtonBar.BUTTONINDEX_PLUGIN) { - if(entry.PluginInfo.Enabled) { - pluginButtons.Add(new PluginManager.PluginButton { - id = entry.PluginInfo.PluginID, - index = entry.PluginButtonIndex - }); + List<string> activeIDs = new List<string>(); + WorkingConfig.bbar.ButtonIndexes = CurrentButtons.Select(entry => { + int p = 0; + if(entry.PluginInfo != null) { + p = activeIDs.IndexOf(entry.PluginInfo.PluginID) + 1; + if(p == 0) { + activeIDs.Add(entry.PluginInfo.PluginID); + p = activeIDs.Count; } - else { - CurrentButtons.RemoveAt(i--); - } + p <<= 16; } - } - PluginManager.ActivatedButtonsOrder = pluginButtons; - PluginManager.SaveButtonOrder(); - WorkingConfig.bbar.ButtonIndexes = CurrentButtons.Select( - e => Math.Min(e.Index, QTButtonBar.BUTTONINDEX_PLUGIN)).ToArray(); - + return p + entry.Index; + }).ToArray(); + WorkingConfig.bbar.ActivePluginIDs = activeIDs.ToArray(); // TODO: Validate image strip } @@ -143,8 +131,8 @@ int sel = lstButtonBarPool.SelectedIndex; if(sel == -1) return; ButtonEntry entry = ButtonPool[sel]; - if(entry.Index == QTButtonBar.BII_SEPARATOR) { - entry = new ButtonEntry(this, QTButtonBar.BII_SEPARATOR); + if(entry.Order == QTButtonBar.BII_SEPARATOR) { + entry = new ButtonEntry(this, 0, QTButtonBar.BII_SEPARATOR); } else { ButtonPool.RemoveAt(sel); @@ -175,9 +163,9 @@ lstButtonBarCurrent.SelectedIndex = sel; lstButtonBarCurrent.ScrollIntoView(lstButtonBarCurrent.SelectedItem); } - if(entry.Index != QTButtonBar.BII_SEPARATOR) { + if(entry.Order != QTButtonBar.BII_SEPARATOR) { int i = 0; - while(i < ButtonPool.Count && ButtonPool[i].Index < entry.Index) ++i; + while(i < ButtonPool.Count && ButtonPool[i].Order < entry.Order) ++i; ButtonPool.Insert(i, entry); lstButtonBarPool.SelectedIndex = i; } @@ -214,16 +202,16 @@ public PluginInformation PluginInfo { get; private set; } public int Index { get; private set; } - public bool IsPluginButton { get { return Index >= QTButtonBar.BUTTONINDEX_PLUGIN; } } - public int PluginButtonIndex { get; private set; } + public int Order { get; private set; } + public bool IsPluginButton { get { return PluginInfo != null; } } public string PluginButtonText { get { if(!IsPluginButton) return ""; - if(PluginInfo.PluginType == PluginType.BackgroundMultiple && PluginButtonIndex != -1) { + if(PluginInfo.PluginType == PluginType.BackgroundMultiple) { Plugin plugin; if(PluginManager.TryGetStaticPluginInstance(PluginInfo.PluginID, out plugin)) { try { - return ((IBarMultipleCustomItems)plugin.Instance).GetName(PluginButtonIndex); + return ((IBarMultipleCustomItems)plugin.Instance).GetName(Index); } catch { } } @@ -235,12 +223,12 @@ public Image LargeImage { get { return getImage(true); } } public Image SmallImage { get { return getImage(false); } } private Image getImage(bool large) { - if(Index >= QTButtonBar.BUTTONINDEX_PLUGIN) { - if(PluginInfo.PluginType == PluginType.BackgroundMultiple && PluginButtonIndex != -1) { + if(IsPluginButton) { + if(PluginInfo.PluginType == PluginType.BackgroundMultiple) { Plugin plugin; if(PluginManager.TryGetStaticPluginInstance(PluginInfo.PluginID, out plugin)) { try { - return ((IBarMultipleCustomItems)plugin.Instance).GetImage(large, PluginButtonIndex); + return ((IBarMultipleCustomItems)plugin.Instance).GetImage(large, Index); } catch { } } @@ -258,15 +246,12 @@ : parent.imageStripSmall[Index - 1]; } } - public ButtonEntry(Options11_ButtonBar parent, int Index) { + + public ButtonEntry(Options11_ButtonBar parent, int Order, int Index, PluginInformation PluginInfo = null) { this.parent = parent; + this.Order = Order; this.Index = Index; - } - public ButtonEntry(Options11_ButtonBar parent, int Index, PluginInformation PluginInfo, int PluginButtonIndex) { - this.parent = parent; this.PluginInfo = PluginInfo; - this.Index = QTButtonBar.BUTTONINDEX_PLUGIN + Index; - this.PluginButtonIndex = PluginButtonIndex; } } Modified: branches/qtservice/QTTabBar/OptionsDialog/Options12_Plugins.xaml.cs =================================================================== --- branches/qtservice/QTTabBar/OptionsDialog/Options12_Plugins.xaml.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/OptionsDialog/Options12_Plugins.xaml.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -48,7 +48,8 @@ } public override void CommitConfig() { - List<PluginAssembly> assemblies = new List<PluginAssembly>(); + HashSet<string> paths = new HashSet<string>(); + HashSet<PluginAssembly> toDispose = new HashSet<PluginAssembly>(); // Don't dispose the assemblies here. That will be done by the plugin manager // when the plugins are unloaded. @@ -61,35 +62,31 @@ List<string> enabled = new List<string>(); foreach(PluginEntry entry in CurrentPlugins) { - PluginAssembly pa = entry.PluginAssembly; - if(!assemblies.Contains(pa)) { - pa.Enabled = false; - assemblies.Add(pa); - } + paths.Add(entry.PluginAssembly.Path); if(entry.DisableOnClose) { entry.Enabled = false; } - else if(entry.EnableOnClose || entry.InstallOnClose) { + else if(entry.EnableOnClose) { entry.Enabled = true; } + else if(entry.InstallOnClose) { + entry.Enabled = true; + toDispose.Add(entry.PluginAssembly); + // Newly installed PluginAssemblies are loaded by the options dialog. + // They will also be loaded by the PluginManager, so we have to + // dispose of the ones we loaded here. + } entry.EnableOnClose = entry.DisableOnClose = entry.InstallOnClose = false; - if(entry.Enabled) { - pa.Enabled = true; - enabled.Add(entry.PluginID); - } + if(entry.Enabled) enabled.Add(entry.PluginID); } WorkingConfig.plugin.Enabled = enabled.ToArray(); - - // todo: redo this crap... - // IM! - /* - QTTabBarClass tabBar = InstanceManager.CurrentTabBar; - if(tabBar != null) { - tabBar.Invoke(new Action(() => tabBar.odCallback_ManagePlugin(assemblies))); - }*/ - PluginManager.SavePluginAssemblies(); - PluginManager.SavePluginShortcutKeys(); + foreach(PluginAssembly asm in toDispose) { + asm.Dispose(); + } + PluginManager.SavePluginAssemblyPaths(paths.ToList()); + PluginManager.SavePluginShortcutKeys(); // todo: kill + CurrentPlugins = new ObservableCollection<PluginEntry>(); } private void btnPluginOptions_Click(object sender, RoutedEventArgs e) { @@ -144,7 +141,6 @@ PluginEntry otherEntry = CurrentPlugins[i]; if(otherEntry.PluginAssembly == entry.PluginAssembly) { if(otherEntry.InstallOnClose) { - otherEntry.PluginAssembly.Dispose(); CurrentPlugins.RemoveAt(i); --i; } @@ -153,6 +149,9 @@ } } } + if(entry.InstallOnClose) { + entry.PluginAssembly.Dispose(); + } } private void btnBrowsePlugin_Click(object sender, RoutedEventArgs e) { Modified: branches/qtservice/QTTabBar/PluginManager.cs =================================================================== --- branches/qtservice/QTTabBar/PluginManager.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/PluginManager.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -28,7 +28,6 @@ namespace QTTabBarLib { internal static class PluginManager { - private static List<PluginButton> lstPluginButtonsOrder = new List<PluginButton>(); private static IEncodingDetector plgEncodingDetector; private static Dictionary<string, PluginAssembly> dicPluginAssemblies = new Dictionary<string, PluginAssembly>(); private static Dictionary<string, Plugin> dicStaticPluginInstances = new Dictionary<string, Plugin>(); @@ -55,10 +54,8 @@ using(RegistryKey key = Registry.CurrentUser.CreateSubKey(RegConst.Root + @"Plugins")) { if(key == null) return; - PluginButton[] buttons = QTUtility2.ReadRegBinary<PluginButton>("Buttons_Order", key); string[] keys = QTUtility2.ReadRegBinary<string>("ShortcutKeyIDs", key); int[][] values = QTUtility2.ReadRegBinary<int[]>("ShortcutKeyValues", key); - if(buttons != null) lstPluginButtonsOrder.AddRange(buttons); if(keys == null || values == null) return; for(int i = 0; i < Math.Min(keys.Length, values.Length); ++i) { QTUtility.dicPluginShortcutKeys[keys[i]] = values[i]; @@ -152,23 +149,15 @@ InstanceManager.LocalTabBroadcast(tabbar => tabbar.pluginServer.RefreshPlugins()); } - public static void SaveButtonOrder() { - using(RegistryKey key = Registry.CurrentUser.CreateSubKey(RegConst.Root + @"Plugins")) { - if(key != null) { - QTUtility2.WriteRegBinary(lstPluginButtonsOrder.ToArray(), "Buttons_Order", key); - } - } - } - - public static void SavePluginAssemblies() { + public static void SavePluginAssemblyPaths(List<string> paths) { const string RegPath = RegConst.Root + @""; // TODO using(RegistryKey key = Registry.CurrentUser.CreateSubKey(RegPath + @"Plugins\Paths")) { foreach(string str in key.GetValueNames()) { key.DeleteValue(str); } int idx = 0; - foreach(PluginAssembly asm in PluginAssemblies) { - key.SetValue("" + idx++, asm.Path); + foreach(string path in paths) { + key.SetValue("" + idx++, path); } } } @@ -204,15 +193,6 @@ pa.Dispose(); } - public static List<PluginButton> ActivatedButtonsOrder { - get { - return lstPluginButtonsOrder; - } - set { - lstPluginButtonsOrder = value; - } - } - public static IEncodingDetector IEncodingDetector { get { return plgEncodingDetector; Modified: branches/qtservice/QTTabBar/QTButtonBar.cs =================================================================== --- branches/qtservice/QTTabBar/QTButtonBar.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/QTButtonBar.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -75,7 +75,6 @@ private VisualStyleRenderer BackgroundRenderer; private const int BARHEIGHT_LARGE = 34; private const int BARHEIGHT_SMALL = 26; - internal const int BUTTONINDEX_PLUGIN = 0x10000; private IContainer components; private DropDownMenuReorderable ddmrGroupButton; private DropDownMenuReorderable ddmrRecentlyClosed; @@ -87,7 +86,6 @@ private ShellContextMenu shellContextMenu = new ShellContextMenu(); private const int INTERVAL_REARRANGE = 300; private const int INTERVAL_SEARCHSTART = 250; - private int iPluginCreatingIndex; private int iSearchResultCount = -1; private List<ToolStripItem> lstPluginCustomItem = new List<ToolStripItem>(); private List<IntPtr> lstPUITEMIDCHILD = new List<IntPtr>(); @@ -407,12 +405,11 @@ timerSearchBox_Rearrange.Tick += timerSearchBox_Rearrange_Tick; continue; - case BUTTONINDEX_PLUGIN: - CreatePluginItem(); - continue; - default: - if(index >= INTERNAL_BUTTON_COUNT) continue; + if(index >= INTERNAL_BUTTON_COUNT) { + if(index.HiWord() > 0) CreatePluginItem(index); + continue; + } item = new ToolStripButton(); break; } @@ -441,35 +438,31 @@ toolStrip.ResumeLayout(); toolStrip.RaiseOnResize(); - iPluginCreatingIndex = 0; } - private void CreatePluginItem() { + private void CreatePluginItem(int buttonIndex) { QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); if(tabbar == null) return; QTTabBarClass.PluginServer pluginServer = tabbar.pluginServer; - if(pluginServer != null && iPluginCreatingIndex < PluginManager.ActivatedButtonsOrder.Count) { - string pluginID = string.Empty; - try { - int buttonIndex = BUTTONINDEX_PLUGIN + iPluginCreatingIndex; - pluginID = PluginManager.ActivatedButtonsOrder[iPluginCreatingIndex].id; - bool showText = Config.BBar.ShowButtonLabels; - PluginInformation pi = PluginManager.PluginInformations.FirstOrDefault(info => info.PluginID == pluginID); - if(pi == null) return; - Plugin plugin; - pluginServer.TryGetPlugin(pluginID, out plugin); - if(plugin == null) { - plugin = pluginServer.Load(pi, null); - } - if(plugin == null) return; + if(pluginServer == null) return; + string pluginID = Config.BBar.ActivePluginIDs[buttonIndex.HiWord() - 1]; + try { + bool showText = Config.BBar.ShowButtonLabels; + PluginInformation pi = PluginManager.PluginInformations.FirstOrDefault(info => info.PluginID == pluginID); + if(pi == null || !pi.Enabled) return; + Plugin plugin; + pluginServer.TryGetPlugin(pluginID, out plugin); + if(plugin == null) { + plugin = pluginServer.Load(pi, null); + } + if(plugin == null) return; - ToolStripItem itemToAdd = null; - - if(plugin.Instance is IBarDropButton) { - IBarDropButton instance = (IBarDropButton)plugin.Instance; - instance.InitializeItem(); - if(instance.IsSplitButton) { - itemToAdd = new ToolStripSplitButton(instance.Text) { + ToolStripItem itemToAdd = null; + if(plugin.Instance is IBarDropButton) { + IBarDropButton instance = (IBarDropButton)plugin.Instance; + instance.InitializeItem(); + if(instance.IsSplitButton) { + itemToAdd = new ToolStripSplitButton(instance.Text) { ImageScaling = ToolStripItemImageScaling.None, DropDownButtonWidth = Config.BBar.LargeButtons ? 14 : 11, DisplayStyle = showText @@ -477,81 +470,77 @@ : ToolStripItemDisplayStyle.Image, ToolTipText = instance.Text, Image = instance.GetImage(Config.BBar.LargeButtons) - }; - DropDownMenuReorderable reorder = new DropDownMenuReorderable(components); - reorder.ItemClicked += pluginDropDown_ItemClicked; - reorder.ItemRightClicked += pluginDropDown_ItemRightClicked; - ((ToolStripSplitButton)itemToAdd).DropDown = reorder; - ((ToolStripSplitButton)itemToAdd).DropDownOpening += pluginDropDown_DropDownOpening; - ((ToolStripSplitButton)itemToAdd).ButtonClick += pluginButton_ButtonClick; - } - else { - itemToAdd = new ToolStripDropDownButton(instance.Text) { + }; + DropDownMenuReorderable reorder = new DropDownMenuReorderable(components); + reorder.ItemClicked += pluginDropDown_ItemClicked; + reorder.ItemRightClicked += pluginDropDown_ItemRightClicked; + ((ToolStripSplitButton)itemToAdd).DropDown = reorder; + ((ToolStripSplitButton)itemToAdd).DropDownOpening += pluginDropDown_DropDownOpening; + ((ToolStripSplitButton)itemToAdd).ButtonClick += pluginButton_ButtonClick; + } + else { + itemToAdd = new ToolStripDropDownButton(instance.Text) { ImageScaling = ToolStripItemImageScaling.None, DisplayStyle = showText ? ToolStripItemDisplayStyle.ImageAndText : ToolStripItemDisplayStyle.Image, ToolTipText = instance.Text, Image = instance.GetImage(Config.BBar.LargeButtons) - }; - DropDownMenuReorderable reorder = new DropDownMenuReorderable(components); - reorder.ItemClicked += pluginDropDown_ItemClicked; - reorder.ItemRightClicked += pluginDropDown_ItemRightClicked; - ((ToolStripDropDownButton)itemToAdd).DropDown = reorder; - ((ToolStripDropDownButton)itemToAdd).DropDownOpening += pluginDropDown_DropDownOpening; - } + }; + DropDownMenuReorderable reorder = new DropDownMenuReorderable(components); + reorder.ItemClicked += pluginDropDown_ItemClicked; + reorder.ItemRightClicked += pluginDropDown_ItemRightClicked; + ((ToolStripDropDownButton)itemToAdd).DropDown = reorder; + ((ToolStripDropDownButton)itemToAdd).DropDownOpening += pluginDropDown_DropDownOpening; } - else if(plugin.Instance is IBarButton) { - IBarButton instance = (IBarButton)plugin.Instance; - instance.InitializeItem(); - itemToAdd = new ToolStripButton(instance.Text) { + } + else if(plugin.Instance is IBarButton) { + IBarButton instance = (IBarButton)plugin.Instance; + instance.InitializeItem(); + itemToAdd = new ToolStripButton(instance.Text) { ImageScaling = ToolStripItemImageScaling.None, DisplayStyle = showText ? ToolStripItemDisplayStyle.ImageAndText : ToolStripItemDisplayStyle.Image, ToolTipText = instance.Text, Image = instance.GetImage(Config.BBar.LargeButtons) - }; - itemToAdd.Click += pluginButton_ButtonClick; + }; + itemToAdd.Click += pluginButton_ButtonClick; + } + else if(plugin.Instance is IBarCustomItem) { + IBarCustomItem instance = (IBarCustomItem)plugin.Instance; + DisplayStyle displayStyle = showText ? DisplayStyle.ShowTextLabel : DisplayStyle.NoLabel; + itemToAdd = instance.CreateItem(Config.BBar.LargeButtons, displayStyle); + if(itemToAdd != null) { + itemToAdd.ImageScaling = ToolStripItemImageScaling.None; + lstPluginCustomItem.Add(itemToAdd); } - else if(plugin.Instance is IBarCustomItem) { - IBarCustomItem instance = (IBarCustomItem)plugin.Instance; - DisplayStyle displayStyle = showText ? DisplayStyle.ShowTextLabel : DisplayStyle.NoLabel; - itemToAdd = instance.CreateItem(Config.BBar.LargeButtons, displayStyle); - if(itemToAdd != null) { - itemToAdd.ImageScaling = ToolStripItemImageScaling.None; - lstPluginCustomItem.Add(itemToAdd); - } + } + else if(plugin.Instance is IBarMultipleCustomItems) { + IBarMultipleCustomItems instance = (IBarMultipleCustomItems)plugin.Instance; + if(buttonIndex.LoWord() >= instance.Count) return; + if(!plugin.BackgroundButtonEnabled) { + // This is to maintain backwards compatibility. + instance.Initialize(instance.Count.RangeSelect(i => i).ToArray()); } - else if(plugin.Instance is IBarMultipleCustomItems) { - IBarMultipleCustomItems instance = (IBarMultipleCustomItems)plugin.Instance; - if(!plugin.BackgroundButtonEnabled) { - // This is to maintain backwards compatibility. - instance.Initialize(Enumerable.Range(0, instance.Count).ToArray()); - } - DisplayStyle style = showText ? DisplayStyle.ShowTextLabel : DisplayStyle.NoLabel; - int index = PluginManager.ActivatedButtonsOrder[iPluginCreatingIndex].index; - itemToAdd = instance.CreateItem(Config.BBar.LargeButtons, style, index); - if(itemToAdd != null) { - lstPluginCustomItem.Add(itemToAdd); - } + DisplayStyle style = showText ? DisplayStyle.ShowTextLabel : DisplayStyle.NoLabel; + itemToAdd = instance.CreateItem(Config.BBar.LargeButtons, style, buttonIndex.LoWord()); + if(itemToAdd != null) { + lstPluginCustomItem.Add(itemToAdd); } + } - if(itemToAdd != null) { - itemToAdd.Tag = buttonIndex; - toolStrip.Items.Add(itemToAdd); - if(pi.PluginType == PluginType.Background || pi.PluginType == PluginType.BackgroundMultiple) { - plugin.BackgroundButtonEnabled = true; - } + if(itemToAdd != null) { + itemToAdd.Tag = buttonIndex; + toolStrip.Items.Add(itemToAdd); + if(pi.PluginType == PluginType.Background || pi.PluginType == PluginType.BackgroundMultiple) { + plugin.BackgroundButtonEnabled = true; } } - catch(Exception exception) { - PluginManager.HandlePluginException(exception, ExplorerHandle, pluginID, "Loading plugin button."); - } - finally { - iPluginCreatingIndex++; - } } + catch(Exception exception) { + PluginManager.HandlePluginException(exception, ExplorerHandle, pluginID, "Loading plugin button."); + } } private void ddmr45_ItemRightClicked(object sender, ItemRightClickedEventArgs e) { @@ -853,19 +842,16 @@ private void pluginButton_ButtonClick(object sender, EventArgs e) { ToolStripItem item = (ToolStripItem)sender; - int num = ((int)item.Tag) - 0x10000; - if(PluginManager.ActivatedButtonsOrder.Count > num) { - Plugin plugin; - string pluginID = PluginManager.ActivatedButtonsOrder[num].id; - QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); - if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { - try { - ((IBarButton)plugin.Instance).OnButtonClick(); - } - catch(Exception exception) { - PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On button clicked."); - } + Plugin plugin; + string pluginID = Config.BBar.ActivePluginIDs[((int)item.Tag).HiWord() - 1]; + QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); + if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { + try { + ((IBarButton)plugin.Instance).OnButtonClick(); } + catch(Exception exception) { + PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On button clicked."); + } } } @@ -873,56 +859,47 @@ toolStrip.HideToolTip(); ToolStripDropDownItem item = (ToolStripDropDownItem)sender; item.DropDown.SuspendLayout(); - int num = ((int)item.Tag) - 0x10000; - if(PluginManager.ActivatedButtonsOrder.Count > num) { - Plugin plugin; - string pluginID = PluginManager.ActivatedButtonsOrder[num].id; - QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); - if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { - try { - ((IBarDropButton)plugin.Instance).OnDropDownOpening((ToolStripDropDownMenu)item.DropDown); - } - catch(Exception exception) { - PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdwon menu is showing."); - } + Plugin plugin; + string pluginID = Config.BBar.ActivePluginIDs[((int)item.Tag).HiWord() - 1];; + QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); + if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { + try { + ((IBarDropButton)plugin.Instance).OnDropDownOpening((ToolStripDropDownMenu)item.DropDown); } + catch(Exception exception) { + PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdwon menu is showing."); + } } item.DropDown.ResumeLayout(); } private void pluginDropDown_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripDropDownItem ownerItem = (ToolStripDropDownItem)((DropDownMenuReorderable)sender).OwnerItem; - int num = ((int)ownerItem.Tag) - 0x10000; - if((PluginManager.ActivatedButtonsOrder.Count > num) && (num > -1)) { - Plugin plugin; - string pluginID = PluginManager.ActivatedButtonsOrder[num].id; - QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); - if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { - try { - ((IBarDropButton)plugin.Instance).OnDropDownItemClick(e.ClickedItem, MouseButtons.Left); - } - catch(Exception exception) { - PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdown menu is clicked."); - } + Plugin plugin; + string pluginID = Config.BBar.ActivePluginIDs[((int)ownerItem.Tag).HiWord() - 1]; + QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); + if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { + try { + ((IBarDropButton)plugin.Instance).OnDropDownItemClick(e.ClickedItem, MouseButtons.Left); } + catch(Exception exception) { + PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdown menu is clicked."); + } } } private void pluginDropDown_ItemRightClicked(object sender, ItemRightClickedEventArgs e) { ToolStripDropDownItem ownerItem = (ToolStripDropDownItem)((DropDownMenuReorderable)sender).OwnerItem; - int num = ((int)ownerItem.Tag) - 0x10000; - if((PluginManager.ActivatedButtonsOrder.Count > num) && (num > -1)) { - Plugin plugin; - string pluginID = PluginManager.ActivatedButtonsOrder[num].id; - QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); - if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { - try { - ((IBarDropButton)plugin.Instance).OnDropDownItemClick(e.ClickedItem, MouseButtons.Right); - } - catch(Exception exception) { - PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdown menu is right clicked."); - } + Plugin plugin; + string pluginID = Config.BBar.ActivePluginIDs[((int)ownerItem.Tag).HiWord() - 1]; + QTTabBarClass tabbar = InstanceManager.GetThreadTabBar(); + if(tabbar != null && tabbar.pluginServer.TryGetPlugin(pluginID, out plugin)) { + try { + ((IBarDropButton)plugin.Instance).OnDropDownItemClick(e.ClickedItem, MouseButtons.Right); } + catch(Exception exception) { + PluginManager.HandlePluginException(exception, ExplorerHandle, plugin.PluginInformation.Name, "On dropdown menu is right clicked."); + } } } @@ -1242,7 +1219,7 @@ IntPtr tabBarHandle = InstanceManager.GetThreadTabBar().Handle; if(tabBarHandle != IntPtr.Zero) { int tag = (int)e.ClickedItem.Tag; - if((tag < 0x10000) && (tag != 9)) { + if((tag.HiWord() == 0) && (tag != 9)) { IntPtr ptr2; if((tag == 1) || (tag == 2)) { ptr2 = (IntPtr)(0xf00 | tag); @@ -1457,12 +1434,12 @@ PluginType pluginType = plugin.PluginInformation.PluginType; string pluginID = plugin.PluginInformation.PluginID; if(pluginType == PluginType.Interactive) { - if(!PluginManager.ActivatedButtonsOrder.Any(btn => btn.id == pluginID)) { + if(!Config.BBar.ActivePluginIDs.Contains(pluginID)) { tabbar.pluginServer.UnloadPluginInstance(pluginID, EndCode.Unloaded); } } else if((pluginType == PluginType.Background || pluginType == PluginType.BackgroundMultiple) - && plugin.BackgroundButtonEnabled && PluginManager.ActivatedButtonsOrder.All(btn => btn.id != pluginID)) { + && plugin.BackgroundButtonEnabled && !Config.BBar.ActivePluginIDs.Contains(pluginID)) { try { if(plugin.Instance != null) { plugin.Instance.Close(EndCode.Hidden); Modified: branches/qtservice/QTTabBar/QTUtility2.cs =================================================================== --- branches/qtservice/QTTabBar/QTUtility2.cs 2012-02-12 21:54:53 UTC (rev 414) +++ branches/qtservice/QTTabBar/QTUtility2.cs 2012-02-13 09:17:16 UTC (rev 415) @@ -65,13 +65,27 @@ } public static int GET_X_LPARAM(IntPtr lParam) { - return (short)(((int)lParam) & 0xffff); + return ((int)lParam).LoWord(); } public static int GET_Y_LPARAM(IntPtr lParam) { - return (short)((((int)lParam) >> 0x10) & 0xffff); + return ((int)lParam).HiWord(); } + public static int HiWord(this int i) { + return (short)((i >> 0x10) & 0xffff); + } + + public static int LoWord(this int i) { + return (short)(i & 0xffff); + } + + public static IEnumerable<T> RangeSelect<T>(this int i, Converter<int, T> converter) { + for(int j = 0; j < i; j++) { + yield return converter(j); + } + } + public static string GetDriveDisplayText(string path) { if((path.Length != 3) || !path.EndsWith(@":\")) { return string.Empty; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |