internal static bool ContainsImmediateWindow(this IEnumerable<IVsTextView> vsTextViews, IVsUIShell shellService, IVsEditorAdaptersFactoryService _editorAdaptersFactoryService)
        {
            IEnumWindowFrames windowEnum = null;
            Marshal.ThrowExceptionForHR(shellService.GetToolWindowEnum(out windowEnum));

            IVsWindowFrame[] frame = new IVsWindowFrame[1];
            uint value;

            var immediateWindowGuid = Guid.Parse(ToolWindowGuids80.ImmediateWindow);

            while (windowEnum.Next(1, frame, out value) == VSConstants.S_OK)
            {
                Guid toolWindowGuid;
                Marshal.ThrowExceptionForHR(frame[0].GetGuidProperty((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, out toolWindowGuid));
                if (toolWindowGuid == immediateWindowGuid)
                {
                    IntPtr frameTextView;
                    Marshal.ThrowExceptionForHR(frame[0].QueryViewInterface(typeof(IVsTextView).GUID, out frameTextView));
                    try
                    {
                        var immediateWindowTextView = Marshal.GetObjectForIUnknown(frameTextView) as IVsTextView;
                        var immediateWindowWpfTextView = _editorAdaptersFactoryService.GetWpfTextView(immediateWindowTextView);
                        return vsTextViews.Any(vsTextView => _editorAdaptersFactoryService.GetWpfTextView(vsTextView) == immediateWindowWpfTextView);
                    }
                    finally
                    {
                        Marshal.Release(frameTextView);
                    }
                }
            }

            return false;
        }
 private ShowSimpleOrmWindowSingleton(
     IVsWindowFrame vsWindowFrame,
     SimpleOrmMappingWindow simpleOrmMappingWindow)
 {
     _vsWindowFrame = vsWindowFrame;
     _simpleOrmMappingWindow = simpleOrmMappingWindow;
 }
 public virtual int OnAfterDocumentWindowHide(
     uint docCookie,
     IVsWindowFrame pFrame
     )
 {
     return VSConstants.S_OK;
 }
Example #4
0
        /// <summary>
        /// Retrieves captions and positions of all active tool windows
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ToolWindowData> GetToolWindowData(IVsUIShell shell) {
            var data = new List<ToolWindowData>();
            try {
                IEnumWindowFrames e;
                shell.GetToolWindowEnum(out e);

                IVsWindowFrame[] frame = new IVsWindowFrame[1];
                uint fetched = 0;
                while (VSConstants.S_OK == e.Next(1, frame, out fetched) && fetched > 0) {
                    object objCaption;
                    frame[0].GetProperty((int)__VSFPROPID.VSFPROPID_Caption, out objCaption);

                    VSSETFRAMEPOS[] pos = new VSSETFRAMEPOS[1];
                    Guid relative;
                    int x, y, cx, cy;
                    frame[0].GetFramePos(pos, out relative, out x, out y, out cx, out cy);

                    var d = new ToolWindowData() {
                        Caption = objCaption as string,
                        X = x,
                        Y = y,
                        Width = cx,
                        Height = cy
                    };

                    data.Add(d);
                }
            } catch (Exception) { }

            return data;
        }
Example #5
0
    public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame frame)
    {
      ThreadHelper.ThrowIfNotOnUIThread();

      if (fFirstShow != 0)
      {
        var windowFrameInfo = new WindowFrameInfo(frame, this);
        _windowFrames.Add(frame, windowFrameInfo);
      }

      //var path = frame.GetFilePath();
      //int isOnScreen;
      //frame.IsOnScreen(out isOnScreen);
      //Debug.WriteLine($"tr: BeforeDocumentWindowShow(docCookie={docCookie}, fFirstShow='{fFirstShow != 0}', isOnScreen={isOnScreen}, path='{path}')");


      //if (_activeFrames.Count == 0 || _activeFrames[0] != frame)
      //{
      //  _activeFrames.Remove(frame);
      //  _activeFrames.Insert(0, frame);
      //}
      //
      // посылаем сообщение активации
      return VSConstants.S_OK;
    }
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            if( VSGestureService.Current.VSGestureInfo.UserSettings.EnableVSGesture == false ) return VSConstants.S_OK;

            var win = VsShellUtilities.GetWindowObject(pFrame);
            if( win == null ) return VSConstants.S_OK;

            var view = VsShellUtilities.GetTextView(pFrame);
            if( view == null ) return VSConstants.S_OK;

            IDesignerHost host = win.Object as IDesignerHost;

            var handler = view.GetWindowHandle();

            var hwnd = handler;
            if (list.ContainsKey(hwnd) == true) return VSConstants.S_OK;

            GestureNativeWindow window = new GestureNativeWindow(hwnd);
            list.Add(hwnd, window);

            if (VSGestureService.Current.VSGestureInfo.UserSettings.EnableVSGestureAlram == true)
            {
                // Welcome 메시지
                VSGesture.Controls.frmWelcome frm = new Umc.Core.Tools.VSGesture.Controls.frmWelcome();
                frm.ShowInTaskbar = false;
                frm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                frm.Show();

                VSGestureService.Current.VSGestureInfo.UserSettings.EnableVSGestureAlram = false;
                VSGestureService.Current.VSGestureInfo = VSGestureService.Current.VSGestureInfo;
            }

            return VSConstants.S_OK;
        }
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            Debug.Assert(editorType == VSConstants.GUID_ProjectDesignerEditor, "Cannot open project designer with guid " + editorType.ToString());

            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return VSConstants.E_FAIL;
            }

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider serviceProvider = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            if (serviceProvider != null && uiShellOpenDocument != null)
            {
                string fullPath = this.GetFullPathForDocument();
                string caption = this.GetOwnerCaption();

                IVsUIHierarchy parentHierarchy = this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchy) as IVsUIHierarchy;

                IntPtr parentHierarchyItemId = (IntPtr)this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid);

                ErrorHandler.ThrowOnFailure(uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, parentHierarchy, (uint)(parentHierarchyItemId.ToInt32()), docDataExisting, serviceProvider, out frame));

                if (frame != null)
                {
                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(frame.Show());
                    }
                }
            }

            return VSConstants.S_OK;
        }
 public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame,
     WindowFrameShowAction windowFrameAction)
 {
     var editorGuid = VSConstants.GUID_ProjectDesignerEditor;
     return OpenWithSpecific(0, ref editorGuid, string.Empty, ref logicalView, docDataExisting, out windowFrame,
         windowFrameAction);
 }
 /// <summary>
 /// Open a file with a specific editor
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
 public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     windowFrame = null;
     bool newFile = false;
     bool openWith = false;
     return this.Open(newFile, openWith, editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
 }
 protected override void OnBeforeDocumentWindowShow(IVsWindowFrame frame, DocumentId id, bool firstShow)
 {
     if (_documentTrackingService != null)
     {
         _documentTrackingService.DocumentFrameShowing(frame, id, firstShow);
     }
 }
