예제 #1
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            for (var index = model.Count - 1; index >= 0; index--)
            {
                var nCmd = model.GetCommandIdAt(index);

                if (!ContextMenuHelper.IsEdition(nCmd) && !ContextMenuHelper.IsUserDefined(nCmd))
                {
                    model.Remove(nCmd);
                }
            }

            if (WinFormium.Runtime.IsDebuggingMode && (state.ContextMenuType & CefContextMenuTypeFlags.Editable) != CefContextMenuTypeFlags.Editable)
            {
                if (model.Count > 0)
                {
                    model.AddSeparator();
                }

                model.AddItem((int)((CefMenuId)ContextMenuHelper.MenuIdentifier.MENU_ID_SHOW_DEVTOOLS), Resources.Messages.ContextMenu_ShowDevTools);
                model.AddItem((int)((CefMenuId)ContextMenuHelper.MenuIdentifier.MENU_ID_HIDE_DEVTOOLS), Resources.Messages.ContextMenu_CloseDevTools);
            }

            var e = new BeforeContextMenuEventArgs(frame, state, model);



            _owner.InvokeIfRequired(() => _owner.OnBeforeContextMenu(e));
        }
예제 #2
0
        /// <summary>
        /// The on before context menu.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            // To disable the menu then call clear
            model.Clear();

            // Removing existing menu item
            // Remove "View Source" option
            model.Remove((int)CefMenuId.ViewSource);

            // Add new custom menu items
            model.AddItem((int)((CefMenuId)ShowDevTools), "Show DevTools");
            model.AddItem((int)((CefMenuId)CloseDevTools), "Close DevTools");
        }
예제 #3
0
 protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams menuParams, CefMenuModel model)
 {
     //处理 鼠标右键的快捷键
     model.Clear();
     model.AddItem((int)CefMenuId.Copy, "复制");
     //model.AddItem((int)CefMenuId.ViewSource, AppResource.查看源);
 }
예제 #4
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            if (!webBrowser.menuVisible)
            {
                model.Clear();
            }
            int commandId = 1001;

            if (webBrowser.ContextMenu != null)
            {
                foreach (MenuItem item in webBrowser.ContextMenu.MenuItems)
                {
                    if (item.Text == "-")
                    {
                        model.AddSeparator();
                    }
                    else
                    {
                        model.AddItem(commandId, item.Text);
                    }
                    CommandItem commandItem = new CommandItem();
                    commandItem.id   = commandId;
                    commandItem.item = item;
                    commandItems.Add(commandItem);
                    commandId++;
                }
            }

            base.OnBeforeContextMenu(browser, frame, state, model);
        }
예제 #5
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams menuParams, CefMenuModel model)
        {
            var count = model.Count;

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    var commandId = (CefMenuId)model.GetCommandIdAt(i);
                    switch (commandId)
                    {
                    case CefMenuId.Undo:
                    case CefMenuId.Redo:
                    case CefMenuId.Cut:
                    case CefMenuId.Copy:
                    case CefMenuId.Paste:
                    case CefMenuId.Delete:
                    case CefMenuId.SelectAll:
                    case CefMenuId.Find:
                        break;

                    default:
                        break;
                    }
                }
            }

            if (AppHelper.EnableDevtools)
            {
                model.Remove((int)CefMenuId.Print);
                model.Remove((int)CefMenuId.ViewSource);
                if (model.Count >= 1)
                {
                    model.RemoveAt(model.Count - 1);
                }

                model.AddItem(SHOW_DEV_TOOLS, "&Show DevTools");
            }
            else
            {
                model.Clear(); // 禁用右键菜单
            }

            //model.InsertItemAt(model.Count > 0 ? 1 : 0, (int)CefMenuId.ReloadNocache, "Refresh");
            //model.AddSeparator();
            //model.AddItem(SHOW_DEV_TOOLS, "&Show DevTools");
            //model.AddItem(INSPECT_ELEMENT, "Inspect element");

            //CefMenuModel submenu = model.AddSubMenu(0, "Submenu Test");
            //submenu.AddItem((int)CefMenuId.Copy, "Copy");
            //submenu.AddItem((int)CefMenuId.Paste, "Paste");
            //submenu.SetColorAt(submenu.Count - 1, CefMenuColorType.Text, CefColor.FromArgb((int)Colors.Blue.ToUint32()));
            //submenu.AddCheckItem(0, "Checked Test");
            //submenu.SetCheckedAt(submenu.Count - 1, true);
            //submenu.AddRadioItem(0, "Radio Off", 0);
            //submenu.AddRadioItem(0, "Radio On", 1);
            //submenu.SetCheckedAt(submenu.Count - 1, true);
        }
예제 #6
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            model.Clear();//清除掉构建的菜单对象
            if (this._isShowMenu == false)
            {
                return;
            }


            //添加刷新菜单
            //model.AddItem((int)CefMenuId.ReloadNoCache, "强制刷新");
            model.AddItem((int)CefMenuId.Back, "返回");
            model.AddItem((int)CefMenuId.Forward, "前进");
            model.AddItem((int)CefMenuId.ReloadNoCache, "强制刷新");
            model.AddItem((int)CefMenuId.ViewSource, "查看源码");

            base.OnBeforeContextMenu(browser, frame, state, model);
        }
