Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Moves the up before comment.
        /// </summary>
        /// <param name="sel">The sel.</param>
        /// ------------------------------------------------------------------------------------
        private void MoveUpBeforeComment(TextSelection sel)
        {
            TextRanges textRanges = null;

            for (; true;)
            {
                if (sel.FindPattern("\\<summary\\>|/// ---", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression),
                                    ref textRanges))
                {
                    // GhostDoc messes up dashed lines from inherited comments from base class,
                    // so delete those
                    if (sel.Text.StartsWith("/// ---"))
                    {
                        sel.EndOfLine(true);
                        sel.WordRight(true, 1);
                        sel.Delete(1);
                    }
                    else if (sel.Text.StartsWith("<summary>"))
                    {
                        while (true)
                        {
                            sel.MoveToLineAndOffset(sel.ActivePoint.Line - 1, 1, false);
                            sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, false);
                            sel.EndOfLine(true);
                            if (!sel.Text.StartsWith("///"))
                            {
                                if (sel.Text.Length > 0)
                                {
                                    // there is a non-empty comment line. We want to start at the end
                                    // of it
                                    sel.EndOfLine(false);
                                }
                                else
                                {
                                    sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, false);
                                }
                                break;
                            }

                            // GhostDoc messes up dashed lines from inherited comments from base class,
                            // so delete those
                            if (sel.Text.StartsWith("/// -----"))
                            {
                                sel.WordRight(true, 1);
                                sel.Delete(1);
                            }
                        }
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>mark the method and bring the Visual Studio on front</summary>
        /// <param term='codeFunction'>is the right codeFunction element to the searched method</param>
        /// <param name="methodString">name of the method</param>

        internal void markMethod(CodeFunction codeFunction)
        {
            dte.Documents.Open(codeFunction.ProjectItem.get_FileNames(0), "Auto", false);

            TextSelection textSelection = (TextSelection)dte.ActiveDocument.Selection;

            textSelection.MoveToLineAndOffset(codeFunction.StartPoint.Line, codeFunction.StartPoint.LineCharOffset, false);

            TextRanges textRanges = null;
            string     pattern    = @"[:b]<{" + codeFunction.Name + @"}>[:b(\n]";

            if (textSelection.FindPattern(pattern, (int)vsFindOptions.vsFindOptionsRegularExpression, ref textRanges))
            {
                TextRange r = textRanges.Item(2);
                textSelection.MoveToLineAndOffset(r.StartPoint.Line, r.StartPoint.LineCharOffset, false);
                textSelection.MoveToLineAndOffset(r.EndPoint.Line, r.EndPoint.LineCharOffset, true);
            }
            dte.MainWindow.Activate();
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Moves the up before comment.
        /// </summary>
        /// <param name="sel">The sel.</param>
        /// ------------------------------------------------------------------------------------
        private void MoveUpBeforeComment(TextSelection sel)
        {
            TextRanges textRanges = null;
            for (; true; )
            {
                if (sel.FindPattern("\\<summary\\>|/// ---", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression),
                    ref textRanges))
                {
                    // GhostDoc messes up dashed lines from inherited comments from base class,
                    // so delete those
                    if (sel.Text.StartsWith("/// ---"))
                    {
                        sel.EndOfLine(true);
                        sel.WordRight(true, 1);
                        sel.Delete(1);
                    }
                    else if (sel.Text.StartsWith("<summary>"))
                    {
                        while (true)
                        {
                            sel.MoveToLineAndOffset(sel.ActivePoint.Line - 1, 1, false);
                            sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, false);
                            sel.EndOfLine(true);
                            if (!sel.Text.StartsWith("///"))
                            {
                                if (sel.Text.Length > 0)
                                {
                                    // there is a non-empty comment line. We want to start at the end
                                    // of it
                                    sel.EndOfLine(false);
                                }
                                else
                                    sel.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, false);
                                break;
                            }

                            // GhostDoc messes up dashed lines from inherited comments from base class,
                            // so delete those
                            if (sel.Text.StartsWith("/// -----"))
                            {
                                sel.WordRight(true, 1);
                                sel.Delete(1);
                            }
                        }
                        return;
                    }
                }
                else
                    return;
            }
        }
