ExDirListing.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. include("scripts/EAction.js");
  20. /**
  21. * \ingroup ecma_misc_examples_qtexamples
  22. * \class ExDirListing
  23. * This action lists the contents of the home directory and prints
  24. * it into the QCAD command line history.
  25. */
  26. function ExDirListing(guiAction) {
  27. EAction.call(this, guiAction);
  28. }
  29. ExDirListing.prototype = new EAction();
  30. ExDirListing.prototype.beginEvent = function() {
  31. EAction.prototype.beginEvent.call(this);
  32. // create QDir object that represents a directory:
  33. var dir = QDir.home();
  34. // get directory listing:
  35. var fileInfos = dir.entryInfoList(
  36. // name filter(s):
  37. ["*"],
  38. // we don't want to get information about '.' or '..', we want all directories and all files:
  39. makeQDirFilters(QDir.NoDotAndDotDot, QDir.Dirs, QDir.Files),
  40. // sort by name:
  41. QDir.Name
  42. );
  43. // print some of the available information:
  44. for (var i=0; i<fileInfos.length; i++) {
  45. EAction.handleUserMessage(
  46. fileInfos[i].fileName() +
  47. " [" + (fileInfos[i].isDir() ? "Directory" : "File") + "] " +
  48. fileInfos[i].size() + " Bytes"
  49. );
  50. }
  51. this.terminate();
  52. };
  53. /**
  54. * Adds a menu for this action to Examples/Math Examples/ExDirListing.
  55. */
  56. ExDirListing.init = function(basePath) {
  57. var action = new RGuiAction(qsTr("&Directory Listing"), RMainWindowQt.getMainWindow());
  58. action.setRequiresDocument(false);
  59. action.setScriptFile(basePath + "/ExDirListing.js");
  60. action.setGroupSortOrder(79600);
  61. action.setSortOrder(100);
  62. action.setWidgetNames(["QtExamplesMenu"]);
  63. };