sleep(1000)
import win.ui;
/*DSG{{*/
mainForm = win.form(text="开始页.....";left=0;top=0;right=599;bottom=399;border="none";exmode="none";mode="child";parent=...;scroll=1)
mainForm.add()
/*}}*/
import ide;
import web.layout;
global.onError = function( err,over ){
ide.setConfig("startpage","off");
mainForm.msgboxErr('抱歉!\n开始页遇到错误,\n已自动禁用开始页。',"aardio")
win.close(win.getParent(win.getParent(mainForm.hwnd)));
}
if( _WINE ){
win.close(win.getParent(...))
return;
}
var wbLayout = web.layout(mainForm);
wbLayout.go("\res\start-page.htm");
wbLayout.wait();
import string.xml;
getProjectInfo = function(path){
if(!path) return;
if( ..string.startsWith(path,"\\") ) return;
var xmlstr = string.load(path);
if(!xmlstr) return;
var xmlDoc = string.xml( xmlstr )
if(!xmlDoc) return;
var project = xmlDoc.queryEles( tagName = "project");
if(!project) return;
return project[1];
}
loadRecentProjectFromFile = function(){
var recentList = {};
var cfgRecentProject = ..string.load("~/config/RECENT.PROJECT.TABLE");
if( cfgRecentProject ){
try{
recentList = eval(cfgRecentProject)
}
}
return recentList;
}
refreshRecentProject = function(){
var ltList = wbLayout.getEle("recent-projects-list");
ltList.innerHTML = "";
var recentList = loadRecentProjectFromFile();
if( #recentList ){
var len = #recentList;
if( len > 12 ) len = 12;
for(i=1;len;1){
if(!recentList[i])break;
var inf = getProjectInfo( recentList[i] );
if(!inf) {
if( #recentList + 1 > len ){
table.remove(recentList,i);
i--;
}
continue;
}
ltList.printf( '
%s '
,recentList[i],inf.name );
}
}
else {
ltList.innerHTML = '我的第一个工程'
}
}
refreshRecentProject();
var isCurrentProject = function(projPath){
var curProjPath= ide.getProjectPath();
if( fsys.path.cmp(projPath,curProjPath) === 0 ){
var mainFile = ide.getProjectMainFile();
ide.openDocument(mainFile);
return true;
}
}
import process;
wbLayout.sinking = {
onHyperlinkClick = {
["recent-project-item"] = function (ltTarget,ltEle,reason,behaviorParams) {
var projPath = ltEle.href;
if( io.exist(projPath) ){
if(isCurrentProject(projPath)) return true;
thread.invoke(
function(path){
import ide;
ide.openDocument(path);
},projPath
)
}
return true;
}
["create-project"] = function (ltTarget,ltEle,reason,behaviorParams) {
thread.invoke(
function(path){
import ide;
ide.newProject();
},path
)
return true;
}
["open-project"] = function (ltTarget,ltEle,reason,behaviorParams) {
import fsys.dlg;
var defDir = ide.getConfig("project_default_dir");
var recentList = loadRecentProjectFromFile();
if(#recentList) defDir = ..fsys.getParentDir( recentList[1] );
var path = fsys.dlg.open("aardio工程文件|*.aproj||","请选择要打开的aardio工程文件",defDir,ide.getMainHwnd(),,"default.aproj")
if( path ? io.exist(path) ){
thread.invoke(
function(path){
import ide;
ide.openDocument(path);
},path
)
}
return true;
}
["update-tool"] = function (ltTarget,ltEle,reason,behaviorParams) {
loadcode("~\tools\update.aardio")("自动更新");
ltEle.delete();
return true;
}
["lnkdsk"]= function (ltTarget,ltEle,reason,behaviorParams) {
import fsys.lnk;
lnk = fsys.lnk();
lnk.description = "aardio:网站/桌面软件快速开发工具"
lnk.path = io._exepath //设置目标路径
lnk.setIcon(io._exepath,0); //设置图标
lnk.save(
io.joinpath(
fsys.getSpecial(0x0010 /*_CSIDL_DESKTOPDIRECTORY*/ )
,"aardio.lnk"
)
)
loadcode("/dsktip.aardio")();
return true;
}
["jiaqun"] = function (ltTarget,ltEle,reason,behaviorParams) {
import web.form;
var frmJiaQun = win.form(text="Web Form";right=1;bottom=1);
var wb = web.form( frmJiaQun ,,,,true/*securityTrusted*/ );
wb.noScriptErr=true;
wb.go(ltEle.href);
wb.wait(,5000);
frmJiaQun.close();
return true;
}
["default"] = function (ltTarget,ltEle,reason,behaviorParams) {
var path = ltEle.href;
if(..string.startsWith(path,"doc://")){
ide.openDocument(path)
return true;
}
if( ..string.endsWith(path,".aardio",true) ){
if( ..io.exist(path)) {
ide.createProcess(path);
return true;
}
import inet.url;
var code,err = thread.invokeAndWait(
function(url){
import inet.http;
return inet.http(null,"").get(url)
},path
)
if(!code) {
if(path) process.execute(path);
return true;
}
import fsys;
fsys.createDir("/.sampleCode/");
var codePath = "/.sampleCode/" + ..string.match(path,"[^/]+$");
string.save(codePath,code )
ide.openDocument(codePath)
return true;
}
if(path) {
thread.invoke(
function(path){
import process;
process.execute(path);
},path
)
}
return true;
}
}
}
wbLayout.onButtonClick = {
["search-tool"] = function (ltTarget,ltEle,reason,behaviorParams) {
loadcode("~\tools\search.aardio")("自动更新");
return true;
}
}
wbLayout.onMenuItemClick = {
["open-project"] = function (ltTarget,ltOwner,reason,behaviorParams) {
var ltPopupOwner = ..web.layout.element( behaviorParams.he )
var projPath = ltPopupOwner.href;
if(isCurrentProject(projPath)) return true;
..thread.invoke(
function(path){
import ide;
ide.openDocument(path);
},projPath
)
}
["open-project-as"] = function (ltTarget,ltOwner,reason,behaviorParams) {
var ltPopupOwner = ..web.layout.element( behaviorParams.he )
var projPath = ltPopupOwner.href;
var curProjPath= ide.getProjectPath();
if(isCurrentProject(projPath)) return true;
var title = ltPopupOwner.innerHTML;
ltPopupOwner.innerHTML = `
`;
..thread.invoke(
function(path){
import process;
process.execute(io._exepath,{ path });
},projPath
)
thread.delay(2000);
ltPopupOwner.innerHTML = title;
}
["explore-project"] = function (ltTarget,ltOwner,reason,behaviorParams) {
var ltPopupOwner = ..web.layout.element( behaviorParams.he )
process.explore_select(ltPopupOwner.href);
}
["delete-project"] = function (ltTarget,ltEle,reason,behaviorParams) {
var ltPopupOwner = ..web.layout.element( behaviorParams.he )
var recentList = loadRecentProjectFromFile();
if(#recentList){
var idx = ..table.find( recentList,ltPopupOwner.href );
if(idx){
table.remove( recentList,idx)
..string.save("~/config/RECENT.PROJECT.TABLE", table.tostring(recentList));
refreshRecentProject();
}
}
}
["delete-project-all"] = function (ltTarget,ltEle,reason,behaviorParams) {
..string.save("~/config/RECENT.PROJECT.TABLE", "{}");
refreshRecentProject();
}
}
import ide;
import thread.event
mainForm.updateNews = function(html){
wbLayout.getEle("start-page-news").innerHTML = html : "获取官网最新消息失败......";
var event = thread.event(ide.processGroup(".startPage"));
event.set();
}
import ide.command;
ide.command.join( ide.processGroup() );
var listener = ide.command();
listener.onProjectOpened = function(){
refreshRecentProject();
}
listener.onUpdateAvailable = function(strVersion){
if(!strVersion)return;
var ltEle = wbLayout.getEle("update-tool")
if( ltEle ) ltEle.delete();
var html = "发现aardio已更新版本:" + strVersion + ",点这里立即更新"
wbLayout.getEle("start-page-news").insertAdjacentHTML("afterBegin", html);
ide.mdiActivate( mainForm.hwnd );
}
listener.onUpdateFinished = function(){
var ltEle = wbLayout.getEle("update-tool")
if( ltEle ) ltEle.delete();
}
thread.invoke(
function(mainForm){
import inet.http;
var http = inet.http();
var html = http.get("http://api.aardio.com/v10/pages/startpage/");
http.close();
mainForm.updateNews(html);
},mainForm
)
mainForm.show(0x3/*_SW_MAXIMIZE*/);
mainForm.setTimeout(function(){
mainForm.show(0x3/*_SW_MAXIMIZE*/);
},1000);
//转发IDE快捷键
var ideHwnd = ide.getMainHwnd();
mainForm.isDialogMessage = function(hwnd,msg){
if( msg.message == 0x100/*_WM_KEYDOWN*/){
var vk = msg.wParam;
if( ( vk >0x70/*_VK_F1*/ && vk < 0x7B/*_VK_F12*/)
|| vk == 0x11/*_VK_CTRL*/ || vk==0x10/*_VK_SHIFT*/ || vk==0x12/*_VK_ALT*/ ){
::PostMessage(ideHwnd,msg.message,msg.wParam,msg.lParam);
return true;
}
var ctrl = ::GetKeyState( 0x11/*_VK_CONTROL*/ ) & 0x8000;
var alt = ::GetKeyState( 0x12/*_VK_ALT*/ ) & 0x8000;
var shift = ::GetKeyState( 0x10/*_VK_SHIFT*/ ) & 0x8000;
if( ctrl || alt || shift ){
::PostMessage(ideHwnd,msg.message,msg.wParam,msg.lParam);
return true;
}
}
return win.isDialogMessage(hwnd,msg);
}
win.loopMessage();