import web.npm; import wsock.tcp.asynHttpServer; import win.ui; /*DSG{{*/ var winform = win.form(text="web.view - JSON 编辑器";left=-2;top=-2;right=966;bottom=622) winform.add() /*}}*/ import web.view; var wb = web.view(winform); import key; import fsys.dlg; wb.external = { save = function(json){ var path = ( !key.getState("CTRL") && wb.currentJsonFilePath ) || fsys.dlg.save("*.json|*.json|*.*|*.*|","保存 JSON 文件"); if(path){ string.save(path,json); wb.currentJsonFilePath = path; winform.text = "已保存到:"+wb.currentJsonFilePath winform.setTimeout( function(){ winform.text = "web.view - JSON 编辑器"; },2000); } }; load = function(json){ var path = fsys.dlg.open("*.json|*.json|*.*|*.*|","打开 JSON 文件(也可以直接拖放文件到 JSON 编辑器页面)"); if(path){ wb.currentJsonFilePath = path; return string.load(path); } }; copyAsTable = function(json){ var tab = JSON.tryParse(json); if(tab){ var str = ..table.tostring(tab); import win.clip; win.clip.write(str); winform.text = "已转换为 table 对象并复制为 aardio 代码。" winform.setTimeout( function(){ winform.text = "web.view - JSON 编辑器"; },2000); } }; toggleTopmost = function(){ var topmost = win.getStyleEx(winform.hwnd,8/*_WS_EX_TOPMOST*/); win.setTopmost(winform.hwnd,!topmost) return !topmost; }; } //启动内嵌 HTTP 服务器 wb.asynHttpServer = wsock.tcp.asynHttpServer(); //创建虚拟文件表 wb.asynHttpServer.run( { ["/vanilla-jsoneditor.js"] = web.npm.load("/","vanilla-jsoneditor","standalone.js"); ["/index.html"] = /********
********/ }); //打开首页 wb.go("/index.html"); //弹出新窗口触发 wb.onNewWindow = function(url){ return function(){ //如果打开的是 file: 前缀网址,例如拖放文件到网页上。 var filePath = inet.url.getFilePath(url) if(filePath){ wb.currentJsonFilePath = filePath; wb.invoke("editor.set",{text=string.load(filePath)}) } else { } } } if(_JSON_EDITOR_TEXT){ wb.waitDoc(); wb.invoke("editor.set",{text=_JSON_EDITOR_TEXT}) } winform.show(3/*_SW_MAXIMIZE*/); win.loopMessage();