public void TextViewCreated(IWpfTextView textView) { if (contextDeterminator != null && editorFactory != null) { var vsTextView = editorFactory.GetViewAdapter(textView); if (vsTextView != null) { IVsTextLines ppBuffer = null; vsTextView.GetBuffer(out ppBuffer); if (ppBuffer != null) { SqlExtensions.SetSqlEditorConnection(ppBuffer, contextDeterminator, _commandService, _sqlEditorConnectCmdId); } } } }
public override void DoCommand(object sender, EventArgs args) { // TODO: get the selected text in the code window and copy any extracted sql statements to the clipboard if (VSGeneroPackage.Instance.ActiveDocument != null) { EnvDTE.TextSelection sel = (EnvDTE.TextSelection)VSGeneroPackage.Instance.ActiveDocument.Selection; if (sel != null && sel.Text.Length > 0) { StringBuilder sb = new StringBuilder(); foreach (var fragment in SqlStatementExtractor.ExtractStatements(sel.Text)) { sb.AppendLine(fragment.GetText()); sb.AppendLine(); } var tempText = sb.ToString().Trim(); if (tempText.Length > 0) { SqlExtensions.SetSqlExtractionFile(VSGeneroPackage.Instance.ActiveDocument.Path); ITextBuffer buffer = null; if (_tempfilename == null || (buffer = GetBufferAt(_tempfilename)) == null) { _tempfilename = Path.GetTempPath() + "temp_sql_file.sql"; File.WriteAllText(_tempfilename, tempText); VSGeneroPackage.NavigateTo(_tempfilename, Guid.Empty, 0); } else { var edit = buffer.CreateEdit(); edit.Insert(buffer.CurrentSnapshot.Length, (buffer.CurrentSnapshot.LineCount > 0 ? "\n\n" : "") + tempText); edit.Apply(); } } } } }