private void listBoxes_DrawItem(object sender, DrawItemEventArgs e) { ListBox box = (ListBox)sender; if (box.Items.Count >= 1) { e.DrawBackground(); object obj2 = box.Items[e.Index]; string s; PluginInformation information = obj2 as PluginInformation; if (information == null) { int index = (int)obj2; s = ButtonItemsDisplayName[index]; if ((index != 0) && (index < 0x13)) { Rectangle rect = new Rectangle(e.Bounds.Location, fLargeIcon ? new Size(0x18, 0x18) : new Size(0x10, 0x10)); try { Image image2 = fLargeIcon ? imageStripLarge[index - 1] : imageStripSmall[index - 1]; if (image2 != null) { e.Graphics.DrawImage(image2, rect); } } catch { } } } else { Image image = fLargeIcon ? information.ImageLarge : information.ImageSmall; s = information.Name; if ((information.PluginType == PluginType.BackgroundMultiple) && (information.Index != -1)) { foreach (Plugin plugin in pluginManager.Plugins) { if (plugin.PluginInformation.PluginID == information.PluginID) { IBarMultipleCustomItems instance = plugin.Instance as IBarMultipleCustomItems; if (instance == null) { break; } try { image = instance.GetImage(fLargeIcon, information.Index); s = instance.GetName(information.Index); break; } catch { s = "Failed to get name."; break; } } } } if (image != null) { e.Graphics.DrawImage(image, new Rectangle(e.Bounds.Location, fLargeIcon ? new Size(0x18, 0x18) : new Size(0x10, 0x10))); } } bool flag = (e.State & DrawItemState.Selected) != DrawItemState.None; e.Graphics.DrawString(s, Font, flag ? SystemBrushes.HighlightText : SystemBrushes.ControlText, new PointF((e.Bounds.X + 0x1c), (e.Bounds.Y + (fLargeIcon ? 5 : 2)))); } }
private void buttonRestoreDefault_Click(object sender, EventArgs e) { fChangedExists = true; listBoxCurrent.SuspendLayout(); listBoxPool.SuspendLayout(); listBoxCurrent.Items.Clear(); listBoxPool.Items.Clear(); dicActivePluginMulti.Clear(); foreach (int index in QTButtonBar.DefaultButtonIndices) { listBoxCurrent.Items.Add(index); } listBoxPool.Items.Add(0); for (int j = 1; j < ButtonItemsDisplayName.Length; j++) { if (Array.IndexOf(QTButtonBar.DefaultButtonIndices, j) == -1) { listBoxPool.Items.Add(j); } } listBoxPool.Items.AddRange(PluginManager.PluginInformations.Where(info => info.Enabled && info.PluginType == PluginType.Interactive).ToArray()); if (pluginManager != null) { foreach (Plugin plugin in pluginManager.Plugins) { if (plugin.PluginInformation.PluginType == PluginType.BackgroundMultiple) { IBarMultipleCustomItems instance = plugin.Instance as IBarMultipleCustomItems; if (instance != null) { try { int count = instance.Count; if (count > 0) { for (int k = 0; k < count; k++) { listBoxPool.Items.Add(plugin.PluginInformation.Clone(k)); } } else if (count == -1) { listBoxPool.Items.Add(plugin.PluginInformation.Clone(-1)); } } catch (Exception exception) { PluginManager.HandlePluginException(exception, Handle, plugin.PluginInformation.Name, "Adding multi items to pool."); } } continue; } if (plugin.BackgroundButtonSupported) { listBoxPool.Items.Add(plugin.PluginInformation); } } } InitializeImages(string.Empty, true); listBoxPool.ResumeLayout(); listBoxCurrent.ResumeLayout(); }
public ButtonBarOptionForm(int[] currentItemIndexes, bool fLargeIcon, string currentImagePath, PluginManager pluginManager) { InitializeComponent(); this.fLargeIcon = fLargeIcon; this.pluginManager = pluginManager; ButtonItemsDisplayName = QTUtility.TextResourcesDic["ButtonBar_BtnName"]; string[] strArray = QTUtility.TextResourcesDic["ButtonBar_Option"]; string[] strArray2 = QTUtility.TextResourcesDic["DialogButtons"]; buttonOK.Text = strArray2[0]; buttonCancel.Text = strArray2[1]; buttonRestoreDefault.Text = strArray[3]; buttonUp.Text = strArray[4]; buttonDown.Text = strArray[5]; buttonBrowseImage.Text = strArray[6]; buttonResetImage.Text = strArray[11]; comboBoxImageSize.Items.AddRange(new string[] { strArray[7], strArray[8] }); comboBoxImageText.Items.AddRange(new string[] { strArray[12], strArray[13], strArray[14] }); chbLockSearchBox.Text = strArray[15]; comboBoxImageSize.SelectedIndex = this.fLargeIcon ? 1 : 0; if ((QTButtonBar.ConfigValues[0] & 0x20) == 0x20) { comboBoxImageText.SelectedIndex = ((QTButtonBar.ConfigValues[0] & 0x10) == 0x10) ? 1 : 0; } else { comboBoxImageText.SelectedIndex = 2; } comboBoxImageSize.SelectedIndexChanged += comboBoxes_ImageSizeAndText_SelectedIndexChanged; comboBoxImageText.SelectedIndexChanged += comboBoxes_ImageSizeAndText_SelectedIndexChanged; chbLockSearchBox.Checked = (QTButtonBar.ConfigValues[0] & 8) != 0; InitializeImages(currentImagePath, true); List <PluginInformation> list = new List <PluginInformation>(); foreach (int item in currentItemIndexes) { if (item >= 0x10000) { int count = list.Count; if (PluginManager.ActivatedButtonsOrder.Count > count) { string key = PluginManager.ActivatedButtonsOrder[count]; foreach (PluginInformation information in PluginManager.PluginInformations .Where(information => information.PluginID == key)) { list.Add(information); if (information.PluginType == PluginType.BackgroundMultiple) { int num3; if (dicActivePluginMulti.TryGetValue(key, out num3)) { dicActivePluginMulti[key] = num3 + 1; } else { dicActivePluginMulti[key] = 1; } listBoxCurrent.Items.Add(information.Clone(num3)); } else { listBoxCurrent.Items.Add(information); } break; } } } else if (item != 0x15) { listBoxCurrent.Items.Add(item); } } listBoxPool.Items.Add(0); for (int j = 1; j < ButtonItemsDisplayName.Length; j++) { if (Array.IndexOf(currentItemIndexes, j) == -1) { listBoxPool.Items.Add(j); } } listBoxPool.Items.AddRange(PluginManager.PluginInformations .Where(info => info.Enabled && info.PluginType == PluginType.Interactive) .Except(list).ToArray()); if (this.pluginManager == null) { return; } foreach (Plugin plugin in this.pluginManager.Plugins) { if (plugin.PluginInformation.PluginType == PluginType.BackgroundMultiple) { IBarMultipleCustomItems instance = plugin.Instance as IBarMultipleCustomItems; if (instance != null) { try { int num5 = instance.Count; if (num5 > 0) { int num6; dicActivePluginMulti.TryGetValue(plugin.PluginInformation.PluginID, out num6); for (int k = 0; k < (num5 - num6); k++) { listBoxPool.Items.Add(plugin.PluginInformation.Clone(num6 + k)); } } else if (num5 == -1) { listBoxPool.Items.Add(plugin.PluginInformation.Clone(-1)); } } catch (Exception exception) { PluginManager.HandlePluginException(exception, IntPtr.Zero, plugin.PluginInformation.Name, "Adding multi items to pool."); } } } else if (plugin.BackgroundButtonSupported && !plugin.BackgroundButtonEnabled) { listBoxPool.Items.Add(plugin.PluginInformation); } } }
public override void InitializeConfig() { // Initialize the button bar tab. imageStripLarge = new ImageStrip(new Size(24, 24)); imageStripSmall = new ImageStrip(new Size(16, 16)); if (null != WorkingConfig.bbar.ImageStripPath && WorkingConfig.bbar.ImageStripPath.Length > 0) { Bitmap bitmap; Bitmap bitmap2; if (LoadExternalImage(WorkingConfig.bbar.ImageStripPath, out bitmap, out bitmap2)) { imageStripLarge.AddStrip(bitmap); imageStripSmall.AddStrip(bitmap2); bitmap.Dispose(); bitmap2.Dispose(); if (Path.GetExtension(WorkingConfig.bbar.ImageStripPath).PathEquals(".bmp")) { imageStripLarge.TransparentColor = imageStripSmall.TransparentColor = Color.Magenta; } else { imageStripLarge.TransparentColor = imageStripSmall.TransparentColor = Color.Empty; } } } else { using (Bitmap b = Resources_Image.ButtonStrip24) { imageStripLarge.AddStrip(b); } imageStripSmall = new ImageStrip(new Size(16, 16)); using (Bitmap b = Resources_Image.ButtonStrip16) { imageStripSmall.AddStrip(b); } } ButtonPool = new ObservableCollection <ButtonEntry>(); CurrentButtons = new ObservableCollection <ButtonEntry>(); // 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) { lstPluginIDs.Add(pi.PluginID); dicPluginButtons[pi.PluginID] = new ButtonEntry[] { new ButtonEntry(this, order++, 0, pi) }; } else if (pi.PluginType == PluginType.BackgroundMultiple) { Plugin plugin; if (PluginManager.TryGetStaticPluginInstance(pi.PluginID, out plugin)) { IBarMultipleCustomItems bmci = plugin.Instance as IBarMultipleCustomItems; try { if (bmci != null && bmci.Count > 0) { lstPluginIDs.Add(pi.PluginID); dicPluginButtons[pi.PluginID] = bmci.Count.RangeSelect(i => new ButtonEntry(this, order++, i, pi)).ToArray(); } } catch { } } } } // Add the current buttons (right pane) foreach (int i in WorkingConfig.bbar.ButtonIndexes) { 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()]); } } else { CurrentButtons.Add(new ButtonEntry(this, i, i)); } } // Add the rest of the buttons to the button pool (left pane) 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, i)); } } foreach (ButtonEntry entry in lstPluginIDs.SelectMany(pid => dicPluginButtons[pid]).Except(CurrentButtons)) { ButtonPool.Add(entry); } lstButtonBarPool.ItemsSource = ButtonPool; lstButtonBarCurrent.ItemsSource = CurrentButtons; }