public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
        if (ts == null)
        {
            throw new Exception("No Selection");
        }

        EnvDTE.CodeParameter codeParam = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementParameter] as EnvDTE.CodeParameter;
        if (codeParam == null)
        {
            throw new Exception("Not Parameter");
        }

        System.Type tClass     = GetTypeByName(DTE, package, codeParam.Type.AsFullName);
        string      properties = System.Environment.NewLine;

        foreach (var p in tClass.GetProperties())
        {
            properties += codeParam.Name + "." + p.Name + System.Environment.NewLine;
        }

        // Move into the method and dump the properties there
        ts.FindText("{");
        ts.Insert("{" + properties);
    }
Esempio n. 2
0
        private void PerformBugTracker(bool dotNet)
        {
            //! https://blogs.msdn.microsoft.com/vsx/2016/04/21/how-to-add-a-custom-paste-special-command-to-the-vs-editor-menu/

            Application.DoEvents();

            EnvDTE.TextSelection selection = (EnvDTE.TextSelection) this.CommandManager.ApplicationObject.ActiveDocument.Selection;
            string text           = selection.Text;
            string text_trim      = text.Trim();
            bool   is_numeric     = int.TryParse(text_trim, out int n);
            string bug_tracker_id = is_numeric ? text_trim : "00000";

            string        date   = DateTime.Now.ToString("yyyy-MM-dd");
            List <string> result = new List <string>();

            string comment_line = dotNet ?
                                  "/// @date " + date + "  @author " + this.CommandManager.UserName + "  @bugtracker{" + bug_tracker_id + "}" :
                                  "//! @date " + date + "  @author " + this.CommandManager.UserName + "  @bugtracker{" + bug_tracker_id + "}";

            /* TODO $$$ `selection.CurrentColumn` does not give a proper result
             *      try
             *      {
             *              int column = selection.CurrentColumn;
             *              if (column > 0)
             *              {
             *                      string indent_str = "";
             *                      for (int i = 0; i < column; ++i)
             *                              indent_str += " ";
             *                      comment_line = indent_str + comment_line;
             *              }
             *      }
             *      catch {}
             */

            result.Add(comment_line);

            string str = "";

            for (int i = 0; i < result.Count; i++)
            {
                str += result[i] + "\n";
            }

            selection.Insert(str, 2);
            if (!is_numeric)
            {
                selection.FindText("00000");
            }
        }
Esempio n. 3
0
        private void FunctionComment()
        {
            EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)_applicationObject.ActiveWindow.Selection;

            textSelection.StartOfDocument();

            textSelection.Insert("// *");

            textSelection.NewLine();
            textSelection.Insert("// * @author  모바일 기술팀 ");
            textSelection.Insert(System.Environment.UserName);

            textSelection.NewLine();
            textSelection.Insert("// * @date    ");
            textSelection.Insert(System.DateTime.Now.ToLongDateString());
            textSelection.Insert(" ");
            textSelection.Insert(System.DateTime.Now.ToLongTimeString());

            textSelection.NewLine();
            textSelection.Insert("// *");

            textSelection.NewLine();
            textSelection.NewLine();
        }
Esempio n. 4
0
        private void PerformCommentBlock(bool dotNet)
        {
            DoxUtil.CManager manager = DoxUtil.CManager.Manager;
            if (manager == null)
            {
                return;
            }

            bool          makeRegion;
            string        date       = DateTime.Now.ToString("yyyy-MM-dd");
            Regex         rx         = new Regex(@"[^ \t]");
            List <string> lines      = new List <string>();
            List <string> SpaceShift = new List <string>(2);
            List <string> result     = new List <string>();

            string[]             commentLines;
            EnvDTE.TextSelection selection = (EnvDTE.TextSelection) this.CommandManager.ApplicationObject.ActiveDocument.Selection;
            string text = selection.Text;

            SpaceShift.Insert(0, "");

            if (text.Trim() != "")
            {
                text = text.TrimEnd();
                lines.AddRange(text.Split('\n'));
                makeRegion = true;
            }
            else
            {
                makeRegion = false;
            }
            if (lines.Count > 0)
            {
                SpaceShift.InsertRange(0, rx.Split(lines[0], 2));
            }
            if (makeRegion)
            {
                if (dotNet)
                {
                    result.Add(SpaceShift[0] + "#region " + this.GetFunctionName(this.GetFirstLine(text)));
                }
                else
                {
                    result.Add(SpaceShift[0] + "#pragma region " + this.GetFunctionName(this.GetFirstLine(text)));
                }
            }

            string headerText = manager != null && manager.Options.UserDefinedHead ? manager.Options.HeadCommentBlock  : "";

            if (headerText.Length > 0)
            {
                commentLines = headerText.Split(new[] { '\r', '\n' });
                // commentLines = Regex.Split(text, "\r\n|\r|\n");
                for (int i = 0; i < commentLines.Length; ++i)
                {
                    string lineText = commentLines[i];
                    lineText = lineText.Replace("\\author", "\\author  " + this.CommandManager.UserName);
                    lineText = lineText.Replace("@author", "@author  " + this.CommandManager.UserName);
                    lineText = lineText.Replace("\\date", "\\date  " + date);
                    lineText = lineText.Replace("@date", "@date  " + date);
                    result.Add(SpaceShift[0] + lineText);
                }
            }
            else if (dotNet)
            {
                result.Add(SpaceShift[0] + "/// <summary>");
                result.Add(SpaceShift[0] + "///");
                result.Add(SpaceShift[0] + "/// </summary>");
                result.Add(SpaceShift[0] + "/// <revision date=\"" + date + "\" author=\"" + this.CommandManager.UserName + "\"></revision>");
            }
            else
            {
                int          block_len  = Math.Max(this.HeadCommentLength, 80);
                const string head_start = "/*XEOMETRIC";
                const string head_end   = "//**";
                string       head_mid   = "";
                for (int i = 0; i < block_len - head_start.Length - head_end.Length; ++i)
                {
                    head_mid += "*";
                }
                string head = head_start + head_mid + head_end;
                string tail = "";
                for (int i = 0; i < block_len - 1; ++i)
                {
                    tail += "*";
                }
                tail += "/";

                result.Add(SpaceShift[0] + "/***********************************************************************************************//**");
                result.Add(SpaceShift[0] + "* \\brief   ");
                result.Add(SpaceShift[0] + "*");
                result.Add(SpaceShift[0] + "* \\author  " + this.CommandManager.UserName);
                result.Add(SpaceShift[0] + "* \\date    " + date);
                result.Add(SpaceShift[0] + "* \\version 1.0");
                result.Add(SpaceShift[0] + "***************************************************************************************************/");
            }
            if (text != "")
            {
                result.Add(text);
            }
            if (makeRegion)
            {
                if (dotNet)
                {
                    result.Add(SpaceShift[0] + "#endregion\n");
                }
                else
                {
                    result.Add(SpaceShift[0] + "#pragma endregion\n");
                }
            }
            Application.DoEvents();
            if (text == "")
            {
                selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn, false);
            }
            string str = "";

            for (int i = 0; i < result.Count; i++)
            {
                str += result[i] + "\n";
            }
            selection.Insert(str, 2);
        }