Advertisement
GlobalAccessSoftware

SmesaNewTab.cs

Apr 26th, 2019
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.90 KB | None | 0 0
  1.  
  2.  
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // NewTabPage.cs From SmesaFileMenu.cs
  5. // 21-Dec-2017 Rev2 begins!
  6. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  7. // v1.2.4.26ninja to become Rev2.2.5.27
  8. // v1.2.5.26saphire 23-Dec-2017
  9. // v2.2.6.27alaru 08-Jan-2018
  10. // v2.3.7.28alfy 22-Jan-2018 Major Mods
  11. // v2.3.8.29algor 24-Jan-18 Multiple
  12. // fixes & upgrades evolved in testing
  13. // and is the best I've seen so far!
  14. // v2.5.9.30 01-Feb-2018 Perfected!
  15. // v2.5.9.31 08-Feb-2018 Editing Final.
  16. // v2.6.0.32 15-Feb-2018 SmesaMmfIpc.cs
  17. // will be more advanced code growth.^^
  18. // v2.6.1.32 20-Feb-2018 0151 Threading.
  19. // v3.0.0.36 28-Feb-2018 0420 WPF MyApp!
  20. // v3.0.1.37 01-Mar-2018 Reverted Hybrid
  21. // v3.1.1.39 08-Mar-2018 Awesome Mods!
  22. // v3.1.3.42 20-Mar-2018 PrefClick Code.
  23. // v4.5.9.62 07-Aug-2018 Default Files.
  24. // v4.5.9.63 Omega Plan
  25. // v4.5.9.63 15-Aug-2018 Cmplt TestsWell.
  26. // v4.6.9.67 09-Sep-2018 Barely touched.
  27. // v4.8.1.77 01-Oct Debugging from FN Mods
  28. // v4.8.2.82 27-Oct Farmed out a few
  29. // static methods to MCT2 and so forth.
  30. // v5.0.5.99 15-Jan-2019 MCPL Design.
  31. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  32.  
  33. using System;
  34. using System.IO;
  35. using System.Linq;
  36. using System.Threading;
  37. using System.Windows.Forms;
  38. using System.Collections.Generic;
  39. using System.Collections.ObjectModel;
  40.  
  41. // Custom NameSpaces
  42. using MyCustomControls;
  43. // Class Aliases
  44. using MCD = MyCustomLibrary.Dialogs;
  45. using MCT = MyCustomLibrary.MyToolbox;
  46. // Property Aliases
  47. using SMS = MyEditor.Properties.Settings;
  48. using SMR = MyEditor.Properties.Resources;
  49.  
  50. namespace MyEditor
  51. {
  52.   public partial class Smesa // <-== NOTE
  53.   {
  54. #region Rev3 Parms Passed-in Handling.
  55.  
  56.     // Keep This For Reference:
  57.     ///// <summary> For Parms Passed in While Running!
  58.     ///// Kills the earlier instance, creating new
  59.     ///// that now has all the files present.
  60.     ///// Awesome v2.5.9.31 08-Feb-2018 perfected.
  61.     ///// </summary>
  62.     //[PermissionSet(SecurityAction.Demand,
  63.     //  Name = "FullTrust")]
  64.     //private static bool
  65.     //  CheckIfA2NdInstance(
  66.     //  string[] args, string mmfn)
  67.     //{
  68.     //  var processes =
  69.     //    Process.GetProcessesByName(
  70.     //      Process.GetCurrentProcess()
  71.     //        .ProcessName).ToList();
  72.     //  if (processes.Count <= 1)
  73.     //    return false; // Nope.
  74.     //  // Yep, this IS a 2nd Instance.
  75.     //  processes.Sort((x, y) =>
  76.     //    DateTime.Compare(
  77.     //    x.StartTime, y.StartTime));
  78.     //  // Current Process Leaves a
  79.     //  MmfClientSideWrite(
  80.     //    GetCommandLine(args), mmfn);
  81.     //  // note and commits suicide.
  82.     //  processes[1].CloseMainWindow();
  83.     //  return true;
  84.     //}
  85.  
  86.     /// <summary> Allows Parms to be passed in
  87.     /// loading those files as well as previously
  88.     /// opened files.
  89.     /// </summary>
  90.     private void ParmsPassedInAtStart()
  91.     {
  92.       // Adds Passed in Files to Open-Files List.
  93.       foreach (var file in Args
  94.         .Where(file =>
  95.           !string.IsNullOrEmpty(file)
  96.           && File.Exists(file)
  97.           && !SMS.Default.FileNames
  98.           .Contains(file)))
  99.             SMS.Default.FileNames.Add(file);
  100.       var ct = Args.Length - 1;
  101.       var hit = false;
  102.       for (var i = ct; i > -1; --i)
  103.       { // v72mods vv
  104.         if (!SMS.Default.FileNames
  105.           .Contains(Args[i])) continue;
  106.         SMS.Default.Index = SMS.Default
  107.           .FileNames.IndexOf(Args[i]);
  108.         hit = true; // ^ Nice Touch!
  109.         break;
  110.       }
  111.       if (!hit) SMS.Default.Index =
  112.         SMS.Default.FileNames.Count -1;
  113.       SMS.Default.Save();
  114.       Args = new string[0];
  115.     }
  116. #endregion Rev3 Parms Passed-in Handling.
  117.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  118.  
  119.  
  120. #region MultiSelect Method Group.
  121.  
  122.     /// <summary> Posted from a worker thread
  123.     /// in SmesaMmfIpc.MmfServerSide lines 73 & 79.
  124.     /// See: WindowsFormsSynchronizationContext
  125.     /// v3.1.1.39 08-Mar-2018 integrated new method
  126.     /// Also called from Smesa.OpenSelectedFiles on
  127.     /// return from Preferences Object.
  128.     /// </summary>
  129.     /// <param name="files"></param>
  130.     private void MultiSelect(object files)
  131.     {
  132.       var args = files as Collection<string>;
  133.       if (args == null
  134.         || args.Count < 2) return;
  135.       var c = args.Count;
  136.       var tab = Convert.ToInt32(args[c-1]);
  137.       args.RemoveAt(c - 1);
  138.       var cnt = args.Count;
  139.       var ary = new string[cnt];
  140.       for (var i = 0; i  < cnt; ++i)
  141.         ary[i] = Convert.ToString(args[i]);
  142.       MultiSelect(tab, ary, true);
  143.     }
  144.  
  145.     /// <summary> First file goes into the
  146.     /// current tab (TabPref already handled
  147.     /// by TabPrompt() call in OpenClick()
  148.     /// && MmfServerSide())
  149.     /// Then the rest go into new tabs we'll need
  150.     /// to create. (All but the first one that is!)
  151.     /// </summary>
  152.     /// <param name="tab"></param>
  153.     /// <param name="fnms"></param>
  154.     /// <param name="mmf"></param>
  155.     private void MultiSelect(
  156.       int tab, string[] fnms, bool mmf = false)
  157.     {
  158.       if (!mmf)
  159.       { ProgressBar1.Value = 49;
  160.         var dir = Path.GetDirectoryName(
  161.           SMS.Default.FileNames[
  162.             TabControl.SelectedIndex]);
  163.         KeyDown -= SmesaKeyDown;
  164.         fnms = FileNameGet(fnms, dir);
  165.         KeyDown += SmesaKeyDown; }
  166.       if (fnms.Length < 2)
  167.       { SingleSelect(tab, fnms, true);
  168.         return; }
  169.       ProgressBar1.Value = 75;
  170.       var was = SMS.Default.FileNames.Count;
  171.       var files = new Collection<string>();
  172.       foreach (var fn in fnms.Where(fn =>
  173.         !SMS.Default.FileNames.Contains(fn)
  174.           && File.Exists(fn))) files.Add(fn);
  175.       // Skip ^ duplicates and nonexistents.
  176.       if (files.Count < 1)
  177.       {
  178.         NeverMind(); // <-= v67mods
  179.         var ct = fnms.Length -1;
  180.         // if all files are already open
  181.         // then go to the last tab listed.
  182.         for (var i = ct; i > -1; --i)
  183.         { // v72mods vv
  184.           if (!SMS.Default.FileNames
  185.             .Contains(fnms[i])) continue;
  186.           TabControl.SelectedIndex =
  187.             SMS.Default.FileNames.IndexOf(fnms[i]);
  188.           break;
  189.         }
  190.         return;
  191.       }
  192.       if (files.Count == 1) // bugg fixx
  193.         SingleSelect(tab, new[]{files[0]}, true);
  194.       else MultiSelect(was, tab, files);
  195.     }
  196.  
  197.     private void NeverMind()
  198.     {
  199.       if (!_newTab) return;
  200.       var last = TabControl.TabPages.Count -1;
  201.       TabControl.SelectedIndex = last;
  202.       TabClose(last);
  203.     }
  204.  
  205.     private void MultiSelect(
  206.       int was, int tab, IList<string> files)
  207.     {
  208.       NotOpenYet(files[0], tab);
  209.       // Get that ^ first one out of the way.
  210.       var c = files.Count - 1;
  211.       for (var i = 0; i < c; ++i)
  212.         NewClick(); // minus ^ that one.
  213.       var x = 0; // index zero above...
  214.       #region NOTE
  215.       // What was the count, now
  216.       // becomes the starting index.
  217.       // NOTE: loop starts at index = 1;
  218.       #endregion NOTE
  219.       for (var i = was; i < was + c; ++i)
  220.         NotOpenYet(files[++x], i);
  221.       for (var i = 0; i < SMS.Default
  222.         .FileNames.Count; ++i)
  223.           Editor(i, true, true);
  224.       MultiSelect(tab);
  225.       SMS.Default.BarValue[tab] =
  226.         Convert.ToString("100");
  227.       SMS.Default.Save();
  228.     }
  229.  
  230.     private void MultiSelect(int tab)
  231.     {
  232.       TabControl.SelectedIndex = tab;
  233.       #region Event ^ Note
  234.       // ^ This li guy Triggers TabChange() event:
  235.       // Then Editing and everything does the rest.
  236.       // Makes sure the Filename is the Tab-text &
  237.       // all that stuff, Colors per extension, etc.
  238.       #endregion
  239.       var rtb = TabControl.TabPages[tab]
  240.         .Controls[_index] as RichTextBox;
  241.       if (rtb == null) throw new
  242.         ArgumentException(
  243.         "MultiSelect(int)");
  244.       rtb.Focus();
  245.       rtb.SelectionStart =
  246.         rtb.SelectionLength = 0;
  247.     }
  248. #endregion MultiSelect Method Group.
  249.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  250.  
  251.  
  252. #region NewTabPage Related Code
  253.  
  254.     // If no Current Tabs in Settings it Defaults
  255.     // to the Primary Tab & Empty RTB of Pref FileType.
  256.  
  257.     // App Comes with 1 tabPage in Design...
  258.     // ...2nd TabPage & up are Added here.
  259.     private void PreCreatePages()
  260.     {
  261.       if (!SMS.Default.MultiTab) return;
  262.       var trash = new Collection<int>();
  263.       for (var i = 1; i < SMS.Default
  264.         .FileNames.Count; ++i)
  265.         if (File.Exists(
  266.           SMS.Default.FileNames[i]))
  267.             NewClick();
  268.         else // Trash non existents.
  269.           trash.Add(i);
  270.       foreach (var i in trash)
  271.         SMS.Default.FileNames.RemoveAt(i);
  272.       SMS.Default.Save();
  273.     }
  274.  
  275.     private void NewClick
  276.       (object sender, EventArgs e)
  277.     {
  278.       if (!SMS.Default.MultiTab
  279.         && !YesNoDialog(
  280.         SMR.NewClickText,
  281.         SMR.NewClickTitle, 1)) return;
  282.       SMS.Default.MultiTab = true;
  283.       NewClick();
  284.       GetCharCount(null, true);
  285.     }
  286.  
  287.     /// <summary> See GetNewRtb Html Below
  288.     /// </summary>
  289.     private void NewClick()
  290.     {
  291.       var tc = TabControl.TabPages.Count;
  292.       var fn = GetDefaultFileName(tc);
  293.       // Create New tabPage Object.
  294.       TabControl.TabPages.Add(fn);// <-===<<
  295.       // Name the new Tab
  296.       TabControl.TabPages[tc].Name =
  297.         string.Format("tabPage{0}", tc + 1);
  298.       // SmeRtb Custom Control Project Instance.
  299.       CreateRtb(tc);
  300.       // Getta good handle on new tabPage's RTB.
  301.       var rt = TabControl.TabPages[tc]
  302.         .Controls[_index] as RichTextBox;
  303.       if (rt == null) throw new
  304.         ArgumentException("NewClick");
  305.       rt.ForeColor = NotText(tc)
  306.         ? SMS.Default.SmeSelFore
  307.         : MyCustomPrintLibrary
  308.           .MyFontClass.MePrintColor;
  309.       rt.Focus();
  310.       Validate();
  311.     }
  312.  
  313.     /// <summary> Works with NewClick
  314.     /// There is already a Design-Time RichTextBox.
  315.     /// Create Custom Control from a Copy of it
  316.     /// to set the defaults we want. Grab a new
  317.     /// instance of it during run-time. Then
  318.     /// give it some of the Run-Time Properties,
  319.     /// Give it a Unique Name and Add it to a New
  320.     /// tabPage which is then added to the
  321.     /// TabControl.TabPage[Collection];
  322.     /// Puts the Focus on it, etc, etc.
  323.     /// v2.2.6.27 07-Jan-2018
  324.     /// </summary>
  325.     /// <param name="tab"></param>
  326.     private void CreateRtb(int tab)
  327.     {
  328.       // See MyCustomControl v Project.
  329.       RichTextBox rtb;
  330.       using (var cc = new CustomControl()) // <-=
  331.       { rtb = cc.R1; }
  332.       // ^ Using Free Garbage Disposal!
  333.       if (rtb == null) throw new
  334.         ArgumentException("CreateRtb1");
  335.       SyncRtb(tab, rtb);
  336.       var test = TabControl
  337.         .TabPages[tab].Controls[_index];
  338.       if (test == null) throw new
  339.         ArgumentException("CreateRtb2");
  340.       // And Select this new Tab.
  341.       Zoomed = true;
  342.       TabControl.SelectedIndex = tab;
  343.       #region Event ^ Note
  344.       // ^ This li guy Triggers TabChange() event:
  345.       // Then Editing and everything does the rest.
  346.       // Makes sure the Filename is the Tab-text &
  347.       // all that stuff, Colors per extension, etc.
  348.       #endregion
  349.       Zoomed = false;
  350.       Check5();
  351.       // Bring ALL Collections up or down.
  352.     }
  353.  
  354.     private void SyncRtb(
  355.       int tc, RichTextBox rtb)
  356.     { // Name the new Custom Control.
  357.       rtb.Name = string.Format(
  358.         "RichTextBox{0}", tc + 1);
  359.       // Sync Certain Properties:
  360.       var r1 = RichTextBox1;
  361.       rtb.ZoomFactor = 1;
  362.       rtb.Size = r1.Size;
  363.       rtb.ContentsResized += Zoomer;
  364.       rtb.ContextMenuStrip = ContextMenu1;
  365.       rtb.WordWrap = r1.WordWrap;
  366.       TabControl.TabPages[tc]
  367.         .Controls.Add(rtb);
  368.     }
  369. #endregion NewTabPage Related Code
  370.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  371.  
  372.  
  373. #region MultiTab Related Code
  374.  
  375.     // v3.1.1.39 08-Mar-2018
  376.     private void TabPrompt()
  377.     {
  378.       _tab = TabPrompt(
  379.         TabControl.SelectedIndex);
  380.     }
  381.  
  382.     /// <summary> Legend:
  383.     /// Choice = 1 ; New Tab
  384.     /// Choice = 2 ; Current Tab
  385.     /// Choice = 3 ; Cancel
  386.     /// Choice = 4 ; New Tab Pref
  387.     /// Choice = 5 ; Current Pref
  388.     /// </summary>
  389.     /// <param name="tab"></param>
  390.     /// <returns></returns>
  391.     private int TabPrompt(int tab)
  392.     {
  393.       var choice = -1;
  394.       if (SMS.Default.TabPrefSet)
  395.       {
  396.         if (!SMS.Default.TabPref)
  397.           return tab; // item 5
  398.         choice = 4;
  399.       }
  400.       KeyDown -= SmesaKeyDown;// very cool! <-=
  401.       if ( choice != 4) choice =
  402.         MCD.NewTabPrompt(); // <-= Awesome!
  403.       KeyDown += SmesaKeyDown;
  404.       if (choice == 3) return -1;
  405.       if (choice == 5 || choice == 2)
  406.       {
  407.         if (choice == 5)
  408.         {
  409.           SMS.Default.TabPrefSet = true;
  410.           SMS.Default.TabPref = false;
  411.         }
  412.         return tab;
  413.       }
  414.       // Only choice 1 & 4 remain.
  415.       if (choice == 4)
  416.       {
  417.         SMS.Default.TabPref = true;
  418.         SMS.Default.TabPrefSet = true;
  419.       }
  420.       tab = TabControl.TabPages.Count;
  421.       NewClick();
  422.       _newTab = true;
  423.       return
  424.         TabControl.SelectedIndex = tab;
  425.       #region Event ^ Note
  426.       // ^ This li guy Triggers TabChange() EVENT:
  427.       // Then Editing and everything does the rest.
  428.       // Makes sure the Filename is the Tab-text &
  429.       // all that stuff, Colors per extension, etc.
  430.       #endregion
  431.     }
  432.  
  433.     private bool _newTab;
  434.  
  435.     private void CheckTabs(int tab)
  436.     {
  437.       var tpgs = TabControl.TabPages.Count;
  438.       while (tpgs <= tab)
  439.       {
  440.         NewClick();
  441.         tpgs = TabControl.TabPages.Count;
  442.       }
  443.     }
  444. #endregion Multi Tab Pages Related Code
  445.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  446.  
  447.  
  448. #region Changed Tabs Related Code
  449.  
  450.     /// <summary> Wraps top to bottom or
  451.     /// bottom to top of list if needed.
  452.     /// </summary>
  453.     /// <param name="tab"></param>
  454.     /// <returns></returns>
  455.     private int CheckForWrap(int tab)
  456.     {
  457.       var c = TabControl.TabPages.Count;
  458.       #region TestCode
  459.       //if (tab < 0 || tab >= c
  460.       //  && SMS.Default.Testing)
  461.       //    MessageBox.Show(string.Format(
  462.       //      "Caught one!\n\nTab == {0}", tab));
  463.       #endregion TestCode
  464.       if (tab < 0)  tab = c - 1;
  465.       if (tab >= c) tab = 0;
  466.       return tab;
  467.     }
  468.  
  469.     /// <summary> This event is before the Tab Change,
  470.     /// and ChangedTabs(); is after this event here.
  471.     /// Stores relevant data in case of return to
  472.     /// this Tab from afar.
  473.     /// </summary>
  474.     /// <param name="sender"></param>
  475.     /// <param name="e"></param>
  476.     private void PageDeselecting(
  477.       object sender,
  478.       TabControlCancelEventArgs e)
  479.     {
  480.       var tab = CheckForWrap(
  481.         TabControl.SelectedIndex);
  482.       var cnt = SMS.Default.BarValue.Count;
  483.       var str = Convert.ToString(
  484.         ProgressBar1.Value);
  485.       if (tab < cnt)
  486.         SMS.Default.BarValue[tab] = str;
  487.       else SMS.Default.BarValue.Add(str);
  488.       str = StatusLabel.Text;
  489.       var c = SMS.Default.Status.Count;
  490.       if (tab < c)
  491.         SMS.Default.Status[tab] = str;
  492.       else
  493.         SMS.Default.Status.Add(str);
  494.       SMS.Default.Save();
  495.     }
  496.     // NOTE: Before Above, After Below. (extreme interaction)
  497.  
  498.     /// <summary> This is called AFTER the above
  499.     /// whenever the User Clicks a different Tab.
  500.     /// Then this Method brings back relevant
  501.     /// data from Previous views of this
  502.     /// tabPage, saved via the above.
  503.     /// </summary>
  504.     /// <param name="sender"></param>
  505.     /// <param name="e"></param>
  506.     private void ChangedTabs
  507.       (object sender, EventArgs e)
  508.     {
  509.       var t = TabControl.SelectedIndex;
  510.       var r = TabControl.TabPages[t]
  511.         .Controls[_index] as RichTextBox;
  512.       if (r != null) r.Focus();
  513.       Editing(t < SMS.Default.FileNames.Count, false);
  514.       ProgressBar1.Value = GetValue(t);
  515.       SaveButtonHandler(t); // So Sweet!
  516.       Zoomer();
  517.       Validate();
  518.     }
  519.  
  520.     private void
  521.       SaveButtonHandler(int t)
  522.     {
  523.       var unsaved = CheckForSave();
  524.       if (unsaved.Count < 1)
  525.       {
  526.         SaveButton.Enabled =
  527.           SaveAllButton.Enabled = false;
  528.         SavedStatus(t);
  529.         return;
  530.       }
  531.       SaveAllButton.Enabled = true;
  532.       SaveButton.Enabled =
  533.         unsaved.Contains(t);
  534.       if (SaveButton.Enabled)
  535.         UnSavedStatus(t);
  536.     }
  537.  
  538.     private void SavedStatus(int tab)
  539.     {
  540.       var file = MCT.GetFile(
  541.         tab, SMS.Default.FileNames,
  542.           GetDefaultFileName(tab));
  543.       var status = string.Format(
  544.         "Editing File: {0}", file);
  545.       if (tab < SMS.Default.Status.Count)
  546.         SMS.Default.Status[tab] = status;
  547.       else
  548.         SMS.Default.Status.Add(status);
  549.       StatusLabel.Text =
  550.         StatusLabel.ToolTipText = status;
  551.     }
  552.  
  553.     private void UnSavedStatus(int tab)
  554.     {
  555.       const string s = " : ";
  556.       var status = SMR.Status_Unsaved +
  557.         s + MCT.GetFile(
  558.           tab, SMS.Default.FileNames,
  559.           GetDefaultFileName(tab));
  560.       if (tab < SMS.Default.Status.Count)
  561.         SMS.Default.Status[tab] = status;
  562.       else
  563.         SMS.Default.Status.Add(status);
  564.       StatusLabel.Text =
  565.         StatusLabel.ToolTipText = status;
  566.       Asterisk(tab);
  567.     }
  568.  
  569.     // Add ^ asterisk to unsaved tab text.
  570.     private void Asterisk(int tab)
  571.     {
  572.       var fn = Path.GetFileName(
  573.         SMS.Default.FileNames[tab]);
  574.       var tp = TabControl.TabPages[tab];
  575.       if (tp == null || TabControl
  576.         .TabPages.Count < 1) throw new
  577.           ArgumentException("Asterisk");
  578.       const string ast = "*";
  579.       tp.Text = fn + ast;
  580.     }
  581.  
  582.     /// <summary> These are the ints
  583.     /// you're looking for. Keep Moving.
  584.     /// </summary>
  585.     /// <param name="tab"></param>
  586.     /// <returns></returns>
  587.     private int GetValue(int tab)
  588.     {
  589.       var value = 100;
  590.       if (tab >= SMS.Default.BarValue.Count)
  591.         SMS.Default.BarValue.Add("100");
  592.       try
  593.       {
  594.         value = Convert.ToInt32(
  595.           SMS.Default.BarValue[tab]);
  596.       }
  597.       catch (ArgumentOutOfRangeException ex)
  598.       {
  599.         ChangedTabsCatcher(tab,
  600.           Convert.ToString(ex));
  601.       }
  602.       catch (FormatException ex)
  603.       {
  604.         ChangedTabsCatcher(tab,
  605.           Convert.ToString(ex));
  606.       }
  607.       catch (OverflowException ex)
  608.       {
  609.         ChangedTabsCatcher(tab,
  610.           Convert.ToString(ex));
  611.       }
  612.       SMS.Default.Save();
  613.       return value;
  614.     }
  615.  
  616.     private void ChangedTabsCatcher(
  617.       int t, string ex)
  618.     {
  619.       ProgressBar1.Value = 100;
  620.       var c = SMS.Default.BarValue.Count;
  621.       const string x = "100";
  622.       if (t < c)
  623.         SMS.Default.BarValue[t] = x;
  624.       else SMS.Default.BarValue.Add(x);
  625.       SMS.Default.Save();
  626.       if (!MCT.Testing) return;
  627.       var tx = string.Format(
  628.         "Managed Exception in " +
  629.         "Changed Tabs:\n\n{0}", ex);
  630.       MessageBox.Show(tx);
  631.     }
  632. #endregion Changed Tabs Related Code
  633.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  634.  
  635.  
  636. #region Shade or Unshade Both Save Buttons.
  637.  
  638.     /// <summary> Shade the Smesa SaveButton
  639.     /// Icon in ToolBar and Check to
  640.     /// see if Everything else is saved
  641.     /// and if so Shade SaveAllButton too.
  642.     /// </summary>
  643.     private void ShadyMethod()
  644.     {
  645.       SavedStatus(
  646.         TabControl.SelectedIndex);
  647.       SaveButton.Enabled = false;
  648.       if (CheckForSave().Count > 1)
  649.         return;
  650.       // If anything else needs Saved.
  651.       SaveAllButton.Enabled = false;
  652.     }
  653.  
  654.     /// <summary> UnShade Both SaveButton
  655.     /// & SaveAllButton Icons in the ToolBar.
  656.     /// UnShade SaveAll anytime even 1 is unsaved.
  657.     /// </summary>
  658.     private void UnshadyMethod()
  659.     {
  660.       UnSavedStatus(
  661.         TabControl.SelectedIndex);
  662.       SaveAllButton.Enabled =
  663.         SaveButton.Enabled = true;
  664.     }
  665. #endregion Shade or Unshade
  666.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  667.  
  668.  
  669. #region RestoreEditors Related Code
  670.  
  671.     /// <summary> Open any Tabs and Files
  672.     /// from the Last Run for this
  673.     /// particular User in AppData.
  674.     /// v4.5.9.63 11-Aug-2018 -JpE-
  675.     /// </summary>
  676.     private void SetupOpenFiles()
  677.     {
  678.       var dir = Path.
  679.         GetDirectoryName(Mapped);
  680.       dir = Path.GetDirectoryName(dir);
  681.       dir = Path.GetDirectoryName(dir);
  682.       dir += SMR.Res;
  683.       #region testcode
  684.       //MessageBox.Show(// testscode
  685.       //  string.Format(
  686.       //    "dir == {0}",dir));
  687.       #endregion
  688.       string
  689.         l = dir + SMR.Lic,
  690.         a = dir + SMR.Abt,
  691.         b = MCT.GetDocFolder,
  692.         o = b + "\\" + Path.GetFileName(l),
  693.         r = b + "\\" + Path.GetFileName(a);
  694.       if ( !File.Exists(l) || !File.Exists(a))
  695.       { if (MCT.Testing)
  696.         { MessageBox.Show(SMR.Err3);
  697.           throw new
  698.             ArgumentException("ME Err3"); }
  699.         return; }
  700.       File.Copy(l, o, true);
  701.       Thread.Sleep(37);
  702.       File.Copy(a, r, true);
  703.       var f = SMS.Default.FileNames[0];
  704.       var u = SMS.Default.FileNames.Count;
  705.       var n = true;
  706.       if (string.IsNullOrEmpty(f) || u < 3){
  707.         if (u == 0 || u <= 2
  708.           && f.Contains(GetDefaultFileName(0))
  709.           || f.Contains(o) || f.Contains(r)){
  710.           n = false; // Welcome to MyEditor!
  711.           SMS.Default.FileNames.Clear();
  712.           SMS.Default.FileNames.Add(r);
  713.           SMS.Default.FileNames.Add(o);
  714.           Editing(); } }
  715.       u = SMS.Default.FileNames.Count;
  716.       if (!SMS.Default.MultiTab)
  717.         while (u > 1) SMS.Default
  718.           .FileNames.RemoveAt(--u);
  719.       SMS.Default.Save();
  720.       Check5();
  721.       SetupAllTabs(n); // v to simplify v
  722.     }
  723.  
  724.     /// <summary> Create and Load Open Tabs
  725.     /// from the Last Run by This User.
  726.     /// Restore Previous Properties for
  727.     /// each Editor-Window / Rtb.
  728.     /// Final Rev2.2.6.27agate 07-Jan-2018
  729.     /// v4.5.9.63 11-Aug-2018 -JpE-
  730.     /// </summary>
  731.     private void SetupAllTabs(bool normal)
  732.     {
  733.       TabControl.SelectedIndex = 0;
  734.       #region Event ^ Note
  735.       // ^ This li guy Triggers TabChange() event:
  736.       // Then Editing and everything does the rest.
  737.       // Makes sure the Filename is the Tab-text &
  738.       // all that stuff, Colors per extension, etc.
  739.       #endregion
  740.       var r = RichTextBox1;
  741.       RichTextBox1.Focus();
  742.       if (!NotText(0)) SetupRtb4Txt(r);
  743.       else SetupRtb4Rtf(r);
  744.  
  745.       // Rev2 creates tabPages 1st.
  746.       var c = SMS.Default.FileNames.Count;
  747.       if (c > 1) PreCreatePages();
  748.       if (c > 0) // <-= This may help! LoL
  749.         for (var i = 0; i < c; ++i)
  750.           LoadRtb(SMS.Default.FileNames[i], i);
  751.  
  752.       ProgressBar1.Value = 87;
  753.       for (var i = 0; i < c; ++i)
  754.         ZeroSaveMeItem(i);
  755.  
  756.       if (normal) RestoreEditors();
  757.       // else Welcome Files, About & License.
  758.       // v4.6.9.68 10-Sep-2018
  759.       Editing(); // <-= Critical!
  760.     }
  761.  
  762.     /// <summary> Restore Entire App Editors
  763.     /// and Line Numbers & cursor position,
  764.     /// etc back to state of previous run
  765.     /// for that user.
  766.     /// (called on form loading)
  767.     /// </summary>
  768.     private void RestoreEditors()
  769.     {
  770.       for (var i = 0; i <
  771.         SMS.Default.FileNames.Count; ++i)
  772.       {
  773.         var tb = TabControl.TabPages[i];
  774.         if (tb == null) throw new
  775.           ArgumentException("RestoreEditorTabs");
  776.         tb.Text = Path.GetFileName(
  777.           SMS.Default.FileNames[i]);
  778.         var rtb = tb.Controls[_index]
  779.           as RichTextBox;
  780.         if (rtb == null) throw new
  781.           ArgumentException("RestoreEditors");
  782.         rtb.ZoomFactor = Convert.ToSingle(
  783.           SMS.Default.Zoo[i]);
  784.         var sel = MCT.PositionCursor(
  785.           i, SMS.Default.Curses);
  786.         var nums = sel.Split(',');
  787.         int start, lngth;
  788.         try { start = Convert.ToInt32(nums[0]);
  789.           lngth = Convert.ToInt32(nums[1]); }
  790.         catch (FormatException) { start = 0;
  791.           lngth = 0; }
  792.         catch (OverflowException) { start = 0;
  793.           lngth = 0; }
  794.         rtb.SelectionStart = start;
  795.         rtb.SelectionLength = lngth;
  796.       }
  797.     }
  798. #endregion RestoreEditors Related Code
  799.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  800.  
  801.  
  802.   }
  803. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement