private void FilesTabControl_SelectedIndexChanged(object sender, EventArgs e) { UpdateText(); if (filesTabControl.SelectedIndex >= 0) { curFile = files[filesTabControl.SelectedIndex]; curFile.ShowText(textEditorRichTextBox); } UpdateFont(currentFont); }
public BackUp(DoAtMainFormFile[] todo, MyFile myFile) { InitializeComponent(); doBeforeClosure = todo; curFile = myFile; foreach (var elem in myFile.timings) { versionsComboBox.Items.Add(elem); } versionsComboBox.SelectedIndex = myFile.timings.Count - 1; }
private void OpenFileMenuItem_Click(object sender, EventArgs e) { // Set limit for opened files. if (files.Count == 10) { MessageBox.Show("You can open no more than 10 files"); return; } OpenFileDialog open = new OpenFileDialog { Title = "Open File", Filter = "(*.txt)|*.txt|(*.rtf)|*.rtf|(*.cs)|*.cs|All files (*.txt;*.rtf;*.cs*)|*.txt;*.rtf;*.cs;", FilterIndex = 4 }; if (open.ShowDialog() == DialogResult.OK) { try { UpdateText(); MyFile file = new MyFile(open.FileName); files.Add(file); curFile = file; // Check for correct text assignment. if (curFile.wasRtf) { textEditorRichTextBox.Rtf = curFile.FileText; } else { textEditorRichTextBox.Text = curFile.FileText; } textEditorRichTextBox.Visible = true; AddTab(Path.GetFileName(curFile.FilePath)); filesTabControl.SelectedTab = curFile.Page; } catch (Exception exc) { MessageBox.Show(exc.Message); } } }
/// <summary> /// Trying to get saved settings from ApplicationData.txt. /// </summary> private void PreLoadData() { var data = new ApplicationData(); try { settingsList = data.settingsParams; files = data.SetTabControl(filesTabControl); if (files.Count > 0) { curFile = files[filesTabControl.SelectedIndex]; curFile.ShowTextFirstTime(textEditorRichTextBox); } } catch { data.SetDefault(); settingsList = data.settingsParams; files = new MyFileList(); filesTabControl.TabPages.Clear(); } }
/// <summary> /// Close opened tab. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CloseCurrentTabMenuItem_Click(object sender, EventArgs e) { try { // If tab was unsaved. if (curFile.Changed || curFile.FilePath == null) { switch (MessageBox.Show($"Do you want to save changes to {filesTabControl.SelectedTab.Text}?", "Text Editor", MessageBoxButtons.YesNoCancel)) { case DialogResult.Yes: curFile.Save(); break; case DialogResult.Cancel: return; } } int id = filesTabControl.SelectedIndex; filesTabControl.TabPages.Remove(curFile.Page); curFile = files.Remove(id); if (curFile != null) { filesTabControl.SelectedTab = curFile.Page; textEditorRichTextBox.Rtf = curFile.FileText; filesTabControl.SelectedIndex = Math.Max(id - 1, 0); } else { textEditorRichTextBox.Visible = false; filesTabControl.Visible = false; fontStylePanel.Visible = false; } } catch { } }
/// <summary> /// Create new file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NewFileMenuItem_Click(object sender, EventArgs e) { // Set limit for opened files. if (files.Count == 10) { MessageBox.Show("You can open no more than 10 files"); return; } try { UpdateText(); MyFile file = new MyFile(); files.Add(file); curFile = file; curFile.ShowText(textEditorRichTextBox); textEditorRichTextBox.Visible = true; AddTab($"New document {id++}"); filesTabControl.SelectedTab = curFile.Page; } catch { MessageBox.Show("Error"); } }
/// <summary> /// Synchronize textbox and curFile. /// </summary> /// <param name="file"> Fake parameter to set multidelegate. </param> private void UpdateCurFile(MyFile file) { curFile.ShowText(textEditorRichTextBox); UpdateTab(); }
public void Add(MyFile e) { list.Add(e); }
public MyFileList(MyFile e) { Add(e); }