Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // ShowMeEdit.cs v5.7.7.86 by -JpE-
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // Modeled after ShowMeForm But Editable
- // Ready to testwell and evolve, etc.
- // v5.7.7.88 21-Aug-2017 Early Beta
- // Still Designing as I Develop this.
- // v5.7.7.89 Opts Out of Dual Use mods.
- // Leave commented out code for that in
- // v5.7.7.91 MUMs the Word. 22-Aug-2017
- // v5.7.8.05 28-Aug-2017 Context Menu
- // v5.7.8.07 30-Aug--17 Fixed & trimmed.
- // v5.7.8.17 08-Sep-2017 Prep for Rev.
- // v5.7.8.21 19-Sep-2017 File-Menu stuff
- //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
- // Dependencies
- using System;
- using System.Globalization;
- using System.IO;
- using System.Windows.Forms;
- // Class Aliases
- using AP = WhoAreYou.AppStatic;
- // Properties Aliases
- using PS = WhoAreYou.Properties.PersonSettings;
- using PR = WhoAreYou.Properties.PersonResources;
- using OS = WhoAreYou.Properties.OptionsSettings;
- using AU = WhoAreYou.Properties.AppUserSettings;
- namespace WhoAreYou
- {
- public sealed partial class ShowMeEdit : Form
- {
- // Class Global Properties
- private bool Ok { get; set; }
- private string TextWas { get; set; }
- private readonly string _original;
- private string Edited { get; set; }
- public string // ^v Cool Trick, NOTE!
- EditedText { get{ return Edited; } }
- private string ClipBoard { get; set; }
- // Class Global ^ for the Edit/Context Menu Items.
- #region ShowMeEdit Form Related Code v5.7.8.03 28-Aug-2017
- public ShowMeEdit(string text, string title) //, bool read) // MUMs
- {
- InitializeComponent();
- //ShowMeRichTextBox.ReadOnly = read; // <-= ^v Multiple Use Mods.
- _original = TextWas = ShowMeRichTextBox.Text = Edited = text;
- // NOTE: quadruple assignment ^ at Start.
- Text += title; // Edit This ^ text file.
- // // KEEP THIS! v^ MUMs the word.
- //SaveButton.Visible = OkButton.Visible = // MUMs ^
- // MenuStrip.Visible = !read;
- //if (read) CanceButton.Text = PR.SME_EditClose;
- }
- private void OkButtonClick(object sender, EventArgs e)
- {
- if (Edited != ShowMeRichTextBox.Text)
- {
- if (AP.YesNoDialog(
- "Unsaved Changes were made.\n\n" +
- "Would you like to Save These Changes?",
- "Save Changes?"))
- {
- Edited = ShowMeRichTextBox.Text;
- Ok = true;
- }
- }
- Close();
- }
- private void SaveButtonClick(object sender, EventArgs e)
- {
- if (Edited == ShowMeRichTextBox.Text) return;
- Ok = true;
- Edited = TextWas = ShowMeRichTextBox.Text;
- if (OS.Default.MiniVerb) return;
- MessageBox.Show(PR.SME_ChangesSaved);
- }
- private void EditFormClosing(
- object sender, FormClosingEventArgs e)
- {
- if (!Ok) Edited = TextWas;
- else
- if (ShowMeRichTextBox.Text != Edited)
- OkButtonClick("Form Closing", EventArgs.Empty);
- PS.Default.Save();
- }
- #endregion ShowMeEdit Form Related Code v5.7.8.03 28-Aug-2017
- //\\//\\//\\////\\//\\//\\////\\//\\//\\////\\//\\//\\//
- #region File Menu
- private void SaveChangesClick(object sender, EventArgs e)
- {
- Ok = true;
- Edited = TextWas = ShowMeRichTextBox.Text;
- }
- // Start over with Previous Text
- // if that equals the _original txt then no Ok.
- private void RevertClick(object sender, EventArgs e)
- {
- if (!OS.Default.MiniVerb)
- if (!AP.YesNoDialog(
- "Revert back to previous save?")) return;
- ShowMeRichTextBox.Text = TextWas;
- if (TextWas.Equals(_original)) Ok = false;
- }
- private void ClearAllClick(object sender, EventArgs e)
- {
- const string
- txt = "Wipe this entire document:\n\n" +
- "Are You Sure?";
- if (!OS.Default.MiniVerb)
- if (!AP.YesNoDialog(
- txt, "Clear All Text?")) return;
- TextWas = ShowMeRichTextBox.Text;
- ShowMeRichTextBox.Text = "";
- }
- // todo Largely Completed Above Here. /\/\/\/\/\/\/\/\/\
- private void ImportClick(object sender, EventArgs e)
- {
- // todo testwell
- var fn = GetDefaultFileName();
- if (!string.IsNullOrEmpty(PS.Default.SME_Imported))
- fn = PS.Default.SME_Imported;
- else PS.Default.SME_Imported = fn; // <-= TestWell this branch.
- const string tt = "Importing this text file:";
- using (var d = new OpenFileDialog())
- {
- d.Title = tt;
- d.FileName = Path.GetFileName(fn);
- d.InitialDirectory = Path.GetDirectoryName(fn);
- d.DefaultExt = PS.Default.TxtExt;
- if (!d.ShowDialog().Equals(DialogResult.OK)
- || string.IsNullOrEmpty(d.FileName)) return;
- PS.Default.SME_Imported = d.FileName;
- }
- TextWas = ShowMeRichTextBox.Text =
- File.ReadAllText(PS.Default.SME_Imported);
- PS.Default.Save();
- //Validate(); // todo remnant?
- }
- /// <summary> Saves Duplicating this Code Twice Here.
- /// <returns></returns>
- private static string GetDefaultFileName()
- {
- var fn = AU.Default.RootDir +
- "\\" + AU.Default.FileName;
- var rc = (InfoForm.CurrentRecord + 1)
- .ToString(CultureInfo.InvariantCulture);
- fn = fn.Substring(0, fn.Length - 4) +
- "_Rec" + rc + "_Note.txt";
- return fn;
- }
- private void ExportClick(object sender, EventArgs e)
- {
- var fn = GetDefaultFileName();
- if (!string.IsNullOrEmpty(PS.Default.SME_Exported))
- fn = PS.Default.SME_Exported; // test this branch now!
- else PS.Default.SME_Exported = fn; // this branch tests well...
- while (File.Exists(fn))
- fn = AP.ItsACopy(fn); // todo test this too
- // but it's 100% tested code reused here as far
- // as the AppStatic Class (AP) is concerned..
- const string tt = "Exporting this to text file:";
- using (var s = new SaveFileDialog())
- {
- s.Title = tt;
- s.FileName = Path.GetFileName(fn);
- s.InitialDirectory = Path.GetDirectoryName(fn);
- if (!s.ShowDialog().Equals(DialogResult.OK)
- || string.IsNullOrEmpty(s.FileName)) return;
- PS.Default.SME_Exported = s.FileName;
- }
- // Now simply Write the string to that path.
- File.WriteAllText(PS.Default.SME_Exported,
- ShowMeRichTextBox.Text);
- PS.Default.Save();
- }
- #endregion File Menu
- //\\//\\//\\////\\//\\//\\////\\//\\//\\////\\//\\//\\//
- #region EditMenu, ClipBoard && ContextMenu Items covered here.
- /* Brought in from InfoFormMenuAndEdit.cs:
- * v5.7.8.03 28-Aug-2017
- * Allows all the functionality of an editor.
- * Sorta, working on it anyway. Not to bad of a start.
- */
- private void
- UndoClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- ClipBoard = tx.SelectedText;
- tx.Undo();
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- ClipBoard = rtx.SelectedText;
- rtx.Undo();
- }
- private void
- RedoClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- tx.SelectedText = ClipBoard;
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- rtx.SelectedText = ClipBoard;
- rtx.Redo();
- }
- private void
- CutClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- ClipBoard = tx.SelectedText;
- tx.Cut();
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- ClipBoard = rtx.SelectedText;
- rtx.Cut();
- }
- private void CopyClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- ClipBoard = tx.SelectedText;
- tx.Copy();
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- ClipBoard = rtx.SelectedText;
- rtx.Copy();
- }
- private void PasteClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- ClipBoard = tx.SelectedText;
- tx.Paste();
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- ClipBoard = rtx.SelectedText;
- //rtx.Paste();
- }
- private void SelectAllClick(object sender, EventArgs e)
- {
- if (ActiveControl == null) return;
- var tx = ActiveControl as RichTextBox;
- if (tx != null)
- {
- tx.SelectAll();
- }
- var rtx = ActiveControl as RichTextBox;
- if (rtx == null) return;
- rtx.SelectAll();
- }
- #endregion Edit Menu
- //\\//\\//\\////\\//\\//\\////\\//\\//\\////\\//\\//\\//
- #region Options Menu
- private void ChangeFontClick(object sender, EventArgs e)
- {
- var f = PS.Default.SME_Font;
- Zone();
- // todo
- }
- private void BackColorClick(object sender, EventArgs e)
- {
- var bc = PS.Default.SME_BackColor;
- using (var c = new ColorDialog())
- {
- c.ShowDialog();
- }
- Zone();
- // todo
- }
- private void ForeColorClick(object sender, EventArgs e)
- {
- var fc = PS.Default.SME_ForeColor;
- using (var c = new ColorDialog())
- {
- c.ShowDialog();
- }
- Zone();
- // todo
- }
- // todo testcode
- private static void Zone()
- {
- const string t =
- "Under Construction, Please Return.";
- MessageBox.Show(t);
- }
- private void WordWrapClick(object sender, EventArgs e)
- {
- WordWrapMenuItem.Checked =
- ShowMeRichTextBox.WordWrap =
- !ShowMeRichTextBox.WordWrap;
- }
- #endregion Options Menu
- //\\//\\//\\////\\//\\//\\////\\//\\//\\////\\//\\//\\//
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement