Esempio n. 1
0
        private static void CreateWindow()
        {
            // http://www.codeproject.com/Articles/35407/Creating-Visual-Studio-Tool-Windows
            var wins = (Windows2)VSApp.Windows;
            var guid = "{87907470-2841-11de-8c30-0800200c9a66}";
            object w = null;
            var asm = Assembly.GetCallingAssembly().Location;
            AddinWindow = wins.CreateToolWindow2(Addin, asm, typeof(WindowUI).FullName, "TfsX Power Source Control", guid, ref w);

            AddinWindow.IsFloating = false;
            AddinWindow.Linkable = true;
        }
Esempio n. 2
0
 public StepState(ReplWindowProxy interactive, PythonVisualStudioApp app, EditorWindow editor, EnvDTE.Window window) {
     Interactive = interactive;
     App = app;
     Editor = editor;
     Window = window;
     Content = new StringBuilder();
 }
Esempio n. 3
0
        public void Capture()
        {
            if (SEViewControl != null && SEViewControl.IsValid)
            {
                return;
            }

            EnvDTE.Window window;
            try
            {
                SolutionExplorer = FindSolutionExplorerFrame();

                window = VsShellUtilities.GetWindowObject(SolutionExplorer);
            }
            catch (COMException)
            {
                // for VS2010 - WPF Shell compatibility (we cannot find the solution explorer frame there)
                return;
            }

            string expCaption = window.Caption;

            IntPtr handle = IntPtr.Zero;

            if (window.HWnd != IntPtr.Zero)
            {
                // We've got the parent
                handle = (IntPtr)window.HWnd;
            }
            else
            {
                EnvDTE.Window hostWindow = window.LinkedWindowFrame;

                if (hostWindow != null)
                {
                    handle = FindSolutionExplorerWnd((IntPtr)hostWindow.HWnd, expCaption);
                }

                if (handle == IntPtr.Zero)
                {
                    hostWindow = window.DTE.MainWindow;

                    if (hostWindow != null)
                    {
                        handle = FindSolutionExplorerWnd((IntPtr)hostWindow.HWnd, expCaption);
                    }
                }

                if (handle == IntPtr.Zero)
                {
                    handle = FindInVBFloatingPalettes(expCaption);
                }
            }

            if (handle == IntPtr.Zero)
            {
                return; // Not found :(
            }
            IntPtr uiHierarchy = NativeTreeView.FindWindowEx(handle, IntPtr.Zero,
                                                             UIHIERARCHY, null);
            IntPtr treeHwnd = NativeTreeView.FindWindowEx(uiHierarchy, IntPtr.Zero, TREEVIEW,
                                                          null);

            if (treeHwnd == IntPtr.Zero)
            {
                return;
            }

            SEViewControl = new NativeTreeView(treeHwnd);

            SetGlyphs();
        }
Esempio n. 4
0
        private async Task <int> Open_File_Async(Mnemonic mnemonic)
        {
            if (!ThreadHelper.CheckAccess())
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            string url = this.Get_Url(mnemonic);

            if (url == null)
            { // this situation happens for all keywords that do not have an url specified (such as registers).
                //AsmDudeToolsStatic.Output_INFO(string.Format("INFO: {0}:openFile; url for keyword \"{1}\" is null.", this.ToString(), keyword));
                return(1);
            }
            //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Open_File; url={1}", this.ToString(), url));

            DTE2 dte2 = Package.GetGlobalService(typeof(SDTE)) as DTE2;

            if (dte2 == null)
            {
                AsmDudeToolsStatic.Output_WARNING(string.Format("{0}:Open_File; dte2 is null.", this.ToString()));
                return(1);
            }

            try
            {
                EnvDTE.Window window = await this.GetWindowAsync(dte2, url);

                if (window == null)
                {
                    // vsNavigateOptionsDefault    0   The Web page opens in the currently open browser window. (Default)
                    // vsNavigateOptionsNewWindow  1   The Web page opens in a new browser window.
                    AsmDudeToolsStatic.Output_INFO(string.Format("{0}:Open_File; going to open url {1}.", this.ToString(), url));
                    window = dte2.ItemOperations.Navigate(url, EnvDTE.vsNavigateOptions.vsNavigateOptionsNewWindow);

                    string[] parts   = url.Split('/');
                    string   caption = parts[parts.Length - 1];
                    caption = caption.Replace('_', '/');

                    window.Caption = caption;

                    Action action = new Action(() =>
                    {
                        try
                        {
                            ThreadHelper.ThrowIfNotOnUIThread();
                            if (!window.Caption.Equals(caption))
                            {
                                window.Caption = caption;
                            }
                        }
                        catch (Exception e)
                        {
                            AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Open_File; exception={1}", this.ToString(), e));
                        }
                    });
                    DelayAction(100, action);
                    DelayAction(500, action);
                    DelayAction(1000, action);
                    DelayAction(1500, action);
                    DelayAction(3000, action);
                }
                else
                {
                    window.Activate();
                }
                return(0);
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Open_File; exception={1}", this.ToString(), e));
                return(2);
            }
        }
        public static bool IsCrmDevExWindow(EnvDTE.Window window)
        {
            string windowGuid = window.ObjectKind.Replace("{", String.Empty).Replace("}", String.Empty);

            return(ExtensionConstants.CrmDevExWindows.Contains(windowGuid));
        }
