<commit_before>/*jshint moz:true */
// vi: sts=2 sw=2 et
//
// accelerator setting based on
// https://github.com/ambrice/spatialnavigation-tastycactus.com/blob/master/prefs.js

const Lang = imports.lang;
const Signals = imports.signals;

const Gtk = imports.gi.Gtk;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;

const Gettext = imports.gettext.domain('gnome-shell-screenshot');
const _ = Gettext.gettext;

const Local = imports.misc.extensionUtils.getCurrentExtension();
const Path = Local.imports.path;
const Config = Local.imports.config;
const Filename = Local.imports.filename;
const Convenience = Local.imports.convenience;



let _settings;


const buildHbox = () => {
  return new Gtk.Box({
    orientation: Gtk.Orientation.HORIZONTAL,
    margin_top: 5,
    expand: false
  });
};

const buildConfigSwitch = (label, configKey) => {
  let hbox = buildHbox();

  const gtkLabel = new Gtk.Label({
    label: label,
    xalign: 0,
    expand: true
  });

  const gtkSwitch = new Gtk.Switch();

  gtkSwitch.connect('notify::active', (button) => {
    _settings.set_boolean(configKey, button.active);
  });

  gtkSwitch.active = _settings.get_boolean(configKey);

  hbox.add(gtkLabel);
  hbox.add(gtkSwitch);

  return {
    hbox: hbox,
    gtkLabel: gtkLabel,
    gtkSwitch: gtkSwitch
  };
};

const bindSensitivity = (source, target) => {
  let set = () => {
    target.set_sensitive(source.active)
  };
  source.connect('notify::active', set);
  set();
}