Example #11
0
        private static IVsTextView GetVsTextView(IVsWindowFrame windowFrame)
        {
            Validate.IsNotNull(windowFrame, nameof(windowFrame));

            object docView;
            int hresult = windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);

            if (ErrorHandler.Failed(hresult))
            {
                return null;
            }

            IVsTextView viewAdapter = docView as IVsTextView;

            if (viewAdapter != null)
            {
                return viewAdapter;
            }

            IVsCodeWindow codeWindow = docView as IVsCodeWindow;

            if (codeWindow != null)
            {
                IVsTextView codeView;

                if (ErrorHandler.Succeeded(codeWindow.GetPrimaryView(out codeView)) && codeView != null)
                {
                    return codeView;
                }
            }

            return null;
        }
        private void CreateInfoBar(IVsInfoBarUIFactory factory, IVsWindowFrame frame, string message, ErrorReportingUI[] items)
        {
            if (ErrorHandler.Failed(frame.GetProperty((int)__VSFPROPID7.VSFPROPID_InfoBarHost, out var unknown)))
            {
                return;
            }

            var textSpans = new List<IVsInfoBarTextSpan>()
            {
                new InfoBarTextSpan(message)
            };

            // create action item list
            var actionItems = new List<IVsInfoBarActionItem>();

            foreach (var item in items)
            {
                switch (item.Kind)
                {
                    case ErrorReportingUI.UIKind.Button:
                        actionItems.Add(new InfoBarButton(item.Title));
                        break;
                    case ErrorReportingUI.UIKind.HyperLink:
                        actionItems.Add(new InfoBarHyperlink(item.Title));
                        break;
                    case ErrorReportingUI.UIKind.Close:
                        break;
                    default:
                        throw ExceptionUtilities.UnexpectedValue(item.Kind);
                }
            }

            var infoBarModel = new InfoBarModel(
                textSpans,
                actionItems.ToArray(),
                KnownMonikers.StatusInformation,
                isCloseButtonVisible: true);
            if (!TryCreateInfoBarUI(factory, infoBarModel, out var infoBarUI))
            {
                return;
            }

            uint? infoBarCookie = null;
            var eventSink = new InfoBarEvents(items, () =>
            {
                // run given onClose action if there is one.
                items.FirstOrDefault(i => i.Kind == ErrorReportingUI.UIKind.Close).Action?.Invoke();

                if (infoBarCookie.HasValue)
                {
                    infoBarUI.Unadvise(infoBarCookie.Value);
                }
            });
            infoBarUI.Advise(eventSink, out var cookie);
            infoBarCookie = cookie;

            var host = (IVsInfoBarHost)unknown;
            host.AddInfoBar(infoBarUI);
        }
 public virtual int OnBeforeDocumentWindowShow(
     uint docCookie,
     int fFirstShow,
     IVsWindowFrame pFrame
     )
 {
     return VSConstants.S_OK;
 }
 public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
 {
     if (OnBeforeDocumentWindowShowEvent != null)
     {
         OnBeforeDocumentWindowShowEvent(docCookie,fFirstShow,pFrame);
     }
     return VSConstants.S_OK;
 }