Esempio n. 6
0
 void WindowEvents_WindowActivated(EnvDTE.Window gotFocus, EnvDTE.Window lostFocus)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     IsActive = gotFocus.Kind == "Tool" && // gotFocus.ObjectKind may throw an InvalidCastException when gotFocus is not a tool window.
                new Guid(gotFocus.ObjectKind) == this.GetType().GUID;
 }
Esempio n. 7
0
        static private void ApplyTasks(Dictionary <string, FormatTask> tasks, bool applyFormatting, FormatterOptionsPage formatSettings)
        {
            var dte = VSUtils.GetDTE();

            foreach (KeyValuePair <string, FormatTask> entry in tasks)
            {
                string        filename   = entry.Key.Replace('/', '\\'); // Classy. But Necessary.
                EnvDTE.Window fileWindow = dte.ItemOperations.OpenFile(filename);
                if (fileWindow == null)
                {
                    Output.Instance.ErrorMsg("Failed to open File {0}", filename);
                    continue;
                }
                fileWindow.Activate();

                var viewHost = VSUtils.GetCurrentTextViewHost();
                using (var edit = viewHost.TextView.TextBuffer.CreateEdit())
                {
                    var originalLines = edit.Snapshot.Lines.ToArray();

                    // Determine which line ending to use by majority.
                    string lineEndingToBeUsed = Utils.GetDominantNewLineSeparator(edit.Snapshot.GetText());

                    // Add lines.
                    {
                        // Find last include.
                        // Will find even if commented out, but we don't care.
                        int lastIncludeLine = -1;
                        for (int line = originalLines.Length - 1; line >= 0; --line)
                        {
                            if (originalLines[line].GetText().Contains("#include"))
                            {
                                lastIncludeLine = line;
                                break;
                            }
                        }

                        // Build replacement string
                        StringBuilder stringToInsertBuilder = new StringBuilder();
                        foreach (string lineToAdd in entry.Value.linesToAdd)
                        {
                            stringToInsertBuilder.Append(lineToAdd);
                            stringToInsertBuilder.Append(lineEndingToBeUsed);
                        }
                        string stringToInsert = stringToInsertBuilder.ToString();


                        // optional, format before adding.
                        if (applyFormatting)
                        {
                            var includeDirectories = VSUtils.GetProjectIncludeDirectories(fileWindow.Document.ProjectItem?.ContainingProject);
                            stringToInsert = Formatter.IncludeFormatter.FormatIncludes(stringToInsert, fileWindow.Document.FullName, includeDirectories, formatSettings);

                            // Add a newline if we removed it.
                            if (formatSettings.RemoveEmptyLines)
                            {
                                stringToInsert += lineEndingToBeUsed;
                            }
                        }

                        // Insert.
                        int insertPosition = 0;
                        if (lastIncludeLine >= 0 && lastIncludeLine < originalLines.Length)
                        {
                            insertPosition = originalLines[lastIncludeLine].EndIncludingLineBreak;
                        }
                        edit.Insert(insertPosition, stringToInsert.ToString());
                    }

                    // Remove lines.
                    // It should safe to do that last since we added includes at the bottom, this way there is no confusion with the text snapshot.
                    {
                        foreach (int lineToRemove in entry.Value.linesToRemove.Reverse())
                        {
                            if (!Formatter.IncludeLineInfo.ContainsPreserveFlag(originalLines[lineToRemove].GetText()))
                            {
                                edit.Delete(originalLines[lineToRemove].ExtentIncludingLineBreak);
                            }
                        }
                    }

                    edit.Apply();
                }

                // For Debugging:
                //Output.Instance.WriteLine("");
                //Output.Instance.WriteLine(entry.Key);
                //Output.Instance.WriteLine(entry.Value.ToString());
            }
        }
