Esempio n. 1
0
        string GetNewTemplateName()
        {
            var input = new InputComboDialog("TeX2img", Properties.Resources.INPUTE_TEMPLATE_NAME, null);

            input.OKButtonClicked += ((sss, eee) => {
                if (invalidTemplateNames.Contains(eee.InputedText))
                {
                    MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
                    eee.Cancel = true;
                }
                else if (Templates.ContainsKey(eee.InputedText))
                {
                    if (MessageBox.Show(String.Format(Properties.Resources.OVERWRITEMSG, eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                    {
                        eee.Cancel = true;
                    }
                }
            });
            if (input.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                return(input.InputedText);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 string GetNewTemplateName() {
     var input = new InputComboDialog("TeX2img", Properties.Resources.INPUTE_TEMPLATE_NAME, null);
     input.OKButtonClicked += ((sss, eee) => {
         if (invalidTemplateNames.Contains(eee.InputedText)) {
             MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
             eee.Cancel = true;
         } else if (Templates.ContainsKey(eee.InputedText)) {
             if (MessageBox.Show(String.Format(Properties.Resources.OVERWRITEMSG, eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) {
                 eee.Cancel = true;
             }
         }
     });
     if(input.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
         return input.InputedText;
     } else return null;
 }
Esempio n. 3
0
        private void TemplateButon_Click(object sender, EventArgs e) {
            string addItemStr = Properties.Resources.SAVE_CURRENT_PREAMBLE + "...";
            string manageItemStr = Properties.Resources.MANAGE_TEMPLATES + "...";
            var menu = new ContextMenuStrip();
            foreach(var d in Properties.Settings.Default.preambleTemplates) {
                menu.Items.Add(new ToolStripMenuItem(d.Key) { Tag = d.Key });
            }
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(addItemStr) { Tag = addItemStr });
            menu.Items.Add(new ToolStripMenuItem(manageItemStr) { Tag = manageItemStr });
            menu.ItemClicked += ((ss, ee) => {
                menu.Close();
                var tag = (string) ee.ClickedItem.Tag;
                if(tag == manageItemStr) {
                    var managedlg = new ManageTemplateDialog(Properties.Settings.Default.preambleTemplates, preambleTextBox.Text, new List<string> { manageItemStr, addItemStr ,""});
                    if(managedlg.ShowDialog(mainForm) == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates = managedlg.Templates;
                    }
                }else if(tag == addItemStr){
                    var input = new InputComboDialog(
                        Properties.Resources.ADD_TEMPLATEMSG,Properties.Resources.INPUTE_TEMPLATE_NAME,
                        Properties.Settings.Default.preambleTemplates.Select(d => d.Key).ToList());
                    input.OKButtonClicked += ((sss, eee) => {
                        if(eee.InputedText == manageItemStr || eee.InputedText == addItemStr || eee.InputedText == "") {
                            MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
                            eee.Cancel = true;
                        } else if(Properties.Settings.Default.preambleTemplates.ContainsKey(eee.InputedText)) {
                            if(MessageBox.Show(
                                String.Format(Properties.Resources.OVERWRITETEMPLATEMSG,eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) {
                                eee.Cancel = true;
                            }
                        }
                    });
                    if(input.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates[input.InputedText] = preambleTextBox.Text;
                    }
                } else {
                    try {
                        var text = Properties.Settings.Default.preambleTemplates[tag];
                        if(text != null) {
                            if(MessageBox.Show(String.Format(Properties.Resources.CHANGE_CURRENTPREAMBLE, text), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                preambleTextBox.Text = ChangeReturnCode(text);

                                var latex = Properties.Settings.Default.GuessPlatexPath(text, "");
                                var dvipdfmx = Properties.Settings.Default.GuessDvipdfmxPath(text, "");
                                string str = "";
                                if(latex != "") str += "\nlatex: " + latex;
                                if(dvipdfmx != "") str += "\nDVI driver: " + dvipdfmx;
                                if(str != "") {
                                    if(MessageBox.Show(String.Format(Properties.Resources.DETECT_RECOMMENDED_PATH, str), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                        if(latex != "") Properties.Settings.Default.platexPath = latex;
                                        if(dvipdfmx != "") Properties.Settings.Default.dvipdfmxPath = dvipdfmx;
                                    }
                                }
                            }
                        }
                    }
                    catch(KeyNotFoundException) { }
                    catch(ArgumentNullException) { }
                }
            });

            var btn = (Button) sender;
            menu.Show(btn, new Point(0, btn.Height));
        }
Esempio n. 4
0
        private void TemplateButon_Click(object sender, EventArgs e)
        {
            string addItemStr    = Properties.Resources.SAVE_CURRENT_PREAMBLE + "...";
            string manageItemStr = Properties.Resources.MANAGE_TEMPLATES + "...";
            var    menu          = new ContextMenuStrip();

            foreach (var d in Properties.Settings.Default.preambleTemplates)
            {
                menu.Items.Add(new ToolStripMenuItem(d.Key)
                {
                    Tag = d.Key
                });
            }
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(addItemStr)
            {
                Tag = addItemStr
            });
            menu.Items.Add(new ToolStripMenuItem(manageItemStr)
            {
                Tag = manageItemStr
            });
            menu.ItemClicked += ((ss, ee) => {
                menu.Close();
                var tag = (string)ee.ClickedItem.Tag;
                if (tag == manageItemStr)
                {
                    var managedlg = new ManageTemplateDialog(Properties.Settings.Default.preambleTemplates, preambleTextBox.Text, new List <string> {
                        manageItemStr, addItemStr, ""
                    });
                    if (managedlg.ShowDialog(mainForm) == System.Windows.Forms.DialogResult.OK)
                    {
                        Properties.Settings.Default.preambleTemplates = managedlg.Templates;
                    }
                }
                else if (tag == addItemStr)
                {
                    var input = new InputComboDialog(
                        Properties.Resources.ADD_TEMPLATEMSG, Properties.Resources.INPUTE_TEMPLATE_NAME,
                        Properties.Settings.Default.preambleTemplates.Select(d => d.Key).ToList());
                    input.OKButtonClicked += ((sss, eee) => {
                        if (eee.InputedText == manageItemStr || eee.InputedText == addItemStr || eee.InputedText == "")
                        {
                            MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
                            eee.Cancel = true;
                        }
                        else if (Properties.Settings.Default.preambleTemplates.ContainsKey(eee.InputedText))
                        {
                            if (MessageBox.Show(
                                    String.Format(Properties.Resources.OVERWRITETEMPLATEMSG, eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
                            {
                                eee.Cancel = true;
                            }
                        }
                    });
                    if (input.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Properties.Settings.Default.preambleTemplates[input.InputedText] = preambleTextBox.Text;
                    }
                }
                else
                {
                    try {
                        var text = Properties.Settings.Default.preambleTemplates[tag];
                        if (text != null)
                        {
                            if (MessageBox.Show(String.Format(Properties.Resources.CHANGE_CURRENTPREAMBLE, text), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                            {
                                preambleTextBox.Text = ChangeReturnCode(text);

                                var latex = Properties.Settings.Default.GuessPlatexPath(text, "");
                                var dvipdfmx = Properties.Settings.Default.GuessDvipdfmxPath(text, "");
                                string str = "";
                                if (latex != "")
                                {
                                    str += "\nlatex: " + latex;
                                }
                                if (dvipdfmx != "")
                                {
                                    str += "\nDVI driver: " + dvipdfmx;
                                }
                                if (str != "")
                                {
                                    if (MessageBox.Show(String.Format(Properties.Resources.DETECT_RECOMMENDED_PATH, str), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        if (latex != "")
                                        {
                                            Properties.Settings.Default.platexPath = latex;
                                        }
                                        if (dvipdfmx != "")
                                        {
                                            Properties.Settings.Default.dvipdfmxPath = dvipdfmx;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (KeyNotFoundException) { }
                    catch (ArgumentNullException) { }
                }
            });

            var btn = (Button)sender;

            menu.Show(btn, new Point(0, btn.Height));
        }