2019-03-05 08:36:59 -03:00
/* jslint esversion: 6 */
2020-09-08 15:11:57 -03:00
/* exported init, buildPrefsWidget */
2019-03-05 08:36:59 -03:00
/ *
* Copyright 2019 Abakkk
*
2019-12-28 09:25:41 -03:00
* This file is part of DrawOnYourScreen , a drawing extension for GNOME Shell .
2019-03-05 08:36:59 -03:00
* https : //framagit.org/abakkk/DrawOnYourScreen
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
2020-09-01 08:43:30 -03:00
const Atk = imports . gi . Atk ;
2020-08-31 04:43:00 -03:00
const Gdk = imports . gi . Gdk ;
2020-09-10 23:06:21 -03:00
const Gio = imports . gi . Gio ;
2020-06-18 20:35:25 -03:00
const GLib = imports . gi . GLib ;
2019-03-05 08:36:59 -03:00
const GObject = imports . gi . GObject ;
const Gtk = imports . gi . Gtk ;
const ExtensionUtils = imports . misc . extensionUtils ;
2020-01-05 11:44:51 -03:00
const Me = ExtensionUtils . getCurrentExtension ( ) ;
const Convenience = ExtensionUtils . getSettings && ExtensionUtils . initTranslations ? ExtensionUtils : Me . imports . convenience ;
2020-09-22 12:31:48 -03:00
const GimpPaletteParser = Me . imports . gimpPaletteParser ;
2020-09-10 10:55:19 -03:00
const Shortcuts = Me . imports . shortcuts ;
2020-08-31 04:43:00 -03:00
const gettext = imports . gettext . domain ( Me . metadata [ 'gettext-domain' ] ) . gettext ;
const _ = function ( string ) {
if ( ! string )
return "" ;
return gettext ( string ) ;
} ;
2019-03-28 10:59:14 -03:00
const _GTK = imports . gettext . domain ( 'gtk30' ) . gettext ;
2019-03-05 08:36:59 -03:00
const MARGIN = 10 ;
2020-09-01 08:43:30 -03:00
const ROWBOX _MARGIN _PARAMS = { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _left : MARGIN , margin _right : MARGIN } ;
2020-09-25 06:55:36 -03:00
// GTypeName is not sanitized in GS 3.28-
const sanitizeGType = function ( name ) {
return ` Gjs_ ${ name . replace ( /@/gi , '_at_' ) . replace ( /[^a-z0-9+_-]/gi , '_' ) } ` ;
}
2019-03-05 08:36:59 -03:00
function init ( ) {
Convenience . initTranslations ( ) ;
}
2019-03-28 10:59:14 -03:00
function buildPrefsWidget ( ) {
let topStack = new TopStack ( ) ;
let switcher = new Gtk . StackSwitcher ( { halign : Gtk . Align . CENTER , visible : true , stack : topStack } ) ;
2020-06-22 07:16:17 -03:00
GLib . idle _add ( GLib . PRIORITY _DEFAULT _IDLE , ( ) => {
2019-03-28 10:59:14 -03:00
let window = topStack . get _toplevel ( ) ;
let headerBar = window . get _titlebar ( ) ;
headerBar . custom _title = switcher ;
return false ;
} ) ;
topStack . show _all ( ) ;
return topStack ;
}
2020-03-02 12:32:50 -03:00
const TopStack = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .TopStack ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -TopStack ` ) ,
2019-03-28 10:59:14 -03:00
Extends : Gtk . Stack ,
_init : function ( params ) {
this . parent ( { transition _type : 1 , transition _duration : 500 , expand : true } ) ;
this . prefsPage = new PrefsPage ( ) ;
2020-09-08 15:11:57 -03:00
// Translators: "Preferences" page in preferences
2019-03-28 10:59:14 -03:00
this . add _titled ( this . prefsPage , 'prefs' , _ ( "Preferences" ) ) ;
2020-08-31 04:43:00 -03:00
this . drawingPage = new DrawingPage ( ) ;
2020-09-08 15:11:57 -03:00
// Translators: "Drawing" page in preferences
2020-08-31 04:43:00 -03:00
this . add _titled ( this . drawingPage , 'drawing' , _ ( "Drawing" ) ) ;
2019-03-28 10:59:14 -03:00
this . aboutPage = new AboutPage ( ) ;
2020-09-08 15:11:57 -03:00
// Translators: "About" page in preferences
2019-03-28 10:59:14 -03:00
this . add _titled ( this . aboutPage , 'about' , _ ( "About" ) ) ;
}
} ) ;
2020-03-02 12:32:50 -03:00
const AboutPage = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .AboutPage ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -AboutPage ` ) ,
2019-03-28 10:59:14 -03:00
Extends : Gtk . ScrolledWindow ,
_init : function ( params ) {
2020-08-31 04:43:00 -03:00
this . parent ( { hscrollbar _policy : Gtk . PolicyType . NEVER } ) ;
2019-03-28 10:59:14 -03:00
2020-09-01 08:43:30 -03:00
let vbox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin : MARGIN * 3 } ) ;
2019-03-28 10:59:14 -03:00
this . add ( vbox ) ;
2020-09-08 15:11:57 -03:00
// Translators: you are free to translate the extension name, that is displayed in About page, or not
let name = "<b> " + _ ( "Draw On You Screen" ) + "</b>" ;
// Translators: version number in "About" page
2020-09-17 16:59:38 -03:00
let version = _ ( "Version %f" ) . format ( Me . metadata . version ) ;
2020-09-08 15:11:57 -03:00
// Translators: you are free to translate the extension description, that is displayed in About page, or not
let description = _ ( "Start drawing with Super+Alt+D and save your beautiful work by taking a screenshot" ) ;
2020-01-06 11:29:01 -03:00
let link = "<span><a href=\"" + Me . metadata . url + "\">" + Me . metadata . url + "</a></span>" ;
2019-03-28 10:59:14 -03:00
let licenceName = _GTK ( "GNU General Public License, version 2 or later" ) ;
let licenceLink = "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html" ;
let licence = "<small>" + _GTK ( "This program comes with absolutely no warranty.\nSee the <a href=\"%s\">%s</a> for details." ) . format ( licenceLink , licenceName ) + "</small>" ;
let aboutLabel = new Gtk . Label ( { wrap : true , justify : 2 , use _markup : true , label :
name + "\n\n" + version + "\n\n" + description + "\n\n" + link + "\n\n" + licence + "\n" } ) ;
vbox . add ( aboutLabel ) ;
2020-09-01 08:43:30 -03:00
let creditBox = new Gtk . Box ( { orientation : Gtk . Orientation . HORIZONTAL , margin : 2 * MARGIN } ) ;
2019-03-28 10:59:14 -03:00
let leftBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let rightBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let leftLabel = new Gtk . Label ( { wrap : true , valign : 1 , halign : 2 , justify : 1 , use _markup : true , label : "<small>" + _GTK ( "Created by" ) + "</small>" } ) ;
let rightLabel = new Gtk . Label ( { wrap : true , valign : 1 , halign : 1 , justify : 0 , use _markup : true , label : "<small><a href=\"https://framagit.org/abakkk\">Abakkk</a></small>" } ) ;
2019-04-01 16:05:18 -03:00
leftBox . pack _start ( leftLabel , false , false , 0 ) ;
rightBox . pack _start ( rightLabel , false , false , 0 ) ;
2019-03-28 10:59:14 -03:00
creditBox . pack _start ( leftBox , true , true , 5 ) ;
creditBox . pack _start ( rightBox , true , true , 5 ) ;
vbox . add ( creditBox ) ;
2020-09-08 15:11:57 -03:00
// Translators: add your name here or keep it empty, it will be displayed in about page, e.g.
// msgstr ""
// "translator1\n"
// "<a href=\"mailto:translator2@mail.org\">translator2</a>\n"
// "<a href=\"https://...\">translator3</a>"
2020-02-09 14:03:36 -03:00
if ( _ ( "translator-credits" ) != "translator-credits" && _ ( "translator-credits" ) != "" ) {
2019-04-01 16:05:18 -03:00
leftBox . pack _start ( new Gtk . Label ( ) , false , false , 0 ) ;
rightBox . pack _start ( new Gtk . Label ( ) , false , false , 0 ) ;
2019-03-28 10:59:14 -03:00
leftLabel = new Gtk . Label ( { wrap : true , valign : 1 , halign : 2 , justify : 1 , use _markup : true , label : "<small>" + _GTK ( "Translated by" ) + "</small>" } ) ;
2020-02-09 14:03:36 -03:00
rightLabel = new Gtk . Label ( { wrap : true , valign : 1 , halign : 1 , justify : 0 , use _markup : true , label : "<small>" + _ ( "translator-credits" ) + "</small>" } ) ;
2019-04-01 16:05:18 -03:00
leftBox . pack _start ( leftLabel , false , false , 0 ) ;
rightBox . pack _start ( rightLabel , false , false , 0 ) ;
2019-03-28 10:59:14 -03:00
}
}
} ) ;
2020-08-31 04:43:00 -03:00
const DrawingPage = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .DrawingPage ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -DrawingPage ` ) ,
2020-08-31 04:43:00 -03:00
Extends : Gtk . ScrolledWindow ,
_init : function ( params ) {
this . parent ( { hscrollbar _policy : Gtk . PolicyType . NEVER } ) ;
this . settings = Convenience . getSettings ( Me . metadata [ 'settings-schema' ] + '.drawing' ) ;
this . schema = this . settings . settings _schema ;
2020-09-01 08:43:30 -03:00
let box = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin : 3 * MARGIN , spacing : 3 * MARGIN } ) ;
2020-08-31 04:43:00 -03:00
this . add ( box ) ;
2020-09-01 08:43:30 -03:00
let palettesFrame = new Frame ( { label : _ ( "Palettes" ) } ) ;
2020-08-31 04:43:00 -03:00
box . add ( palettesFrame ) ;
2020-09-22 12:31:48 -03:00
let palettesFrameBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
palettesFrame . add ( palettesFrameBox ) ;
2020-08-31 04:43:00 -03:00
2020-09-22 12:31:48 -03:00
let palettesScrolledWindow = new Gtk . ScrolledWindow ( { vscrollbar _policy : Gtk . PolicyType . NEVER } ) ;
palettesFrameBox . add ( palettesScrolledWindow ) ;
let palettesViewport = new Gtk . Viewport ( { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 } ) ;
palettesScrolledWindow . add ( palettesViewport ) ;
2020-08-31 04:43:00 -03:00
this . palettesListBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true } ) ;
this . palettesListBox . get _style _context ( ) . add _class ( 'background' ) ;
2020-09-01 08:43:30 -03:00
this . palettesListBox . get _accessible ( ) . set _name ( this . schema . get _key ( 'palettes' ) . get _summary ( ) ) ;
this . palettesListBox . get _accessible ( ) . set _description ( this . schema . get _key ( 'palettes' ) . get _description ( ) ) ;
2020-09-22 12:31:48 -03:00
palettesViewport . add ( this . palettesListBox ) ;
2020-08-31 04:43:00 -03:00
this . settings . connect ( 'changed::palettes' , this . _updatePalettes . bind ( this ) ) ;
this . _updatePalettes ( ) ;
2020-09-22 12:31:48 -03:00
let addBox = new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ;
2020-08-31 04:43:00 -03:00
let addButton = Gtk . Button . new _from _icon _name ( 'list-add-symbolic' , Gtk . IconSize . BUTTON ) ;
2020-09-01 08:43:30 -03:00
addButton . set _tooltip _text ( _ ( "Add a new palette" ) ) ;
2020-09-22 12:31:48 -03:00
addBox . pack _start ( addButton , true , true , 4 ) ;
2020-08-31 04:43:00 -03:00
addButton . connect ( 'clicked' , this . _addNewPalette . bind ( this ) ) ;
2020-09-22 12:31:48 -03:00
let importButton = Gtk . Button . new _from _icon _name ( 'document-open-symbolic' , Gtk . IconSize . BUTTON ) ;
importButton . set _tooltip _text ( _GTK ( "Select a File" ) ) ;
addBox . pack _start ( importButton , true , true , 4 ) ;
importButton . connect ( 'clicked' , this . _importPalette . bind ( this ) ) ;
palettesFrameBox . add ( addBox ) ;
2020-08-31 04:43:00 -03:00
2020-09-01 08:43:30 -03:00
let areaFrame = new Frame ( { label : _ ( "Area" ) } ) ;
2020-08-31 04:43:00 -03:00
box . add ( areaFrame ) ;
2020-09-01 08:43:30 -03:00
let areaListBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 } ) ;
2020-08-31 04:43:00 -03:00
areaListBox . get _style _context ( ) . add _class ( 'background' ) ;
areaFrame . add ( areaListBox ) ;
2020-09-01 08:43:30 -03:00
let squareAreaRow = new PrefRow ( { label : this . schema . get _key ( 'square-area-size' ) . get _summary ( ) } ) ;
let squareAreaAutoButton = new Gtk . CheckButton ( { label : _ ( "Auto" ) ,
name : this . schema . get _key ( 'square-area-auto' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'square-area-auto' ) . get _description ( ) } ) ;
2020-09-09 07:12:29 -03:00
let squareAreaSizeButton = new PixelSpinButton ( { width _chars : 5 , digits : 0 , step : 1 ,
range : this . schema . get _key ( 'square-area-size' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'square-area-size' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'square-area-size' ) . get _description ( ) } ) ;
2020-08-31 04:43:00 -03:00
this . settings . bind ( 'square-area-auto' , squareAreaAutoButton , 'active' , 0 ) ;
this . settings . bind ( 'square-area-size' , squareAreaSizeButton , 'value' , 0 ) ;
squareAreaAutoButton . bind _property ( 'active' , squareAreaSizeButton , 'sensitive' , GObject . BindingFlags . SYNC _CREATE | GObject . BindingFlags . INVERT _BOOLEAN ) ;
squareAreaRow . addWidget ( squareAreaAutoButton ) ;
squareAreaRow . addWidget ( squareAreaSizeButton ) ;
areaListBox . add ( squareAreaRow ) ;
2020-09-01 08:43:30 -03:00
let backgroundColorRow = new PrefRow ( { label : this . schema . get _key ( 'background-color' ) . get _summary ( ) } ) ;
2020-08-31 04:43:00 -03:00
let backgroundColorButton = new ColorStringButton ( { use _alpha : true , show _editor : true ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'background-color' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'background-color' ) . get _description ( ) } ) ;
this . settings . bind ( 'background-color' , backgroundColorButton , 'color-string' , 0 ) ;
2020-08-31 04:43:00 -03:00
backgroundColorRow . addWidget ( backgroundColorButton ) ;
areaListBox . add ( backgroundColorRow ) ;
let gridLineRow = new PrefRow ( { label : _ ( "Grid overlay line" ) } ) ;
2020-09-01 08:43:30 -03:00
let gridLineAutoButton = new Gtk . CheckButton ( { label : _ ( "Auto" ) ,
name : this . schema . get _key ( 'grid-line-auto' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'grid-line-auto' ) . get _description ( ) } ) ;
2020-09-09 07:12:29 -03:00
let gridLineWidthButton = new PixelSpinButton ( { width _chars : 5 , digits : 1 , step : 0.1 ,
range : this . schema . get _key ( 'grid-line-width' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'grid-line-width' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'grid-line-width' ) . get _description ( ) } ) ;
2020-09-09 07:12:29 -03:00
let gridLineSpacingButton = new PixelSpinButton ( { width _chars : 5 , digits : 1 , step : 1 ,
range : this . schema . get _key ( 'grid-line-spacing' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'grid-line-spacing' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'grid-line-spacing' ) . get _description ( ) } ) ;
2020-08-31 04:43:00 -03:00
this . settings . bind ( 'grid-line-auto' , gridLineAutoButton , 'active' , 0 ) ;
this . settings . bind ( 'grid-line-width' , gridLineWidthButton , 'value' , 0 ) ;
this . settings . bind ( 'grid-line-spacing' , gridLineSpacingButton , 'value' , 0 ) ;
gridLineAutoButton . bind _property ( 'active' , gridLineWidthButton , 'sensitive' , GObject . BindingFlags . SYNC _CREATE | GObject . BindingFlags . INVERT _BOOLEAN ) ;
gridLineAutoButton . bind _property ( 'active' , gridLineSpacingButton , 'sensitive' , GObject . BindingFlags . SYNC _CREATE | GObject . BindingFlags . INVERT _BOOLEAN ) ;
gridLineRow . addWidget ( gridLineAutoButton ) ;
gridLineRow . addWidget ( gridLineWidthButton ) ;
gridLineRow . addWidget ( gridLineSpacingButton ) ;
areaListBox . add ( gridLineRow ) ;
2020-09-01 08:43:30 -03:00
let gridColorRow = new PrefRow ( { label : this . schema . get _key ( 'grid-color' ) . get _summary ( ) } ) ;
2020-08-31 04:43:00 -03:00
let gridColorButton = new ColorStringButton ( { use _alpha : true , show _editor : true ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'grid-color' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'grid-color' ) . get _description ( ) } ) ;
2020-08-31 04:43:00 -03:00
this . settings . bind ( 'grid-color' , gridColorButton , 'color-string' , 0 ) ;
gridColorRow . addWidget ( gridColorButton ) ;
areaListBox . add ( gridColorRow ) ;
2020-09-01 08:43:30 -03:00
let toolsFrame = new Frame ( { label : _ ( "Tools" ) } ) ;
2020-08-31 04:43:00 -03:00
box . add ( toolsFrame ) ;
2020-09-01 08:43:30 -03:00
let toolsListBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 } ) ;
2020-08-31 04:43:00 -03:00
toolsListBox . get _style _context ( ) . add _class ( 'background' ) ;
toolsFrame . add ( toolsListBox ) ;
let dashArrayRow = new PrefRow ( { label : _ ( "Dash array" ) } ) ;
2020-09-01 08:43:30 -03:00
let dashArrayAutoButton = new Gtk . CheckButton ( { label : _ ( "Auto" ) ,
name : this . schema . get _key ( 'dash-array-auto' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'dash-array-auto' ) . get _description ( ) } ) ;
2020-09-09 07:12:29 -03:00
let dashArrayOnButton = new PixelSpinButton ( { width _chars : 5 , digits : 1 , step : 0.1 ,
range : this . schema . get _key ( 'dash-array-on' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'dash-array-on' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'dash-array-on' ) . get _description ( ) } ) ;
2020-09-09 07:12:29 -03:00
let dashArrayOffButton = new PixelSpinButton ( { width _chars : 5 , digits : 1 , step : 0.1 ,
range : this . schema . get _key ( 'dash-array-off' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'dash-array-off' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'dash-array-off' ) . get _description ( ) } ) ;
2020-08-31 04:43:00 -03:00
this . settings . bind ( 'dash-array-auto' , dashArrayAutoButton , 'active' , 0 ) ;
this . settings . bind ( 'dash-array-on' , dashArrayOnButton , 'value' , 0 ) ;
this . settings . bind ( 'dash-array-off' , dashArrayOffButton , 'value' , 0 ) ;
dashArrayAutoButton . bind _property ( 'active' , dashArrayOnButton , 'sensitive' , GObject . BindingFlags . SYNC _CREATE | GObject . BindingFlags . INVERT _BOOLEAN ) ;
dashArrayAutoButton . bind _property ( 'active' , dashArrayOffButton , 'sensitive' , GObject . BindingFlags . SYNC _CREATE | GObject . BindingFlags . INVERT _BOOLEAN ) ;
dashArrayRow . addWidget ( dashArrayAutoButton ) ;
dashArrayRow . addWidget ( dashArrayOnButton ) ;
dashArrayRow . addWidget ( dashArrayOffButton ) ;
toolsListBox . add ( dashArrayRow ) ;
2020-09-01 08:43:30 -03:00
let dashOffsetRow = new PrefRow ( { label : this . schema . get _key ( 'dash-offset' ) . get _summary ( ) } ) ;
2020-09-09 07:12:29 -03:00
let dashOffsetButton = new PixelSpinButton ( { width _chars : 5 , digits : 1 , step : 0.1 ,
range : this . schema . get _key ( 'dash-offset' ) . get _range ( ) ,
2020-09-01 08:43:30 -03:00
name : this . schema . get _key ( 'dash-offset' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'dash-offset' ) . get _description ( ) } ) ;
2020-08-31 04:43:00 -03:00
this . settings . bind ( 'dash-offset' , dashOffsetButton , 'value' , 0 ) ;
dashOffsetRow . addWidget ( dashOffsetButton ) ;
toolsListBox . add ( dashOffsetRow ) ;
2020-09-02 16:13:23 -03:00
2020-09-10 23:06:21 -03:00
let imageLocationRow = new PrefRow ( { label : this . schema . get _key ( 'image-location' ) . get _summary ( ) } ) ;
let imageLocationButton = new FileChooserButton ( { action : Gtk . FileChooserAction . SELECT _FOLDER ,
name : this . schema . get _key ( 'image-location' ) . get _summary ( ) ,
tooltip _text : this . schema . get _key ( 'image-location' ) . get _description ( ) } ) ;
this . settings . bind ( 'image-location' , imageLocationButton , 'location' , 0 ) ;
imageLocationRow . addWidget ( imageLocationButton ) ;
toolsListBox . add ( imageLocationRow ) ;
2020-09-02 16:13:23 -03:00
let resetButton = new Gtk . Button ( { label : _ ( "Reset settings" ) , halign : Gtk . Align . CENTER } ) ;
resetButton . get _style _context ( ) . add _class ( 'destructive-action' ) ;
resetButton . connect ( 'clicked' , ( ) => this . schema . list _keys ( ) . forEach ( key => this . settings . reset ( key ) ) ) ;
box . add ( resetButton ) ;
2020-08-31 04:43:00 -03:00
} ,
_updatePalettes : function ( ) {
this . palettes = this . settings . get _value ( 'palettes' ) . deep _unpack ( ) ;
2020-09-22 12:31:48 -03:00
this . palettesListBox . get _children ( ) . slice ( this . palettes . length )
2020-08-31 04:43:00 -03:00
. forEach ( row => this . palettesListBox . remove ( row ) ) ;
2020-09-22 12:31:48 -03:00
let paletteBoxes = this . palettesListBox . get _children ( ) . map ( row => row . get _child ( ) ) ;
2020-08-31 04:43:00 -03:00
this . palettes . forEach ( ( palette , paletteIndex ) => {
let [ name , colors ] = palette ;
let paletteBox ;
if ( paletteBoxes [ paletteIndex ] ) {
paletteBox = paletteBoxes [ paletteIndex ] ;
let nameEntry = paletteBox . get _children ( ) [ 0 ] ;
if ( nameEntry . get _text ( ) !== _ ( name ) ) {
GObject . signal _handler _block ( nameEntry , nameEntry . paletteNameChangedHandler ) ;
nameEntry . set _text ( _ ( name ) ) ;
GObject . signal _handler _unblock ( nameEntry , nameEntry . paletteNameChangedHandler ) ;
}
} else {
let nameEntry = new Gtk . Entry ( { text : name , halign : Gtk . Align . START , tooltip _text : _ ( "Rename the palette" ) } ) ;
nameEntry . paletteNameChangedHandler = nameEntry . connect ( 'changed' , this . _onPaletteNameChanged . bind ( this , paletteIndex ) ) ;
let removeButton = Gtk . Button . new _from _icon _name ( 'list-remove-symbolic' , Gtk . IconSize . BUTTON ) ;
removeButton . set _tooltip _text ( _ ( "Remove the palette" ) ) ;
removeButton . connect ( 'clicked' , this . _removePalette . bind ( this , paletteIndex ) ) ;
2020-09-01 08:43:30 -03:00
paletteBox = new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ;
2020-08-31 04:43:00 -03:00
paletteBox . pack _start ( nameEntry , true , true , 4 ) ;
paletteBox . pack _start ( new Gtk . Box ( { spacing : 4 } ) , false , false , 4 ) ;
paletteBox . pack _start ( removeButton , false , false , 4 ) ;
this . palettesListBox . insert ( paletteBox , paletteIndex ) ;
paletteBox . get _parent ( ) . set _activatable ( false ) ;
}
while ( colors . length < 9 )
colors . push ( 'transparent' ) ;
let colorsBox = paletteBox . get _children ( ) [ 1 ] ;
let colorButtons = colorsBox . get _children ( ) ;
colors . forEach ( ( color , colorIndex ) => {
2020-09-22 12:31:48 -03:00
let [ colorString , displayName ] = color . split ( ':' ) ;
2020-08-31 04:43:00 -03:00
if ( colorButtons [ colorIndex ] ) {
2020-09-22 12:31:48 -03:00
colorButtons [ colorIndex ] . color _string = colorString ;
colorButtons [ colorIndex ] . tooltip _text = displayName || null ;
2020-08-31 04:43:00 -03:00
} else {
2020-09-22 12:31:48 -03:00
let colorButton = new ColorStringButton ( { color _string : colorString , tooltip _text : displayName || null ,
use _alpha : true , show _editor : true ,
halign : Gtk . Align . START , hexpand : false } ) ;
2020-08-31 04:43:00 -03:00
colorButton . connect ( 'notify::color-string' , this . _onPaletteColorChanged . bind ( this , paletteIndex , colorIndex ) ) ;
colorsBox . add ( colorButton ) ;
}
} ) ;
paletteBox . show _all ( ) ;
} ) ;
} ,
_savePalettes : function ( ) {
this . settings . set _value ( 'palettes' , new GLib . Variant ( 'a(sas)' , this . palettes ) ) ;
} ,
_onPaletteNameChanged : function ( index , entry ) {
this . palettes [ index ] [ 0 ] = entry . get _text ( ) ;
this . _savePalettes ( ) ;
} ,
_onPaletteColorChanged : function ( paletteIndex , colorIndex , colorButton ) {
this . palettes [ paletteIndex ] [ 1 ] [ colorIndex ] = colorButton . get _rgba ( ) . to _string ( ) ;
2020-09-22 12:31:48 -03:00
if ( colorButton . tooltip _text )
this . palettes [ paletteIndex ] [ 1 ] [ colorIndex ] += ` : ${ colorButton . tooltip _text } ` ;
2020-08-31 04:43:00 -03:00
this . _savePalettes ( ) ;
} ,
_addNewPalette : function ( ) {
let colors = Array ( 9 ) . fill ( 'Black' ) ;
2020-09-08 15:11:57 -03:00
// Translators: default name of a new palette
2020-08-31 04:43:00 -03:00
this . palettes . push ( [ _ ( "New palette" ) , colors ] ) ;
this . _savePalettes ( ) ;
} ,
2020-09-22 12:31:48 -03:00
_importPalette : function ( ) {
let dialog = new Gtk . FileChooserNative ( { action : Gtk . FileChooserAction . OPEN , title : _GTK ( "Select a File" ) } ) ;
let filter = new Gtk . FileFilter ( ) ;
filter . set _name ( "GIMP Palette (*.gpl)" ) ;
filter . add _pattern ( '*.gpl' ) ;
dialog . add _filter ( filter ) ;
if ( dialog . run ( ) == Gtk . ResponseType . ACCEPT ) {
let file = dialog . get _file ( ) ;
let palettes = GimpPaletteParser . parseFile ( file ) ;
palettes . forEach ( palette => this . palettes . push ( palette ) ) ;
this . _savePalettes ( ) ;
}
} ,
2020-08-31 04:43:00 -03:00
_removePalette : function ( paletteIndex ) {
this . palettes . splice ( paletteIndex , 1 ) ;
this . _savePalettes ( ) ;
}
} ) ;
2020-03-02 12:32:50 -03:00
const PrefsPage = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .PrefsPage ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -PrefsPage ` ) ,
2019-03-05 08:36:59 -03:00
Extends : Gtk . ScrolledWindow ,
_init : function ( params ) {
2020-08-31 04:43:00 -03:00
this . parent ( { hscrollbar _policy : Gtk . PolicyType . NEVER } ) ;
2019-03-05 08:36:59 -03:00
2020-08-23 06:49:26 -03:00
let settings = Convenience . getSettings ( ) ;
2020-09-01 08:43:30 -03:00
let schema = settings . settings _schema ;
2020-08-23 06:49:26 -03:00
let internalShortcutSettings = Convenience . getSettings ( Me . metadata [ 'settings-schema' ] + '.internal-shortcuts' ) ;
2019-03-05 08:36:59 -03:00
2020-09-01 08:43:30 -03:00
let box = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin : MARGIN * 3 , spacing : 3 * MARGIN } ) ;
2019-03-05 08:36:59 -03:00
this . add ( box ) ;
2020-09-01 08:43:30 -03:00
let globalFrame = new Frame ( { label : _ ( "Global" ) } ) ;
2020-01-07 18:15:18 -03:00
box . add ( globalFrame ) ;
2020-09-02 16:13:23 -03:00
let listBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN , margin _bottom : MARGIN / 2 } ) ;
2020-09-01 08:43:30 -03:00
listBox . get _style _context ( ) . add _class ( 'background' ) ;
2020-01-07 18:15:18 -03:00
globalFrame . add ( listBox ) ;
2019-03-05 08:36:59 -03:00
2020-09-08 15:11:57 -03:00
Shortcuts . GLOBAL _KEYBINDINGS . forEach ( ( settingKeys , index ) => {
if ( index )
listBox . add ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ) ;
let globalKeybindingsRow = new Gtk . ListBoxRow ( { activatable : false } ) ;
let globalKeybindingsWidget = new KeybindingsWidget ( settingKeys , settings ) ;
globalKeybindingsRow . add ( globalKeybindingsWidget ) ;
listBox . add ( globalKeybindingsRow ) ;
} ) ;
2020-09-01 08:43:30 -03:00
2020-09-17 12:30:30 -03:00
let persistentOverTogglesKey = schema . get _key ( 'persistent-over-toggles' ) ;
let persistentOverTogglesRow = new PrefRow ( { label : persistentOverTogglesKey . get _summary ( ) , desc : persistentOverTogglesKey . get _description ( ) } ) ;
let persistentOverTogglesSwitch = new Gtk . Switch ( ) ;
settings . bind ( 'persistent-over-toggles' , persistentOverTogglesSwitch , 'active' , 0 ) ;
persistentOverTogglesRow . addWidget ( persistentOverTogglesSwitch , true ) ;
listBox . add ( persistentOverTogglesRow ) ;
let persistentOverRestartsKey = schema . get _key ( 'persistent-over-restarts' ) ;
let persistentOverRestartsRow = new PrefRow ( { label : persistentOverRestartsKey . get _summary ( ) , desc : persistentOverRestartsKey . get _description ( ) } ) ;
let persistentOverRestartsSwitch = new Gtk . Switch ( ) ;
settings . bind ( 'persistent-over-restarts' , persistentOverRestartsSwitch , 'active' , 0 ) ;
persistentOverRestartsRow . addWidget ( persistentOverRestartsSwitch , true ) ;
persistentOverTogglesSwitch . bind _property ( 'active' , persistentOverRestartsSwitch , 'sensitive' , GObject . BindingFlags . SYNC _CREATE ) ;
listBox . add ( persistentOverRestartsRow ) ;
2020-09-01 08:43:30 -03:00
let desktopKey = schema . get _key ( 'drawing-on-desktop' ) ;
let desktopRow = new PrefRow ( { label : desktopKey . get _summary ( ) , desc : desktopKey . get _description ( ) } ) ;
let desktopSwitch = new Gtk . Switch ( ) ;
2020-08-23 06:49:26 -03:00
settings . bind ( 'drawing-on-desktop' , desktopSwitch , 'active' , 0 ) ;
2020-09-01 08:43:30 -03:00
desktopRow . addWidget ( desktopSwitch , true ) ;
2020-09-17 12:30:30 -03:00
persistentOverTogglesSwitch . bind _property ( 'active' , desktopSwitch , 'sensitive' , GObject . BindingFlags . SYNC _CREATE ) ;
2020-09-01 08:43:30 -03:00
listBox . add ( desktopRow ) ;
let osdKey = schema . get _key ( 'osd-disabled' ) ;
let osdRow = new PrefRow ( { label : osdKey . get _summary ( ) , desc : osdKey . get _description ( ) } ) ;
let osdSwitch = new Gtk . Switch ( ) ;
2020-08-23 06:49:26 -03:00
settings . bind ( 'osd-disabled' , osdSwitch , 'active' , 0 ) ;
2020-09-01 08:43:30 -03:00
osdRow . addWidget ( osdSwitch , true ) ;
listBox . add ( osdRow ) ;
let indicatorKey = schema . get _key ( 'indicator-disabled' ) ;
let indicatorRow = new PrefRow ( { label : indicatorKey . get _summary ( ) , desc : indicatorKey . get _description ( ) } ) ;
let indicatorSwitch = new Gtk . Switch ( ) ;
2020-08-23 06:49:26 -03:00
settings . bind ( 'indicator-disabled' , indicatorSwitch , 'active' , 0 ) ;
2020-09-01 08:43:30 -03:00
indicatorRow . addWidget ( indicatorSwitch , true ) ;
listBox . add ( indicatorRow ) ;
2020-01-07 18:15:18 -03:00
2020-09-01 08:43:30 -03:00
let internalFrame = new Frame ( { label : _ ( "Internal" ) , desc : _ ( "In drawing mode" ) } ) ;
2020-01-07 18:15:18 -03:00
box . add ( internalFrame ) ;
2019-03-05 08:36:59 -03:00
2020-09-02 16:13:23 -03:00
listBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN , margin _bottom : MARGIN } ) ;
2020-09-01 08:43:30 -03:00
listBox . get _style _context ( ) . add _class ( 'background' ) ;
2020-01-07 18:15:18 -03:00
internalFrame . add ( listBox ) ;
2019-03-05 08:36:59 -03:00
2020-09-13 10:46:22 -03:00
Shortcuts . OTHERS . forEach ( ( pairs , index ) => {
2020-09-01 08:43:30 -03:00
if ( index )
listBox . add ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ) ;
2020-09-13 10:46:22 -03:00
pairs . forEach ( pair => {
let [ action , shortcut ] = pair ;
2020-09-01 08:43:30 -03:00
let otherBox = new Gtk . Box ( { margin _left : MARGIN , margin _right : MARGIN } ) ;
2020-09-13 10:46:22 -03:00
let otherLabel = new Gtk . Label ( { label : action , use _markup : true } ) ;
2020-09-01 08:43:30 -03:00
otherLabel . set _halign ( 1 ) ;
2020-09-13 10:46:22 -03:00
let otherLabel2 = new Gtk . Label ( { label : shortcut } ) ;
2020-09-01 08:43:30 -03:00
otherBox . pack _start ( otherLabel , true , true , 4 ) ;
otherBox . pack _start ( otherLabel2 , false , false , 4 ) ;
listBox . add ( otherBox ) ;
2020-09-13 10:46:22 -03:00
} ) ;
2020-09-01 08:43:30 -03:00
} ) ;
2019-03-05 08:36:59 -03:00
2020-09-01 08:43:30 -03:00
listBox . add ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ) ;
2020-09-08 15:11:57 -03:00
Shortcuts . INTERNAL _KEYBINDINGS . forEach ( ( settingKeys , index ) => {
2020-09-01 08:43:30 -03:00
if ( index )
listBox . add ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ) ;
2020-09-08 15:11:57 -03:00
let internalKeybindingsWidget = new KeybindingsWidget ( settingKeys , internalShortcutSettings ) ;
2020-09-01 08:43:30 -03:00
listBox . add ( internalKeybindingsWidget ) ;
} ) ;
2019-03-05 08:36:59 -03:00
2020-09-01 08:43:30 -03:00
listBox . get _children ( ) . forEach ( row => row . set _activatable ( false ) ) ;
2020-09-02 16:13:23 -03:00
let resetButton = new Gtk . Button ( { label : _ ( "Reset settings" ) , halign : Gtk . Align . CENTER } ) ;
resetButton . get _style _context ( ) . add _class ( 'destructive-action' ) ;
resetButton . connect ( 'clicked' , ( ) => {
internalShortcutSettings . settings _schema . list _keys ( ) . forEach ( key => internalShortcutSettings . reset ( key ) ) ;
settings . settings _schema . list _keys ( ) . forEach ( key => settings . reset ( key ) ) ;
} ) ;
box . add ( resetButton ) ;
2020-09-01 08:43:30 -03:00
}
} ) ;
const Frame = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .Frame ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -Frame ` ) ,
2020-09-01 08:43:30 -03:00
Extends : Gtk . Frame ,
_init : function ( params ) {
let labelWidget = new Gtk . Label ( { margin _bottom : MARGIN / 2 , use _markup : true , label : ` <b><big> ${ params . label } </big></b> ` } ) ;
this . parent ( { label _yalign : 1.0 , label _widget : labelWidget } ) ;
if ( params . desc ) {
labelWidget . set _tooltip _text ( params . desc ) ;
this . get _accessible ( ) . set _description ( params . desc ) ;
2019-03-05 08:36:59 -03:00
}
}
} ) ;
2020-08-31 04:43:00 -03:00
const PrefRow = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .PrefRow ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -PrefRow ` ) ,
2020-08-31 04:43:00 -03:00
Extends : Gtk . ListBoxRow ,
_init : function ( params ) {
this . parent ( { activatable : false } ) ;
2020-09-01 08:43:30 -03:00
let hbox = new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) ;
2020-08-31 04:43:00 -03:00
this . add ( hbox ) ;
let labelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
hbox . pack _start ( labelBox , true , true , 4 ) ;
this . widgetBox = new Gtk . Box ( { spacing : 4 } ) ;
hbox . pack _start ( this . widgetBox , false , false , 4 ) ;
2020-09-01 08:43:30 -03:00
this . label = new Gtk . Label ( { use _markup : true , label : params . label , halign : Gtk . Align . START } ) ;
labelBox . pack _start ( this . label , true , true , 0 ) ;
2020-08-31 04:43:00 -03:00
if ( params . desc ) {
2020-09-01 08:43:30 -03:00
this . desc = new Gtk . Label ( { use _markup : true , label : ` <small> ${ params . desc } </small> ` , halign : Gtk . Align . START , wrap : true , xalign : 0 } ) ;
this . desc . get _style _context ( ) . add _class ( 'dim-label' ) ;
labelBox . pack _start ( this . desc , true , true , 0 ) ;
2020-08-31 04:43:00 -03:00
this . widgetBox . set _valign ( Gtk . Align . START ) ;
}
} ,
2020-09-01 08:43:30 -03:00
addWidget : function ( widget , setRelationship ) {
2020-08-31 04:43:00 -03:00
this . widgetBox . add ( widget ) ;
2020-09-01 08:43:30 -03:00
if ( widget . name )
widget . get _accessible ( ) . set _name ( widget . name ) ;
if ( setRelationship ) {
this . label . get _accessible ( ) . add _relationship ( Atk . RelationType . LABEL _FOR , widget . get _accessible ( ) ) ;
widget . get _accessible ( ) . add _relationship ( Atk . RelationType . LABELLED _BY , this . label . get _accessible ( ) ) ;
if ( this . desc ) {
this . desc . get _accessible ( ) . add _relationship ( Atk . RelationType . DESCRIPTION _FOR , widget . get _accessible ( ) ) ;
widget . get _accessible ( ) . add _relationship ( Atk . RelationType . DESCRIBED _BY , this . desc . get _accessible ( ) ) ;
}
}
2020-08-31 04:43:00 -03:00
}
} ) ;
const PixelSpinButton = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .PixelSpinButton ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -PixelSpinButton ` ) ,
2020-08-31 04:43:00 -03:00
Extends : Gtk . SpinButton ,
2020-09-09 07:12:29 -03:00
Properties : {
'range' : GObject . param _spec _variant ( 'range' , 'range' , 'GSettings range' ,
GLib . VariantType . new ( '(sv)' ) , null , GObject . ParamFlags . WRITABLE ) ,
'step' : GObject . ParamSpec . double ( 'step' , 'step' , 'step increment' ,
GObject . ParamFlags . WRITABLE ,
0 , 1000 , 1 )
} ,
set range ( range ) {
let [ type , variant ] = range . deep _unpack ( ) ;
if ( type == 'range' ) {
let [ min , max ] = variant . deep _unpack ( ) ;
this . adjustment . set _lower ( min ) ;
this . adjustment . set _upper ( max ) ;
}
} ,
set step ( step ) {
this . adjustment . set _step _increment ( step ) ;
this . adjustment . set _page _increment ( step * 10 ) ;
} ,
2020-08-31 04:43:00 -03:00
// Add 'px' unit.
vfunc _output : function ( ) {
2020-09-08 15:11:57 -03:00
this . text = _ ( "%f px" ) . format ( Number ( this . value ) . toFixed ( 2 ) ) ;
2020-08-31 04:43:00 -03:00
return true ;
} ,
// Prevent accidental scrolling.
vfunc _scroll _event : function ( event ) {
return this . has _focus ? this . parent ( event ) : Gdk . EVENT _PROPAGATE ;
}
} ) ;
// A color button that can be easily bound with a color string setting.
const ColorStringButton = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .ColorStringButton ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -ColorStringButton ` ) ,
2020-08-31 04:43:00 -03:00
Extends : Gtk . ColorButton ,
Properties : {
'color-string' : GObject . ParamSpec . string ( 'color-string' , 'colorString' , 'A string that describes the color' ,
2020-09-10 23:06:21 -03:00
GObject . ParamFlags . READWRITE , 'black' )
2020-08-31 04:43:00 -03:00
} ,
get color _string ( ) {
return this . _color _string || 'black' ;
} ,
set color _string ( colorString ) {
this . _color _string = colorString ;
let newRgba = new Gdk . RGBA ( ) ;
newRgba . parse ( colorString ) ;
this . set _rgba ( newRgba ) ;
} ,
// Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)").
vfunc _color _set ( args ) {
let oldRgba = new Gdk . RGBA ( ) ;
oldRgba . parse ( this . color _string ) ;
if ( ! this . rgba . equal ( oldRgba ) ) {
this . _color _string = this . rgba . to _string ( ) ;
this . notify ( 'color-string' ) ;
}
}
} ) ;
2020-09-10 23:06:21 -03:00
const FileChooserButton = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .FileChooserButton ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -FileChooserButton ` ) ,
2020-09-10 23:06:21 -03:00
Extends : Gtk . FileChooserButton ,
Properties : {
'location' : GObject . ParamSpec . string ( 'location' , 'location' , 'location' ,
GObject . ParamFlags . READWRITE , '' )
} ,
get location ( ) {
return this . get _file ( ) . get _path ( ) ;
} ,
set location ( location ) {
if ( ! location ) {
this . unselect _all ( ) ;
if ( this . get _file ( ) )
this . set _file ( Gio . File . new _for _path ( 'aFileThatDoesNotExist' ) ) ;
return ;
}
let file = Gio . File . new _for _commandline _arg ( location ) ;
if ( file . query _exists ( null ) )
this . set _file ( file ) ;
} ,
vfunc _file _set : function ( args ) {
this . notify ( 'location' ) ;
}
} ) ;
2019-03-05 08:36:59 -03:00
// this code comes from Sticky Notes View by Sam Bull, https://extensions.gnome.org/extension/568/notes/
2020-03-02 12:32:50 -03:00
const KeybindingsWidget = new GObject . Class ( {
2020-09-25 06:55:36 -03:00
Name : ` ${ Me . uuid } .KeybindingsWidget ` ,
GTypeName : sanitizeGType ( ` ${ Me . uuid } -KeybindingsWidget ` ) ,
2019-03-05 08:36:59 -03:00
Extends : Gtk . Box ,
2020-09-08 15:11:57 -03:00
_init : function ( settingKeys , settings ) {
2020-09-01 08:43:30 -03:00
this . parent ( ROWBOX _MARGIN _PARAMS ) ;
2019-03-05 08:36:59 -03:00
this . set _orientation ( Gtk . Orientation . VERTICAL ) ;
2020-09-08 15:11:57 -03:00
this . _settingKeys = settingKeys ;
2019-03-05 08:36:59 -03:00
this . _settings = settings ;
this . _columns = {
NAME : 0 ,
ACCEL _NAME : 1 ,
MODS : 2 ,
KEY : 3
} ;
this . _store = new Gtk . ListStore ( ) ;
this . _store . set _column _types ( [
GObject . TYPE _STRING ,
GObject . TYPE _STRING ,
GObject . TYPE _INT ,
GObject . TYPE _INT
] ) ;
this . _tree _view = new Gtk . TreeView ( {
model : this . _store ,
hexpand : false ,
vexpand : false
} ) ;
this . _tree _view . set _activate _on _single _click ( false ) ;
this . _tree _view . get _selection ( ) . set _mode ( Gtk . SelectionMode . SINGLE ) ;
let action _renderer = new Gtk . CellRendererText ( ) ;
let action _column = new Gtk . TreeViewColumn ( {
title : "" ,
expand : true ,
} ) ;
action _column . pack _start ( action _renderer , true ) ;
action _column . add _attribute ( action _renderer , 'text' , 1 ) ;
this . _tree _view . append _column ( action _column ) ;
let keybinding _renderer = new Gtk . CellRendererAccel ( {
editable : true ,
accel _mode : Gtk . CellRendererAccelMode . GTK ,
xalign : 1
} ) ;
2020-08-01 10:00:49 -03:00
keybinding _renderer . connect ( 'accel-edited' , ( renderer , iter , key , mods ) => {
let value = Gtk . accelerator _name ( key , mods ) ;
let [ success , iterator ] =
this . _store . get _iter _from _string ( iter ) ;
2019-03-05 08:36:59 -03:00
2020-08-01 10:00:49 -03:00
if ( ! success ) {
printerr ( "Can't change keybinding" ) ;
}
2019-03-05 08:36:59 -03:00
2020-08-01 10:00:49 -03:00
let name = this . _store . get _value ( iterator , 0 ) ;
2019-03-05 08:36:59 -03:00
2020-08-01 10:00:49 -03:00
this . _store . set (
iterator ,
[ this . _columns . MODS , this . _columns . KEY ] ,
[ mods , key ]
) ;
this . _settings . set _strv ( name , [ value ] ) ;
} ) ;
2019-03-05 08:36:59 -03:00
let keybinding _column = new Gtk . TreeViewColumn ( {
title : "" ,
} ) ;
keybinding _column . pack _end ( keybinding _renderer , false ) ;
keybinding _column . add _attribute (
keybinding _renderer ,
'accel-mods' ,
this . _columns . MODS
) ;
keybinding _column . add _attribute (
keybinding _renderer ,
'accel-key' ,
this . _columns . KEY
) ;
this . _tree _view . append _column ( keybinding _column ) ;
this . _tree _view . columns _autosize ( ) ;
this . _tree _view . set _headers _visible ( false ) ;
this . add ( this . _tree _view ) ;
this . keybinding _column = keybinding _column ;
this . action _column = action _column ;
2020-09-02 16:13:23 -03:00
this . _settings . connect ( 'changed' , this . _onSettingsChanged . bind ( this ) ) ;
2019-03-05 08:36:59 -03:00
this . _refresh ( ) ;
} ,
2020-09-02 16:13:23 -03:00
// Support the case where all the settings has been reset.
_onSettingsChanged : function ( ) {
if ( this . _refreshTimeout )
GLib . source _remove ( this . _refreshTimeout ) ;
this . _refreshTimeout = GLib . idle _add ( GLib . PRIORITY _DEFAULT _IDLE , ( ) => {
this . _refreshTimeout = 0 ;
this . _refresh ( ) ;
} ) ;
} ,
2019-03-05 08:36:59 -03:00
_refresh : function ( ) {
this . _store . clear ( ) ;
2020-09-08 15:11:57 -03:00
this . _settingKeys . forEach ( settingKey => {
2019-03-05 08:36:59 -03:00
let [ key , mods ] = Gtk . accelerator _parse (
2020-09-13 10:46:22 -03:00
this . _settings . get _strv ( settingKey ) [ 0 ] || ''
2019-03-05 08:36:59 -03:00
) ;
let iter = this . _store . append ( ) ;
this . _store . set ( iter ,
[
this . _columns . NAME ,
this . _columns . ACCEL _NAME ,
this . _columns . MODS ,
this . _columns . KEY
] ,
[
2020-09-08 15:11:57 -03:00
settingKey ,
this . _settings . settings _schema . get _key ( settingKey ) . get _summary ( ) ,
2019-03-05 08:36:59 -03:00
mods ,
key
]
) ;
2020-09-08 15:11:57 -03:00
} ) ;
2019-03-05 08:36:59 -03:00
}
} ) ;