public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { #if DEBUG return(false); #else return(true); #endif }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(true); }
/// <inheritdoc /> public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(false); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return false; //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread //var menuItems = GetMenuItems(model); //chromiumWebBrowser.Dispatcher.Invoke(() => //{ // var menu = new ContextMenu // { // IsOpen = true // }; // RoutedEventHandler handler = null; // handler = (s, e) => // { // menu.Closed -= handler; // //If the callback has been disposed then it's already been executed // //so don't call Cancel // if(!callback.IsDisposed) // { // callback.Cancel(); // } // }; // menu.Closed += handler; // foreach (var item in menuItems) // { // menu.Items.Add(new MenuItem // { // Header = item.Item1, // Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); }) // }); // } // chromiumWebBrowser.ContextMenu = menu; //}); //return true; }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { callback.Dispose(); ActionExtension.InvokeInMainThread(() => { var menu = new ContextMenu { Items = { new MenuItem { Header = "Back", Command = new DelegateCommand(browser.GoBack, () => browser.CanGoBack) }, new MenuItem { Header = "Forward", Command = new DelegateCommand(browser.GoForward, () => browser.CanGoForward) }, new MenuItem { Header = "Refresh", Command = new DelegateCommand(() => browser.Reload(true)) }, new Separator(), new MenuItem { Header = "Select All", Command = new DelegateCommand(() => browser.FocusedFrame.SelectAll()) }, new MenuItem { Header = "Open Page In Default Browser", Command = new DelegateCommand <string>(WindowsHelper.ViewInBrowser), CommandParameter = frame.Url }, } }; menu.IsOpen = true; }); return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { callback.Dispose(); Application.Current.Dispatcher.Invoke(() => { var menu = new ContextMenu { Items = { new MenuItem { Header = "Back", Command = new DelegateCommand(browser.GoBack, () => browser.CanGoBack) }, new MenuItem { Header = "Forward", Command = new DelegateCommand(browser.GoForward, () => browser.CanGoForward) }, new MenuItem { Header = "Refresh", Command = new DelegateCommand(() => browser.Reload(true)) }, new Separator(), new MenuItem { Header = "Select All", Command = new DelegateCommand(() => browser.FocusedFrame.SelectAll()) }, new MenuItem { Header = "Open Page In Default Browser", Command = new DelegateCommand<string>(WindowsHelper.ViewInBrowser), CommandParameter = frame.Url }, } }; menu.IsOpen = true; }); return true; }
public override bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var menuItems = GetMenuItems(model).ToList(); var linkUrl = parameters.LinkUrl; var selectionText = parameters.SelectionText; wfChromiumWebBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { string header = string.Empty; if (item.commandId == CefMenuCommand.NotFound) { menu.Items.Add(new Separator()); continue; } switch (item.commandId) { case CefMenuCommand.Back: { header = LanguageManager.GetString("menu_back"); break; } case CefMenuCommand.Forward: { header = LanguageManager.GetString("menu_forward"); break; } case CefMenuCommand.Cut: { header = LanguageManager.GetString("menu_cut"); break; } case CefMenuCommand.Copy: { header = LanguageManager.GetString("menu_copy"); break; } case CefMenuCommand.Paste: { header = LanguageManager.GetString("menu_paste"); break; } case CefMenuCommand.Print: { header = LanguageManager.GetString("menu_print"); break; } case CefMenuCommand.ViewSource: { header = LanguageManager.GetString("menu_viewSource"); break; } case CefMenuCommand.Undo: { header = LanguageManager.GetString("menu_undo"); break; } case CefMenuCommand.StopLoad: { header = LanguageManager.GetString("menu_stop"); break; } case CefMenuCommand.SelectAll: { header = LanguageManager.GetString("menu_selectAll"); break; } case CefMenuCommand.Redo: { header = LanguageManager.GetString("menu_redo"); break; } case CefMenuCommand.Find: { header = LanguageManager.GetString("menu_find"); break; } case CefMenuCommand.AddToDictionary: { header = LanguageManager.GetString("menu_addToDictionary"); break; } case CefMenuCommand.Reload: { header = LanguageManager.GetString("menu_reload"); break; } case CefMenuCommand.ReloadNoCache: { header = LanguageManager.GetString("menu_reloadNoCache"); break; } case OpenInNewWindow: { header = string.Format(LanguageManager.GetString(item.header), linkUrl); break; } case Search: { var tmp = selectionText.Length > 32 ? selectionText.Substring(0, 32) + "..." : selectionText; header = string.Format(LanguageManager.GetString(item.header), tmp.Replace('\n', ' ')); break; } default: { header = item.header; break; } } menu.Items.Add(new MenuItem { Header = header, Command = new DelegateCommand { CanExecute = item.isEnable, Execute = obj => callback.Continue(item.commandId, CefEventFlags.None) } }); } wfChromiumWebBrowser.ContextMenu = menu; }); return(true); }
public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { // Suppress the context menu. return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return true; }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { // return true; //绘制了一遍菜单栏 所以初始化的时候不必绘制菜单栏,再此处绘制即可 var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; chromiumWebBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; menu.Items.Add(new MenuItem { Header = "最小化", // Command = new CustomCommand(MinWindow) }); menu.Items.Add(new MenuItem { Header = "关闭", // Command = new CustomCommand(CloseWindow) }); chromiumWebBrowser.ContextMenu = menu; }); return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(false); //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread //var menuItems = GetMenuItems(model); //chromiumWebBrowser.Dispatcher.Invoke(() => //{ // var menu = new ContextMenu // { // IsOpen = true // }; // RoutedEventHandler handler = null; // handler = (s, e) => // { // menu.Closed -= handler; // //If the callback has been disposed then it's already been executed // //so don't call Cancel // if(!callback.IsDisposed) // { // callback.Cancel(); // } // }; // menu.Closed += handler; // foreach (var item in menuItems) // { // menu.Items.Add(new MenuItem // { // Header = item.Item1, // Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); }) // }); // } // chromiumWebBrowser.ContextMenu = menu; //}); //return true; }
bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(RunContextMenu(chromiumWebBrowser, browser, frame, parameters, model, callback)); }
/// <summary> /// The run context menu. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="model"> /// The model. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(false); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { model.SetEnabled(CefMenuCommand.Cut, false); return(false); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //throw new NotImplementedException(); return(true); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //NOTE: Return false to use the built in Context menu - in WPF this requires you integrate into your existing message loop, read the General Usage Guide for more details //https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop //return false; var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model).ToList(); webBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { if (item.Item2 == CefMenuCommand.NotFound && string.IsNullOrWhiteSpace(item.Item1)) { menu.Items.Add(new Separator()); continue; } menu.Items.Add(new MenuItem { Header = item.Item1.Replace("&", "_"), IsEnabled = item.Item3, Command = new RelayCommand(() => { //BUG: CEF currently not executing callbacks correctly so we manually map the commands below //see https://github.com/cefsharp/CefSharp/issues/1767 //The following line worked in previous versions, it doesn't now, so custom EXAMPLE below //callback.Continue(item.Item2, CefEventFlags.None); //NOTE: Note all menu item options below have been tested, you can work out the rest switch (item.Item2) { case CefMenuCommand.Back: { browser.GoBack(); break; } case CefMenuCommand.Forward: { browser.GoForward(); break; } case CefMenuCommand.Cut: { browser.FocusedFrame.Cut(); break; } case CefMenuCommand.Copy: { browser.FocusedFrame.Copy(); break; } case CefMenuCommand.Paste: { browser.FocusedFrame.Paste(); break; } case CefMenuCommand.Print: { browser.GetHost().Print(); break; } case CefMenuCommand.ViewSource: { browser.FocusedFrame.ViewSource(); break; } case CefMenuCommand.Undo: { browser.FocusedFrame.Undo(); break; } case CefMenuCommand.StopLoad: { browser.StopLoad(); break; } case CefMenuCommand.SelectAll: { browser.FocusedFrame.SelectAll(); break; } case CefMenuCommand.Redo: { browser.FocusedFrame.Redo(); break; } case CefMenuCommand.Find: { browser.GetHost().Find(0, parameters.SelectionText, true, false, false); break; } case CefMenuCommand.AddToDictionary: { browser.GetHost().AddWordToDictionary(parameters.MisspelledWord); break; } case CefMenuCommand.Reload: { browser.Reload(); break; } case CefMenuCommand.ReloadNoCache: { browser.Reload(ignoreCache: true); break; } case (CefMenuCommand)26501: { browser.GetHost().ShowDevTools(); break; } case (CefMenuCommand)26502: { browser.GetHost().CloseDevTools(); break; } } }) }); } webBrowser.ContextMenu = menu; }); return(true); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model).ToList(); chromiumWebBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { if (item.Item2 == CefMenuCommand.NotFound && string.IsNullOrWhiteSpace(item.Item1)) { menu.Items.Add(new Separator()); continue; } menu.Items.Add(new MenuItem { Header = item.Item1.Replace("&", "_"), IsEnabled = item.Item3, Command = new RelayCommand(x => _menuSetup(item.Item2)) }); } chromiumWebBrowser.ContextMenu = menu; }); return(true); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //绘制了一遍菜单栏 所以初始化的时候不必绘制菜单栏,再此处绘制即可 var WebBrowser = (ChromiumWebBrowser)chromiumWebBrowser; WebBrowser.Invoke(new Action(() => { })); var menu = new ContextMenu(); //var menu = new ContextMenu //{ // IsOpen = true //}; //RoutedEventHandler handler = null; //handler = (s, e) => //{ // menu.Closed -= handler; // //If the callback has been disposed then it's already been executed // //so don't call Cancel // if (!callback.IsDisposed) // { // callback.Cancel(); // } //}; //menu.Closed += handler; var mi = new MenuItem(); mi.Text = "最小化"; mi.Click += Mi_Click; menu.MenuItems.Add(mi); //menu.Items.Add(new MenuItem //{ // Header = "关闭", // Command = new CustomCommand(CloseWindow) //}); WebBrowser.ContextMenu = menu; return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { Console.WriteLine(@"RunContextMenu"); return(false); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; chromiumWebBrowser.Dispatcher.Invoke(new Action(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; var showDevOp = new MenuItem { Header = "Show DevTools", }; showDevOp.Click += delegate(object obj, RoutedEventArgs ev) { chromiumWebBrowser.ShowDevTools(); }; menu.Items.Add(showDevOp); chromiumWebBrowser.ContextMenu = menu; })); return(true); }
public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { if (ctxMenuCallback == null) { // Suppress the context menu. return(true); } else { return(ctxMenuCallback(parameters.XCoord, parameters.YCoord)); } }
bool IContextMenuHandler.RunContextMenu( IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //NOTE: Return false to use the built in Context menu - // in WPF this requires you integrate into your existing message loop, // read the General Usage Guide for more details //https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop //return false; var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; //IMenuModel is only valid in the context of this method, // so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model).ToList(); webBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { if (item.Item2 == CefMenuCommand.NotFound && string.IsNullOrWhiteSpace(item.Item1)) { menu.Items.Add(new Separator()); continue; } menu.Items.Add(new MenuItem { Header = item.Item1.Replace("&", "_"), IsEnabled = item.Item3, Command = new RelayCommand(() => ProcessMenu(item, browser, parameters), keepTargetAlive: true) }); } webBrowser.ContextMenu = menu; }); return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(false);//返回true则不显示,返回false则显示 }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var webBrowser = (ChromiumWebBrowser)browserControl; model.SetEnabled(CefMenuCommand.Back, webBrowser.CanGoBack); model.SetEnabled(CefMenuCommand.Forward, webBrowser.CanGoForward); model.SetEnabled(CefMenuCommand.SelectAll, webBrowser.CanSelect); //var menuItems = GetMenuItems(model).ToList(); //menuItems.ForEach(m => //{ // if(m.Item3 == CefMenuCommand.Back) // { // if (!webBrowser.CanGoBack) // { // } // } //}); #region MyRegion //webBrowser.Invoke(new Action(() => //{ // foreach (var item in menuItems) // { // switch (item.Item2) // { // case CefMenuCommand.Back: // { // //browser.GoBack(); // break; // } // case CefMenuCommand.Forward: // { // //browser.GoForward(); // break; // } // case CefMenuCommand.Cut: // { // //browser.FocusedFrame.Cut(); // break; // } // case CefMenuCommand.Copy: // { // //browser.FocusedFrame.Copy(); // break; // } // case CefMenuCommand.Paste: // { // //browser.FocusedFrame.Paste(); // break; // } // case CefMenuCommand.Print: // { // //browser.GetHost().Print(); // break; // } // case CefMenuCommand.ViewSource: // { // //browser.FocusedFrame.ViewSource(); // break; // } // case CefMenuCommand.Undo: // { // //browser.FocusedFrame.Undo(); // break; // } // case CefMenuCommand.StopLoad: // { // //browser.StopLoad(); // break; // } // case CefMenuCommand.SelectAll: // { // //browser.FocusedFrame.SelectAll(); // break; // } // case CefMenuCommand.Redo: // { // //browser.FocusedFrame.Redo(); // break; // } // case CefMenuCommand.Find: // { // //browser.GetHost().Find(0, parameters.SelectionText, true, false, false); // break; // } // case CefMenuCommand.AddToDictionary: // { // //browser.GetHost().AddWordToDictionary(parameters.MisspelledWord); // break; // } // case CefMenuCommand.Reload: // { // //browser.Reload(); // break; // } // case CefMenuCommand.ReloadNoCache: // { // //browser.Reload(ignoreCache: true); // break; // } // case (CefMenuCommand)26501: // { // //browser.GetHost().ShowDevTools(); // break; // } // case (CefMenuCommand)26502: // { // //browser.GetHost().CloseDevTools(); // break; // } // } // } //})); #endregion return(false); // 弹出 }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { if (model.Count == 0) { // No menu if 0 items (flash) return(true); } var chromium = (ChromiumWebBrowser)browserControl; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model); ActionExtension.InvokeInMainThread(() => { var contextMenu = new ContextMenu(); if (menuItems.ArrayContains(CefMenuCommand.Cut)) { contextMenu.Items.Add(new MenuItem { Header = "Cut", Command = chromium.CutCommand }); } if (menuItems.ArrayContains(CefMenuCommand.Copy)) { contextMenu.Items.Add(new MenuItem { Header = "Copy", Command = chromium.CopyCommand }); } if (menuItems.ArrayContains(CefMenuCommand.Paste)) { contextMenu.Items.Add(new MenuItem { Header = "Paste", Command = chromium.PasteCommand }); } if (contextMenu.Items.Count > 1) { contextMenu.Items.Add(new Separator()); } if (menuItems.ArrayContains(CefMenuCommand.SelectAll)) { contextMenu.Items.Add(new MenuItem { Header = "Select all", Command = chromium.SelectAllCommand }); } if (contextMenu.Items.Count > 0) { contextMenu.Items.Add(new Separator()); } contextMenu.Items.Add(new MenuItem { Header = "Back", Command = new DelegateCommand(browser.GoBack, () => !browser.IsDisposed && browser.CanGoBack) }); contextMenu.Items.Add(new MenuItem { Header = "Forward", Command = new DelegateCommand(browser.GoForward, () => !browser.IsDisposed && browser.CanGoForward) }); contextMenu.Items.Add(new MenuItem { Header = "Refresh", Command = new DelegateCommand(() => browser.Reload(true)) }); contextMenu.Items.Add(new Separator()); contextMenu.Items.Add(new MenuItem { Header = "Open page in default browser", Command = new DelegateCommand <string>(WindowsHelper.ViewInBrowser), CommandParameter = frame.Url }); contextMenu.Items.Add(new MenuItem { Header = "Show developer tools", Command = new DelegateCommand(() => browser.ShowDevTools()) }); chromium.ContextMenu = contextMenu; contextMenu.IsOpen = true; }); callback.Cancel(); return(true); }
public bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(false); //throw new System.NotImplementedException(); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //return false; //绘制了一遍菜单栏 所以初始化的时候不必绘制菜单栏,再此处绘制即可 var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread //var menuItems = GetMenuItems(model); chromiumWebBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; //foreach (var item in menuItems) //{ // menu.Items.Add(new MenuItem // { // Header = item.Item1, // Command = MinWindow // }); //} menu.Items.Add(new MenuItem { Header = "最小化", Command = new CustomCommand(MinWindow) }); menu.Items.Add(new MenuItem { Header = "关闭", Command = new CustomCommand(CloseWindow) }); chromiumWebBrowser.ContextMenu = menu; }); return(true); //以下方法是,获取初始化的菜单栏,对其进行加载,稍微有点问题,事件不响应 //参考:https://github.com/cefsharp/CefSharp/issues/1795 //var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; ////IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread //var menuItems = GetMenuItems(model); //chromiumWebBrowser.Dispatcher.Invoke(() => //{ // var menu = new ContextMenu // { // IsOpen = true // }; // RoutedEventHandler handler = null; // handler = (s, e) => // { // menu.Closed -= handler; // //If the callback has been disposed then it's already been executed // //so don't call Cancel // if (!callback.IsDisposed) // { // callback.Cancel(); // } // }; // menu.Closed += handler; // foreach (var item in menuItems) // { // menu.Items.Add(new MenuItem // { // Header = item.Item1, // Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.LeftMouseButton); }) // }); // } // chromiumWebBrowser.ContextMenu = menu; //}); //return true; }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { // show default menu return(false); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return false; }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { //return false 才可以弹出;如果需要完完全全对右键菜单进行重构的话,这里也可以实现,实现菜单命令的处理过程;; return(false); }
bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model); chromiumWebBrowser.Dispatcher.Invoke(() => { var menu = new ContextMenu { IsOpen = true }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { menu.Items.Add(new MenuItem { Header = item.Item1, Command = new RelayCommand(() => { callback.Continue(item.Item2, CefEventFlags.None); }) }); } chromiumWebBrowser.ContextMenu = menu; }); return(true); }
public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return(!_settings.EnableDebugMenu); }
/// <inheritdoc/> protected override bool RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { var webBrowser = (ChromiumWebBrowser)chromiumWebBrowser; //IMenuModel is only valid in the context of this method, so need to read the values before invoking on the UI thread var menuItems = GetMenuItems(model); var dictionarySuggestions = parameters.DictionarySuggestions; var xCoord = parameters.XCoord; var yCoord = parameters.YCoord; var misspelledWord = parameters.MisspelledWord; var selectionText = parameters.SelectionText; webBrowser.UiThreadRunAsync(() => { var menu = new ContextMenu { IsOpen = true, Placement = PlacementMode.Mouse }; RoutedEventHandler handler = null; handler = (s, e) => { menu.Closed -= handler; //If the callback has been disposed then it's already been executed //so don't call Cancel if (!callback.IsDisposed) { callback.Cancel(); } }; menu.Closed += handler; foreach (var item in menuItems) { if (item.CommandId == CefMenuCommand.NotFound) { continue; } if (item.IsSeperator) { menu.Items.Add(new Separator()); continue; } var menuItem = new MenuItem { Header = item.Label.Replace("&", "_"), IsEnabled = item.IsEnabled, IsChecked = item.IsChecked.GetValueOrDefault(), IsCheckable = item.IsChecked.HasValue, Command = new DelegateCommand(() => { //BUG: CEF currently not executing callbacks correctly so we manually map the commands below //see https://github.com/cefsharp/CefSharp/issues/1767 //The following line worked in previous versions, it doesn't now, so custom handling below //callback.Continue(item.Item2, CefEventFlags.None); ExecuteCommand(browser, new ContextMenuExecuteModel(item.CommandId, dictionarySuggestions, xCoord, yCoord, selectionText, misspelledWord)); }), }; //TODO: Make this recursive and remove duplicate code if (item.SubMenus != null && item.SubMenus.Count > 0) { foreach (var subItem in item.SubMenus) { if (subItem.CommandId == CefMenuCommand.NotFound) { continue; } if (subItem.IsSeperator) { menu.Items.Add(new Separator()); continue; } var subMenuItem = new MenuItem { Header = subItem.Label.Replace("&", "_"), IsEnabled = subItem.IsEnabled, IsChecked = subItem.IsChecked.GetValueOrDefault(), IsCheckable = subItem.IsChecked.HasValue, Command = new DelegateCommand(() => { //BUG: CEF currently not executing callbacks correctly so we manually map the commands below //see https://github.com/cefsharp/CefSharp/issues/1767 //The following line worked in previous versions, it doesn't now, so custom handling below //callback.Continue(item.Item2, CefEventFlags.None); ExecuteCommand(browser, new ContextMenuExecuteModel(subItem.CommandId, dictionarySuggestions, xCoord, yCoord, selectionText, misspelledWord)); }), }; menuItem.Items.Add(subMenuItem); } } menu.Items.Add(menuItem); } webBrowser.ContextMenu = menu; }); return(true); }
public bool RunContextMenu(IWebBrowser browserControl, CefSharp.IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback) { return false; }