private bool CancelOpening() { var eventArgs = new CancelEventArgs(); ContextMenuOpening?.Invoke(this, eventArgs); return(eventArgs.Cancel); }
public void Show() { ContextMenuOpening?.Invoke(this, ContextMenu); if (ContextMenu != null) { Model.ActiveEditor.SetMarkdownMonsterWindowFocus(); ContextMenu.PlacementTarget = Model.ActiveEditor.WebBrowser; ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; ContextMenu.Focus(); ContextMenu.IsOpen = true; var item = ContextMenu.Items[0] as MenuItem; item.Focus(); } }
public void Show() { ContextMenuOpening?.Invoke(this, ContextMenu); if (ContextMenu != null) { Model.ActiveEditor?.SetMarkdownMonsterWindowFocus(); ContextMenu.PlacementTarget = Model.Window.TabControl; ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; ContextMenu.VerticalOffset = 8; ContextMenu.Focus(); ContextMenu.IsOpen = true; TreeFolderBrowser.ContextMenu = ContextMenu; var item = ContextMenu.Items[0] as MenuItem; item.Focus(); } }
public void Show() { ContextMenuOpening?.Invoke(this, ContextMenu); if (ContextMenu != null) { ContextMenu.PlacementTarget = Window.WebBrowser; ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; ContextMenu.VerticalOffset = 8; ContextMenu.Focus(); ContextMenu.IsOpen = true; Window.WebBrowser.ContextMenu = ContextMenu; var item = ContextMenu.Items[0] as MenuItem; Window.Activate(); ContextMenu.Dispatcher.InvokeAsync(() => item.Focus(), System.Windows.Threading.DispatcherPriority.ApplicationIdle); } }
public FileViewer() { TreatAllFilesAsText = false; ShowEntireFile = false; NumberOfContextLines = AppSettings.NumberOfContextLines; InitializeComponent(); InitializeComplete(); UICommandsSourceSet += OnUICommandsSourceSet; internalFileViewer.MouseEnter += (_, e) => OnMouseEnter(e); internalFileViewer.MouseLeave += (_, e) => OnMouseLeave(e); internalFileViewer.MouseMove += (_, e) => OnMouseMove(e); internalFileViewer.KeyUp += (_, e) => OnKeyUp(e); _async = new AsyncLoader(); _async.LoadingError += (_, e) => { if (!IsDisposed) { ResetForText(null); internalFileViewer.SetText("Unsupported file: \n\n" + e.Exception.ToString(), openWithDifftool: null /* not applicable */); TextLoaded?.Invoke(this, null); } }; IgnoreWhitespaceChanges = AppSettings.IgnoreWhitespaceChanges; ignoreWhiteSpaces.Checked = IgnoreWhitespaceChanges; ignoreWhiteSpaces.Image = Images.WhitespaceIgnore; ignoreWhitespaceChangesToolStripMenuItem.Checked = IgnoreWhitespaceChanges; ignoreWhitespaceChangesToolStripMenuItem.Image = ignoreWhiteSpaces.Image; ignoreAllWhitespaces.Checked = AppSettings.IgnoreAllWhitespaceChanges; ignoreAllWhitespaces.Image = Images.WhitespaceIgnoreAll; ignoreAllWhitespaceChangesToolStripMenuItem.Checked = ignoreAllWhitespaces.Checked; ignoreAllWhitespaceChangesToolStripMenuItem.Image = ignoreAllWhitespaces.Image; ShowEntireFile = AppSettings.ShowEntireFile; showEntireFileButton.Checked = ShowEntireFile; showEntireFileToolStripMenuItem.Checked = ShowEntireFile; SetStateOfContextLinesButtons(); showNonPrintChars.Checked = AppSettings.ShowNonPrintingChars; showNonprintableCharactersToolStripMenuItem.Checked = AppSettings.ShowNonPrintingChars; ToggleNonPrintingChars(AppSettings.ShowNonPrintingChars); IsReadOnly = true; internalFileViewer.MouseMove += (_, e) => { if (_currentViewIsPatch && !fileviewerToolbar.Visible) { fileviewerToolbar.Visible = true; fileviewerToolbar.Location = new Point(Width - fileviewerToolbar.Width - 40, 0); fileviewerToolbar.BringToFront(); } }; internalFileViewer.MouseLeave += (_, e) => { if (GetChildAtPoint(PointToClient(MousePosition)) != fileviewerToolbar && fileviewerToolbar != null) { fileviewerToolbar.Visible = false; } }; internalFileViewer.TextChanged += (sender, e) => { if (_patchHighlighting) { internalFileViewer.AddPatchHighlighting(); } TextChanged?.Invoke(sender, e); }; internalFileViewer.ScrollPosChanged += (sender, e) => ScrollPosChanged?.Invoke(sender, e); internalFileViewer.SelectedLineChanged += (sender, e) => SelectedLineChanged?.Invoke(sender, e); internalFileViewer.DoubleClick += (_, args) => RequestDiffView?.Invoke(this, EventArgs.Empty); HotkeysEnabled = true; if (!IsDesignModeActive && ContextMenuStrip == null) { ContextMenuStrip = contextMenu; } contextMenu.Opening += (sender, e) => { copyToolStripMenuItem.Enabled = internalFileViewer.GetSelectionLength() > 0; ContextMenuOpening?.Invoke(sender, e); }; _fullPathResolver = new FullPathResolver(() => Module.WorkingDir); }
public FileViewer() { TreatAllFilesAsText = false; ShowEntireFile = false; NumberOfContextLines = AppSettings.NumberOfContextLines; InitializeComponent(); InitializeComplete(); UICommandsSourceSet += OnUICommandsSourceSet; _internalFileViewer = new FileViewerInternal(() => Module); _internalFileViewer.MouseEnter += (_, e) => OnMouseEnter(e); _internalFileViewer.MouseLeave += (_, e) => OnMouseLeave(e); _internalFileViewer.MouseMove += (_, e) => OnMouseMove(e); _internalFileViewer.KeyUp += (_, e) => OnKeyUp(e); var internalFileViewerControl = (Control)_internalFileViewer; internalFileViewerControl.Dock = DockStyle.Fill; Controls.Add(internalFileViewerControl); _async = new AsyncLoader(); _async.LoadingError += (_, e) => { if (!IsDisposed) { ResetForText(null); _internalFileViewer.SetText("Unsupported file: \n\n" + e.Exception.ToString(), openWithDifftool: null /* not applicable */); TextLoaded?.Invoke(this, null); } }; IgnoreWhitespaceChanges = AppSettings.IgnoreWhitespaceChanges; ignoreWhiteSpaces.Checked = IgnoreWhitespaceChanges; ignoreWhiteSpaces.Image = Images.WhitespaceIgnore; ignoreWhitespaceChangesToolStripMenuItem.Checked = IgnoreWhitespaceChanges; ignoreWhitespaceChangesToolStripMenuItem.Image = ignoreWhiteSpaces.Image; ignoreAllWhitespaces.Checked = AppSettings.IgnoreAllWhitespaceChanges; ignoreAllWhitespaces.Image = Images.WhitespaceIgnoreAll; ignoreAllWhitespaceChangesToolStripMenuItem.Checked = ignoreAllWhitespaces.Checked; ignoreAllWhitespaceChangesToolStripMenuItem.Image = ignoreAllWhitespaces.Image; ShowEntireFile = AppSettings.ShowEntireFile; showEntireFileButton.Checked = ShowEntireFile; showEntireFileToolStripMenuItem.Checked = ShowEntireFile; SetStateOfContextLinesButtons(); showNonPrintChars.Checked = AppSettings.ShowNonPrintingChars; showNonprintableCharactersToolStripMenuItem.Checked = AppSettings.ShowNonPrintingChars; ToggleNonPrintingChars(AppSettings.ShowNonPrintingChars); IsReadOnly = true; var encodingList = AppSettings.AvailableEncodings.Values.Select(e => e.EncodingName).ToList(); var defaultEncodingName = Encoding.Default.EncodingName; for (int i = 0; i < encodingList.Count; i++) { if (string.Equals(encodingList[i], defaultEncodingName, StringComparison.OrdinalIgnoreCase)) { encodingList[i] = "Default (" + Encoding.Default.HeaderName + ")"; break; } } encodingToolStripComboBox.Items.AddRange(encodingList.ToArray <object>()); _internalFileViewer.MouseMove += (_, e) => { if (_currentViewIsPatch && !fileviewerToolbar.Visible) { fileviewerToolbar.Visible = true; fileviewerToolbar.Location = new Point(Width - fileviewerToolbar.Width - 40, 0); fileviewerToolbar.BringToFront(); } }; _internalFileViewer.MouseLeave += (_, e) => { if (GetChildAtPoint(PointToClient(MousePosition)) != fileviewerToolbar && fileviewerToolbar != null) { fileviewerToolbar.Visible = false; } }; _internalFileViewer.TextChanged += (sender, e) => { if (_patchHighlighting) { _internalFileViewer.AddPatchHighlighting(); } TextChanged?.Invoke(sender, e); }; _internalFileViewer.ScrollPosChanged += (sender, e) => ScrollPosChanged?.Invoke(sender, e); _internalFileViewer.SelectedLineChanged += (sender, e) => SelectedLineChanged?.Invoke(sender, e); _internalFileViewer.DoubleClick += (_, args) => RequestDiffView?.Invoke(this, EventArgs.Empty); HotkeysEnabled = true; if (!IsDesignModeActive && ContextMenuStrip == null) { ContextMenuStrip = contextMenu; } contextMenu.Opening += (sender, e) => { copyToolStripMenuItem.Enabled = _internalFileViewer.GetSelectionLength() > 0; ContextMenuOpening?.Invoke(sender, e); }; _fullPathResolver = new FullPathResolver(() => Module.WorkingDir); }
void ContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) { copyToolStripMenuItem.Enabled = (_internalFileViewer.GetSelectionLength() > 0); ContextMenuOpening?.Invoke(sender, e); }
/// <summary> /// Raises the context menu opening. /// </summary> /// <param name="listBoxItem">The list box item.</param> private void RaiseContextMenuOpening(ListBoxItem listBoxItem) { ContextMenuOpening?.Invoke(listBoxItem); }
/// <summary> /// Raises the context menu opening. /// </summary> private void RaiseContextMenuOpening() { ContextMenuOpening?.Invoke(this, EventArgs.Empty); }
private void ContextMenu_Opening(object sender, CancelEventArgs e) { copyToolStripMenuItem.Enabled = _internalFileViewer.GetSelectionLength() > 0; ContextMenuOpening?.Invoke(sender, e); }
/// <summary> /// Creates a context menu. /// </summary> /// <param name="parms"></param> /// <param name="model"></param> /// <param name="webBrowser"></param> public void ShowContextMenu(PositionAndDocumentType parms, AppModel model, WebBrowser webBrowser) { var ctm = new ContextMenu(); MenuItem mi; // Image Selected if (!string.IsNullOrEmpty(parms.Src)) { mi = new MenuItem() { Header = "Copy Image to Clipboard" }; mi.Click += (o, args) => { string image = null; bool deleteFile = false; if (parms.Src.StartsWith("https://") || parms.Src.StartsWith("http://")) { image = HttpUtils.DownloadImageToFile(parms.Src); if (string.IsNullOrEmpty(image)) { model.Window.ShowStatusError("Unable to copy image from URL to clipboard: " + parms.Src); return; } deleteFile = true; } else { try { image = new Uri(parms.Src).LocalPath; } catch { image = FileUtils.NormalizePath(parms.Src); } image = mmFileUtils.NormalizeFilenameWithBasePath(image, Path.GetDirectoryName(model.ActiveDocument.Filename)); } try { BitmapSource bmpSrc; using (var bmp = new Bitmap(image)) { bmpSrc = WindowUtilities.BitmapToBitmapSource(bmp); Clipboard.SetImage(bmpSrc); } model.Window.ShowStatusSuccess("Image copied to clipboard."); } catch (Exception ex) { model.Window.ShowStatusError("Couldn't copy image to clipboard: " + ex.Message); } finally { if (deleteFile && File.Exists(image)) { File.Delete(image); } } }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "Edit Image in Image editor" }; mi.Click += (o, args) => { string image = null; if (parms.Src.StartsWith("https://") || parms.Src.StartsWith("http://")) { image = HttpUtils.DownloadImageToFile(parms.Src); if (string.IsNullOrEmpty(image)) { model.Window.ShowStatusError("Unable to copy image from URL to clipboard: " + parms.Src); return; } } else { try { image = new Uri(parms.Src).LocalPath; } catch { image = FileUtils.NormalizePath(parms.Src); } image = mmFileUtils.NormalizeFilenameWithBasePath(image, Path.GetDirectoryName(model.ActiveDocument.Filename)); } mmFileUtils.OpenImageInImageEditor(image); }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); } // HREF link selected if (!string.IsNullOrEmpty(parms.Href)) { // Navigate relative hash links in the document if (parms.Href.StartsWith("#") && parms.Href.Length > 1) { var docModel = new DocumentOutlineModel(); int lineNo = docModel.FindHeaderHeadline(model.ActiveEditor?.GetMarkdown(), parms.Href?.Substring(1)); if (lineNo > -1) { mi = new MenuItem() { Header = "Jump to: " + parms.Href, CommandParameter = parms.Href.Substring(1) }; mi.Click += (s, e) => { var mitem = s as MenuItem; var anchor = mitem.CommandParameter as string; if (string.IsNullOrEmpty(anchor)) { return; } docModel = new DocumentOutlineModel(); lineNo = docModel.FindHeaderHeadline(model.ActiveEditor?.GetMarkdown(), anchor); if (lineNo != -1) { model.ActiveEditor.GotoLine(lineNo); } }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); } } } // ID to clipboard if (!string.IsNullOrEmpty(parms.Id)) { mi = new MenuItem() { Header = "Copy Id to Clipboard: #" + parms.Id, }; mi.Click += (s, e) => { ClipboardHelper.SetText("#" + parms.Id); model.Window.ShowStatusSuccess("'#" + parms.Id + "' copied to the clipboard."); }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); } mi = new MenuItem() { Header = "View in Web _Browser", Command = model.Commands.ViewInExternalBrowserCommand, InputGestureText = model.Commands.ViewInExternalBrowserCommand.KeyboardShortcut }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "Refresh _Browser", Command = model.Commands.RefreshPreviewCommand, InputGestureText = "F5" }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "View Html _Source", Command = model.Commands.ViewHtmlSourceCommand }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); mi = new MenuItem() { Header = "Save As _Html", Command = model.Commands.SaveAsHtmlCommand, }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "Save As _PDF", Command = model.Commands.GeneratePdfCommand, }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "P_rint...", Command = model.Commands.PrintPreviewCommand, }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); mi = new MenuItem() { Header = "Edit Preview _Theme", Command = model.Commands.EditPreviewThemeCommand, }; ctm.Items.Add(mi); mi = new MenuItem() { Header = "Configure Preview Syncing", Command = model.Commands.PreviewSyncModeCommand, }; ctm.Items.Add(mi); ctm.Items.Add(new Separator()); mi = new MenuItem() { Header = "Toggle Preview Window", Command = model.Commands.TogglePreviewBrowserCommand, IsCheckable = true, InputGestureText = model.Commands.TogglePreviewBrowserCommand.KeyboardShortcut, IsChecked = model.IsPreviewBrowserVisible }; ctm.Items.Add(mi); webBrowser.ContextMenu = ctm; ContextMenuOpening?.Invoke(this, ctm); ctm.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; ctm.PlacementTarget = webBrowser; ctm.IsOpen = true; }
internal void OnContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) { ContextMenuOpening?.Invoke(sender, e); ActiveItem = e.Cell.Row.Data; }