private void OpenRgx() { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Select File to Open"; dlg.AddExtension = true; dlg.DefaultExt = ".rgx"; dlg.Filter = "Regular Expression Files|*.rgx;*.txt|All Files|*.*"; dlg.FilterIndex = 0; dlg.Multiselect = true; dlg.ValidateNames = true; dlg.SupportMultiDottedExtensions = true; dlg.CheckFileExists = true; if (dlg.ShowDialog(this) == DialogResult.OK) { // Grab the currently active document. frmRgxDoc curDoc = ((frmRgxDoc)this.dockPanel.ActiveDocument); // If the document is blank and the status "IsSaved" = true, then // it means the user hasen't altered the doc, so we're going to // replace it. if (curDoc == null || (string.IsNullOrEmpty(curDoc.RegExText) && curDoc.IsSaved)) { curDoc.Close(); } // Open each file selected in the dialog. for (int i = 0; i < dlg.FileNames.Length; i++) { frmRgxDoc newDoc = this.CreateNewDoc(); newDoc.OpenFile(dlg.FileNames[i]); } } } }
private void CompileAssembly(string asmFileNm, string Nmspc, string classNm, string protLvl, bool allDocs) { char[] invalidClassChars = new char[] { '*', ' ', '#', '$', '%', '(', ')', '@', '!', '[', ']', '{', '}', '<', '>', ',', ';', '.' }; try { if (this.dockPanel.DocumentsCount < 1) { throw new Exception("No open documents."); } List <RegexCompilationInfo> lstRgxInfos = new List <RegexCompilationInfo>(); if (allDocs) { foreach (WeifenLuo.WinFormsUI.Docking.IDockContent iRgxDoc in this.dockPanel.Documents) { frmRgxDoc doc = (iRgxDoc as frmRgxDoc); if (doc == null) { continue; } string rgxText = doc.RegExText; string rgxName = System.IO.Path.GetFileNameWithoutExtension(RainstormStudios.rsString.RemoveChars(doc.Text, invalidClassChars)); System.Text.RegularExpressions.RegexCompilationInfo compInfo = new RegexCompilationInfo(rgxText, this.GetRegExOpts(), rgxName, Nmspc, (protLvl.ToLower() == "public")); lstRgxInfos.Add(compInfo); } } else { frmRgxDoc doc = (this.dockPanel.ActiveDocument as frmRgxDoc); if (doc == null) { throw new Exception("No active document."); } string rgxText = doc.RegExText; string rgxName = RainstormStudios.rsString.RemoveChars(doc.Text, invalidClassChars); System.Text.RegularExpressions.RegexCompilationInfo compInfo = new RegexCompilationInfo(rgxText, this.GetRegExOpts(), rgxName, Nmspc, (protLvl.ToLower() == "public")); } System.Reflection.AssemblyName asmName = new System.Reflection.AssemblyName(); asmName.CultureInfo = System.Globalization.CultureInfo.CurrentCulture; asmName.Name = System.IO.Path.GetFileNameWithoutExtension(asmFileNm); asmName.Version = new Version(1, 0); asmName.VersionCompatibility = System.Configuration.Assemblies.AssemblyVersionCompatibility.SameProcess; Regex.CompileToAssembly(lstRgxInfos.ToArray(), asmName); } catch (Exception ex) { MessageBox.Show(this, "An unexpected error has occured while trying to create the regular expression assembly:\n\n" + ex.Message + "\n\nApplication Version: " + Application.ProductVersion, "Unexpected Error"); } }
private void mnuEdit_DropDownOpening(object sender, EventArgs e) { frmRgxDoc activeDoc = (this.dockPanel.ActiveDocument as frmRgxDoc); bool txtSelected = (activeDoc == null) ? false : activeDoc.IsTextSelected; this.mnuEditCut.Enabled = this.mnuEditCopy.Enabled = this.mnuEditDelete.Enabled = txtSelected; this.mnuEditPaste.Enabled = (activeDoc != null) && (!activeDoc.IsReadOnly) && (Clipboard.ContainsText()); this.mnuEditSelectAll.Enabled = (activeDoc != null); }
private frmRgxDoc CreateNewDoc() { frmRgxDoc frmRgxDoc00 = new frmRgxDoc(); frmRgxDoc00.Text = "Untitled" + (this.dockPanel.DocumentsCount + 1).ToString().PadLeft(2, '0'); frmRgxDoc00.Name = frmRgxDoc00.Text; frmRgxDoc00.CloseButton = true; frmRgxDoc00.TabPageContextMenuStrip = this.mnuDocTabs; frmRgxDoc00.AllowEndUserDocking = true; frmRgxDoc00.MdiParent = this; frmRgxDoc00.InsertModeChanged += new EventHandler(this.rgxDoc_InsertModeChanged); frmRgxDoc00.Show(this.dockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document); return(frmRgxDoc00); }
private void mnuStripDocTabs_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { this.mnuDocTabs.Close(ToolStripDropDownCloseReason.ItemClicked); switch (e.ClickedItem.Name) { case "mnuDocTabClose": { frmRgxDoc frmDoc = (frmRgxDoc)this.dockPanel.ActiveDocument; frmDoc.Close(); } break; case "mnuDocTabSave": ((frmRgxDoc)this.dockPanel.ActiveDocument).SaveFile(); break; case "mnuDocTabOpenFolder": break; } }
private void mnuTools_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.Name) { case "mnuToolsCompileAsm": { frmRgxDoc doc = (frmRgxDoc)this.dockPanel.ActiveDocument; string asmDetBase = string.Empty; if (!string.IsNullOrEmpty(doc.FileName)) { asmDetBase = System.IO.Path.GetFileNameWithoutExtension(doc.FileName); } using (frmCompileAsm frm = new frmCompileAsm(asmDetBase, "Match" + asmDetBase, asmDetBase)) if (frm.ShowDialog(this) == DialogResult.OK) { this.CompileAssembly(frm.AssemblyName, frm.NamespaceName, frm.ClassName, frm.ProtectionLevel, frm.AllActiveDocs); } break; } case "mnuToolsGenCode": break; } }