Exemplo n.º 1
0
        public void TextViewCreated(IWpfTextView textView)
        {
            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            var textViewAdapter = EditorAdaptersFactoryService.GetViewAdapter(textView);

            if (textViewAdapter == null)
            {
                return;
            }

            if (BuilderInfo.Supports(document.FilePath))
            {
                // add commands to view form or code
                //textView.Properties.AddProperty(ViewFormKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewForm, () => ViewDesigner(document)));
                //textView.Properties.AddProperty(ViewCodeKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewCode, () => ViewCode(document)));
            }
            else if (BuilderInfo.IsCodeBehind(document.FilePath))
            {
                textView.Properties.AddProperty(ViewFormKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewForm, () => ViewDesigner(document)));
            }
        }
Exemplo n.º 2
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(context.Snapshot.TextBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName) || !fileName.Equals(Constants.FILENAME, StringComparison.OrdinalIgnoreCase))
                {
                    yield break;
                }
            }
            else
            {
                yield break;
            }

            JSONMember member = context.ContextItem.Parent?.FindType <JSONMember>();

            if (member == null || member.UnquotedNameText != Constants.ELEMENT_NAME)
            {
                yield break;
            }

            yield return(new SimpleCompletionEntry("AfterBuild", "Fires after the MSBuild process ended.", _glyph, context.Session));

            yield return(new SimpleCompletionEntry("BeforeBuild", "Fires before the MSBuild process ended.", _glyph, context.Session));

            yield return(new SimpleCompletionEntry("Clean", "Fires after the MSBuild 'Clean' process ended.", _glyph, context.Session));

            yield return(new SimpleCompletionEntry("ProjectOpen", "Fires when the project is opened in Visual Studio.", _glyph, context.Session));
        }
Exemplo n.º 3
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(context.Snapshot.TextBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName) || !fileName.Equals(Constants.FILENAME, StringComparison.OrdinalIgnoreCase))
                {
                    yield break;
                }
            }
            else
            {
                yield break;
            }

            JSONMember member = context.ContextItem.FindType <JSONMember>();

            while (member != null && member.Parent != null && member.UnquotedNameText != Constants.ELEMENT_NAME)
            {
                member = member.Parent.FindType <JSONMember>();
            }

            if (member == null || member.UnquotedNameText != Constants.ELEMENT_NAME)
            {
                yield break;
            }

            foreach (var task in GetTasks(context.ContextItem.JSONDocument))
            {
                yield return(new SimpleCompletionEntry(task.Item1, task.Item2, StandardGlyphGroup.GlyphGroupEvent, context.Session));
            }
        }
Exemplo n.º 4
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = GetInitializedTextView(textViewAdapter);

            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            var saveListeners = Mef.GetAllImports <IFileSaveListener>(document.TextBuffer.ContentType);

            if (saveListeners.Count == 0)
            {
                return;
            }

            EventHandler <TextDocumentFileActionEventArgs> saveHandler = (s, e) =>
            {
                if (e.FileActionType != FileActionTypes.ContentSavedToDisk)
                {
                    return;
                }

                foreach (var listener in saveListeners)
                {
                    listener.FileSaved(document.TextBuffer.ContentType, e.FilePath, false, false);
                }
            };

            document.FileActionOccurred += saveHandler;
            textView.Closed             += delegate { document.FileActionOccurred -= saveHandler; };
        }
Exemplo n.º 5
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            if (_hasRun || _isProcessing)
            {
                return;
            }

            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            ITextDocument doc;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out doc))
            {
                if (Path.IsPathRooted(doc.FilePath) && File.Exists(doc.FilePath))
                {
                    _isProcessing = true;
                    var dte  = (DTE2)Package.GetGlobalService(typeof(DTE));
                    var item = dte.Solution?.FindProjectItem(doc.FilePath);

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        EnsureInitialized(item);
                        _hasRun = _isProcessing = false;
                    });
                }
            }
        }
        protected override void ReParseImpl()
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                ITextSnapshot snapshot = TextBuffer.CurrentSnapshot;
                ITextDocument textDocument;
                if (!TextDocumentFactoryService.TryGetTextDocument(DocumentBuffer, out textDocument))
                {
                    textDocument = null;
                }

                IEnumerable <HunkRangeInfo> diff;
                if (textDocument != null)
                {
                    diff = _commands.GetGitDiffFor(textDocument, snapshot);
                }
                else
                {
                    diff = Enumerable.Empty <HunkRangeInfo>();
                }

                DiffParseResultEventArgs result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
                OnParseComplete(result);
            }
            catch (InvalidOperationException)
            {
                base.MarkDirty(true);
                throw;
            }
        }
Exemplo n.º 7
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(context.Snapshot.TextBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName) || !_files.Contains(fileName))
                {
                    yield break;
                }
            }
            else
            {
                yield break;
            }

            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.UnquotedNameText != "license")
            {
                yield break;
            }

            foreach (string prop in _props)
            {
                yield return(new SimpleCompletionEntry(prop, context.Session));
            }
        }
Exemplo n.º 8
0
        public void TextViewCreated(IWpfTextView textView)
        {
            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                return;
            }

            var textViewAdapter = EditorAdaptersFactoryService.GetViewAdapter(textView);

            if (textViewAdapter == null)
            {
                return;
            }

            var info = BuilderInfo.Find(document.FilePath);

            if (info != null)
            {
                // add commands to view form or code
                //textView.Properties.AddProperty(ViewFormKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewForm, () => ViewDesigner(document)));
                //textView.Properties.AddProperty(ViewCodeKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewCode, () => ViewCode(document)));
                if (string.Equals(info.Extension, ".xeto", StringComparison.OrdinalIgnoreCase))
                {
                    textView.Properties.GetOrCreateSingletonProperty(() => new XamlCompletionHandler(textViewAdapter, textView, this));
                }
            }
            else if (BuilderInfo.IsCodeBehind(document.FilePath))
            {
                textView.Properties.AddProperty(ViewFormKey, new AdapterCommand(textViewAdapter, ServiceProvider, VSConstants.GUID_VSStandardCommandSet97, (uint)VSConstants.VSStd97CmdID.ViewForm, () => ViewDesigner(document)));
            }
        }
Exemplo n.º 9
0
        internal DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, string originalPath, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            _documentBuffer = documentBuffer;
            _commands       = commands;
            ReparseDelay    = TimeSpan.FromMilliseconds(500);

            if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
            {
                _originalPath = originalPath;
                if (_commands.IsGitRepository(_textDocument.FilePath, _originalPath))
                {
                    _textDocument.FileActionOccurred += OnFileActionOccurred;

                    var repositoryDirectory = _commands.GetGitRepository(_textDocument.FilePath, _originalPath);
                    if (repositoryDirectory != null)
                    {
                        _watcher                     = new FileSystemWatcher(repositoryDirectory);
                        _watcher.Changed            += HandleFileSystemChanged;
                        _watcher.Created            += HandleFileSystemChanged;
                        _watcher.Deleted            += HandleFileSystemChanged;
                        _watcher.Renamed            += HandleFileSystemChanged;
                        _watcher.EnableRaisingEvents = true;
                    }
                }
            }
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);

            textView.Properties.GetOrCreateSingletonProperty(() => new MinifySelection(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new JavaScriptFindReferences(textViewAdapter, textView, Navigator));
            textView.Properties.GetOrCreateSingletonProperty(() => new CssExtractToFile(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new NodeModuleGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new ReferenceTagGoToDefinition(textViewAdapter, textView));
            textView.Properties.GetOrCreateSingletonProperty(() => new CommentCompletionCommandTarget(textViewAdapter, textView, AggregatorService));
            textView.Properties.GetOrCreateSingletonProperty(() => new CommentIndentationCommandTarget(textViewAdapter, textView, AggregatorService, CompletionBroker));

            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                if (ProjectHelpers.GetProjectItem(document.FilePath) == null)
                {
                    return;
                }

                var jsHintLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsHintCompiler(), f), document);
                textView.Closed += (s, e) => jsHintLintInvoker.Dispose();

                textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsHintLintInvoker);

                var jsCodeStyleLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f), document);
                textView.Closed += (s, e) => jsCodeStyleLintInvoker.Dispose();

                textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsCodeStyleLintInvoker);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates an <see cref="IWpfTextViewMargin"/> for the given <see cref="IWpfTextViewHost"/>.
        /// </summary>
        /// <param name="wpfTextViewHost">The <see cref="IWpfTextViewHost"/> for which to create the <see cref="IWpfTextViewMargin"/>.</param>
        /// <param name="marginContainer">The margin that will contain the newly-created margin.</param>
        /// <returns>The <see cref="IWpfTextViewMargin"/>.
        /// The value may be null if this <see cref="IWpfTextViewMarginProvider"/> does not participate for this context.
        /// </returns>
        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
        {
            IWpfTextViewMargin result = null;

            // Github issue 9
            // https://github.com/PhilJollans/AnkhSVN2019/issues/9
            // Make sure that this method returns null if any error occurs.
            // This probably means that we will never find the error.
            // Note: I intend to add a log file to AnkhSvn, in which case we could at least log the error.
            try
            {
                // From https://github.com/madskristensen/MarkdownEditor/blob/master/src/Margin/BrowserMarginProvider.cs
                ITextDocument document;
                bool          isok = TextDocumentFactoryService.TryGetTextDocument(wpfTextViewHost.TextView.TextDataModel.DocumentBuffer, out document);

                // Get the filename
                var fn = document.FilePath;

                // Is there an annotation view model?
                var vm = AnnotateService.GetModel(fn);
                if (vm != null)
                {
                    wpfTextViewHost.TextView.Options.SetOptionValue(DefaultTextViewOptions.ViewProhibitUserInputId, true);
                    result = new AnnotationMargin(wpfTextViewHost.TextView, vm);
                }
            }
            catch (Exception)
            {
                // Set result to null as a matter of form.
                // To do, log the error in a log file.
                result = null;
            }
            return(result);
        }
        public DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            _documentBuffer = documentBuffer;
            _commands       = commands;
            ReparseDelay    = TimeSpan.FromMilliseconds(500);

            if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
            {
                if (_commands.IsGitRepository(_textDocument.FilePath))
                {
                    _textDocument.FileActionOccurred += OnFileActionOccurred;

                    var solutionDirectory = _commands.GetGitRepository(_textDocument.FilePath);

                    if (!string.IsNullOrWhiteSpace(solutionDirectory))
                    {
                        var gitDirectory = Path.Combine(solutionDirectory, ".git");
                        _watcher                     = new FileSystemWatcher(gitDirectory);
                        _watcher.Changed            += HandleFileSystemChanged;
                        _watcher.Created            += HandleFileSystemChanged;
                        _watcher.Deleted            += HandleFileSystemChanged;
                        _watcher.Renamed            += HandleFileSystemChanged;
                        _watcher.EnableRaisingEvents = true;
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_hasRun || _isProcessing)
            {
                return;
            }

            IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);


            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out ITextDocument doc))
            {
                if (Path.IsPathRooted(doc.FilePath) && File.Exists(doc.FilePath))
                {
                    _isProcessing = true;
                    var         dte  = (DTE2)Package.GetGlobalService(typeof(DTE));
                    ProjectItem item = dte.Solution?.FindProjectItem(doc.FilePath);

                    ThreadHelper.JoinableTaskFactory.Run(async() =>
                    {
                        await EnsureInitializedAsync(item);
                        _hasRun = _isProcessing = false;
                    });
                }
            }
        }