Example #15
0
 public LoadFilesIntoRepl(
     ReplWriter writer,
     IProvider<List<string>> filesProvider,
     IVsWindowFrame replToolWindowFrame)
 {
     _writer = writer;
     _filesProvider = filesProvider;
     _replToolWindowFrame = replToolWindowFrame;
 }
Example #16
0
 internal VisualStudioDocument(IVsWindowFrame frame, IVsTextLines buffer, IOleServiceProvider docViewService)
 {
     this.textEditorBuffer = buffer;
     this.currentWindowFrame = frame;
     if (GetSource(docViewService))
     {
         LoadDocument();
     }
 }
        public UDNDocView(string sourceFilePath, IWpfTextView textEditorView, IVsWindowFrame windowFrame, MarkdownPackage package, IVsUIShell uiShell)
        {
            SourceFilePath = sourceFilePath;
            TextEditorView = textEditorView;
            WindowFrame = windowFrame;

            NavigateToComboData = new NavigateToComboData(textEditorView, uiShell);
            ParsingResultsCache = new UDNParsingResultsCache(package, sourceFilePath, textEditorView);
        }
        private ITextView GetTextView(IVsWindowFrame frame)
        {
            if (frame == null)
                return null;

            IVsTextView viewAdapter = VsShellUtilities.GetTextView(frame);
            IWpfTextView wpfTextView = this.VsEditorAdaptorsFactoryService.GetWpfTextView(viewAdapter);
            return wpfTextView;
        }
        int IVsUIShell.FindToolWindow(uint grfFTW, ref Guid rguidPersistenceSlot, out IVsWindowFrame windowFrame)
        {
            windowFrame = null;
            if (this.FindToolWindowAction != null)
            {
                windowFrame = this.FindToolWindowAction(rguidPersistenceSlot);
            }

            return VSConstants.S_OK;
        }
 private IWpfTextView GetWpfTextView(IVsWindowFrame frame) {
     IVsTextView textView = null;
     if (frame != null) {
         try {
             textView = VsShellUtilities.GetTextView(frame);
             // IDE occasionally throws 'not implemented' on close
         } catch (NotImplementedException) { }
     }
     return textView != null ?_editorAdaptersFactory.GetWpfTextView(textView) : null;
 }
        public int Next(uint celt, IVsWindowFrame[] rgelt, out uint pceltFetched) {
            if(_index >= _frames.Count) {
                pceltFetched = 0;
                return VSConstants.S_FALSE;
            }

            rgelt[0] = _frames[_index++];
            pceltFetched = 1;
            return VSConstants.S_OK;
        }
        public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame)
        {
            if (CookieDocumentMap.ContainsKey(docCookie))
            {
                MonitorSelection.SetCmdUIContext(MarkdownModeUIContextCookie, 0);
                CommandsEnabled = false;
            }

            return VSConstants.S_OK;
        }
