public void SetupActiveTab()
        {
            EditorTabPage etb = GetActiveTab();

            if (etb != null)
            {
                etb.Show();

                UpdateMainWindowTitle();
                etb.Editor.Focus();

                toolStripStatusLabel2.Text = string.Format("Line: {0}", (etb.Editor.ActiveTextAreaControl.TextArea.Caret.Line + 1).ToString());
                toolStripStatusLabel3.Text = string.Format("Col: {0}", etb.Editor.ActiveTextAreaControl.TextArea.Caret.Column.ToString());

                string highlighter = etb.Editor.Document.HighlightingStrategy.Name;

                foreach (ToolStripMenuItem tsi in highlightingToolStripMenuItem.DropDownItems)
                {
                    if (tsi.Name == highlighter)
                    {
                        tsi.Checked = true;
                    }
                    else
                    {
                        tsi.Checked = false;
                    }
                }
            }
            else
            {
                this.Text = "MyPad";
            }
        }
        internal void InternalOpenFile(string fileToLoad)
        {
            if (string.IsNullOrWhiteSpace(fileToLoad))
            {
                return;
            }
            if (this.WindowState != FormWindowState.Normal)
            {
                this.WindowState = FormWindowState.Normal;
            }
            this.BringToFront();

            var tab = FindTabByPath(fileToLoad);

            if (tab != null)
            {
                tabControl1.SelectedTab = tab;
                SetupActiveTab();
                return;
            }

            EditorTabPage etb = new EditorTabPage();

            etb.LoadFile(fileToLoad);
            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);
            tabControl1.TabPages.Add(etb);
            etb.Show();
            tabControl1.SelectedTab = etb;
            etb.Update();

            MRUListConfigurationSection mruList = cfg.GetMRUList();

            if (!mruList.Contains(fileToLoad))
            {
                if (mruList.Instances.Count >= 15)
                {
                    mruList.RemoveAt(14);
                }
                mruList.InsertAt(0, fileToLoad);
                ToolStripMenuItem tsi = new ToolStripMenuItem(fileToLoad, null, new EventHandler(RecentFiles_Click));
                recentFilesToolStripMenuItem.DropDown.Items.Insert(0, tsi);
            }
            else
            {
                mruList.Remove(fileToLoad);
                mruList.InsertAt(0, fileToLoad);
                ToolStripMenuItem tsi = GetRecentMenuItem(fileToLoad);
                recentFilesToolStripMenuItem.DropDown.Items.Remove(tsi);
                recentFilesToolStripMenuItem.DropDown.Items.Insert(0, tsi);
            }
        }
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditorTabPage etb        = new EditorTabPage();
            string        newTabName = string.Format("Untitled{0}", GetUntitledTabCount());

            etb.SetTitle(newTabName);
            etb.Editor.DragEnter        += new DragEventHandler(tabControl1_DragEnter);
            etb.Editor.DragDrop         += new DragEventHandler(tabControl1_DragDrop);
            etb.OnEditorTextChanged     += new EventHandler(etb_TextChanged);
            etb.OnEditorFilenameChanged += new EventHandler(etb_FilenameChanged);
            etb.Show();

            tabControl1.TabPages.Add(etb);
            tabControl1.SelectedTab = etb;
        }
        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;
        }
        void InternalOpenFile(string fileToLoad)
        {
            if (string.IsNullOrWhiteSpace(fileToLoad))
            {
                return;
            }
            var tab = FindTabByPath(fileToLoad);

            if (tab != null)
            {
                tabControl1.SelectedTab = tab;
                SetupActiveTab();
                return;
            }

            EditorTabPage etb = new EditorTabPage();

            etb.LoadFile(fileToLoad);
            etb.Editor.DragEnter        += new DragEventHandler(tabControl1_DragEnter);
            etb.Editor.DragDrop         += new DragEventHandler(tabControl1_DragDrop);
            etb.OnEditorTextChanged     += new EventHandler(etb_TextChanged);
            etb.OnEditorFilenameChanged += new EventHandler(etb_FilenameChanged);
            tabControl1.TabPages.Add(etb);
            etb.Show();
            tabControl1.SelectedTab = etb;
            etb.Update();

            if (!SettingsManager.MRUList.Contains(fileToLoad))
            {
                if (SettingsManager.MRUList.Count >= 15)
                {
                    SettingsManager.MRUList.RemoveAt(14);
                }
                SettingsManager.MRUList.Insert(0, fileToLoad);
                ToolStripMenuItem tsi = new ToolStripMenuItem(fileToLoad, null, new EventHandler(RecentFiles_Click));
                recentFilesToolStripMenuItem.DropDown.Items.Insert(0, tsi);
            }
            else
            {
                SettingsManager.MRUList.Remove(fileToLoad);
                SettingsManager.MRUList.Insert(0, fileToLoad);
                ToolStripMenuItem tsi = GetRecentMenuItem(fileToLoad);
                recentFilesToolStripMenuItem.DropDown.Items.Remove(tsi);
                recentFilesToolStripMenuItem.DropDown.Items.Insert(0, tsi);
            }
        }
Beispiel #6
0
        /// <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);
        }
        public void SetupActiveTab()
        {
            var initializableTabPage = tabControl1.SelectedTab as IInitializable;

            // In case you have other tab-pages.
            if (initializableTabPage != null)
            {
                initializableTabPage.Initialize();
            }

            TabPage tb = tabControl1.SelectedTab;

            if (tb is EditorTabPage)
            {
                EditorTabPage etb = tb as EditorTabPage;
                if (etb != null)
                {
                    etb.Show();

                    UpdateMainWindowTitle();
                    etb.Editor.Focus();

                    toolStripStatusLabel2.Text = string.Format("Line: {0}", (etb.Editor.ActiveTextAreaControl.TextArea.Caret.Line + 1).ToString());
                    toolStripStatusLabel3.Text = string.Format("Col: {0}", etb.Editor.ActiveTextAreaControl.TextArea.Caret.Column.ToString());

                    string highlighter = etb.Editor.Document.HighlightingStrategy.Name;

                    foreach (ToolStripMenuItem tsi in highlightingToolStripMenuItem.DropDownItems)
                    {
                        var nameInTag = tsi.Tag as string;
                        if (string.Compare(nameInTag, highlighter, StringComparison.InvariantCulture) == 0)
                        {
                            tsi.Checked = true;
                        }
                        else
                        {
                            tsi.Checked = false;
                        }
                    }
                    return;
                }
            }
            this.Text = "MyPad";
        }