panel_ex.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. 面板扩展
  3. 功能: 绑定快捷键事件
  4. */
  5. 'use strict';
  6. var path = require('path');
  7. var fs = require('fs');
  8. var md5 = require('md5');
  9. var fe = Editor.require('packages://simple-code/tools/tools.js');
  10. const inputType = {"text":1,"password":1,"number":1,"date":1,"color":1,"range":1,"month":1,"week":1,"time":1,"email":1,"search":1,"url":1,"textarea":1}
  11. module.exports = {
  12. /** @type import('../../panel/vs-panel/vs-panel-base') */
  13. parent : null,
  14. // 面板初始化
  15. onLoad(parent){
  16. // index.js 对象
  17. this.parent = parent;
  18. this.bindKey()
  19. },
  20. bindKey(){
  21. // 0代表只有非编辑状态时可用,1代表仅在在文本编辑状态使用,2全局不受影响
  22. let KEY_MODE = 2;
  23. // 绑定页面全局快捷键事件,编辑器翻页
  24. this.parent.addKeybodyEventByName('moveUp',(e)=>
  25. {
  26. // let is_vim_cmd_mode = Editor.monaco.vim_mode && !Editor.monaco.vim_mode.state.vim.insertMode;// vim模式禁止输入
  27. // if(!is_vim_cmd_mode){
  28. // return
  29. // }
  30. let pos = this.parent.vs_editor.getPosition();
  31. pos.lineNumber -=7;
  32. if(pos.lineNumber < 0) pos.lineNumber = 0
  33. this.parent.vs_editor.setPosition(pos)
  34. this.parent.vs_editor.revealPosition(pos)
  35. e.preventDefault();// 吞噬捕获事件
  36. return false;
  37. },1)
  38. // 绑定页面全局快捷键事件,编辑器翻页
  39. this.parent.addKeybodyEventByName('moveDown',(e)=>
  40. {
  41. // let is_vim_cmd_mode = Editor.monaco.vim_mode && !Editor.monaco.vim_mode.state.vim.insertMode;// vim模式禁止输入
  42. // if(!is_vim_cmd_mode){
  43. // return
  44. // }
  45. let pos = this.parent.vs_editor.getPosition();
  46. pos.lineNumber +=7;
  47. // if(pos.lineNumber > 0) pos.lineNumber = 0
  48. this.parent.vs_editor.setPosition(pos)
  49. this.parent.vs_editor.setScrollTop(this.parent.vs_editor.getScrollTop()+100)
  50. e.preventDefault();// 吞噬捕获事件
  51. return false;
  52. },1)
  53. // // 绑定页面全局快捷键事件
  54. // this.parent.addKeybodyEventByName('execCode',(e)=>
  55. // {
  56. // // 运行命令
  57. // Editor.Ipc.sendToPanel('simple-code','run-command-code',"cmd");
  58. // },1)
  59. // // 绑定页面全局快捷键事件
  60. // this.parent.addKeybodyEventByName('execCodeByScene',(e)=>
  61. // {
  62. // // 运行 Scene 命令
  63. // Editor.Ipc.sendToPanel('simple-code','run-command-code',"scene");
  64. // },2)
  65. // 锁定/解锁编程
  66. this.parent.addKeybodyEventByName('lockView',(e)=>
  67. {
  68. e.preventDefault();// 吞噬捕获事件
  69. this.parent.setLockEdit(!this.parent.file_info.is_lock)
  70. },1)
  71. // 字体变大
  72. this.parent.addKeybodyEventByName('fontBigger',(e)=>
  73. {
  74. e.preventDefault();// 吞噬捕获事件
  75. this.parent.setOptions({fontSize : this.parent.vs_editor.getRawOptions().fontSize+0.5})
  76. },1)
  77. // 字体变小
  78. this.parent.addKeybodyEventByName('fontSmall',(e)=>
  79. {
  80. e.preventDefault();// 吞噬捕获事件
  81. this.parent.setOptions({fontSize : this.parent.vs_editor.getRawOptions().fontSize-0.5})
  82. },1)
  83. for (let i = 0; i < 10; i++) {
  84. // 绑定页面全局快捷键事件,注意: 区分大小写 Ctrl = ctrl
  85. this.parent.addKeybodyEvent([[Editor.isWin32 ? "Alt" : "Meta",String(i)]],(e)=>
  86. {
  87. let activeInfo = Editor.Selection.curGlobalActivate() // 检测面板焦点在资源管理器还是层级管理器
  88. if (activeInfo && activeInfo.type == "asset")
  89. {
  90. Editor.info("设置标签:",Editor.remote.assetdb.uuidToUrl(activeInfo.id));
  91. localStorage.setItem("simple-code-tag_"+i,activeInfo.id);
  92. e.preventDefault();// 吞噬捕获事件
  93. return false;
  94. }
  95. },0)
  96. }
  97. for (let i = 0; i < 10; i++) {
  98. // 绑定页面全局快捷键事件,注意: 区分大小写 Ctrl = ctrl
  99. this.parent.addKeybodyEvent([[String(i)]],(e)=>
  100. {
  101. let uuid = localStorage.getItem("simple-code-tag_"+i);
  102. if (!this.inputTypeChk(e) && Editor.remote.assetdb.uuidToUrl(uuid))
  103. {
  104. Editor.Ipc.sendToAll('assets:hint', uuid)
  105. Editor.Selection.select('asset', uuid)
  106. e.preventDefault();// 吞噬捕获事件
  107. return false;
  108. }
  109. },0)
  110. }
  111. this.parent.addKeybodyEventByName('setNodeTreeTag',(e)=>
  112. {
  113. let activeInfo = Editor.Selection.curGlobalActivate() // 检测面板焦点在资源管理器还是层级管理器
  114. if (activeInfo && activeInfo.type == "node")
  115. {
  116. let nodes = Editor.Selection.curSelection("node");
  117. this._select_nodes = nodes;
  118. Editor.info("设置Node标签");
  119. e.preventDefault();// 吞噬捕获事件
  120. return false;
  121. }
  122. },0)
  123. this.parent.addKeybodyEventByName('getNodeTreeTag',(e)=>
  124. {
  125. if (this._select_nodes)
  126. {
  127. Editor.Selection.select('node', this._select_nodes);
  128. e.preventDefault();// 吞噬捕获事件
  129. }
  130. },0);
  131. // 全选节点
  132. this.parent.addKeybodyEventByName('quickAddNextNode',(e)=>
  133. {
  134. if (!this.inputTypeChk(e)){
  135. e.preventDefault();// 吞噬捕获事件
  136. Editor.Scene.callSceneScript('simple-code', 'select-node' ,"");
  137. }
  138. },0)
  139. // 绑定页面全局快捷键事件,注意: 区分大小写 Ctrl = ctrl
  140. this.arr_cut_asset = [];
  141. this.parent.addKeybodyEvent([Editor.isWin32 ? ["Ctrl",'x'] : ["Meta",'x'] ],(e)=>
  142. {
  143. let panel = Editor.Panel.getFocusedPanel()
  144. if (!panel || this.inputTypeChk(e) || panel.id != "assets"){
  145. return
  146. }
  147. let activeInfo = Editor.Selection.curGlobalActivate() // 检测面板焦点在资源管理器还是层级管理器
  148. if (activeInfo && activeInfo.type == "asset" && !this.inputTypeChk(e))
  149. {
  150. this.arr_cut_asset = Editor.Selection.curSelection('asset')
  151. for (var i = 0; i < this.arr_cut_asset.length; i++) {
  152. Editor.Ipc.sendToAll('assets:hint', this.arr_cut_asset[i]);
  153. }
  154. e.preventDefault();// 吞噬捕获事件
  155. return false;
  156. }
  157. },0)
  158. this.parent.addKeybodyEvent([Editor.isWin32 ? ["Ctrl",'c'] : ["Meta",'c'] ],(e)=>
  159. {
  160. this.arr_cut_asset = [];
  161. },0)
  162. this.parent.addKeybodyEvent([Editor.isWin32 ? ["Ctrl",'v'] : ["Meta",'v'] ],(e)=>
  163. {
  164. let panel = Editor.Panel.getFocusedPanel()
  165. if (!panel || this.arr_cut_asset.length == 0 || this.inputTypeChk(e) || panel.id != "assets" ){
  166. return
  167. }
  168. let activeInfo = Editor.Selection.curGlobalActivate() // 检测面板焦点在资源管理器还是层级管理器
  169. if (activeInfo && activeInfo.type == "asset" && !this.inputTypeChk(e))
  170. {
  171. let t_url = Editor.remote.assetdb.uuidToUrl(activeInfo.id);
  172. let t_path = Editor.remote.assetdb.urlToFspath(t_url);
  173. if(!fe.isDirectory(t_path))
  174. {
  175. t_url = t_url.substr(0,t_url.lastIndexOf('/'));
  176. }
  177. for (var i = 0; i < this.arr_cut_asset.length; i++) {
  178. let m_url = Editor.remote.assetdb.uuidToUrl(this.arr_cut_asset[i]);
  179. let wb = m_url.substr(m_url.lastIndexOf('/'));
  180. Editor.assetdb.move(m_url, t_url+wb);
  181. }
  182. this.arr_cut_asset = [];
  183. e.preventDefault();// 吞噬捕获事件
  184. e.stopPropagation();
  185. return false;
  186. }
  187. },0)
  188. this.parent.addKeybodyEventByName('setNodeActive',(e)=>
  189. {
  190. Editor.Scene.callSceneScript('simple-code', 'active-curr-node' ,{},function (err, event) {
  191. // Editor.log("delect node")
  192. });
  193. e.preventDefault();// 吞噬捕获事件
  194. return false;
  195. },0)
  196. },
  197. // 不是输入状态是时
  198. inputTypeChk(e){
  199. if (e.path[0] ){
  200. let type = e.path[0].type ;
  201. if ( inputType[type]){
  202. return true
  203. }
  204. }
  205. },
  206. // 键盘按下
  207. onKeyDown(event){
  208. // cc.log("按下",event.key);
  209. },
  210. // 键盘弹起
  211. onKeyUp(event){
  212. },
  213. // 面板销毁
  214. onDestroy(){
  215. },
  216. /************* 事件 *************/
  217. messages:{
  218. // 快捷键打开当前选中文件/节点进入编辑
  219. 'custom-cmd' (event,info) {
  220. },
  221. 'scene:saved'(){
  222. // Editor.log("事件 save")
  223. }
  224. },
  225. };