Пример #1
0
        /// <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="eventArgs">Event args.</param>
        private void Execute(object sender, EventArgs eventArgs)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            TextDocument textDocument = VSTools.GetTextDocument();

            int count = 0;

            textDocument.Selection.CharLeft(true, 1);

            while (textDocument.Selection.Text != " " && textDocument.Selection.Text != ";")
            {
                textDocument.Selection.CharLeft(false, 1);
                textDocument.Selection.CharLeft(true, 1);
                count++;

                // Ensure I don't back up over a semi-colon.Use this as a test if the
                // routine was called at the end or beginning of a line (perhaps by accident).
                // Should immediately test if there is a semi-colon, new-line or tab when the routine
                // is entered, by I don't know how the tab and new-line is represented "\t" did not work.
                if (textDocument.Selection.Text == ";")
                {
                    textDocument.Selection.CharRight(false, count);
                    textDocument.Selection.Text = "[]";
                    break;
                }
            }

            textDocument.Selection.Text = "[";
            textDocument.Selection.CharRight(false, count);
            textDocument.Selection.Text = "]";
        }
Пример #2
0
        /// <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="eventArgs">Event args.</param>
        private void Execute(object sender, EventArgs eventArgs)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            TextDocument textDocument = VSTools.GetTextDocument();

            textDocument.Selection.Text = "->";
        }
        /// <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="eventArgs">Event args.</param>
        private void Execute(object sender, EventArgs eventArgs)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            TextDocument textDocument = VSTools.GetTextDocument();

            textDocument.Selection.Text = "{";
            textDocument.Selection.NewLine();
            textDocument.Selection.Backspace();
            textDocument.Selection.Text = "}";
            textDocument.Selection.LineUp(false, 1);
//			textDocument.Selection.NewLine();
        }
Пример #4
0
        /// <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="eventArgs">Event args.</param>
        private void Execute(object sender, EventArgs eventArgs)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            TextDocument textDocument = VSTools.GetTextDocument();

            // Select the current line and copy the text to a string.
            textDocument.Selection.SelectLine();

            // Copy the line from the selection while remove ending spaces, tabs, carriage returns, and carriage return, line feeds.  The
            // selection of the lines seems to grab the "return" so we need to remove it.
            // 9  - Tab
            // 10 - Line feed
            // 13 - Carriage return
            string line = textDocument.Selection.Text.TrimEnd(System.Text.Encoding.ASCII.GetChars(new byte[] { 9, 10, 13 }));

            // Split the string into the left and right parts at the equal sign.  These will be used as find and replace values.  We only want
            // the left code section and right code section, so we need to strip tabs and the ending semi-colon as well.
            string[] leftandright = line.Split(new char[] { Convert.ToChar(9), '=', ';' }, StringSplitOptions.RemoveEmptyEntries);

            // Now that we've split them into the two parts, removing the equal sign and trailing semi-color, we remove all leading and trailing
            // spaces.  We only want the two pieces of code on either side of the equal sign.
            leftandright[0] = leftandright[0].Trim();
            leftandright[1] = leftandright[1].Trim();

            // Split the line at the equal sign, removing the equal sign.
            string[] halves = line.Split('=');

            // Replace the strings in the two halves.  This preserves the leading tabs and any spacing between the two sides.
            halves[0] = halves[0].Replace(leftandright[0], leftandright[1]);
            halves[1] = halves[1].Replace(leftandright[1], leftandright[0]);

            // Reassemble the string from the two halves which had the strings swapped.
            // We also never have extraneous blank/white space at the end of a line, so we might as well kill that while we are here.
            textDocument.Selection.Insert(halves[0] + "=" + halves[1].TrimEnd() + "\n");
        }