Advertisement
GlobalAccessSoftware

SearchForm4.cs

Oct 3rd, 2019
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.22 KB | None | 0 0
  1.  
  2. #region Top Part
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyCustomLibrary.SearchForm4.cs
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  6. // v5.4.5.33 12-Aug-2019 Split Out from SF3
  7. // v5.4.5.34 17-Aug-2019 Solidification des5
  8. // v5.4.5.35 20-Aug 27-Aug Extension mods
  9. // v5.4.6.36 29-31 Aug Brings in Proven Code
  10. // From SearchForm2 to organize better.
  11. // Renumeration on basic building blocks.
  12. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  13. // Work down testwells &
  14. // BreakPoints, Clean and Polish++
  15. // v5.4.7.40 24-Sep-2019 Settling down after
  16. // some evolution during tracing & testing.
  17. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  18.  
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Collections.ObjectModel;
  22. using System.Linq;
  23. using System.Threading;
  24. using System.Windows.Forms;
  25.  
  26. // My Class Aliases:
  27. using MCD = MyCustomLibrary.Dialogs;
  28. using MMF = MyCustomLibrary.MemoryMapper;
  29. using MCT = MyCustomLibrary.MyToolbox;
  30. //using P3D = MyCustomLibrary.P3D;
  31. using Wl2 = MyCustomLibrary.WorkList2;
  32.  
  33. // My Property Aliases:
  34. using MCR = MyCustomLibrary
  35.   .Properties.Resources;
  36. using MCS = MyCustomLibrary
  37.   .Properties.Settings;
  38.  
  39. #endregion Pop Tart
  40.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  41.  
  42.  
  43. namespace MyCustomLibrary
  44. {
  45.   public partial class SearchForm
  46.   {
  47. #region SwitchBoard & Routing to Methods.
  48.  
  49.     int RunMyEditor()
  50.     {
  51.       var cnt = Info.File.Count + 1;
  52.       var arg = new string[cnt];
  53.       var inc = 0;
  54.  
  55.       arg[inc++] = Application.ExecutablePath;
  56.       for ( ; inc < cnt; ++inc)
  57.         arg[inc] =
  58.           Info.File[inc-1].Name;
  59.  
  60.       // Always pass files,run'in or not.
  61.       MCT.RunApp(arg);
  62.  
  63.       var t = 0;
  64.       do Thread.Sleep(3333);
  65.       while (!MCT.MeRunning
  66.         && ++t < 9);
  67.  
  68.       return t;
  69.     }
  70.  
  71.     void BlasterCalling()
  72.     {
  73.       var scope = scopeBox.SelectedIndex;
  74.       if (scope.Equals(0))
  75.         FindByName1();      // 001*
  76.       else Info = GetNewInfo;
  77.       if (scope.Equals(1))
  78.         ContentOfSelected();// 2 to 5
  79.       if (scope.Equals(2))
  80.         ContentOfAll();     // 3 to 5
  81.     }
  82.     // * = it's an Instrumental Method Group
  83.     // REM: Open is ME speak for Selected.
  84.     void EditorCalling()
  85.     {
  86.       var scope = scopeBox.SelectedIndex;
  87.       if (scope.Equals(0))
  88.         FindByName2();      // 4 to 1
  89.       else Info = GetNewInfo; // Fixt
  90.       if (scope.Equals(1))
  91.         ContentOfCurrent(true); // 005*
  92.       if (scope.Equals(2))
  93.         ContentOfSelected();// 6 to 5
  94.       if (scope.Equals(3))
  95.         ContentOfAll();     // 7 to 5
  96.     }
  97. #endregion SwitchBoard & Routing Methods
  98.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  99.  
  100.  
  101. #region Designed for Custom Data Type
  102.  
  103.     // Custom Composite Data Type:
  104.     WorkList2 GetNewInfo
  105.     {
  106.       get
  107.       {
  108.         return  new WorkList2(
  109.           new Collection<Files>())
  110.         {
  111.           CaseCheck = caseCheckBox.Checked,
  112.           WordCheck = wordCheckBox.Checked,
  113.           FindThis  = searchBox .Text,
  114.           Change2   = replaceBox.Text
  115.         };
  116.       }
  117.     }
  118.  
  119.     void SomethingChanged(
  120.       object sender, EventArgs e)
  121.     {
  122.       if (Beagle  == null) return;
  123.       IndexesFound = Indexes
  124.         = new Collection<int>();
  125.       MatchesFound = Info = GetNewInfo;
  126.       CancelSearch = true;
  127.     } // eventTrigger ^ Send Msg to Editor.
  128.  
  129.     // This Method Group turns
  130.     // Collection<WorkList2> WorkList
  131.     // into a collection of strings.
  132.     // v5.3.3.27 19-July-2019
  133.     void SendMatches()
  134.     {
  135.       using (new Mutex(true,
  136.         "SendMatchesMutex4"))
  137.       {
  138.         var fn = MCT.GetRoot + MCR.Matches;
  139.         var args = MCD.GetArgs(fn, 0);
  140.  
  141.         args[3] = GetMatchesAsStrings2();
  142.  
  143.         if (!MMF.WriteStrings(args) &&
  144.           !MCT.Skip && MCT.Testing)
  145.             MessageBox.Show(MCR.Err11);
  146.  
  147.         // experimental locking.
  148.         // Lock form until flow comes back.
  149.         //Enabled = false;
  150.       }
  151.     }
  152.  
  153.     // NOTE FILE-Design Layout Doc:
  154.     // 1st num on each Line is the Y,
  155.     // everything else on that CS line
  156.     // are it's Xs if many.
  157.     // (CS = Comma Separated)
  158.     // v5.3.5.30 30-Jul-2019
  159.     // v5.4.5.33 12-Aug-2019
  160.     // cstr = Collection of Strings.
  161.     Collection<string>
  162.       GetMatchesAsStrings2() // 4 the write
  163.     {
  164.       var cstr = new Collection<string>();//
  165.       var line = string.Format("{0}, {1}",
  166.         caseCheckBox.Checked,
  167.         wordCheckBox.Checked);
  168.       cstr.Add(line);
  169.       line = string.Format("{0}, {1}",
  170.         searchBox.Text, replaceBox.Text);
  171.       cstr.Add(line);
  172.       return AddFiles(cstr);
  173.     }
  174.  
  175.     // From WorkList2 to string collection.
  176.     // Rem: It comes partly setup. (above)
  177.     Collection<string> AddFiles(
  178.       Collection<string> cstr)
  179.     {
  180.       if (cstr == null
  181.         ||cstr.Count < 1) return null;
  182.  
  183.       foreach (var f in MatchesFound.File)
  184.       {
  185.         // File Level:
  186.         cstr.Add(f.Name);
  187.         const string c = ", ";
  188.  
  189.         foreach (var l in f.Line)
  190.         {
  191.           // Line Level:
  192.           var xs ="";
  193.           //  ^ our X-Coord accumulator.
  194.  
  195.           foreach (var n in l.Star)
  196.           {
  197.             // Character Number Level:
  198.             if (!string.IsNullOrEmpty(xs
  199.               )) xs += c; // appends commas.
  200.             xs += string.Format("{0}", n);
  201.           }
  202.           cstr.Add(string.Format(
  203.             "{0},{1}", l.LineNumber, xs));
  204.         }
  205.         // Special Between Files Marker.
  206.         cstr.Add(MCT.Special);
  207.       }
  208.       SearchAll = false; // <-===<<
  209.  
  210.       return cstr;
  211.     }
  212.     bool SearchAll { get; set; } // <-===<<
  213.    
  214. #endregion Designed for Custom Data Type
  215.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  216.  
  217.  
  218. #region RTB.Text Editing desRev4
  219.  
  220.     // v5.4.5.34
  221.     void ExtractUnOpened()
  222.     {
  223.       var nums = new Collection<int>();
  224.       foreach (var i in Info.File
  225.         .Select(f => CheckName(f.Name))
  226.           .Where(i => i >= 0))
  227.           nums.Add(i);
  228.       if (nums.Count > 0
  229.         ) ExtraIndexes(nums); // <-===<<
  230.       SearchAll = false;
  231.     }
  232.  
  233.     // Gets Matches that aren't Open
  234.     // & Grabs Indexes for SendSelected();//
  235.     // v5.4.5.33 12-Aug-2019 by -JpE-
  236.     static int CheckName(string fn)
  237.     {
  238.       var num = -1;
  239.  
  240.       if (!MCD.Selected.Contains(fn))
  241.         num = MCD.WholeList.IndexOf(fn);
  242.  
  243.       return num;
  244.     }
  245.  
  246.     /********************************/
  247.     // Handles User's Choice:
  248.     // (buttons from Left to Right)
  249.     //*******************************/
  250.     // Choice = 1: BOTH!
  251.     // Choice = 2: MyEditor Only.
  252.     // Choice = 3: Blaster  Only.
  253.     // Choice = 4: Cancel Operation.
  254.     //*******************************/
  255.     // 3: Is Default Accept Button. CF
  256.     /********************************/
  257.     void ExtraIndexes(Collection<int> i)
  258.     {
  259.       switch (Choice())
  260.       {
  261.         case 1: Send2Blaster(i, 1); break;
  262.         case 3: Send2Blaster(i, 3); break;
  263.       }
  264.     }
  265.  
  266.     static int Choice()
  267.     {
  268.       using (var cf = new ChoiceForm())
  269.       {
  270.         cf.ShowDialog();  //   ^^^^
  271.         return cf.Choice; //   ||||
  272.       }
  273.     }
  274.  
  275.     // Assign what we got and let our
  276.     // PropertyChanged call SendSelected();
  277.     void Send2Blaster(
  278.       Collection<int> n, int i)
  279.     {
  280.       // breakpoint Send2Blaster();
  281.       if (i > 1 && SearchAll && Info != null
  282.         && Info.File != null && Info
  283.         .File.Count > 0) RemoveFromInfo(n);
  284.      
  285.       IndexesFound = n; // <-= event trigger
  286.     }
  287.  
  288.     private void RemoveFromInfo(
  289.       ICollection<int> n)
  290.     {
  291.       // testwell RemoveFromInfo();
  292.       if ( n == null
  293.         || n.Count < 1
  294.         || Info == null
  295.         || Info.File == null
  296.         || Info.File.Count < 1) return;
  297.  
  298.       var f = Info.File;
  299.       var c = f.Count;
  300.       var m = n.Count;
  301.  
  302.       foreach (var t in n.Select(
  303.         i => MCD.WholeList[i]))
  304.         for (var ii = 0; ii < c; ++ii)
  305.           if (t.Equals(f[ii].Name))
  306.             Info.File.RemoveAt(ii);
  307.  
  308.       // breakpoint RemoveFromInfo();
  309.       if (c-m != Info.File.Count)
  310.         throw new ArgumentException(
  311.           "Error in Remove From Info.");
  312.     } // Sanity Check ^ by Justin Kase:
  313.  
  314. #endregion RTB.Text Editing
  315.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  316.  
  317.  
  318.   }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement