internal DothtmlCompletionCommandHandler(IVsTextView textViewAdapter, ITextView textView, DothtmlCompletionHandlerProvider provider) { this.textView = textView; this.provider = provider; //add the command to the chain and get following command nextCommandHandler = new NextIOleCommandTarget <DothtmlCompletionCommandHandler>(textViewAdapter, this); }
protected override bool Execute(uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, NextIOleCommandTarget nextCommandTarget) { var groupId = CommandGroupId; if (nextCommandTarget.Execute(ref groupId, nCmdId, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK) { // parse the content var tokenizer = new DothtmlTokenizer(); var text = TextView.TextSnapshot.GetText(); tokenizer.Tokenize(new StringReader(text)); var parser = new DothtmlParser(); var node = parser.Parse(tokenizer.Tokens); // prepare the metadata control resolver var completionSource = TextView.TextBuffer.Properties.GetProperty <DothtmlCompletionSource>(typeof(DothtmlCompletionSource)); var metadataControlResolver = completionSource.MetadataControlResolver; metadataControlResolver.ReloadAllControls(completionSource.GetCompletionContext(null)); try { DTEHelper.UndoContext.Open("Format Dothtml document"); var edit = TextView.TextBuffer.CreateEdit(EditOptions.None, null, null); // fix the casing of all elements var editText = new StringBuilder(text); foreach (var element in node.EnumerateNodes().OfType <DothtmlElementNode>()) { FixElement(editText, metadataControlResolver, TextView.TextBuffer, element); } edit.Replace(0, editText.Length, editText.ToString()); edit.Apply(); } finally { DTEHelper.UndoContext.Close(); } } return(true); }
protected override bool Execute(uint nCmdId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, NextIOleCommandTarget nextCommandTarget) { //check triggered automatic function if (VsShellUtilities.IsInAutomationFunction(provider.ServiceProvider)) { var groupId = new Guid(CommandGroupId.ToString()); return(nextCommandTarget.Execute(ref groupId, nCmdId, nCmdexecopt, pvaIn, pvaOut) > 0); } //get position of cursor var position = TextView.Caret.Position.BufferPosition.Position; //get root node of syntax tree var rootNode = TextView.TextBuffer.GetDothtmlRootNode(); if (ProcessDirectives(position, rootNode)) { return(true); } return(false); }