GlobalAccessSoftware icon

SearchForm1.cs

GlobalAccessSoftware | PRO | 10/04/19 12:20:41 AM UTC | 0 ⭐ | 968 👁️ | Never ⏰ | []
C# |

10.43 KB

|

None

|

0 👍

/

0 👎

 
#region Top Part
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// MyCustomLibrary.SearchForm1.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 18-May-2019 EyeOutBug Fixed ++
// v5.2.8.17 24-May PropertyChangedEvents.
// v5.2.9.19 31-May Minor Revision, Setups.
// 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.22 24-June Sorting it out in 2 & 3
// v5.3.1.23 30-June CurrentFile Name, etc.
// v5.3.3.27 19-July Integration & Polish.
// -=[ Design Revision 4 ]=- My Custom Type.
// v5.3.4.29 25-Jul-2019 Spelling things out
// Class{in-Class{in-Class}}; Custom Types:
// v5.4.5.32 07-Aug-2019 Search & Replace.
// v5.4.5.35 21-Aug-2019 Final Details Alpha
// v5.4.6.36 07-Sep ""   Minor Details.
// v5.4.6.37 12-Sep-2019 Debug Testing. 1
// v5.4.7.39 26-Sep-2019 Cleaning up.
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
 
using MCD = MyCustomLibrary.Dialogs;
using MCT = MyCustomLibrary.MyToolbox;
 
using MCR = MyCustomLibrary
  .Properties.Resources;
using MCS = MyCustomLibrary
  .Properties.Settings;
 
 
namespace MyCustomLibrary
{
  public partial class SearchForm : Form
  {
    // Incoming Property (ReUsed)
    // searchBox.Text till load, fn after
    public void Search4(string value)
    { Search2 = value; }
    string  Search2 { get; set; }
 
    FileSystemWatcher
      Beagle   { get; set; }
 
 
    // 1/1 Class Constructor
    public SearchForm()
    {
      InitializeComponent();
    }
#endregion Pop Tart
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Search Form Load
 
    void SearchFormLoad(
      object sender, EventArgs e)
    {
      if (Dialogs.WholeList == null
       || Dialogs.WholeList
       .Count < 1) return;
 
      Size = MCS.Default.SearchSize;
      Location = MCS.Default.SearchLoca;
 
      if (SearchFormLoad2()) return;
 
      if (MCT.Testing && !MCT.Skip)
        MessageBox.Show(MCR.FL2);
      Close();
    }
 
    bool SearchFormLoad2()
    {
      var app = Application.ExecutablePath;
      if (app.Contains(MCR.MyApp))
        SearchEditor();
      else
        if (app.Contains(MCR.MyOtherApp) )
          SearchPrintBlaster();
        else return false;
 
      caseCheckBox.Checked = 
        MCS.Default.Case;
      wordCheckBox.Checked =
        MCS.Default.Word;
 
      searchBox.Text = Search2;
 
      if (replaceBox.Visible)
        UpdateReplaceList();
      UpdateSearchList();
 
      LoadSharedColors();
      ScopeSelectedChanged(
        // These are unused dummy args.
        "startup", EventArgs.Empty);
 
      // v5.3.0.21 10-June-2019 -JpE-
      Beagle = new FileSystemWatcher();
      SetupWatcher4MeComms();
 
      return true;
    }
#endregion Form Load
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Load Shared Colors Members
 
    void LoadSharedColors()
    {
      Color
        back    = DefaultBackColor,
        fore    = DefaultForeColor, 
        formB   = BackColor,
        formF   = ForeColor;
 
      var fnt   = DefaultFont;
      var info  = MCT.ReadShared(fnt,
        back,  fore, formB, formF, fnt);
 
      if ( info == null
        || info .Length < 6
        || info .Length > 6
        || ! (bool)  info[5]) return;
      
      // If needed in ReUses:
      //Font    = (Font) info[4];
      LoadSharedColors(info);
    }
 
    void LoadSharedColors(
      IList<object> info)
    {
      var colors =
        new Collection<Color>();
      try
      {
        colors.Add((Color) info[0]);
        colors.Add((Color) info[1]);
        colors.Add((Color) info[2]);
        colors.Add((Color) info[3]);
      }
      catch (InvalidCastException)
      { if ( MCT.Testing && !MCT.Skip)
             MessageBox.Show(MCR.Err7);
        return; }
      catch (FormatException)
      { if ( MCT.Testing && !MCT.Skip)
             MessageBox.Show(MCR.Err8);
        return; }
 
      LoadSharedColors(colors);
    }
 
    void LoadSharedColors(
      IList<Color> colors)
    {
      replaceBox.BackColor =
       searchBox.BackColor =
        scopeBox.BackColor = colors[0];
 
      replaceBox.ForeColor =
       searchBox.ForeColor =
        scopeBox.ForeColor = colors[1];
 
      BackColor = colors[2];
      ForeColor = colors[3];
   }
#endregion Load Shared Colors Members
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Setup Search Form
 
    void SearchEditor()
    {
      var scope = MCS.Default.ScopeMe;
      var ct = scope.Count;
      var ob = new object[ct];
 
      for (var i = 0; i < ct; ++i)
      {
        if (string.IsNullOrEmpty(
          scope[i])) continue;
        ob[i] = scope[i];
      }
 
      scopeBox.Items.Clear();
      scopeBox.Items.AddRange(ob);
 
      scopeBox.SelectedIndex =
        MCS.Default.ScopeMePref;
    }
    /**********************************
     ** Who ^v is calling, ME or PB? **
    /**********************************/
    void SearchPrintBlaster()
    {
      var pb = MCS.Default.ScopePb;
      var cn = pb.Count;
      var ob = new object[cn];
 
      for (var i = 0; i < cn; ++i)
      {
        if (string.IsNullOrEmpty(
          pb[i])) continue;
        ob[i] = pb[i];
      }
 
      scopeBox.Items.Clear();
      scopeBox.Items.AddRange(ob);
 
      scopeBox.SelectedIndex =
        MCS.Default.ScopePbPref;
    }
 
