Ejemplo n.º 1
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);
            }
        }