예제 #7
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams menuParams, CefMenuModel model)
        {
            model.InsertItemAt(model.Count > 0 ? 1 : 0, (int)CefMenuId.ReloadNocache, "Refresh");
            model.AddSeparator();
            model.AddItem(SHOW_DEV_TOOLS, "&Show DevTools");
            model.AddItem(INSPECT_ELEMENT, "Inspect element");


            CefMenuModel submenu = model.AddSubMenu(0, "Submenu Test");

            submenu.AddItem((int)CefMenuId.Copy, "Copy");
            submenu.AddItem((int)CefMenuId.Paste, "Paste");
            submenu.SetColorAt(submenu.Count - 1, CefMenuColorType.Text, CefColor.FromArgb(Colors.Blue.ToArgb()));
            submenu.AddCheckItem(0, "Checked Test");
            submenu.SetCheckedAt(submenu.Count - 1, true);
            submenu.AddRadioItem(0, "Radio Off", 0);
            submenu.AddRadioItem(0, "Radio On", 1);
            submenu.SetCheckedAt(submenu.Count - 1, true);
        }
        /// <summary>
        /// The on before context menu.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        /// <param name="frame">
        /// The frame.
        /// </param>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            base.OnBeforeContextMenu(browser, frame, state, model);
            for (int x = model.Count - 1; x > -1; x--)
            {
                var item = model.GetLabelAt(x);
                if (item == "&Back" || item == "&Forward" || item == "&Print…" || item == "&View page source")
                {
                    model.RemoveAt(x);
                }
            }

            if (model.Count == 1 && model.GetItemTypeAt(0).ToString() == "Separator")
            {
                model.RemoveAt(0);
            }

            model.AddItem((int)(CefMenuId)ShowDevTools, "Show DevTools");
            model.AddItem((int)(CefMenuId)Refresh, "Refresh");
        }
        public void Populate(ref CefMenuModel model, CefContextMenuParams context)
        {
            if (ShouldPopulate(context))
            {
                if (ChildItems != null && ChildItems.Count > 0)
                {
                    var childMenu = model.AddSubMenu(Id, Title);
                    AddChildItems(ref childMenu, context);
                }
                else
                {
                    switch (Type)
                    {
                    case "radio":
                        model.AddRadioItem(Id, Title, GroupId <= 0 ? 1 : GroupId);
                        if (Checked)
                        {
                            model.SetChecked(Id, true);
                        }
                        break;

                    case "checkbox":
                        model.AddCheckItem(Id, Title);
                        if (Checked)
                        {
                            model.SetChecked(Id, true);
                        }
                        break;

                    case "separator":
                        model.AddSeparator();
                        break;

                    default:
                        model.AddItem(Id, Title);
                        break;
                    }
                }
            }
        }
예제 #10
0
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            if (model.Count > 0)
            {
                model.Clear();
            }

            //bool removed = model.Remove(CefMenuCommand.ViewSource); // Remove "View Source" option
            if (state.LinkUrl != null || IsUrl(state.SelectionText))
            {
                model.AddItem(133, "新窗口中打开链接");
                model.AddItem(134, "复制链接");
                model.AddSeparator();
            }
            model.AddItem(135, "搜索此内容");

            if (state.MediaType == CefContextMenuMediaType.Image)
            {
                SearStr = state.SelectionText;
                model.AddItem(136, "图片另存为");
            }
            model.AddSeparator();

            model.AddItem(100, "复制");
            model.AddItem(114, "粘贴");
            model.AddSeparator();
            model.AddItem(200, "返回");
            model.AddItem(300, "前进");
            model.AddItem(350, "刷新");
            model.AddItem(113, "停止");
            model.AddSeparator();

            if (_core.Browser.GetHost() != null)
            {
                //  model.AddSeparator();
                model.AddItem(402, "打印此页");
                model.AddItem(401, "页面另存为PDF");
                model.AddSeparator();
            }
            if (!_core.DevToolsOpen)
            {
                model.AddItem(400, "打开调试工具");
            }
            else
            {
                model.AddItem(400, "关闭调试工具");
            }
            if (state.SelectionText != null)
            {
                model.SetEnabled(100, true);
            }
            else
            {
                model.SetEnabled(100, false);
            }
            if (Clipboard.GetText() == "")
            {
                model.SetEnabled(114, false);
            }
            else
            {
                model.SetEnabled(114, true);
            }


            if (state.SelectionText != "" && state.SelectionText != null)
            {
                SearStr = state.SelectionText;
                model.SetEnabled(135, true);
            }
            else
            {
                model.SetEnabled(135, false);
            }

            if (browser.IsLoading)
            {
                model.SetEnabled(113, true);
            }
            else
            {
                model.SetEnabled(113, false);
            }


            if (browser.CanGoBack)
            {
                model.SetEnabled(200, true);
            }
            else
            {
                model.SetEnabled(200, false);
            }
            if (browser.CanGoForward)
            {
                model.SetEnabled(300, true);
            }
            else
            {
                model.SetEnabled(300, false);
            }
        }
예제 #11
0
 protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
 {
     base.OnBeforeContextMenu(browser, frame, state, model);
     AddSeparator(model);
     model.AddItem(26500, "Open dev tools");
 }