Ejemplo n.º 1
0
        public void VsTextViewCreated(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                throw new ArgumentNullException(nameof(vsTextView));
            }

            if (ErrorHandler.Failed(vsTextView.GetBuffer(out var textLines)))
            {
                return;
            }

            IVsUserData userData = textLines as IVsUserData;

            if (userData == null)
            {
                return;
            }

            Guid monikerGuid = typeof(IVsUserData).GUID;

            if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out var monikerObj)))
            {
                return;
            }

            string filePath = monikerObj as string;

            _rdt.Value.FindDocument(filePath, out var hierarchy, out var itemId, out var docCookie);

            AbstractProject project = GetXamlProject(hierarchy);

            if (project == null)
            {
                project = new XamlProject(
                    _vsWorkspace.GetProjectTrackerAndInitializeIfNecessary(_serviceProvider),
                    hierarchy,
                    _serviceProvider,
                    _vsWorkspace);
            }

            IVisualStudioHostDocument vsDocument = project.GetCurrentDocumentFromPath(filePath);

            if (vsDocument == null)
            {
                if (!TryCreateXamlDocument(project, filePath, out vsDocument))
                {
                    return;
                }

                project.AddDocument(vsDocument, isCurrentContext: true, hookupHandlers: true);
            }

            AttachRunningDocTableEvents();

            var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView);
            var target      = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);

            target.AttachToVsTextView();
        }
Ejemplo n.º 2
0
 public XamlProject(VisualStudioProjectTracker projectTracker, IVsHierarchy hierarchy, IServiceProvider serviceProvider, VisualStudioWorkspaceImpl visualStudioWorkspace) :
     base(
         projectTracker,
         reportExternalErrorCreatorOpt: null,
         projectSystemName: $"{XamlProject.GetProjectName(hierarchy)}-{nameof(XamlProject)}",
         hierarchy: hierarchy,
         language: StringConstants.XamlLanguageName,
         serviceProvider: serviceProvider,
         visualStudioWorkspaceOpt: visualStudioWorkspace,
         hostDiagnosticUpdateSourceOpt: null)
 {
     projectTracker.AddProject(this);
 }
Ejemplo n.º 3
0
 public XamlProject(IVsHierarchy hierarchy, IServiceProvider serviceProvider, VisualStudioWorkspaceImpl visualStudioWorkspace) :
     base(
         visualStudioWorkspace.ProjectTracker,
         reportExternalErrorCreatorOpt: null,
         projectSystemName: $"{XamlProject.GetProjectName(hierarchy)}|{nameof(XamlProject)}",
         hierarchy: hierarchy,
         language: StringConstants.XamlLanguageName,
         serviceProvider: serviceProvider,
         visualStudioWorkspaceOpt: visualStudioWorkspace,
         hostDiagnosticUpdateSourceOpt: null)
 {
     // We initialized ProjectSystemName to include nameof(XamlProject).
     // Update DisplayName to just the project name.
     DisplayName = XamlProject.GetProjectName(hierarchy);
 }
        public void VsTextViewCreated(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                throw new ArgumentNullException(nameof(vsTextView));
            }

            IVsTextLines textLines;
            if (ErrorHandler.Failed(vsTextView.GetBuffer(out textLines)))
            {
                return;
            }

            IVsUserData userData = textLines as IVsUserData;
            if (userData == null)
            {
                return;
            }

            object monikerObj;
            Guid monikerGuid = typeof(IVsUserData).GUID;
            if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out monikerObj)))
            {
                return;
            }

            string filePath = monikerObj as string;
            uint itemId;
            uint docCookie;
            IVsHierarchy hierarchy;

            _rdt.Value.FindDocument(filePath, out hierarchy, out itemId, out docCookie);

            AbstractProject project = GetXamlProject(hierarchy);
            if (project == null)
            {
                project = new XamlProject(_vsWorkspace.ProjectTracker, hierarchy, _serviceProvider, _vsWorkspace);
            }

            IVisualStudioHostDocument vsDocument = project.GetCurrentDocumentFromPath(filePath);
            if (vsDocument == null)
            {
                if (!TryCreateXamlDocument(project, filePath, out vsDocument))
                {
                    return;
                }

                project.AddDocument(vsDocument, isCurrentContext: true, hookupHandlers: true);
            }

            AttachRunningDocTableEvents();

            var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView);
            var target = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);
            target.AttachToVsTextView();
        }