예제 #1
0
파일: MainForm.cs 프로젝트: sw0/RegexTool
        private void tsmiLanguage_DropDownOpening(object sender, EventArgs e)
        {
            var ci = ResxManager.GetCultureInfo();

            if (tsmiLanguage.DropDownItems == null || tsmiLanguage.DropDownItems.Count == 0)
            {
                ToolStripMenuItem tsmi = null;
                {
                    var culture = CultureInfo.CreateSpecificCulture("en-us");
                    tsmi      = new ToolStripMenuItem();
                    tsmi.Name = "tsmiLanEnglish";
                    tsmi.Text = culture.DisplayName;
                    tsmi.Tag  = culture.Name;
                    if (ci == null || ci.DisplayName == culture.DisplayName)
                    {
                        tsmi.Checked = true;
                    }
                    tsmiLanguage.DropDownItems.Add(tsmi);
                    tsmi.Click += SwichLanguge_Click;
                }
                {
                    var culture = CultureInfo.CreateSpecificCulture("zh-CN");
                    tsmi      = new ToolStripMenuItem();
                    tsmi.Name = "tsmiLanChinese";
                    tsmi.Text = culture.DisplayName;
                    tsmi.Tag  = culture.Name;
                    if (ci != null && ci.DisplayName == culture.DisplayName)
                    {
                        tsmi.Checked = true;
                    }
                    tsmiLanguage.DropDownItems.Add(tsmi);
                    tsmi.Click += SwichLanguge_Click;
                }
                {
                    var culture = CultureInfo.CreateSpecificCulture("zh-tw");
                    tsmi      = new ToolStripMenuItem();
                    tsmi.Name = "tsmiLanTaiwan";
                    tsmi.Text = "繁体中文";
                    tsmi.Tag  = culture.Name;
                    if (ci != null && ci.DisplayName == culture.DisplayName)
                    {
                        tsmi.Checked = true;
                    }
                    tsmiLanguage.DropDownItems.Add(tsmi);
                    tsmi.Click += SwichLanguge_Click;
                }
            }
            else
            {
                foreach (ToolStripMenuItem item in tsmiLanguage.DropDownItems)
                {
                    item.Checked = ci != null && ci.DisplayName == item.Text;
                }

                if (ci == null)
                {
                    ((ToolStripMenuItem)tsmiLanguage.DropDownItems[0]).Checked = true;
                }
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: sw0/RegexTool
        void tsmiDonate_Click(object sender, EventArgs e)
        {
            var cul  = ResxManager.GetCultureInfo() ?? Thread.CurrentThread.CurrentUICulture;
            var info = AppHelper.GetAppInfo();

            string url = string.Format(RegexToolHelper.ULR_DONATE, info.AppId, cul.Name);

            Process.Start(url);
        }
예제 #3
0
        private void InitializeRegexButtons()
        {
            tsRegexButtons.Items.Clear();

            var tsis = GetRegexToolStripItems();

            Regex reg = new Regex(@"[^(]+\((.+)\)");

            foreach (var tsb in tsis)
            {
                tsRegexButtons.Items.Add(tsb);
                if (!string.IsNullOrEmpty(tsb.Text))
                {
                    var m = reg.Match(tsb.Text);

                    if (m.Success)
                    {
                        tsb.Tag = m.Groups[1].Value;
                    }
                    else
                    {
                        tsb.Tag = tsb.Text;
                    }

                    if (tsb.Text.IndexOf("document", 0, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        //Open online Regular Expression document
                        tsb.Click += (sender, e) => Process.Start(
                            string.Format("http://msdn.microsoft.com/{0}/library/az24scfc.aspx",
                                          (ResxManager.GetCultureInfo() ?? Thread.CurrentThread.CurrentUICulture).Name));
                    }
                    else
                    {
                        tsb.MouseUp += RegexButton_MouseUp;
                    }
                }
            }
        }
예제 #4
0
파일: MainForm.cs 프로젝트: sw0/RegexTool
        void SwichLanguge_Click(object sender, EventArgs e)
        {
            var menuItem = sender as ToolStripMenuItem;

            if (menuItem == null)
            {
#if DEBUG
                throw new Exception("SwichLanguge_Click: sender is not a ToolStripMenuItem.");
#else
                return;
#endif
            }
            var ci = ResxManager.GetCultureInfo();

            if (ci != null && ci.Name == ((ToolStripMenuItem)sender).Tag.ToString())
            {
                //Makes no change
                return;
            }
            else
            {
                try
                {
                    var newCulture = CultureInfo.CreateSpecificCulture(menuItem.Tag.ToString());
                    ResxManager.SetCultureInfo(newCulture);
                    this.SetUserInterfaceTexts();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
#if DEBUG
                    throw;
#endif
                }
            }
        }
예제 #5
0
        public RegexBar()
        {
            InitializeComponent();

            //var cms = new CommonTextContextMenuStrip(this.components, "xdsds", txtRegPattern);
            //txtRegPattern.ContextMenuStrip = cms;
#if INIT_TEST_DATA
            this.txtRegPattern.Text = @"{""titleID"":(\d+),""boxartPrefix"":""(.+?)"",""name"":""(.+?)""}";
#endif
            //txtRegPattern.AutoWordSelection = true;
            //txtRegPattern.AutoWordSelection = false;

            InitializeContextMenuItemsForRegexBox();

            ControlHelper.SetDragDropAbility(txtRegPattern, true);
            {
                cbIgnoreCase.Checked     = true;
                cbIgnoreCase.ToolTipText = "指定不区分大小写的匹配。";

                cbIgnoreCase.Click              += RegexOptionBox_Click;
                cbExplicitCapture.Click         += RegexOptionBox_Click;
                cbECMAScript.Click              += RegexOptionBox_Click;
                cbCultureInvariant.Click        += RegexOptionBox_Click;
                cbIgnorePatternWhitespace.Click += RegexOptionBox_Click;
                cbMultiline.Click   += RegexOptionBox_Click;
                cbRightToLeft.Click += RegexOptionBox_Click;
                cbSingleline.Click  += RegexOptionBox_Click;

                cbSingleline.DisplayStyle                                     = cbExplicitCapture.DisplayStyle
                                                                              = cbECMAScript.DisplayStyle
                                                                              = cbCultureInvariant.DisplayStyle
                                                                              = cbIgnorePatternWhitespace.DisplayStyle
                                                                              = cbMultiline.DisplayStyle
                                                                              = cbRightToLeft.DisplayStyle
                                                                              = cbIgnoreCase.DisplayStyle
                                                                              = ToolStripItemDisplayStyle.Text;

                tsmiRegOptionsHelp.Click += (s, o) =>
                                            Process.Start(string.Format("http://msdn.microsoft.com/{0}/library/yd1hzczs.aspx", ResxManager.GetCultureInfo().Name));
            }

            InitializeRegexButtons();

            var tsmiSelectionOnly = cmsRegex.FindByName <ToolStripMenuItem>(FormStringKeys.STR_MENU_ITEM_SELECTION_ONLY);
            if (tsmiSelectionOnly != null)
            {
                txtRegPattern.HideSelection = !tsmiSelectionOnly.Checked;
            }
        }
예제 #6
0
        /// <summary>
        /// populate the group name buttons that user can be easier to input the template by clicking.
        /// Notice: it will take in 15 group names at maximum.
        /// </summary>
        /// <param name="groupNames"></param>
        public void GotGroupNamesChanged(string[] groupNames)
        {
            if (groupNames == null || groupNames.Length == 0)
            {
                //the regular expression is invalid, do nothing
                return;
            }
            string oldValue = txtOrderBy.Text;

            if (tsGroups.Items.Count > 0)
            {
                tsGroups.Items.Clear();
            }

            txtOrderBy.Items.Clear();
            txtOrderBy.Text = "$0";

            for (int i = 0; i < groupNames.Length; i++)
            {
                if (i > 15)
                {
                    break;
                }

                string gName = groupNames[i];
                string item  = string.Empty;

                if (gName.ToCharArray().All(c => char.IsNumber(c)))
                {
                    item = "$" + gName;
                    tsGroups.Items.Add(new ToolStripMenuItem()
                    {
                        Text = item
                    });
                    txtOrderBy.Items.Add(item);
                }
                else
                {
                    item = "${" + gName + "}";
                    tsGroups.Items.Add(new ToolStripMenuItem()
                    {
                        Text = item
                    });
                    txtOrderBy.Items.Add(item);
                }
            }

            var cul = ResxManager.GetCultureInfo() ?? Thread.CurrentThread.CurrentUICulture;

            _tsmiRowNumber.ToolTipText = ResxManager.GetResourceString(FormStringKeys.TIP_ROWNUMBER);
            tsGroups.Items.Add(_tsmiRowNumber);

            foreach (var item in txtOrderBy.Items)
            {
                if (item.ToString() == oldValue)
                {
                    txtOrderBy.Text = oldValue;
                    oldValue        = "";
                    break;
                }
            }

            if (oldValue != "")
            {
                //if we cannot find the old select item, set it to the first item.
                if (txtOrderBy.Items.Count > 0)
                {
                    txtOrderBy.Text = txtOrderBy.Items[0].ToString();
                }
                else
                {
                    txtOrderBy.Items.Add("$0");
                    txtOrderBy.Text = "$0";
                }
            }

            if (groupNames.Length > 0)
            {
                tsGroups.Items.Add(new ToolStripSeparator());
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = "Tab"
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = "Space"
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = "Return"
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = ","
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = ";"
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = "-"
                });
                tsGroups.Items.Add(new ToolStripMenuItem()
                {
                    Text = "|"
                });
            }

            foreach (ToolStripItem item in tsGroups.Items)
            {
                if (item is ToolStripMenuItem && item != _tsmiRowNumber)
                {
                    item.Click += GroupItem_Click;
                }
            }
        }