示例#1
0
        private bool close(MarkdownEditor meditor)
        {
            if (meditor.AlreadyUpdate)
            {
                DialogResult dr = MessageBox.Show("修改还没有保存,需要保存吗?", "提示", MessageBoxButtons.YesNoCancel);
                if (dr == DialogResult.Cancel)
                {
                    return(false);
                }

                if (dr == DialogResult.Yes)
                {
                    if (!save(meditor))
                    {
                        return(false);
                    }
                }
            }

            int ind = TabSelectRec.GetLast();

            if (ind > -1 && ind < _tabparent.TabCount)
            {
                _tabparent.SelectedIndex = ind;
            }

            _editors.Remove((int)meditor.MarkdownPage.Tag);
            _tabparent.TabPages.Remove(meditor.MarkdownPage);

            return(true);
        }
示例#2
0
        private bool filetypeConvert(MarkdownEditor meditor)
        {
            string marktext = meditor.GetMarkdown();

            if (string.IsNullOrEmpty(marktext))
            {
                return(false);
            }

            string ext = Path.GetExtension(meditor.FileName);

            if (_regexExtMarkdowns.IsMatch(ext))
            {
                Markdown mark = new Markdown();
                string   html = mark.Transform(marktext);
                rtbHtml.Text             = html;
                webBrowser1.DocumentText = meditorManager.GetHTMLStyle(html);
                return(true);
            }

            if (_regexExtHtml.IsMatch(ext))
            {
                webBrowser1.DocumentText = marktext;
                rtbHtml.Text             = marktext;
                return(true);
            }

            if (_regexExtOthertext.IsMatch(ext))
            {
                webBrowser1.DocumentText = meditorManager.GetHTMLStyle("<pre><code>" + marktext + "</code></pre>");
                rtbHtml.Text             = marktext;
                return(true);
            }
            return(false);
        }
示例#3
0
        private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            string url = e.Url.ToString();

            if (url == "about:blank")
            {
                return;
            }

            if (url.StartsWith("http://") || url.StartsWith("https://"))
            {
                return;
            }

            //if (url.EndsWith(".md"))
            //{
            url = url.Remove(0, 6);
            MarkdownEditor me = meditorManager.GetCurrEditor();

            if (me == null)
            {
                return;
            }
            url = Path.Combine(Path.GetDirectoryName(me.FileName), url);

            if (_regexExtMarkdowns.IsMatch(url) || _regexExtOthertext.IsMatch(url))
            {
                e.Cancel = true;
                openfile(url);
            }
            //webBrowser1.Navigate(url);
            //}
        }
示例#4
0
        private void PreviewHtml()
        {
            MarkdownEditor meditor = meditorManager.SetStyle();

            if (meditor == null)
            {
                return;
            }

            this.toolStripStatusLabel1.Text = " 正在转换。。。。 ";

            if (filetypeConvert(meditor))
            {
                if (isLeft)
                {
                    if (splitContainer1.Panel2Collapsed)
                    {
                        splitContainer1.Panel2Collapsed = false;
                    }
                }
                else
                {
                    if (splitContainer1.Panel1Collapsed)
                    {
                        splitContainer1.Panel1Collapsed = false;
                    }
                }
            }

            tabBrowser.Text = meditor.MarkdownPage.Text;
            this.toolStripStatusLabel1.Text = "当前文档:" + meditor.FileName;

            //tabControl1.Focus();
            meditor.GetTextBox().Focus();
        }
示例#5
0
        private bool saveas(MarkdownEditor meditor)
        {
            SaveFileDialog fileone = new SaveFileDialog();

            fileone.Filter      = myExtName;
            fileone.FilterIndex = 1;
            if (fileone.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (_thisModify.ContainsKey(meditor.FileName))
                    {
                        _thisModify.Remove(meditor.FileName);
                    }
                    meditor.Save(fileone.FileName);
                    mruManager.Add(meditor.FileName);                              // when file is successfully opened
                    if (!_thisModify.ContainsKey(meditor.FileName))
                    {
                        _thisModify.Add(meditor.FileName, true);
                    }
                    return(true);
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("保存不成功");
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        private void 查找替换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MarkdownEditor me = meditorManager.GetCurrEditor();

            if (me == null)
            {
                return;
            }
        }
示例#7
0
        private void 转为小写ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MarkdownEditor me = meditorManager.GetCurrEditor();

            if (me == null)
            {
                return;
            }
            me.GetTextBox().SelectedText = me.GetTextBox().SelectedText.ToLower();
        }