    void FindSetup()
    {
      replaceButton.Hide();
      replaceAllButton.Hide();
      replaceBox.Hide();
      replaceLabel.Hide();
 
      SetupSearchBoxItems();
    }
 
    void ScopeSelectedChanged(
      object sender, EventArgs e)
    {
      var sel = scopeBox.SelectedIndex;
      if (Application.ExecutablePath
        .Contains(MCR.MyApp)) // ME Calling.
      {
        if (sel.Equals(0)) FindSetup();
        else ReplaceSetup();
      }
      else // It's PB calling.
      {
        if (sel.Equals(0)) FindSetup();
        else ReplaceSetup();
      }
    }
 
    void ReplaceSetup()
    {
      replaceButton.Show();
      replaceAllButton.Show();
      replaceBox.Show();
      replaceLabel.Show();
 
      SetupReplaceBoxItems();
      SetupSearchBoxItems();
    }
 
    /**********************************/
 
    void SetupSearchBoxItems()
    {
      if (MCS.Default
        .SearchBoxCollection == null)
        MCS.Default
          .SearchBoxCollection =
            new StringCollection();
 
      MCS.Default.Save();
      if (MCS.Default
          .SearchBoxCollection
            .Count < 1) return;
 
      var sbc = MCS.Default
        .SearchBoxCollection;
      var cnt = sbc.Count;
      var obj = new object[cnt];
 
      for (var i = 0; i <  cnt; ++i)
      {
        if (string.IsNullOrEmpty(
          sbc[i])) continue;
        obj[i] = sbc[i];
      }
 
      searchBox.Items.Clear();
      searchBox.Items.AddRange(obj);
 
      if (string.IsNullOrEmpty(searchBox
        .Text) && !string.IsNullOrEmpty(
        sbc[0])) 
        searchBox.Text = sbc[0];
    }
 
    void SetupReplaceBoxItems()
    {
      if (MCS.Default
        .ReplaceBoxCollection == null)
        MCS.Default
          .ReplaceBoxCollection =
            new StringCollection();
 
      if (MCS.Default
        .ReplaceBoxCollection
          .Count < 1) return;
 
      var rbc = MCS.Default
        .ReplaceBoxCollection;
      var cnt = rbc.Count;
      var obj = new object[cnt];
 
      for (var i = 0; i < cnt; ++i)
      {
        if (string.IsNullOrEmpty(
          rbc[i])) continue;
        obj[i] = rbc[i];
      }
 
      replaceBox.Items.Clear();
      replaceBox.Items.AddRange(obj);
 
      if (string.IsNullOrEmpty(
        replaceBox.Text)
        && !string.IsNullOrEmpty(
        rbc[0])) replaceBox
          .Text = rbc[0];
    }
#endregion Setup Search Form
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Form Close and Save
 
    void SearchFormClosing(
      object sender,
      FormClosingEventArgs e)
    {
      Beagle.EnableRaisingEvents = false;
 
      MCS.Default.SearchSize = Size;
      MCS.Default.SearchLoca = Location;
 
      MCS.Default.Case =
        caseCheckBox.Checked;
      MCS.Default.Word =
        wordCheckBox.Checked;
 
      if (Application.ExecutablePath
        .Contains(MCR.MyApp))
      {
        MCS.Default.ReplacePref =
          replaceBox.Visible;
        UpdateReplaceList();
        MCS.Default.ScopeMePref =
          scopeBox.SelectedIndex;
      }
      else MCS.Default.ScopePbPref =
        scopeBox.SelectedIndex;
 
      ListMaintenance();
      UpdateSearchList();
      // ^ MCS.Default.Save(); is in there.
 
      CancelSearch = true; // <-===<< Alerts
      // Smesa of Search Form Closing.^^^^^^
    }
 
    static void ListMaintenance()
    {
      while (MCS.Default.SearchBoxCollection
        .Count > 32) MCS.Default
          .SearchBoxCollection.RemoveAt(32);
      while (MCS.Default.ReplaceBoxCollection
        .Count > 32) MCS.Default
          .ReplaceBoxCollection.RemoveAt(32);
    }
#endregion Form Close and Save
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Update Recents Lists
 
    void UpdateSearchList()
    {
      var str = searchBox.Text;
      if (!string.IsNullOrEmpty(str))
      {
        while (MCS.Default
          .SearchBoxCollection
          .Contains(str)) MCS.Default
            .SearchBoxCollection
              .Remove(str);
        MCS.Default.SearchBoxCollection
          .Insert(0, str);
      }
      SetupSearchBoxItems();
    }
 
    void UpdateReplaceList()
    {
      var txt = replaceBox.Text;
      if (!string.IsNullOrEmpty(txt))
      {
        while (MCS.Default
          .ReplaceBoxCollection
          .Contains(txt)) MCS.Default
            .ReplaceBoxCollection
              .Remove(txt);
        MCS.Default.ReplaceBoxCollection
          .Insert(0, txt);
      }
      SetupReplaceBoxItems();
    }
#endregion Update Lists
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
  }
}
 
// 100% -JpE-

Comments