2019-03-05 08:36:59 -03:00
/* jslint esversion: 6 */
/ *
* 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-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 Lang = imports . lang ;
2020-06-08 10:26:55 -03:00
const Config = imports . misc . config ;
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-01-06 11:29:01 -03:00
const _ = imports . gettext . domain ( Me . metadata [ 'gettext-domain' ] ) . gettext ;
2019-03-28 10:59:14 -03:00
const _GTK = imports . gettext . domain ( 'gtk30' ) . gettext ;
2019-03-05 08:36:59 -03:00
2020-06-08 10:26:55 -03:00
const GS _VERSION = Config . PACKAGE _VERSION ;
2019-03-05 08:36:59 -03:00
const MARGIN = 10 ;
var GLOBAL _KEYBINDINGS = {
'toggle-drawing' : "Enter/leave drawing mode" ,
2020-06-29 07:21:21 -03:00
'toggle-modal' : "Grab/ungrab keyboard and pointer" ,
2020-06-28 08:10:31 -03:00
'erase-drawing' : "Erase all drawings"
2019-03-05 08:36:59 -03:00
} ;
var INTERNAL _KEYBINDINGS = {
'undo' : "Undo last brushstroke" ,
'redo' : "Redo last brushstroke" ,
'delete-last-element' : "Erase last brushstroke" ,
2019-03-05 17:08:43 -03:00
'smooth-last-element' : "Smooth last brushstroke" ,
2019-03-05 08:36:59 -03:00
'-separator-1' : '' ,
2020-06-13 08:53:52 -03:00
'select-none-shape' : "Free drawing" ,
2019-03-26 21:07:20 -03:00
'select-line-shape' : "Select line" ,
'select-ellipse-shape' : "Select ellipse" ,
'select-rectangle-shape' : "Select rectangle" ,
2020-06-07 13:57:11 -03:00
'select-polygon-shape' : "Select polygon" ,
2020-06-15 17:13:03 -03:00
'select-polyline-shape' : "Select polyline" ,
2019-03-26 21:07:20 -03:00
'select-text-shape' : "Select text" ,
2020-07-30 06:13:23 -03:00
'select-image-shape' : "Select image" ,
2020-06-13 08:53:52 -03:00
'select-move-tool' : "Select move" ,
2020-06-15 17:13:03 -03:00
'select-resize-tool' : "Select resize" ,
2020-06-17 13:30:57 -03:00
'select-mirror-tool' : "Select mirror" ,
2019-03-26 21:07:20 -03:00
'-separator-2' : '' ,
2020-08-05 19:04:12 -03:00
'switch-fill' : "Toggle fill/outline" ,
'switch-fill-rule' : "Toggle fill rule" ,
2020-06-20 06:17:56 -03:00
'-separator-3' : '' ,
2019-03-05 08:36:59 -03:00
'increment-line-width' : "Increment line width" ,
'decrement-line-width' : "Decrement line width" ,
'increment-line-width-more' : "Increment line width even more" ,
'decrement-line-width-more' : "Decrement line width even more" ,
2020-08-05 19:04:12 -03:00
'switch-linejoin' : "Change linejoin" ,
'switch-linecap' : "Change linecap" ,
'switch-dash' : "Dashed line" ,
2020-06-20 06:17:56 -03:00
'-separator-4' : '' ,
2020-08-05 19:26:10 -03:00
'switch-font-family' : "Change font family" ,
'reverse-switch-font-family' : "Change font family (reverse)" ,
2020-08-05 19:04:12 -03:00
'switch-font-weight' : "Change font weight" ,
'switch-font-style' : "Change font style" ,
'switch-text-alignment' : "Toggle text alignment" ,
'switch-image-file' : "Change image file" ,
2020-06-20 06:17:56 -03:00
'-separator-5' : '' ,
2019-03-05 08:36:59 -03:00
'toggle-panel-and-dock-visibility' : "Hide panel and dock" ,
'toggle-background' : "Add a drawing background" ,
2020-06-05 10:58:58 -03:00
'toggle-grid' : "Add a grid overlay" ,
2019-03-07 12:32:06 -03:00
'toggle-square-area' : "Square drawing area" ,
2020-06-20 06:17:56 -03:00
'-separator-6' : '' ,
2020-01-03 20:16:20 -03:00
'open-previous-json' : "Open previous drawing" ,
'open-next-json' : "Open next drawing" ,
'save-as-json' : "Save drawing" ,
2019-03-05 08:36:59 -03:00
'save-as-svg' : "Save drawing as a SVG file" ,
2020-03-04 10:23:49 -03:00
'open-user-stylesheet' : "Edit style" ,
2020-06-08 10:26:55 -03:00
'open-preferences' : "Open preferences" ,
2019-03-05 08:36:59 -03:00
'toggle-help' : "Show help"
} ;
2020-06-08 10:26:55 -03:00
if ( GS _VERSION < "3.36" )
delete INTERNAL _KEYBINDINGS [ 'open-preferences' ] ;
2020-06-08 09:30:47 -03:00
function getKeyLabel ( accel ) {
let [ keyval , mods ] = Gtk . accelerator _parse ( accel ) ;
return Gtk . accelerator _get _label ( keyval , mods ) ;
}
2019-03-05 18:00:14 -03:00
var OTHER _SHORTCUTS = [
2020-06-08 09:30:47 -03:00
{ desc : "Draw" , get shortcut ( ) { return _ ( "Left click" ) ; } } ,
{ desc : "Menu" , get shortcut ( ) { return _ ( "Right click" ) ; } } ,
2020-06-28 08:10:31 -03:00
{ desc : "Toggle fill/outline" , get shortcut ( ) { return _ ( "Center click" ) ; } } ,
2020-06-08 09:30:47 -03:00
{ desc : "Increment/decrement line width" , get shortcut ( ) { return _ ( "Scroll" ) ; } } ,
{ desc : "Select color" , get shortcut ( ) { return _ ( "%s … %s" ) . format ( getKeyLabel ( '<Primary>1' ) , getKeyLabel ( '<Primary>9' ) ) ; } } ,
{ desc : "Ignore pointer movement" , get shortcut ( ) { return _ ( "%s held" ) . format ( getKeyLabel ( 'space' ) ) ; } } ,
2020-06-20 06:17:56 -03:00
{ desc : "Leave" , shortcut : getKeyLabel ( 'Escape' ) } ,
{ desc : "-separator-1" , shortcut : "" } ,
2020-06-27 11:55:26 -03:00
{ desc : "Select eraser <span alpha=\"50%\">(while starting drawing)</span>" , shortcut : getKeyLabel ( '<Shift>' ) } ,
2020-06-28 08:10:31 -03:00
{ desc : "Duplicate <span alpha=\"50%\">(while starting handling)</span>" , shortcut : getKeyLabel ( '<Shift>' ) } ,
2020-06-24 04:18:24 -03:00
{ desc : "Rotate rectangle, polygon, polyline" , shortcut : getKeyLabel ( '<Primary>' ) } ,
2020-06-20 06:17:56 -03:00
{ desc : "Extend circle to ellipse" , shortcut : getKeyLabel ( '<Primary>' ) } ,
{ desc : "Curve line" , shortcut : getKeyLabel ( '<Primary>' ) } ,
2020-06-30 08:01:05 -03:00
{ desc : "Smooth free drawing outline" , shortcut : getKeyLabel ( '<Primary>' ) } ,
2020-06-20 06:17:56 -03:00
{ desc : "Rotate <span alpha=\"50%\">(while moving)</span>" , shortcut : getKeyLabel ( '<Primary>' ) } ,
{ desc : "Stretch <span alpha=\"50%\">(while resizing)</span>" , shortcut : getKeyLabel ( '<Primary>' ) } ,
{ desc : "Inverse <span alpha=\"50%\">(while mirroring)</span>" , shortcut : getKeyLabel ( '<Primary>' ) }
2019-03-05 18:00:14 -03:00
] ;
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 ( ) ;
window . resize ( 720 , 500 ) ;
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 ( {
2019-03-28 10:59:14 -03:00
Name : 'DrawOnYourScreenTopStack' ,
GTypeName : 'DrawOnYourScreenTopStack' ,
Extends : Gtk . Stack ,
_init : function ( params ) {
this . parent ( { transition _type : 1 , transition _duration : 500 , expand : true } ) ;
this . prefsPage = new PrefsPage ( ) ;
this . add _titled ( this . prefsPage , 'prefs' , _ ( "Preferences" ) ) ;
this . aboutPage = new AboutPage ( ) ;
this . add _titled ( this . aboutPage , 'about' , _ ( "About" ) ) ;
}
} ) ;
2020-03-02 12:32:50 -03:00
const AboutPage = new GObject . Class ( {
2019-03-28 10:59:14 -03:00
Name : 'DrawOnYourScreenAboutPage' ,
GTypeName : 'DrawOnYourScreenAboutPage' ,
Extends : Gtk . ScrolledWindow ,
_init : function ( params ) {
this . parent ( ) ;
let vbox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin : MARGIN * 3 } ) ;
this . add ( vbox ) ;
2020-01-06 11:29:01 -03:00
let name = "<b> " + _ ( Me . metadata . name ) + "</b>" ;
let version = _ ( "Version %d" ) . format ( Me . metadata . version ) ;
let description = _ ( Me . metadata . description ) ;
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 ) ;
let creditBox = new Gtk . Box ( { orientation : Gtk . Orientation . HORIZONTAL , margin : 2 * MARGIN } ) ;
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-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-03-02 12:32:50 -03:00
const PrefsPage = new GObject . Class ( {
2019-03-08 07:37:59 -03:00
Name : 'DrawOnYourScreenPrefsPage' ,
GTypeName : 'DrawOnYourScreenPrefsPage' ,
2019-03-05 08:36:59 -03:00
Extends : Gtk . ScrolledWindow ,
_init : function ( params ) {
this . parent ( ) ;
this . settings = Convenience . getSettings ( ) ;
2020-01-07 18:15:18 -03:00
let box = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL , margin : MARGIN * 3 } ) ;
2019-03-05 08:36:59 -03:00
this . add ( box ) ;
2020-01-07 18:15:18 -03:00
let globalFrame = new Gtk . Frame ( { label _yalign : 1.0 } ) ;
globalFrame . set _label _widget ( new Gtk . Label ( { margin _bottom : MARGIN / 2 , use _markup : true , label : "<b><big>" + _ ( "Global" ) + "</big></b>" } ) ) ;
box . add ( globalFrame ) ;
let listBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 } ) ;
globalFrame . add ( listBox ) ;
2019-03-05 08:36:59 -03:00
let styleContext = listBox . get _style _context ( ) ;
styleContext . add _class ( 'background' ) ;
let globalKeybindingsWidget = new KeybindingsWidget ( GLOBAL _KEYBINDINGS , this . settings ) ;
globalKeybindingsWidget . margin = MARGIN ;
listBox . add ( globalKeybindingsWidget ) ;
2019-03-10 18:16:11 -03:00
2020-01-07 18:15:18 -03:00
let persistentBox = new Gtk . Box ( { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _left : MARGIN , margin _right : MARGIN } ) ;
2019-03-11 13:53:35 -03:00
let persistentLabelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let persistentLabel1 = new Gtk . Label ( { label : _ ( "Persistent" ) } ) ;
2020-01-07 18:15:18 -03:00
let persistentLabel2 = new Gtk . Label ( { use _markup : true , halign : 1 , wrap : true , xalign : 0 , label : "<small>" + _ ( "Persistent drawing through session restart" ) + "</small>" } ) ;
2019-03-11 13:53:35 -03:00
persistentLabel1 . set _halign ( 1 ) ;
2020-01-07 18:15:18 -03:00
persistentLabel2 . get _style _context ( ) . add _class ( 'dim-label' ) ;
2019-03-11 13:53:35 -03:00
persistentLabelBox . pack _start ( persistentLabel1 , true , true , 0 ) ;
persistentLabelBox . pack _start ( persistentLabel2 , true , true , 0 ) ;
let persistentSwitch = new Gtk . Switch ( { valign : 3 } ) ;
2020-01-07 18:15:18 -03:00
this . settings . bind ( 'persistent-drawing' , persistentSwitch , 'active' , 0 ) ;
2019-03-11 13:53:35 -03:00
persistentBox . pack _start ( persistentLabelBox , true , true , 4 ) ;
persistentBox . pack _start ( persistentSwitch , false , false , 4 ) ;
listBox . add ( persistentBox ) ;
2019-03-28 18:01:39 -03:00
2020-01-07 18:15:18 -03:00
let desktopBox = new Gtk . Box ( { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _left : MARGIN , margin _right : MARGIN } ) ;
2020-01-05 10:50:38 -03:00
let desktopLabelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let desktopLabel1 = new Gtk . Label ( { label : _ ( "Drawing on the desktop" ) } ) ;
2020-01-07 18:15:18 -03:00
let desktopLabel2 = new Gtk . Label ( { use _markup : true , halign : 1 , wrap : true , xalign : 0 , label : "<small>" + _ ( "<i>Draw On Your Screen</i> becomes <i>Draw On Your Desktop</i>" ) + "</small>" } ) ;
2020-01-05 10:50:38 -03:00
desktopLabel1 . set _halign ( 1 ) ;
2020-01-07 18:15:18 -03:00
desktopLabel2 . get _style _context ( ) . add _class ( 'dim-label' ) ;
2020-01-05 10:50:38 -03:00
desktopLabelBox . pack _start ( desktopLabel1 , true , true , 0 ) ;
desktopLabelBox . pack _start ( desktopLabel2 , true , true , 0 ) ;
let desktopSwitch = new Gtk . Switch ( { valign : 3 } ) ;
2020-01-07 18:15:18 -03:00
this . settings . bind ( 'drawing-on-desktop' , desktopSwitch , 'active' , 0 ) ;
2020-01-05 10:50:38 -03:00
desktopBox . pack _start ( desktopLabelBox , true , true , 4 ) ;
desktopBox . pack _start ( desktopSwitch , false , false , 4 ) ;
listBox . add ( desktopBox ) ;
2020-01-07 18:15:18 -03:00
let osdBox = new Gtk . Box ( { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _left : MARGIN , margin _right : MARGIN } ) ;
2019-03-28 18:01:39 -03:00
let osdLabelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let osdLabel1 = new Gtk . Label ( { label : _ ( "Disable on-screen notifications" ) } ) ;
osdLabel1 . set _halign ( 1 ) ;
osdLabelBox . pack _start ( osdLabel1 , true , true , 0 ) ;
let osdSwitch = new Gtk . Switch ( { valign : 3 } ) ;
2020-01-07 18:15:18 -03:00
this . settings . bind ( 'osd-disabled' , osdSwitch , 'active' , 0 ) ;
2019-03-28 18:01:39 -03:00
osdBox . pack _start ( osdLabelBox , true , true , 4 ) ;
osdBox . pack _start ( osdSwitch , false , false , 4 ) ;
listBox . add ( osdBox ) ;
2020-01-07 18:15:18 -03:00
let indicatorBox = new Gtk . Box ( { margin _top : MARGIN / 2 , margin _bottom : MARGIN / 2 , margin _left : MARGIN , margin _right : MARGIN } ) ;
2019-03-28 18:01:39 -03:00
let indicatorLabelBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
let indicatorLabel1 = new Gtk . Label ( { label : _ ( "Disable panel indicator" ) } ) ;
indicatorLabel1 . set _halign ( 1 ) ;
indicatorLabelBox . pack _start ( indicatorLabel1 , true , true , 0 ) ;
let indicatorSwitch = new Gtk . Switch ( { valign : 3 } ) ;
2020-01-07 18:15:18 -03:00
this . settings . bind ( 'indicator-disabled' , indicatorSwitch , 'active' , 0 ) ;
2019-03-28 18:01:39 -03:00
indicatorBox . pack _start ( indicatorLabelBox , true , true , 4 ) ;
indicatorBox . pack _start ( indicatorSwitch , false , false , 4 ) ;
listBox . add ( indicatorBox ) ;
2020-01-05 10:50:38 -03:00
2020-01-07 18:15:18 -03:00
let children = listBox . get _children ( ) ;
for ( let i = 0 ; i < children . length ; i ++ ) {
if ( children [ i ] . activatable )
children [ i ] . set _activatable ( false ) ;
}
let internalFrame = new Gtk . Frame ( { margin _top : 3 * MARGIN , label _yalign : 1.0 } ) ;
internalFrame . set _label _widget ( new Gtk . Label ( { margin _bottom : MARGIN / 2 , use _markup : true , label : "<b><big>" + _ ( "Internal" ) + " </big></b>" + _ ( "(in drawing mode)" ) } ) ) ;
box . add ( internalFrame ) ;
2019-03-05 08:36:59 -03:00
2020-01-07 18:15:18 -03:00
listBox = new Gtk . ListBox ( { selection _mode : 0 , hexpand : true , margin _top : MARGIN } ) ;
internalFrame . add ( listBox ) ;
2019-03-05 08:36:59 -03:00
2020-01-07 18:15:18 -03:00
styleContext = listBox . get _style _context ( ) ;
styleContext . add _class ( 'background' ) ;
2019-03-05 08:36:59 -03:00
2019-03-05 18:00:14 -03:00
for ( let i = 0 ; i < OTHER _SHORTCUTS . length ; i ++ ) {
if ( OTHER _SHORTCUTS [ i ] . desc . indexOf ( '-separator-' ) != - 1 ) {
2019-03-05 08:36:59 -03:00
listBox . add ( new Gtk . Box ( { margin _top : MARGIN , margin _left : MARGIN , margin _right : MARGIN } ) ) ;
continue ;
}
let otherBox = new Gtk . Box ( { margin _left : MARGIN , margin _right : MARGIN } ) ;
2020-06-20 06:17:56 -03:00
let otherLabel = new Gtk . Label ( { label : _ ( OTHER _SHORTCUTS [ i ] . desc ) , use _markup : true } ) ;
2019-03-05 08:36:59 -03:00
otherLabel . set _halign ( 1 ) ;
2020-06-08 09:30:47 -03:00
let otherLabel2 = new Gtk . Label ( { label : OTHER _SHORTCUTS [ i ] . shortcut } ) ;
2019-03-05 08:36:59 -03:00
otherBox . pack _start ( otherLabel , true , true , 4 ) ;
otherBox . pack _start ( otherLabel2 , false , false , 4 ) ;
listBox . add ( otherBox ) ;
}
let internalKeybindingsWidget = new KeybindingsWidget ( INTERNAL _KEYBINDINGS , this . settings ) ;
internalKeybindingsWidget . margin = MARGIN ;
listBox . add ( internalKeybindingsWidget ) ;
2020-01-07 18:15:18 -03:00
let styleBox = new Gtk . Box ( { margin : MARGIN } ) ;
2020-01-06 17:24:29 -03:00
let styleLabel = new Gtk . Label ( {
2020-01-07 18:15:18 -03:00
wrap : true ,
xalign : 0 ,
2020-01-06 17:24:29 -03:00
use _markup : true ,
2020-03-04 10:23:49 -03:00
label : _ ( "<b>Default</b> drawing style attributes (color palette, font, line, dash) are defined in an editable <b>css</b> file.\n" +
"See <i>“%s”</i>." ) . format ( _ ( "Edit style" ) )
2020-01-06 17:24:29 -03:00
} ) ;
2019-03-05 08:36:59 -03:00
styleLabel . set _halign ( 1 ) ;
2020-01-07 18:15:18 -03:00
styleLabel . get _style _context ( ) . add _class ( 'dim-label' ) ;
2019-03-05 08:36:59 -03:00
styleBox . pack _start ( styleLabel , true , true , 4 ) ;
listBox . add ( styleBox ) ;
2020-01-07 18:15:18 -03:00
let noteBox = new Gtk . Box ( { margin : MARGIN } ) ;
2019-03-05 08:36:59 -03:00
let noteLabel = new Gtk . Label ( {
2020-01-07 18:15:18 -03:00
wrap : true ,
xalign : 0 ,
2019-03-05 08:36:59 -03:00
use _markup : true ,
2020-06-28 08:10:31 -03:00
label : _ ( "When you save elements made with <b>eraser</b> in a <b>SVG</b> file, " +
2020-01-07 18:15:18 -03:00
"they are colored with background color, transparent if it is disabled.\n" +
"See <i>“%s”</i> or edit the SVG file afterwards." ) . format ( _ ( "Add a drawing background" ) )
2019-03-05 08:36:59 -03:00
} ) ;
noteLabel . set _halign ( 1 ) ;
2020-01-07 18:15:18 -03:00
noteLabel . get _style _context ( ) . add _class ( 'dim-label' ) ;
2019-03-05 08:36:59 -03:00
noteBox . pack _start ( noteLabel , true , true , 4 ) ;
listBox . add ( noteBox ) ;
2020-01-07 18:15:18 -03:00
children = listBox . get _children ( ) ;
2019-03-05 08:36:59 -03:00
for ( let i = 0 ; i < children . length ; i ++ ) {
if ( children [ i ] . activatable )
children [ i ] . set _activatable ( false ) ;
}
}
} ) ;
// 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 ( {
2019-03-08 07:37:59 -03:00
Name : 'DrawOnYourScreenKeybindings.Widget' ,
GTypeName : 'DrawOnYourScreenKeybindingsWidget' ,
2019-03-05 08:36:59 -03:00
Extends : Gtk . Box ,
_init : function ( keybindings , settings ) {
this . parent ( ) ;
this . set _orientation ( Gtk . Orientation . VERTICAL ) ;
this . _keybindings = keybindings ;
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 ;
this . _refresh ( ) ;
} ,
_refresh : function ( ) {
this . _store . clear ( ) ;
for ( let settings _key in this . _keybindings ) {
if ( settings _key . indexOf ( '-separator-' ) != - 1 )
continue ;
let [ key , mods ] = Gtk . accelerator _parse (
this . _settings . get _strv ( settings _key ) [ 0 ]
) ;
let iter = this . _store . append ( ) ;
this . _store . set ( iter ,
[
this . _columns . NAME ,
this . _columns . ACCEL _NAME ,
this . _columns . MODS ,
this . _columns . KEY
] ,
[
settings _key ,
_ ( this . _keybindings [ settings _key ] ) ,
mods ,
key
]
) ;
}
}
} ) ;