| | |
| | | using Microsoft.VisualStudio.Shell;
|
| | | using Microsoft.VisualStudio.Shell.Interop;
|
| | | using Microsoft.VisualStudio.VCProjectEngine;
|
| | | using QtVsTools.Core;
|
| | | using QtVsTools.VisualStudio;
|
| | |
|
| | | namespace QtVsTools.Editors
|
| | | {
|
| | | using Core;
|
| | | using VisualStudio;
|
| | |
|
| | | using static Core.HelperFunctions;
|
| | |
|
| | | public abstract class Editor : IVsEditorFactory
|
| | |
| | |
|
| | | protected virtual string GetToolsPath()
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | | return GetQtToolsPath() ?? GetDefaultQtToolsPath();
|
| | | }
|
| | |
|
| | |
| | |
|
| | | string GetQtToolsPath()
|
| | | {
|
| | | var project = VsShell.GetProject(Context);
|
| | | if (project == null)
|
| | | return null;
|
| | | return ThreadHelper.JoinableTaskFactory.Run(async () =>
|
| | | {
|
| | | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
|
| | | var project = VsShell.GetProject(Context);
|
| | | if (project == null)
|
| | | return null;
|
| | |
|
| | | var vcProject = project.Object as VCProject;
|
| | | if (vcProject == null)
|
| | | return null;
|
| | | var vcProject = project.Object as VCProject;
|
| | | if (vcProject == null)
|
| | | return null;
|
| | |
|
| | | var vcConfigs = vcProject.Configurations as IVCCollection;
|
| | | if (vcConfigs == null)
|
| | | return null;
|
| | | var vcConfigs = vcProject.Configurations as IVCCollection;
|
| | | if (vcConfigs == null)
|
| | | return null;
|
| | |
|
| | | var activeConfig = project.ConfigurationManager?.ActiveConfiguration;
|
| | | if (activeConfig == null)
|
| | | return null;
|
| | | var activeConfig = project.ConfigurationManager?.ActiveConfiguration;
|
| | | if (activeConfig == null)
|
| | | return null;
|
| | |
|
| | | var activeConfigId = string.Format("{0}|{1}",
|
| | | activeConfig.ConfigurationName, activeConfig.PlatformName);
|
| | | var vcConfig = vcConfigs.Item(activeConfigId) as VCConfiguration;
|
| | | if (vcConfig == null)
|
| | | return null;
|
| | | var activeConfigId = string.Format("{0}|{1}",
|
| | | activeConfig.ConfigurationName, activeConfig.PlatformName);
|
| | | var vcConfig = vcConfigs.Item(activeConfigId) as VCConfiguration;
|
| | | if (vcConfig == null)
|
| | | return null;
|
| | |
|
| | | var qtToolsPath = vcConfig.GetEvaluatedPropertyValue("QtToolsPath");
|
| | | if (string.IsNullOrEmpty(qtToolsPath))
|
| | | return null;
|
| | | var qtToolsPath = vcConfig.GetEvaluatedPropertyValue("QtToolsPath");
|
| | | if (string.IsNullOrEmpty(qtToolsPath))
|
| | | return null;
|
| | |
|
| | | return qtToolsPath;
|
| | | return qtToolsPath;
|
| | | });
|
| | | }
|
| | |
|
| | | string GetDefaultQtToolsPath()
|
| | |
| | | out Guid pguidCmdUI,
|
| | | out int pgrfCDW)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | // Initialize to null
|
| | | ppunkDocView = IntPtr.Zero;
|
| | | ppunkDocData = IntPtr.Zero;
|
| | |
| | | {
|
| | | if (string.IsNullOrEmpty(qtToolsPath))
|
| | | qtToolsPath = GetDefaultQtToolsPath();
|
| | | var st = GetStartInfo(filePath, qtToolsPath, hideWindow);
|
| | | try {
|
| | | return Process.Start(GetStartInfo(filePath, qtToolsPath, hideWindow));
|
| | | } catch (Exception e) {
|
| | | Messages.Print(
|
| | | e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
|
| | | return Process.Start(st);
|
| | | } catch (Exception exception) {
|
| | | exception.Log();
|
| | | if (!File.Exists(st.Arguments))
|
| | | Messages.Print("The system cannot find the file: " + st.Arguments);
|
| | | if (!File.Exists(st.FileName))
|
| | | Messages.Print("The system cannot find the file: " + st.FileName);
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | private class EditorPane : WindowPane, IVsPersistDocData
|
| | | {
|
| | | public Editor Editor { get; private set; }
|
| | | public string QtToolsPath { get; private set; }
|
| | | private Editor Editor { get; }
|
| | | private string QtToolsPath { get; }
|
| | |
|
| | | public TableLayoutPanel EditorContainer { get; private set; }
|
| | | public Label EditorTitle { get; private set; }
|
| | | public LinkLabel EditorDetachButton { get; private set; }
|
| | | public Panel EditorControl { get; private set; }
|
| | | private TableLayoutPanel EditorContainer { get; set; }
|
| | | private Label EditorTitle { get; }
|
| | | private LinkLabel EditorDetachButton { get; }
|
| | | private Panel EditorControl { get; }
|
| | | public override IWin32Window Window => EditorContainer;
|
| | |
|
| | | public Process EditorProcess { get; private set; }
|
| | | public IntPtr EditorWindow { get; private set; }
|
| | | public int EditorWindowStyle { get; private set; }
|
| | | public int EditorWindowStyleExt { get; private set; }
|
| | | public IntPtr EditorIcon { get; private set; }
|
| | | private Process EditorProcess { get; set; }
|
| | | private IntPtr EditorWindow { get; set; }
|
| | | private int EditorWindowStyle { get; set; }
|
| | | private int EditorWindowStyleExt { get; set; }
|
| | | private IntPtr EditorIcon { get; set; }
|
| | |
|
| | | public EditorPane(Editor editor, string qtToolsPath)
|
| | | {
|
| | |
| | |
|
| | | int IVsPersistDocData.LoadDocData(string pszMkDocument)
|
| | | {
|
| | | var solution = GetService(typeof(SVsSolution)) as IVsSolution;
|
| | | EditorProcess = Editor.Start(pszMkDocument, QtToolsPath,
|
| | | hideWindow: !Editor.Detached);
|
| | | if (EditorProcess == null)
|
| | | return VSConstants.E_FAIL;
|
| | |
|
| | | if (Editor.Detached) {
|
| | | Editor.OnStart(EditorProcess);
|
| | | CloseParentFrame();
|
| | |
| | | {
|
| | | EditorProcess = null;
|
| | | EditorWindow = IntPtr.Zero;
|
| | | var parentFrame = GetService(typeof(SVsWindowFrame)) as IVsWindowFrame;
|
| | | parentFrame?.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
|
| | | ThreadHelper.JoinableTaskFactory.Run(async () =>
|
| | | {
|
| | | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
|
| | | var parentFrame = GetService(typeof(SVsWindowFrame)) as IVsWindowFrame;
|
| | | parentFrame?.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
|
| | | });
|
| | | }
|
| | |
|
| | | private void EditorProcess_Exited(object sender, EventArgs e)
|
| | |
| | | EditorWindow = IntPtr.Zero;
|
| | |
|
| | | // Close editor window
|
| | | System.Threading.Tasks.Task.Run(() =>
|
| | | _ = System.Threading.Tasks.Task.Run(() =>
|
| | | {
|
| | | NativeAPI.SendMessage(editorWindow, NativeAPI.WM_CLOSE, 0, 0);
|
| | | if (!editorProcess.WaitForExit(500)) {
|