aardio_代码编辑框书签管理器开源,经常需要用到书签的群友快来体验吧.
//书签管理器
/********************************************************************
作者:简码编程
博客:www.jianma123.com
最后修改日期:2022.01.14
用法:
将此代码复制粘贴到aardio里新窗口,
保存为 aardio\tools\6.bookmark.aardio
重启aardio后在右侧工具页顶部可以看到"书签管理器",双击运行,右键编辑
所解决的问题:
设计视图和代码视图切换后书签自动丢失问题.
书签没能自动保存在工程里下次打开自动加载问题.
跳转书签在所有打开代码文档里跳转没能设置固定只在当前文档里跳转的问题.
********************************************************************/
import win.ui;
import web.json;
import fsys;
import ide;
import process;
import win.ui.menu;
/*DSG{{*/
var winform = win.form(text="书签管理器";right=599;bottom=771;bgcolor=15529196;border="none";exmode="toolwindow";topmost=1)
winform.add(
buttonAddBm={cls="button";text="添加书签";left=115;top=411;right=175;bottom=439;db=1;z=10};
buttonTest={cls="button";text="Test";left=479;top=412;right=539;bottom=440;db=1;z=6};
editLineNum={cls="edit";left=49;top=414;right=110;bottom=438;db=1;edge=1;num=1;z=8};
editLog={cls="edit";left=7;top=531;right=595;bottom=766;db=1;dl=1;dr=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=7};
listview={cls="listview";left=7;top=72;right=595;bottom=400;ah=1;aw=1;db=1;dl=1;dr=1;dt=1;edge=1;fullRow=1;gridLines=1;hscroll=1;msel=false;vscroll=1;z=3};
plusClose={cls="close";text="×";left=578;top=3;right=596;bottom=21;bgcolor=32896;border={radius=10};color=8421504;dr=1;dt=1;font=LOGFONT(h=-21);z=2};
plusMain={cls="plus";text="书签管理器";left=491;top=8;right=591;bottom=48;bgcolor=12639424;border={color=-16744320;radius=12};dr=1;dt=1;notify=1;z=1};
static3={cls="static";text="行号:";left=10;top=416;right=45;bottom=434;db=1;transparent=1;z=9};
staticActiveFileDir={cls="static";text="所在文件夹:";left=12;top=27;right=464;bottom=63;dl=1;dt=1;transparent=1;z=5};
staticActiveFileName={cls="static";text="活动文件名:";left=12;top=9;right=458;bottom=27;dl=1;dt=1;transparent=1;z=4};
staticSelFileDir={cls="static";text="选定行所在文件夹:";left=14;top=471;right=594;bottom=516;db=1;dl=1;transparent=1;z=12};
staticSelFileName={cls="static";text="选定行所在文件名:";left=14;top=453;right=592;bottom=471;db=1;dl=1;transparent=1;z=11}
)
/*}}*/
win.setPos(winform.hwnd,980,80);
import win.ui.shadow;
win.ui.shadow(winform);
winform.editLog.limit = 1000000;
winform.listview.insertColumn("行号",40);
winform.listview.insertColumn("行代码",250);
winform.listview.insertColumn("文件名",150);
winform.listview.insertColumn("所在文件夹",100);
winform.plusMain.skin( color = { hover = 0xE0008800; active = 0x60F00000; default = 0x90000000 ; } );
var leftMove = 0;
var menuHelp = win.ui.popmenu(winform);//创建弹出菜单
var showActiveDocInfo = function(){
//显示当前活动文档信息
var editor = ide.getActiveCodeEditor();
if(!editor){ return; }
var docPath = ide.getActiveDocPath();
var proDir = ide.getProjectDir();
var fileName = fsys.getFileName(docPath);
var fileDir = fsys.getParentDir(docPath);
winform.staticActiveFileName.text = string.concat("活动文件名:",fileName);
winform.staticActiveFileDir.text = string.concat("所在文件夹:",fileDir);
}
showActiveDocInfo();
var loadBookMarkFile = function(){
//加载书签记录文件
var filePath = io._exedir ++ "bookmark.json";
if(io.exist(filePath)){
var jsonStr = string.load(filePath);
var jsonTab = web.json.tryParse(jsonStr);
for(i=1;table.count(jsonTab);1){
var 行号 = jsonTab[i].行号;
var 行代码 = jsonTab[i].行代码;
var 文件名 = jsonTab[i].文件名;
var 所在文件夹 = jsonTab[i].所在文件夹;
winform.listview.addItem({text={行号;行代码;文件名;所在文件夹;}});
}
}
}
loadBookMarkFile();
var saveBookMarkFile = function(){
var tempTab = {};
var lvCount = winform.listview.count;
for(LVi=1;lvCount;1){
var txt1 = winform.listview.getItemText(LVi,1);
var txt2 = winform.listview.getItemText(LVi,2);
var txt3 = winform.listview.getItemText(LVi,3);
var txt4 = winform.listview.getItemText(LVi,4);
table.push(tempTab,{行号=txt1;行代码=txt2;文件名=txt3;所在文件夹=txt4;});
}
var saveStr = web.json.stringify(tempTab,true,false);
var filePath = io._exedir ++ "bookmark.json";
string.save(filePath,saveStr);
}
winform.onClose = function(hwnd,message,wParam,lParam){
saveBookMarkFile();
}
winform.buttonAddBm.oncommand = function(id,event){
//添加书签
var editor = ide.getActiveCodeEditor();
if(!editor){ winform.editLog.print("当前为界面设计窗,请切换到代码编辑框");return; }
var lineNum = winform.editLineNum.text;
if(!#lineNum){ winform.editLog.print("请输入行号");return; }
var lineCodeStr = "";
var codeStr = editor.text;
var linTab = string.split(codeStr,'\n');
lineCodeStr = linTab[tonumber(lineNum)];
var docPath = ide.getActiveDocPath();
if(!#docPath){
winform.editLog.print("未保存的文档不能添加到书签管理器");
return ;
}
var fileName = fsys.getFileName(docPath);
var fileDir = fsys.getParentDir(docPath);
winform.listview.addItem({text={lineNum;lineCodeStr;fileName;fileDir;}});
winform.editLineNum.text = "";
}
winform.onMouseDown = function(wParam,lParam){
winform.hitCaption();
}
winform.plusMain.onMouseDown = function(wParam,lParam){
winform.hitCaption();
}
var contractWinform = function(){
//收缩窗口
winform.height = 56;
var left = winform.left;
var right = winform.right;
winform.right = right;
leftMove = ((right-left)-120);
winform.left = left+leftMove;
for(hwnd,ctrl in winform.eachControlEx() ){
if(hwnd!=winform.plusMain.hwnd and hwnd!=winform.plusClose.hwnd){ ctrl.hide=true; }
}
}
var developWinform = function(){
//展开窗口
winform.height = 780;
var left = winform.left;
var right = winform.right;
winform.right = right;
winform.left = left-leftMove;
for(hwnd,ctrl in winform.eachControlEx() ){
if(hwnd!=winform.plusMain.hwnd and hwnd!=winform.plusClose.hwnd){ ctrl.hide=false; }
}
}
winform.plusMain.onMouseDoubleClick = function(wParam,lParam){
showActiveDocInfo();
var x,y = win.getMessagePos(lParam);
if(winform.height>200){
contractWinform();
}else {
developWinform();
}
}
menuHelp.addTable( {
{ "打开所在文件夹";
function(id){
var hang = winform.listview.selIndex;
if(hang){
var txt4 = winform.listview.getItemText(hang,4);
process(,"explorer "++txt4);
contractWinform();
winform.editLog.print("打开所在文件夹");
}
}
};
{};
{ "显示全部文件书签";
function(id){
winform.editLog.print("显示全部文件书签,待写");
}
};
{};
{ "只显示此文件书签";
function(id){
winform.editLog.print("只显示此文件书签,待写");
}
};
{};
{ "删除所选行";
function(id){
var hang = winform.listview.selIndex;
winform.listview.delItem(hang);
saveBookMarkFile();
winform.editLog.print("已删除所选行");
}
};
{};
{ "清空所有行";
function(id){
winform.listview.clear();
saveBookMarkFile();
winform.editLog.print("已清空所有行");
}
};
} )
//显示所选定行的信息
var showSelLineInfo = function(hang){
var txt1 = winform.listview.getItemText(hang,1);
var txt2 = winform.listview.getItemText(hang,2);
var txt3 = winform.listview.getItemText(hang,3);
var txt4 = winform.listview.getItemText(hang,4);
winform.staticSelFileName.text = string.concat("选定行所在文件名:",txt3);
winform.staticSelFileDir.text = string.concat("选定行所在文件夹:",txt4);
}
winform.listview.wndproc = function(hwnd,message,wParam,lParam){
if(message==0x201/*_WM_LBUTTONDOWN*/){
var hang,lie=winform.listview.hitTest();
showSelLineInfo(hang);
}
if(message==0x203/*_WM_LBUTTONDBLCLK*/){
var hang,lie=winform.listview.hitTest();
if(hang){
var txt1 = winform.listview.getItemText(hang,1);
var txt2 = winform.listview.getItemText(hang,2);
var txt3 = winform.listview.getItemText(hang,3);
var txt4 = winform.listview.getItemText(hang,4);
if(!#txt3){
winform.editLog.print("无文件名或无文件夹路径,不处理");
return ;
}
ide.openDocument(txt4++txt3);
ide.mdiActivate(txt3);
ide.switchActiveForm(false);
ide.gotoLine(tonumber(txt1));
winform.editLog.print("左键双击,代码编辑框跳到指定文件指定代码行:",txt3,txt1);
}
}
}
winform.listview.onnotify = function(id,code,ptr){
if( code = 0xFFFFFFFB/*_NM_RCLICK*/ ){
var x,y = win.getMessagePos();
var hang,lie=winform.listview.hitTest();
if(hang){
showSelLineInfo(hang);
var nowSel = winform.listview.selIndex;
menuHelp.popup(x,y,true);
}
}
}
winform.plusClose.oncommand = function(id,event){
winform.close();
}
winform.editLog.text = /*
使用说明:
1.填写行号点添加书签按钮,将当前活动文件信息添加到表格.
2.单击表格某行,显示完整信息到底部.
3.双击表格某行,跳到指定文件指定代码行,默认会先打开文件并激活文档切换到源码视图.
4.双击"书签管理器"区块,收缩或展开界面.
5.点击"书签管理器"右上角圆形按钮,关闭本工具窗口.
6.表格所有行内容默认以json格式保存到aardio.exe目录下,运行本工具时自动加载.
7.在表格中点击右键可以打开右键菜单.
8.可以在窗口空白处按下鼠标拖动窗口.
9.未保存的代码文档不能添加书签.
10.右键菜单项功能 显示全部文件书签 只显示此文件书签 未写好.
*/
winform.buttonTest.oncommand = function(id,event){
import ide;
var editor = ide.getActiveCodeEditor();
winform.editLog.print("editor:",editor);
}
winform.plusClose.show(true);
winform.show();
win.loopMessage();