Esempio n. 8
0
        private static object GetFrame(Window window)
        {
            var windowImpl = window.GetPrivateFieldValue <object>("_impl");

            return(windowImpl.GetPublicPropertyValue <object>("Frame"));
        }
Esempio n. 9
0
        private void EnsureControl(SolutionExplorerWindow solutionExplorerWindow)
        {
            if (_treeViewControl != null && _treeViewControl.IsValid)
            {
                return;
            }

            EnvDTE.Window window;
            try
            {
                window = VsShellUtilities.GetWindowObject(solutionExplorerWindow.SolutionExplorerFrame);
            }
            catch (COMException)
            {
                return;
            }

            string expCaption = window.Caption;

            IntPtr handle = IntPtr.Zero;

            if (window.HWnd != 0)
            {
                // We've got the parent
                handle = (IntPtr)window.HWnd;
            }
            else
            {
                EnvDTE.Window hostWindow = window.LinkedWindowFrame;

                if (hostWindow != null)
                {
                    handle = SearchForSolutionExplorer((IntPtr)hostWindow.HWnd, expCaption);
                }

                if (handle == IntPtr.Zero)
                {
                    hostWindow = window.DTE.MainWindow;

                    if (hostWindow != null)
                    {
                        handle = SearchForSolutionExplorer((IntPtr)hostWindow.HWnd, expCaption);
                    }
                }

                if (handle == IntPtr.Zero)
                {
                    handle = SearchFloatingPalettes(expCaption);
                }
            }

            if (handle == IntPtr.Zero)
            {
                return; // Not found :(
            }
            IntPtr uiHierarchy = NativeMethods.FindWindowEx(handle, IntPtr.Zero,
                                                            UIHIERARCHY, null);
            IntPtr treeHwnd = NativeMethods.FindWindowEx(uiHierarchy, IntPtr.Zero, TREEVIEW,
                                                         null);

            if (treeHwnd == IntPtr.Zero)
            {
                return;
            }

            this._treeViewControl = new Win32TreeView(treeHwnd);
        }
Esempio n. 10
0
 public StepState(ReplWindowProxy interactive, PythonVisualStudioApp app, EditorWindow editor, EnvDTE.Window window)
 {
     Interactive = interactive;
     App         = app;
     Editor      = editor;
     Window      = window;
     Content     = new StringBuilder();
 }
 void WindowEvents_WindowActivated(EnvDTE.Window GotFocus, EnvDTE.Window LostFocus)
 {
     CommandVisible = (GotFocus != null && GotFocus.Kind == "Document");
 }
 /// <summary>
 /// Remove the matching classifier from the document list
 /// </summary>
 private static void OnWindowClosing(EnvDTE.Window Window)
 {
     ScanActiveClassifierWindows();
 }
