void SaveTabToDisk(EditorTabPage etb) { string fileName = etb.GetFileFullPathAndName(); // tooltip is exact name of file, and Text property of tab may contain "*" if file is modified and unsaved FileInfo fi = new FileInfo(fileName); if (fi.Name.StartsWith("Untitled")) { // propose to reneame file var newPageName = GetNewNameInSaveAsDialogFromProposedName(fi.FullName); if (string.IsNullOrWhiteSpace(newPageName)) { return; // user stopped save operation } //var etb = DoRealSaveAs(newPageName); there is no need for new tab in simple save operation fileName = newPageName; } else { // create deirectory if necessary if (Directory.Exists(fi.DirectoryName) == false) { // Message with alert? fi.Directory.Create(); } } etb.SaveFile(fileName); AppendToMRU(fileName); }
public string InputFileFromURL() { TabPage tb = tabControl1.SelectedTab; if (tb as EditorTabPage == null) { return(string.Empty); } EditorTabPage etb = tb as EditorTabPage; FileInfo fi = new FileInfo(etb.GetFileFullPathAndName()); var dialog = new InsertImageDialog(); dialog.FileName = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length) + "_pic1"; if (dialog.ShowDialog() != DialogResult.OK) { return(String.Empty); } if (fi.Directory.Exists == false) { Directory.CreateDirectory(fi.DirectoryName); } Download(dialog.URL, fi.DirectoryName, dialog.FileName); var resBuilder = new StringBuilder(); resBuilder.AppendFormat($"<img src=\"{dialog.FileName}\" alt=\"{dialog.ALT}\"/>"); return(resBuilder.ToString()); }
protected override void OnClosing(CancelEventArgs e) { EditorConfigurationSection section = cfg.GetEditorConfiguration(); section.MainWindowX.Value = this.Location.X; section.MainWindowY.Value = this.Location.Y; section.MainWindowWidth.Value = this.Size.Width; section.MainWindowHeight.Value = this.Size.Height; cfg.SaveAll(); unsavedDocumentsDialog.ClearDocuments(); foreach (TabPage tb in tabControl1.TabPages) { if (tb is EditorTabPage) { EditorTabPage etb = tb as EditorTabPage; if (!etb.Saved) { unsavedDocumentsDialog.AddDocument(etb.GetFileFullPathAndName()); } } } if (unsavedDocumentsDialog.SelectedDocumentsCount > 0) { DialogResult dr = unsavedDocumentsDialog.ShowDialog(); if (dr == DialogResult.Yes) { IEnumerable <string> documents = unsavedDocumentsDialog.SelectedDocuments; foreach (string document in documents) { string file = Path.GetFileName(document); EditorTabPage etb = GetTabByTitle(file); if (etb != null) { tabControl1.SelectedTab = etb; saveToolStripMenuItem_Click(null, null); } } } else if (dr == DialogResult.Cancel) { e.Cancel = true; } } base.OnClosing(e); }
/*private void tabControl1_MouseClick (object sender, MouseEventArgs e) * { * return; * if (e.Button == MouseButtons.Right) { * //Point pt = new Point(e.X, e.Y); * Point pt = Cursor.Position; * Point p = this.tabControl1.PointToClient (pt); * for (int i = 0; i < this.tabControl1.TabCount; i++) { * Rectangle r = this.tabControl1.GetTabRect (i); * if (r.Contains (p)) { * this.tabControl1.SelectedIndex = i; // i is the index of tab under cursor * var menu = new ContextMenu (); * menu.MenuItems.Add ("Закрыть", closeToolStripMenuItem_Click); * if (tabControl1.SelectedTab as EditorTabPage != null) { * menu.MenuItems.Add ("-"); * menu.MenuItems.Add ("Имя и путь файла скопировать", filepathnameToolStripMenuItem_Click); * menu.MenuItems.Add ("Директорию файла скопировать", foldernameToolStripMenuItem_Click); * } * menu.Show (this.tabControl1, p); * SetupActiveTab (); * return; * } * } * //e.Cancel = true; * } * }*/ private void filepathnameToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tb = tabControl1.SelectedTab; if (tb as EditorTabPage == null) { return; } EditorTabPage etb = tb as EditorTabPage; Globals.TextClipboard.CopyTextToClipboard(etb.GetFileFullPathAndName(), false); }
public void UpdateMainWindowTitle() { TabPage tb = tabControl1.SelectedTab; if (tb is EditorTabPage) { EditorTabPage etb = tb as EditorTabPage; if (etb != null) { this.Text = string.Format("MyPad - {0} [{1}]", etb.Text, etb.GetFileFullPathAndName()); } } }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { EditorTabPage currentActiveTab = tabControl1.SelectedTab as EditorTabPage; bool bSavingNecessary = true; EditorTabPage etb = new EditorTabPage(); string newTabName = null; string nearestInternalLink = GetNearestInternalLink(etb.Editor); if (string.IsNullOrWhiteSpace(nearestInternalLink)) { newTabName = string.Format("Untitled{0}", tabControl1.GetUntitledTabCount()); bSavingNecessary = false; // это совершенно новый файл и его можно не сохранять } else { string name = newTabName = string.Format("Untitled{0}", tabControl1.GetUntitledTabCount()); // name = nearestInternalLink; string fullPath = Path.Combine(etb.GetFileFullPathAndName(), name); if (File.Exists(fullPath)) { InternalOpenFile(fullPath); return; } newTabName = fullPath; // А здесь уже есть полезная информация от пользователя - имя файла, // поэтому не сохранять молча уже нельзя } var oldName = currentActiveTab == null ? String.Empty : currentActiveTab.GetFileFullPathAndName(); etb.Editor.Text = Globals.GetDefaultTemplateText(newTabName, oldName, newTabName); etb.IsSavingNecessary = bSavingNecessary; etb.SetFileName(newTabName); etb.Editor.DragEnter += new DragEventHandler(tabControl1_DragEnter); etb.Editor.DragDrop += new DragEventHandler(tabControl1_DragDrop); etb.OnEditorTextChanged += new EventHandler(etb_TextChanged); etb.OnEditorTabFilenameChanged += new EventHandler(TabControl_TabCaptionUpdate); etb.OnEditorTabStateChanged += new EventHandler(TabControl_TabCaptionUpdate); etb.Show(); tabControl1.TabPages.Add(etb); tabControl1.SelectedTab = etb; }
/// <summary> /// Создаёт новую вкладку, размещает в ней текст /// </summary> /// <param name="targetFilename">File name.</param> private EditorTabPage CreateNewTabWithProposedFileName(string targetFilename, string title) { TabPage tbA = tabControl1.SelectedTab; if (tbA as EditorTabPage == null) { throw new ApplicationException("Shouldn't get here"); } EditorTabPage currentActiveTab = tbA as EditorTabPage; if (AlreadyOpen(targetFilename)) { return(this.FindTabByPath(targetFilename)); } if (Exists(targetFilename)) { InternalOpenFile(targetFilename); return(this.FindTabByPath(targetFilename)); } EditorTabPage etb = new EditorTabPage(); etb.SetFileName(targetFilename); // Create content string sourceFilename = currentActiveTab.GetFileFullPathAndName(); etb.Editor.Text = Globals.GetDefaultTemplateText(targetFilename, title, sourceFilename); // setup event handlers etb.Editor.DragEnter += new DragEventHandler(tabControl1_DragEnter); etb.Editor.DragDrop += new DragEventHandler(tabControl1_DragDrop); etb.OnEditorTextChanged += new EventHandler(etb_TextChanged); etb.OnEditorTabFilenameChanged += new EventHandler(TabControl_TabCaptionUpdate); etb.OnEditorTabStateChanged += new EventHandler(TabControl_TabCaptionUpdate); // Add into container tabControl1.TabPages.Add(etb); tabControl1.SelectedTab = etb; etb.Show(); return(etb); }
/// <summary> /// Вызывается из главного меню, когда надо сохранить файл /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tb = tabControl1.SelectedTab; if (tb as EditorTabPage == null) { return; } EditorTabPage etb = tb as EditorTabPage; string newName = etb.Editor.ActiveTextAreaControl.SelectionManager.SelectedText; if (string.IsNullOrEmpty(newName)) { newName = Globals.DefaultIndexFileName; // "index.htm" } FileInfo finfo = new FileInfo(etb.GetFileFullPathAndName()); string proposedFileName = Path.Combine(finfo.DirectoryName, newName); try { proposedFileName = finfo.DirectoryName.ToString().ToFilePath() + newName; // normalize } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } // extract hyperlink text to title int col = etb.Editor.ActiveTextAreaControl.Caret.Column; int line = etb.Editor.ActiveTextAreaControl.Caret.Line; IDocument document = etb.Editor.ActiveTextAreaControl.Document; ISegment s = document.GetLineSegment(line); string content = document.GetText(s); string title = GetATagText(content, col); if (string.IsNullOrWhiteSpace(title)) { title = proposedFileName; } CreateNewTabWithProposedFileName(proposedFileName, title); // GetNewNameInSaveAsDialogFromProposedName(proposedFileName); }
private void foldernameToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tb = tabControl1.SelectedTab; if (tb as EditorTabPage == null) { return; } EditorTabPage etb = tb as EditorTabPage; var fileFullPathAndName = etb.GetFileFullPathAndName(); FileInfo fi = new FileInfo(fileFullPathAndName); if (fileFullPathAndName.Contains(Path.DirectorySeparatorChar)) { Globals.TextClipboard.CopyTextToClipboard(fi.DirectoryName, false); } else { Globals.TextClipboard.CopyTextToClipboard("." + Path.DirectorySeparatorChar, false); } }
public bool AlreadyOpen(string filename) { if (string.IsNullOrWhiteSpace(filename)) { return(false); } filename = GetFullFilename(filename); foreach (TabPage tb in tabControl1.TabPages) { if (tb is EditorTabPage) { EditorTabPage etb = tb as EditorTabPage; if (etb.GetFileFullPathAndName().CompareTo(filename) == 0) { return(true); } } } return(false); }