示例#8
0
        public bool SaveAs()
        {
            MarkdownEditor meditor = GetCurrEditor();

            if (meditor == null)
            {
                return(true);
            }
            return(saveas(meditor));
        }
示例#9
0
        public bool Close()
        {
            MarkdownEditor meditor = GetCurrEditor();

            if (meditor == null)
            {
                return(true);
            }

            return(close(meditor));
        }
示例#10
0
        public void Save()
        {
            MarkdownEditor meditor = GetCurrEditor();

            if (meditor == null)
            {
                return;
            }

            save(meditor);
        }
示例#11
0
        public TextEditor GetTextBox()
        {
            MarkdownEditor meditor = GetCurrEditor();

            if (meditor == null)
            {
                return(null);
            }

            return(meditor.GetTextBox());
        }
示例#12
0
        public MarkdownEditor SetStyle()
        {
            MarkdownEditor m = GetCurrEditor();

            if (m == null)
            {
                return(null);
            }

            m.SetStyle(_bgColor, _foreColor, _font, _wordWrap, _tabWidth);

            return(m);
        }
示例#13
0
        public void openDir()
        {
            MarkdownEditor meditor = GetCurrEditor();

            if (meditor == null)
            {
                return;
            }

            System.IO.FileInfo fi = new FileInfo(meditor.FileName);

            System.Diagnostics.Process.Start("explorer.exe", fi.Directory.ToString());
        }
示例#14
0
 private bool save(MarkdownEditor meditor)
 {
     if (string.IsNullOrEmpty(meditor.FileName) || meditor.FileName.IndexOf("未命名") != -1)
     {
         return(saveas(meditor));
     }
     meditor.Save();
     if (!_thisModify.ContainsKey(meditor.FileName))
     {
         _thisModify.Add(meditor.FileName, true);
     }
     mruManager.Add(meditor.FileName);                      // when file is successfully opened
     return(true);
 }
示例#15
0
        private void 转到行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MarkdownEditor me = meditorManager.GetCurrEditor();

            if (me == null)
            {
                return;
            }

            if (me.GetTextBox().Document.LineCount > 0)
            {
                //Show the dialog
                GoToLineDialog gtl = new GoToLineDialog(me.GetTextBox());
                gtl.ShowDialog();
            }
        }
示例#16
0
        private bool openfile_(string file)
        {
            TabPage markPage = new TabPage(GetDisplayName(file));

            markPage.ToolTipText = file;
            _tabparent.TabPages.Add(markPage);
            markPage.Tag = _fileInd;

            MarkdownEditor meditor = new MarkdownEditor(_thisForm, markPage, _previewBrowser);

            _editors.Add(_fileInd++, meditor);
            bool rel = meditor.Openfile(file);

            if (rel)
            {
                _tabparent.SelectedTab = markPage;
            }

            return(rel);
        }
示例#17
0
        private bool save(MarkdownEditor meditor)
        {
            if (string.IsNullOrEmpty(meditor.FileName) || meditor.FileName.IndexOf("未命名")!=-1)
            {
                return saveas(meditor);

            }
            meditor.Save();
            if (!_thisModify.ContainsKey(meditor.FileName))
            {
                _thisModify.Add(meditor.FileName, true);
            }
            mruManager.Add(meditor.FileName);          // when file is successfully opened
            return true;
        }
