private void timer_Jump(object sender, System.Timers.ElapsedEventArgs e) { m_timer.Stop(); if (m_activeDocumentFileName != null) { s_dte.ExecuteCommand("Window.ActivateDocumentWindow"); // s_dte.ExecuteCommand("File.OpenFile", m_activeDocumentFileName); s_dte.ItemOperations.OpenFile(m_activeDocumentFileName, EnvDTE.Constants.vsViewKindTextView); Document document = GetActiveDocument(); if (document != null) { EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)(document.Selection); textSelection.GotoLine(m_activeDocumentLineNo, false); document.Activate(); if (document.Windows.Count > 0) { document.Windows.Item(1).Activate(); } textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn); } m_activeDocumentFileName = null; } }
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 = ""; foreach (var p in tClass.GetProperties()) { properties += codeParam.Name + "." + p.Name + System.Environment.NewLine; } // Move into the method and dump the properties there ts.LineDown(); ts.LineDown(); ts.StartOfLine(); ts.Insert(properties); }
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); }