GlobalAccessSoftware icon

MyDialogs.cs (lower level connecting code)

GlobalAccessSoftware | PRO | 10/04/19 12:30:32 AM UTC | 0 ⭐ | 1064 👁️ | Never ⏰ | []
C# |

13.97 KB

|

None

|

0 👍

/

0 👎

 
#region Top Part
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// MyDialogs.cs AppStatic Assembly
// Tools and Dialogs among others.
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// Brought over from Smesav Project
// AppStatic.Tools & .Dialogs are
// Independent like MyCustomControl
// v2.3.7.27 15-Dec-2018 -JpE-
// v4.5.7.57 09-Jun-18
// v4.5.7.58 03-Jul-18 ReOrganized.
// v4.7.0.71 19-Sep About Colors.
// v5.0.6.01 06-Mar-2019 Overloads
// v5.2.7.12 02-May-2019 Search Pro
// v5.2.7.14 12-May-2019 Perfectionist
// v5.2.8.16 18-May Ready for After Dialog.
// v5.2.8.17 24-May PropertyChangedEvents.
// v5.2.8.18 26-May-2019 Search Pro Design.
// v5.3.0.22 22-Jun Search Pro Development.
// v5.3.1.23 01-Jul light Search touches.
// v5.3.1.24 03-Jul Integrating Search mods.
// v5.3.1.25 10-Jul Final Here in MCD!
// v5.3.3.28 21-July SmesaSearch.cs rockin'
// v5.4.5.32 07-Aug-2019 Search & Replace.
// v5.4.6.36 04-Sep Search string, BuggFixxd
// & further refined Search Launch. ++ 9-07
// v5.4.6.37 10-Sep-2019 Shakedown 4 Search.
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
 
// My Custom Controls Class
using MyCustomControls;
 
// & My Custom Library alias
using MCT = MyCustomLibrary.MyToolbox;
 
// & Custom Property Aliases
using MCS = MyCustomLibrary
  .Properties.Settings;
using MCR = MyCustomLibrary
  .Properties.Resources;
 
#endregion Pop Tart
 
 
namespace MyCustomLibrary
{
  /**  MyCustomControls Legend: **
   *******************************
   * O1 = MyOpenDialog;
   * R1 = MyRichTextBox;
   * P1 = MyPrintDialog;
   * P2 = MyPreviewControl;
   * P3 = MyPreviewDialog;
   * D1 = MyPrintDoc;
   * P4 = MyPageSetup;
   * M1 = MyPreviewMenuStrip;
   * M2 = MyColorDialog;
   * F0 = MyFontDialog;
   * S1 = MySaveDialog;
   *******************************
   */
 
  public static class Dialogs
  {
#region Everything Else
 
    /// <summary> ReUses About Form
    /// for each Smesa App. Args for
    /// each are passed in; making this
    /// Public Method very ReUsable. -JpE-
    /// v4.5.7.58 03-July-2018
    /// </summary>
    /// <param name="colors"></param>
    /// <param name="args"></param>
    public static void AboutApp(
      IList<Color> colors, IList<string> args)
    {
      if (args == null) return;
      var l = args.Count;
      using (var a = new AboutBox(colors))
      {
        if (l>0) a.Title141(args[0]);
        if (l>1) a.Product1(args[2]);
        if (l>3) a.Rights12(args[3]);
        if (l>4) a.Company4(args[4]);
        if (l>5) a.Describe(args[5]);
        // args for each passed in.
        a.Size = MCS.Default.AboutSize;
        a.Location = MCS.Default.AboutLocation;
        a.ShowDialog();
        MCS.Default.AboutSize = a.Size;
        MCS.Default.AboutLocation = a.Location;
      }
      MCS.Default.Save();
    }
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
    
    //public static bool // cleanup unused when finished.
    //  YesNoDialog()
    //{ return YesNoDialog(MCR.YND_Txt); }
    //// Defaults to Text, Title, & NO
    
    public static bool
      YesNoDialog(string text)
    {
      return YesNoDialog(
        text, MCR.YND_Ttl);
    }
    
    public static bool YesNoDialog(
      string text, string title)
    {
      const int no = 2;
      return YesNoDialog(
      text, title, no);
    }
    /// <summary> Public Access Multi-Purpose
    /// ReUsable OverLoaded Method-Group
    /// Designed For Extreme ReUse Potential.
    /// Defaults to SMR.AYS_Txt,
    /// title is SMR.AYS_Ttl
    /// The NO (2) button as DEFAULT. NO
    /// v1.0.3.26a 04-Dec-2017
    /// v2.2.5.26y 27-Dec-2017
    /// </summary>
    /// <param name="text"></param>
    /// <param name="title"></param>
    /// <param name="def"></param>
    /// <returns></returns>
    public static bool
      YesNoDialog(string text,
      string title, int def)
    {
      if (MyToolbox.Skip) return true;
      if (def < 1 || def > 2) def = 2;
      if (string.IsNullOrEmpty(text))
        text = MCR.YND_Txt;
      if (string.IsNullOrEmpty(title))
        title = MCR.YND_Ttl;
      var db = MessageBoxDefaultButton.Button2;
      const MessageBoxDefaultButton
        yes  = MessageBoxDefaultButton.Button1;
      if (def < 2) db = yes;
      return 
        DialogResult.Yes.Equals(
        MessageBox.Show(text, title,
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question, db));
    }
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
    //public static DialogResult YesNoCancel()
    //{ return YesNoCancel(MCR.YND_Txt); }
    ///* Default to Text, Title, & NO */
    
    //public static DialogResult
    //  YesNoCancel(string text)
    //{ return YesNoCancel(text, MCR.YND_Ttl); }
    //// Default to Title & NO
 
    public static DialogResult
      YesNoCancel(string text, string title)
    {
      const int cancel = 3;
      return YesNoCancel(text, title, cancel);
    }
    // Default to Cancel              ^
 
    /// <summary> Defaults to ASR.AYS_Txt,
    /// ASR.AYS_Ttl and Cancel.
    /// Returns the Actual Dialog Result.
    /// </summary>
    /// <param name="text"> </param>
    /// <param name="title"> </param>
    /// <param name="def"> </param>
    /// <returns> </returns>
    static DialogResult YesNoCancel(
      string text, string title, int def)
    {
      if (MyToolbox.Skip)
        return DialogResult.Yes;
      if (def < 1 || def > 3) def = 3;
      if (string.IsNullOrEmpty(text))
        text = MCR.YND_Txt;
      if (string.IsNullOrEmpty(title))
        title = MCR.YND_Ttl;
      var
        d = MessageBoxDefaultButton.Button3;
      if (def == 2)
        d = MessageBoxDefaultButton.Button2;
      if (def == 1)
        d = MessageBoxDefaultButton.Button1;
      return
        MessageBox.Show(text, title,
          MessageBoxButtons.YesNoCancel,
          MessageBoxIcon.Information, d);
    }
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
    public static int GetSavePreference()
    {
      const string t = "";
      return GetSavePreference(t);
    }
 
    static int
      GetSavePreference(string text)
    {
      const string t = "";
      return GetSavePreference(text, t);
    }
 
    public static int
      GetSavePreference(
      string text, string title)
    {
      const bool no = false;
      return GetSavePreference(
        text, title, no);
    }
 
    static int
      GetSavePreference(
      string text, string title, bool hide)
    {
      const bool no = false;
      return GetSavePreference(
        text, title, hide, no);
    }
 
    /// <summary> Ask User to Save @ 500 chars.
    /// Their response becomes their default
    /// if CheckBox.Checked, is 1 time otherwise
    /// NOTE: tab = Tab our User has Open, the
    /// Active RTB in the FileName Collection.
    /// v1.0.2.25j Modified for Multi-Use.
    /// </summary>
    /// <param name="text"> </param>
    /// <param name="title"> </param>
    /// <param name="hide"> </param>
    /// <param name="check"> </param>
    public static int GetSavePreference(
      string text, string title,
      bool hide, bool check)
    {
      int status;
      if (hide) check = false;
      using (var y =
        new YesNoAlwaysForm2(text, title))
      {
        y.Check = check;
        y.HideAlways = hide;
        y.Local = MCS.Default.YnaLoca;
        y.ShowDialog();
        MCS.Default.YnaLoca = y.Local;
        status = y.Status; // Get Result.
      }
      MCS.Default.Save();
      return status;
    }
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
    public static int NewTabPrompt()
    {
      int pref;// Awesome and Simple!
      using (var t = new NewTabForm())
      {
        t.ShowDialog();
        pref = t.Preference;
      }
      return pref;
    }
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
    /// <summary> Gets existing FileName(s) w/
    /// Users Input ReDesigned & Moved to MCD
    /// v3.1.3.43 23-Mar-2018
    /// </summary>
    /// <param name="fileNames"></param>
    /// <param name="multiple"></param>
    /// <param name="ext"></param>
    /// <param name="filter"></param>
    /// <param name="dir"></param>
    /// <returns></returns>
    public static string[] FileNameGetter(
      string[] fileNames, bool multiple,
      string ext, string filter, string dir)
    {
      if (fileNames == null
        || fileNames.Length < 1)
          return fileNames;
      OpenFileDialog ofd;
      using (var od = new CustomControl())
      { ofd = od.O1; }
      using (var o = ofd)
      {
        o.Multiselect = multiple;
        o.FileName = fileNames[0];
        o.DefaultExt = ext;
        o.Filter = filter;
        o.FilterIndex = 4;
        o.InitialDirectory = dir;
        if (!o.ShowDialog().Equals(
          DialogResult.OK))
            return fileNames;
        if ( o.Multiselect
          && o.FileNames.Length > 0
          && !string
          .IsNullOrEmpty(o.FileNames[0])
          && File.Exists(o.FileNames[0]))
            fileNames = o.FileNames;
        else
        {
          if (!o.Multiselect && !string
              .IsNullOrEmpty(o.FileName)
              && File.Exists(o.FileName))
            fileNames[0] = o.FileName;
        }
      }
      return fileNames;
    }
#endregion Everything Else
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
#region Static Search Members
 
    static string
      GetSearchDefault
    { get { return Criteria; } }
 
    static string Criteria
    { get { return MCS.Default
      .SearchBoxCollection[0]; } }
 
    internal static
      Collection<string> WholeList
    { get; private set; }
 
    internal static
      Collection<string> Selected
    { get; set; }
    
    // Currently Editing FileName.
    internal static string Current
    { get; private set; }
 
    internal static
      Collection<string> OpenFiles
    { get; private set; }
 
 
    public static object[] GetArgs(
      string file, byte task)
    {
      if (string.IsNullOrEmpty(file))
        throw new
          ArgumentException(MCR.Err9);
 
      var mn1 = Path
        .GetFileNameWithoutExtension(file);
      var arr = new Collection<byte>{task};
      // if not coll ^ bytes reset at usage.
      var obj = new object[]
      { file, 0, 0, arr, true, mn1, true };
      return obj;
    }
 
    #region args_Doc
    // mmf = Memory Mapped File(s) Arguments
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // args[0] = Full Path to mmf.
    // args[1] = Size of file in bytes,
    // args[2] = Start @ Byte (offset)
    // args[3] = What to write? (OR Shred? T/F)
    // args[4] = true; Read?
    // args[5] = this mapping's name.
    // args[6] = true; Delete after Read?
    // args[7] = View Length from Offset.
    // (if Given) Not Required, either way.8
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #endregion
 
 
    /// <summary> Entry Point 4 Search Class
    /// NOTE: few.Count == 0 is Okay.
    /// </summary>
    /// <param name="find"></param>
    /// <param name="all"></param>
    /// <param name="few"></param>
    public static void Search(
      string find,
      Collection<string> all,
      Collection<string> few)
    {
      if ( few == null
        || all == null
        || all.Count < 1
        || SearchIsOpen()) return;
 
      if (few.Count.Equals(1)
        && Application.ExecutablePath
        .Contains(MCR.MyApp))
          ItsMeCalling(all, few); // <-===<<
      else
      {
        OpenFiles = new 
          Collection<string>();
        WholeList = all;
        Selected  = few;
      }
      if (string.IsNullOrEmpty(find)
        || find.Equals(MCR.Search1))
        find = GetSearchDefault;
 
      var thd = new Thread(Search2)
      { Name  = "Search2" };
      thd.Start(find);
    }
 
    // REM: New Worker-Thread from here-on!
    static void Search2(object obj)
    {
      SearchOpenToggle();
      using (var sf = new SearchForm())
      {
        sf.Search4(obj as String);
        sf.ShowDialog();
      }
      Current  = null;
      Selected = WholeList = null;
      SearchOpenToggle();
    }
 
    static void SearchOpenToggle()
    {
      var  f = SearchOpenName();
      if ( File.Exists(f)) File.Delete(f);
      else File.WriteAllText(f,
        MCR.SearchOpenTxt + // Arbitrary atm
           Application.ExecutablePath);
    }
 
    static bool SearchIsOpen()
    {
      if (!File.Exists(
        SearchOpenName())) return false;
      if (!MCT.Skip) MessageBox
        .Show(MCR.SearchOpenTxt);
      return true;
    }
 
    static string SearchOpenName()
    {
      return
        Application.StartupPath +
          MCR.Search_Running;
    }
 
    // REM: it's ME calling so
    // Editor file is Current.
    // Makes Open = Selection.
    // Goes and gets Favorites.sme
    // data and sets as WholeList.
    static void ItsMeCalling(
      Collection<string> all,
      IList<string> few)
    {
      var file = MCT.GetRoot + MCR.Favs;
      var fav  = MCT.GetList(file);
 
      if ( string.IsNullOrEmpty(file)
        || !File.Exists(file)
        || all.Equals(null)
        || all.Count < 1
        || few.Equals(null)
        || few.Count < 1
        || fav.Equals(null)
        || fav.Count < 1) return;
 
      // Swap around & ready for SearchForm.
      Current   = few[0];// Editing file.
      OpenFiles = Selected = all;
      WholeList = fav; // <===<< from disk. 
    }
 
    public static bool IsFile(string text)
    {
      if (string.IsNullOrEmpty(text)
        || text.Length < 1) throw new
        ArgumentException(
        "Bad arg in IsFile");
 
      return
        text.Contains("\\")
        && text.Contains(":")
        && File.Exists(text);
    }
#endregion Search Members
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
 
 
  }
}

Comments