#region Top Part //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // MyCustomLibrary.SearchForm2.cs //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // v5.2.7.12 05-May-2019 Created and Roughed //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // v5.2.7.14 12-May-2019 Great Design Stage. // v5.2.8.15 15-May-2019 Comin along nicely! // v5.2.8.16 16-May-2019 EyeOutBug Fixed ++ // v5.2.8.17 18-May Split out from SF1 for // Buttons & getting ready for InterObjects // v5.2.8.18 25-May-2019 Worked into SF3: // v5.2.8.19 31-May Minor Revision, Setups. // v5.2.8.19 31-May Mechanisms such as the // PropertyChanged Events & App Detect plus // Tie-ins to Both MyEditor & PrintBlaster. // v5.2.9.19 June 2019, Ready Mods ++ // v5.2.9.20 07-June Integration w/MyEditor! // v5.3.0.21 10-June Brought MySearchType & // SearchCom into SearchForm Class, but now // it's MST for the Mutexes AND MySearchType // and SearchForm Class for what was MSC // v5.3.0.21 15-June Getting Serious Now! // v5.3.1.23 25-Jun Coming Together! Rev-1; // v5.3.1.24 02-Jul Integrating Search mods. // v5.3.1.25 10-July SearchForm Features++ // v5.3.2.26 14-Jul-2019 Design Rev to FSWs. // v5.3.3.27 19-July-2019 Design Revisions3. // v5.3.3.28 21-July SmesaSearch.cs rockin' // -=[ Design Revision 4 ]=- My Custom Type. // v5.3.4.29 25-Jul-2019 Spelling things out // Class{in-Class{in-Class}}; Custom Types: // v5.3.5.31 03-Aug ReCoded4 WorkList2 // v5.4.5.32 07-Aug-2019 Search & Replace. // v5.4.5.35 21-Aug-2019 Design finished! // v5.4.6.36 29-31 " " Work down testwells // & BreakPoints, Clean and Polish++ 06-Sept // v5.4.7.40 24-Sep-2019 Settling down after // some evolution during tracing & testing. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ using System; using System.Collections.ObjectModel; using System.IO; using System.Threading; using System.Windows.Forms; using MCD = MyCustomLibrary.Dialogs; using MMF = MyCustomLibrary.MemoryMapper; using MCT = MyCustomLibrary.MyToolbox; using MCR = MyCustomLibrary .Properties.Resources; using MCS = MyCustomLibrary .Properties.Settings; #endregion Pop Tart //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ namespace MyCustomLibrary { // This is the Primary Class & Form. public partial class SearchForm { #region SF3 Design Documentation: //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ /*//\\//Scope items Doc [w/Legend]//\\// //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ \\ Indice | Design said PB Scopes://\\// // [0] Find Files by Name. //\\//\\//\\ \\ [1] Content of Selected Files. //\\// // [2] Content of All Managed Files.//\\ \\ *********************************\\// // Indice | Design said ME Scopes:\\//\\ \\ [0] Current File Content\\//\\//\\// // [1] Opened Files Content//\\//\\//\\ \\ [2] Managed Files Content\\//\\//\\// // [3] Find Files by Name.\\//\\//\\//\\ // \\//\\//\\//\\//\\//\\//\\//\\//\\// // Rev9: Content goes to ME, // Rev9: Name goes to PB. // if (scope.List > 3) it's ME; /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ /* Important Design Elements: * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= * * caseCheckBox.Checked; * wordCheckBox.Checked; * scopeBox.SelectedIndex; * * searchBox .Text; // to search for. * replaceBox.Text // to replace with. * * Selected List: MCD.Selected; * Whole Mngd List: MCD.WholeList; * * See Notes: MMMF_Doc & Analysis. */ /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ #endregion SF3 Original Design Doc: //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #region Find-Button Subgroup of methods. // v5.2.8.16-17 : 18-20th May-2019 // (shown/called by ME and PB) void FindButtonClicked( object sender, EventArgs e) { if (CheckFindNext()) return; UpdateSearchList(); if (Application.ExecutablePath .Contains(MCR.MyApp)) EditorCalling(); else BlasterCalling(); if (AnyMatches()) FoundMatches(); } void FoundMatches() { if (SearchAll) ExtractUnOpened(); var t = 0; if (!MCT.MeRunning) t = RunMyEditor(); if (t < 9) { // v Event Trigger when assigned to. MatchesFound = Info; Info = GetNewInfo; Validate(); } else { if (!MCT.Testing || MCT.Skip) return; #region Permanent TestCode MessageBox.Show( string.Format( "{0}{1}{2}{3}{4}", MCR.TimeOut1, Path.GetFileName( Application.ExecutablePath), MCR.TimeOut2, MCR.FindButton, "\n\nCycles == " + t)); #endregion } } bool AnyMatches() { return Info != null && Info.File != null && Info.File.Count > 0 && !string.IsNullOrEmpty( Info.FindThis) && !string.IsNullOrEmpty( Info.Change2); } // FindNext, MatchesFound if // True Search already underway. private bool CheckFindNext() { return MatchesFound != null && MatchesFound.File != null && MatchesFound.File.Count > 0 && searchBox.Text.Equals(MCS.Default .SearchBoxCollection[0]) && (FindNext = true); // Remote ^ Trigger or NOT } #endregion Find-Button Subgroup of Methods. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #region Replace & Replace-ALL Methods. // shown/called by ME only void ReplaceButtonClicked( object sender, EventArgs e) { if (MatchesFound != null && searchBox.Text.Equals(MCS.Default .SearchBoxCollection[0]) && replaceBox.Text.Equals(MCS.Default .ReplaceBoxCollection[0])) { Replace = true; // ^ EventTrigger! Writes Remote.sme return; } // else UpdateReplaceList(); FindButtonClicked(sender, e); } // Shown / Called by ME only) // NOTE: Cancel is Changed on Closing. void ReplaceAllButtonClicked( object sender, EventArgs e) { // breakpoint SF2.RABC if (MatchesFound != null && searchBox.Text.Equals(MCS.Default .SearchBoxCollection[0])) { ReplaceAll = true; // ^ EventTrigger! Writes Remote.sme return; } // else UpdateReplaceList(); FindButtonClicked(sender, e); } #endregion Replace & Replace-ALL Methods. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #region Outgoing Messaging /************************************** / IndexFound Property Members for PB: /**************************************/ // REM: SearchForm is Signaling caller, // either MyEditor OR PrintBlaster Apps. Collection IndexesFound { get { return _indexes; } set { _indexes = value; if ( value == null || value.Count < 1) return; // Think of it as a PropertyChanged SendSelected(); // EventHandler. } } Collection _indexes; // This 1 is Separate until Assigned. Collection Indexes { get; set; } // REM: SearchForm is Signaling MyEditor //************************************** // MatchesFound Property Members //**************************************/ WorkList2 MatchesFound { get { return _skinny; } set { _skinny = value; if ( value == null || value.File == null || value.File.Count < 1) return; SendMatches(); } } WorkList2 _skinny; // This 1 is Separate until Assigned. WorkList2 Info { get; set; } /*********[Events 4 ME 2 handle]********/ void SendRemote(byte code) { var fn = MCT.GetRoot + MCR.Remote; var args = MCD.GetArgs(fn, code); if (!MMF.WriteBytes(args)) MessageBox.Show(MCR.Err12); // develop Enabled locks Enabled = false; } bool FindNext { set { if (!value) return; SendRemote(1); } } bool Replace { set { if (!value) return; SendRemote(2); } } bool ReplaceAll { set { if (!value) return; SendRemote(3); } } bool CancelSearch { set { if (!value) return; SendRemote(4); } } #endregion Outgoing Messaging //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #region Incoming Messaging // Rev5.3.0.21 Design Changes // this to a FileSystemWatcher // sent directly from: MyEditor // .Smesa via SearchReplace.cs void SetupWatcher4MeComms() { Beagle.NotifyFilter = NotifyFilters.FileName; Beagle.InternalBufferSize = 32; Beagle.EnableRaisingEvents = false; // Setup File System Watcher: var dir = Application.StartupPath; if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) throw new ArgumentException(MCR.Err14); Beagle.Path = dir; var fn = dir + MCR.Search; Beagle.Filter = Path.GetFileName(fn); // Start Clean Each Run. if (File.Exists(fn)) File.Delete(fn); // Create Eventhandler... Beagle.Created += WatchRemote; Beagle.EnableRaisingEvents = true; } /*********************************/ void WatchRemote(// from MyEditor object sender, FileSystemEventArgs e) { Thread.CurrentThread.Name = "Msg Detected"; if (searchBox.InvokeRequired) Invoke(new Invoker1(SearchTask)); else SearchTask(); } /*********************************/ delegate void Invoker1(); // Back on UI Thread at this point. void SearchTask() { Thread.CurrentThread.Name = "Search Task"; Enabled = true; var fn = Application .StartupPath + MCR.Search; if (!File.Exists(fn)) return; // Now read the file in and then // it's deleted after the read. var bytes = MMF.ReadBytes( MCD.GetArgs(fn, 0)); if (Convert.ToByte( bytes[0]) < 2) LetsGo(); else AllDone(); #region Release Version TestCode //const string t = // "Made it to Search Task with\n" + // "a TASK of: "; //MessageBox.Show(t + task); #endregion } // Async Msg From MyEditor. // Basic CTS Signal Circuit Logic. // (Clear To Send) void LetsGo() { // testwell LetsGo(); using (new Mutex(true, "GOM505")) { // hack UNFINISHED CODE // testcode LetsGo const string txt = "Made it to Lets Go!"; MessageBox.Show(txt); } } // All Done on Editor End, now what? // Act on Search Task Completed // in SmesaSearch over here in SF2. void AllDone() { // breakpoint AllDone(); using (new Mutex(true, "DONEM521")) { MatchesFound = Info = GetNewInfo; IndexesFound = Indexes = new Collection(); } } #endregion Incoming Messaging //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ #region Free Parking For View Only. #endregion Free Parking For View Only //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ } }