/// <summary> /// Shows the tool window when the menu item is clicked. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> private void ShowToolWindow(object sender, EventArgs e) { try { if (ProductEnvironment.Instance.CheckConEmuAndDisplay() == false) { return; } ToolWindowPane window = this.package.FindToolWindow(typeof(ConEmuWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public void OpenConEmuToolWindow() { if (this.Package == null || this.Package.Zombied) { return; } try { if (CheckConEmuAndDisplay() == false) { return; } ToolWindowPane window = this.Package.FindToolWindow(typeof(ConEmuWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } ThreadHelper.ThrowIfNotOnUIThread(); IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
private void ExecuteLegacy(string asWhere, string asMacro) { try { if (m_ConEmuHandle == IntPtr.Zero) { return; } string cmdLine = " -GuiMacro"; if (string.IsNullOrEmpty(asWhere) == false) { cmdLine += ":" + asWhere; } else { cmdLine += " " + asMacro; } Environment.SetEnvironmentVariable("ConEmuMacroResult", null); m_fnConsoleMain3.Invoke(3, cmdLine); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public bool RunConEmu() { try { if (ProductEnvironment.Instance.CheckConEmuAndDisplay() == false) { return(false); } string conemu = ProductEnvironment.Instance.GetConEmuExecutable(); string configFile = ProductEnvironment.Instance.GetConfigurationFile(); string parameter = "-NoKeyHooks " + "-InsideWnd 0x" + plnConEmu.Handle.ToString("X") + " " + "-LoadCfgFile \"" + configFile + "\" " + "-Dir \"" + Directory.GetCurrentDirectory() + "\" " + "-detached -cmd \"{cmd}\""; ProductEnvironment.Instance.ConEmuProcess = Process.Start(conemu, parameter); var macro = "Shell(\"new_console\", \"\", \"{cmd}\")"; ExecuteGuiMacro(macro); return(true); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } return(false); }
private void LoadConEmuDll(string asLibrary) { try { if (m_ConEmuHandle != IntPtr.Zero) { return; } m_ConEmuHandle = LoadLibrary(asLibrary); if (m_ConEmuHandle == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while load the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); return; } const string fnNameOld = "ConsoleMain3"; IntPtr ptrConsoleMain = GetProcAddress(m_ConEmuHandle, fnNameOld); const string fnNameNew = "GuiMacro"; IntPtr ptrGuiMacro = GetProcAddress(m_ConEmuHandle, fnNameNew); if (ptrConsoleMain == IntPtr.Zero && ptrGuiMacro == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while getting the addresses of the methods in the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Methods: ConsoleMain3, GuiMacro" + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); UnloadConEmuDll(); return; } m_fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer(ptrGuiMacro, typeof(FGuiMacro)); m_fnConsoleMain3 = (FConsoleMain3)Marshal.GetDelegateForFunctionPointer(ptrConsoleMain, typeof(FConsoleMain3)); } catch (Exception error) { UnloadConEmuDll(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public bool CheckConEmuAndDisplay() { bool result = CheckConEmu(); if (result == false) { var conemu = GetConEmuExecutable(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to find the ConEmu installation", "Please set the paths of your ConEmu installation in the Visual Studio options pane" + Environment.NewLine + Environment.NewLine + "ConEmu Path: " + conemu + Environment.NewLine); box.ShowDialog(); } return(result); }
private void MenuItemCallback(object sender, EventArgs e) { try { var window = (FastFileAccessWindow)this.package.FindToolWindow(typeof(FastFileAccessWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public void Execute(string asWhere, string asMacro) { try { if (m_ConEmuHandle == IntPtr.Zero) { return; } new Thread(() => { Thread.CurrentThread.IsBackground = true; ExecuteHelper(asWhere, asMacro); }).Start(); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public void OpenConEmuToolWindow() { if (this.Package == null || this.Package.Zombied) { return; } try { if (CheckConEmuAndDisplay() == false) { return; } var window = this.Package.FindToolWindow(typeof(ConEmuWindow), 0, true) as ConEmuWindow; if (window?.Frame == null) { throw new NotSupportedException("Cannot create tool window"); } ThreadHelper.ThrowIfNotOnUIThread(); IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; ErrorHandler.ThrowOnFailure(windowFrame.Show()); if (IsConEmuToolWindowVisible(windowFrame) == false) { window.RunConEmu(); } } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public bool RunConEmu() { ThreadHelper.ThrowIfNotOnUIThread(); try { if (ProductEnvironment.Instance.ConEmu == null || m_HasExited) { RunConEmuSession(); } else { DisableMaxMinCloseButtons(); } return(true); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } return(false); }
private void ExecuteHelper(string asWhere, string asMacro) { try { if (m_fnGuiMacro != null) { IntPtr bstrPtr = IntPtr.Zero; int result = m_fnGuiMacro.Invoke(asWhere, asMacro, out bstrPtr); if (result != 133 /*CERR_GUIMACRO_SUCCEEDED*/ || result != 134 /*CERR_GUIMACRO_FAILED*/) { return; // Sucess } ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Invoke GuiMacro method failed", "Failure while invoke the GuiMacro of the conemu library" + Environment.NewLine + "Result code: " + result); box.ShowDialog(); if (bstrPtr != IntPtr.Zero) { Marshal.FreeBSTR(bstrPtr); } } else { ExecuteLegacy(asWhere, asMacro); } } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }