static void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var doc = CodistPackage.DTE.ActiveDocument; if (doc == null) { return; } var docWindow = TextEditorHelper.GetActiveWpfDocumentView(); if (docWindow == null) { return; } using (var f = new System.Windows.Forms.SaveFileDialog { Filter = "PNG images (*.png)|*.png", AddExtension = true, Title = "Please specify the location of the screenshot file", FileName = System.IO.Path.GetFileNameWithoutExtension(doc.Name) + ".png" }) { if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { var g = docWindow.VisualElement.GetParent <System.Windows.Controls.Grid>(); WpfHelper.ScreenShot(g, f.FileName, (int)g.ActualWidth, (int)g.ActualHeight); } catch (Exception ex) { CodistPackage.ShowErrorMessageBox("Failed to save screenshot for " + doc.Name + "\n" + ex.Message, null, true); } } } }
/// <summary> /// Shows the tool window when the menu item is clicked. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> internal static void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); if (Config.Instance.Features.MatchFlags(Features.SyntaxHighlight) == false) { CodistPackage.ShowMessageBox(R.T_SyntaxHighlightDisabled, R.CMD_ConfigureSyntaxHighlight, true); return; } if (_Window == null || _Window.IsVisible == false) { var v = TextEditorHelper.GetActiveWpfDocumentView(); if (v == null) { CodistPackage.ShowMessageBox(R.T_CustomizeSyntaxHighlightNote, R.CMD_ConfigureSyntaxHighlight, true); return; } CreateWindow(v); } _Window.Show(); //// Get the instance number 0 of this tool window. This window is single instance so this instance //// is actually the only one. //// The last flag is set to true so that if the tool window does not exists it will be created. //var window = CodistPackage.Instance.FindToolWindow(typeof(SyntaxCustomizerWindow), 0, true); //if ((null == window) || (null == window.Frame)) { // throw new NotSupportedException("Cannot create SyntaxCustomizerWindow"); //} //var windowFrame = (IVsWindowFrame)window.Frame; //Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); }
static void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var doc = CodistPackage.DTE.ActiveDocument; if (doc == null) { return; } var docWindow = TextEditorHelper.GetActiveWpfDocumentView(); if (docWindow == null) { return; } using (var f = new System.Windows.Forms.SaveFileDialog { Filter = R.T_PngFileFilter, AddExtension = true, Title = R.T_SpecifyScreenshotLocation, FileName = System.IO.Path.GetFileNameWithoutExtension(doc.Name) + ".png" }) { if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { var g = docWindow.VisualElement.GetParent <System.Windows.Controls.Grid>(); WpfHelper.ScreenShot(g, f.FileName, (int)g.ActualWidth, (int)g.ActualHeight); } catch (Exception ex) { CodistPackage.ShowMessageBox(R.T_FailedToSaveScreenshot.Replace("<NAME>", doc.Name) + Environment.NewLine + ex.Message, null, true); } } } }
public static void Initialize() { Command.CodeWindowScreenshot.Register(Execute, (s, args) => { ThreadHelper.ThrowIfNotOnUIThread(); ((OleMenuCommand)s).Visible = TextEditorHelper.GetActiveWpfDocumentView() != null; }); }
public static void Initialize() { Command.GetContentType.Register(Execute, (s, args) => { ThreadHelper.ThrowIfNotOnUIThread(); ((OleMenuCommand)s).Visible = Config.Instance.DeveloperOptions.MatchFlags(DeveloperOptions.ShowDocumentContentType) && TextEditorHelper.GetActiveWpfDocumentView() != null; }); }
public static void Initialize(AsyncPackage package) { var menuItem = new OleMenuCommand(Execute, new CommandID(CommandSet, CommandId)); menuItem.BeforeQueryStatus += (s, args) => { ThreadHelper.ThrowIfNotOnUIThread(); var c = s as OleMenuCommand; c.Enabled = TextEditorHelper.GetActiveWpfDocumentView() != null; }; CodistPackage.MenuService.AddCommand(menuItem); }
static void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); var doc = CodistPackage.DTE.ActiveDocument; if (doc == null) { return; } var docWindow = TextEditorHelper.GetActiveWpfDocumentView(); if (docWindow == null) { return; } var t = docWindow.TextBuffer.ContentType; using (var b = ReusableStringBuilder.AcquireDefault(100)) { var sb = b.Resource; var d = docWindow.TextBuffer.GetTextDocument(); sb.Append(R.T_ContentTypeOfDocument); if (d != null) { sb.Append(System.IO.Path.GetFileName(d.FilePath)); } sb.AppendLine(); sb.AppendLine(); var h = new HashSet <IContentType>(); ShowContentType(t, sb, h, 0); System.Windows.Forms.MessageBox.Show(sb.ToString(), nameof(Codist)); } void ShowContentType(IContentType type, StringBuilder sb, HashSet <IContentType> h, int indent) { sb.Append(' ', indent) .Append(type.DisplayName); if (type.DisplayName != type.TypeName) { sb.Append('(') .Append(type.TypeName) .Append(')'); } sb.AppendLine(); foreach (var bt in type.BaseTypes) { if (h.Add(bt)) { ShowContentType(bt, sb, h, indent + 2); } } } }
static void RefreshWindow(object sender, EventArgs e) { if (_Window != null && _Window.IsClosing == false && _Window.IsVisible) { var b = _Window.RestoreBounds; var s = _Window.WindowState; _Window.Close(); if (_Window.IsClosing == false) { CreateWindow(TextEditorHelper.GetActiveWpfDocumentView()); _Window.Top = b.Top; _Window.Left = b.Left; _Window.Width = b.Width; _Window.Height = b.Height; _Window.WindowState = s; } _Window.Show(); } }
static NaviBar.INaviBar GetCSharpBar() { NaviBar.INaviBar bar = null; return(TextEditorHelper.GetActiveWpfDocumentView()?.Properties.TryGetProperty(nameof(NaviBar), out bar) == true ? bar : null); }