Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Top Part
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // MyCustomLibrary.SearchForm4.cs
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // v5.4.5.33 12-Aug-2019 Split Out from SF3
- // v5.4.5.34 17-Aug-2019 Solidification des5
- // v5.4.5.35 20-Aug 27-Aug Extension mods
- // v5.4.6.36 29-31 Aug Brings in Proven Code
- // From SearchForm2 to organize better.
- // Renumeration on basic building blocks.
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // Work down testwells &
- // BreakPoints, Clean and Polish++
- // v5.4.7.40 24-Sep-2019 Settling down after
- // some evolution during tracing & testing.
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
- using System.Windows.Forms;
- // My Class Aliases:
- using MCD = MyCustomLibrary.Dialogs;
- using MMF = MyCustomLibrary.MemoryMapper;
- using MCT = MyCustomLibrary.MyToolbox;
- //using P3D = MyCustomLibrary.P3D;
- using Wl2 = MyCustomLibrary.WorkList2;
- // My Property Aliases:
- using MCR = MyCustomLibrary
- .Properties.Resources;
- using MCS = MyCustomLibrary
- .Properties.Settings;
- #endregion Pop Tart
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- namespace MyCustomLibrary
- {
- public partial class SearchForm
- {
- #region SwitchBoard & Routing to Methods.
- int RunMyEditor()
- {
- var cnt = Info.File.Count + 1;
- var arg = new string[cnt];
- var inc = 0;
- arg[inc++] = Application.ExecutablePath;
- for ( ; inc < cnt; ++inc)
- arg[inc] =
- Info.File[inc-1].Name;
- // Always pass files,run'in or not.
- MCT.RunApp(arg);
- var t = 0;
- do Thread.Sleep(3333);
- while (!MCT.MeRunning
- && ++t < 9);
- return t;
- }
- void BlasterCalling()
- {
- var scope = scopeBox.SelectedIndex;
- if (scope.Equals(0))
- FindByName1(); // 001*
- else Info = GetNewInfo;
- if (scope.Equals(1))
- ContentOfSelected();// 2 to 5
- if (scope.Equals(2))
- ContentOfAll(); // 3 to 5
- }
- // * = it's an Instrumental Method Group
- // REM: Open is ME speak for Selected.
- void EditorCalling()
- {
- var scope = scopeBox.SelectedIndex;
- if (scope.Equals(0))
- FindByName2(); // 4 to 1
- else Info = GetNewInfo; // Fixt
- if (scope.Equals(1))
- ContentOfCurrent(true); // 005*
- if (scope.Equals(2))
- ContentOfSelected();// 6 to 5
- if (scope.Equals(3))
- ContentOfAll(); // 7 to 5
- }
- #endregion SwitchBoard & Routing Methods
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region Designed for Custom Data Type
- // Custom Composite Data Type:
- WorkList2 GetNewInfo
- {
- get
- {
- return new WorkList2(
- new Collection<Files>())
- {
- CaseCheck = caseCheckBox.Checked,
- WordCheck = wordCheckBox.Checked,
- FindThis = searchBox .Text,
- Change2 = replaceBox.Text
- };
- }
- }
- void SomethingChanged(
- object sender, EventArgs e)
- {
- if (Beagle == null) return;
- IndexesFound = Indexes
- = new Collection<int>();
- MatchesFound = Info = GetNewInfo;
- CancelSearch = true;
- } // eventTrigger ^ Send Msg to Editor.
- // This Method Group turns
- // Collection<WorkList2> WorkList
- // into a collection of strings.
- // v5.3.3.27 19-July-2019
- void SendMatches()
- {
- using (new Mutex(true,
- "SendMatchesMutex4"))
- {
- var fn = MCT.GetRoot + MCR.Matches;
- var args = MCD.GetArgs(fn, 0);
- args[3] = GetMatchesAsStrings2();
- if (!MMF.WriteStrings(args) &&
- !MCT.Skip && MCT.Testing)
- MessageBox.Show(MCR.Err11);
- // experimental locking.
- // Lock form until flow comes back.
- //Enabled = false;
- }
- }
- // NOTE FILE-Design Layout Doc:
- // 1st num on each Line is the Y,
- // everything else on that CS line
- // are it's Xs if many.
- // (CS = Comma Separated)
- // v5.3.5.30 30-Jul-2019
- // v5.4.5.33 12-Aug-2019
- // cstr = Collection of Strings.
- Collection<string>
- GetMatchesAsStrings2() // 4 the write
- {
- var cstr = new Collection<string>();//
- var line = string.Format("{0}, {1}",
- caseCheckBox.Checked,
- wordCheckBox.Checked);
- cstr.Add(line);
- line = string.Format("{0}, {1}",
- searchBox.Text, replaceBox.Text);
- cstr.Add(line);
- return AddFiles(cstr);
- }
- // From WorkList2 to string collection.
- // Rem: It comes partly setup. (above)
- Collection<string> AddFiles(
- Collection<string> cstr)
- {
- if (cstr == null
- ||cstr.Count < 1) return null;
- foreach (var f in MatchesFound.File)
- {
- // File Level:
- cstr.Add(f.Name);
- const string c = ", ";
- foreach (var l in f.Line)
- {
- // Line Level:
- var xs ="";
- // ^ our X-Coord accumulator.
- foreach (var n in l.Star)
- {
- // Character Number Level:
- if (!string.IsNullOrEmpty(xs
- )) xs += c; // appends commas.
- xs += string.Format("{0}", n);
- }
- cstr.Add(string.Format(
- "{0},{1}", l.LineNumber, xs));
- }
- // Special Between Files Marker.
- cstr.Add(MCT.Special);
- }
- SearchAll = false; // <-===<<
- return cstr;
- }
- bool SearchAll { get; set; } // <-===<<
- #endregion Designed for Custom Data Type
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- #region RTB.Text Editing desRev4
- // v5.4.5.34
- void ExtractUnOpened()
- {
- var nums = new Collection<int>();
- foreach (var i in Info.File
- .Select(f => CheckName(f.Name))
- .Where(i => i >= 0))
- nums.Add(i);
- if (nums.Count > 0
- ) ExtraIndexes(nums); // <-===<<
- SearchAll = false;
- }
- // Gets Matches that aren't Open
- // & Grabs Indexes for SendSelected();//
- // v5.4.5.33 12-Aug-2019 by -JpE-
- static int CheckName(string fn)
- {
- var num = -1;
- if (!MCD.Selected.Contains(fn))
- num = MCD.WholeList.IndexOf(fn);
- return num;
- }
- /********************************/
- // Handles User's Choice:
- // (buttons from Left to Right)
- //*******************************/
- // Choice = 1: BOTH!
- // Choice = 2: MyEditor Only.
- // Choice = 3: Blaster Only.
- // Choice = 4: Cancel Operation.
- //*******************************/
- // 3: Is Default Accept Button. CF
- /********************************/
- void ExtraIndexes(Collection<int> i)
- {
- switch (Choice())
- {
- case 1: Send2Blaster(i, 1); break;
- case 3: Send2Blaster(i, 3); break;
- }
- }
- static int Choice()
- {
- using (var cf = new ChoiceForm())
- {
- cf.ShowDialog(); // ^^^^
- return cf.Choice; // ||||
- }
- }
- // Assign what we got and let our
- // PropertyChanged call SendSelected();
- void Send2Blaster(
- Collection<int> n, int i)
- {
- // breakpoint Send2Blaster();
- if (i > 1 && SearchAll && Info != null
- && Info.File != null && Info
- .File.Count > 0) RemoveFromInfo(n);
- IndexesFound = n; // <-= event trigger
- }
- private void RemoveFromInfo(
- ICollection<int> n)
- {
- // testwell RemoveFromInfo();
- if ( n == null
- || n.Count < 1
- || Info == null
- || Info.File == null
- || Info.File.Count < 1) return;
- var f = Info.File;
- var c = f.Count;
- var m = n.Count;
- foreach (var t in n.Select(
- i => MCD.WholeList[i]))
- for (var ii = 0; ii < c; ++ii)
- if (t.Equals(f[ii].Name))
- Info.File.RemoveAt(ii);
- // breakpoint RemoveFromInfo();
- if (c-m != Info.File.Count)
- throw new ArgumentException(
- "Error in Remove From Info.");
- } // Sanity Check ^ by Justin Kase:
- #endregion RTB.Text Editing
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement