------ #### SuperDesign V3.0.2412.2002 - *.[新增]新增对.NET5以上项目文件的版本修改支持。 - *.[新增]新增支持双击历史更新记录,查看具体更新日志。 - *.[新增]更新日志新增对项目中文名称的设置和显示。 - *.[改进]当窗口失去焦点时,自动保存更新日志。 - *.[改进]对于同个项目,只允许打开一个实例的开发辅助工具。
1941 lines
83 KiB
C#
1941 lines
83 KiB
C#
using AutocompleteMenuNS;
|
|
using GameBackup3H3.DbOp;
|
|
using Jsbeautifier;
|
|
using MyDb;
|
|
using MyPage;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using ObjectListViewDemo;
|
|
using ryCommon;
|
|
using ryCommonDb;
|
|
using ryControls;
|
|
using ScintillaNET;
|
|
using ScintillaNET_FindReplaceDialog;
|
|
using SuperDesign.Manager.FTP;
|
|
using SuperDesign.Manager.Site;
|
|
using SuperDesign.Tools.SmartEditor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using VPKSoft.ScintillaLexers;
|
|
using WeifenLuo.WinFormsUI.Docking;
|
|
using WinSCP;
|
|
using 开发辅助工具.Manager;
|
|
using 开发辅助工具.Manager.FTP;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
|
|
|
namespace 开发辅助工具.Tools.SmartEditor
|
|
{
|
|
public partial class FrmMainEditor : Form
|
|
{
|
|
public static FrmMainEditor MainEditor { get; private set; }
|
|
private readonly string _filepath = "";
|
|
public FrmMainEditor(string filepath)
|
|
{
|
|
InitializeComponent();
|
|
EnableVSRenderer(VisualStudioToolStripExtender.VsVersion.Vs2015, vS2015BlueTheme1);
|
|
//DragManager = RyFiles.AddDropDrag(Handle);
|
|
//DragManager.ElevatedDragDrop += FrmMainEditor_ElevatedDragDrop;
|
|
Manager.Itrycn_Db.CreateDb();
|
|
_filepath = filepath;
|
|
MainEditor = this;
|
|
this.AllowDrop = true;
|
|
this.DragEnter += FrmMainEditor_DragEnter;
|
|
this.DragDrop += FrmMainEditor_DragDrop;
|
|
}
|
|
public DockPanel DockPanel
|
|
{
|
|
get
|
|
{
|
|
return this.dockPanel;
|
|
}
|
|
}
|
|
private void FrmMainEditor_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
|
if (s.Length == 1 && System.IO.Directory.Exists(s[0]))
|
|
{
|
|
var opens = Application.OpenForms;
|
|
for (int i = 0; i < opens.Count; i++)
|
|
{
|
|
if (opens[i] is FrmFileBrowser frm)
|
|
{
|
|
if (frm.DisplayRectangle.Contains(e.X, e.Y))
|
|
{
|
|
frm.Add(s[0]);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < s.Length; i++)
|
|
{
|
|
if (!System.IO.File.Exists(s[i])) { continue; }
|
|
OpenFile(s[i], s.Length == 1);
|
|
}
|
|
}
|
|
|
|
private void FrmMainEditor_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
{
|
|
e.Effect = DragDropEffects.All;
|
|
}
|
|
else
|
|
{
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
}
|
|
|
|
|
|
private void EnableVSRenderer(VisualStudioToolStripExtender.VsVersion version, ThemeBase theme)
|
|
{
|
|
vsToolStripExtender1.SetStyle(menuStrip1, version, theme);
|
|
vsToolStripExtender1.SetStyle(toolStrip1, version, theme);
|
|
vsToolStripExtender1.SetStyle(statusStrip1, version, theme);
|
|
}
|
|
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFile("");
|
|
}
|
|
|
|
private void DummyDoc_OnUnSaveChanged(object sender, EventArgs e)
|
|
{
|
|
var dummyDoc = (FrmFileEditor)sender;
|
|
dummyDoc.UpdateTitle();
|
|
EnabledBtn(dummyDoc);
|
|
}
|
|
private void EnabledBtn(FrmFileEditor frm)
|
|
{
|
|
var isChanged = frm != null && frm.IsChanged;
|
|
保存ToolStripMenuItem.Enabled = isChanged;
|
|
TsSave.Enabled = isChanged;
|
|
TsFTPUpload.Enabled = frm!=null && frm.SiteInfo.FtpId > 0;
|
|
上传当前文件ToolStripMenuItem.Enabled = frm != null && frm.SiteInfo.FtpId > 0;
|
|
上传所有站点当前位置文件ToolStripMenuItem.Enabled= frm != null && frm.SiteInfo.FtpId > 0;
|
|
重新读取ToolStripMenuItem.Enabled = frm != null && frm.FilePath.Length > 0;
|
|
查找与替换ToolStripMenuItem.Enabled = frm != null;
|
|
跳到指定行ToolStripMenuItem.Enabled = frm != null;
|
|
TsUndo.Enabled = frm != null && frm.highlightEditor1.Editor.CanUndo;
|
|
TsRedo.Enabled = frm != null && frm.highlightEditor1.Editor.CanRedo;
|
|
if (frm != null)
|
|
{
|
|
var lng = frm.highlightEditor1.CurHighliteLang;
|
|
for (int m = 0; m < 语言ToolStripMenuItem.DropDownItems.Count; m++)
|
|
{
|
|
var item = (ToolStripMenuItem)语言ToolStripMenuItem.DropDownItems[m];
|
|
Tuple<LexerEnumerations.LexerType, string,string> lng_item = (Tuple<LexerEnumerations.LexerType, string,string>)item.Tag;
|
|
item.Checked = lng_item.Item1 == lng;
|
|
if (!item.Enabled) { item.Enabled = true; }
|
|
}
|
|
SetEncoding(frm.Encoding);
|
|
}
|
|
else
|
|
{
|
|
for (int m = 0; m < 语言ToolStripMenuItem.DropDownItems.Count; m++)
|
|
{
|
|
var item = (ToolStripMenuItem)语言ToolStripMenuItem.DropDownItems[m];
|
|
item.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog
|
|
{
|
|
Filter = "常用格式|*.php;*.cs;*.txt;*.pas;*.js;*.html;*.htm;*.css;*.ini;*.json;*.xml;*.java;*.vbs;*.asp;*.aspx|所有文件|*.*"
|
|
};
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
OpenFile(dialog.FileName,true);
|
|
}
|
|
}
|
|
public FrmFileEditor OpenFile(string path,bool openOtherSite=false,bool GotoSameLoc=true,string FindText="")
|
|
{
|
|
if(path.Length==0)
|
|
{
|
|
FrmFileEditor dummyDoc_new = new FrmFileEditor
|
|
{
|
|
Text = "*新文档"
|
|
};
|
|
AddEvent(dummyDoc_new);
|
|
dummyDoc_new.Show(dockPanel);
|
|
SetEncoding(Encoding.UTF8);
|
|
return dummyDoc_new;
|
|
}
|
|
HighlightEditor high_editor = null;
|
|
if (GetActiveForm() is FrmFileEditor frm2)
|
|
{
|
|
high_editor = frm2.highlightEditor1;
|
|
}
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm)
|
|
{
|
|
if (frm.FilePath == path)
|
|
{
|
|
frm.Show(dockPanel);
|
|
if (GotoSameLoc)
|
|
{
|
|
if (high_editor != null)
|
|
{
|
|
if(frm.highlightEditor1.GotoSameLocation(high_editor)==0)
|
|
{
|
|
frm.highlightEditor1.FindText(FindText);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (FindText.Length > 0)
|
|
{
|
|
frm.highlightEditor1.FindText(FindText);
|
|
}
|
|
}
|
|
return frm;
|
|
}
|
|
}
|
|
}
|
|
FrmFileEditor dummyDoc = new FrmFileEditor();
|
|
AddEvent(dummyDoc);
|
|
dummyDoc.LoadFile(path);
|
|
if (!dummyDoc.IsDisposed)
|
|
{
|
|
dummyDoc.Show(dockPanel);
|
|
if (high_editor != null)
|
|
{
|
|
if(dummyDoc.highlightEditor1.GotoSameLocation(high_editor)==0)
|
|
{
|
|
dummyDoc.highlightEditor1.FindText(FindText);
|
|
}
|
|
}
|
|
if (openOtherSite && dummyDoc.SiteInfo.Id > 0)
|
|
{
|
|
OpenOtherSiteFile(dummyDoc.FilePath, dummyDoc.SiteInfo);
|
|
}
|
|
SetEncoding(dummyDoc.Encoding);
|
|
}
|
|
this.Focus();
|
|
return dummyDoc;
|
|
}
|
|
public int OpenFTPFileByNewForm(SiteInfo site, string remotePath)
|
|
{
|
|
if (site.FtpId <= 0) { return -2; }
|
|
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=" + site.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 = site.FtpDir,
|
|
UserName = row["username"].ToString(),
|
|
Pwd = row["pwd"].ToString(),
|
|
Encrypt = row["encrypt"].ToInt(0, 2, 0),
|
|
AddTime = row["AddTime"].ToDateTime()
|
|
};
|
|
if (site.Name.Length == 0)
|
|
{
|
|
site.Name = row["name"].ToString();
|
|
}
|
|
uploadinfo = new UploadInfo()
|
|
{
|
|
FtpInfo = FtpInfo,
|
|
RemotePath = remotePath,
|
|
LocalPath = Application.StartupPath + "\\UserDb\\tmp\\FTP\\" + System.IO.Path.GetFileName(remotePath)
|
|
};
|
|
}
|
|
ds.Dispose();
|
|
}
|
|
db.Free();
|
|
var result = -2;
|
|
if (uploadinfo == null) { return -1; }
|
|
RyFiles.DeleteFile(uploadinfo.LocalPath);
|
|
FrmDownProg frm = new FrmDownProg();
|
|
frm.DownList.Add(uploadinfo);
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
result = 1;
|
|
var ext = System.IO.Path.GetExtension(uploadinfo.LocalPath).ToLower();
|
|
if (";.bmp;.ico;.jpg;.gif;.png;.jpeg;.webp;.psd;.tga;.tif;.tiff;.wmf;".IndexOfEx(";" + ext + ";") >= 0)
|
|
{
|
|
RyFiles.OpenFile(uploadinfo.LocalPath);
|
|
}
|
|
else if (";.aac;.ac3;.aif;.aifc;.aiff;.ogg;.au;.cda;.dts;.fla;.flac;.it;.m1a;.m2a;.m3u;.m4a;.m4b;.m4p;.mid;.midi;.mka;.mp2;.mp3;.mpa;.ogg;.rmi;.snd;.spc;.umx;.voc;.wav;.wma;.xm;".IndexOfEx(";" + ext + ";") >= 0)
|
|
{
|
|
RyFiles.OpenFile(uploadinfo.LocalPath);
|
|
}
|
|
else if (";.3g2;.3gp;.3gp2;.3gpp;.amr;.amv;.asf;.avi;.bdmv;.bik;.d2v;.divx;.drc;.dsa;.dsm;.dss;.dsv;.evo;.f4v;.flc;.fli;.flic;.flv;.hdmov;.ifo;.ivf;.m1v;.m2p;.m2t;.m2ts;.m2v;.m4v;.mkv;.mp2v;.mp4;.mp4v;.mpe;.mpeg;.mpg;.mpls;.mpv2;.mpv4;.mov;.mts;.ogm;.ogv;.pss;.pva;.qt;.ram;.ratdvd;.rm;.rmm;.rmvb;.roq;.rpm;.smil;.smk;.swf;.tp;.tpr;.ts;.vob;.vp6;.webm;.wm;.wmp;.wmv;".IndexOfEx(";" + ext + ";") >= 0)
|
|
{
|
|
RyFiles.OpenFile(uploadinfo.LocalPath);
|
|
}
|
|
else if (";.xls;.xlsx;.ppt;.pptx;.doc;.docx;.et;.ett;.xlsm;.xltx;.xltm;.xlsb;.xlt;.dps;.dpt;.pps;.pot;.ppsx;.potx;.wps;.wpt;.dot;.dotx;.docm;.dotm;".IndexOfEx(";" + ext + ";") >= 0)
|
|
{
|
|
RyFiles.OpenFile(uploadinfo.LocalPath);
|
|
}
|
|
else
|
|
{
|
|
FrmFileEditor dummyDoc_new = new FrmFileEditor
|
|
{
|
|
FTPRemotePath = uploadinfo.RemotePath,
|
|
SiteInfo = site,
|
|
Encoding = TxtFileEncoder.GetEncoding(uploadinfo.LocalPath, Encoding.GetEncoding("GB2312")),
|
|
//dummyDoc_new.Text = "[FTP]"+ System.IO.Path.GetFileName(uploadinfo.RemotePath);
|
|
Icon = ShellUtilities.GetFileIcon(uploadinfo.LocalPath, true, true)
|
|
};
|
|
var content = RyFiles.ReadAllText(uploadinfo.LocalPath, dummyDoc_new.Encoding);
|
|
dummyDoc_new.highlightEditor1.SetHightlightText(content, System.IO.Path.GetFileName(uploadinfo.LocalPath));
|
|
if (content.Length > 0 && RyFiles.GetFileSize(uploadinfo.LocalPath) <= 1024 * 1024 * 10)
|
|
{
|
|
Itrycn_Db.AddHistory("[FTP:" + site.FtpId + "]" + uploadinfo.RemotePath, content);
|
|
}
|
|
RyFiles.DeleteFile(uploadinfo.LocalPath);
|
|
dummyDoc_new.IsChanged = false;
|
|
dummyDoc_new.UpdateTitle();
|
|
AddEvent(dummyDoc_new);
|
|
dummyDoc_new.Show(dockPanel);
|
|
SetEncoding(dummyDoc_new.Encoding);
|
|
}
|
|
}
|
|
frm.Dispose();
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 比对FTP文件
|
|
/// </summary>
|
|
/// <param name="site"></param>
|
|
/// <param name="remotePath"></param>
|
|
/// <param name="frm_editor"></param>
|
|
/// <returns></returns>
|
|
public int CompareFTPFile(SiteInfo site, string remotePath,FrmFileEditor frm_editor)
|
|
{
|
|
if (site.FtpId <= 0) { return -2; }
|
|
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=" + site.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 = site.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 = Application.StartupPath + "\\UserDb\\tmp\\FTP\\" + System.IO.Path.GetFileName(remotePath)
|
|
};
|
|
}
|
|
ds.Dispose();
|
|
}
|
|
db.Free();
|
|
var result = -2;
|
|
if (uploadinfo == null) { return -1; }
|
|
RyFiles.DeleteFile(uploadinfo.LocalPath);
|
|
FrmDownProg frm = new FrmDownProg();
|
|
frm.DownList.Add(uploadinfo);
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
result = 1;
|
|
FrmCompare frm2 = new FrmCompare
|
|
{
|
|
CurHighliteLang = frm_editor.highlightEditor1.CurHighliteLang,
|
|
TextLeft = frm_editor.highlightEditor1.Text,
|
|
TextRight = RyFiles.ReadAllText(uploadinfo.LocalPath),
|
|
TitleLeft = "本地文件",
|
|
TitleRight = "FTP文件"
|
|
};
|
|
frm2.ShowDialog();
|
|
frm2.Dispose();
|
|
RyFiles.DeleteFile(uploadinfo.LocalPath);
|
|
}
|
|
frm.Dispose();
|
|
return result;
|
|
}
|
|
void AddEvent(FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.UseCustomShowFindReplace = true;
|
|
frm.OnSaveKeyHappen += DummyDoc_OnSaveKeyHappen;
|
|
frm.OnUnSaveChanged += DummyDoc_OnUnSaveChanged;
|
|
frm.OnOpenOtherSiteFile += DummyDoc_OnOpenOtherSiteFile;
|
|
frm.FormClosing += DummyDoc_FormClosing;
|
|
frm.highlightEditor1.OnCustomShowFind += HighlightEditor1_OnCustomShowFind;
|
|
frm.highlightEditor1.Editor.UpdateUI += Editor_UpdateUI;
|
|
frm.highlightEditor1.TextChanged += Frm_TextChanged;
|
|
}
|
|
private void Editor_UpdateUI(object sender, UpdateUIEventArgs e)
|
|
{
|
|
if (sender is Scintilla editor)
|
|
{
|
|
TsRowCol.Text = "行:" +(editor.LineFromPosition(editor.SelectionStart)+1) +
|
|
" 列:" +(editor.GetColumn(editor.SelectionStart)+1);
|
|
}
|
|
}
|
|
|
|
private void Frm_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (sender is HighlightEditor editor)
|
|
{
|
|
TsUndo.Enabled = editor.Editor.CanUndo;
|
|
TsRedo.Enabled = editor.Editor.CanRedo;
|
|
}
|
|
}
|
|
|
|
private void HighlightEditor1_OnCustomShowFind(object sender, EventArgs e)
|
|
{
|
|
if(sender is HighlightEditor editor)
|
|
{
|
|
MyFindReplace.Scintilla = editor.Editor;
|
|
if(GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
if(frm.FilePath.Length>0)
|
|
{
|
|
MyFindReplace.SearchDir = System.IO.Path.GetDirectoryName(frm.FilePath);
|
|
}
|
|
}
|
|
MyFindReplace.ShowFind();
|
|
}
|
|
}
|
|
|
|
private void DummyDoc_OnOpenOtherSiteFile(object sender, EventArgs e)
|
|
{
|
|
var dummyDoc = (FrmFileEditor)sender;
|
|
if (dummyDoc.SiteInfo.Id == 0) { return; }
|
|
OpenOtherSiteFile(dummyDoc.FilePath, dummyDoc.SiteInfo, false);
|
|
}
|
|
|
|
public void OpenOtherSiteFile(string filepath, SiteInfo SiteInfo, bool slient = false)
|
|
{
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
DataSet ds = db.ReadData("select * from Site where id<>" + SiteInfo.Id);
|
|
var dict=new Dictionary<string, string>();
|
|
if (ds.HaveData())
|
|
{
|
|
var xd_path = filepath.Replace(SiteInfo.LocalPath, "", true).Trim('\\');
|
|
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))
|
|
{
|
|
dict.Add(reader["name"].ToString(), reader["localPath"].ToString() + "\\" + xd_path);
|
|
}
|
|
}
|
|
}
|
|
ds.Dispose();
|
|
if(slient)
|
|
{
|
|
foreach (var item in dict)
|
|
{
|
|
OpenFile(item.Value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dict.Count > 0)
|
|
{
|
|
List<SiteInfo> list = new List<SiteInfo>();
|
|
foreach (var item in dict)
|
|
{
|
|
list.Add(new SiteInfo() { Name = item.Key, LocalPath = item.Value });
|
|
}
|
|
FrmSiteSelect frm = new FrmSiteSelect
|
|
{
|
|
TopMost = this.TopMost,
|
|
Icon = Icon
|
|
};
|
|
frm.objectListView1.AddObjects(list);
|
|
frm.objectListView1.CheckAll();
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
for (int i = 0; i < frm.SelectedList.Count; i++)
|
|
{
|
|
var item = (SiteInfo)frm.SelectedList[i];
|
|
OpenFile(item.LocalPath);
|
|
}
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
}
|
|
}
|
|
db.Free();
|
|
}
|
|
private void DummyDoc_OnSaveKeyHappen(object sender, EventArgs e)
|
|
{
|
|
if(Itrycn_Db.WinSCP_IsRunning())
|
|
{
|
|
MessageBox.Show("存在外部FTP软件运行,部分保存功能受限。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
var dummyDoc = (FrmFileEditor)sender;
|
|
dummyDoc.Save();
|
|
}
|
|
private DialogResult ShowSaveMsg(string title)
|
|
{
|
|
FrmSaveMsg frm = new FrmSaveMsg();
|
|
frm.labelTx1.Text = title;
|
|
var result = frm.ShowDialog();
|
|
frm.Dispose();
|
|
return result;
|
|
}
|
|
private void DummyDoc_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
var dummyDoc = (FrmFileEditor)sender;
|
|
if(dummyDoc.IsChanged && e.CloseReason== CloseReason.UserClosing)
|
|
{
|
|
switch (ShowSaveMsg("是否要保存后关闭?"))
|
|
{
|
|
case DialogResult.Cancel:
|
|
e.Cancel = true;
|
|
break;
|
|
case DialogResult.No:
|
|
break;
|
|
case DialogResult.Yes:
|
|
if(dummyDoc.Save()!=1)
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
break;
|
|
default:
|
|
e.Cancel = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private Form GetActiveForm()
|
|
{
|
|
if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
|
|
return ActiveMdiChild;
|
|
else if (dockPanel.ActiveDocument != null)
|
|
return (Form)dockPanel.ActiveDocument;
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 更新列表中的文件信息
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
public void UpdateFileState(string path) {
|
|
foreach (IDockContent document in dockPanel.Contents) {
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileBrowser frm) {
|
|
frm.UpdateFileInfo(path);
|
|
}
|
|
else if (document is FrmFileBrowser_New frm2) {
|
|
frm2.UpdateFileInfo(path);
|
|
}
|
|
else if (document is FrmFTPBrowser frm3) {
|
|
frm3.UpdateFileInfo();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 更新列表中的文件信息
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
public void UpdateFTPFileState(int FTPId, string ftp_path,DateTime LastWriteTime, long FileSize) {
|
|
foreach (IDockContent document in dockPanel.Contents) {
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFTPBrowser frm) {
|
|
if (FTPId == frm.FTPId) {
|
|
frm.UpdateFileInfo(ftp_path, LastWriteTime, FileSize);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if(GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Save();
|
|
ChangedTitle(frm);
|
|
}
|
|
}
|
|
private void ChangedTitle(FrmFileEditor frm)
|
|
{
|
|
if (frm == null) { Text = "文本智能编辑器V"+RySoft.VersionStr;return; }
|
|
var title = (frm.FilePath.Length > 0 ? frm.FilePath : "无");
|
|
if (frm.SiteInfo.Id > 0) { title = "[" + frm.SiteInfo.Name + "]" + title; }
|
|
Text = "文本智能编辑器V"+RySoft.VersionStr+"=>" + title;
|
|
}
|
|
private void 保存全部ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm)
|
|
{
|
|
if (frm.IsChanged)
|
|
{
|
|
frm.Save();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
SaveFileDialog dialog = new SaveFileDialog
|
|
{
|
|
FileName = frm.FilePath.Length == 0 ? "" : System.IO.Path.GetFileName(frm.FilePath),
|
|
Filter = "常用格式|*.php;*.cs;*.txt;*.pas;*.js;*.html;*.htm;*.css;*.ini;*.json;*.xml;*.java;*.vbs;*.asp;*.aspx|所有文件|*.*"
|
|
};
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
frm.Save(dialog.FileName);
|
|
frm.LoadFile(dialog.FileName);
|
|
if (!frm.IsDisposed)
|
|
{
|
|
SetEncoding(frm.Encoding);
|
|
ChangedTitle(frm);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void 重新读取ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
if (frm.IsChanged)
|
|
{
|
|
switch (MessageBox.Show("当前文档已经修改,是否要重新读取文件?这将导致已修改的内容丢失。", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
|
|
{
|
|
case DialogResult.No:
|
|
return;
|
|
}
|
|
}
|
|
frm.LoadFile(frm.FilePath);
|
|
SetEncoding(frm.Encoding);
|
|
}
|
|
}
|
|
|
|
private void 删除重复行ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.DeleteRepeatLine() ;
|
|
}
|
|
}
|
|
|
|
private void 删除空白行ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.DeleteWhiteLine();
|
|
}
|
|
}
|
|
|
|
#region 文件编码
|
|
private void SetEncoding(Encoding encoding)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = false;
|
|
使用UTF16BigToolStripMenuItem.Checked = false;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = false;
|
|
if (encoding == Encoding.BigEndianUnicode) { 使用UTF16BigToolStripMenuItem.Checked = true; }
|
|
else if (encoding == Encoding.UTF8) { 使用UTF8BOM编码ToolStripMenuItem.Checked = true; }
|
|
else if (encoding.EncodingName == Encoding.UTF8.EncodingName) { 使用UTF8编码ToolStripMenuItem.Checked = true; }
|
|
else if (encoding == Encoding.GetEncoding("GB2312")) { 使用ANSI编码ToolStripMenuItem.Checked = true; }
|
|
else if (encoding == Encoding.Unicode) { 使用UTF16LittleEndian编码ToolStripMenuItem.Checked = true; }
|
|
}
|
|
private void 使用ANSI编码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = true;
|
|
使用UTF8编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = false;
|
|
使用UTF16BigToolStripMenuItem.Checked = false;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = false;
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Encoding = Encoding.GetEncoding("GB2312");
|
|
}
|
|
}
|
|
|
|
private void 使用UTF8编码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8编码ToolStripMenuItem.Checked = true;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = false;
|
|
使用UTF16BigToolStripMenuItem.Checked = false;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = false;
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Encoding = new UTF8Encoding(false);
|
|
}
|
|
}
|
|
|
|
private void 使用UTF8BOM编码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = true;
|
|
使用UTF16BigToolStripMenuItem.Checked = false;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = false;
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Encoding = Encoding.UTF8;
|
|
}
|
|
}
|
|
|
|
private void 使用UTF16BigToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = false;
|
|
使用UTF16BigToolStripMenuItem.Checked = true;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = false;
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Encoding = Encoding.BigEndianUnicode;
|
|
}
|
|
}
|
|
|
|
private void 使用UTF16LittleEndian编码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
使用ANSI编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8编码ToolStripMenuItem.Checked = false;
|
|
使用UTF8BOM编码ToolStripMenuItem.Checked = false;
|
|
使用UTF16BigToolStripMenuItem.Checked = false;
|
|
使用UTF16LittleEndian编码ToolStripMenuItem.Checked = true;
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.Encoding = Encoding.Unicode;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void TsSaveAll_Click(object sender, EventArgs e)
|
|
{
|
|
保存全部ToolStripMenuItem.PerformClick();
|
|
}
|
|
|
|
private void TsSave_Click(object sender, EventArgs e)
|
|
{
|
|
保存ToolStripMenuItem.PerformClick();
|
|
}
|
|
|
|
private void TsOpen_Click(object sender, EventArgs e)
|
|
{
|
|
打开ToolStripMenuItem.PerformClick();
|
|
}
|
|
|
|
private void TsNew_Click(object sender, EventArgs e)
|
|
{
|
|
新建ToolStripMenuItem.PerformClick();
|
|
}
|
|
private bool msg_show = false;
|
|
private Form last_active_doc= null;
|
|
private bool ProcUse = false;
|
|
private void DockPanel_ActiveContentChanged(object sender, EventArgs e)
|
|
{
|
|
if (ProcUse) { return; }
|
|
var form = GetActiveForm();
|
|
if (dockPanel.ActiveContent is FrmFileBrowser_New frm_file)
|
|
{
|
|
if(frm_file.InitPath.Length>0)
|
|
{
|
|
frm_file.GotoPath(frm_file.InitPath,frm_file.Init_Selected_Path);
|
|
frm_file.InitPath = "";
|
|
frm_file.Init_Selected_Path = "";
|
|
}
|
|
}
|
|
if (form != last_active_doc)
|
|
{
|
|
last_active_doc = form;
|
|
if (last_active_doc is FrmFileEditor frm)
|
|
{
|
|
if (frm.InitFilePath.Length > 0)
|
|
{
|
|
frm.LoadFile(frm.InitFilePath, frm.InitCacheText);
|
|
frm.InitFilePath = "";
|
|
frm.InitCacheText = "";
|
|
frm.highlightEditor1.Editor.FirstVisibleLine = frm.FirstVisibleLine;
|
|
}
|
|
MyFindReplace.Scintilla = frm.highlightEditor1.Editor;
|
|
MyGoTo.Scintilla = frm.highlightEditor1.Editor;
|
|
ChangedTitle(frm);
|
|
EnabledBtn(frm);
|
|
TsFtpPath.Text = "FTP路径:" + (frm.SiteInfo.FtpId > 0 ? frm.RemotePath : "无");
|
|
if (frm.FilePath.Length > 0 && frm.Fileinfo_Changed_Tip)
|
|
{
|
|
var fileinfo_changed = false;
|
|
var filesize = RyFiles.GetFileSize(frm.FilePath);
|
|
if (filesize != frm.FileSize) { fileinfo_changed = true; }
|
|
else
|
|
{
|
|
var filedt = RyFiles.GetFileDate(frm.FilePath);
|
|
if (filedt.CreateTime.ToInt64() != frm.FileCreateTime || filedt.LastWriteTime.ToInt64() != frm.FileWriteTime) { fileinfo_changed = true; }
|
|
}
|
|
if (fileinfo_changed && !msg_show)
|
|
{
|
|
msg_show = true;
|
|
new Thread(Start).Start();
|
|
void Start()
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
switch (MessageBox.Show(this, "当前文件内容已经改变,是否要重新加载?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2))
|
|
{
|
|
case DialogResult.No:
|
|
frm.Fileinfo_Changed_Tip = false;
|
|
break;
|
|
case DialogResult.Yes:
|
|
if (frm.IsChanged)
|
|
{
|
|
Itrycn_Db.AddHistory(frm.FilePath, frm.highlightEditor1.Text);
|
|
}
|
|
frm.LoadFile(frm.FilePath);
|
|
Focus();
|
|
break;
|
|
}
|
|
}));
|
|
msg_show = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MyFindReplace.Scintilla = null;
|
|
MyGoTo.Scintilla = null;
|
|
ChangedTitle(null);
|
|
EnabledBtn(null);
|
|
TsRowCol.Text = "行:0" +
|
|
" 列:0";
|
|
TsFtpPath.Text = "FTP路径:无";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void TsFTPUpload_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
if(frm.IsChanged)
|
|
{
|
|
frm.Save();
|
|
}
|
|
if(Itrycn_Db.WinSCP_IsRunning()) {
|
|
MessageBox.Show("检测到外部FTP相关软件正在运行,上传出错。", "上传失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if(frm.UploadFTP()==1)
|
|
{
|
|
TsState.Text = "状态:["+DateTime.Now.ToString("HH:mm:ss")+"]FTP上传成功=>"+frm.FilePath;
|
|
TsState.ForeColor = Color.Black;
|
|
}
|
|
else
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]FTP上传失败=>" + frm.FilePath;
|
|
TsState.ForeColor = Color.Red;
|
|
}
|
|
}
|
|
}
|
|
private void FindNext(string text)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
var _scintilla = frm.highlightEditor1.Editor;
|
|
var startPos = _scintilla.CurrentPosition;
|
|
var endPos = _scintilla.TextLength;
|
|
_scintilla.TargetStart = startPos;
|
|
_scintilla.TargetEnd = endPos;
|
|
_scintilla.SearchFlags = SearchFlags.None;
|
|
int pos = _scintilla.SearchInTarget(text);
|
|
if (pos == -1)
|
|
{
|
|
if (startPos != 0)
|
|
{
|
|
_scintilla.TargetStart = 0;
|
|
_scintilla.TargetEnd = endPos;
|
|
_scintilla.SearchFlags = SearchFlags.None;
|
|
pos = _scintilla.SearchInTarget(text);
|
|
if (pos == -1)
|
|
{ return; }
|
|
}
|
|
return;
|
|
}
|
|
var r= new ScintillaNET_FindReplaceDialog.CharacterRange(_scintilla.TargetStart, _scintilla.TargetEnd);
|
|
if (r.CpMin != r.CpMax)
|
|
{
|
|
_scintilla.GotoPosition(r.CpMin);
|
|
_scintilla.SetSel(r.CpMin, r.CpMax);
|
|
}
|
|
}
|
|
}
|
|
private void TxtFind_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
FindNext(TxtFind.Text);
|
|
}
|
|
}
|
|
|
|
private void TsFind_Click(object sender, EventArgs e)
|
|
{
|
|
FindNext(TxtFind.Text);
|
|
}
|
|
|
|
private void FrmMainEditor_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
SaveState();
|
|
var unsave = false;
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm)
|
|
{
|
|
if (frm.IsChanged)
|
|
{
|
|
unsave = true; break;
|
|
}
|
|
}
|
|
}
|
|
if (unsave)
|
|
{
|
|
switch (ShowSaveMsg("还有未保存的文档,是否要保存后关闭?"))
|
|
{
|
|
case DialogResult.Cancel:
|
|
e.Cancel = true;
|
|
return;
|
|
case DialogResult.No:
|
|
break;
|
|
case DialogResult.Yes:
|
|
保存全部ToolStripMenuItem.PerformClick();
|
|
break;
|
|
default:
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
}
|
|
ProcUse = true;
|
|
QuickMsg.RyMemoryShare.DelMemory("SmartEditor");
|
|
//DragManager.ElevatedDragDrop -= FrmMainEditor_ElevatedDragDrop;
|
|
//DragManager.Remove();
|
|
}
|
|
|
|
private void TsFavView_Click(object sender, EventArgs e)
|
|
{
|
|
FrmFavView frm = new FrmFavView
|
|
{
|
|
SelectModeOn = true,
|
|
TopMost = this.TopMost
|
|
};
|
|
if (frm.ShowDialog()==DialogResult.OK)
|
|
{
|
|
OpenFile(frm.SelectedItem.FilePath,true,true,frm.SelectedItem.FindText);
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
#region FTP相关
|
|
private void 上传当前文件ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
TsFTPUpload.PerformClick();
|
|
}
|
|
|
|
private void 上传所有站点当前位置文件ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm2)
|
|
{
|
|
if (frm2.IsChanged && frm2.XDPath == frm.XDPath)
|
|
{
|
|
frm2.Save();
|
|
}
|
|
}
|
|
}
|
|
if (frm.UploadFTPByAllSite() == 1)
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]FTP上传到所有站点成功=>" + frm.XDPath;
|
|
TsState.ForeColor = Color.Black;
|
|
}
|
|
else
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]FTP上传到所有站点失败=>" + frm.XDPath;
|
|
TsState.ForeColor = Color.Red;
|
|
}
|
|
}
|
|
}
|
|
private void 上传全部FTP标签文件ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
List<UploadInfo> list = new List<UploadInfo>();
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm2)
|
|
{
|
|
if (frm2.IsChanged && frm2.SiteInfo.FtpId > 0)
|
|
{
|
|
frm2.Save();
|
|
}
|
|
if (frm2.SiteInfo.FtpId > 0)
|
|
{
|
|
list.Add(frm2.GetUploadInfo());
|
|
}
|
|
}
|
|
}
|
|
if (list.Count == 0)
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]无需上传";
|
|
TsState.ForeColor = Color.Black;
|
|
}
|
|
else
|
|
{
|
|
FrmUploadProg frm = new FrmUploadProg();
|
|
frm.UploadList.AddRange(list);
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]上传所有FTP标签成功";
|
|
TsState.ForeColor = Color.Black;
|
|
}
|
|
else
|
|
{
|
|
TsState.Text = "状态:[" + DateTime.Now.ToString("HH:mm:ss") + "]上传所有FTP标签失败";
|
|
TsState.ForeColor = Color.Red;
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
}
|
|
#endregion
|
|
private void ShowUI(bool changelocation=true)
|
|
{
|
|
this.WindowState = FormWindowState.Normal;
|
|
if (changelocation)
|
|
{
|
|
this.Top = (Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2;
|
|
this.Left = (Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2;
|
|
}
|
|
bool topmost = this.TopMost;
|
|
this.TopMost = true;
|
|
RyForm.BringToTop(Handle);
|
|
this.TopMost = topmost;
|
|
}
|
|
private const int WM_COPYDATA = 0x004A;
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
switch (m.Msg)
|
|
{
|
|
case 17189:
|
|
#region 显示窗体
|
|
switch (m.WParam.ToInt32())
|
|
{
|
|
case 100://
|
|
if ((int)m.LParam.ToInt32() == 100)
|
|
{
|
|
ShowUI();
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
break;
|
|
case WM_COPYDATA:
|
|
switch (m.WParam.ToInt32())
|
|
{
|
|
case 1666:
|
|
#region 打开文件
|
|
string str = ryConfig.MsgManager.GetMsg(m);
|
|
if(System.IO.File.Exists(str))
|
|
{
|
|
ShowUI(false);
|
|
OpenFile(str);
|
|
}
|
|
#endregion
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
base.WndProc(ref m);
|
|
}
|
|
private int GetSortOrderInt(System.Windows.Forms.SortOrder sortOrder)
|
|
{
|
|
if(sortOrder== System.Windows.Forms.SortOrder.None) { return 0; }
|
|
else if (sortOrder == System.Windows.Forms.SortOrder.Ascending) { return 1; }
|
|
else if (sortOrder == System.Windows.Forms.SortOrder.Descending) { return -1; }
|
|
return 0;
|
|
}
|
|
private System.Windows.Forms.SortOrder GetSortOrder(int sortOrder)
|
|
{
|
|
if (sortOrder ==0) { return System.Windows.Forms.SortOrder.None; }
|
|
else if (sortOrder == 1) { return System.Windows.Forms.SortOrder.Ascending; }
|
|
else if (sortOrder == -1) { return System.Windows.Forms.SortOrder.Descending; }
|
|
return System.Windows.Forms.SortOrder.None;
|
|
}
|
|
/// <summary>
|
|
/// 保存软件状态
|
|
/// </summary>
|
|
private void SaveState()
|
|
{
|
|
last_save = DateTime.Now;
|
|
JObject jo = new JObject();
|
|
var opens = Application.OpenForms;
|
|
JArray jarr_workarea = new JArray();
|
|
JArray jarr_editor = new JArray();
|
|
JArray jarr_ftp = new JArray();
|
|
for (int i = 0; i < opens.Count; i++)
|
|
{
|
|
if (opens[i] is FrmFileBrowser frm)
|
|
{
|
|
var selected_item = (MyFileSystemInfo)frm.treeListView.SelectedObject;
|
|
var jo_item = new JObject
|
|
{
|
|
{ "mode", "workarea" },
|
|
{ "text", frm.Text },
|
|
{ "selected_path", selected_item == null ? "" : selected_item.FullName },
|
|
{ "visible", frm.Visible }
|
|
};
|
|
for (int c = 0; c < frm.treeListView.AllColumns.Count; c++)
|
|
{
|
|
var column = frm.treeListView.AllColumns[c];
|
|
jo_item.Add(column.AspectName+"_width",column.Width);
|
|
jo_item.Add(column.AspectName + "_visible", column.IsVisible?1:0);
|
|
}
|
|
jarr_workarea.Add(jo_item);
|
|
}
|
|
else if (opens[i] is FrmFileBrowser_New frm_file) {
|
|
var selected_item = (MyFileSystemInfo)frm_file.olvFiles.SelectedObject;
|
|
var jo_item = new JObject
|
|
{
|
|
{ "mode", "file" },
|
|
{ "text", frm_file.Text },
|
|
{ "folder", frm_file.CurFolderPath },
|
|
{ "selected_path", selected_item == null ? "" : selected_item.FullName },
|
|
{ "visible", frm_file.Visible },
|
|
{ "SplitterDistance", frm_file.splitContainer1.SplitterDistance },
|
|
};
|
|
if (frm_file.olvFiles.PrimarySortColumn != null)
|
|
{
|
|
jo_item.Add("PrimarySortColumn", frm_file.olvFiles.PrimarySortColumn.AspectName);
|
|
jo_item.Add("PrimarySortOrder", GetSortOrderInt(frm_file.olvFiles.PrimarySortOrder));
|
|
}
|
|
if (frm_file.olvFiles.SecondarySortColumn != null)
|
|
{
|
|
jo_item.Add("SecondarySortColumn", frm_file.olvFiles.SecondarySortColumn.AspectName);
|
|
jo_item.Add("SecondarySortOrder", GetSortOrderInt(frm_file.olvFiles.SecondarySortOrder));
|
|
}
|
|
for (int c = 0; c < frm_file.olvFiles.AllColumns.Count; c++) {
|
|
var column = frm_file.olvFiles.AllColumns[c];
|
|
jo_item.Add(column.AspectName + "_width", column.Width);
|
|
jo_item.Add(column.AspectName + "_visible", column.IsVisible ? 1 : 0);
|
|
}
|
|
jarr_workarea.Add(jo_item);
|
|
}
|
|
else if (opens[i] is FrmFileEditor frm2)
|
|
{
|
|
if (frm2.FilePath.Length == 0) { continue; }
|
|
var jo_item = new JObject
|
|
{
|
|
{ "path", frm2.FilePath },
|
|
{ "text",frm2.IsChanged?frm2.highlightEditor1.Text:"" },
|
|
{ "file_editTime",RyFiles.GetFileDate(frm2.FilePath).LastWriteTime.ToInt64() },
|
|
{ "FirstVisibleLine", frm2.highlightEditor1.Editor.FirstVisibleLine },
|
|
};
|
|
jarr_editor.Add(jo_item);
|
|
}
|
|
else if (opens[i] is FrmFTPBrowser frm_ftp)
|
|
{
|
|
var jo_item = new JObject
|
|
{
|
|
{ "text", frm_ftp.Text },
|
|
{ "ftpid", frm_ftp.FTPId },
|
|
{ "cur_folder", frm_ftp.CurFolder },
|
|
{ "visible", frm_ftp.Visible },
|
|
};
|
|
if (frm_ftp.objectListView1.PrimarySortColumn != null)
|
|
{
|
|
jo_item.Add("PrimarySortColumn", frm_ftp.objectListView1.PrimarySortColumn.AspectName);
|
|
jo_item.Add("PrimarySortOrder", GetSortOrderInt(frm_ftp.objectListView1.PrimarySortOrder));
|
|
}
|
|
if (frm_ftp.objectListView1.SecondarySortColumn != null)
|
|
{
|
|
jo_item.Add("SecondarySortColumn", frm_ftp.objectListView1.SecondarySortColumn.AspectName);
|
|
jo_item.Add("SecondarySortOrder", GetSortOrderInt(frm_ftp.objectListView1.SecondarySortOrder));
|
|
}
|
|
for (int c = 0; c < frm_ftp.objectListView1.AllColumns.Count; c++)
|
|
{
|
|
var column = frm_ftp.objectListView1.AllColumns[c];
|
|
jo_item.Add(column.Tag + "_width", column.Width);
|
|
jo_item.Add(column.Tag + "_visible", column.IsVisible ? 1 : 0);
|
|
}
|
|
jarr_ftp.Add(jo_item);
|
|
}
|
|
}
|
|
jo.Add("workarea",jarr_workarea);
|
|
jo.Add("editor_area", jarr_editor);
|
|
jo.Add("ftp_area", jarr_ftp);
|
|
jo.Add("DockRightPortion", this.dockPanel.DockRightPortion);
|
|
jo.Add("DockLeftPortion", this.dockPanel.DockLeftPortion);
|
|
if (this.WindowState == FormWindowState.Normal)
|
|
{
|
|
jo.Add("width", this.Width);
|
|
jo.Add("height", this.Height);
|
|
jo.Add("top", this.Top);
|
|
jo.Add("left", this.Left);
|
|
}
|
|
else
|
|
{
|
|
jo.Add("width", this.RestoreBounds.Width);
|
|
jo.Add("height", this.RestoreBounds.Height);
|
|
jo.Add("top", this.RestoreBounds.Top);
|
|
jo.Add("left", this.RestoreBounds.Left);
|
|
}
|
|
jo.Add("topmost", this.TopMost);
|
|
if(GetActiveForm() is FrmFileEditor frm3)
|
|
{
|
|
jo.Add("selected_file", frm3.FilePath);
|
|
}
|
|
Itrycn_Db.SetSetting("EditorState",jo.ToString());
|
|
}
|
|
public void OpenFileList(List<string> list)
|
|
{
|
|
var list_exist = new Dictionary<string, int>();
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm_editor)
|
|
{
|
|
if(frm_editor.FilePath.Length>0)
|
|
list_exist[frm_editor.FilePath.ToLower()] = 1;
|
|
}
|
|
}
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (list_exist.ContainsKey(list[i].ToLower())) { continue; }
|
|
FrmFileEditor frm = new FrmFileEditor();
|
|
AddEvent(frm);
|
|
frm.LoadInitFile(list[i]);
|
|
if (!frm.IsDisposed)
|
|
{
|
|
frm.Show(dockPanel);
|
|
}
|
|
}
|
|
if (GetActiveForm() is FrmFileEditor frm_editor2)
|
|
{
|
|
if (frm_editor2.InitFilePath.Length > 0)
|
|
{
|
|
if (frm_editor2.LoadFile(frm_editor2.InitFilePath, frm_editor2.InitCacheText) == -1)
|
|
{
|
|
|
|
}
|
|
frm_editor2.InitFilePath = "";
|
|
frm_editor2.InitCacheText = "";
|
|
frm_editor2.highlightEditor1.Editor.FirstVisibleLine = frm_editor2.FirstVisibleLine;
|
|
}
|
|
}
|
|
}
|
|
string EditorState = "";
|
|
/// <summary>
|
|
/// 加载软件状态
|
|
/// </summary>
|
|
private int LoadState(bool OnlySetUISize=false)
|
|
{
|
|
try
|
|
{
|
|
if (EditorState.Length == 0)
|
|
{
|
|
EditorState = Itrycn_Db.GetSetting("EditorState", "");
|
|
}
|
|
if (EditorState.Length == 0) { return 0; }
|
|
JObject jo = EditorState.Length == 0 ? new JObject() : JObject.Parse(EditorState);
|
|
if (OnlySetUISize)
|
|
{
|
|
var width = jo["width"].ToInt();
|
|
var height = jo["height"].ToInt();
|
|
var top = jo["top"].ToInt();
|
|
var left = jo["left"].ToInt();
|
|
if (width <= 100) { width = 800; }
|
|
if (height < 100) { height = 500; }
|
|
var screen = Screen.FromPoint(MousePosition);
|
|
if (top < screen.WorkingArea.Top || top > screen.WorkingArea.Bottom)
|
|
{
|
|
top = screen.WorkingArea.Top + (screen.WorkingArea.Height - height) / 2;
|
|
}
|
|
if (left < screen.WorkingArea.Left || left > screen.WorkingArea.Right)
|
|
{
|
|
left = screen.WorkingArea.Left + (screen.WorkingArea.Width - width) / 2;
|
|
}
|
|
this.Location = new Point(left, top);
|
|
this.Size = new Size(width, height);
|
|
this.TopMost = jo["topmost"].ToBool();
|
|
}
|
|
if (!OnlySetUISize)
|
|
{
|
|
置顶显示ToolStripMenuItem.Checked = this.TopMost;
|
|
menuStrip1.Refresh();
|
|
toolStrip1.Refresh();
|
|
statusStrip1.Refresh();
|
|
//dockPanel.SuspendLayout();
|
|
this.SuspendLayout();
|
|
dockPanel.DockLeftPortion = jo["DockLeftPortion"].ToDouble(250);
|
|
dockPanel.DockRightPortion = jo["DockRightPortion"].ToDouble(300);
|
|
ProcUse = true;
|
|
if (jo["workarea"] != null)
|
|
{
|
|
JArray jarr_workarea = JArray.Parse(jo["workarea"].ToString());
|
|
Form def_form = null;
|
|
for (int i = 0; i < jarr_workarea.Count; i++)
|
|
{
|
|
var item = jarr_workarea[i];
|
|
var mode = item.GetJsonValue("mode", "");
|
|
if (mode == "file")
|
|
{
|
|
FrmFileBrowser_New frm = new FrmFileBrowser_New
|
|
{
|
|
Text = item["text"].ToString()
|
|
};
|
|
var PrimarySortColumn = item.GetJsonValue("PrimarySortColumn","");
|
|
var SecondarySortColumn = item.GetJsonValue("SecondarySortColumn", "");
|
|
for (int c = 0; c < frm.olvFiles.AllColumns.Count; c++)
|
|
{
|
|
var column = frm.olvFiles.AllColumns[c];
|
|
column.Width = item[column.AspectName + "_width"].ToInt(column.Width);
|
|
column.IsVisible = item[column.AspectName + "_visible"].ToInt(1) == 1;
|
|
if (column.AspectName == PrimarySortColumn)
|
|
{
|
|
frm.olvFiles.PrimarySortColumn = column;
|
|
frm.olvFiles.PrimarySortOrder = GetSortOrder(item["PrimarySortOrder"].ToInt());
|
|
}
|
|
else if (column.AspectName == SecondarySortColumn)
|
|
{
|
|
frm.olvFiles.SecondarySortColumn = column;
|
|
frm.olvFiles.SecondarySortOrder = GetSortOrder(item["SecondarySortOrder"].ToInt());
|
|
}
|
|
}
|
|
frm.olvFiles.RebuildColumns();
|
|
frm.Show(dockPanel, DockState.DockLeft);
|
|
frm.splitContainer1.SplitterDistance = item.GetJsonValue("SplitterDistance", "280").ToInt(22, 4000, 280);
|
|
frm.InitPath = item.GetJsonValue("folder", "");
|
|
frm.Init_Selected_Path = item.GetJsonValue("selected_path", "");
|
|
frm.CurFolderPath = item.GetJsonValue("folder", "");
|
|
//frm.GotoPath(item.GetValue("folder", ""), item.GetValue("selected_path", ""));
|
|
if (item["visible"].ToBool()) { def_form = frm; }
|
|
}
|
|
else
|
|
{
|
|
FrmFileBrowser frm = new FrmFileBrowser
|
|
{
|
|
Text = item["text"].ToString()
|
|
};
|
|
for (int c = 0; c < frm.treeListView.AllColumns.Count; c++)
|
|
{
|
|
var column = frm.treeListView.AllColumns[c];
|
|
column.Width = item[column.AspectName + "_width"].ToInt(column.Width);
|
|
column.IsVisible = item[column.AspectName + "_visible"].ToInt(1) == 1;
|
|
}
|
|
frm.treeListView.RebuildColumns();
|
|
frm.Show(dockPanel, DockState.DockLeft);
|
|
frm.GotoPath(item.GetJsonValue("selected_path", ""));
|
|
if (item["visible"].ToBool()) { def_form = frm; }
|
|
}
|
|
}
|
|
if (def_form != null)
|
|
{
|
|
var file_frm = (DockContent)def_form;
|
|
file_frm.Show(dockPanel, DockState.DockLeft);
|
|
if (file_frm is FrmFileBrowser_New frm1)
|
|
{
|
|
frm1.GotoPath(frm1.InitPath, frm1.Init_Selected_Path);
|
|
frm1.InitPath = "";
|
|
frm1.Init_Selected_Path = "";
|
|
}
|
|
}
|
|
}
|
|
if (jo["editor_area"] != null)
|
|
{
|
|
JArray jarr_editor = JArray.Parse(jo["editor_area"].ToString());
|
|
for (int i = 0; i < jarr_editor.Count; i++)
|
|
{
|
|
var item = jarr_editor[i];
|
|
FrmFileEditor frm = new FrmFileEditor();
|
|
AddEvent(frm);
|
|
var file_editTime = item["file_editTime"].ToInt64().ToDateTime();
|
|
if (file_editTime.ToInt64() == RyFiles.GetFileDate(item["path"].ToString()).LastWriteTime.ToInt64())
|
|
{
|
|
var text = item.GetJsonValue("text", "");
|
|
frm.LoadInitFile(item["path"].ToString(), text);
|
|
}
|
|
else
|
|
{
|
|
frm.LoadInitFile(item["path"].ToString());
|
|
}
|
|
frm.FirstVisibleLine = item["FirstVisibleLine"].ToInt();
|
|
if (!frm.IsDisposed)
|
|
{
|
|
frm.Show(dockPanel);
|
|
}
|
|
}
|
|
}
|
|
if (jo["ftp_area"] != null)
|
|
{
|
|
JArray jarr_ftp = JArray.Parse(jo["ftp_area"].ToString());
|
|
FrmFTPBrowser def_show = null;
|
|
for (int i = 0; i < jarr_ftp.Count; i++)
|
|
{
|
|
var item = jarr_ftp[i];
|
|
FrmFTPBrowser frm = new FrmFTPBrowser
|
|
{
|
|
Text = item["text"].ToString(),
|
|
FTPId = item["ftpid"].ToInt()
|
|
};
|
|
var PrimarySortColumn = item.GetJsonValue("PrimarySortColumn","");
|
|
var SecondarySortColumn = item.GetJsonValue("SecondarySortColumn","");
|
|
for (int c = 0; c < frm.objectListView1.AllColumns.Count; c++)
|
|
{
|
|
var column = frm.objectListView1.AllColumns[c];
|
|
var tag = column.Tag.ToString();
|
|
column.Width = item[tag + "_width"].ToInt(column.Width);
|
|
column.IsVisible = item[tag + "_visible"].ToInt(1) == 1;
|
|
if(tag == PrimarySortColumn)
|
|
{
|
|
frm.objectListView1.PrimarySortColumn = column;
|
|
frm.objectListView1.PrimarySortOrder = GetSortOrder(item["PrimarySortOrder"].ToInt());
|
|
}
|
|
else if (tag == SecondarySortColumn)
|
|
{
|
|
frm.objectListView1.SecondarySortColumn = column;
|
|
frm.objectListView1.SecondarySortOrder = GetSortOrder(item["SecondarySortOrder"].ToInt());
|
|
}
|
|
}
|
|
frm.objectListView1.RebuildColumns();
|
|
if (!frm.IsDisposed)
|
|
frm.Show(dockPanel, DockState.DockRight);
|
|
frm.InitByNoFiles(item["cur_folder"].ToString());
|
|
if (item["visible"].ToBool()) { def_show = frm; }
|
|
}
|
|
def_show?.Show(dockPanel, DockState.DockRight);
|
|
}
|
|
ProcUse = false;
|
|
if (jo["selected_file"] != null)
|
|
{
|
|
var path = jo["selected_file"].ToString();
|
|
var result = -1;
|
|
foreach (IDockContent document in dockPanel.DocumentsToArray())
|
|
{
|
|
// IMPORANT: dispose all panes.
|
|
if (document is FrmFileEditor frm)
|
|
{
|
|
if (frm.FilePath == path)
|
|
{
|
|
frm.Show();
|
|
if (frm.InitFilePath.Length > 0)
|
|
{
|
|
if (frm.LoadFile(frm.InitFilePath, frm.InitCacheText) == 1)
|
|
{
|
|
result = 1;
|
|
}
|
|
frm.InitFilePath = "";
|
|
frm.InitCacheText = "";
|
|
frm.highlightEditor1.Editor.FirstVisibleLine = frm.FirstVisibleLine;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (result == -1)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm_editor)
|
|
{
|
|
if (frm_editor.InitFilePath.Length > 0)
|
|
{
|
|
if (frm_editor.LoadFile(frm_editor.InitFilePath, frm_editor.InitCacheText) == -1)
|
|
{
|
|
result = -1;
|
|
}
|
|
frm_editor.InitFilePath = "";
|
|
frm_editor.InitCacheText = "";
|
|
frm_editor.highlightEditor1.Editor.FirstVisibleLine = frm_editor.FirstVisibleLine;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//dockPanel.ResumeLayout(true);
|
|
this.ResumeLayout(true);
|
|
}
|
|
return 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
dockPanel.ResumeLayout(true);
|
|
this.ResumeLayout(true);
|
|
MessageBox.Show(ex.Message, "状态加载失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return 0;
|
|
}
|
|
}
|
|
readonly GoTo MyGoTo = new GoTo();
|
|
private void 跳到指定行ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
MyGoTo.Scintilla = frm.highlightEditor1.Editor;
|
|
MyGoTo.ShowGoToDialog();
|
|
}
|
|
}
|
|
|
|
readonly FindReplace MyFindReplace = new FindReplace();
|
|
private void 查找与替换ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
MyFindReplace.Scintilla=frm.highlightEditor1.Editor;
|
|
MyFindReplace.SearchDir = System.IO.Path.GetDirectoryName(frm.FilePath);
|
|
MyFindReplace.ShowFind();
|
|
}
|
|
}
|
|
|
|
private void TsUndo_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.Editor.Undo();
|
|
TsUndo.Enabled = frm.highlightEditor1.Editor.CanUndo;
|
|
TsRedo.Enabled = frm.highlightEditor1.Editor.CanRedo;
|
|
}
|
|
}
|
|
|
|
private void TsRedo_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.Editor.Redo();
|
|
TsUndo.Enabled = frm.highlightEditor1.Editor.CanUndo;
|
|
TsRedo.Enabled = frm.highlightEditor1.Editor.CanRedo;
|
|
}
|
|
}
|
|
|
|
private void 转换为小写ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText= frm.highlightEditor1.SelectedText.ToLower();
|
|
}
|
|
}
|
|
|
|
private void 转换为大写ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText = frm.highlightEditor1.SelectedText.ToUpper();
|
|
}
|
|
}
|
|
|
|
private void 注释选定行ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
var editor = frm.highlightEditor1.Editor;
|
|
switch (editor.LexerName)
|
|
{
|
|
case "phpscript":
|
|
case "cpp":
|
|
for (int i = 0; i < editor.Selections.Count; i++)
|
|
{
|
|
var item = editor.Selections[i];
|
|
var selStartLine=editor.LineFromPosition(item.Start);
|
|
var selEndLine= editor.LineFromPosition(item.End);
|
|
for (int r = selStartLine; r <= selEndLine; r++)
|
|
{
|
|
if (editor.Lines[r].Text.Trim().IndexOfEx("//") == 0) { continue; }
|
|
var pos = editor.Lines[r].Text.IndexOfEx(editor.Lines[r].Text.Trim());
|
|
editor.InsertText(editor.Lines[r].Position+ pos, "//");
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
MessageBox.Show("暂不支持当前语言注释。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void 取消选定行注释ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
var editor = frm.highlightEditor1.Editor;
|
|
switch (editor.LexerName)
|
|
{
|
|
case "phpscript":
|
|
case "cpp":
|
|
for (int i = 0; i < editor.Selections.Count; i++)
|
|
{
|
|
var item = editor.Selections[i];
|
|
var selStartLine = editor.LineFromPosition(item.Start);
|
|
var selEndLine = editor.LineFromPosition(item.End);
|
|
for (int r = selStartLine; r <= selEndLine; r++)
|
|
{
|
|
if (editor.Lines[r].Text.Trim().IndexOfEx("//") == 0) {
|
|
editor.DeleteRange(editor.Lines[r].Position+ editor.Lines[r].Text.IndexOfEx("//"), 2);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
MessageBox.Show("暂不支持当前语言取消注释。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void 替换ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
MyFindReplace.Scintilla = frm.highlightEditor1.Editor;
|
|
if (frm.FilePath.Length > 0)
|
|
{
|
|
MyFindReplace.SearchDir = System.IO.Path.GetDirectoryName(frm.FilePath);
|
|
}
|
|
MyFindReplace.ShowFind(1);
|
|
}
|
|
}
|
|
|
|
private void Base64编码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
Strings strings = new Strings();
|
|
frm.highlightEditor1.SelectedText = strings.StrToBase64(frm.highlightEditor1.SelectedText);
|
|
}
|
|
}
|
|
|
|
private void Base64解码ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
Strings strings = new Strings();
|
|
frm.highlightEditor1.SelectedText = strings.Base64ToStr(frm.highlightEditor1.SelectedText);
|
|
}
|
|
}
|
|
|
|
private void UrlEncodeToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText = RyWeb.WebDecode.UrlEncode(frm.highlightEditor1.SelectedText);
|
|
}
|
|
}
|
|
|
|
private void UrlDecodeUTF8ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText = RyWeb.WebDecode.UrlDecode(frm.highlightEditor1.SelectedText);
|
|
}
|
|
}
|
|
|
|
private void UrlEncodeGB2312ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText = RyWeb.WebDecode.UrlEncode(frm.highlightEditor1.SelectedText,Encoding.GetEncoding("GB2312"));
|
|
}
|
|
}
|
|
|
|
private void UrlDecodeGB2312ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
frm.highlightEditor1.SelectedText = RyWeb.WebDecode.UrlDecode(frm.highlightEditor1.SelectedText, Encoding.GetEncoding("GB2312"));
|
|
}
|
|
}
|
|
|
|
private void 文件浏览窗口ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var index = 0;
|
|
var opens = Application.OpenForms;
|
|
for (int i = 0; i < opens.Count; i++)
|
|
{
|
|
if (opens[i] is FrmFileBrowser)
|
|
{
|
|
index++;
|
|
}
|
|
}
|
|
FrmFileBrowser frm = new FrmFileBrowser
|
|
{
|
|
Text = "工作区" + (index == 0 ? "" : index.ToString())
|
|
};
|
|
frm.Show(dockPanel, DockState.DockLeft);
|
|
}
|
|
|
|
private void 置顶显示ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
置顶显示ToolStripMenuItem.Checked = !置顶显示ToolStripMenuItem.Checked;
|
|
this.TopMost = 置顶显示ToolStripMenuItem.Checked;
|
|
}
|
|
|
|
private void FTP浏览器ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
List<FTPInfo> list = new List<FTPInfo>();
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
DataSet ds = db.ReadData("select * from Ftp");
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
{
|
|
DataRow row = ds.Tables[0].Rows[i];
|
|
list.Add(new FTPInfo()
|
|
{
|
|
Id = row["id"].ToInt(),
|
|
Name = row["name"].ToString(),
|
|
IP = row["ip"].ToString(),
|
|
Port = row["port"].ToInt(),
|
|
RemoteDir = row["remoteDir"].ToString(),
|
|
UserName = row["username"].ToString(),
|
|
Pwd = row["pwd"].ToString(),
|
|
Encrypt = row["encrypt"].ToInt(0, 2, 0),
|
|
AddTime = row["AddTime"].ToDateTime()
|
|
});
|
|
}
|
|
}
|
|
db.Free();
|
|
FrmFTPSelect frm = new FrmFTPSelect
|
|
{
|
|
Icon = Icon
|
|
};
|
|
frm.objectListView1.AddObjects(list);
|
|
if (frm.ShowDialog()==DialogResult.OK)
|
|
{
|
|
FrmFTPBrowser frm2 = new FrmFTPBrowser
|
|
{
|
|
Text = frm.SelectedItem.Name,
|
|
FTPId=frm.SelectedItem.Id
|
|
};
|
|
frm2.Show(dockPanel, DockState.DockRight);
|
|
frm2.Init();
|
|
}
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void 在文件中查找ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
MyFindReplace.Scintilla = frm.highlightEditor1.Editor;
|
|
if (frm.FilePath.Length > 0)
|
|
{
|
|
MyFindReplace.SearchDir = System.IO.Path.GetDirectoryName(frm.FilePath);
|
|
}
|
|
MyFindReplace.ShowFind(2);
|
|
}
|
|
}
|
|
|
|
private void 文件关联ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
FrmSetting frm = new FrmSetting();
|
|
frm.tabControl1.SelectedTab = frm.tabPage2;
|
|
frm.ShowDialog();
|
|
frm.Dispose();
|
|
}
|
|
|
|
private void 站点设置ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
FrmSetting frm = new FrmSetting();
|
|
frm.tabControl1.SelectedTab = frm.tabPage4;
|
|
frm.ShowDialog();
|
|
frm.Dispose();
|
|
}
|
|
private DateTime last_save = DateTime.Now.AddSeconds(-50);
|
|
private void FrmMainEditor_Deactivate(object sender, EventArgs e)
|
|
{
|
|
if (last_save <= DateTime.Now.AddMinutes(-1))
|
|
{
|
|
SaveState();
|
|
}
|
|
}
|
|
|
|
private void 文件浏览器ToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
var index = 0;
|
|
var opens = Application.OpenForms;
|
|
for (int i = 0; i < opens.Count; i++) {
|
|
if (opens[i] is FrmFileBrowser_New) {
|
|
index++;
|
|
}
|
|
}
|
|
FrmFileBrowser_New frm = new FrmFileBrowser_New {
|
|
Text = "文件浏览" + (index == 0 ? "" : index.ToString())
|
|
};
|
|
frm.Show(dockPanel, DockState.DockLeft);
|
|
}
|
|
public string ConvertJsonString(string str)
|
|
{
|
|
//格式化json字符串
|
|
try
|
|
{
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
TextReader tr = new StringReader(str);
|
|
JsonTextReader jtr = new JsonTextReader(tr);
|
|
object obj = serializer.Deserialize(jtr);
|
|
if (obj != null)
|
|
{
|
|
StringWriter textWriter = new StringWriter();
|
|
JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
|
|
{
|
|
Formatting = Formatting.Indented,
|
|
Indentation = 4,
|
|
IndentChar = ' '
|
|
};
|
|
serializer.Serialize(jsonWriter, obj);
|
|
return textWriter.ToString();
|
|
}
|
|
else
|
|
{
|
|
return str;
|
|
}
|
|
}
|
|
catch { return str; }
|
|
}
|
|
private string ReplaceRegex(string input,string from,string to)
|
|
{
|
|
Regex regex = new Regex(from);
|
|
return regex.Replace(input, to);
|
|
}
|
|
private void 美化ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
if (frm.highlightEditor1.CurHighliteLang == LexerEnumerations.LexerType.JavaScript)
|
|
{
|
|
var beautifier = new Beautifier();
|
|
beautifier.Opts.IndentSize = 4;
|
|
beautifier.Opts.IndentChar = ' ';
|
|
beautifier.Opts.PreserveNewlines = true;
|
|
beautifier.Opts.JslintHappy = false;
|
|
beautifier.Opts.KeepArrayIndentation = false;
|
|
beautifier.Opts.BraceStyle = BraceStyle.Collapse;
|
|
beautifier.Flags.IndentationLevel = 0;
|
|
beautifier.Opts.BreakChainedMethods = true;
|
|
frm.highlightEditor1.Text = beautifier.Beautify(frm.highlightEditor1.Text);
|
|
frm.highlightEditor1.Editor.GotoPosition(0);
|
|
}
|
|
else if (frm.highlightEditor1.CurHighliteLang == LexerEnumerations.LexerType.Css)
|
|
{
|
|
//var beautifier = new Beautifier();
|
|
//beautifier.Opts.IndentSize = 4;
|
|
//beautifier.Opts.IndentChar = ' ';
|
|
//beautifier.Opts.PreserveNewlines = true;
|
|
//beautifier.Opts.JslintHappy = false;
|
|
//beautifier.Opts.KeepArrayIndentation = false;
|
|
//beautifier.Opts.BraceStyle = BraceStyle.Collapse;
|
|
//beautifier.Flags.IndentationLevel = 0;
|
|
//beautifier.Opts.BreakChainedMethods = true;
|
|
//frm.highlightEditor1.Text = beautifier.Beautify(frm.highlightEditor1.Text).Replace("}", "}\r\n").Replace("\r\n\r\n", "\r\n");
|
|
var input = frm.highlightEditor1.Text;
|
|
input = ReplaceRegex(input, "\\s*([{}:;,])\\s*", "$1");
|
|
input = ReplaceRegex(input, ";\\s*;", ";");
|
|
input = ReplaceRegex(input, ",[\\s\\.\\#\\d]*{", "{");
|
|
input = ReplaceRegex(input, "([^\\s])\\{([^\\s])", "$1 {\n\t$2");
|
|
input = ReplaceRegex(input, "([^\\s])\\}([^\\n]*)", "$1\n}\n$2");
|
|
input = ReplaceRegex(input, "([^\\s])\\;([^\\s}])", "$1;\n\t$2");
|
|
frm.highlightEditor1.Text = input;
|
|
frm.highlightEditor1.Editor.GotoPosition(0);
|
|
|
|
}
|
|
else if (frm.highlightEditor1.CurHighliteLang == LexerEnumerations.LexerType.Json)
|
|
{
|
|
frm.highlightEditor1.Text = ConvertJsonString(frm.highlightEditor1.Text);
|
|
frm.highlightEditor1.Editor.GotoPosition(0);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void FrmMainEditor_Shown(object sender, EventArgs e)
|
|
{
|
|
PnlLoad.Dock = DockStyle.Fill;
|
|
PnlLoad.Parent = this;
|
|
PnlLoad.Visible = true;
|
|
PnlLoad.BringToFront();
|
|
label1.BringToFront();
|
|
Application.DoEvents();
|
|
Text = "文本智能编辑器V" + RySoft.VersionStr;
|
|
var list = VPKSoft.ScintillaLexers.HelperClasses.LexerTypeName.LexerTypeNameList;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var item22 = list[i];
|
|
ToolStripMenuItem add_item = (ToolStripMenuItem)语言ToolStripMenuItem.DropDownItems.Add(list[i].Item3);
|
|
add_item.Tag = list[i];
|
|
add_item.Click += delegate (object s, EventArgs e1) {
|
|
if (GetActiveForm() is FrmFileEditor frm)
|
|
{
|
|
var item = (ToolStripMenuItem)s;
|
|
item.Checked = true;
|
|
Tuple<LexerEnumerations.LexerType, string, string> lng = (Tuple<LexerEnumerations.LexerType, string, string>)item.Tag;
|
|
ScintillaLexers.CreateLexer(frm.highlightEditor1.Editor, lng.Item1);
|
|
frm.highlightEditor1.CurHighliteLang = lng.Item1;
|
|
frm.highlightEditor1.Font = frm.highlightEditor1.Font;
|
|
for (int m = 0; m < 语言ToolStripMenuItem.DropDownItems.Count; m++)
|
|
{
|
|
var lng_item = (ToolStripMenuItem)语言ToolStripMenuItem.DropDownItems[m];
|
|
if (lng_item != item) { lng_item.Checked = false; }
|
|
}
|
|
}
|
|
};
|
|
}
|
|
QuickMsg.RyMemoryShare.WriteToMemory(this.Handle.ToInt64(), "SmartEditor");
|
|
if (LoadState() == 0)
|
|
{
|
|
FrmFileBrowser frm = new FrmFileBrowser();
|
|
frm.Show(dockPanel, DockState.DockLeft);
|
|
}
|
|
if (_filepath.Length > 0)
|
|
{
|
|
OpenFile(_filepath, false);
|
|
}
|
|
PnlLoad.Visible = false;
|
|
}
|
|
public string CompareTitle1 { get; set; } = "";
|
|
public string CompareText1 { get; set; } = "";
|
|
public string CompareTitle2 { get; set; } = "";
|
|
public string CompareText2 { get; set; } = "";
|
|
|
|
private void FrmMainEditor_Load(object sender, EventArgs e)
|
|
{
|
|
LoadState(true);
|
|
}
|
|
}
|
|
}
|