MyAction.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. // MyAction.js
  20. // Include base class definition:
  21. include("../MyScripts.js");
  22. // Constructor calls base class constructor:
  23. function MyAction(guiAction) {
  24. MyScripts.call(this, guiAction);
  25. }
  26. // Derive class MyAction from class MyScripts:
  27. MyAction.prototype = new MyScripts();
  28. // This function is called immediately after the constructor when the user
  29. // starts this action. For actions that don't require any user input (for
  30. // example auto zoom), beginEvent does everything and then terminates the
  31. // action.
  32. MyAction.prototype.beginEvent = function() {
  33. // call base class implementation of beginEvent:
  34. MyScripts.prototype.beginEvent.call(this);
  35. // get main application window:
  36. var appWin = EAction.getMainWindow();
  37. // print a message in the console of QCAD:
  38. appWin.handleUserMessage("MyAction() is running...");
  39. // terminate this action immediately:
  40. this.terminate();
  41. };
  42. // MyAction.init() is called by QCAD to initialize the action and create
  43. // the menu / toolbar for it.
  44. MyAction.init = function(basePath) {
  45. // Create a new RGuiAction (extended QAction):
  46. var action = new RGuiAction("&My Action", RMainWindowQt.getMainWindow());
  47. // This action requires a document to be open. If no document is
  48. // open, the menu and tool button are grayed out:
  49. action.setRequiresDocument(true);
  50. // Define the script file that is executed when this action is
  51. // launched:
  52. action.setScriptFile(basePath + "/MyAction.js");
  53. // Set the icon that is shown in the toolbar and on some platforms
  54. // also in the menu:
  55. action.setIcon(basePath + "/MyAction.svg");
  56. // Set the command(s) that can be used on the command line to
  57. // launch this action:
  58. action.setDefaultCommands(["myaction"]);
  59. // Define the sort order of this action. Menus and tool buttons are
  60. // ordered by these values:
  61. action.setGroupSortOrder(80100);
  62. action.setSortOrder(200);
  63. // Set list of widgets this action is added to
  64. // (menus, tool bars, CAD tool bar panels):
  65. action.setWidgetNames(["MyScriptsMenu"]);
  66. };