Ejemplo n.º 4
0
        private void EnterTextToActiveDocument(string text)
        {
            if (Statics.DTE.ActiveDocument == null)
            {
                MessageBox.Show("No active document is visible to write the generated code in, copying to clipboard instead (press ctrl-v on the document you want to place the code into)", "No Active Document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Clipboard.Clear();
                if (!string.IsNullOrEmpty(text))
                {
                    Clipboard.SetText(text);
                }
                return;
            }
            TextSelection sel   = (TextSelection)Statics.DTE.ActiveDocument.Selection;
            TextRanges    dummy = null;

            if (Statics.Language == ProjectLanguage.CSharp)
            {
                bool isRegionExists = false;

                sel.StartOfDocument(true);
                if (sel.FindPattern("#region Temporary Recording", (int)vsFindOptions.vsFindOptionsMatchInHiddenText, ref dummy))
                {
                    isRegionExists = true;
                }

                sel.EndOfDocument(true);

                sel.FindPattern("}", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsMatchInHiddenText), ref dummy);
                sel.FindPattern("}", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsMatchInHiddenText), ref dummy);
                if (isRegionExists)
                {
                    sel.FindPattern("#endregion", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsMatchInHiddenText), ref dummy);
                }
                sel.LineUp(true, 1);
                if (!isRegionExists)
                {
                    sel.Insert("\t\t#region Temporary Recording Code\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                }
                sel.Insert("\t\tprivate void " + GetAvailableMethodName() + "()\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert("\t\t{\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert(text, (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert("\r\n\t\t}\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                if (!isRegionExists)
                {
                    sel.Insert("\t\t#endregion\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                    sel.Insert("\t}\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                }
            }
            else if (Statics.Language == ProjectLanguage.VB)
            {
                sel.EndOfDocument(true);

                sel.FindPattern("End Class", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsMatchInHiddenText), ref dummy);
                //sel.LineUp(true, 1);
                sel.Insert("\tPrivate Sub " + GetAvailableMethodName() + "()\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert(text, (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert("\tEnd Sub\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
                sel.Insert("End Class\r\n", (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);
            }


            //sel.SelectAll();
            Statics.DTE.ActiveDocument.Activate();
            System.Threading.Thread.Sleep(200);
            Statics.DTE.ExecuteCommand("Edit.FormatDocument", string.Empty);
        }
Ejemplo n.º 5
0
        public static void ApplyPrefeence(DTE2 dte, string region, string controller, string field, string property, string preferredValue)
        {
            //string preferredValue = GetMostPreferredValue(region, controller, field, property);
            List <PreviousPropertyValue> listDefault = new List <PreviousPropertyValue>();

            foreach (ProjectItem pi in dte.Solution.Projects.Item(1).ProjectItems)
            {
                if (pi.ProjectItems != null)
                {
                    foreach (ProjectItem p in pi.ProjectItems)
                    {
                        if (p.Name.EndsWith(".Designer.cs"))
                        {
                            p.Open(EnvDTE.Constants.vsViewKindCode);
                            p.Document.Activate();
                            TextSelection     ts           = (TextSelection)dte.ActiveDocument.Selection;
                            TextSelection     ts2          = (TextSelection)dte.ActiveDocument.Selection;
                            string            srchPattern1 = "new System.Windows.Forms.Button();";
                            EnvDTE.TextRanges textRanges   = null;

                            ts.StartOfDocument(false);

                            int count = 0;

                            string   nameLine = "";
                            string   name     = "";
                            string[] np       = new string[50];

                            while (ts.FindPattern(srchPattern1, 0, ref textRanges))
                            {
                                ts.SelectLine();
                                nameLine = ts.Text;
                                count++;
                                string[] sp  = nameLine.Split('.');
                                string   spi = sp[1];
                                string[] sp2 = spi.Split('=');
                                name      = sp2[0];
                                np[count] = name;
                            }

                            int i = 1;
                            while (ts2.FindPattern(".BackColor = System.Drawing.Color", 0, ref textRanges))
                            {
                                PreviousPropertyValue def = new PreviousPropertyValue();

                                ts2.SelectLine();
                                string codeLine = ts2.Text;
                                codeLine = codeLine.Trim();
                                foreach (string s in np)
                                {
                                    string ss = s;
                                    if (ss != null)
                                    {
                                        ss = ss.Trim();
                                        if (codeLine.Contains(ss) == true)
                                        {
                                            ts2.ReplacePattern(codeLine, "this." + s + ".BackColor = System.Drawing.Color." + preferredValue + ";", 0, ref textRanges);
                                            np                 = np.Where(w => w != s).ToArray();
                                            def.FileName       = p.Name;
                                            def.ControllerType = controller;
                                            def.Property       = property;
                                            def.ControllerName = ss;
                                            def.DefaultValue   = codeLine;
                                            listDefault.Add(def);
                                        }
                                        //else
                                        //{
                                        //    ts2.LineDown();
                                        //    ts2.NewLine();
                                        //    ts2.Insert("this." + np[i] + ".BackColor = System.Drawing.Color." + preferredValue + ";");
                                        //}
                                        //def.FileName = p.Name;
                                        //def.ControllerType = controller;
                                        //def.Property = property;
                                        //def.ControllerName = ss;
                                        //def.DefaultValue = codeLine;
                                        //listDefault.Add(def);
                                    }
                                }

                                //i++;
                            }
                            if (np != null)
                            {
                                foreach (string s in np)
                                {
                                    if (s != null)
                                    {
                                        ts2.EndOfLine();

                                        ts2.NewLine();
                                        ts2.Insert("this." + np[i] + ".BackColor = System.Drawing.Color." + preferredValue + ";");
                                        np = np.Where(w => w != s).ToArray();
                                    }
                                }
                            }
                            SaveDefaultValues(listDefault);
                            dte.ActiveDocument.Save(p.Document.FullName);
                            dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesNo);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static bool ChangeToPreveiousValue(DTE2 dte, string controller, string property)
        {
            List <PreviousPropertyValue> listDefault = new List <PreviousPropertyValue>();
            List <PreviousPropertyValue> list        = LoadDefaultValues();

            if (list == null)
            {
                return(false);
            }
            else
            {
                foreach (ProjectItem pi in
                         dte.Solution.Projects.Item(1).ProjectItems)
                {
                    if (pi.ProjectItems != null)
                    {
                        foreach (ProjectItem p in pi.ProjectItems)
                        {
                            if (p.Name.EndsWith(".Designer.cs"))
                            {
                                p.Open(EnvDTE.Constants.vsViewKindCode);
                                p.Document.Activate();
                                TextSelection ts2 = (TextSelection)dte.ActiveDocument.Selection;

                                EnvDTE.TextRanges textRanges = null;

                                ts2.StartOfDocument(false);
                                //Find2 findWin = (Find2)dte.Find;
                                int count = 0;
                                //c = findWin.FindReplace(vsFindAction.vsFindActionFindAll, "button1", 0);
                                string   s    = "";
                                string   name = "";
                                string[] np   = new string[50];
                                // Advance to the next Visual Basic function beginning or end by
                                // searching for  "Sub" with white space before and after it.
                                //while
                                //while (ts.FindPattern(srchPattern1, 0, ref textRanges))
                                //{

                                //    //    //  Select the entire line.

                                //    count++;
                                //    ts.SelectLine();
                                //    s = ts.Text;

                                //    string[] sp = s.Split('.');
                                //    string spi = sp[1];


                                //    string[] sp2 = spi.Split('=');
                                //    name = sp2[0];

                                //    np[count] = name;
                                //    //ts.FindPattern("this." + name + ".BackColor = System.Drawing.Color", 0, ref textRanges);
                                //    //ts.SelectLine();
                                //    //s = ts.Text;
                                //    //ts2.StartOfDocument(false);
                                //    //while (ts.FindText("this." + name + ".BackColor = System.Drawing.Color", 0))
                                //    //{

                                //    //    ts.SelectLine();
                                //    //    string sd = ts.Text;
                                //    //    bool t = ts.ReplacePattern(sd, "this.button1.BackColor = System.Drawing.Color.Red;", 0, ref textRanges);
                                //    //}

                                //}

                                int i = 1;
                                //for(int i=1; i<=5;i++)
                                //{
                                //ts2 = null;


                                while (ts2.FindPattern(".BackColor = System.Drawing.Color", 0, ref textRanges))
                                {
                                    ts2.SelectLine();
                                    string sd = ts2.Text;
                                    sd = sd.Trim();
                                    foreach (PreviousPropertyValue dfcon in list)
                                    {
                                        if (dfcon.FileName == p.Name && sd.Contains(dfcon.ControllerName) && dfcon.Property == property && dfcon.ControllerType == controller)
                                        {
                                            ts2.ReplacePattern(sd, dfcon.DefaultValue, 0, ref textRanges);
                                        }
                                        i++;
                                        //}
                                    }
                                }
                                //ts.NewLine(1);


                                dte.ActiveDocument.Save(p.Document.FullName);
                                dte.ActiveDocument.Close(vsSaveChanges.vsSaveChangesNo);
                            }
                        }
                    }
                }
                return(true);
            }
        }
Ejemplo n.º 7
0
 private void OperatorCompletion_ForVector(ref TextSelection textSelection, String varName)
 {
     String prevComponent = GetPreviousPhrase(ref textSelection);
     textSelection.Text = "for(int " + varName + " = 0; " + varName + " < int(" + prevComponent + ".size()); " + varName + "++) {\n;\n}";
     TextRanges tr = null;
     textSelection.FindPattern(";", (int)vsFindOptions.vsFindOptionsBackwards, ref tr);
     textSelection.Text = "";
 }
Ejemplo n.º 8
0
 private void OperatorCompletion_ForIterator(ref TextSelection textSelection, String iteratorType, String reversePrefix, String varName)
 {
     String containerName, typeName;
     GetTypeAndNameForOperatorCompletion(ref textSelection, out typeName, out containerName);
     textSelection.Text = "for(" + typeName + "::" + iteratorType + " " + varName + " = " + containerName + "." + reversePrefix + "begin(); " + varName + " != " + containerName + "." + reversePrefix + "end(); ++" + varName + ") {\n;\n}";
     TextRanges tr = null;
     textSelection.FindPattern(";", (int)vsFindOptions.vsFindOptionsBackwards, ref tr);
     textSelection.Text = "";
 }