Example #23
0
        private static bool IsFrameForFilePath(IVsWindowFrame frame, string filePath)
        {
            string frameFilePath;

            if (GetPhysicalPathFromFrame(frame, out frameFilePath))
            {
                return String.Equals(filePath, frameFilePath, StringComparison.OrdinalIgnoreCase);
            }

            return false;
        }
        int IVsUIShell.FindToolWindow(uint grfFTW, ref Guid rguidPersistenceSlot, out IVsWindowFrame ppWindowFrame)
        {
            Assert.AreEqual(this.ExpectedFindToolWindowArgument, (__VSFINDTOOLWIN)grfFTW);

            if (this.toolwindowFrames.TryGetValue(rguidPersistenceSlot, out ppWindowFrame))
            {
                return VSConstants.S_OK;
            }

            return VSConstants.E_FAIL;
        }
Example #25
0
    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates a new instance of the class 
    /// </summary>
    /// <param name="frame"></param>
    // --------------------------------------------------------------------------------------------
    public WindowFrame(IVsWindowFrame frame)
    {
      if (frame == null)
      {
        throw new ArgumentNullException("frame");
      }
      _Frame = frame;

      // --- Set up event handlers
      ErrorHandler.ThrowOnFailure(_Frame.SetProperty((int)__VSFPROPID.VSFPROPID_ViewHelper, this));
    }
        public void OnActiveFrameChanged(IVsWindowFrame oldFrame, IVsWindowFrame newFrame) {
            var wpfTextView = GetWpfTextView(oldFrame);
            if (wpfTextView != null) {
                UpdateTextViewIfRequired(wpfTextView);
            }

            wpfTextView = GetWpfTextView(newFrame);
            if (wpfTextView != null) {
                UpdateTextViewIfRequired(wpfTextView);
            }
        }
Example #27
0
 public int FindToolWindow(uint grfFTW, ref Guid rguidPersistenceSlot, out IVsWindowFrame ppWindowFrame) {
     VsWindowFrameMock mock;
     _frames.TryGetValue(rguidPersistenceSlot, out mock);
     if (mock == null && grfFTW == (uint)__VSFINDTOOLWIN.FTW_fForceCreate) {
         Guid g = Guid.Empty;
         CreateToolWindow(0, 1, null, ref g, ref rguidPersistenceSlot, ref g, null, string.Empty, null, out ppWindowFrame);
     } else {
         ppWindowFrame = mock;
     }
     return ppWindowFrame != null ? VSConstants.S_OK : VSConstants.E_FAIL;
 }
Example #28
0
        public static bool NavigateToFrame(IVsWindowFrame frame, int start, int length) {
            int hr = frame.Show();
            if (ErrorHandler.Succeeded(hr)) {
                IVsTextView vsTextView = VsShellUtilities.GetTextView(frame);
                if (vsTextView != null) {
                    return NavigateToTextView(vsTextView, start, length);
                }
            }

            return false;
        }
        public StartReplUsingProjectVersion(
			ReplFactory replFactory,
			IVsWindowFrame toolWindowFrame,
			Func<string> frameworkProvider,
			IProvider<EnvDTE.Project> selectedProjectProvider)
        {
            _frameworkProvider = frameworkProvider;
            _selectedProjectProvider = selectedProjectProvider;
            _replFactory = replFactory;
            _toolWindowFrame = toolWindowFrame;
        }
        public void OnActiveFrameChanged(IVsWindowFrame oldFrame, IVsWindowFrame newFrame) {
            var interactiveWindow = GetComponent(oldFrame);
            if (interactiveWindow != null) {
                UpdateInteractiveWindowIfRequired(interactiveWindow);
            }

            interactiveWindow = GetComponent(newFrame);
            if (interactiveWindow != null) {
                UpdateInteractiveWindowIfRequired(interactiveWindow);
            }
        }
Example #31
0
 public ReplFactory(TabControl replManager, IVsWindowFrame replToolWindow, IServiceProvider serviceProvider)
 {
     _replManager     = replManager;
     _replToolWindow  = replToolWindow;
     _serviceProvider = serviceProvider;
 }
 public void OnFrameIsVisibleChanged(IVsWindowFrame frame, bool newIsVisible)
 {
 }
Example #33
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            //
            if (_documents.ContainsKey(docCookie))
            {
                return(VSConstants.S_OK);
            }

            // Get the information about this document from the RDT.
            //
            IVsRunningDocumentTable rdt =
                _provider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Note that here we don't want to throw in case of error.
                uint         flags;
                uint         readLocks;
                uint         writeLoks;
                string       documentMoniker;
                IVsHierarchy hierarchy;
                uint         itemId;
                IntPtr       unkDocData;

                int hr = rdt.GetDocumentInfo(
                    docCookie,
                    out flags,
                    out readLocks,
                    out writeLoks,
                    out documentMoniker,
                    out hierarchy,
                    out itemId,
                    out unkDocData);

                try
                {
                    if (ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData))
                    {
                        return(VSConstants.S_OK);
                    }

                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    //
                    if (!_hierarchies.ContainsKey(hierarchy))
                    {
                        // This hierarchy is not monitored, we can exit now.
                        return(VSConstants.S_OK);
                    }

                    // Check the extension of the file to see if a listener is required.
                    //
                    string extension = Path.GetExtension(documentMoniker);

                    if (string.Compare(extension, NemerleConstants.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        return(VSConstants.S_OK);
                    }

                    // Create the module id for this document.
                    //
                    ModuleID docId = new ModuleID(hierarchy, itemId);

                    // Try to get the text buffer.
                    //
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    //
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);

                    // Set the event handler for the change event. Note that there is no
                    // difference between the AddFile and FileChanged operation, so we
                    // can use the same handler.
                    //
                    listener.OnFileChanged += OnFileChanged;

                    // Add the listener to the dictionary, so we will not create it anymore.
                    //
                    _documents.Add(docCookie, listener);
                }
                finally
                {
                    if (IntPtr.Zero != unkDocData)
                    {
                        Marshal.Release(unkDocData);
                    }
                }
            }

            // Always return success.
            //
            return(VSConstants.S_OK);
        }
Example #34
0
        private async Task <IVsWindowFrame> CreateDocWindowForSolutionAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsWindowFrame windowFrame = null;
            var            solution    = await this.GetServiceAsync <IVsSolution>();

            var uiShell = await this.GetServiceAsync <SVsUIShell, IVsUIShell>();

            var windowFlags =
                (uint)_VSRDTFLAGS.RDT_DontAddToMRU |
                (uint)_VSRDTFLAGS.RDT_DontSaveAs;

            // when VSSolutionManager is already initialized, then use the existing APIs to check pre-conditions.
            if (!await SolutionManager.Value.IsSolutionAvailableAsync())
            {
                throw new InvalidOperationException(Resources.SolutionIsNotSaved);
            }

            var projects = (await SolutionManager.Value.GetNuGetProjectsAsync()).ToArray();

            if (projects.Length == 0)
            {
                MessageHelper.ShowWarningMessage(Resources.NoSupportedProjectsInSolution, Resources.ErrorDialogBoxTitle);
                return(null);
            }

            // pass empty array of NuGetProject
            var uiController = UIFactory.Value.Create(projects);

            var solutionName = (string)_dte.Solution.Properties.Item("Name").Value;

            var model = new PackageManagerModel(
                uiController,
                isSolution: true,
                editorFactoryGuid: GuidList.guidNuGetEditorType)
            {
                SolutionName = solutionName
            };

            var vsWindowSearchHostfactory = await GetServiceAsync(typeof(SVsWindowSearchHostFactory)) as IVsWindowSearchHostFactory;

            var vsShell = await GetServiceAsync(typeof(SVsShell)) as IVsShell4;

            var control        = new PackageManagerControl(model, Settings.Value, vsWindowSearchHostfactory, vsShell, OutputConsoleLogger.Value);
            var windowPane     = new PackageManagerWindowPane(control);
            var guidEditorType = GuidList.guidNuGetEditorType;
            var guidCommandUI  = Guid.Empty;
            var caption        = Resx.Label_SolutionNuGetWindowCaption;
            var documentName   = await SolutionManager.Value.GetSolutionFilePathAsync();

            var ppunkDocView = IntPtr.Zero;
            var ppunkDocData = IntPtr.Zero;
            var hr           = 0;

            try
            {
                ppunkDocView = Marshal.GetIUnknownForObject(windowPane);
                ppunkDocData = Marshal.GetIUnknownForObject(model);
                hr           = uiShell.CreateDocumentWindow(
                    windowFlags,
                    documentName,
                    (IVsUIHierarchy)solution,
                    (uint)VSConstants.VSITEMID.Root,
                    ppunkDocView,
                    ppunkDocData,
                    ref guidEditorType,
                    null,
                    ref guidCommandUI,
                    null,
                    caption,
                    string.Empty,
                    null,
                    out windowFrame);

                if (windowFrame != null)
                {
                    WindowFrameHelper.AddF1HelpKeyword(windowFrame, keywordValue: F1KeywordValuePmUI);
                    WindowFrameHelper.DisableWindowAutoReopen(windowFrame);
                }
            }
            finally
            {
                if (ppunkDocView != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocData);
                }

                if (ppunkDocData != IntPtr.Zero)
                {
                    Marshal.Release(ppunkDocView);
                }
            }

            ErrorHandler.ThrowOnFailure(hr);
            return(windowFrame);
        }
 internal VsWindowFrameMonitor(DocumentMonitorService documentMonitorService, IVsWindowFrame vsWindowFrame, IDisposable innerDisp)
 {
     _documentMonitorService = documentMonitorService;
     _vsWindowFrame          = vsWindowFrame;
     _innerDisp = innerDisp;
 }