Exemplo n.º 14
0
        private void CreateTextViewHost(string text, string filePath)
        {
            if (text == null)
            {
                text = string.Empty;
            }

            var diskBuffer = TextBufferFactoryService.CreateTextBuffer(text, ContentType);

            _editorIntance = EditorInstanceFactory.CreateEditorInstance(diskBuffer, _compositionService);

            ITextDataModel textDataModel;

            if (_editorIntance != null)
            {
                textDataModel = new TextDataModel(diskBuffer, _editorIntance.ViewBuffer);
            }
            else
            {
                textDataModel = new TextDataModel(diskBuffer, diskBuffer);
            }

            var textBuffer = textDataModel.DocumentBuffer;

            TextDocument = TextDocumentFactoryService.CreateTextDocument(textBuffer, filePath);

            SetGlobalEditorOptions();

            var textView = TextEditorFactoryService.CreateTextView(textDataModel,
                                                                   new DefaultTextViewRoleSet(),
                                                                   GlobalOptions);

            _wpftextViewHost = TextEditorFactoryService.CreateTextViewHost(textView, true);

            ApplyDefaultSettings();

            _contentControl.Content = _wpftextViewHost.HostControl;

            var baseController = new BaseController();

            BaseController = baseController;

            if (_editorIntance != null)
            {
                CommandTarget = _editorIntance.GetCommandTarget(textView);
                var controller = CommandTarget as Microsoft.Languages.Editor.Controller.Controller;
                controller.ChainedController = baseController;
            }
            else
            {
                CommandTarget = baseController;
            }

            baseController.Initialize(textView, EditorOperations, UndoManager, _coreShell);
        }
Exemplo n.º 15
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(context.Snapshot.TextBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName) || (Path.GetExtension(fileName) != Constants.EXTENSION && fileName != Constants.SUGGESTIONS_FILENAME))
                {
                    yield break;
                }
            }
            else
            {
                yield break;
            }

            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null)
            {
                yield break;
            }

            string property = member.UnquotedNameText.ToLowerInvariant();

            if (!_supported.Contains(property))
            {
                yield break;
            }

            foreach (var extension in ExtensionInstalledChecker.Instance.GetInstalledExtensions())
            {
                ImageSource glyph = GetExtensionIcon(extension);

                if (property == "productid")
                {
                    yield return(new SimpleCompletionEntry(extension.Header.Name, extension.Header.Identifier, glyph, context.Session));
                }
                else if (property == "name")
                {
                    yield return(new SimpleCompletionEntry(extension.Header.Name, Normalize(extension.Header.Name), glyph, context.Session));
                }
                else if (property == "description")
                {
                    yield return(new SimpleCompletionEntry(extension.Header.Name, Normalize(extension.Header.Description), glyph, context.Session));
                }
                else if (property == "link")
                {
                    string url = extension.Header.MoreInfoUrl?.ToString() ?? extension.Header.GettingStartedGuide?.ToString() ?? "<no link found>";
                    yield return(new SimpleCompletionEntry(extension.Header.Name, url, glyph, context.Session));
                }
            }
        }
        public ISuggestedActionsSource CreateSuggestedActionsSource(ITextView textView, ITextBuffer textBuffer)
        {
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out document))
            {
                return(textView.Properties.GetOrCreateSingletonProperty(() =>
                                                                        new SuggestedActionsSource(ViewTagAggregatorFactoryService, textView, document.FilePath)));
            }

            return(null);
        }
Exemplo n.º 17
0
 private bool TryLoadPathAsFile(string filePath, out IWpfTextView textView)
 {
     try
     {
         var textDocument = TextDocumentFactoryService.CreateAndLoadTextDocument(filePath, TextBufferFactoryService.TextContentType);
         textView = MainWindow.CreateTextView(textDocument.TextBuffer);
         return(true);
     }
     catch (Exception)
     {
         textView = null;
         return(false);
     }
 }
Exemplo n.º 18
0
 public override HostResult LoadFileIntoNewWindow(string filePath)
 {
     try
     {
         var textDocument = TextDocumentFactoryService.CreateAndLoadTextDocument(filePath, TextBufferFactoryService.TextContentType);
         var wpfTextView  = MainWindow.CreateTextView(textDocument.TextBuffer);
         MainWindow.AddNewTab(System.IO.Path.GetFileName(filePath), wpfTextView);
         return(HostResult.Success);
     }
     catch (Exception ex)
     {
         return(HostResult.NewError(ex.Message));
     }
 }