示例#18
0
        private bool close(MarkdownEditor meditor)
        {
            if (meditor.AlreadyUpdate)
            {
                DialogResult dr= MessageBox.Show("修改还没有保存,需要保存吗?", "提示", MessageBoxButtons.YesNoCancel) ;
                 if(dr==DialogResult.Cancel)
                     return false;

                if (dr== DialogResult.Yes)
                {
                    if (!save(meditor))
                        return false;
                }
            }

            int ind=TabSelectRec.GetLast();
            ind = TabSelectRec.GetLast();
            if (ind > -1 && ind<_tabparent.TabCount)
                _tabparent.SelectedIndex = ind;

            _editors.Remove((int)meditor.MarkdownPage.Tag);
            _tabparent.TabPages.Remove(meditor.MarkdownPage);

            return true;
        }
示例#19
0
        private bool openfile_(string file)
        {
            TabPage markPage = new TabPage(GetDisplayName(file));
            markPage.ToolTipText = file;
            _tabparent.TabPages.Add(markPage);
            markPage.Tag = _fileInd;

            MarkdownEditor meditor = new MarkdownEditor(_thisForm, markPage);
            _editors.Add(_fileInd, meditor);
            _fileInd++;
            meditor.SetStyle(_bgColor, _foreColor, _font, _wordWrap, _tabWidth);
            bool rel = meditor.Openfile(file);
            if (rel)
            {
                _tabparent.SelectedTab = markPage;
            }

            return rel;
        }
示例#20
0
        private bool filetypeConvert(MarkdownEditor meditor)
        {
            string marktext = meditor.GetMarkdown();
            if (string.IsNullOrEmpty(marktext))
            {
                return false;
            }

            string ext = Path.GetExtension(meditor.FileName);
            if (_regexExtMarkdowns.IsMatch(ext))
            {
                string html = "";
                html = Utils.ConvertTextToHTML(marktext);
                rtbHtml.Text = html;
                webControl1.LoadHTML(meditorManager.GetHTMLStyle(html));
                return true;
            }

            if (_regexExtHtml.IsMatch(ext))
            {
                webControl1.LoadHTML(marktext);
                rtbHtml.Text = marktext;
                return true;
            }

            if (_regexExtOthertext.IsMatch(ext))
            {
                webControl1.LoadHTML(meditorManager.GetHTMLStyle("<pre><code>" + marktext + "</code></pre>"));
                rtbHtml.Text = marktext;
                return true;
            }
            return false;
        }
示例#21
0
 private bool saveas(MarkdownEditor meditor)
 {
     SaveFileDialog fileone = new SaveFileDialog();
     fileone.Filter = myExtName;
     fileone.FilterIndex = 1;
     if (fileone.ShowDialog() == DialogResult.OK)
     {
         try
         {
             if (_thisModify.ContainsKey(meditor.FileName))
             {
                 _thisModify.Remove(meditor.FileName);
             }
             meditor.Save(fileone.FileName);
             mruManager.Add(meditor.FileName);          // when file is successfully opened
             if (!_thisModify.ContainsKey(meditor.FileName))
             {
                 _thisModify.Add(meditor.FileName, true);
             }
             return true;
         }
         catch (ArgumentException)
         {
             MessageBox.Show("保存不成功");
             return false;
         }
     }
     else
     {
         return false;
     }
 }
示例#22
0
        private bool filetypeConvert(MarkdownEditor meditor)
        {
            string marktext = meditor.GetMarkdown();
                if (string.IsNullOrEmpty(marktext))
                {
                    return false ;
                }

            string ext = Path.GetExtension(meditor.FileName);
            if (_regexExtMarkdowns.IsMatch(ext))
            {
            string html="";
                Markdown mark = new Markdown();
                html = mark.Transform(marktext);
                rtbHtml.Text = html;
                webBrowser1.DocumentText = meditorManager.GetHTMLStyle(html);
                return true;
            }

            if (_regexExtHtml.IsMatch(ext))
            {
                webBrowser1.DocumentText = marktext;
                rtbHtml.Text = marktext;
                return true;
            }

            if (_regexExtOthertext.IsMatch(ext))
            {
                webBrowser1.DocumentText = meditorManager.GetHTMLStyle("<pre><code>"+marktext+"</code></pre>");
                rtbHtml.Text = marktext;
                return true;
            }
            return false;
        }