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-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 ;
2021-02-19 20:01:08 -03:00
const IS _GTK3 = Gtk . get _major _version ( ) == 3 ;
2019-03-05 08:36:59 -03:00
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 ) ;
} ;
2021-02-18 12:36:36 -03:00
const _GTK = imports . gettext . domain ( IS _GTK3 ? 'gtk30' : 'gtk40' ) . gettext ;
2019-03-05 08:36:59 -03:00
const MARGIN = 10 ;
2021-02-18 12:36:36 -03:00
const ROWBOX _MARGIN _PARAMS = { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _start : MARGIN , margin _end : MARGIN , spacing : 4 } ;
2020-10-04 05:01:55 -03:00
const UUID = Me . uuid . replace ( /@/gi , '_at_' ) . replace ( /[^a-z0-9+_-]/gi , '_' ) ;
2020-09-25 06:55:36 -03:00
2021-02-18 12:36:36 -03:00
if ( IS _GTK3 ) {
Gtk . Container . prototype . append = Gtk . Container . prototype . add ;
Gtk . Bin . prototype . set _child = Gtk . Container . prototype . add ;
}
const setAccessibleLabel = function ( widget , label ) {
if ( IS _GTK3 )
widget . get _accessible ( ) . set _name ( label ) ;
else
widget . update _property ( [ Gtk . AccessibleProperty . LABEL ] , [ label ] ) ;
} ;
const setAccessibleDescription = function ( widget , description ) {
if ( IS _GTK3 )
widget . get _accessible ( ) . set _description ( description ) ;
else
widget . update _property ( [ Gtk . AccessibleProperty . DESCRIPTION ] , [ description ] ) ;
} ;
const getChildrenOf = function ( widget ) {
if ( IS _GTK3 ) {
return widget . get _children ( ) ;
} else {
let listModel = widget . observe _children ( ) ;
let i = 0 ;
let children = [ ] ;
let child ;
2021-02-19 20:01:08 -03:00
while ( ! ! ( child = listModel . get _item ( i ) ) ) {
2021-02-18 12:36:36 -03:00
children . push ( child ) ;
i ++ ;
}
return children ;
}
} ;
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 ( ) ;
2021-02-18 12:36:36 -03:00
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 , ( ) => {
2021-02-18 12:36:36 -03:00
if ( IS _GTK3 )
topStack . get _toplevel ( ) . get _titlebar ( ) . set _custom _title ( switcher ) ;
else
topStack . get _root ( ) . get _titlebar ( ) . set _title _widget ( switcher ) ;
return GLib . SOURCE _REMOVE ;
2019-03-28 10:59:14 -03:00
} ) ;
2021-02-18 12:36:36 -03:00
if ( IS _GTK3 )
topStack . show _all ( ) ;
2019-03-28 10:59:14 -03:00
return topStack ;
}
2020-03-02 12:32:50 -03:00
const TopStack = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ UUID } -TopStack ` ,
2019-03-28 10:59:14 -03:00
Extends : Gtk . Stack ,
_init : function ( params ) {
2021-02-19 20:01:08 -03:00
this . parent ( { transition _type : Gtk . StackTransitionType . CROSSFADE , transition _duration : 500 , hexpand : true , vexpand : true } ) ;
2019-03-28 10:59:14 -03:00
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-10-04 05:01:55 -03:00
Name : ` ${ 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
2021-02-18 12:36:36 -03:00
let vbox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin _top : 3 * MARGIN , margin _bottom : 3 * MARGIN , margin _start : 3 * MARGIN , margin _end : 3 * MARGIN } ) ;
this . set _child ( vbox ) ;
2019-03-28 10:59:14 -03:00
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>" ;
2021-02-18 12:36:36 -03:00
let aboutLabel = new Gtk . Label ( { wrap : true , justify : Gtk . Justification . CENTER , use _markup : true , label :
2019-03-28 10:59:14 -03:00
name + "\n\n" + version + "\n\n" + description + "\n\n" + link + "\n\n" + licence + "\n" } ) ;
2021-02-18 12:36:36 -03:00
vbox . append ( aboutLabel ) ;
2019-03-28 10:59:14 -03:00
2021-02-18 12:36:36 -03:00
let creditBox = new Gtk . Box ( { orientation : Gtk . Orientation . HORIZONTAL , margin _top : 2 * MARGIN , margin _bottom : 2 * MARGIN , margin _start : 2 * MARGIN , margin _end : 2 * MARGIN , spacing : 5 } ) ;
let leftBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , hexpand : true } ) ;
let rightBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , hexpand : true } ) ;
leftBox . append ( new Gtk . Label ( { wrap : true , valign : Gtk . Align . START , halign : Gtk . Align . END , justify : Gtk . Justification . RIGHT ,
use _markup : true , label : "<small>" + _GTK ( "Created by" ) + "</small>" } ) ) ;
rightBox . append ( new Gtk . Label ( { wrap : true , valign : Gtk . Align . START , halign : Gtk . Align . START , justify : Gtk . Justification . LEFT ,
use _markup : true , label : "<small><a href=\"https://framagit.org/abakkk\">Abakkk</a></small>" } ) ) ;
creditBox . append ( leftBox ) ;
creditBox . append ( rightBox ) ;
vbox . append ( creditBox ) ;
2019-03-28 10:59:14 -03:00
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" ) != "" ) {
2021-02-18 12:36:36 -03:00
leftBox . append ( new Gtk . Label ( ) ) ;
rightBox . append ( new Gtk . Label ( ) ) ;
leftBox . append ( new Gtk . Label ( { wrap : true , valign : Gtk . Align . START , halign : Gtk . Align . END , justify : 1 , use _markup : true , label : "<small>" + _GTK ( "Translated by" ) + "</small>" } ) ) ;
rightBox . append ( new Gtk . Label ( { wrap : true , valign : Gtk . Align . START , halign : Gtk . Align . START , justify : 0 , use _markup : true , label : "<small>" + _ ( "translator-credits" ) + "</small>" } ) ) ;
2019-03-28 10:59:14 -03:00
}
}
} ) ;
2020-08-31 04:43:00 -03:00
const DrawingPage = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ 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 ;
2021-02-18 12:36:36 -03:00
let box = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin _top : 3 * MARGIN , margin _bottom : 3 * MARGIN , margin _start : 3 * MARGIN , margin _end : 3 * MARGIN , spacing : 3 * MARGIN } ) ;
this . set _child ( box ) ;
2020-08-31 04:43:00 -03:00
2020-09-01 08:43:30 -03:00
let palettesFrame = new Frame ( { label : _ ( "Palettes" ) } ) ;
2021-02-18 12:36:36 -03:00
box . append ( palettesFrame ) ;
2020-09-22 12:31:48 -03:00
let palettesFrameBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
2021-02-18 12:36:36 -03:00
palettesFrame . set _child ( 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 } ) ;
2021-02-18 12:36:36 -03:00
palettesFrameBox . append ( palettesScrolledWindow ) ;
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' ) ;
2021-02-18 12:36:36 -03:00
setAccessibleLabel ( this . palettesListBox , this . schema . get _key ( 'palettes' ) . get _summary ( ) ) ;
setAccessibleDescription ( this . palettesListBox , this . schema . get _key ( 'palettes' ) . get _description ( ) ) ;
palettesScrolledWindow . set _child ( this . palettesListBox ) ;
palettesScrolledWindow . get _child ( ) . set _margin _top ( MARGIN / 2 ) ;
palettesScrolledWindow . get _child ( ) . set _margin _bottom ( MARGIN / 2 ) ;
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 ) ;
2021-02-18 12:36:36 -03:00
let addButton = IS _GTK3 ? Gtk . Button . new _from _icon _name ( 'list-add-symbolic' , Gtk . IconSize . BUTTON ) : Gtk . Button . new _from _icon _name ( 'list-add-symbolic' ) ;
2020-09-01 08:43:30 -03:00
addButton . set _tooltip _text ( _ ( "Add a new palette" ) ) ;
2021-02-18 12:36:36 -03:00
addButton . set _hexpand ( true ) ;
addBox . append ( addButton ) ;
2020-08-31 04:43:00 -03:00
addButton . connect ( 'clicked' , this . _addNewPalette . bind ( this ) ) ;
2021-02-18 12:36:36 -03:00
let importButton = IS _GTK3 ? Gtk . Button . new _from _icon _name ( 'document-open-symbolic' , Gtk . IconSize . BUTTON ) : Gtk . Button . new _from _icon _name ( 'document-open-symbolic' ) ;
2020-09-22 12:31:48 -03:00
importButton . set _tooltip _text ( _GTK ( "Select a File" ) ) ;
2021-02-18 12:36:36 -03:00
importButton . set _hexpand ( true ) ;
addBox . append ( importButton ) ;
2020-09-22 12:31:48 -03:00
importButton . connect ( 'clicked' , this . _importPalette . bind ( this ) ) ;
2021-02-18 12:36:36 -03:00
palettesFrameBox . append ( addBox ) ;
2020-08-31 04:43:00 -03:00
2020-09-01 08:43:30 -03:00
let areaFrame = new Frame ( { label : _ ( "Area" ) } ) ;
2021-02-18 12:36:36 -03:00
box . append ( areaFrame ) ;
2020-08-31 04:43:00 -03:00
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' ) ;
2021-02-18 12:36:36 -03:00
areaFrame . set _child ( areaListBox ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
areaListBox . insert ( squareAreaRow , - 1 ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
areaListBox . insert ( backgroundColorRow , - 1 ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
areaListBox . insert ( gridLineRow , - 1 ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
areaListBox . insert ( gridColorRow , - 1 ) ;
2020-08-31 04:43:00 -03:00
2020-09-01 08:43:30 -03:00
let toolsFrame = new Frame ( { label : _ ( "Tools" ) } ) ;
2021-02-18 12:36:36 -03:00
box . append ( toolsFrame ) ;
2020-08-31 04:43:00 -03:00
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' ) ;
2021-02-18 12:36:36 -03:00
toolsFrame . set _child ( toolsListBox ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
toolsListBox . insert ( dashArrayRow , - 1 ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
toolsListBox . insert ( dashOffsetRow , - 1 ) ;
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 ) ;
2021-02-18 12:36:36 -03:00
toolsListBox . insert ( imageLocationRow , - 1 ) ;
2020-09-10 23:06:21 -03:00
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 ) ) ) ;
2021-02-18 12:36:36 -03:00
box . append ( resetButton ) ;
2020-08-31 04:43:00 -03:00
} ,
_updatePalettes : function ( ) {
this . palettes = this . settings . get _value ( 'palettes' ) . deep _unpack ( ) ;
2021-02-18 12:36:36 -03:00
getChildrenOf ( this . palettesListBox ) . slice ( this . palettes . length )
2020-08-31 04:43:00 -03:00
. forEach ( row => this . palettesListBox . remove ( row ) ) ;
2021-02-18 12:36:36 -03:00
let paletteBoxes = getChildrenOf ( this . palettesListBox ) . 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 ] ;
2021-02-18 12:36:36 -03:00
let nameEntry = getChildrenOf ( paletteBox ) [ 0 ] ;
2020-08-31 04:43:00 -03:00
if ( nameEntry . get _text ( ) !== _ ( name ) ) {
GObject . signal _handler _block ( nameEntry , nameEntry . paletteNameChangedHandler ) ;
nameEntry . set _text ( _ ( name ) ) ;
GObject . signal _handler _unblock ( nameEntry , nameEntry . paletteNameChangedHandler ) ;
}
} else {
2021-02-18 12:36:36 -03:00
let nameEntry = new Gtk . Entry ( { text : name , halign : Gtk . Align . START , tooltip _text : _ ( "Rename the palette" ) , hexpand : true } ) ;
2020-08-31 04:43:00 -03:00
nameEntry . paletteNameChangedHandler = nameEntry . connect ( 'changed' , this . _onPaletteNameChanged . bind ( this , paletteIndex ) ) ;
2021-02-18 12:36:36 -03:00
// Minimum size, for Gtk4
nameEntry . set _size _request ( nameEntry . get _preferred _size ( ) [ 1 ] . width , - 1 ) ;
let removeButton = IS _GTK3 ? Gtk . Button . new _from _icon _name ( 'list-remove-symbolic' , Gtk . IconSize . BUTTON ) : Gtk . Button . new _from _icon _name ( 'list-remove-symbolic' ) ;
2020-08-31 04:43:00 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
paletteBox . append ( nameEntry ) ;
paletteBox . append ( new Gtk . Box ( { spacing : 4 } ) ) ;
paletteBox . append ( removeButton ) ;
2020-08-31 04:43:00 -03:00
this . palettesListBox . insert ( paletteBox , paletteIndex ) ;
paletteBox . get _parent ( ) . set _activatable ( false ) ;
}
while ( colors . length < 9 )
colors . push ( 'transparent' ) ;
2021-02-18 12:36:36 -03:00
let colorsBox = getChildrenOf ( paletteBox ) [ 1 ] ;
let colorButtons = getChildrenOf ( colorsBox ) ;
2020-08-31 04:43:00 -03:00
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 ) ) ;
2021-02-18 12:36:36 -03:00
colorsBox . append ( colorButton ) ;
2020-08-31 04:43:00 -03:00
}
} ) ;
2021-02-18 12:36:36 -03:00
if ( IS _GTK3 )
paletteBox . show _all ( ) ;
2020-08-31 04:43:00 -03:00
} ) ;
} ,
_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 ( ) {
2021-02-18 12:36:36 -03:00
let dialog = new Gtk . FileChooserDialog ( {
title : _GTK ( "Select a File" ) ,
action : Gtk . FileChooserAction . OPEN ,
modal : true ,
transient _for : IS _GTK3 ? this . get _toplevel ( ) : this . get _root ( ) ,
} ) ;
dialog . add _button ( _GTK ( "_Cancel" ) , Gtk . ResponseType . CANCEL ) ;
dialog . add _button ( _GTK ( "_Open" ) , Gtk . ResponseType . ACCEPT ) ;
2020-09-22 12:31:48 -03:00
let filter = new Gtk . FileFilter ( ) ;
filter . set _name ( "GIMP Palette (*.gpl)" ) ;
filter . add _pattern ( '*.gpl' ) ;
dialog . add _filter ( filter ) ;
2021-02-18 12:36:36 -03:00
dialog . connect ( 'response' , ( dialog , response ) => {
if ( response == Gtk . ResponseType . ACCEPT ) {
let file = dialog . get _file ( ) ;
let palettes = GimpPaletteParser . parseFile ( file ) ;
palettes . forEach ( palette => this . palettes . push ( palette ) ) ;
this . _savePalettes ( ) ;
}
dialog . destroy ( ) ;
} ) ;
dialog . show ( ) ;
2020-09-22 12:31:48 -03:00
} ,
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-10-04 05:01:55 -03:00
Name : ` ${ 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
2021-02-18 12:36:36 -03:00
let box = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin _top : 3 * MARGIN , margin _bottom : 3 * MARGIN , margin _start : 3 * MARGIN , margin _end : 3 * MARGIN , spacing : 3 * MARGIN } ) ;
this . set _child ( box ) ;
2019-03-05 08:36:59 -03:00
2020-09-01 08:43:30 -03:00
let globalFrame = new Frame ( { label : _ ( "Global" ) } ) ;
2021-02-18 12:36:36 -03:00
box . append ( globalFrame ) ;
2020-01-07 18:15:18 -03:00
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' ) ;
2021-02-18 12:36:36 -03:00
globalFrame . set _child ( 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 )
2021-02-18 12:36:36 -03:00
listBox . insert ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) , - 1 ) ;
2020-09-08 15:11:57 -03:00
let globalKeybindingsRow = new Gtk . ListBoxRow ( { activatable : false } ) ;
let globalKeybindingsWidget = new KeybindingsWidget ( settingKeys , settings ) ;
2021-02-18 12:36:36 -03:00
globalKeybindingsRow . set _child ( globalKeybindingsWidget ) ;
listBox . insert ( globalKeybindingsRow , - 1 ) ;
2020-09-08 15:11:57 -03:00
} ) ;
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 ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( persistentOverTogglesRow , - 1 ) ;
2020-09-17 12:30:30 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( persistentOverRestartsRow , - 1 ) ;
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 ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( desktopRow , - 1 ) ;
2020-09-01 08:43:30 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( osdRow , - 1 ) ;
2020-09-01 08:43:30 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( indicatorRow , - 1 ) ;
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" ) } ) ;
2021-02-18 12:36:36 -03:00
box . append ( 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' ) ;
2021-02-18 12:36:36 -03:00
internalFrame . set _child ( 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 )
2021-02-18 12:36:36 -03:00
listBox . insert ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) , - 1 ) ;
2020-09-01 08:43:30 -03:00
2020-09-13 10:46:22 -03:00
pairs . forEach ( pair => {
let [ action , shortcut ] = pair ;
2021-02-18 12:36:36 -03:00
let otherBox = new Gtk . Box ( { margin _start : MARGIN , margin _end : MARGIN , spacing : 4 } ) ;
otherBox . append ( new Gtk . Label ( { label : action , use _markup : true , halign : Gtk . Align . START , hexpand : true } ) ) ;
otherBox . append ( new Gtk . Label ( { label : shortcut } ) ) ;
listBox . insert ( otherBox , - 1 ) ;
2020-09-13 10:46:22 -03:00
} ) ;
2020-09-01 08:43:30 -03:00
} ) ;
2019-03-05 08:36:59 -03:00
2021-02-18 12:36:36 -03:00
listBox . insert ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) , - 1 ) ;
2020-09-01 08:43:30 -03:00
2020-09-08 15:11:57 -03:00
Shortcuts . INTERNAL _KEYBINDINGS . forEach ( ( settingKeys , index ) => {
2020-09-01 08:43:30 -03:00
if ( index )
2021-02-18 12:36:36 -03:00
listBox . insert ( new Gtk . Box ( ROWBOX _MARGIN _PARAMS ) , - 1 ) ;
2020-09-01 08:43:30 -03:00
2020-09-08 15:11:57 -03:00
let internalKeybindingsWidget = new KeybindingsWidget ( settingKeys , internalShortcutSettings ) ;
2021-02-18 12:36:36 -03:00
listBox . insert ( internalKeybindingsWidget , - 1 ) ;
2020-09-01 08:43:30 -03:00
} ) ;
2019-03-05 08:36:59 -03:00
2021-02-18 12:36:36 -03:00
getChildrenOf ( listBox ) . 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 ) ) ;
} ) ;
2021-02-18 12:36:36 -03:00
box . append ( resetButton ) ;
2020-09-01 08:43:30 -03:00
}
} ) ;
const Frame = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ UUID } -Frame ` ,
2020-09-01 08:43:30 -03:00
Extends : Gtk . Frame ,
_init : function ( params ) {
2021-02-18 12:36:36 -03:00
let labelWidget = new Gtk . Label ( { use _markup : true , label : ` <b><big> ${ params . label } </big></b> ` } ) ;
this . parent ( { label _widget : labelWidget } ) ;
2020-09-01 08:43:30 -03:00
if ( params . desc ) {
labelWidget . set _tooltip _text ( params . desc ) ;
2021-02-18 12:36:36 -03:00
setAccessibleDescription ( this , params . desc ) ;
2019-03-05 08:36:59 -03:00
}
}
} ) ;
2020-08-31 04:43:00 -03:00
const PrefRow = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ 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 ) ;
2021-02-18 12:36:36 -03:00
this . set _child ( hbox ) ;
2020-08-31 04:43:00 -03:00
2021-02-18 12:36:36 -03:00
let labelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , hexpand : true } ) ;
hbox . append ( labelBox ) ;
2020-08-31 04:43:00 -03:00
this . widgetBox = new Gtk . Box ( { spacing : 4 } ) ;
2021-02-18 12:36:36 -03:00
hbox . append ( this . widgetBox ) ;
2020-08-31 04:43:00 -03:00
2021-02-18 12:36:36 -03:00
this . label = new Gtk . Label ( { use _markup : true , label : params . label , halign : Gtk . Align . START , vexpand : true } ) ;
labelBox . append ( this . label ) ;
2020-08-31 04:43:00 -03:00
if ( params . desc ) {
2021-02-18 12:36:36 -03:00
this . desc = new Gtk . Label ( { use _markup : true , label : ` <small> ${ params . desc } </small> ` , halign : Gtk . Align . START , wrap : true , xalign : 0 , vexpand : true } ) ;
2020-09-01 08:43:30 -03:00
this . desc . get _style _context ( ) . add _class ( 'dim-label' ) ;
2021-02-18 12:36:36 -03:00
labelBox . append ( this . desc ) ;
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 ) {
2021-02-18 12:36:36 -03:00
this . widgetBox . append ( widget ) ;
2020-09-01 08:43:30 -03:00
if ( widget . name )
2021-02-18 12:36:36 -03:00
setAccessibleLabel ( widget , widget . name ) ;
2020-09-01 08:43:30 -03:00
2021-02-18 12:36:36 -03:00
if ( setRelationship && IS _GTK3 ) {
this . label . get _accessible ( ) . add _relationship ( imports . gi . Atk . RelationType . LABEL _FOR , widget . get _accessible ( ) ) ;
widget . get _accessible ( ) . add _relationship ( imports . gi . Atk . RelationType . LABELLED _BY , this . label . get _accessible ( ) ) ;
2020-09-01 08:43:30 -03:00
if ( this . desc ) {
2021-02-18 12:36:36 -03:00
this . desc . get _accessible ( ) . add _relationship ( imports . gi . Atk . RelationType . DESCRIPTION _FOR , widget . get _accessible ( ) ) ;
widget . get _accessible ( ) . add _relationship ( imports . gi . Atk . RelationType . DESCRIBED _BY , this . desc . get _accessible ( ) ) ;
2020-09-01 08:43:30 -03:00
}
}
2020-08-31 04:43:00 -03:00
}
} ) ;
2021-02-18 12:36:36 -03:00
const PixelSpinButton = new GObject . Class ( Object . assign ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ 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
2021-02-18 12:36:36 -03:00
vfunc _constructed ( ) {
this . parent ( ) ;
// No virtual functions with Gtk4 :/.
// Add 'px' unit.
this . connect ( 'output' , spinButton => {
this . text = _ ( "%f px" ) . format ( Number ( spinButton . value ) . toFixed ( 2 ) ) ;
return true ;
} ) ;
}
} , IS _GTK3 ? {
2020-08-31 04:43:00 -03:00
// Prevent accidental scrolling.
vfunc _scroll _event : function ( event ) {
return this . has _focus ? this . parent ( event ) : Gdk . EVENT _PROPAGATE ;
}
2021-02-18 12:36:36 -03:00
} : { } ) ) ;
2020-08-31 04:43:00 -03:00
// A color button that can be easily bound with a color string setting.
const ColorStringButton = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ 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 ) ;
} ,
2021-02-18 12:36:36 -03:00
vfunc _constructed ( ) {
this . parent ( ) ;
// No virtual functions with Gtk4 :/.
// Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)").
this . connect ( 'color-set' , colorButton => {
let oldRgba = new Gdk . RGBA ( ) ;
oldRgba . parse ( colorButton . color _string ) ;
if ( ! this . rgba . equal ( oldRgba ) ) {
this . _color _string = colorButton . rgba . to _string ( ) ;
this . notify ( 'color-string' ) ;
}
} ) ;
2020-08-31 04:43:00 -03:00
}
} ) ;
2020-09-10 23:06:21 -03:00
const FileChooserButton = new GObject . Class ( {
2020-10-04 05:01:55 -03:00
Name : ` ${ UUID } -FileChooserButton ` ,
2021-02-18 12:36:36 -03:00
Extends : Gtk . Button ,
2020-09-10 23:06:21 -03:00
Properties : {
2021-02-18 12:36:36 -03:00
'action' : GObject . ParamSpec . enum ( 'action' , 'action' , 'action' ,
GObject . ParamFlags . READWRITE ,
Gtk . FileChooserAction . $gtype ,
Gtk . FileChooserAction . SELECT _FOLDER ) ,
2020-09-10 23:06:21 -03:00
'location' : GObject . ParamSpec . string ( 'location' , 'location' , 'location' ,
GObject . ParamFlags . READWRITE , '' )
} ,
get location ( ) {
2021-02-18 12:36:36 -03:00
return this . _location || "" ;
2020-09-10 23:06:21 -03:00
} ,
set location ( location ) {
2021-02-19 20:01:08 -03:00
if ( ! this . _location || this . _location != location ) {
2021-02-18 12:36:36 -03:00
this . _location = location ;
this . label = location ?
Gio . File . new _for _commandline _arg ( location ) . query _info ( 'standard::display-name' , Gio . FileQueryInfoFlags . NONE , null ) . get _display _name ( ) :
_GTK ( "(None)" ) ;
this . notify ( 'location' ) ;
2020-09-10 23:06:21 -03:00
}
} ,
2021-02-18 12:36:36 -03:00
vfunc _clicked : function ( ) {
let dialog = new Gtk . FileChooserDialog ( {
title : _ ( this . name ) ,
action : this . action ,
modal : true ,
transient _for : IS _GTK3 ? this . get _toplevel ( ) : this . get _root ( ) ,
} ) ;
dialog . add _button ( _GTK ( "_Cancel" ) , Gtk . ResponseType . CANCEL ) ;
dialog . add _button ( _GTK ( "_Select" ) , Gtk . ResponseType . ACCEPT ) ;
if ( this . location )
dialog . set _file ( Gio . File . new _for _commandline _arg ( this . location ) ) ;
dialog . connect ( 'response' , ( dialog , response ) => {
if ( response == Gtk . ResponseType . ACCEPT )
this . location = dialog . get _file ( ) . get _path ( ) ;
dialog . destroy ( ) ;
} ) ;
dialog . show ( ) ;
2020-09-10 23:06:21 -03:00
}
} ) ;
2021-02-18 12:36:36 -03:00
// 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-10-04 05:01:55 -03:00
Name : ` ${ 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
2021-02-18 12:36:36 -03:00
if ( ! success ) {
2020-08-01 10:00:49 -03:00
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 ) ;
2021-02-18 12:36:36 -03:00
this . append ( this . _tree _view ) ;
2019-03-05 08:36:59 -03:00
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 => {
2021-02-18 12:36:36 -03:00
let success _ , key , mods ;
if ( IS _GTK3 )
[ key , mods ] = Gtk . accelerator _parse ( this . _settings . get _strv ( settingKey ) [ 0 ] || '' ) ;
else
[ success _ , key , mods ] = Gtk . accelerator _parse ( 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
}
} ) ;