Example #36
0
 public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame)
 {
     return(VSConstants.S_OK);
 }
Example #37
0
        /// <summary>
        /// Open a file with a specific editor
        /// </summary>
        /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
        /// <param name="editorType">Unique identifier of the editor type</param>
        /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int ReOpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            bool newFile  = false;
            bool openWith = false;

            return(Open(newFile, openWith, editorFlags, ref editorType, physicalView, ref logicalView, docDataExisting, out windowFrame, windowFrameAction, reopen: true));
        }
Example #38
0
        internal static void OpenDocument(IServiceProvider serviceProvider, string filename, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame)
        {
            IVsTextManager textMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            IVsUIHierarchy hierarchy;
            uint           itemid;

            VsShellUtilities.OpenDocument(
                serviceProvider,
                filename,
                Guid.Empty,
                out hierarchy,
                out itemid,
                out pWindowFrame,
                out viewAdapter);
        }
        public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
        {
            frame = null;
            Debug.Assert(editorType == VSConstants.GUID_ProjectDesignerEditor, "Cannot open project designer with guid " + editorType.ToString());


            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return(VSConstants.E_FAIL);
            }

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider    serviceProvider     = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

            if (serviceProvider != null && uiShellOpenDocument != null)
            {
                string fullPath = this.GetFullPathForDocument();
                string caption  = this.GetOwnerCaption();

                IVsUIHierarchy parentHierarchy = this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchy) as IVsUIHierarchy;

                IntPtr parentHierarchyItemId = (IntPtr)this.Node.ProjectMgr.GetProperty((int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid);

                ErrorHandler.ThrowOnFailure(uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, parentHierarchy, (uint)(parentHierarchyItemId.ToInt32()), docDataExisting, serviceProvider, out frame));

                if (frame != null)
                {
                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(frame.Show());
                    }
                }
            }

            return(VSConstants.S_OK);
        }
Example #40
0
        internal static void OpenDocument(IServiceProvider serviceProvider, string filename, Guid docViewGuid, out IVsTextView viewAdapter, out IVsWindowFrame pWindowFrame)
        {
            IVsUIHierarchy hierarchy;
            uint           itemid;

            VsShellUtilities.OpenDocumentWithSpecificEditor(
                serviceProvider,
                filename,
                docViewGuid,
                Guid.Empty,
                out hierarchy,
                out itemid,
                out pWindowFrame
                );
            viewAdapter = VsShellUtilities.GetTextView(pWindowFrame);
        }
 public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
 {
     AttachToDocumentChanges(docCookie, pFrame);
     return(S_OK);
 }
Example #42
0
 int IVsRunningDocTableEvents.OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame) => 0;
