private bool HandlePasteCommand(Guid pguidCmdGroup, uint nCmdID)
        {
            if (ShouldHandleThisCommand(pguidCmdGroup, nCmdID))
            {
                return(false);
            }

            EnvDTE.TextDocument doc = (EnvDTE.TextDocument)_dte.ActiveDocument.Object("TextDocument");
            if (doc.Language != "TypeScript")
            {
                return(false);
            }

            string text = Clipboard.GetText(TextDataFormat.Text);

            var typescriptCode = csharpToTypescriptConverter.ConvertToTypescript(text, SettingStore.Instance);

            if (typescriptCode == null)
            {
                return(false);
            }

            InsertIntoDocument(doc, typescriptCode);

            return(true);
        }
Esempio n. 2
0
        private string GetSQLString(EnvDTE.TextDocument doc)
        {
            /*
             * String selectedText = doc.Selection.Text;
             *
             * if (selectedText.Length == 0)
             * {
             *  // get all text in window
             *  doc.Selection.SelectAll();
             *  selectedText = doc.Selection.Text;
             * }
             * return selectedText;
             */

            // Update from Matt P.
            String selectedText = doc.Selection.Text;

            if (selectedText.Length == 0)
            {
                // Nothing is selected, so get all text in the editor window
                var editPoint = doc.StartPoint.CreateEditPoint();
                selectedText = editPoint.GetText(doc.EndPoint);
            }
            return(selectedText);
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                EnvDTE._DTE         theDTE             = DteResources.Instance.GetDteInstance();
                EnvDTE.TextDocument activeTextDocument = (EnvDTE.TextDocument)theDTE.ActiveDocument.Object("TextDocument");
                TextSelection       selection          = activeTextDocument.Selection;

                this.SubstituteStringFromSelection_RemoveCheckSteps(activeTextDocument);
            }
            catch (InvalidOperationException)
            {
                VsShellUtilities.ShowMessageBox(this.ServiceProvider, "The code selection is unbalanced; please try again selecting in the correct lines of code for a complete set of opening and closing check steps.", "Error in Text Selection",
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            catch (Exception ex)
            {
                VsShellUtilities.ShowMessageBox(this.ServiceProvider, string.Format("Exception type='{0}', Message='{1}'", ex.GetType().ToString(), ex.Message), "Exception",
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Documents a specific element.
 /// </summary>
 /// <param name="document">The TextDocument that contains the code.</param>
 /// <param name="element">The element to document.</param>
 private void DocumentElement(EnvDTE.TextDocument document, EnvDTE.CodeElement element)
 {
     EnvDTE.EditPoint startPoint;
     document.Selection.GotoLine(element.StartPoint.Line, true);
     startPoint = document.CreateEditPoint(document.Selection.ActivePoint);
     document.Selection.MoveToPoint(startPoint, true);
     window.SetFocus();
     window.DTE.ExecuteCommand("Tools.Submain.GhostDoc.DocumentThis", string.Empty);
 }
Esempio n. 5
0
        /// <summary>
        /// Writes TSQL query history to an XML file
        /// </summary>
        /// <param name="Guid"></param>
        /// <param name="ID"></param>
        /// <param name="customIn"></param>
        /// <param name="customOut"></param>
        public void CommandEvents_AfterExecute(string Guid, int ID, object customIn, object customOut)
        {
            EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.ActiveDocument.Object(null);
            if (doc != null)
            {
                string Sql = GetSQLString(doc);

                if (String.IsNullOrWhiteSpace(Sql))
                {
                    return;
                }

                // Get Current Connection Information
                UIConnectionInfo connInfo = ServiceCache.ScriptFactory.CurrentlyActiveWndConnectionInfo.UIConnectionInfo;

                // Set the path to the history file
                string path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    "SSMS Query History",
                    DateTime.Now.ToString("yyyy-MMM-dd"));

                // Create the history file path if it doesn't exist
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                // Set the filename of the history file
                string filename = Path.Combine(path, "QueryHistory.xml");

                // Attempt to load the history file and create an empty file if it doesn't exist
                XDocument history;
                try
                {
                    history = XDocument.Load(filename);
                }
                catch (FileNotFoundException)
                {
                    history = XDocument.Parse("<SSMSQueryHistory/>");
                }

                // Add the newly executed TSQL query
                history.Root.Add(
                    new XElement("HistoryEntry",
                                 new XElement("Server", new XCData(connInfo.ServerName ?? String.Empty)),
                                 new XElement("Database", new XCData(connInfo.AdvancedOptions["DATABASE"])),
                                 new XElement("DateTime", DateTime.Now),
                                 new XElement("Query", new XCData(Sql))));

                // Save the history file
                history.Save(filename);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// GetContentsOfCurrentQueryWindow
        /// </summary>
        /// <returns></returns>
        public string GetContentsOfCurrentQueryWindow()
        {
            EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(null);

            if (doc != null)
            {
                return(GetSQLString(doc));
            }
            else
            {
                return(null);
            }
        }
        private void InsertIntoDocument(EnvDTE.TextDocument doc, string typescriptCode)
        {
            EditPoint start = doc.Selection.TopPoint.CreateEditPoint();

            // First insert plain text
            _dte.UndoContext.Open("Paste");
            doc.Selection.Insert(typescriptCode);
            _dte.UndoContext.Close();
            doc.Selection.MoveToPoint(start, true);

            FormatSelection();
            _textView.Selection.Clear();
        }
Esempio n. 8
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            /*
             * // Show a Message Box to prove we were here
             * IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
             * Guid clsid = Guid.Empty;
             * int result;
             * Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
             *         0,
             *         ref clsid,
             *         "VSExtension",
             *         string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
             *         string.Empty,
             *         0,
             *         OLEMSGBUTTON.OLEMSGBUTTON_OK,
             *         OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
             *         OLEMSGICON.OLEMSGICON_INFO,
             *         0,        // false
             *         out result));
             */
            EnvDTE.DTE app = (EnvDTE.DTE)GetService(typeof(SDTE));
            if (app.ActiveDocument != null && app.ActiveDocument.Type == "Text")
            {
                EnvDTE.TextDocument text = (EnvDTE.TextDocument)app.ActiveDocument.Object(String.Empty);
                if (!text.Selection.IsEmpty)
                {
                    // File url
                    using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "pexpipe",
                                                                                        PipeDirection.Out,
                                                                                        PipeOptions.Asynchronous))
                    {
                        try
                        {
                            pipeClient.Connect(2000);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("PexVisualiser is not running. Start it, then try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        using (StreamWriter sw = new StreamWriter(pipeClient))
                        {
                            sw.WriteLine(text.Parent.FullName + "|" + text.Selection.TopPoint.Line.ToString() + "|" + text.Selection.BottomPoint.Line.ToString());
                        }
                    }

                    //MessageBox.Show(text.Parent.Path + text.Parent.FullName +  "|" + text.Selection.TopPoint.Line.ToString());
                    //work with text.Selection.Text
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Get Selected Text or All Text in window
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public string GetSQLString(EnvDTE.TextDocument doc)
        {
            // Get Selected Text on screen
            String selectedparttest = doc.Selection.Text;


            if (selectedparttest.Length == 0)
            {
                // get all text in window
                doc.Selection.SelectAll();
                selectedparttest = doc.Selection.Text;
            }

            return(selectedparttest);
        }
Esempio n. 10
0
        public override string GetLine(int lineIndex)
        {
            if (dte == null || dte.ActiveDocument == null)
            {
                return("");
            }

            EnvDTE.TextDocument objTextDoc = GetCurrentVSTextDocument();
            EditPoint           ep         = objTextDoc.StartPoint.CreateEditPoint();

            ep.LineDown(lineIndex - 1);
            EditPoint ep2 = ep.CreateEditPoint();

            ep2.EndOfLine();
            return(ep.GetText(ep2));
        }
Esempio n. 11
0
        private void ScriptQuery_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item     = (ToolStripMenuItem)sender;
            QueryTemplate     template = (QueryTemplate)item.Tag;
            string            context  = this.Parent.Context;

            string[] text = GetQueryByContext(((QueryTemplate)item.Tag).Template, context);
            ServiceCache.ScriptFactory.CreateNewBlankScript(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptType.Sql);
            EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.ActiveDocument.Object(null);
            StringBuilder       sb  = new StringBuilder();

            foreach (string str in text)
            {
                sb.AppendLine(str);
            }
            doc.EndPoint.CreateEditPoint().Insert(sb.ToString());
            if (template.Autoexec)
            {
                doc.DTE.ExecuteCommand("Query.Execute");
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                EnvDTE._DTE         theDTE             = DteResources.Instance.GetDteInstance();
                EnvDTE.TextDocument activeTextDocument = (EnvDTE.TextDocument)theDTE.ActiveDocument.Object("TextDocument");
                TextSelection       selection          = activeTextDocument.Selection;

                this.SubstituteStringFromSelection_AddCheckStep(activeTextDocument);
            }
            catch (NullReferenceException)
            {
            }
            catch (Exception ex)
            {
                VsShellUtilities.ShowMessageBox(this.ServiceProvider, string.Format("Exception type='{0}', Message='{1}'", ex.GetType().ToString(), ex.Message), "Exception",
                                                OLEMSGICON.OLEMSGICON_INFO,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
        }
        private TextSelection GetTextSelection()
        {
            try
            {
                EnvDTE.Document objDocument = this.dteProvider.Dte.ActiveDocument;
                if (objDocument == null)
                {
                    ShowMessageBox("GetTextSelection()", "ActiveDocument not found. Are you in a code editor window ?");
                    return(null);
                }

                EnvDTE.TextDocument  objTextDocument  = (EnvDTE.TextDocument)objDocument.Object("TextDocument");
                EnvDTE.TextSelection objTextSelection = objTextDocument.Selection;
                return(objTextSelection);
            }
            catch (Exception ex)
            {
                ShowMessageBox("GetTextSelection()", ex.Message);
            }
            return(null);
        }
Esempio n. 14
0
 private static void openFile(string strFilename, int lineno)
 {
     EnvDTE.DTE dte = null;
     // try to connect to visual studio instance
     try
     {
         dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
     }
     catch (System.Runtime.InteropServices.COMException)
     {
         return;
     }
     if (dte != null)
     {
         EnvDTE.Window w = dte.ItemOperations.OpenFile(strFilename, Constants.vsViewKindCode);
         w.Activate();
         EnvDTE.TextDocument td = (EnvDTE.TextDocument)dte.ActiveDocument.Object("TextDocument");
         td.Selection.MoveTo(lineno, 1, false);
         td.Selection.EndOfLine(false);
         td.Selection.SelectLine();
         dte.Debugger.Stop(false);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Documents child CodeElements within a document.
        /// </summary>
        /// <param name="document">The TextDocument that contains the code.</param>
        /// <param name="elements">The elements to document.</param>
        private void DocumentElements(EnvDTE.TextDocument document, EnvDTE.CodeElements elements)
        {
            try
            {
                foreach (CodeElement element in elements)
                {
                    switch (element.Kind)
                    {
                    case vsCMElement.vsCMElementFunction:
                        EnvDTE.CodeFunction func;
                        func = (EnvDTE.CodeFunction)element;
                        if (func.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, func.Children);
                        break;

                    case vsCMElement.vsCMElementProperty:
                        EnvDTE.CodeProperty prop;
                        prop = (EnvDTE.CodeProperty)element;
                        if (prop.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, prop.Children);
                        break;

                    case vsCMElement.vsCMElementEvent:
                        EnvDTE80.CodeEvent evt;
                        evt = (EnvDTE80.CodeEvent)element;
                        if (evt.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, evt.Children);
                        break;

                    case vsCMElement.vsCMElementClass:
                        EnvDTE.CodeClass cls;
                        cls = (EnvDTE.CodeClass)element;
                        if (cls.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, cls.Children);
                        break;

                    case vsCMElement.vsCMElementStruct:
                        EnvDTE.CodeStruct strct;
                        strct = (EnvDTE.CodeStruct)element;
                        if (strct.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, strct.Children);
                        break;

                    case vsCMElement.vsCMElementDelegate:
                        EnvDTE.CodeDelegate dlg;
                        dlg = (EnvDTE.CodeDelegate)element;
                        if (dlg.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, dlg.Children);
                        break;

                    case vsCMElement.vsCMElementEnum:
                        EnvDTE.CodeEnum enm;
                        enm = (EnvDTE.CodeEnum)element;
                        if (enm.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, enm.Children);
                        break;

                    case vsCMElement.vsCMElementVariable:
                        EnvDTE.CodeVariable var;

                        var = (EnvDTE.CodeVariable)element;
                        if (var.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        break;

                    case vsCMElement.vsCMElementNamespace:
                        EnvDTE.CodeNamespace nmspc;
                        nmspc = (EnvDTE.CodeNamespace)element;
                        DocumentElements(document, nmspc.Children);
                        break;

                    case vsCMElement.vsCMElementInterface:
                        EnvDTE.CodeInterface inter;
                        inter = (EnvDTE.CodeInterface)element;
                        if (inter.Access != vsCMAccess.vsCMAccessProject)
                        {
                            DocumentElement(document, element);
                        }

                        DocumentElements(document, inter.Children);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }