Advertisement
GlobalAccessSoftware

MyDialogs.cs (lower level connecting code)

Oct 3rd, 2019
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.97 KB | None | 0 0
  1.  
  2. #region Top Part
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyDialogs.cs AppStatic Assembly
  5. // Tools and Dialogs among others.
  6. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  7. // Brought over from Smesav Project
  8. // AppStatic.Tools & .Dialogs are
  9. // Independent like MyCustomControl
  10. // v2.3.7.27 15-Dec-2018 -JpE-
  11. // v4.5.7.57 09-Jun-18
  12. // v4.5.7.58 03-Jul-18 ReOrganized.
  13. // v4.7.0.71 19-Sep About Colors.
  14. // v5.0.6.01 06-Mar-2019 Overloads
  15. // v5.2.7.12 02-May-2019 Search Pro
  16. // v5.2.7.14 12-May-2019 Perfectionist
  17. // v5.2.8.16 18-May Ready for After Dialog.
  18. // v5.2.8.17 24-May PropertyChangedEvents.
  19. // v5.2.8.18 26-May-2019 Search Pro Design.
  20. // v5.3.0.22 22-Jun Search Pro Development.
  21. // v5.3.1.23 01-Jul light Search touches.
  22. // v5.3.1.24 03-Jul Integrating Search mods.
  23. // v5.3.1.25 10-Jul Final Here in MCD!
  24. // v5.3.3.28 21-July SmesaSearch.cs rockin'
  25. // v5.4.5.32 07-Aug-2019 Search & Replace.
  26. // v5.4.6.36 04-Sep Search string, BuggFixxd
  27. // & further refined Search Launch. ++ 9-07
  28. // v5.4.6.37 10-Sep-2019 Shakedown 4 Search.
  29. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  30.  
  31. using System;
  32. using System.Collections.ObjectModel;
  33. using System.IO;
  34. using System.Drawing;
  35. using System.Threading;
  36. using System.Windows.Forms;
  37. using System.Collections.Generic;
  38.  
  39. // My Custom Controls Class
  40. using MyCustomControls;
  41.  
  42. // & My Custom Library alias
  43. using MCT = MyCustomLibrary.MyToolbox;
  44.  
  45. // & Custom Property Aliases
  46. using MCS = MyCustomLibrary
  47.   .Properties.Settings;
  48. using MCR = MyCustomLibrary
  49.   .Properties.Resources;
  50.  
  51. #endregion Pop Tart
  52.  
  53.  
  54. namespace MyCustomLibrary
  55. {
  56.   /**  MyCustomControls Legend: **
  57.    *******************************
  58.    * O1 = MyOpenDialog;
  59.    * R1 = MyRichTextBox;
  60.    * P1 = MyPrintDialog;
  61.    * P2 = MyPreviewControl;
  62.    * P3 = MyPreviewDialog;
  63.    * D1 = MyPrintDoc;
  64.    * P4 = MyPageSetup;
  65.    * M1 = MyPreviewMenuStrip;
  66.    * M2 = MyColorDialog;
  67.    * F0 = MyFontDialog;
  68.    * S1 = MySaveDialog;
  69.    *******************************
  70.    */
  71.  
  72.   public static class Dialogs
  73.   {
  74. #region Everything Else
  75.  
  76.     /// <summary> ReUses About Form
  77.     /// for each Smesa App. Args for
  78.     /// each are passed in; making this
  79.     /// Public Method very ReUsable. -JpE-
  80.     /// v4.5.7.58 03-July-2018
  81.     /// </summary>
  82.     /// <param name="colors"></param>
  83.     /// <param name="args"></param>
  84.     public static void AboutApp(
  85.       IList<Color> colors, IList<string> args)
  86.     {
  87.       if (args == null) return;
  88.       var l = args.Count;
  89.       using (var a = new AboutBox(colors))
  90.       {
  91.         if (l>0) a.Title141(args[0]);
  92.         if (l>1) a.Product1(args[2]);
  93.         if (l>3) a.Rights12(args[3]);
  94.         if (l>4) a.Company4(args[4]);
  95.         if (l>5) a.Describe(args[5]);
  96.         // args for each passed in.
  97.         a.Size = MCS.Default.AboutSize;
  98.         a.Location = MCS.Default.AboutLocation;
  99.         a.ShowDialog();
  100.         MCS.Default.AboutSize = a.Size;
  101.         MCS.Default.AboutLocation = a.Location;
  102.       }
  103.       MCS.Default.Save();
  104.     }
  105.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  106.  
  107.    
  108.     //public static bool // cleanup unused when finished.
  109.     //  YesNoDialog()
  110.     //{ return YesNoDialog(MCR.YND_Txt); }
  111.     //// Defaults to Text, Title, & NO
  112.    
  113.     public static bool
  114.       YesNoDialog(string text)
  115.     {
  116.       return YesNoDialog(
  117.         text, MCR.YND_Ttl);
  118.     }
  119.    
  120.     public static bool YesNoDialog(
  121.       string text, string title)
  122.     {
  123.       const int no = 2;
  124.       return YesNoDialog(
  125.       text, title, no);
  126.     }
  127.     /// <summary> Public Access Multi-Purpose
  128.     /// ReUsable OverLoaded Method-Group
  129.     /// Designed For Extreme ReUse Potential.
  130.     /// Defaults to SMR.AYS_Txt,
  131.     /// title is SMR.AYS_Ttl
  132.     /// The NO (2) button as DEFAULT. NO
  133.     /// v1.0.3.26a 04-Dec-2017
  134.     /// v2.2.5.26y 27-Dec-2017
  135.     /// </summary>
  136.     /// <param name="text"></param>
  137.     /// <param name="title"></param>
  138.     /// <param name="def"></param>
  139.     /// <returns></returns>
  140.     public static bool
  141.       YesNoDialog(string text,
  142.       string title, int def)
  143.     {
  144.       if (MyToolbox.Skip) return true;
  145.       if (def < 1 || def > 2) def = 2;
  146.       if (string.IsNullOrEmpty(text))
  147.         text = MCR.YND_Txt;
  148.       if (string.IsNullOrEmpty(title))
  149.         title = MCR.YND_Ttl;
  150.       var db = MessageBoxDefaultButton.Button2;
  151.       const MessageBoxDefaultButton
  152.         yes  = MessageBoxDefaultButton.Button1;
  153.       if (def < 2) db = yes;
  154.       return
  155.         DialogResult.Yes.Equals(
  156.         MessageBox.Show(text, title,
  157.         MessageBoxButtons.YesNo,
  158.         MessageBoxIcon.Question, db));
  159.     }
  160.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  161.  
  162.  
  163.     //public static DialogResult YesNoCancel()
  164.     //{ return YesNoCancel(MCR.YND_Txt); }
  165.     ///* Default to Text, Title, & NO */
  166.    
  167.     //public static DialogResult
  168.     //  YesNoCancel(string text)
  169.     //{ return YesNoCancel(text, MCR.YND_Ttl); }
  170.     //// Default to Title & NO
  171.  
  172.     public static DialogResult
  173.       YesNoCancel(string text, string title)
  174.     {
  175.       const int cancel = 3;
  176.       return YesNoCancel(text, title, cancel);
  177.     }
  178.     // Default to Cancel              ^
  179.  
  180.     /// <summary> Defaults to ASR.AYS_Txt,
  181.     /// ASR.AYS_Ttl and Cancel.
  182.     /// Returns the Actual Dialog Result.
  183.     /// </summary>
  184.     /// <param name="text"> </param>
  185.     /// <param name="title"> </param>
  186.     /// <param name="def"> </param>
  187.     /// <returns> </returns>
  188.     static DialogResult YesNoCancel(
  189.       string text, string title, int def)
  190.     {
  191.       if (MyToolbox.Skip)
  192.         return DialogResult.Yes;
  193.       if (def < 1 || def > 3) def = 3;
  194.       if (string.IsNullOrEmpty(text))
  195.         text = MCR.YND_Txt;
  196.       if (string.IsNullOrEmpty(title))
  197.         title = MCR.YND_Ttl;
  198.       var
  199.         d = MessageBoxDefaultButton.Button3;
  200.       if (def == 2)
  201.         d = MessageBoxDefaultButton.Button2;
  202.       if (def == 1)
  203.         d = MessageBoxDefaultButton.Button1;
  204.       return
  205.         MessageBox.Show(text, title,
  206.           MessageBoxButtons.YesNoCancel,
  207.           MessageBoxIcon.Information, d);
  208.     }
  209.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  210.  
  211.  
  212.     public static int GetSavePreference()
  213.     {
  214.       const string t = "";
  215.       return GetSavePreference(t);
  216.     }
  217.  
  218.     static int
  219.       GetSavePreference(string text)
  220.     {
  221.       const string t = "";
  222.       return GetSavePreference(text, t);
  223.     }
  224.  
  225.     public static int
  226.       GetSavePreference(
  227.       string text, string title)
  228.     {
  229.       const bool no = false;
  230.       return GetSavePreference(
  231.         text, title, no);
  232.     }
  233.  
  234.     static int
  235.       GetSavePreference(
  236.       string text, string title, bool hide)
  237.     {
  238.       const bool no = false;
  239.       return GetSavePreference(
  240.         text, title, hide, no);
  241.     }
  242.  
  243.     /// <summary> Ask User to Save @ 500 chars.
  244.     /// Their response becomes their default
  245.     /// if CheckBox.Checked, is 1 time otherwise
  246.     /// NOTE: tab = Tab our User has Open, the
  247.     /// Active RTB in the FileName Collection.
  248.     /// v1.0.2.25j Modified for Multi-Use.
  249.     /// </summary>
  250.     /// <param name="text"> </param>
  251.     /// <param name="title"> </param>
  252.     /// <param name="hide"> </param>
  253.     /// <param name="check"> </param>
  254.     public static int GetSavePreference(
  255.       string text, string title,
  256.       bool hide, bool check)
  257.     {
  258.       int status;
  259.       if (hide) check = false;
  260.       using (var y =
  261.         new YesNoAlwaysForm2(text, title))
  262.       {
  263.         y.Check = check;
  264.         y.HideAlways = hide;
  265.         y.Local = MCS.Default.YnaLoca;
  266.         y.ShowDialog();
  267.         MCS.Default.YnaLoca = y.Local;
  268.         status = y.Status; // Get Result.
  269.       }
  270.       MCS.Default.Save();
  271.       return status;
  272.     }
  273.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  274.  
  275.  
  276.     public static int NewTabPrompt()
  277.     {
  278.       int pref;// Awesome and Simple!
  279.       using (var t = new NewTabForm())
  280.       {
  281.         t.ShowDialog();
  282.         pref = t.Preference;
  283.       }
  284.       return pref;
  285.     }
  286.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  287.  
  288.  
  289.     /// <summary> Gets existing FileName(s) w/
  290.     /// Users Input ReDesigned & Moved to MCD
  291.     /// v3.1.3.43 23-Mar-2018
  292.     /// </summary>
  293.     /// <param name="fileNames"></param>
  294.     /// <param name="multiple"></param>
  295.     /// <param name="ext"></param>
  296.     /// <param name="filter"></param>
  297.     /// <param name="dir"></param>
  298.     /// <returns></returns>
  299.     public static string[] FileNameGetter(
  300.       string[] fileNames, bool multiple,
  301.       string ext, string filter, string dir)
  302.     {
  303.       if (fileNames == null
  304.         || fileNames.Length < 1)
  305.           return fileNames;
  306.       OpenFileDialog ofd;
  307.       using (var od = new CustomControl())
  308.       { ofd = od.O1; }
  309.       using (var o = ofd)
  310.       {
  311.         o.Multiselect = multiple;
  312.         o.FileName = fileNames[0];
  313.         o.DefaultExt = ext;
  314.         o.Filter = filter;
  315.         o.FilterIndex = 4;
  316.         o.InitialDirectory = dir;
  317.         if (!o.ShowDialog().Equals(
  318.           DialogResult.OK))
  319.             return fileNames;
  320.         if ( o.Multiselect
  321.           && o.FileNames.Length > 0
  322.           && !string
  323.           .IsNullOrEmpty(o.FileNames[0])
  324.           && File.Exists(o.FileNames[0]))
  325.             fileNames = o.FileNames;
  326.         else
  327.         {
  328.           if (!o.Multiselect && !string
  329.               .IsNullOrEmpty(o.FileName)
  330.               && File.Exists(o.FileName))
  331.             fileNames[0] = o.FileName;
  332.         }
  333.       }
  334.       return fileNames;
  335.     }
  336. #endregion Everything Else
  337.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  338.  
  339.  
  340. #region Static Search Members
  341.  
  342.     static string
  343.       GetSearchDefault
  344.     { get { return Criteria; } }
  345.  
  346.     static string Criteria
  347.     { get { return MCS.Default
  348.       .SearchBoxCollection[0]; } }
  349.  
  350.     internal static
  351.       Collection<string> WholeList
  352.     { get; private set; }
  353.  
  354.     internal static
  355.       Collection<string> Selected
  356.     { get; set; }
  357.    
  358.     // Currently Editing FileName.
  359.     internal static string Current
  360.     { get; private set; }
  361.  
  362.     internal static
  363.       Collection<string> OpenFiles
  364.     { get; private set; }
  365.  
  366.  
  367.     public static object[] GetArgs(
  368.       string file, byte task)
  369.     {
  370.       if (string.IsNullOrEmpty(file))
  371.         throw new
  372.           ArgumentException(MCR.Err9);
  373.  
  374.       var mn1 = Path
  375.         .GetFileNameWithoutExtension(file);
  376.       var arr = new Collection<byte>{task};
  377.       // if not coll ^ bytes reset at usage.
  378.       var obj = new object[]
  379.       { file, 0, 0, arr, true, mn1, true };
  380.       return obj;
  381.     }
  382.  
  383.     #region args_Doc
  384.     // mmf = Memory Mapped File(s) Arguments
  385.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386.     // args[0] = Full Path to mmf.
  387.     // args[1] = Size of file in bytes,
  388.     // args[2] = Start @ Byte (offset)
  389.     // args[3] = What to write? (OR Shred? T/F)
  390.     // args[4] = true; Read?
  391.     // args[5] = this mapping's name.
  392.     // args[6] = true; Delete after Read?
  393.     // args[7] = View Length from Offset.
  394.     // (if Given) Not Required, either way.8
  395.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  396.     #endregion
  397.  
  398.  
  399.     /// <summary> Entry Point 4 Search Class
  400.     /// NOTE: few.Count == 0 is Okay.
  401.     /// </summary>
  402.     /// <param name="find"></param>
  403.     /// <param name="all"></param>
  404.     /// <param name="few"></param>
  405.     public static void Search(
  406.       string find,
  407.       Collection<string> all,
  408.       Collection<string> few)
  409.     {
  410.       if ( few == null
  411.         || all == null
  412.         || all.Count < 1
  413.         || SearchIsOpen()) return;
  414.  
  415.       if (few.Count.Equals(1)
  416.         && Application.ExecutablePath
  417.         .Contains(MCR.MyApp))
  418.           ItsMeCalling(all, few); // <-===<<
  419.       else
  420.       {
  421.         OpenFiles = new
  422.           Collection<string>();
  423.         WholeList = all;
  424.         Selected  = few;
  425.       }
  426.       if (string.IsNullOrEmpty(find)
  427.         || find.Equals(MCR.Search1))
  428.         find = GetSearchDefault;
  429.  
  430.       var thd = new Thread(Search2)
  431.       { Name  = "Search2" };
  432.       thd.Start(find);
  433.     }
  434.  
  435.     // REM: New Worker-Thread from here-on!
  436.     static void Search2(object obj)
  437.     {
  438.       SearchOpenToggle();
  439.       using (var sf = new SearchForm())
  440.       {
  441.         sf.Search4(obj as String);
  442.         sf.ShowDialog();
  443.       }
  444.       Current  = null;
  445.       Selected = WholeList = null;
  446.       SearchOpenToggle();
  447.     }
  448.  
  449.     static void SearchOpenToggle()
  450.     {
  451.       var  f = SearchOpenName();
  452.       if ( File.Exists(f)) File.Delete(f);
  453.       else File.WriteAllText(f,
  454.         MCR.SearchOpenTxt + // Arbitrary atm
  455.            Application.ExecutablePath);
  456.     }
  457.  
  458.     static bool SearchIsOpen()
  459.     {
  460.       if (!File.Exists(
  461.         SearchOpenName())) return false;
  462.       if (!MCT.Skip) MessageBox
  463.         .Show(MCR.SearchOpenTxt);
  464.       return true;
  465.     }
  466.  
  467.     static string SearchOpenName()
  468.     {
  469.       return
  470.         Application.StartupPath +
  471.           MCR.Search_Running;
  472.     }
  473.  
  474.     // REM: it's ME calling so
  475.     // Editor file is Current.
  476.     // Makes Open = Selection.
  477.     // Goes and gets Favorites.sme
  478.     // data and sets as WholeList.
  479.     static void ItsMeCalling(
  480.       Collection<string> all,
  481.       IList<string> few)
  482.     {
  483.       var file = MCT.GetRoot + MCR.Favs;
  484.       var fav  = MCT.GetList(file);
  485.  
  486.       if ( string.IsNullOrEmpty(file)
  487.         || !File.Exists(file)
  488.         || all.Equals(null)
  489.         || all.Count < 1
  490.         || few.Equals(null)
  491.         || few.Count < 1
  492.         || fav.Equals(null)
  493.         || fav.Count < 1) return;
  494.  
  495.       // Swap around & ready for SearchForm.
  496.       Current   = few[0];// Editing file.
  497.       OpenFiles = Selected = all;
  498.       WholeList = fav; // <===<< from disk.
  499.     }
  500.  
  501.     public static bool IsFile(string text)
  502.     {
  503.       if (string.IsNullOrEmpty(text)
  504.         || text.Length < 1) throw new
  505.         ArgumentException(
  506.         "Bad arg in IsFile");
  507.  
  508.       return
  509.         text.Contains("\\")
  510.         && text.Contains(":")
  511.         && File.Exists(text);
  512.     }
  513. #endregion Search Members
  514.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  515.  
  516.  
  517.   }
  518. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement