------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
155 lines
5.9 KiB
C#
155 lines
5.9 KiB
C#
using ryCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ryControls
|
|
{
|
|
public partial class ContextMenuStripHighlightText2 : ContextMenuStrip
|
|
{
|
|
public ContextMenuStripHighlightText2()
|
|
{
|
|
InitializeComponent();
|
|
AddMenu("撤销", "undo").Click += Undo_Click;
|
|
AddMenu("重做", "redo").Click += Redo_Click;
|
|
AddSeparatorMenu();
|
|
AddMenu("剪切", "cut").Click += Cut_Click;
|
|
AddMenu("复制", "copy").Click += Copy_Click;
|
|
AddMenu("粘贴", "paste").Click += Paste_Click;
|
|
AddMenu("删除", "del").Click += Del_Click;
|
|
AddMenu("全选", "selectall").Click += SelectAll_Click;
|
|
AddMenu("查找", "find").Click += Find_Click;
|
|
AddSeparatorMenu();
|
|
AddMenu("用百度搜索选中内容", "bdsearch").Click += BDSearch_Click;
|
|
}
|
|
private void BDSearch_Click(object sender, EventArgs e)
|
|
{
|
|
if (base.SourceControl is ScintillaNET.Scintilla editor)
|
|
{
|
|
RyFiles.OpenUrl("https://www.baidu.com/s?wd=" +RyWeb.WebDecode.UrlEncode(editor.SelectedText));
|
|
}
|
|
}
|
|
private void Find_Click(object sender, EventArgs e)
|
|
{
|
|
if(base.SourceControl is ScintillaNET.Scintilla editor)
|
|
{
|
|
if(editor.Parent is HighlightEditor rich_txt)
|
|
{
|
|
rich_txt.ShowFind();
|
|
}
|
|
}
|
|
}
|
|
private void SelectAll_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.SelectAll();
|
|
//Thread th = new Thread(sendkey);
|
|
//th.Start();
|
|
//void sendkey()
|
|
//{
|
|
// Thread.Sleep(100);
|
|
// this.Invoke(new Action(() =>
|
|
// {
|
|
// SendKeys.SendWait("^a");
|
|
// }));
|
|
//}
|
|
}
|
|
private void Undo_Click(object sender, EventArgs e)
|
|
{
|
|
if(!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.Undo();
|
|
}
|
|
private void Redo_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.Redo();
|
|
}
|
|
private void Cut_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.Cut();
|
|
}
|
|
private void Copy_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
//var ss = rich_txt.SelectedText;
|
|
rich_txt.Copy();
|
|
}
|
|
private void Paste_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.Paste();
|
|
}
|
|
private void Del_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
rich_txt.DeleteRange(rich_txt.SelectionStart,rich_txt.SelectedText.Length);
|
|
}
|
|
public ToolStripSeparator AddSeparatorMenu()
|
|
{
|
|
ToolStripSeparator item = new ToolStripSeparator();
|
|
base.Items.Add(item);
|
|
return item;
|
|
}
|
|
public ToolStripMenuItem AddMenu(string name, string tag)
|
|
{
|
|
ToolStripMenuItem item = new ToolStripMenuItem(name)
|
|
{
|
|
Tag = tag
|
|
};
|
|
base.Items.Add(item);
|
|
return item;
|
|
}
|
|
|
|
private void ContextMenuStripRichText_Opening(object sender, CancelEventArgs e)
|
|
{
|
|
if (!(base.SourceControl is ScintillaNET.Scintilla)) { return; }
|
|
var rich_txt = (ScintillaNET.Scintilla)base.SourceControl;
|
|
for (int i = 0; i < base.Items.Count; i++)
|
|
{
|
|
var item = base.Items[i];
|
|
if (item.Tag == null) { continue; }
|
|
switch(item.Tag.ToString())
|
|
{
|
|
case "undo":
|
|
item.Enabled = rich_txt.CanUndo && !rich_txt.ReadOnly;
|
|
break;
|
|
case "redo":
|
|
item.Enabled = rich_txt.CanRedo && !rich_txt.ReadOnly;
|
|
break;
|
|
case "cut":
|
|
item.Enabled = (rich_txt.SelectedText != "" && !rich_txt.ReadOnly);
|
|
break;
|
|
case "copy":
|
|
item.Enabled = rich_txt.SelectedText != "";
|
|
break;
|
|
case "paste":
|
|
item.Enabled = !rich_txt.ReadOnly;
|
|
break;
|
|
case "del":
|
|
item.Enabled =(rich_txt.SelectedText != "" && !rich_txt.ReadOnly);
|
|
break;
|
|
case "bdsearch":
|
|
item.Enabled = (rich_txt.SelectedText != "" && rich_txt.SelectedText.IndexOfEx("\n")<0 && rich_txt.SelectedText.Length<50);
|
|
break;
|
|
case "selectall":
|
|
item.Enabled = rich_txt.SelectedText != rich_txt.Text;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|