Exemplo n.º 19
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            var           textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextBuffer, out document))
            {
                textView.Properties.GetOrCreateSingletonProperty(() => new PasteImage(textViewAdapter, textView, document.FilePath));
                textView.Properties.GetOrCreateSingletonProperty(() => new BoldCommandTarget(textViewAdapter, textView));
                textView.Properties.GetOrCreateSingletonProperty(() => new ItalicCommandTarget(textViewAdapter, textView));
                textView.Properties.GetOrCreateSingletonProperty(() => new SmartIndentCommandTarget(textViewAdapter, textView));
                textView.Properties.GetOrCreateSingletonProperty(() => new IndentationCommandTarget(textViewAdapter, textView));
                textView.Properties.GetOrCreateSingletonProperty(() => new ToogleTaskCommandTarget(textViewAdapter, textView));
            }
        }
Exemplo n.º 20
0
 public override bool LoadFileIntoNewWindow(string filePath)
 {
     try
     {
         var textDocument = TextDocumentFactoryService.CreateAndLoadTextDocument(filePath, TextBufferFactoryService.TextContentType);
         var wpfTextView  = MainWindow.CreateTextView(textDocument.TextBuffer);
         MainWindow.AddNewTab(System.IO.Path.GetFileName(filePath), wpfTextView);
         return(true);
     }
     catch (Exception ex)
     {
         _vim.ActiveStatusUtil.OnError(ex.Message);
         return(false);
     }
 }
        protected IMarginCore TryGetMarginCore(IWpfTextViewHost textViewHost)
        {
            MarginCore marginCore;

            if (textViewHost.TextView.Properties.TryGetProperty(typeof(MarginCore), out marginCore))
            {
                return(marginCore);
            }

            // play nice with other source control providers
            ITextView      textView       = textViewHost.TextView;
            ITextDataModel textDataModel  = textView != null ? textView.TextDataModel : null;
            ITextBuffer    documentBuffer = textDataModel != null ? textDataModel.DocumentBuffer : null;

            if (documentBuffer == null)
            {
                return(null);
            }

            ITextDocument textDocument;

            if (!TextDocumentFactoryService.TryGetTextDocument(documentBuffer, out textDocument))
            {
                return(null);
            }

            var fullPath = GetFullPath(textDocument.FilePath);

            if (fullPath == null)
            {
                return(null);
            }

            if (!GitCommands.TryGetOriginalPath(fullPath, out string originalPath))
            {
                return(null);
            }

            var repositoryPath = GitCommands.GetGitRepository(fullPath, originalPath);

            if (repositoryPath == null)
            {
                return(null);
            }

            return(textViewHost.TextView.Properties.GetOrCreateSingletonProperty(
                       () => new MarginCore(textViewHost.TextView, originalPath, TextDocumentFactoryService, ClassificationFormatMapService, EditorFormatMapService, GitCommands)));
        }
        //private void AdornmentVisibilityChanged(object sender, bool isVisible)
        //{
        //    WritableSettingsStore wstore = _settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
        //    _isVisible = isVisible;

        //    if (!wstore.CollectionExists(Constants.FILENAME))
        //        wstore.CreateCollection(Constants.FILENAME);

        //    wstore.SetBoolean(Constants.FILENAME, _propertyName, isVisible);
        //}

        public void TextViewCreated(IWpfTextView textView)
        {
            if (!_hasLoaded)
                LoadSettings();

            ITextDocument document;
            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName))
                    return;

                CreateAdornments(document, textView);
            }
        }
Exemplo n.º 23
0
        internal DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            _documentBuffer = documentBuffer;
            ReparseDelay    = TimeSpan.FromMilliseconds(500);

            if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
            {
                if (PerforceCommands.GetInstance().IsDiffPerformed(_textDocument.FilePath))
                {
                    _textDocument.FileActionOccurred += OnFileActionOccurred;
                    // TODO: implement a mechanism that will monitor perforce submit and update diff after submit
                    // Probably class which will check if current changelist already submitted using p4 describe every second can work as workaround
                    // or "Custom Tool": https://stackoverflow.com/questions/16053503/perforce-client-side-pre-commit-hook
                }
            }
        }
