using ryCommon; using ryCommonDb; using 开发辅助工具.Manager.FTP; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Security.Policy; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; using WeifenLuo.WinFormsUI.Docking; using 开发辅助工具.Manager; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; using static System.Net.Mime.MediaTypeNames; using System.IO; using ryControls; using SuperDesign.Tools.SmartEditor; using GameBackup3H3.DbOp; using MyPage; using ObjectListViewDemo; namespace 开发辅助工具.Tools.SmartEditor { public partial class FrmFileEditor : DockContent { public FrmFileEditor() { InitializeComponent(); AutoScaleMode = AutoScaleMode.Dpi; highlightEditor1.TextChanged += HighlightEditor1_TextChanged; highlightEditor1.OnSaveKeyHappen += HighlightEditor1_OnSaveKeyHappen; List autoc_list = new List(); highlightEditor1.Font = new Font("Consolas",12f); autoc_list.AddRange(RyFiles.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\SysDb\\AutoComplete\\editor.txt")); highlightEditor1.SetAutoCompleteList(autoc_list); } private void HighlightEditor1_OnSaveKeyHappen(object sender, EventArgs e) { OnSaveKeyHappen?.Invoke(this, e); } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.R)) { if (FilePath.Length == 0) { return true; } } return base.ProcessCmdKey(ref msg, keyData);//这里就是返回没有重写的键位,也就是这个函数原本的处理方式 //其余键位默认处理 } /// /// 未保存状态改变 /// [Description("未保存状态改变")] public event EventHandler OnUnSaveChanged; /// /// 保存热键发生时 /// [Description("保存热键发生时")] public event EventHandler OnSaveKeyHappen; /// /// 打开其它站点文件 /// [Description("打开其它站点文件")] public event EventHandler OnOpenOtherSiteFile; private void HighlightEditor1_TextChanged(object sender, EventArgs e) { if (!IsChanged) { IsChanged = true; OnUnSaveChanged?.Invoke(this, new EventArgs()); } } /// /// 对应的Site /// public SiteInfo SiteInfo { get; set; } = new SiteInfo(); private Encoding encoding = Encoding.UTF8; /// /// 当前文件格式 /// public Encoding Encoding { get { return encoding; } set { encoding = value; IsChanged = true; OnUnSaveChanged?.Invoke(this, new EventArgs()); } } /// /// 加载的文件大小 /// public long FileSize { get; private set; } = 0; /// /// 文件写入时间 /// public long FileWriteTime { get; private set; } = 0; /// /// 文件创建时间 /// public long FileCreateTime { get; private set; } = 0; /// /// 当前选择的文件路径 /// public string FilePath { get; set; } = ""; /// /// 文件改变是否进行提醒,保存文件后会重新进行提醒 /// public bool Fileinfo_Changed_Tip { get; set; } = true; /// /// 当前选择的FTP远程文件路径,只有当FilePath为空时才生效 /// public string FTPRemotePath { get; set; } = ""; public void GetFileInfo(string path) { FileSize = RyFiles.GetFileSize(path); var dt = RyFiles.GetFileDate(path); FileWriteTime = dt.LastWriteTime.ToInt64(); FileCreateTime = dt.CreateTime.ToInt64(); } public string InitFilePath { get; set; } = ""; public string InitCacheText { get; set; } = ""; public int FirstVisibleLine { get; set; } = 0; public void LoadInitFile(string path, string CacheText = "") { if (!System.IO.File.Exists(path)) { MessageBox.Show("文件不存在=>" + path, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } InitFilePath = path; InitCacheText = CacheText; FilePath = path; GetSites(); IsChanged = CacheText.Length > 0; UpdateTitle(); this.Icon = ShellUtilities.GetFileIcon(path, true, true); } private void GetSites() { IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds = db.ReadData("select * from Site"); if (ds.HaveData()) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow reader = ds.Tables[0].Rows[i]; if (FilePath.IndexOfEx(reader["localPath"].ToString()) < 0) { continue; } #region 读取信息 SiteInfo.Name = reader["name"].ToString(); SiteInfo.LocalPath = reader["localPath"].ToString(); SiteInfo.FtpDir = reader["ftpDir"].ToString(); SiteInfo.FtpId = reader["ftpId"].ToInt(); SiteInfo.Id = reader["Id"].ToInt(); break; #endregion } } ds.Dispose(); } db.Free(); } public int LoadFile(string path,string CacheText="") { if (!System.IO.File.Exists(path)) { MessageBox.Show("文件不存在=>"+path, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return -1; } Encoding = TxtFileEncoder.GetEncoding(path,Encoding.GetEncoding("GB2312")); highlightEditor1.SetHightlightText(CacheText.Length==0? RyFiles.ReadAllText(path,Encoding): CacheText, System.IO.Path.GetFileName(path)); GetFileInfo(path); FilePath = path; SiteInfo.FtpId=0; SiteInfo.Id = 0; GetSites(); IsChanged = CacheText.Length>0; UpdateTitle(); highlightEditor1.Editor.EmptyUndoBuffer(); this.Icon = ShellUtilities.GetFileIcon(path, true, true); OnUnSaveChanged?.Invoke(this, new EventArgs()); return 1; } public void UpdateTitle() { if (FilePath.Length == 0 && FTPRemotePath.Length==0) { return; } var text = System.IO.Path.GetFileName(FilePath.Length == 0 ?FTPRemotePath: FilePath); if(SiteInfo.FtpId>0) { if (FilePath.Length == 0) { text = "[" + SiteInfo.Name + "][FTP]" + text; } else { text = "[" + SiteInfo.Name + "]" + text; } } if (IsChanged) { text = "*" + text; } Text = text; } /// /// FTP远程路径 /// public string RemotePath { get { if (FilePath.Length == 0 && SiteInfo.FtpId > 0) { return FTPRemotePath; } else { return SiteInfo.FtpDir.Trim('/') + "/" + XDPath.Replace("\\", "/"); } } } /// /// 相对路径 /// public string XDPath { get { if (FilePath.Length == 0) { return ""; } if (SiteInfo.LocalPath.Length == 0) { return ""; } return FilePath.Replace(SiteInfo.LocalPath, "", true).Trim('\\'); } } public int UploadFTP() { if (SiteInfo.FtpId <= 0) { return -1; } var result = -2; var uploadinfo = GetUploadInfo(); if (uploadinfo == null) { return -1; } FrmUploadProg frm = new FrmUploadProg(); frm.UploadList.Add(uploadinfo); if (frm.ShowDialog() == DialogResult.OK) { result = 1; } frm.Dispose(); return result; } /// /// 获取FTP上传信息 /// /// public UploadInfo GetUploadInfo() { UploadInfo uploadinfo = null; IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds = db.ReadData("select * from Ftp where Id=" + SiteInfo.FtpId); if (ds.HaveData()) { DataRow row = ds.Tables[0].Rows[0]; var FtpInfo = new GameBackup3H3.DbOp.FTPInfo() { Id = row["id"].ToInt(), Name = row["name"].ToString(), IP = row["ip"].ToString(), Port = row["port"].ToInt(), RemoteDir = SiteInfo.FtpDir, UserName = row["username"].ToString(), Pwd = row["pwd"].ToString(), Encrypt = row["encrypt"].ToInt(0, 2, 0), AddTime = row["AddTime"].ToDateTime() }; uploadinfo = new UploadInfo() { FtpInfo = FtpInfo, RemotePath = RemotePath, LocalPath = FilePath, Content = highlightEditor1.Text, Encoding = Encoding }; } ds.Dispose(); } db.Free(); return uploadinfo; } public int UploadFTPByAllSite() { if (SiteInfo.FtpId <= 0) { return -1; } var result = -2; IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { DataSet ds = db.ReadData("select * from Site"); if (ds.HaveData()) { FrmUploadProg frm = new FrmUploadProg(); var xd_path = XDPath; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow reader = ds.Tables[0].Rows[i]; if(!System.IO.File.Exists(reader["localPath"].ToString() + "\\" + xd_path)) { continue; } DataSet ds_ftp = db.ReadData("select * from Ftp where Id=" + reader["ftpId"].ToInt()); if (ds_ftp.HaveData()) { DataRow row = ds_ftp.Tables[0].Rows[0]; var FtpInfo = new GameBackup3H3.DbOp.FTPInfo() { Id = row["id"].ToInt(), Name = row["name"].ToString(), IP = row["ip"].ToString(), Port = row["port"].ToInt(), RemoteDir = reader["ftpDir"].ToString(), UserName = row["username"].ToString(), Pwd = row["pwd"].ToString(), Encrypt = row["encrypt"].ToInt(0, 2, 0), AddTime = row["AddTime"].ToDateTime() }; var remotepath = reader["ftpDir"].ToString().Trim('/') + "/" + xd_path.Replace("\\", "/").Trim('/'); frm.UploadList.Add(new UploadInfo() { FtpInfo = FtpInfo, RemotePath = remotepath, LocalPath = reader["localPath"].ToString()+"\\"+ xd_path }); } ds_ftp.Dispose(); } if (frm.ShowDialog() == DialogResult.OK) { result = 1; } frm.Dispose(); } ds.Dispose(); } db.Free(); return result; } /// /// 保存 /// public int Save() { Fileinfo_Changed_Tip = true; if(InitFilePath.Length>0) { LoadFile(InitFilePath,InitCacheText); InitFilePath = ""; InitCacheText = ""; } if(FilePath.Length==0) { if (SiteInfo.FtpId > 0) { var result = -1; var uploadinfo = GetUploadInfo(); if (uploadinfo == null) { return -1; } FrmUploadProg frm = new FrmUploadProg(); frm.UploadList.Add(uploadinfo); if (frm.ShowDialog() == DialogResult.OK) { result = 1; Itrycn_Db.AddHistory("[FTP:"+ SiteInfo.FtpId + "]"+uploadinfo.RemotePath, highlightEditor1.Text); IsChanged = false; //FrmMainEditor.MainEditor.UpdateFTPFileState(uploadinfo.FtpInfo.Id, uploadinfo.RemotePath, uploadinfo.FileWriteTime, uploadinfo.FileSize); OnUnSaveChanged?.Invoke(this, new EventArgs()); } frm.Dispose(); return result; //Itrycn_Db.AddHistory(dialog.FileName, highlightEditor1.Text); } else { SaveFileDialog dialog = new SaveFileDialog { FileName = "新建文档.txt", Filter = "常用格式|*.php;*.cs;*.txt;*.pas;*.js;*.html;*.htm;*.css;*.ini;*.json;*.xml;*.java;*.vbs;*.asp;*.aspx|所有文件|*.*" }; if (dialog.ShowDialog() == DialogResult.OK) { FilePath = dialog.FileName; try { RyFiles.WriteAllText(dialog.FileName, highlightEditor1.Text, Encoding); } catch (Exception ex) { MessageBox.Show(FilePath + "\r\n" + ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return -1; } Itrycn_Db.AddHistory(dialog.FileName, highlightEditor1.Text); GetFileInfo(dialog.FileName); FrmMainEditor.MainEditor.UpdateFileState(FilePath); IsChanged = false; OnUnSaveChanged?.Invoke(this, new EventArgs()); return 1; } } } else { try { RyFiles.WriteAllText(FilePath, highlightEditor1.Text, Encoding); } catch(Exception ex) { MessageBox.Show(FilePath+"\r\n" +ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return -1; } Itrycn_Db.AddHistory(FilePath, highlightEditor1.Text); GetFileInfo(FilePath); IsChanged = false; FrmMainEditor.MainEditor.UpdateFileState(FilePath); OnUnSaveChanged?.Invoke(this, new EventArgs()); return 1; } return -1; } /// /// 是否内容改变 /// public bool IsChanged { get; internal set; } = true; /// /// 保存 /// /// public void Save(string path) { RyFiles.WriteAllText(path, highlightEditor1.Text, Encoding); Itrycn_Db.AddHistory(path, highlightEditor1.Text); IsChanged = false; Fileinfo_Changed_Tip = true; FrmMainEditor.MainEditor.UpdateFileState(FilePath); OnUnSaveChanged?.Invoke(this, new EventArgs()); } /// /// 删除重复行 /// public void DeleteRepeatLine() { var lines = highlightEditor1.Text.Replace("\r", "").Split('\n'); var txt = ""; var dict=new Dictionary(); for (int i = 0; i < lines.Length; i++) { var line = lines[i]; if (line.Length == 0) { continue; } if (dict.ContainsKey(line)) { continue; } if (txt.Length != 0) { txt += "\r\n"; } txt+= line; dict[line] = i; } highlightEditor1.Text = txt; } /// /// 删除空白行 /// public void DeleteWhiteLine() { var lines = highlightEditor1.Text.Replace("\r", "").Split('\n'); var txt = ""; for (int i = 0; i < lines.Length; i++) { var line = lines[i]; if (line.Trim().Length == 0) { continue; } if (txt.Length != 0) { txt += "\r\n"; } txt += line; } highlightEditor1.Text = txt; } private void 关闭本标签ToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void 除此之外全部关闭ToolStripMenuItem_Click(object sender, EventArgs e) { switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { case DialogResult.Cancel: return; } DockContentCollection contents = this.DockPanel.Contents; int num = 0; while (num < contents.Count) { var content = contents[num]; if (content.DockHandler.DockState == DockState.Document && this.DockPanel.ActiveContent != content) { var canClose = true; if (content is FrmFileEditor frm) { if(frm.IsChanged) { switch (MessageBox.Show("是否要保存文档?\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.Cancel: canClose = false; break; case DialogResult.No: break; case DialogResult.Yes: if(frm.Save()!=1) { canClose = false; } break; } } } if (canClose) { content.DockHandler.Close(); } else { num++; } } else { num++; } } } private void 收藏该文件ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length == 0) { return; } bool isAdd = false; if (收藏该文件ToolStripMenuItem.Text.IndexOfEx("取消") >= 0) { switch (MessageBox.Show("是否确定要取消收藏?\r\n选是:取消收藏\r\n选否:新建收藏。\r\n选取消:不再取消收藏。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.Yes: break; case DialogResult.No: isAdd = true; break; default: return; } if (!isAdd) { RyQuickSQL mySQL = new RyQuickSQL("FavFiles"); mySQL.AddField("FilePath", FilePath); IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { db.ExecuteNonQuery("delete from FavFiles where FilePath=@FilePath and GroupId=0", mySQL); } db.Free(); return; } } else { isAdd = true; } if(isAdd) { FrmFavFile frm = new FrmFavFile { FilePath = FilePath }; frm.SelectedId = 0; frm.TxtFind.Text = this.highlightEditor1.GetNearestFunLineStr(this.highlightEditor1, out _); frm.TxtFavName.Text = System.IO.Path.GetFileName(FilePath); if (frm.ShowDialog() == DialogResult.OK) { } frm.Dispose(); } } private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e) { 收藏该文件ToolStripMenuItem.Enabled = FilePath.Length > 0; 文件信息ToolStripMenuItem.Enabled = FilePath.Length > 0; 查看历史记录ToolStripMenuItem.Enabled =FTPRemotePath.Length>0 || FilePath.Length > 0; 打开其它站点文件ToolStripMenuItem.Enabled = SiteInfo.FtpId > 0 && FilePath.Length>0; 复制所在文件夹路径ToolStripMenuItem.Enabled = FilePath.Length > 0; 复制文件名ToolStripMenuItem.Enabled = FilePath.Length > 0; 复制路径ToolStripMenuItem.Enabled = FilePath.Length > 0; 在资源管理器中定位该文件ToolStripMenuItem.Enabled = FilePath.Length > 0; 在工作区定位当前文件ToolStripMenuItem.Enabled = FilePath.Length > 0; 编辑FTP上的对应文件ToolStripMenuItem.Enabled=FilePath.Length > 0 && SiteInfo.FtpId>0; 比对FTP上的对应文件ToolStripMenuItem.Enabled = FilePath.Length > 0 && SiteInfo.FtpId > 0; if (FrmMainEditor.MainEditor.CompareTitle1.Length > 0) { 比对文本1ToolStripMenuItem.Text = "比对文本1=>" + FrmMainEditor.MainEditor.CompareTitle1; } else { 比对文本1ToolStripMenuItem.Text = "比对文本1"; } if (FrmMainEditor.MainEditor.CompareTitle2.Length > 0) { 比对文本2ToolStripMenuItem.Text = "比对文本2=>" + FrmMainEditor.MainEditor.CompareTitle2; } else { 比对文本2ToolStripMenuItem.Text = "比对文本2"; } RyQuickSQL mySQL = new RyQuickSQL("FavFiles"); mySQL.AddField("FilePath", FilePath); IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { var ds = db.ReadData("select * from FavFiles where FilePath=@FilePath and GroupId=0 limit 1", mySQL); if(ds.HaveData()) { 收藏该文件ToolStripMenuItem.Text = "取消该文件收藏"; } else { 收藏该文件ToolStripMenuItem.Text = "收藏该文件"; } ds.Dispose(); } db.Free(); } private void 在资源管理器中定位该文件ToolStripMenuItem_Click(object sender, EventArgs e) { if(FilePath.Length > 0) { RyFiles.OpenFolderGotoFile(FilePath); } } private void 复制路径ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length == 0) { return; } RyFiles.CopyToClip(FilePath); } private void 复制文件名ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length == 0) { return; } RyFiles.CopyToClip(System.IO.Path.GetFileName(FilePath)); } private void 复制所在文件夹路径ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length == 0) { return; } RyFiles.CopyToClip(System.IO.Path.GetDirectoryName(FilePath)); } private void 文件信息ToolStripMenuItem_Click(object sender, EventArgs e) { FrmFileInfo frm = new FrmFileInfo(); frm.LoadInfo(FilePath,SiteInfo); frm.ShowDialog(); frm.Dispose(); } private void 打开其它站点文件ToolStripMenuItem_Click(object sender, EventArgs e) { if (SiteInfo.Id == 0) { return; } OnOpenOtherSiteFile?.Invoke(this, EventArgs.Empty); } private void 在工作区定位当前文件ToolStripMenuItem_Click(object sender, EventArgs e) { DockContentCollection contents = this.DockPanel.Contents; int num = 0; FrmFileBrowser_New first_visible=null; while (num < contents.Count) { var content = contents[num]; if (content.DockHandler.DockState == DockState.DockLeft) { if(content is FrmFileBrowser frm) { if (frm.Visible) { frm.GotoPath(FilePath); break; } else { num++; } } else if (content is FrmFileBrowser_New frm2) { if(this.SiteInfo.Name.IndexOfEx(frm2.Text)>=0 || frm2.Text.IndexOfEx(this.SiteInfo.Name)>=0) { frm2.Show(FrmMainEditor.MainEditor.dockPanel, DockState.DockLeft); //frm2.BringToFront(); frm2.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath); first_visible = null; break; } else if (frm2.Visible) { first_visible = frm2; //frm2.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath); //break; } num++; } else { num++; } } else { num++; } } if (first_visible != null) { first_visible.GotoPath(System.IO.Path.GetDirectoryName(FilePath), FilePath); } } private void 查看历史记录ToolStripMenuItem_Click(object sender, EventArgs e) { FrmHistoryView frm = new FrmHistoryView { FilePath = FilePath.Length==0?"[FTP:"+SiteInfo.FtpId+"]"+ FTPRemotePath : FilePath, Content = highlightEditor1.Text, CurHighliteLang = highlightEditor1.CurHighliteLang, SelectModeOn = true, TopMost = this.TopMost }; frm.FormClosed += delegate (object sender_item, FormClosedEventArgs e1) { if (frm.DialogResult == DialogResult.OK) { if (!this.IsDisposed) { if (IsChanged) { switch (MessageBox.Show("当前记录未保存,是否要替换成历史记录?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.No: frm.Dispose(); return; } Itrycn_Db.AddHistory(FilePath.Length == 0 ? "[FTP:" + SiteInfo.FtpId + "]" + FTPRemotePath : FilePath, highlightEditor1.Text); } IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.History_SQLConn) == 1) { DataSet ds = db.ReadData("select * from History where id=" + frm.SelectedItem.Id); if (ds.HaveData()) { highlightEditor1.Text = ds.GetFirstRowData()["content"].ToString(); } ds?.Dispose(); } db.Free(); } else { MessageBox.Show("窗口已经被关闭,无法加载历史记录。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }; frm.Show(); } private void Frm_FormClosed(object sender, FormClosedEventArgs e) { throw new NotImplementedException(); } private void 关闭左边全部标签ToolStripMenuItem_Click(object sender, EventArgs e) { switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { case DialogResult.Cancel: return; } DockContentCollection contents = this.DockPanel.Contents; int num = 0; while (num < contents.Count) { var content = contents[num]; if (content == this) { break; } if (content.DockHandler.DockState == DockState.Document) { var canClose = true; if (content is FrmFileEditor frm) { if (frm.IsChanged) { switch (MessageBox.Show("是否要保存文档?\r\n" + frm.FilePath + "\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.Cancel: canClose = false; break; case DialogResult.No: break; case DialogResult.Yes: if (frm.Save() != 1) { canClose = false; } break; } } } if (canClose) { content.DockHandler.Close(); } else { num++; } } else { num++; } } } private void 关闭右边全部标签ToolStripMenuItem_Click(object sender, EventArgs e) { switch (MessageBox.Show("是否确定要关闭?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { case DialogResult.Cancel: return; } DockContentCollection contents = this.DockPanel.Contents; int num = 0; var start = false; while (num < contents.Count) { var content = contents[num]; if (content == this) { start = true; num++; continue; } if (content.DockHandler.DockState == DockState.Document && start) { var canClose = true; if (content is FrmFileEditor frm) { if (frm.IsChanged) { switch (MessageBox.Show("是否要保存文档?\r\n" + frm.FilePath + "\r\n\r\n是:保存该文档并关闭。\r\n否:不保存该文档并关闭。\r\n取消:取消关闭该文档。", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.Cancel: canClose = false; break; case DialogResult.No: break; case DialogResult.Yes: if (frm.Save() != 1) { canClose = false; } break; } } } if (canClose) { content.DockHandler.Close(); } else { num++; } } else { num++; } } } private void 编辑FTP上的对应文件ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length > 0) _ = FrmMainEditor.MainEditor.OpenFTPFileByNewForm(SiteInfo, RemotePath); } private void 比对FTP上的对应文件ToolStripMenuItem_Click(object sender, EventArgs e) { if (FilePath.Length > 0) FrmMainEditor.MainEditor.CompareFTPFile(SiteInfo, RemotePath,this); } private void 比对文本1ToolStripMenuItem_Click(object sender, EventArgs e) { FrmMainEditor.MainEditor.CompareText1 = highlightEditor1.Text; FrmMainEditor.MainEditor.CompareTitle1 = this.Text; if (FrmMainEditor.MainEditor.CompareText2.Length>0) { FrmCompare frm2 = new FrmCompare { CurHighliteLang = highlightEditor1.CurHighliteLang, TextLeft = FrmMainEditor.MainEditor.CompareText1, TextRight = FrmMainEditor.MainEditor.CompareText2, TitleLeft = FrmMainEditor.MainEditor.CompareTitle1, TitleRight = FrmMainEditor.MainEditor.CompareTitle2 }; frm2.ShowDialog(FrmMainEditor.MainEditor); frm2.Dispose(); } } private void 比对文本2ToolStripMenuItem_Click(object sender, EventArgs e) { FrmMainEditor.MainEditor.CompareText2 = highlightEditor1.Text; FrmMainEditor.MainEditor.CompareTitle2 = this.Text; if (FrmMainEditor.MainEditor.CompareText1.Length > 0) { FrmCompare frm2 = new FrmCompare { CurHighliteLang = highlightEditor1.CurHighliteLang, TextLeft = FrmMainEditor.MainEditor.CompareText1, TextRight = FrmMainEditor.MainEditor.CompareText2, TitleLeft = FrmMainEditor.MainEditor.CompareTitle1, TitleRight = FrmMainEditor.MainEditor.CompareTitle2 }; frm2.ShowDialog(FrmMainEditor.MainEditor); frm2.Dispose(); } } } }