const ScreenshotToolSettingsWidget = new GObject.Class({
  Name: 'ScreenshotToolSettingsWidget',
  GTypeName: 'ScreenshotToolSettingsWidget',
  Extends: Gtk.Box,

  _init: function (params) {
    this.parent(params);
    this._initLayout();
  },

  _initLayout: function () {
    let notebook = new Gtk.Notebook();

    let page, label;

    page = this._makePrefsIndicator();
    label = new Gtk.Label({label: _("Indicator")});
    notebook.append_page(page, label);

    page = this._makePrefsStorage();
    label = new Gtk.Label({label: _("Storage")});
    notebook.append_page(page, label);

    page = this._makePrefsUploadImgur();
    label = new Gtk.Label({label: _("Imgur Upload (Beta)")});
    notebook.append_page(page, label);

    page = this._makePrefsKeybindings();
    label = new Gtk.Label({label: _("Keybindings")});
    notebook.append_page(page, label);

    this.add(notebook);
  },

  _makePrefsIndicator: function () {
    let prefs = new Gtk.Box({
      orientation: Gtk.Orientation.VERTICAL,
      margin: 20,
      margin_top: 10,
      expand: false
    });

    let hbox;

    /* Show indicator [on|off] */

    let switchShowIndicator = buildConfigSwitch(
      _('Show indicator'),
      Config.KeyEnableIndicator
    );

    prefs.add(switchShowIndicator.hbox, {fill: false});


    /* Default click action [dropdown] */

    hbox = buildHbox();

    const labelDefaultClickAction = new Gtk.Label({
      label: _("Primary Button"),
      xalign: 0,
      expand: true
    });

    const clickActionOptions = [
      [_("Select Area")     , Config.ClickActions.SELECT_AREA],
      [_("Select Window")   , Config.ClickActions.SELECT_WINDOW],
      [_("Select Desktop")  , Config.ClickActions.SELECT_DESKTOP],
      [_("Show Menu")       , Config.ClickActions.SHOW_MENU]
    ];

    const currentClickAction = _settings.get_enum(Config.KeyClickAction);

    const comboBoxDefaultClickAction = this._getComboBox(
      clickActionOptions, GObject.TYPE_INT, currentClickAction,
      (value) => _settings.set_enum(Config.KeyClickAction, value)
    );

    hbox.add(labelDefaultClickAction);
    hbox.add(comboBoxDefaultClickAction);

    prefs.add(hbox, {fill: false});


    /* Clipboard Action [dropdown] */

    hbox = buildHbox();

    const labelClipboardContent = new Gtk.Label({
      label: _('Default Clipboard Content'),
      xalign: 0,
      expand: true
    });

    const comboBoxOptions = [
      [_("Unchanged")     , Config.ClipboardActions.NONE],
      [_("Image Data")    , Config.ClipboardActions.SET_IMAGE_DATA],
      // [_("Local Path")    , Config.ClipboardActions.SET_LOCAL_PATH]
      // TODO
      // [_("Remote URL")    , Config.ClipboardActions.SET_REMOTE_URL]
    ];


    const currentClipboardAction =
      _settings.get_string(Config.KeyClipboardAction);

    const comboBoxClipboardContent = this._getComboBox(
      comboBoxOptions, GObject.TYPE_STRING, currentClipboardAction,
      (value) => _settings.set_string(Config.KeyClipboardAction, value)
    );

    hbox.add(labelClipboardContent);
    hbox.add(comboBoxClipboardContent);

    prefs.add(hbox, {fill: false});

    return prefs;
  },

  _makePrefsStorage: function () {
    let prefs = new Gtk.Box({
      orientation: Gtk.Orientation.VERTICAL,
      margin: 20,
      margin_top: 10,
      expand: false
    });

    let hbox;

    /* Save Screenshot [on|off] */

    const switchSaveScreenshot = buildConfigSwitch(
      _('Auto-Save Screenshot'), Config.KeySaveScreenshot
    );

    prefs.add(switchSaveScreenshot.hbox, {fill: false});<commit_msg>Rename "Default Clipboard Content" to "Auto-Copy"<commit_after>/*jshint moz:true */
// vi: sts=2 sw=2 et
//
// accelerator setting based on
// https://github.com/ambrice/spatialnavigation-tastycactus.com/blob/master/prefs.js

const Lang = imports.lang;
const Signals = imports.signals;

const Gtk = imports.gi.Gtk;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;

const Gettext = imports.gettext.domain('gnome-shell-screenshot');
const _ = Gettext.gettext;

const Local = imports.misc.extensionUtils.getCurrentExtension();
const Path = Local.imports.path;
const Config = Local.imports.config;
const Filename = Local.imports.filename;
const Convenience = Local.imports.convenience;



let _settings;


const buildHbox = () => {
  return new Gtk.Box({
    orientation: Gtk.Orientation.HORIZONTAL,
    margin_top: 5,
    expand: false
  });
};

const buildConfigSwitch = (label, configKey) => {
  let hbox = buildHbox();

  const gtkLabel = new Gtk.Label({
    label: label,
    xalign: 0,
    expand: true
  });

  const gtkSwitch = new Gtk.Switch();

  gtkSwitch.connect('notify::active', (button) => {
    _settings.set_boolean(configKey, button.active);
  });

  gtkSwitch.active = _settings.get_boolean(configKey);

  hbox.add(gtkLabel);
  hbox.add(gtkSwitch);

  return {
    hbox: hbox,
    gtkLabel: gtkLabel,
    gtkSwitch: gtkSwitch
  };
};

const bindSensitivity = (source, target) => {
  let set = () => {
    target.set_sensitive(source.active)
  };
  source.connect('notify::active', set);
  set();
}

const ScreenshotToolSettingsWidget = new GObject.Class({
  Name: 'ScreenshotToolSettingsWidget',
  GTypeName: 'ScreenshotToolSettingsWidget',
  Extends: Gtk.Box,

  _init: function (params) {
    this.parent(params);
    this._initLayout();
  },

  _initLayout: function () {
    let notebook = new Gtk.Notebook();

    let page, label;

    page = this._makePrefsIndicator();
    label = new Gtk.Label({label: _("Indicator")});
    notebook.append_page(page, label);

    page = this._makePrefsStorage();
    label = new Gtk.Label({label: _("Storage")});
    notebook.append_page(page, label);

    page = this._makePrefsUploadImgur();
    label = new Gtk.Label({label: _("Imgur Upload (Beta)")});
    notebook.append_page(page, label);

    page = this._makePrefsKeybindings();
    label = new Gtk.Label({label: _("Keybindings")});
    notebook.append_page(page, label);

    this.add(notebook);
  },

  _makePrefsIndicator: function () {
    let prefs = new Gtk.Box({
      orientation: Gtk.Orientation.VERTICAL,
      margin: 20,
      margin_top: 10,
      expand: false
    });

    let hbox;

    /* Show indicator [on|off] */

    let switchShowIndicator = buildConfigSwitch(
      _('Show indicator'),
      Config.KeyEnableIndicator
    );

    prefs.add(switchShowIndicator.hbox, {fill: false});


    /* Default click action [dropdown] */

    hbox = buildHbox();

    const labelDefaultClickAction = new Gtk.Label({
      label: _("Primary Button"),
      xalign: 0,
      expand: true
    });

    const clickActionOptions = [
      [_("Select Area")     , Config.ClickActions.SELECT_AREA],
      [_("Select Window")   , Config.ClickActions.SELECT_WINDOW],
      [_("Select Desktop")  , Config.ClickActions.SELECT_DESKTOP],
      [_("Show Menu")       , Config.ClickActions.SHOW_MENU]
    ];

    const currentClickAction = _settings.get_enum(Config.KeyClickAction);

    const comboBoxDefaultClickAction = this._getComboBox(
      clickActionOptions, GObject.TYPE_INT, currentClickAction,
      (value) => _settings.set_enum(Config.KeyClickAction, value)
    );

    hbox.add(labelDefaultClickAction);
    hbox.add(comboBoxDefaultClickAction);

    prefs.add(hbox, {fill: false});


    /* Clipboard Action [dropdown] */

    hbox = buildHbox();

    const labelAutoCopy = new Gtk.Label({
      label: _('Auto-Copy to Clipboard'),
      xalign: 0,
      expand: true
    });

    const comboBoxOptions = [
      [_("Nothing")       , Config.ClipboardActions.NONE],
      [_("Image Data")    , Config.ClipboardActions.SET_IMAGE_DATA],
      // [_("Local Path")    , Config.ClipboardActions.SET_LOCAL_PATH]
      // TODO
      // [_("Remote URL")    , Config.ClipboardActions.SET_REMOTE_URL]
    ];


    const currentClipboardAction =
      _settings.get_string(Config.KeyClipboardAction);

    const comboBoxClipboardContent = this._getComboBox(
      comboBoxOptions, GObject.TYPE_STRING, currentClipboardAction,
      (value) => _settings.set_string(Config.KeyClipboardAction, value)
    );

    hbox.add(labelAutoCopy);
    hbox.add(comboBoxClipboardContent);

    prefs.add(hbox, {fill: false});

    return prefs;
  },

  _makePrefsStorage: function () {
    let prefs = new Gtk.Box({
      orientation: Gtk.Orientation.VERTICAL,
      margin: 20,
      margin_top: 10,
      expand: false
    });

    let hbox;

    /* Save Screenshot [on|off] */

    const switchSaveScreenshot = buildConfigSwitch(
      _('Auto-Save Screenshot'), Config.KeySaveScreenshot
    );

    prefs.add(switchSaveScreenshot.hbox, {fill: false});
{'fraction_non_alphanumeric': 0.1326359419717754, 'fraction_numerical': 0.002763248791078654, 'mean_word_length': 3.341902313624679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1943271', 'n_tokens_mistral': 3414, 'n_tokens_neox': 3225, 'n_words': 640}