Exemplo n.º 24
0
        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
        {
            Func <ITextDocument, IWpfTextView, IWpfTextViewMargin> creator;

            if (!marginFactories.TryGetValue(wpfTextViewHost.TextView.TextDataModel.DocumentBuffer.ContentType.TypeName, out creator))
            {
                return(null);
            }

            ITextDocument document;

            if (!TextDocumentFactoryService.TryGetTextDocument(wpfTextViewHost.TextView.TextDataModel.DocumentBuffer, out document))
            {
                return(null);
            }

            return(creator(document, wpfTextViewHost.TextView));
        }
        public async void SubjectBuffersConnected(IWpfTextView textView, ConnectionReason reason, Collection <ITextBuffer> subjectBuffers)
        {
            if (!subjectBuffers.Any(b => b.ContentType.IsOfType("CSharp") || b.ContentType.IsOfType("Basic")))
            {
                return;
            }

            await Dispatcher.Yield();

            IVsTextView textViewAdapter = EditorAdaptersFactoryService.GetViewAdapter(textView);

            if (textViewAdapter == null)
            {
                return;
            }

            if (!TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out _))
            {
                return;
            }
        }
Exemplo n.º 26
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            if (!VSPackage.Manager.Provider.IsInitialized || !context.ContextItem.JSONDocument.HasSchema(_reportCache))
            {
                return(_empty);
            }

            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(context.Snapshot.TextBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath);

                if (fileName.Equals(VSPackage.ManifestFileName, StringComparison.OrdinalIgnoreCase))
                {
                    return(GetEntries(context));
                }
            }

            return(_empty);
        }
Exemplo n.º 27
0
        public void TextViewCreated(IWpfTextView textView)
        {
            if (!_hasLoaded)
            {
                LoadSettings();
            }

            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                if (string.IsNullOrEmpty(fileName) || !_map.ContainsKey(fileName))
                {
                    return;
                }

                LogoAdornment highlighter = new LogoAdornment(textView, _map[fileName], _isVisible, _initOpacity);
            }
        }
Exemplo n.º 28
0
        // TODO: The ITextView parameter isn't necessary.  This command should always load into
        // the active window, not existing
        public override HostResult LoadFileIntoExistingWindow(string filePath, ITextView textView)
        {
            var vimWindow = MainWindow.ActiveVimWindowOpt;

            if (vimWindow == null)
            {
                return(HostResult.NewError("No active vim window"));
            }

            try
            {
                var textDocument    = TextDocumentFactoryService.CreateAndLoadTextDocument(filePath, TextBufferFactoryService.TextContentType);
                var wpfTextViewHost = MainWindow.CreateTextViewHost(MainWindow.CreateTextView(textDocument.TextBuffer));
                vimWindow.Clear();
                vimWindow.AddVimViewInfo(wpfTextViewHost);
                return(HostResult.Success);
            }
            catch (Exception ex)
            {
                return(HostResult.NewError(ex.Message));
            }
        }
Exemplo n.º 29
0
        public void TextViewCreated(IWpfTextView textView)
        {
            if (!_hasLoaded)
            {
                LoadSettings();
            }

            ITextDocument document;

            if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document))
            {
                string fileName = Path.GetFileName(document.FilePath).ToLowerInvariant();

                // Check if filename is absolute because when debugging, script files are sometimes dynamically created.
                if (string.IsNullOrEmpty(fileName) || !Path.IsPathRooted(document.FilePath))
                {
                    return;
                }

                CreateAdornments(document, textView);
            }
        }
Exemplo n.º 30
0
        protected override void ReParseImpl()
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                var           snapshot = TextBuffer.CurrentSnapshot;
                ITextDocument textDocument;
                if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out textDocument))
                {
                    return;
                }

                var diff   = _commands.GetGitDiffFor(textDocument, _originalPath, snapshot);
                var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
                OnParseComplete(result);
            }
            catch (InvalidOperationException)
            {
                MarkDirty(true);
                throw;
            }
        }