mainfrm_pane.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. //Callback of data preparation stage before UI is fully loaded.
  5. function OnInitializeData() {
  6. // 注册保存请求的回调函数,当网页请求保存时会触发此逻辑
  7. model.OnMonacoSaveRequest = function (content, cb) {
  8. // 弹出“保存文件”对话框,初始目录为 D:/,允许保存为 .txt 文件
  9. const filepath = ui.SaveFileDialog("保存文件", "D:/", "*.txt");
  10. // 如果用户选择了文件路径
  11. if (filepath) {
  12. cb(filepath); // 调用回调函数,把选定路径传给 model 层保存文件内容
  13. const filename = filepath.split(/[/\\]/).pop(); // 提取不带路径的文件名
  14. ui.MessageBox("提示", `成功保存‘${filename}’到‘${filepath}’`, MessageBox.Icon.Information, MessageBox.Button.Ok); // 弹出成功提示
  15. } else {
  16. // 用户取消保存操作
  17. ui.MessageBox("提示", "取消", MessageBox.Icon.Warning, MessageBox.Button.Ok);
  18. }
  19. };
  20. // 注册打开请求的回调函数,当网页请求打开文件时会触发此逻辑
  21. model.OnMonacoOpenRequest = function (cb) {
  22. // 弹出“打开文件”对话框,初始目录为 D:/,仅显示 .txt 文件
  23. const filepath = ui.OpenFileDialog("打开文件", "D:/", "*.txt");
  24. // 对于用户选择的文件
  25. if (filepath) {
  26. cb(filepath); // 调用回调函数,把选定路径传给 model 层读取文件内容
  27. const filename = filepath.split(/[/\\]/).pop(); // 提取文件名
  28. ui.MessageBox("提示", `成功打开‘${filename}’`, MessageBox.Icon.Information, MessageBox.Button.Ok); // 弹出成功提示
  29. } else {
  30. // 用户取消打开操作
  31. ui.MessageBox("提示", "取消", MessageBox.Icon.Warning, MessageBox.Button.Ok);
  32. }
  33. };
  34. }
  35. //Callback after UI is fully loaded and displayed.
  36. function OnReady(reload, preview) {
  37. model.StartupMonacoEdit(()=>{
  38. ui.url.value = "http://localhost:3000";
  39. });
  40. }
  41. function OnCloseForm() {
  42. }
  43. function OnException(err) {
  44. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  45. }
  46. //////////////////////////////////////////////////////////////////////////
  47. // Callback Functions.
  48. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  49. function OnPageLoadOkay(){
  50. ui.page.index = 1;
  51. }
  52. function OnPageLoadFail(){
  53. ui.url.value = "http://localhost:3000";
  54. }
  55. //The message corresponding callback executed by the main form
  56. // when calling pui.fireEvent(type,para) in the Docker subform.
  57. //////////////////////////////////////////////////////////////////////////
  58. // Utils Functions.
  59. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  60. function onDragFile(filepath) {
  61. }
  62. /*Usage of BLOCK_EVENT
  63. BLOCK_EVENT(()=>{
  64. ui.[name].[var] = ...;
  65. });
  66. */
  67. function BLOCK_EVENT(cb) {
  68. ui.block_event = true;
  69. cb();
  70. ui.block_event = false;
  71. }