风行者写的一个范例搜索工具,功能挺好用的,运行后搜索界面集成到aardio IDE内部,会一直嵌入到范例列表上方。算是一种嵌入的风格。
我比较习惯直接点的,运行就弹出一个窗口界面直接操作。操作完了直接关闭窗口就OK了。
所以自己抽空写了一个,算是另一种风格。
代码如下:
其中使用了虚表组件,请到 http://chengxu.online 下载。
//📝 范例搜索 V1.0 【光庆】
//与风行者版本不同的另一种风格
import win.ui;
import godking.vlistEx
import fonts.fontAwesome;
/*DSG{{*/
var mainForm = win.form(text="范例搜索 By 光庆";right=1099;bottom=669)
mainForm.add(
checkbox={cls="checkbox";text="忽略大小写";left=290;top=630;right=390;bottom=650;db=1;dl=1;font=LOGFONT(h=-14);z=5};
custom={cls="custom";text="自定义控件";left=620;top=10;right=1090;bottom=600;db=1;dl=1;dr=1;dt=1;z=6};
keyword={cls="edit";left=10;top=630;right=280;bottom=653;border=1;db=1;dl=1;z=2};
search={cls="button";text='\uF002 搜索';left=400;top=620;right=620;bottom=660;db=1;dl=1;font=LOGFONT(name='FontAwesome');z=3};
static={cls="static";text="请输入要搜索的关键词,多个关键词用空格分开。双击搜索结果在IDE中打开。";left=10;top=600;right=610;bottom=620;center=1;color=8421376;db=1;dl=1;transparent=1;z=1};
vlistEx={cls="vlistEx";text="自定义控件";left=10;top=10;right=620;bottom=600;db=1;dl=1;dt=1;edge=1;z=4}
)
/*}}*/
import ide;
import web.form
var wb = web.form(mainForm.custom);
var cols ={ names={"📚","📄 范例名称","📂 文件路径"}, widths={30,150,-1} }
mainForm.vlistEx.setColumns(cols.names,cols.widths);
var lists = {};
var exp;
mainForm.vlistEx.onClick = function(row/*行*/,col/*列*/){
/*鼠标左键点击项目事件*/
if !#lists or !#exp or row<1 or row>#lists return ;
var file = lists[row][4];
mainForm.static.text = file;
import string.html
var html = ..string.load(file);
html = string.replace(html,'\t'," ");
var html = string.html.fromText(html);
for(i=1;#exp;1){
html = string.replace(html,"@"++exp[i],`<span style="background: yellow; color: red; font-size: 20px; font-weight: 700;" >`++exp[i]++"</span>")
}
html = ..string.fromto(`<body style="font: 13px arial;">`++html++"</body>",65001,0);
wb.html = html;
}
mainForm.vlistEx.onDblClick = function(row/*行*/,col/*列*/){
/*鼠标左键点击项目事件*/
if !#lists or !#exp or row<1 or row>#lists return ;
var path = lists[row][4];
if !ide.openDocument(path) return ;
mainForm.hitMin();
}
mainForm.search.oncommand = function(id,event){
lists = {};
mainForm.vlistEx.clear();
var ts = ..string.split(mainForm.keyword.text," ");
..table.removeByValue(ts,"",true);
exp = ts;
var func;
if mainForm.checkbox.checked {
for(i=1;#ts;1){
ts[i]="@@"++ts[i]
}
func = ..string.find
} else {
func = ..string.indexOf
}
if(#ts){
mainForm.search.disabled = true;
import fsys;
fsys.enum( "~\codes\范例程序\", "*.aardio",
function(dirname,filename,fullpath,findData){
if(filename){
var str = string.load(fullpath);
str = string.removeBom(str);
var find = true;
for(i=1;#ts;1){
if !func(filename,ts[i]) {
find = false;
break;
}
}
if find == false {
find = true;
for(i=1;#ts;1){
if !func(str,ts[i]) {
find = false;
break;
}
}
}
if find {
var title = ..string.match(str,"^//(.+?)\n"):io.splitpath(filename).name;
var t = string.split(fullpath,"<\范例程序\>",2);
t = ..string.replace(t[2],"\\"," ➜ ");
..table.push(lists,{"[@rowindex]",title,t,fullpath});
}
}
win.delay();
}
,true
);
mainForm.vlistEx.setTable(lists,cols.names,cols.widths,/*列格式或数组*/,/*字典转为数组*/,/*字符串转为Utf8*/);
mainForm.search.disabled = false ;
}
}
mainForm.keyword.onOk = function(){
mainForm.search.oncommand();
}
mainForm.show();
mainForm.keyword.setFocus();
win.loopMessage();