Пример #1
0
 public CtrlBrowser(MyBrowserInfo pMyBrowserInfo)
 {
     InitializeComponent();
     myBrowserInfo = pMyBrowserInfo;
     //myCustomMenuHandler = pMyCustomMenuHandler;
     webBrowser.MenuHandler = myCustomMenuHandler;
     //webBrowser.Tag = 50;
     //webBrowser.SetZoomLevel(myBrowserInfo.Zoom / 100.0);
     webBrowser.Tag = pMyBrowserInfo;
     tsZoom.Text    = myBrowserInfo.Zoom.ToString(CultureInfo.CurrentCulture) + "%";
 }
Пример #2
0
        private void ReloadDicts()
        {
            lstMyBrowserInfo.Clear();
            foreach (var mb in lstMenuBrowser)
            {
                if (mb.FrmTranslateModal != null)
                {
                    try { mb.FrmTranslateModal.webbrsr.Dispose(); } catch { }
                    try { mb.FrmTranslateModal.Dispose(); } catch { }
                    mb.FrmTranslateModal = null;
                }
            }
            lstMenuBrowser.Clear();

            int          command            = 29502;
            const string MY_SEPARATOR       = "@@@@@@@@";
            string       path               = Path.GetDirectoryName(Application.ExecutablePath);
            var          lines              = File.ReadAllLines(Path.Combine(path, "mydicts.txt"));
            bool         isInRightClickDict = false;
            string       error              = string.Empty;

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.StartsWith("#"))
                {
                    continue;
                }
                if (line.StartsWith("[right_click_dict]", StringComparison.CurrentCultureIgnoreCase))
                {
                    isInRightClickDict = true;
                    continue;
                }
                if (!line.Contains("%WORD%"))
                {
                    error = error + Environment.NewLine + "LINE:" + line + " conatins no %WORD%";
                }
                string[] ar = line.Split(new string[] { MY_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
                if (isInRightClickDict)
                {
                    MenuBrowser menuBrowser = new MenuBrowser();
                    menuBrowser.Command = command++;
                    menuBrowser.Url     = ar[0];
                    if (ar.Length >= 2)
                    {
                        menuBrowser.Name = ar[1];
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(menuBrowser.Url);
                            menuBrowser.Name = uri.Host;
                        }
                        catch
                        {
                        }
                    }

                    if (ar.Length >= 2 && ar[2].StartsWith("f", StringComparison.CurrentCultureIgnoreCase))
                    {
                        menuBrowser.Shortcut = ar[2].ToUpper();
                    }
                    lstMenuBrowser.Add(menuBrowser);
                }
                else
                {
                    MyBrowserInfo info = new MyBrowserInfo();
                    info.Url = ar[0];
                    if (ar.Length >= 2)
                    {
                        info.Name = ar[1];
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(info.Url);
                            info.Name = uri.Host;
                        }
                        catch
                        {
                        }
                    }
                    for (int i = 2; i < ar.Length; i++)
                    {
                        string[] ar2 = ar[i].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                        if (ar2[0].Equals("scrolldown", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.ScrollDown = Convert.ToInt32(ar2[1]);
                        }
                        //else if (ar2[0].Equals("scrollleft", StringComparison.CurrentCultureIgnoreCase))
                        //    info.ScrollLeft = Convert.ToInt32(ar2[1]);
                        else if (ar2[0].Equals("scrollright", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.ScrollRight = Convert.ToInt32(ar2[1]);
                        }
                        else if (ar2[0].Equals("zoomlevel", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.Zoom = Convert.ToInt32(ar2[1]);
                        }
                        else
                        {
                            throw new Exception("Error in line:" + line);
                        }
                    }
                    lstMyBrowserInfo.Add(info);
                }
            }
            this.SuspendLayout();
            pnlShortcuts.SuspendLayout();
            pnlShortcuts.Controls.Clear();
            MyLabel lblMyCopy = new MyLabel();

            lblMyCopy.AutoSize    = true;
            lblMyCopy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            lblMyCopy.Padding     = new System.Windows.Forms.Padding(2);
            lblMyCopy.Text        = "Only Copy = F2";
            lblMyCopy.MouseClick += LblMyCopy_MouseClick;;
            lblMyCopy.Cursor      = Cursors.Hand;

            pnlShortcuts.Controls.Add(lblMyCopy);

            foreach (MenuBrowser l_menuBrowser in lstMenuBrowser)
            {
                if (!string.IsNullOrEmpty(l_menuBrowser.Shortcut) && l_menuBrowser.Shortcut.StartsWith("f", StringComparison.CurrentCultureIgnoreCase))
                {
                    MyLabel lbl = new MyLabel();
                    lbl.AutoSize = true;
                    lbl.Text     = l_menuBrowser.Name + " [" + l_menuBrowser.Shortcut + "]";
                    //mainMenu.Items.Add(lbl.Text);
                    lbl.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                    lbl.Padding           = new System.Windows.Forms.Padding(2);
                    lbl.Margin            = new Padding(1);
                    lbl.Tag               = l_menuBrowser;
                    lbl.MouseClick       += Lbl_MouseClick;
                    lbl.MouseDoubleClick += Lbl_MouseDoubleClick;
                    lbl.Cursor            = Cursors.Hand;
                    pnlShortcuts.Controls.Add(lbl);
                }
            }
            pnlShortcuts.ResumeLayout();

            tabCtrlMain.SuspendLayout();
            foreach (var br in lstCtrlBrowser)
            {
                br.Dispose();
            }
            lstCtrlBrowser.Clear();
            tabCtrlMain.TabPages.Clear();
            foreach (MyBrowserInfo myBrowserInfo in lstMyBrowserInfo)
            {
                TabPage     tabPage     = new TabPage(myBrowserInfo.Name);
                CtrlBrowser ctrlBrowser = new CtrlBrowser(myBrowserInfo);
                ctrlBrowser.Dock = DockStyle.Fill;
                //ctrlBrowser.myBrowserInfo = myBrowserInfo;
                ctrlBrowser.lstMenuBrowser = lstMenuBrowser;
                MyCustomMenuHandler myCustomMenuHandler = new MyCustomMenuHandler(this, ctrlBrowser.webBrowser, lstMenuBrowser);

                ctrlBrowser.myCustomMenuHandler        = myCustomMenuHandler;
                ctrlBrowser.webBrowser.KeyboardHandler = new MyKeyboardHandler(this, ctrlBrowser);
                tabPage.Controls.Add(ctrlBrowser);
                tabCtrlMain.TabPages.Add(tabPage);
                lstCtrlBrowser.Add(ctrlBrowser);
            }
            tabCtrlMain.ResumeLayout();
            this.ResumeLayout();
            if (!string.IsNullOrEmpty(error))
            {
                Helper.ERRORMSG(error);
            }
        }