diff --git a/data/io.github.josephmawa.Bella.gschema.xml b/data/io.github.josephmawa.Bella.gschema.xml index 4f59591..792a3b4 100644 --- a/data/io.github.josephmawa.Bella.gschema.xml +++ b/data/io.github.josephmawa.Bella.gschema.xml @@ -14,6 +14,10 @@ 0 + + Copy picked color to clipboard immediately + false + 2 diff --git a/src/prefs.js b/src/prefs.js index b2d4a53..3cf7525 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -9,14 +9,18 @@ export const BellaPreferencesDialog = GObject.registerClass( { GTypeName: "BellaPreferencesDialog", Template: getResourceUri("prefs.ui"), - InternalChildren: ["color_format_settings", "precision_spin_row"], + InternalChildren: [ + "copy_to_clipboard", + "precision_spin_row", + "color_format_settings", + ], Properties: { color_format: GObject.ParamSpec.string( "color_format", "color-format", "Color format", GObject.ParamFlags.READWRITE, - "" + "", ), }, }, @@ -29,13 +33,19 @@ export const BellaPreferencesDialog = GObject.registerClass( "color-format", this, "color_format", - Gio.SettingsBindFlags.DEFAULT + Gio.SettingsBindFlags.DEFAULT, ); settings.bind( "precision", this._precision_spin_row.adjustment, "value", - Gio.SettingsBindFlags.DEFAULT + Gio.SettingsBindFlags.DEFAULT, + ); + settings.bind( + "copy-color", + this._copy_to_clipboard, + "active", + Gio.SettingsBindFlags.DEFAULT, ); this.bind_property_full( @@ -45,7 +55,7 @@ export const BellaPreferencesDialog = GObject.registerClass( GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE, (_, colorFormat) => { const colorFormatObject = formats.find( - ({ key }) => key === colorFormat + ({ key }) => key === colorFormat, ); if (!colorFormatObject) { @@ -69,7 +79,7 @@ export const BellaPreferencesDialog = GObject.registerClass( if (stringObject?.string) { const colorFormatObject = formats.find( - ({ description }) => description === stringObject?.string + ({ description }) => description === stringObject?.string, ); if (!colorFormatObject) { @@ -78,7 +88,7 @@ export const BellaPreferencesDialog = GObject.registerClass( return [true, colorFormatObject.key]; } return [false, "rgb"]; - } + }, ); } @@ -89,9 +99,9 @@ export const BellaPreferencesDialog = GObject.registerClass( const expression = Gtk.PropertyExpression.new( Gtk.StringObject, null, - "string" + "string", ); this._color_format_settings.expression = expression; }; - } + }, ); diff --git a/src/ui/prefs.ui b/src/ui/prefs.ui index 7338a83..264e687 100644 --- a/src/ui/prefs.ui +++ b/src/ui/prefs.ui @@ -92,6 +92,12 @@ Select color format to display + + + Copy color + Copy picked color to clipboard + + Precision diff --git a/src/window.js b/src/window.js index bdfd0da..6a22d2e 100644 --- a/src/window.js +++ b/src/window.js @@ -59,14 +59,14 @@ export const BellaWindow = GObject.registerClass( "colorFormat", "Selected color format", GObject.ParamFlags.READWRITE, - "" + "", ), visible_color: GObject.ParamSpec.object( "visible_color", "visibleColor", "Color formats to display on picked color page", GObject.ParamFlags.READWRITE, - Color + Color, ), }, }, @@ -91,7 +91,7 @@ export const BellaWindow = GObject.registerClass( Gtk.StyleContext.add_provider_for_display( this.display, cssProvider, - Gtk.STYLE_PROVIDER_PRIORITY_USER + Gtk.STYLE_PROVIDER_PRIORITY_USER, ); }; @@ -123,7 +123,7 @@ export const BellaWindow = GObject.registerClass( key, actionRow, "subtitle", - GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE + GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE, ); this._color_format_pref_group.add(actionRow); @@ -153,7 +153,7 @@ export const BellaWindow = GObject.registerClass( nameProp.key, actionRow, "subtitle", - GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE + GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE, ); this._color_name_pref_group.add(actionRow); @@ -227,7 +227,7 @@ export const BellaWindow = GObject.registerClass( "displayed_format", buffer, "text", - GObject.BindingFlags.SYNC_CREATE + GObject.BindingFlags.SYNC_CREATE, ); }); @@ -244,10 +244,10 @@ export const BellaWindow = GObject.registerClass( (_, rgb) => { const rgba = new Gdk.RGBA(); rgba.parse(rgb); - return [true, rgba] + return [true, rgba]; }, - null - ) + null, + ); }); actionsFactory.connect("bind", (factory, listItem) => { @@ -275,10 +275,13 @@ export const BellaWindow = GObject.registerClass( }); const colorColumn = Gtk.ColumnViewColumn.new(_("Color"), colorFactory); - const previewColumn = Gtk.ColumnViewColumn.new(_("Preview"), previewFactory); + const previewColumn = Gtk.ColumnViewColumn.new( + _("Preview"), + previewFactory, + ); const actionsColumn = Gtk.ColumnViewColumn.new( _("Actions"), - actionsFactory + actionsFactory, ); this._column_view.append_column(colorColumn); @@ -336,25 +339,25 @@ export const BellaWindow = GObject.registerClass( "window-width", this, "default-width", - Gio.SettingsBindFlags.DEFAULT + Gio.SettingsBindFlags.DEFAULT, ); settings.bind( "window-height", this, "default-height", - Gio.SettingsBindFlags.DEFAULT + Gio.SettingsBindFlags.DEFAULT, ); settings.bind( "window-maximized", this, "maximized", - Gio.SettingsBindFlags.DEFAULT + Gio.SettingsBindFlags.DEFAULT, ); settings.bind( "color-format", this, "color_format", - Gio.SettingsBindFlags.GET + Gio.SettingsBindFlags.GET, ); settings.connect("changed::color-scheme", this.setColorScheme); @@ -367,7 +370,7 @@ export const BellaWindow = GObject.registerClass( if (visibleChildName === "color_format_page") { signalId.id = this._color_dialog_button.connect( "notify::rgba", - this.selectColorHandler + this.selectColorHandler, ); return; } @@ -392,7 +395,7 @@ export const BellaWindow = GObject.registerClass( : "no_saved_color_stack_page"; return [true, visiblePage]; }, - null + null, ); }; @@ -402,7 +405,8 @@ export const BellaWindow = GObject.registerClass( ?.get_first_child() ?.get_first_child(); const previewColumnViewTitle = colorColumnViewTitle?.get_next_sibling(); - const actionsColumnViewTitle = previewColumnViewTitle?.get_next_sibling(); + const actionsColumnViewTitle = + previewColumnViewTitle?.get_next_sibling(); colorColumnViewTitle?.get_first_child()?.set_halign(Gtk.Align.CENTER); previewColumnViewTitle?.get_first_child()?.set_halign(Gtk.Align.CENTER); @@ -416,17 +420,17 @@ export const BellaWindow = GObject.registerClass( const showPrefsWin = Gio.SimpleAction.new("preferences", null); const deleteSavedColors = Gio.SimpleAction.new( "delete-saved-colors", - null + null, ); const backToMainPage = Gio.SimpleAction.new("back", null); const pickColor = Gio.SimpleAction.new("pick-color", null); const setEyeDropperStackPage = Gio.SimpleAction.new( "set_eye_dropper_stack_page", - GLib.VariantType.new("s") + GLib.VariantType.new("s"), ); const setSavedColorStackPage = Gio.SimpleAction.new( "set_saved_colors_stack_page", - GLib.VariantType.new("s") + GLib.VariantType.new("s"), ); showPrefsWin.connect("activate", () => { @@ -515,6 +519,13 @@ export const BellaWindow = GObject.registerClass( this.setColorDialogButtonRgba(color.rgb); // Switch page after setting the ColorDialogButton RGB this._main_stack.visible_child_name = "color_format_page"; + + if (settings.get_boolean("copy-color")) { + const displayedFormat = this.visible_color.displayed_format; + this.copyToClipboard(displayedFormat); + this.displayToast(_("Copied %s").format(displayedFormat)); + } + this.saveData(); } catch (err) { if (err instanceof GLib.Error) { @@ -640,7 +651,7 @@ export const BellaWindow = GObject.registerClass( null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, - null + null, ); if (!success) { @@ -667,5 +678,5 @@ export const BellaWindow = GObject.registerClass( const contentProvider = Gdk.ContentProvider.new_for_value(text); clipboard.set_content(contentProvider); }; - } + }, );