Esempio n. 13
0
        /// <summary>
        /// Get the errors in the Error list window
        /// Picks up errors with "The name 'ABCPercentA' does not denote a class, a table, or an extended data type"
        /// as this denotes that there is a missing module reference
        /// </summary>
        /// <returns>True is a reference was added</returns>
        public bool CheckErrorsAndAddReference()
        {
            // Most of the code comes from this stackoverflow conversation
            // https://stackoverflow.com/questions/36834038/visual-studio-2015-envdte-read-errorlist

            bool moduleReferenceAdded = false;

            // get the list of errors from the Error list wondow
            EnvDTE.Window      window = Common.CommonUtil.DTE.Windows.Item(vsWindowKindErrorList);
            EnvDTE80.ErrorList sel    = (EnvDTE80.ErrorList)window.Selection;
            var errorItemsDte         = sel.ErrorItems;

            for (int i = 1; i <= errorItemsDte.Count; i++)
            {
                var errorItem = errorItemsDte.Item(i);
                if (errorItem.ErrorLevel == EnvDTE80.vsBuildErrorLevel.vsBuildErrorLevelHigh &&
                    errorItem.Description.Contains("does not denote a class, a table, or an extended data type"))
                // The name 'ABCPercentA' does not denote a class, a table, or an extended data type
                {
                    //System.Windows.Forms.MessageBox.Show($"Error found: {errorItem.ErrorLevel}; {errorItem.Description}");

                    //now find the element - check if it is an EDT, Table, Class
                    string elementName           = this.GetElementNameFromError(errorItem.Description);
                    var    moduleNameToReference = this.GetModuleFromElement(elementName);
                    if (String.IsNullOrEmpty(moduleNameToReference))
                    {
                        throw new Exception($"No matching element found for {elementName} in EDT's, tables, classes");
                    }
                    // Then find the model

                    // then add the model to the current models reference
                    var currentModel = Common.CommonUtil.GetCurrentModel();
                    // Update the module references
                    if (currentModel.Readonly || currentModel.ModuleReferences.IsReadOnly)
                    {
                        //you cant add to the list as it is read only.
                        // So copy the list into a new one, add the module & updated the model with this list as moduleReference
                        List <string> modules = new List <string>(currentModel.ModuleReferences);
                        if (modules.Contains(moduleNameToReference) == false)
                        {
                            modules.Add(moduleNameToReference);
                            currentModel.ModuleReferences = modules;

                            Common.CommonUtil.GetModelSaveService().UpdateModel(currentModel);
                            this.ReferencesAdded.Add(moduleNameToReference);
                            moduleReferenceAdded = true;
                        }
                        else
                        {
                            // Something else is going on,so break;
                            // User has to manually refresh models and build
                            break;
                        }
                    }
                    //else
                    //{
                    //    // Dont think this will ever go here
                    //    currentModel.ModuleReferences.Add(moduleNameToReference); // this cannot be updated as it is readonly
                    //}

                    // break; // there is usually only one error list this at a time
                }
            }

            return(moduleReferenceAdded);
        }
Esempio n. 14
0
        protected override async Task InitializeAsync
        (
            CancellationToken Token,
            IProgress <ServiceProgressData> Progress
        )
        {
            await base.InitializeAsync(Token, Progress);

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Token);

            #region Events
            #region RunningDocumentTable

            var Table = new RunningDocumentTable(this);
            Table.Advise(new RunningDocTableEvents());

            #endregion
            #region EnvDTE.Events

            var DTE = await Utils.GetDTEAsync();

            Events = DTE.Events;

            DocumentEvents = Events.DocumentEvents;
            DocumentEvents.DocumentClosing += Document =>
            {
                _ = Task.Run(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    if (Document.Language != "C/C++")
                    {
                        return;
                    }

                    await TaskScheduler.Default;
                    await File.Structure.Events.OnBeforeDocumentCloseAsync();
                }, Token);
            };

            WindowEvents = Events.WindowEvents;
            WindowEvents.WindowActivated += (GotFocus, LostFocus) =>
            {
                if (GotFocus == LastWindowThatGotFocus)
                {
                    return;
                }
                _ = Task.Run(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    if (GotFocus.Document == null)
                    {
                        return;
                    }
                    if (GotFocus.Document.Language != "C/C++")
                    {
                        return;
                    }

                    await TaskScheduler.Default;
                    LastWindowThatGotFocus = GotFocus;
                    await File.Structure.Events.OnAfterWindowActivateAsync();
                }, Token);
            };

            #endregion

            await WindowCommand.InitializeAsync(this);

            #endregion
        }
Esempio n. 15
0
 public void ReleaseActivation(EnvDTE.Window window)
 => ReleaseActivation(controllersMapping[window]);
Esempio n. 16
0
 public void RequestActivation(EnvDTE.Window window, string moniker)
 => RequestActivation(controllersMapping[window], moniker);