Esempio n. 1
0
        /// <summary>
        /// Read the comment tokens from the Tools/Options dialog and pass them to the CodeModel assembly
        /// </summary>
        public void SetCommentTokens()
        {
            var commentTokens = _taskList.CommentTokens;
            var tokens        = new List <XCommentToken>();

            foreach (var token in commentTokens)
            {
                var cmttoken = new XCommentToken(token.Text, (int)token.Priority);
                tokens.Add(cmttoken);
            }
            XSolution.SetCommentTokens(tokens);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 7
0
        internal static XFile CreateFileForSystemType(XPETypeSymbol petype, XPESymbol element)
        {
            asmName = petype.Assembly;
            bool mustCreate = false;

            if (Semaphore == null)
            {
                // we create a semaphore file in the workfolder to make sure that if 2 copies of VS are running
                // that we will not delete the files from the other copy
                var tempFolder = Path.GetTempPath();
                tempFolder = Path.Combine(tempFolder, folderName);
                var semFile = Path.Combine(tempFolder, semName);
                // clean up files from previous run
                if (Directory.Exists(tempFolder))
                {
                    if (File.Exists(semFile))
                    {
                        try
                        {
                            File.Delete(semFile);
                            DeleteFolderRecursively(new DirectoryInfo(tempFolder));
                        }
                        catch
                        {
                            // if deletion fails, other copy of VS is running, so do not delete the folder
                        }
                    }
                }
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }
                WorkFolder = tempFolder;
                if (!File.Exists(semFile))
                {
                    Semaphore = File.Create(semFile);
                }
            }
            var ns     = petype.Namespace + "." + petype.Assembly.Version;
            var name   = petype.Name;
            var nspath = Path.Combine(WorkFolder, ns);

            if (!Directory.Exists(nspath))
            {
                Directory.CreateDirectory(nspath);
            }
            var temp = Path.Combine(nspath, petype.Name) + ".prg";

            mustCreate = !File.Exists(temp);
            if (mustCreate)
            {
                VS.StatusBar.ShowMessageAsync("Generating reference source for " + petype.FullName).FireAndForget();
                VS.StatusBar.StartAnimationAsync(StatusAnimation.General).FireAndForget();
                var aLines = XClassCreator.Create(petype, LookupXml);
                File.WriteAllLines(temp, aLines, System.Text.Encoding.UTF8);
                File.SetAttributes(temp, FileAttributes.ReadOnly);
                VS.StatusBar.ClearAsync().FireAndForget();
                VS.StatusBar.EndAnimationAsync(StatusAnimation.General).FireAndForget();
            }
            var xFile = XSolution.AddOrphan(temp);

            return(xFile);
        }