把之前的库提示文件插件化了,现在可直接使用光庆大佬开发的【插件管理】添加使用
以前修改init文件的记得还原了,没必要存在两份了
1 新增了 ctrl+f9的热键,可以根基自己习惯直接修改源码就行,注释里有修改位置
2 新增了自动刷新,之前是因为 ide.refreshUserLib(); 会篡改当前目录导致下一次使用相对路径,读取不到文件了,重置一下当前路径就好了
2023年8月25日
优化
1 为类的构造函数生成,完整代码行提示,类似idea的 .var功能,避免移动光标书写var 变量名的过程,
提示格式为 类名_var ,生成代码为
var 类名小写 = 类名();
//IDE加载后
//新建线程
//插件名称:编译用户库提示文件
//插件说明:编译用户库提示文件,点击右下角按钮,或者ctrl+f9(注意插件热键不要冲突)
namespace UserDeclareBuild{
import fsys;
import string;
import io;
import win;
import ide;
import console;
function build(){
if(ide.getProjectDir()==null||ide.getProjectDir()==""){
win.msgbox("请打开项目在使用此功能")
return;
}
//由于ide.refreshUserLib() 会修改当前目录 所以每次需要重置到项目路径中
fsys.setCurDir(ide.getProjectDir())
declare = io.open (".\lib\declare.aardio","w+")
declare.write(
"/*intellisense()"+'\n'
+"annc = @/**\n@@_desc_clazz __ \n**/"+'\n'
+"annf = @/**\n@@_desc_func __ \n**/"+'\n'
+"mm = @/**\n@@desc __ \n**/"+'\n'
+"end intellisense*/"+'\n'
);
declare.close();
declare = io.open (".\lib\declare.aardio","a+")
fsys.enum( ".\lib", //当前项目的lib目录
"*.aardio", //所有 aardio 文件
function(dir,file,fullpath,findData){
if(file){
//排除掉declare,UserDeclareBuild文件,declare为声明文件,UserDeclareBuild为当前文件
if(file!="declare.aardio"&&file!="UserDeclareBuild.aardio"){
printDeclare(declare,fullpath);
}
}
}
);
declare.close();
//刷新用户库提示文件
ide.refreshUserLib();
win.msgbox("用户库提示文件刷新成功,.\lib\declare.aardio",,,,1000);
}
function printDeclare(declare,fullpath){
var $str = string.load(fullpath)
var method="";
var isClazz=false;
var clazz="";
var clazzDesc="";
for $line in string.lines($str) {
if(string.indexOf($line,"class")){
isClazz=true;
clazz=string.replace(string.replace($line,"@class",""),"{","")
declare.write("/*intellisense()"+'\n');
}
elseif(string.indexOf($line,"namespace")){
var spacename=string.replace(string.replace($line,"@namespace",""),"{","")
declare.write("/*intellisense("+spacename+".)"+'\n');
}elseif(string.indexOf($line,"@@_desc_clazz")){
clazzDesc=string.trim(string.replace(string.replace($line,"@@@@_desc_clazz",""),"{",""))+"\n"
}elseif(string.indexOf($line,"@@desc")){
var desc=string.trim(string.replace(string.replace($line,"@@@@desc",""),"{",""))
method=method+desc;
}
elseif(string.indexOf($line,"@@_desc_func")){
var desc=string.trim(string.replace(string.replace($line,"@@@@_desc_func",""),"{",""))
method=method+desc;
}
elseif(string.indexOf($line,"function")){
var fun=string.replace(string.replace($line,"@function",""),"{","")
fun=string.replace(fun,"\s","",10);
if(isClazz){
fun=string.replace(fun,"@=","",10);
}
method=fun+" = " +string.replace(method,"\s","",10);
if(isClazz){
method="!tmp."+method;
}
declare.write(method+'\n');
method="";
}
}
if(isClazz){
clazzDesc=string.replace(clazzDesc,"\s","",10);
clazz=string.replace(clazz,"\s","",10);
declare.write(clazz+"() = "+clazzDesc+"!tmp."+'\n');
}
declare.write("end intellisense*/"+'\n');
//declare.close();
}
}
import win.ui;
import ide;
import gdi;
import winex;
import fonts.fontAwesome;
import console;
//获取状态栏句柄
var hwndStatusBar = winex.findEx(ide.getMainHwnd(), , "Afx\:RibbonStatusBar", "");
win.modifyStyle(hwndStatusBar, , 0x2000000 /*_WS_CLIPCHILDREN*/ );
/*DSG{{*/
var winform = win.form(text="编译用户库提示文件";right=19;bottom=20;border="none";exmode="none";max=false;min=false;mode="child";parent=hwndStatusBar)
winform.add(
plus={cls="plus";left=0;top=0;right=20;bottom=23;bgcolor=-28642;color=16777215;font=LOGFONT(h=-16);iconStyle={font=LOGFONT(h=-20;name='FontAwesome')};iconText='\uF0E3';notify=1;z=1}
)
/*}}*/
//绑定热键 ctrl+f9 可自行更改
winform.reghotkey(
function(id,mod,vk){
UserDeclareBuild.build();
}
//winform.hotkey.gethotkey()刚好返回2个值对应最后两个参数
,2/*_MOD_CONTROL*/,0x78/*_VK_F9*/
);
winform.plus.skin({
background = {
active = 0xFF0081FF;
default = 0xFF1E90FF;
hover = 0xFF339AFF
};
color = {
default = 0xFFFFFFFF
}
})
//设置点击事件
winform.plus.oncommand = function(id, event) {
//生成用户库提示文件
UserDeclareBuild.build();
}
var intervalId = winform.setInterval(
300,
function(hwnd, msg, id, tick) {
chwnd = winex.findEx(ide.getMainHwnd(), , "Afx\:RibbonStatusBar", "");
if (chwnd) {
var x, y ,weight ,height = win.getPos(chwnd)
var x1, y1 ,weight1 ,height1 = win.getPos(winform.hwnd);
var targetX=weight-255+x;
if(targetX!=x1){
winform.setPos(targetX,2,winform.width,winform.height);
winform.redraw();
}
}
})
winform.onClose = function(hwnd, message, wParam, lParam) {
winform.clearInterval(intervalId);
}
import win.ui.menu;
winform.plus.wndproc = function(hwnd, message, wParam, lParam) {
select (message) {
case 0x205 /*_WM_RBUTTONUP*/ {
//鼠标右键弹起,下面获取坐标
var x, y = win.getMessagePos(lParam);
var menu = win.ui.popmenu(winform);
menu.add("退出", function() {
winform.close()
})
menu.popup(x, y);
return true;
}
}
}
import win.ui.tooltip;
// 在所有者窗口 winform 上创建 tooltip 提示控件
var tooltipCtrl = win.ui.tooltip(winform);
// 添加一个自动模式的控件提示(TOOLINFO 对象,简称 tool )
var toolInfoPlus = tooltipCtrl.addTool(winform.plus, "编译用户库提示文件(Ctrl+F9)")
//console.log(winform.getPos())
winform.show();
return win.loopMessage();