Ejemplo n.º 1
0
        public async void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView view = AdaptersFactory.GetWpfTextView(textViewAdapter);

            if (!DocumentService.TryGetTextDocument(view.TextBuffer, out ITextDocument doc))
            {
                return;
            }

            string ext = Path.GetExtension(doc.FilePath);

            if (!FileExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase))
            {
                return;
            }

            ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
            NodeProcess            node        = view.Properties.GetOrCreateSingletonProperty(() => new NodeProcess());

            AddCommandFilter(textViewAdapter, new SortCommand(view, undoManager, node));
            AddCommandFilter(textViewAdapter, new ModeCommand());

            if (!node.IsReadyToExecute())
            {
                await Install(node);
            }
        }
Ejemplo n.º 2
0
        private static async System.Threading.Tasks.Task Install(NodeProcess node)
        {
            var statusbar = (IVsStatusbar)ServiceProvider.GlobalProvider.GetService(typeof(SVsStatusbar));

            statusbar.FreezeOutput(0);
            statusbar.SetText($"Installing {NodeProcess.Packages} npm modules...");
            statusbar.FreezeOutput(1);

            bool success = await node.EnsurePackageInstalled();

            string status = success ? "Done" : "Failed";

            statusbar.FreezeOutput(0);
            statusbar.SetText($"Installing {NodeProcess.Packages} npm modules... {status}");
            statusbar.FreezeOutput(1);
        }
Ejemplo n.º 3
0
        private static async Task <bool> ExecuteAsync(IWpfTextView view, ITextBufferUndoManager undoManager, NodeProcess node)
        {
            string input  = view.TextBuffer.CurrentSnapshot.GetText();
            string output = await node.ExecuteProcess(input);

            if (string.IsNullOrEmpty(output) || input == output)
            {
                return(false);
            }

            using (ITextEdit edit = view.TextBuffer.CreateEdit())
                using (ITextUndoTransaction undo = undoManager.TextBufferUndoHistory.CreateTransaction("Sort properties"))
                {
                    edit.Replace(0, view.TextBuffer.CurrentSnapshot.Length, output);
                    edit.Apply();

                    undo.Complete();
                }

            return(true);
        }
Ejemplo n.º 4
0
 public SortCommand(IWpfTextView view, ITextBufferUndoManager undoManager, NodeProcess node)
 {
     _view        = view;
     _undoManager = undoManager;
     _node        = node;
 }