Example #43
0
        private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction, bool reopen = false)
        {
            windowFrame = null;
            Debug.Assert(this.Node != null, "No node has been initialized for the document manager");
            Debug.Assert(this.Node.ProjectMgr != null, "No project manager has been initialized for the document manager");
            Debug.Assert(this.Node is FileNode, "Node is not FileNode object");

            if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
            {
                return(VSConstants.E_FAIL);
            }

            int    returnValue = VSConstants.S_OK;
            string caption     = this.GetOwnerCaption();
            string fullPath    = this.GetFullPathForDocument();

            IVsUIShellOpenDocument uiShellOpenDocument = this.Node.ProjectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
            IOleServiceProvider    serviceProvider     = this.Node.ProjectMgr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;

#if DEV11_OR_LATER
            var  openState  = uiShellOpenDocument as IVsUIShellOpenDocument3;
            bool showDialog = !reopen && (openState == null || !((__VSNEWDOCUMENTSTATE)openState.NewDocumentState).HasFlag(__VSNEWDOCUMENTSTATE.NDS_Provisional));
#else
            bool showDialog = !reopen;
#endif

            // Make sure that the file is on disk before we open the editor and display message if not found
            if (!((FileNode)this.Node).IsFileOnDisk(showDialog))
            {
                // Bail since we are not able to open the item
                // Do not return an error code otherwise an internal error message is shown. The scenario for this operation
                // normally is already a reaction to a dialog box telling that the item has been removed.
                return(VSConstants.S_FALSE);
            }

            try {
                this.Node.ProjectMgr.OnOpenItem(fullPath);
                int result = VSConstants.E_FAIL;

                if (openWith)
                {
                    result = uiShellOpenDocument.OpenStandardEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                }
                else
                {
                    __VSOSEFLAGS openFlags = 0;
                    if (newFile)
                    {
                        openFlags |= __VSOSEFLAGS.OSE_OpenAsNewFile;
                    }

                    //NOTE: we MUST pass the IVsProject in pVsUIHierarchy and the itemid
                    // of the node being opened, otherwise the debugger doesn't work.
                    if (editorType != Guid.Empty)
                    {
                        result = uiShellOpenDocument.OpenSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logicalView, caption, this.Node.ProjectMgr.GetOuterInterface <IVsUIHierarchy>(), this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                    else
                    {
                        openFlags |= __VSOSEFLAGS.OSE_ChooseBestStdEditor;
                        result     = uiShellOpenDocument.OpenStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
                    }
                }

                if (result != VSConstants.S_OK && result != VSConstants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return(result);
                }

                if (windowFrame != null)
                {
                    object var;

                    if (newFile)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
                        IVsPersistDocData persistDocData = (IVsPersistDocData)var;
                        ErrorHandler.ThrowOnFailure(persistDocData.SetUntitledDocPath(fullPath));
                    }

                    var = null;
                    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
                    this.Node.DocCookie = (uint)(int)var;

                    if (windowFrameAction == WindowFrameShowAction.Show)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Show());
                    }
                    else if (windowFrameAction == WindowFrameShowAction.ShowNoActivate)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.ShowNoActivate());
                    }
                    else if (windowFrameAction == WindowFrameShowAction.Hide)
                    {
                        ErrorHandler.ThrowOnFailure(windowFrame.Hide());
                    }
                }
            } catch (COMException e) {
                Trace.WriteLine("Exception e:" + e.Message);
                returnValue = e.ErrorCode;
                CloseWindowFrame(ref windowFrame);
            }

            return(returnValue);
        }
Example #44
0
 public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
 {
     return(VSConstants.S_OK);
 }
Example #45
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            if (_documents.ContainsKey(docCookie))
            {
                return(VSConstants.S_OK);
            }
            // Get the information about this document from the RDT.
            IVsRunningDocumentTable rdt = GetPackageService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Note that here we don't want to throw in case of error.
                uint         flags;
                uint         readLocks;
                uint         writeLoks;
                string       documentMoniker;
                IVsHierarchy hierarchy;
                uint         itemId;
                IntPtr       unkDocData;
                int          hr = rdt.GetDocumentInfo(docCookie, out flags, out readLocks, out writeLoks,
                                                      out documentMoniker, out hierarchy, out itemId, out unkDocData);
                try {
                    if (Microsoft.VisualStudio.ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData))
                    {
                        return(VSConstants.S_OK);
                    }
                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    if (!_hierarchies.ContainsKey(hierarchy))
                    {
                        // This hierarchy is not monitored, we can exit now.
                        return(VSConstants.S_OK);
                    }

                    // Check the file to see if a listener is required.
                    if (_package.IsRecognizedFile(documentMoniker))
                    {
                        return(VSConstants.S_OK);
                    }

                    // Create the module id for this document.
                    ModuleId docId = new ModuleId(hierarchy, itemId);

                    // Try to get the text buffer.
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);
                    // Set the event handler for the change event. Note that there is no difference
                    // between the AddFile and FileChanged operation, so we can use the same handler.
                    listener.OnFileChanged += new EventHandler <HierarchyEventArgs>(OnNewFile);
                    // Add the listener to the dictionary, so we will not create it anymore.
                    _documents.Add(docCookie, listener);
                } finally {
                    if (IntPtr.Zero != unkDocData)
                    {
                        Marshal.Release(unkDocData);
                    }
                }
            }
            // Always return success.
            return(VSConstants.S_OK);
        }
