Advertisement
GlobalAccessSoftware

Smesa.cs

Apr 26th, 2019
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.32 KB | None | 0 0
  1.  
  2.  
  3. #region Top Part
  4. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  5. // Smesa.cs v1.0.1.00 02-Oct-2017
  6. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  7. // Created by Jp Edwards as Shareware
  8. // and as a Fresher Course in Windows
  9. // Forms Apps, OOP and C#.NET
  10. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  11. // This is an Early Version meant to
  12. // inspire freshers to dive right in
  13. // and away from mere console Apps, etc.
  14. // I've left many many things for you to
  15. // code and experiment with. Just beware
  16. // of the standard license and rights.
  17. // i.e. Share your improvements!
  18. // Ask questions, Collaborate!
  19. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  20. // v1.0.1.02 02-Oct-17 @ 0455
  21. // v1.0.1.03 03-Oct-17 @ 0643
  22. // v1.0.1.05 07-Oct-17 @ 0000 RC1
  23. // v1.0.1.09 11-Oct-17 @ 0505 RC2b
  24. // v1.0.1.16 23-Oct-17 @ 1220 BRC1
  25. // v1.0.1.20 28-Oct-17 @ 2231 ReDesigns
  26. // v1.0.2.21 29-Oct-17 @ 0116 ReDesigns
  27. // v1.0.2.25 12-Nov-17 @ 0130 Stabilize.
  28. // v1.0.3.26 25-Nov-17 @ 2344 Perfected.
  29. // v1.1.4.26 10-Dec-17 Newest Mods & Ver
  30. // Ready for complete Isolation
  31. // v2.2.5.26zz 28-Dec-2017 Set to fully
  32. // pound on Rev2. Mods are in Tests are
  33. // going well, but a few last things to
  34. // resolve before I can truly call it 27
  35. // v2.2.6.27agate 07-Jan-2018 Minor Rev.
  36. // Fully Working with Multi-Tab and
  37. // ready for Serious Beta-Testing and
  38. // further modification & enhancements.
  39. // v2.3.6.27alaru 10-Dec-18 Behavior.
  40. // v2.3.7.28alfy  22-Jan-18 Integration
  41. // and major mods here and there for
  42. // Multi-Tab. Then, BAM! WOW!
  43. // v2.3.8.29algor 24-Jan-18 Multiple
  44. // fixes and upgrades, evolved in testin
  45. // and is the best I've seen so far!
  46. // v2.5.9.30 04-Feb-2018 Multi-Load and
  47. // Multi-Load-WHILE-RUNNING mods finish!
  48. // v2.5.9.31 08-Feb-2018 MultiLoad Mods!
  49. // v2.6.1.32 20-Feb-2018 0145 Threading.
  50. // v2.6.1.33 22-Feb-2018 MMF & Trigger.
  51. // v3.0.0.01 25-feb-2018 As WPF App.
  52. // Experimental to pass args to an
  53. // active 1st instance Smesa from a
  54. // 2nd Instance AppLaunch2 MyOtherApp.
  55. // v3.0.0.36 28-Feb-2018 0420 MyApp WPF
  56. // v3.0.1.37 01-Mar-2018 Reverted Hybrid
  57. // v3.1.1.39 10-Mar-2018 Fully Working++
  58. // v3.2.3.43 28-Mar-2018 Preferences2+
  59. // v3.2.3.43 29-Mar-2018 GetCharCount();
  60. // v4.3.5.49 22-Apr-2018 Integrated.
  61. // v4.5.7.59 05-Jul-2018 MyToolbox
  62. // v4.5.8.60 18-Jul-18 Shared Info!
  63. // v4.5.8.60 23-Jul-18 FULLY TESTED!
  64. // v4.5.8.60 26-Jul 4 Hooks 4 Shared.sme
  65. // Search usages of WriteSharedData();
  66. // v4.5.8.61 30-Jul-2018 ^ Perfecting.
  67. // v4.5.8.61 03-Aug Integration w/ Shared.sme
  68. // v4.5.9.63 Omega Plan 11-Aug-2018
  69. // v4.5.9.63 15-Aug-2018 Complete & TestsWell.
  70. // v4.5.9.64 21-Aug Fixed and finalized
  71. // v4.6.9.65 To Keep Smesa simple: (Kiss mods)
  72. // v4.6.9.66 05-Sep WriteShared Mods.
  73. // v4.6.9.68 10-Sep-2018 Final Wipe Testing.
  74. // v4.6.9.69 17- " " Perfected PathPb
  75. // v4.7.0.70 18-" " Assy Thread Safe / IO Safe.
  76. // v4.7.0.71 19-Sep About Colors.
  77. // v4.7.0.72 21-Sep-2018 RC
  78. // v4.8.0.76 30-Sep MCT.SaveList & GetList mods
  79. // v4.8.2.82 26-Oct-2018 Wrap Mod integration.
  80. // v4.9.3.88 16-Nov-2018 Removals / Favorites.
  81. // v4.9.4.89 Fellback to 49488G01RC but only
  82. // for MyEditor Project no others. (Removals)
  83. // v4.9.4.90 27-Nov-2018 ReadRemovals() and
  84. // GetSelectedIndex() integration completed.
  85. // NOTE: See calls to GetSelectedIndex();
  86. // v4.9.4.91 01-Dec-2018 Integration ^
  87. // v5.0.6.00 21-Feb-19 List<T> to Collection<T>
  88. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  89.  
  90. using System;
  91. using System.Collections.ObjectModel;
  92. using System.Collections.Specialized;
  93. using System.IO;
  94. using System.Linq;
  95. using System.Threading;
  96. using System.Windows.Forms;
  97.  
  98. // Shortcut Class Aliases
  99. using MCD = MyCustomLibrary.Dialogs;
  100. using MCT = MyCustomLibrary.MyToolbox;
  101. using MWS = MyEditor.WriteShared;
  102. using SMF = ShowMe.ShowMeForm;
  103.  
  104. // Local Properties Shortcut Aliases
  105. using SMR = MyEditor.Properties.Resources;
  106. using SMS = MyEditor.Properties.Settings;
  107.  
  108. namespace MyEditor
  109. {
  110.   public partial class Smesa : Form
  111.   {
  112.      /****************************************/
  113.     /* See SmasaHeader.cs for Class Globals */
  114.    /****************************************/
  115.  
  116.     // Class Constructor 1st Instance Only.
  117.     public Smesa(string[] args, string memo)
  118.     {
  119.       #region Release version testcode
  120.       //MessageBox.Show(string.Format(
  121.       //  "Smesa Constructor:\n\n" +
  122.       //  "memo contains:\n{0}", memo));
  123.       #endregion
  124.       Mapped = memo;
  125.       Args = MCT.GetCommandLine(args);
  126.       Watcher = new FileSystemWatcher();
  127.       InitializeComponent();
  128.       ProgressBar1.Value = 0;
  129.       StatusLabel.Text = SMR.Status_Hello;
  130.     }
  131. #endregion Top Part
  132.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  133.  
  134.  
  135. #region Startup Code
  136.  
  137.     /// <summary> Form Loading Eventhandler
  138.     /// Called as the Form First Opens.
  139.     /// </summary>
  140.     /// <param name="sender"></param>
  141.     /// <param name="e"></param>
  142.     private void SmesaLoading
  143.       (object sender, EventArgs e)
  144.     {
  145.       ProgressBar1.Value = 6;
  146.       Size = SMS.Default.AppSize;
  147.       Location = SMS.Default.AppLocation;
  148.       BackColor = SMS.Default.AppColor;
  149.       _index = TabControl.TabPages[0]
  150.         .Controls.IndexOf(RichTextBox1);
  151.       ReadRemovals();
  152.       // ^ v49488 Hook
  153.       // (see also: GetSelectedIndex)
  154.       if (Args != null && Args.Length > 0)
  155.         ParmsPassedInAtStart();
  156.       ProgressBar1.Value = 24;
  157.       CheckDataFiles();
  158.       ProgressBar1.Value = 69;
  159.       SetPaths(Mapped);
  160.       SetDirectory();
  161.       // ^v Switched order v4.9.4.91b
  162.       SetupOpenFiles();
  163.       GetCharCount();
  164.       MWS.WriteSharedFile(BackColor);
  165.       CheckPref2Collections();
  166.       MmfEventDelegate();
  167.       TestCodeVisibility();
  168.     }
  169.  
  170.     private void TestCodeVisibility()
  171.     {
  172.       TestCode1.Visible =
  173.         nowTestingToolStripMenuItem
  174.           .Visible = MCT.Testing;
  175.     }
  176.  
  177.  
  178. #region Get everything setup & ready.
  179.  
  180.     /// <summary> For Resources Tab in Preferences.
  181.     /// Make Their Documents v Folder Home for Now.
  182.     /// But I want to make this The Reminder to setup
  183.     /// a Prefered Folder or something. -Des
  184.     /// </summary>
  185.     public static void SetDirectory()
  186.     {
  187.       string path;
  188.       if (SMS.Default.EnableRes)
  189.       {
  190.         path = Path.GetDirectoryName(
  191.           SMS.Default.FileNames[
  192.             GetSelectedIndex()]);
  193.       } // Index Bugg ^ Fix.
  194.       else path = MCT.GetDocFolder;
  195.       if (!string.IsNullOrEmpty(path)
  196.         && Directory.Exists(path))
  197.           Directory.SetCurrentDirectory(path);
  198.     }
  199.  
  200.     /// <summary> Checks the last used index
  201.     /// if it has been removed or deleted we
  202.     /// adjust SMS.Default.Index accordingly.
  203.     /// v4.9.4.89 24-Nov-2018 -JpE-
  204.     /// </summary>
  205.     /// <returns></returns>
  206.     private static int GetSelectedIndex()
  207.     {
  208.       // Updated to v4.9.4.90
  209.       var tab = SMS.Default.Index;
  210.       var las = SMS.Default.FileNames.Count-1;
  211.       if (las < 1) return 0;
  212.       while (  tab > las || tab < 0)
  213.       { while (tab > las) --tab;
  214.         while (tab < 0) ++tab; }
  215.       SMS.Default.Index  = tab;
  216.       SMS.Default.Save();
  217.       return tab;
  218.     }
  219.  
  220.     /// <summary> Called when the Form is
  221.     /// First Shown, but, After FormLoading.
  222.     /// </summary>
  223.     /// <param name="sender"></param>
  224.     /// <param name="e"></param>
  225.     private void ShownForm(
  226.       object sender, EventArgs e)
  227.     {
  228.       var t = TabControl.SelectedIndex =
  229.         GetSelectedIndex();
  230.       #region Event ^ Note
  231.       // ^ This lil guy Triggers TabChange() event:
  232.       // Then Editing and everything does the rest.
  233.       // Makes sure the Filename is the Tab-text &
  234.       // all that stuff, Colors per extension, etc.
  235.       #endregion
  236.       // Startup Focus Mods.
  237.       SaveButton.Enabled =
  238.         SaveAllButton.Enabled = false;
  239.       var c = SMS.Default.FileNames.Count - 1;
  240.       if (t > c) t = c;
  241.       RichTextBox rtb;
  242.       try { var b = TabControl.TabPages.Count;
  243.         while (t > b && t > -1) --t;
  244.         rtb = TabControl.TabPages[t]
  245.           .Controls[_index] as RichTextBox;
  246.       } catch (ArgumentOutOfRangeException)
  247.       { if (MCT.Testing && !MCT.Skip)
  248.           MessageBox.Show(SMR.Range);
  249.         return; }
  250.       catch (ArgumentException)
  251.       { if (MCT.Testing && !MCT.Skip)
  252.           MessageBox.Show(SMR.Argument);
  253.         return; }
  254.       WordWrap.Checked = MCT.Wrap;
  255.       if (rtb == null) return;
  256.       rtb.Focus();
  257.       GetCharCount(null, true);
  258.       ProgressBar1.Value = 100;
  259.     }
  260.  
  261.     /// <summary> Checks FileName Collection
  262.     /// Initiating it if necessary, adding default
  263.     /// FileName to the Collection for first tab.
  264.     /// </summary>
  265.     private void CheckDataFiles()
  266.     {
  267.       if (SMS.Default.FileNames == null)
  268.         SMS.Default.FileNames =
  269.           new StringCollection();
  270.       var i = SMS.Default.FileNames.Count;
  271.       // Rev2 Multi-Tab
  272.       if (i >= 1) return;
  273.       var r = TabControl.TabPages[i]
  274.         .Controls[_index] as RichTextBox;
  275.       if (r == null) throw new
  276.         ArgumentException(
  277.           "CheckDataFiles");
  278.       r.Clear();
  279.       SMS.Default.FileNames.Add(
  280.         GetDefaultFileName(i));
  281.     }
  282.  
  283.     /// <summary> Adds the tab number to the
  284.     /// Default FileName for this Application
  285.     /// where tab number == index + 1;
  286.     /// </summary>
  287.     /// <param name="tab"></param>
  288.     /// <returns>
  289.     /// default filename for this tab number.
  290.     /// </returns>
  291.     public static string
  292.       GetDefaultFileName(int tab)
  293.     {
  294.       var dflt = SMS.Default.DefaultFile;
  295.       var fnmn = Path
  296.         .GetFileNameWithoutExtension(dflt);
  297.       if ( tab > int.MaxValue -1) tab = 0;
  298.       var nmbr = string.Format(
  299.         "({0})", Convert.ToString(tab + 1));
  300.       var exts = Path.GetExtension(dflt);
  301.       if (SMS.Default.PrefRTF)
  302.         exts   = SMS.Default.SpecialExt;
  303.       return fnmn + nmbr + exts;
  304.     }
  305.  
  306.     /// <summary> Brings relevant collections
  307.     /// up or down to the same Count as the
  308.     /// FileName collection.
  309.     /// </summary>
  310.     private void Check5()
  311.     {
  312.       CheckForDuplicates();
  313.       // ^ filenames only.
  314.       EvenUpData();
  315.       // split it out to call separately.
  316.     }
  317.  
  318.     private void EvenUpData()
  319.     {
  320.       var f = SMS.Default.FileNames.Count;
  321.       var s = SMS.Default.SaveMe.Count;
  322.       var c = SMS.Default.BarValue.Count;
  323.       var z = SMS.Default.Zoo.Count;
  324.       var p = SMS.Default.Curses.Count;
  325.       var u = SMS.Default.Status.Count;
  326.       if (f == s && f == c && f == z
  327.           && f == p && f == u) return;
  328.       var i = s;
  329.       while (i++ < f)
  330.         SMS.Default.SaveMe.Add("0.00");
  331.       while (s-- > f)
  332.         SMS.Default.SaveMe.RemoveAt(s);
  333.       i = c;
  334.       while (i++ < f)
  335.         SMS.Default.BarValue.Add("100");
  336.       while (c-- > f)
  337.         SMS.Default.BarValue.RemoveAt(c);
  338.       i = z;
  339.       while (i++ < f)
  340.         SMS.Default.Zoo.Add("1.0");
  341.       while (z-- > f)
  342.         SMS.Default.Zoo.RemoveAt(z);
  343.       i = p;
  344.       while (i++ < f)
  345.         SMS.Default.Curses.Add("0, 0");
  346.       while (p-- > f)
  347.         SMS.Default.Curses.RemoveAt(p);
  348.       i = u;
  349.       while (i++ < f)
  350.         SMS.Default.Status.Add(StatusLabel.Text);
  351.       while (u-- > f)
  352.         SMS.Default.Status.RemoveAt(u);
  353.       SMS.Default.Save();
  354.     }
  355.  
  356.     /// <summary> Last ones first removal
  357.     /// as first ones first would change index,
  358.     /// dropping everything down 1 for each one.
  359.     /// Updated to Assure File Exists. v2.2.5.27
  360.     /// </summary>
  361.     private void CheckForDuplicates()
  362.     {
  363.       var idx = -1;
  364.       var tab = new Collection<int>();
  365.       var cpy = new StringCollection();
  366.       foreach (var fn in SMS.Default.FileNames)
  367.       {
  368.         ++idx;
  369.         if (!cpy.Contains(fn)) cpy.Add(fn);
  370.         else tab.Add(idx);
  371.       }
  372.       var c = tab.Count;
  373.       var t = c > 0;
  374.       while (c > 0)
  375.         SMS.Default.FileNames.RemoveAt(tab[--c]);
  376.       // Rev2 Evolutions.
  377.       if (!t) return;
  378.       // if (first) File Not Found.
  379.       if (SMS.Default.FileNames.Count < 1)
  380.       {
  381.         SMS.Default.FileNames.Add(
  382.           GetDefaultFileName(0));
  383.         ZeroSaveMeItem(0);
  384.       }
  385.       SMS.Default.Save();
  386.     }
  387. #endregion Get everything setup & ready.
  388.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  389.  
  390.  
  391. #endregion Startup
  392.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  393.  
  394.  
  395. #region Form Active Code
  396.  
  397.     /// <summary> Keydown Eventhandler detects
  398.     /// keystrokes as part of the current scheme.
  399.     /// </summary>
  400.     /// <param name="sender"></param>
  401.     /// <param name="e"></param>
  402.     private void SmesaKeyDown
  403.       (object sender, KeyEventArgs e)
  404.     {
  405.       var key = e.KeyValue;
  406.       if (_lastKey == 17 &&
  407.         (key == 107 || key == 109))
  408.       { // + is 107  &   - is 109
  409.         if (key == 107) ZoomIn();
  410.         else ZoomOut();
  411.       }
  412.       _lastKey = key;
  413.       if (MCT.NoCount(e))
  414.       {
  415.         if (ProgressBar1.Value < 100)
  416.           UnshadyMethod();
  417.         return;
  418.       }
  419.       SaveOrNot();
  420.       if (ProgressBar1.Value < 100)
  421.         UnshadyMethod();
  422.       GetCharCount(e);
  423.     }
  424.  
  425.     private void GetCharCount(
  426.       KeyEventArgs e = null,
  427.       bool context = false)
  428.     {
  429.       var tab = TabControl.SelectedIndex;
  430.       var rtb = TabControl.TabPages[tab]
  431.         .Controls[_index] as RichTextBox;
  432.       if (rtb == null) return;
  433.       var offset = 1; // v3.2.3.46
  434.       if (context) offset = 0;// YES!
  435.       // Count Fixed ^v w/ offset thusly:
  436.       var d = Keys.F22;// or any Random Key.
  437.       if (e != null) d = e.KeyData;
  438.       if (Keys.Delete.Equals(d)
  439.         || Keys.Back.Equals(d)) offset = -1;
  440.       CharacterCountLabel.Text = string.Format(
  441.         "{0} chars.", rtb.Text.Length + offset);
  442.     }
  443.  
  444.     /// <summary> Determines the Users Preference
  445.     /// for Saving File Automatically or Manually.
  446.     /// </summary>
  447.     private void SaveOrNot()
  448.     {
  449.       var tab = TabControl.SelectedIndex;
  450.       if (tab < 0) tab = 0;
  451.       if (ProgressBar1.Value <= 0)
  452.         ZeroedOut(tab);
  453.       else
  454.         StepDown(tab);
  455.       SMS.Default.BarValue[tab] =
  456.         Convert.ToString(
  457.         ProgressBar1.Value);
  458.       SMS.Default.Save();
  459.     }
  460.  
  461.     /// <summary> Increments the ProgressBar
  462.     /// and SaveMe values every 1/sms.step
  463.     /// keystrokes. OR from 100 to 99 v26.
  464.     /// Also Sets the Status Label Message.
  465.     /// </summary>
  466.     /// <param name="tab"></param>
  467.     private void StepDown(int tab)
  468.     {
  469.       var num = GetDecimal(tab);
  470.       var whole = MCT.GetWhole(num);
  471.       if (num != whole
  472.         && ProgressBar1.Value
  473.           != 100) return;
  474.       if (ProgressBar1.Value > 0)
  475.         ProgressBar1.Value--;
  476.       UnshadyMethod();
  477.     }
  478.  
  479.     private decimal GetDecimal(int tab)
  480.     {
  481.       decimal num;
  482.       var c = SMS.Default.SaveMe.Count;
  483.       if (tab < c)
  484.       { try
  485.         { num = Convert.ToDecimal(
  486.             SMS.Default.SaveMe[tab]); }
  487.         catch (FormatException) { num = 0; }
  488.         catch (OverflowException) { num = 0; }
  489.       }
  490.       else
  491.       { Check5();
  492.         return 00000; }
  493.       SMS.Default.SaveMe[tab] =
  494.         Convert.ToString(num += SMS.Default.Step);
  495.       SMS.Default.Save();
  496.       return num;
  497.     }
  498.  
  499.     /// <summary> Handles Zeroed state of ProgressBar.
  500.     /// SaveMe is a Collection of Decimals, 1 for each tab.
  501.     /// Increments the decimal, converts it back to a...
  502.     /// string & assigns it to the SaveMe[indx] Collection.
  503.     /// So...
  504.     /// Note the dual incrementation of SaveMe[indx]
  505.     /// & deci values. Adjust Step intervals in
  506.     /// the Settings Designer, it's at 0.1 now.
  507.     /// </summary>
  508.     /// <param name="tab"></param>
  509.     private void ZeroedOut(int tab)
  510.     {
  511.       // Resets ProgressBar & Status Text.
  512.       if (SMS.Default.SaveSet)
  513.       {
  514.         if (SMS.Default.SaveIt)
  515.         {
  516.           SaveClick("KeyDown", EventArgs.Empty);
  517.           ZeroSaveMeItem(tab);
  518.         }
  519.       }
  520.       else SaveNotSet(tab);
  521.     }
  522.  
  523.     private void SaveNotSet(int tab)
  524.     {
  525.       // If SaveSet then forget the below.
  526.       var deci = Convert.ToDecimal(
  527.         SMS.Default.SaveMe[tab]);
  528.       SMS.Default.SaveMe[tab] =
  529.         Convert.ToString(deci +=
  530.           SMS.Default.Step);
  531.       var hits = 0;
  532.       var past = Convert.ToString(
  533.         250 + SMS.Default.Step);
  534.       // Move past ^ once hit.
  535.       if (deci > 125 && deci < 250)
  536.         hits = PromptForSave(tab, past);
  537.       past = Convert.ToString(
  538.         600 + SMS.Default.Step);
  539.       if (deci > 400 && deci < 600)
  540.         hits = PromptForSave(tab, past);
  541.       if (SMS.Default.SaveIt
  542.         && SMS.Default.SaveSet)
  543.         SaveClick("KeyDown", EventArgs.Empty);
  544.       if (hits > 0)
  545.         SetSavePref(hits, tab);
  546.       SMS.Default.Save();
  547.     }
  548.  
  549.     private int PromptForSave(
  550.       int tab, string past)
  551.     {
  552.       SMS.Default.SaveMe[tab] = past;
  553.       KeyDown -= SmesaKeyDown;
  554.       var test = MCD.GetSavePreference();
  555.       KeyDown += SmesaKeyDown;
  556.       return test;
  557.     }
  558.  
  559.     /// <summary> Handles Input from GetSavePref:
  560.     /// YesNoAlways Legend: 1 = Yes, 2 = No,
  561.     /// 3 = Yes as Pref. 4 = No as Pref.
  562.     /// </summary>
  563.     /// <param name="state"></param>
  564.     /// <param name="tab"> </param>
  565.     private void SetSavePref(int state, int tab)
  566.     {
  567.       switch (state)
  568.       {
  569.         case 1: SaveCurrentFile(tab);
  570.           break;
  571.         case 2: // do nothing
  572.           break;
  573.         case 3: SaveCurrentFile(tab);
  574.           SMS.Default.SaveIt = true;
  575.           break;
  576.         case 4: SMS.Default.SaveIt = false;
  577.           break;
  578.       }
  579.       SMS.Default.SaveSet = state > 2;
  580.       SMS.Default.Save();
  581.     }
  582. #endregion Smeasa Form Active Code
  583.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  584.  
  585.  
  586. #region View And Zoom Menu Items
  587.  
  588.     private void ShowLists(
  589.       object sender, EventArgs e)
  590.     {  
  591.       string sl="", f = "";
  592.       const string lf = "\n";
  593.       sl = SMS.Default.Favorites
  594.         .Cast<string>().Aggregate(
  595.           sl, (current, file) =>
  596.             current + (file + lf));
  597.       var app  = Path.GetDirectoryName(
  598.         Mapped) + SMR.Sme;
  599.       if (!File.Exists(app))
  600.       { var cn = SMR.Show2;
  601.         var nf = SMR.ShowList;
  602.         var fn = SMR.Sme.Substring(1);
  603.         var tx = string.Format(
  604.           "{0}{1}{2}{3}", fn, cn, lf, nf);
  605.         MessageBox.Show(tx);
  606.         return; }
  607.       var str = string.Format(
  608.         "Files:{0}{1}", lf, sl);
  609.       str = str.Replace("\\", "/");
  610.       MCT.RunApp(str, SMR.Ttl1, app);
  611.       Thread.Sleep(400);
  612.       f = SMS.Default.DataFolders
  613.         .Cast<string>().Aggregate(
  614.           f, (current, dir) =>
  615.             current + (dir + lf));
  616.       var fldr = string.Format(
  617.         "Folders:{0}{1}", lf, f);
  618.       fldr = fldr.Replace("\\", "/");
  619.       MCT.RunApp(fldr, SMR.Ttl2, app);
  620.     }
  621.  
  622.     // Multi-Tab Upgraded.
  623.     // MCT.Wrap v4.8.2.82 25-Oct-2018
  624.     private void WordWrapClick
  625.       (object sender, EventArgs e)
  626.     {
  627.       MCT.Wrap = // <-= 1 of 2 new lines.
  628.         WordWrap.Checked =
  629.           !WordWrap.Checked;
  630.       for (var i = 0; i < SMS.Default
  631.         .FileNames.Count; ++i)
  632.       {
  633.         var rtb = TabControl.TabPages[i]
  634.           .Controls[_index] as RichTextBox;
  635.         if (rtb == null) continue;
  636.         SMS.Default.Zoo[i] =
  637.           Convert.ToString(
  638.             rtb.ZoomFactor);
  639.         rtb.WordWrap = MCT.Wrap;// <-= 2 of 2
  640.         rtb.ZoomFactor =
  641.           Convert.ToSingle(
  642.             SMS.Default.Zoo[i]);
  643.       }
  644.       SMS.Default.Save();
  645.     }
  646.  
  647.     private void ZoomIndexChanged(
  648.       object sender, EventArgs e)
  649.     {
  650.       if (Zoomed) return;
  651.       Zoomed  = true;
  652.       var sgl = Convert.ToSingle(
  653.         ZoomMenu.SelectedIndex + 1) / 10;
  654.       // Multi-Tab updated Rev2.
  655.       var tab = TabControl.SelectedIndex;
  656.       var rtb = TabControl.TabPages[tab]
  657.         .Controls[_index] as RichTextBox;
  658.       if (rtb == null) return;
  659.       rtb.ZoomFactor = sgl;
  660.       Zoomed = false;
  661.     }
  662.  
  663.     private void TabChange
  664.       (object sender, EventArgs e)
  665.     {
  666.       var next = Convert.ToString(
  667.         sender).Contains("Next");
  668.       var c = TabControl.TabCount;
  669.       var t = TabControl.SelectedIndex;
  670.       if (next) TabControl.SelectedIndex =
  671.         #region Event ^ Note
  672.           // ^ This li guy Triggers TabChange() event:
  673.           // Then Editing and everything does the rest.
  674.           // Makes sure the Filename is the Tab-text &
  675.           // all that stuff, Colors per extension, etc.
  676.         #endregion
  677.         ++t < c ? t : 0;
  678.       // else PreviousTab then.
  679.       else TabControl.SelectedIndex =
  680.         t-- > 0 ? t : --c;
  681.       #region Event ^ Note
  682.       // ^ This li guy Triggers TabChange() event:
  683.       // Then Editing and everything does the rest.
  684.       // Makes sure the Filename is the Tab-text &
  685.       // all that stuff, Colors per extension, etc.
  686.       #endregion
  687.     }
  688. #endregion View, WordWrap, & Zoom Menu Items
  689.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  690.  
  691.  
  692. #region Closing Code
  693.  
  694.     /// <summary> Form Closing EVenthandler
  695.     /// triggered when the Form is ready to close.
  696.     /// </summary>
  697.     /// <param name="sender"></param>
  698.     /// <param name="e"></param>
  699.     private void SmesaClosing
  700.       (object sender, FormClosingEventArgs e)
  701.     {
  702.       if (Watcher != null) Watcher
  703.         .EnableRaisingEvents = false;
  704.       CheckSaveStatus();
  705.       SaveZoomValues();
  706.       ProgressBar1.Value = 18;
  707.       StatusLabel.Text = SMR.Status_Closing;
  708.       ProgressBar1.Value = 42;
  709.       ProgressBar1.Value = 67;
  710.       SMS.Default.AppSize = Size;
  711.       SMS.Default.AppLocation = Location;
  712.       SMS.Default.AppColor = BackColor;
  713.       ProgressBar1.Value = 83;
  714.       SMS.Default.Index =
  715.         TabControl.SelectedIndex;
  716.       // ^ Saves current tab number.
  717.       LogOut();
  718.       ProgressBar1.Value = 98;
  719.       // Cuz at 100% closed you won't see it!
  720.       StatusLabel.Text = SMR.Status_Bye;
  721.       CheckPref2Collections();
  722.       // ^ See Preferences2.cs
  723.       MWS.WriteSharedFile(BackColor);
  724.       SMS.Default.Save();
  725.       Mx2.Dispose();
  726.     }
  727.  
  728.     private static void CheckPref2Collections()
  729.     { // On Exit.
  730.       var dirs = new StringCollection();
  731.       // First Files, but grab dirs on the fly.
  732.       foreach (var file in SMS.Default.FileNames
  733.         .Cast<string>().Where(file =>
  734.           !string.IsNullOrEmpty(file)
  735.           && File.Exists(file)))
  736.       {
  737.         dirs.Add(Path.GetDirectoryName(file));
  738.         if (!SMS.Default.Favorites.Contains(file))
  739.           SMS.Default.Favorites.Insert(0, file);
  740.       }
  741.       // Maintain Max Collection Count of 128
  742.       while (SMS.Default.Favorites.Count > 128)
  743.         SMS.Default.Favorites.RemoveAt(128);
  744.       // Then do the dirs.
  745.       foreach (var dir in dirs
  746.         .Cast<string>().Where(dir =>
  747.           !SMS.Default.DataFolders.Contains(dir)))
  748.             SMS.Default.DataFolders.Insert(0, dir);
  749.       // Maintain Max Collection Count of 64
  750.       while (SMS.Default.DataFolders.Count > 64)
  751.         SMS.Default.DataFolders.RemoveAt(64);
  752.       var fn = Path.GetDirectoryName(
  753.         BlasterPath) + SMR.Favs;
  754.       if (!File.Exists(fn)) fn =
  755.         Path.GetDirectoryName(Mapped) + SMR.Favs;
  756.       if (!File.Exists(fn)) return;
  757.       MCT.SaveList(
  758.         SMS.Default.Favorites, fn);
  759.     }
  760.  
  761.     /// <summary> Save Zoom Values to
  762.     /// the Collection of same and More.
  763.     /// </summary>
  764.     private void SaveZoomValues()
  765.     {
  766.       Check5();
  767.       for (var i = 0; i < SMS.Default
  768.         .FileNames.Count; ++i)
  769.       {
  770.         // form closing
  771.         var rtb = TabControl.TabPages[i]
  772.           .Controls[_index] as RichTextBox;
  773.         if (rtb == null) continue;
  774.         SMS.Default.Zoo[i] =
  775.           Convert.ToString(rtb.ZoomFactor);
  776.         SMS.Default.Curses[i] =
  777.           string.Format("{0}, {1}",
  778.           Convert.ToString(rtb.SelectionStart),
  779.           Convert.ToString(rtb.SelectionLength));
  780.       }
  781.       SMS.Default.Save();
  782.     }
  783. #endregion Closing Code
  784.     //\\//\\//\\//\\//\\//\\//\\//\\//\\
  785.  
  786.  
  787.     // ALL test code Below here.
  788. #region TestCode
  789.  
  790.     private void NowTestingClick(
  791.       object sender, EventArgs e)
  792.     {
  793.       const string t =
  794.         "Now Testing Removals:\n\n";
  795.       if (!MCD.YesNoDialog((string.Format(
  796.         "{0}{1}", t, DateTime.Now)))) return;
  797.       // This triggers the Watcher and so forth.
  798.       var list  = new Collection<string>
  799.       {MCT.GetDocFolder + "\\About.txt"};
  800.       if ( //list == null ||
  801.         list.Count < 1) return;
  802.       var file  = Path.GetDirectoryName(
  803.         EditorPath) + "\\Editor.sme";
  804.       var path  = Path.
  805.         GetFileNameWithoutExtension(file);
  806.       var args  = new object[]
  807.       {
  808.         file, SMS.Default.EditorSize,
  809.         SMS.Default.EditorOffset2,
  810.         list, true, path, false,// Uses...
  811.         SMS.Default.EditorView2//<-= ALL 8
  812.       };
  813.       if (!MyCustomLibrary.MemoryMapper
  814.         .WriteStrings(args)) throw new
  815.           ArgumentException(
  816.             "Favorites Testing Failed!");
  817.     }
  818.  
  819.     // These Methods for testing purposes
  820.     // only & hidden when not testing.
  821.     private void Test1Click
  822.       (object sender, EventArgs e)
  823.     {
  824.       MessageBox.Show(string.Format("{0}{1}",
  825.         "Test 1 Clicked:\n\n", DateTime.Now));
  826.  
  827.       //var args =
  828.       //  new object[]
  829.       //  {
  830.       //    Mapped, MySize, MyOffset-2,
  831.       //    new Collection<byte> {1}, true, Path
  832.       //    .GetFileNameWithoutExtension(
  833.       //    Mapped), false
  834.       //  };
  835.       //const string txt =
  836.       //  "Write Bytes Failed!\n\n" +
  837.       //  "Please Report Error #5";
  838.       //if (!MemoryMapper.
  839.       //  ReverseWriteBytes(args))
  840.       //    MessageBox.Show(txt);
  841.      
  842.      
  843.       // Space For Rent.
  844.     }
  845. #endregion TestCode
  846.     //\\//\\//\\////\\//\\//\\////\\//\\
  847.  
  848.  
  849. #region Scrap Yard
  850.  
  851.     //private void ShowFileNamesListClick
  852.     //  (object sender, EventArgs e)
  853.     //{
  854.     //  var msg =
  855.     //    SMS.Default.TestFiles.Cast<string>()
  856.     //    .Aggregate("", (current, fn) =>
  857.     //      current + (fn + ", "));
  858.     //  MessageBox.Show(msg);
  859.     //}
  860.  
  861.     //if (SMS.Default.TestFiles == null)
  862.     //  SMS.Default.TestFiles =
  863.     //    new StringCollection();
  864.     //if (SMS.Default.TestFiles != null
  865.     //  && SMS.Default.TestFiles
  866.     //    .Count.Equals(3))
  867.     //{
  868.     //  var msg =
  869.     //    SMS.Default.TestFiles
  870.     //    .Cast<string>()
  871.     //      .Aggregate("", (current, fn)
  872.     //        => current + (fn + ", "));
  873.     //  MessageBox.Show(msg);
  874.     //}
  875.     //if (test Code.InitializeTestFiles())
  876.     //{
  877.     //  Close();
  878.     //  return;
  879.     //}
  880.     //if (SMS.Default.TestFiles == null) return;
  881.     //// Launcher Mods v2.6.1.33 21-Feb-2018
  882.     //var c = SMS.Default.TestFiles.Count;//+ 2;
  883.     //var args = new string[c];
  884.     //for (var i = 0; i < c; ++i)
  885.     //  args[i]  = SMS.Default.TestFiles[i];
  886.     //if (!YesNoDialog(
  887.     //  "Run the Simulation Now?", "", 1)) return;
  888.     //if (Watcher != null)
  889.     //  Watcher.EnableRaisingEvents = false;
  890.     //MmfClientSideWrite(args, Mapped);
  891.     //if (!YesNoDialog(
  892.     //  "Run the Reader Now?", "", 1)) return;
  893.     //MmfServerSide(true);
  894.     //if (Watcher != null)
  895.     //  Watcher.EnableRaisingEvents = true;
  896.  
  897.  
  898.     //MyCustomLibrary.MCT.RunApp(args);
  899.  
  900.       //const string p =
  901.       //  "Nothing Pending.";
  902.       //MessageBox.Show(p);
  903.  
  904.     //private static void Msg()
  905.     //{
  906.     //  const string msg =
  907.     //    // as are Calls to it.
  908.     //  "Under Construction, Please Return.";
  909.     //  MessageBox.Show(msg);
  910.     //}
  911.  
  912.     //private void Test2()
  913.     //{
  914.     //  var c = SMS.Default.TestFiles.Count;
  915.     //  Args  = new string[c];
  916.     //  for (var i = 0; i < c; ++i)
  917.     //    Args[i] = SMS.Default.TestFiles[i];
  918.     //  ParmsPassedInAtStart();
  919.     //}
  920.  
  921.       //var t = new test Code(1);
  922.       //switch (t.Tested)
  923.       //{
  924.       //  case 3:
  925.       //    Close();
  926.       //    break;
  927.       //  case 1:
  928.       //    ShowFileNamesListClick(
  929.       //      "", EventArgs.Empty);
  930.       //    break;
  931.       //}
  932.       //if (YesNoDialog(
  933.       //  "Test Parameters Passed In Now?",
  934.       //  "Beta Testers Only:"))
  935.           //Test2();
  936.     //const string txt = "Result: \n\n";
  937.     //var test = TabPrompt(
  938.     //  TabControl.SelectedIndex);
  939.     ////var test = MCD.GetSavePref();
  940.     //MessageBox.Show(txt + test);
  941.      
  942.       //MmfClientSideWrite(args);
  943.  
  944.       ////test Code for ByteReader
  945.       //MmfServerSide(true);
  946.  
  947. #endregion Scrap Yard
  948.     //\\//\\//\\////\\//\\//\\////\\//\\
  949.  
  950.  
  951.   }
  952. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement