From b588ec9d32186f6f149e18c56c929d8c5c1a19ac Mon Sep 17 00:00:00 2001 From: Thegmk13 Date: Wed, 8 Feb 2017 00:28:23 +0100 Subject: [PATCH] Replaced DropDownComboBox with MRUComboBox --- Tvl.DebugCommandLine/DebugCommandLine.vsct | 2 +- .../DebugCommandLinePackage.cs | 74 +++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/Tvl.DebugCommandLine/DebugCommandLine.vsct b/Tvl.DebugCommandLine/DebugCommandLine.vsct index 4d87a3c..680ac06 100644 --- a/Tvl.DebugCommandLine/DebugCommandLine.vsct +++ b/Tvl.DebugCommandLine/DebugCommandLine.vsct @@ -4,7 +4,7 @@ - + DynamicVisibility DefaultInvisible CommandWellOnly diff --git a/Tvl.DebugCommandLine/DebugCommandLinePackage.cs b/Tvl.DebugCommandLine/DebugCommandLinePackage.cs index 911fddf..f9a320b 100644 --- a/Tvl.DebugCommandLine/DebugCommandLinePackage.cs +++ b/Tvl.DebugCommandLine/DebugCommandLinePackage.cs @@ -37,19 +37,25 @@ protected override void Initialize() if (menuCommandService != null) { // This is the drop down combo box itself + /* CommandID comboBoxCommandID = new DebugCommandLineCommandID(DebugCommandLineCommand.DebugCommandLineCombo); OleMenuCommand comboBoxCommand = new OleMenuCommand(HandleInvokeCombo, HandleChangeCombo, HandleBeforeQueryStatusCombo, comboBoxCommandID); - menuCommandService.AddCommand(comboBoxCommand); + menuCommandService.AddCommand(comboBoxCommand);*/ // This is the special command to get the list of drop down items - CommandID comboBoxGetListCommandID = new DebugCommandLineCommandID(DebugCommandLineCommand.DebugCommandLineComboGetList); + /*CommandID comboBoxGetListCommandID = new DebugCommandLineCommandID(DebugCommandLineCommand.DebugCommandLineComboGetList); OleMenuCommand comboBoxGetListCommand = new OleMenuCommand(HandleInvokeComboGetList, comboBoxGetListCommandID); - menuCommandService.AddCommand(comboBoxGetListCommand); + menuCommandService.AddCommand(comboBoxGetListCommand);*/ + + // This MRU combo box contains an editable text-field and a drop down menu which is saved on an application and user basis + CommandID comboBoxCommandID = new DebugCommandLineCommandID(DebugCommandLineCommand.DebugCommandLineCombo); + OleMenuCommand comboBoxCommand = new OleMenuCommand(new EventHandler(HandleOnMRUCombo), comboBoxCommandID); + menuCommandService.AddCommand(comboBoxCommand); } - var shellSettingsManager = new ShellSettingsManager(this); + /*var shellSettingsManager = new ShellSettingsManager(this); SettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); - LoadSettings(); + LoadSettings();*/ } private void LoadSettings() @@ -101,6 +107,64 @@ private void HandleInvokeCombo(object sender, EventArgs e) } } + private string currentMRUComboChoice = null; + + private void HandleOnMRUCombo(object sender, EventArgs e) + { + if (e == EventArgs.Empty) + { + // We should never get here; EventArgs are required. + throw new ArgumentException("EventArgs required."); // force an exception to be thrown + } + + OleMenuCmdEventArgs eventArgs = e as OleMenuCmdEventArgs; + + if (eventArgs != null) + { + object input = eventArgs.InValue; + IntPtr vOut = eventArgs.OutValue; + + if (vOut != IntPtr.Zero && input != null) + { + throw new ArgumentException("BothInOutParamsIllegal"); // force an exception to be thrown + } + else if (vOut != IntPtr.Zero) + { + // when vOut is non-NULL, the IDE is requesting the current value for the combo + string commandArguments = TryGetStartupCommandArguments(); + Marshal.GetNativeVariantForObject(commandArguments, vOut); + } + + else if (input != null) + { + string newChoice = input.ToString(); + + // new value was selected or typed in + if (!string.IsNullOrEmpty(newChoice)) + { + currentMRUComboChoice = newChoice; + SetStartupCommandArguments(newChoice); + + //ShowMessage(Resources.MyMRUCombo, currentMRUComboChoice); + } + else + { + // We should never get here + throw new ArgumentException("EmptyStringIllegal"); // force an exception to be thrown + } + } + else + { + throw new ArgumentException("BothInOutParamsIllegal"); // force an exception to be thrown + } + } + else + { + // We should never get here; EventArgs are required. + throw new ArgumentException("EventArgs required."); // force an exception to be thrown + } + } + private void HandleChangeCombo(object sender, EventArgs e) { }