Example #46
0
        /// <summary>
        /// Open a file in a document window
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            Guid editorType = Guid.Empty;

            return(this.Open(newFile, openWith, 0, ref editorType, null, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Example #47
0
 int IVsRunningDocTableEvents.OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame) => 0;
 internal EntityDesignFrameWrapper(IVsWindowFrame frame)
     : base(frame)
 {
 }
 public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame vsWindowFrame)
 {
     checkSubscribe(vsWindowFrame);
     return(VSConstants.S_OK);
 }
        /// <summary>
        /// Open a file in a document window
        /// </summary>
        /// <param name="newFile">Open the file as a new file</param>
        /// <param name="openWith">Use a dialog box to determine which editor to use</param>
        /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
        /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
        /// <param name="windowFrame">A reference to the window frame that is mapped to the file</param>
        /// <param name="windowFrameAction">Determine the UI action on the document window</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int Open(bool newFile, bool openWith, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            windowFrame = null;
            Guid editorType = VSConstants.LOGVIEWID_Primary;

            ThreadHelper.ThrowIfNotOnUIThread();
            return(this.Open(newFile, openWith, 0, ref editorType, null, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }
Example #51
0
        public static IVsShellUtilitiesHelper ImplementOpenDocument(string expectedFilePath, Guid expectedEditorType, Guid expectedLogicalView, IVsWindowFrame retFrame)
        {
            var utilities = new Mock <IVsShellUtilitiesHelper>(MockBehavior.Strict);

            utilities.Setup(u => u.OpenDocumentWithSpecificEditorAsync(It.IsAny <IServiceProvider>(), expectedFilePath, expectedEditorType, expectedLogicalView))
            .Returns(Task.FromResult(retFrame));
            return(utilities.Object);
        }
 public void OnFrameCreated(IVsWindowFrame frame)
 {
 }
 public void OnFrameIsOnScreenChanged(IVsWindowFrame frame, bool newIsOnScreen)
 {
 }
Example #54
0
 /// <summary>
 /// Open a document using the standard editor. This method has no implementation since a document is abstract in this context
 /// </summary>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="windowFrame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager class for an implementation of this method</remarks>
 public virtual int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }
 public void OnFrameDestroyed(IVsWindowFrame frame)
 {
 }
Example #56
0
 /// <summary>
 /// Open a document using a specific editor. This method has no implementation.
 /// </summary>
 /// <param name="editorFlags">Specifies actions to take when opening a specific editor. Possible editor flags are defined in the enumeration Microsoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
 /// <param name="editorType">Unique identifier of the editor type</param>
 /// <param name="physicalView">Name of the physical view. If null, the environment calls MapLogicalView on the editor factory to determine the physical view that corresponds to the logical view. In this case, null does not specify the primary view, but rather indicates that you do not know which view corresponds to the logical view</param>
 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, see constants starting with LOGVIEWID_ defined in NativeMethods class</param>
 /// <param name="docDataExisting">IntPtr to the IUnknown interface of the existing document data object</param>
 /// <param name="frame">A reference to the window frame that is mapped to the document</param>
 /// <param name="windowFrameAction">Determine the UI action on the document window</param>
 /// <returns>NotImplementedException</returns>
 /// <remarks>See FileDocumentManager for an implementation of this method</remarks>
 public virtual int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
 {
     throw new NotImplementedException();
 }
Example #57
0
 protected virtual void OnBeforeNonRoslynDocumentWindowShow(IVsWindowFrame frame, bool firstShow)
 {
 }
 bool ISharedService.IsActiveWindowFrame(IVsWindowFrame vsWindowFrame)
 {
     return(false);
 }
Example #59
0
 protected virtual void OnBeforeDocumentWindowShow(IVsWindowFrame frame, DocumentId id, bool firstShow)
 {
 }
        public override int Open(ref Guid logicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
        {
            Guid editorGuid = VSConstants.GUID_ProjectDesignerEditor;

            return(this.OpenWithSpecific(0, ref editorGuid, String.Empty, ref logicalView, docDataExisting, out windowFrame, windowFrameAction));
        }