private void mArquivo_SalvarComo_Click(object sender, EventArgs e) { // Zerar as Configurações pesqBar_btnFechar_Click(sender, e); substituirBar_btnFechar_Click(sender, e); txtConteudo_SelectionChanged(sender, e); SaveFileDialog dialog = new SaveFileDialog(); dialog.Title = "Salvar Como..."; dialog.Filter = "rich text file|*.rtf|texto|*.txt|próprio|*.npgap|todos|*.*"; dialog.CheckPathExists = true; dialog.CheckFileExists = false; DialogResult result = dialog.ShowDialog(); if (result != DialogResult.Cancel && result != DialogResult.Abort) { SalvarArquivo(dialog.FileName); if (File.Exists(dialog.FileName)) { FileInfo f = new FileInfo(dialog.FileName); Gerenciador.FileName = (f.Name.Contains('.')) ? f.Name.Substring(0, f.Name.LastIndexOf('.')) : f.Name; Gerenciador.FileExt = f.Extension; Gerenciador.FolderPath = f.DirectoryName + "\\"; StreamReader stream = new StreamReader(f.FullName, true); Encoding encoding = stream.CurrentEncoding; statusBar_LabelEncoding.Text = encoding.EncodingName; statusBar_LabelLinhaColuna.Text = txtConteudo.SelectionStart.ToString(); stream.Close(); Gerenciador.AddRecente(f.FullName); AtualizarHistoricoRecentes(); Text = Application.ProductName + " - " + Gerenciador.FileName + Gerenciador.FileExt; Gerenciador.FileSaved = true; } else { MessageBox.Show("O arquivo não existe ou foi deletado.", "Erro ao tentar abrir", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void mArquivo_Abrir_Click(object sender, EventArgs e) { // Zerar as Configurações pesqBar_btnFechar_Click(sender, e); substituirBar_btnFechar_Click(sender, e); txtConteudo_SelectionChanged(sender, e); if (!Gerenciador.FileSaved) { DialogResult result1 = MessageBox.Show($"Deseja salvar as alterações em \"{Gerenciador.FileName}{Gerenciador.FileExt}\" antes de sair?", "Salvar...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result1 == DialogResult.Cancel || result1 == DialogResult.Abort) { return; } else if (result1 == DialogResult.Yes) { mArquivo_Salvar_Click(sender, e); } } OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "Abrir..."; dialog.Filter = "rich text format| *.rtf|texto|*.txt|próprio|*.npgap|todos|*.*"; DialogResult result = dialog.ShowDialog(); if (result != DialogResult.Cancel && result != DialogResult.Abort) { if (File.Exists(dialog.FileName)) { FileInfo f = new FileInfo(dialog.FileName); Gerenciador.FileName = (f.Name.Contains('.')) ? f.Name.Substring(0, f.Name.LastIndexOf('.')) : f.Name; Gerenciador.FileExt = f.Extension; Gerenciador.FolderPath = f.DirectoryName + "\\"; StreamReader stream = new StreamReader(f.FullName, true); Encoding encoding = stream.CurrentEncoding; try { switch (Gerenciador.FileExt) { default: txtConteudo.Text = stream.ReadToEnd(); break; case ".txt": txtConteudo.Text = stream.ReadToEnd(); break; case ".rtf": txtConteudo.Text = stream.ReadToEnd(); break; } statusBar_LabelEncoding.Text = encoding.EncodingName; statusBar_LabelLinhaColuna.Text = txtConteudo.SelectionStart.ToString(); } catch (Exception ex) { MessageBox.Show("Formato de arquivo não suportado.\n" + ex.Message); } stream.Close(); Gerenciador.AddRecente(f.FullName); AtualizarHistoricoRecentes(); Text = Application.ProductName + " - " + Gerenciador.FileName + Gerenciador.FileExt; Gerenciador.FileSaved = true; } else { MessageBox.Show("O arquivo não existe ou foi deletado.", "Erro ao tentar abrir", MessageBoxButtons.OK, MessageBoxIcon.Warning); Gerenciador.DelRecente(dialog.FileName); AtualizarHistoricoRecentes(); } } }
private void AtualizarHistoricoRecentes() { if (Gerenciador.GetRecentes().Count < 1) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Enabled = false; item.Size = new Size(180, 22); item.Text = "(Vázio)"; mArquivo_Recentes.DropDownItems.Add(item); } else { mArquivo_Recentes.DropDownItems.Clear(); foreach (string file in Gerenciador.GetRecentes()) { ToolStripMenuItem item = new ToolStripMenuItem(); item.AutoSize = true; item.Enabled = true; item.Size = new Size(180, 22); item.Text = file; item.Click += new EventHandler((object sender, EventArgs e) => { // Zerar as Configurações pesqBar_btnFechar_Click(sender, e); substituirBar_btnFechar_Click(sender, e); txtConteudo_SelectionChanged(sender, e); if (!Gerenciador.FileSaved) { DialogResult result = MessageBox.Show($"Deseja salvar as alterações em \"{Gerenciador.FileName}{Gerenciador.FileExt}\" antes de sair?", "Salvar...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel || result == DialogResult.Abort) { return; } else if (result == DialogResult.Yes) { mArquivo_Salvar_Click(sender, e); } } if (File.Exists(file)) { FileInfo f = new FileInfo(file); Gerenciador.FileName = (f.Name.Contains('.')) ? f.Name.Substring(0, f.Name.LastIndexOf('.')) : f.Name; Gerenciador.FileExt = f.Extension; Gerenciador.FolderPath = f.DirectoryName + "\\"; StreamReader stream = new StreamReader(f.FullName, true); Encoding encoding = stream.CurrentEncoding; try { switch (Gerenciador.FileExt) { default: break; case ".txt": txtConteudo.Text = stream.ReadToEnd(); break; case ".rtf": txtConteudo.Rtf = stream.ReadToEnd(); break; } statusBar_LabelEncoding.Text = encoding.EncodingName; statusBar_LabelLinhaColuna.Text = txtConteudo.SelectionStart.ToString(); } catch (Exception ex) { MessageBox.Show("Formato de arquivo não suportado."); } stream.Close(); Gerenciador.AddRecente(f.FullName); AtualizarHistoricoRecentes(); Text = Application.ProductName + " - " + Gerenciador.FileName + Gerenciador.FileExt; Gerenciador.FileSaved = true; } else { MessageBox.Show("O arquivo não existe ou foi deletado.", "Erro ao tentar abrir", MessageBoxButtons.OK, MessageBoxIcon.Warning); Gerenciador.DelRecente(file); AtualizarHistoricoRecentes(); } }); mArquivo_Recentes.DropDownItems.Add(item); } Gerenciador.AtualizarArquivoRecentes(); } }
public FormMain() { InitializeComponent(); Gerenciador.VerificarRecentsFile(); }