internal static bool IsXSharpDocument(this ITextDocumentFactoryService factory, ITextBuffer buffer) { string path = ""; if (buffer.Properties.ContainsProperty(typeof(XFile))) { return(buffer.GetFile() != null); } // When not found then locate the file in the XSolution by its name if (factory != null) { ITextDocument doc = null; if (factory.TryGetTextDocument(buffer, out doc)) { path = doc.FilePath; } } // Find and attach the X# document when we have it, or a null to indicate that we have searched // and not found it var file = XSolution.FindFile(path); if (file != null) { buffer.Properties.AddProperty(typeof(XFile), file); } return(file != null); }
private void DocumentEvents_Closed(string document) { // Remove document from OrphanedFilesProject // So it can be opened in normal project afterwards // when possible XSolution.WriteOutputMessage("DocumentEvents_Closed " + document ?? "(none)"); var xfile = XSolution.FindFile(document); if (xfile != null && xfile.Project.Name == OrphanedFilesProject.OrphanName) { XSolution.OrphanedFilesProject.RemoveFile(document); } }
protected override void GotoSource(VSOBJGOTOSRCTYPE gotoType) { // We do not support the "Goto Reference" if (gotoType == VSOBJGOTOSRCTYPE.GS_REFERENCE) { return; } // if (this.CanGoToSource && this.editorInfo != null) { // Need to retrieve the Project, then the File... var file = XSolution.FindFile(editorInfo.FileName); XSettings.OpenDocument(file.FullPath, editorInfo.Line, editorInfo.Column, true); } }
internal static bool IsXSharpDocument(this ITextDocumentFactoryService factory, ITextBuffer buffer) { string path = ""; if (buffer.Properties.ContainsProperty(typeof(XFile))) { return(buffer.GetFile() != null); } // When not found then locate the file in the XSolution by its name if (factory != null) { ITextDocument doc = null; if (factory.TryGetTextDocument(buffer, out doc)) { path = doc.FilePath; } } // Find and attach the X# document when we have it, or a null to indicate that we have searched // and not found it var file = XSolution.FindFile(path); if (file == null) { var type = XFileTypeHelpers.GetFileType(path); switch (type) { case XFileType.SourceCode: case XFileType.Header: file = XSolution.AddOrphan(path); break; default: if (type.IsVOBinary()) { file = XSolution.AddOrphan(path); } break; } } if (file != null) { file.Interactive = true; buffer.Properties.AddProperty(typeof(XFile), file); } return(file != null); }
public int OnAfterSave(uint docCookie) { if (!XSolution.IsClosing) { string fileName = getFileNameFromCookie(docCookie); var xFile = XSolution.FindFile(fileName); if (xFile != null && xFile.HasCode) { xFile.Interactive = true; // this will update the Model in the DataBase xFile.Project.WalkFile(xFile); // Now, check if we need to update the ClassView tree xFile.Project.FileWalkComplete(xFile); } } return(VSConstants.S_OK); }
protected override void GotoSource(VSOBJGOTOSRCTYPE gotoType) { // We do not support the "Goto Reference" if (gotoType == VSOBJGOTOSRCTYPE.GS_REFERENCE) { return; } // if (this.CanGoToSource && this.editorInfo != null) { // Need to retrieve the Project, then the File... //this.member.OpenEditor(); var file = XSolution.FindFile(editorInfo.FileName); var project = file.Project; var node = project.ProjectNode; node.OpenElement(file.FullPath, editorInfo.Line, editorInfo.Column); } }
public static XFile GetFile(this ITextBuffer buffer) { XFile file; if (buffer == null) { return(null); } if (buffer.Properties.TryGetProperty(typeof(XFile), out file)) { return(file); } var fileName = buffer.GetFileName(); file = XSolution.FindFile(fileName); if (file != null) { buffer.Properties.AddProperty(typeof(XFile), file); } return(file); }
public void VsTextViewCreated(IVsTextView textViewAdapter) { IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); IVsTextBuffer textBuffer = EditorAdaptersFactoryService.GetBufferAdapter(textView.TextBuffer); textView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument document); textViewAdapter.GetBuffer(out var textlines); if (textlines != null) { XFile file = null; string fileName = FilePathUtilities.GetFilePath(textlines); textlines.GetLanguageServiceID(out var langId); // Note that this may get called after the classifier has been instantiated if (langId == GuidStrings.guidLanguageService) // is our language service active ? { // Get XFile and assign it to the TextBuffer if (!textView.TextBuffer.Properties.TryGetProperty(typeof(XFile), out file)) { file = XSolution.FindFile(fileName); if (file == null) { XSolution.OrphanedFilesProject.AddFile(fileName); file = XSolution.FindFile(fileName); } if (file != null) { textView.TextBuffer.Properties.AddProperty(typeof(XFile), file); } } if (file != null) { file.Interactive = true; textView.Properties.AddProperty(typeof(XFile), file); } var filter = new XSharpEditorCommandHandler(textView); IOleCommandTarget next; textViewAdapter.AddCommandFilter(filter, out next); filter.Next = next; } // For VS 2017 we look for Microsoft.VisualStudio.Editor.Implementation.VsCodeWindowAdapter // For VS 2019 we look for Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow // Both implement IVsDropdownbarManager IVsDropdownBarManager dropDownBarManager = null; if (dropDownBarKey != null && textView.Properties.ContainsProperty(dropDownBarKey)) { object window = textView.Properties.GetProperty(dropDownBarKey); dropDownBarManager = window as IVsDropdownBarManager; } if (dropDownBarManager == null) { // look at all the properties to find the one that implements IVsDropdownBarManager foreach (var property in textView.Properties.PropertyList) { if (property.Value is IVsDropdownBarManager manager) { dropDownBarKey = property.Key; // remember key for next iteration dropDownBarManager = manager; break; } } } // The same file may be open in multiple textViews // these will share the same dropdown if (_dropDowns.ContainsKey(fileName)) { dropdown = _dropDowns[fileName]; dropdown.addTextView(textView); } else if (dropDownBarManager != null) { dropdown = new XSharpDropDownClient(dropDownBarManager, file); dropDownBarManager.RemoveDropdownBar(); dropDownBarManager.AddDropdownBar(2, dropdown); _dropDowns.Add(fileName, dropdown); dropdown.addTextView(textView); } if (!_textViews.ContainsKey(fileName)) { _textViews.Add(fileName, new List <IWpfTextView>()); } _textViews[fileName].Add(textView); textView.Closed += TextView_Closed; } }