prefs.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const GObject = imports.gi.GObject;
  2. const Gtk = imports.gi.Gtk;
  3. const Gettext = imports.gettext.domain('appfolders-manager');
  4. const _ = Gettext.gettext;
  5. const ExtensionUtils = imports.misc.extensionUtils;
  6. const Me = ExtensionUtils.getCurrentExtension();
  7. const Convenience = Me.imports.convenience;
  8. //-----------------------------------------------
  9. const appfoldersManagerSettingsWidget = new GObject.Class({
  10. Name: 'appfoldersManager.Prefs.Widget',
  11. GTypeName: 'appfoldersManagerPrefsWidget',
  12. Extends: Gtk.Box,
  13. _init: function (params) {
  14. this.parent(params);
  15. this.margin = 30;
  16. this.spacing = 18;
  17. this.set_orientation(Gtk.Orientation.VERTICAL);
  18. this._settings = Convenience.getSettings('org.gnome.shell.extensions.appfolders-manager');
  19. this._settings.set_boolean('debug', this._settings.get_boolean('debug'));
  20. //----------------------------
  21. let labelMain = new Gtk.Label({
  22. label: _("Modifications will be effective after reloading the extension."),
  23. use_markup: true,
  24. wrap: true,
  25. halign: Gtk.Align.START
  26. });
  27. this.add(labelMain);
  28. let generalSection = this.add_section(_("Main settings"));
  29. let categoriesSection = this.add_section(_("Categories"));
  30. //----------------------------
  31. // let autoDeleteBox = this.build_switch('auto-deletion',
  32. // _("Delete automatically empty folders"));
  33. let deleteAllBox = this.build_switch('total-deletion',
  34. _("Delete all related settings when an appfolder is deleted"));
  35. let menusBox = this.build_switch('extend-menus',
  36. _("Use the right-click menus in addition to the drag-and-drop"));
  37. // this.add_row(autoDeleteBox, generalSection);
  38. this.add_row(deleteAllBox, generalSection);
  39. this.add_row(menusBox, generalSection);
  40. //-------------------------
  41. let categoriesBox = this.build_switch('categories', _("Use categories"));
  42. let categoriesLinkButton = new Gtk.LinkButton({
  43. label: _("More informations about \"additional categories\""),
  44. uri: "https://standards.freedesktop.org/menu-spec/latest/apas02.html"
  45. });
  46. this.add_row(categoriesBox, categoriesSection);
  47. this.add_row(categoriesLinkButton, categoriesSection);
  48. //-------------------------
  49. let aboutBox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, spacing: 10 });
  50. let about_label = new Gtk.Label({
  51. label: '(v' + Me.metadata.version.toString() + ')',
  52. halign: Gtk.Align.START
  53. });
  54. let url_button = new Gtk.LinkButton({
  55. label: _("Report bugs or ideas"),
  56. uri: Me.metadata.url.toString()
  57. });
  58. aboutBox.pack_start(url_button, false, false, 0);
  59. aboutBox.pack_end(about_label, false, false, 0);
  60. this.pack_end(aboutBox, false, false, 0);
  61. //-------------------------
  62. let desacLabel = new Gtk.Label({
  63. label: _("This extension can be deactivated once your applications are organized as wished."),
  64. wrap: true,
  65. halign: Gtk.Align.CENTER
  66. });
  67. this.pack_end(desacLabel, false, false, 0);
  68. },
  69. add_section: function (titre) {
  70. let section = new Gtk.Box({
  71. orientation: Gtk.Orientation.VERTICAL,
  72. margin: 6,
  73. spacing: 6,
  74. });
  75. let frame = new Gtk.Frame({
  76. label: titre,
  77. label_xalign: 0.1,
  78. });
  79. frame.add(section);
  80. this.add(frame);
  81. return section;
  82. },
  83. add_row: function (filledbox, section) {
  84. section.add(filledbox);
  85. },
  86. build_switch: function (key, label) {
  87. let rowLabel = new Gtk.Label({
  88. label: label,
  89. halign: Gtk.Align.START,
  90. wrap: true,
  91. visible: true,
  92. });
  93. let rowSwitch = new Gtk.Switch({ valign: Gtk.Align.CENTER });
  94. rowSwitch.set_state(this._settings.get_boolean(key));
  95. rowSwitch.connect('notify::active', (widget) => {
  96. this._settings.set_boolean(key, widget.active);
  97. });
  98. let rowBox = new Gtk.Box({
  99. orientation: Gtk.Orientation.HORIZONTAL,
  100. spacing: 15,
  101. margin: 6,
  102. visible: true,
  103. });
  104. rowBox.pack_start(rowLabel, false, false, 0);
  105. rowBox.pack_end(rowSwitch, false, false, 0);
  106. return rowBox;
  107. },
  108. });
  109. //-----------------------------------------------
  110. function init() {
  111. Convenience.initTranslations();
  112. }
  113. //I guess this is like the "enable" in extension.js : something called each
  114. //time he user try to access the settings' window
  115. function buildPrefsWidget () {
  116. let widget = new appfoldersManagerSettingsWidget();
  117. widget.show_all();
  118. return widget;
  119. }