Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/io.github.josephmawa.Bella.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<range min="0" max="4" />
<default>0</default>
</key>
<key name="copy-color" type="b">
<summary>Copy picked color to clipboard immediately</summary>
<default>false</default>
</key>
<key name="precision" type="i">
<range min="0" max="10" />
<default>2</default>
Expand Down
28 changes: 19 additions & 9 deletions src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
""
"",
),
},
},
Expand All @@ -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(
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -78,7 +88,7 @@ export const BellaPreferencesDialog = GObject.registerClass(
return [true, colorFormatObject.key];
}
return [false, "rgb"];
}
},
);
}

Expand All @@ -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;
};
}
},
);
6 changes: 6 additions & 0 deletions src/ui/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<property name="subtitle" translatable="yes">Select color format to display</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="copy_to_clipboard">
<property name="title" translatable="yes">Copy color</property>
<property name="subtitle" translatable="yes">Copy picked color to clipboard</property>
</object>
</child>
<child>
<object class="AdwSpinRow" id="precision_spin_row">
<property name="title" translatable="yes">Precision</property>
Expand Down
57 changes: 34 additions & 23 deletions src/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
},
},
Expand All @@ -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,
);
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -227,7 +227,7 @@ export const BellaWindow = GObject.registerClass(
"displayed_format",
buffer,
"text",
GObject.BindingFlags.SYNC_CREATE
GObject.BindingFlags.SYNC_CREATE,
);
});

Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -392,7 +395,7 @@ export const BellaWindow = GObject.registerClass(
: "no_saved_color_stack_page";
return [true, visiblePage];
},
null
null,
);
};

Expand All @@ -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);
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -640,7 +651,7 @@ export const BellaWindow = GObject.registerClass(
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null
null,
);

if (!success) {
Expand All @@ -667,5 +678,5 @@ export const BellaWindow = GObject.registerClass(
const contentProvider = Gdk.ContentProvider.new_for_value(text);
clipboard.set_content(contentProvider);
};
}
},
);