implement issue #15: Remember last color format; add settings-class

This commit is contained in:
Ronny Dobra committed 2017-06-26 22:18:58 +02:00
1 parent 657f7594f1
commit a9b2386cc4
8 files changed
+81 -23

No files matched your search

@@ -13,6 +13,11 @@
<summary>Most recent y position of app window</summary>
<description>Most recent y position of app window</description>
</key>
<key name="color-format-index" type="i">
<default>2</default>
<summary>Most recent index of selected color format</summary>
<description>Most recent index of selected color format</description>
</key>
<key name="color-history" type="as">
<default>[]</default>
<summary>Color History</summary>
+1
View File
@@ -24,6 +24,7 @@ executable(
'src/Widgets/ColorArea.vala',
'src/Widgets/ColorHistory.vala',
'src/Widgets/MousePosition.vala',
'src/Services/Settings.vala',
c_args: c_args,
dependencies: [
dependency('glib-2.0'),
+7 -1
View File
@@ -11,7 +11,7 @@
* 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
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
@@ -20,9 +20,13 @@
*/
namespace ColorPicker {
// namespace-wide variable
public ColorPicker.Services.Settings settings;
public class ColorPickerApp : Granite.Application {
public ColorPickerApp () {
Object (application_id: "com.github.ronnydo.colorpicker",
flags: ApplicationFlags.FLAGS_NONE);
@@ -34,6 +38,8 @@ namespace ColorPicker {
return;
}
settings = ColorPicker.Services.Settings.get_instance ();
var app_window = new ColorPickerWindow (this);
app_window.show_all ();
+16 -14
View File
@@ -24,7 +24,7 @@ namespace ColorPicker {
public class ColorPickerWindow: Gtk.Dialog {
ExtRGBA ext_active_color = ExtRGBA ();
public ColorPickerWindow (Gtk.Application application) {
Object (application: application,
icon_name: "com.github.ronnydo.colorpicker",
@@ -32,15 +32,14 @@ namespace ColorPicker {
resizable: false,
//height_request: 500,
width_request: 500
);
);
}
construct {
// main box
// main box
ext_active_color.parse ("#FFFFFF");
var color_area = new ColorArea ();
var color_area = new ColorPicker.Widgets.ColorArea ();
color_area.set_color (ext_active_color);
var hex_label = new Gtk.Label (ext_active_color.to_uppercase_hex_string ());
@@ -87,7 +86,7 @@ namespace ColorPicker {
color_format_combobox.append_text ("rgba");
color_format_combobox.append_text ("Gdk RGBA");
color_format_combobox.append_text ("Qt rgba");
color_format_combobox.active = 2;
color_format_combobox.active = settings.color_format_index;
var adjust_button = new Gtk.Button.from_icon_name ("media-eq-symbolic");
adjust_button.margin_start = 12;
@@ -108,7 +107,7 @@ namespace ColorPicker {
color_history_label.get_style_context ().add_class ("h4");
color_history_label.halign = Gtk.Align.START;
var color_history = new ColorHistory ();
var color_history = new ColorPicker.Widgets.ColorHistory ();
var color_history_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
color_history_box.margin_top = 6;
@@ -145,9 +144,8 @@ namespace ColorPicker {
}
}
var settings = new Settings ("com.github.ronnydo.colorpicker");
var window_x = settings.get_int ("window-x");
var window_y = settings.get_int ("window-y");
var window_x = settings.window_x;
var window_y = settings.window_y;
if (window_x != -1 || window_y != -1) {
move (window_x, window_y);
@@ -207,10 +205,15 @@ namespace ColorPicker {
}
});
//color_format_combobox.changed.connect (color_format_changed);
color_format_combobox.changed.connect (() => {
int id = color_format_combobox.get_active ();
update_color_format_combobox_text (format_entry, id);
ColorPicker.settings.color_format_index = id;
});
// handle changed color in color history
color_history.color_clicked.connect ((t, color) => {
@@ -259,9 +262,8 @@ namespace ColorPicker {
int root_x, root_y;
get_position (out root_x, out root_y);
var settings = new Settings ("com.github.ronnydo.colorpicker");
settings.set_int ("window-x", root_x);
settings.set_int ("window-y", root_y);
settings.window_x = root_x;
settings.window_y = root_y;
return false;
}
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2017 Ronny Dobra (https://github.com/RonnyDo/ColorPicker)
*
* 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Ronny Dobra <ronnydobra at arcor dot de>
*/
namespace ColorPicker.Services {
public class Settings : Granite.Services.Settings {
private static Settings? instance = null;
public int window_x { get; set; }
public int window_y { get; set; }
public int color_format_index { get; set; }
public string[] color_history { get; set; }
public static Settings get_instance () {
if (instance == null) {
instance = new Settings ();
}
return instance;
}
private Settings () {
base ("com.github.ronnydo.colorpicker");
}
}
}
+1 -1
View File
@@ -19,7 +19,7 @@
* Authored by: Ronny Dobra <ronnydobra at arcor dot de>
*/
namespace ColorPicker {
namespace ColorPicker.Widgets {
public class ColorArea: Gtk.DrawingArea {
+4 -7
View File
@@ -18,7 +18,8 @@
*
* Authored by: Ronny Dobra <ronnydobra at arcor dot de>
*/
namespace ColorPicker {
namespace ColorPicker.Widgets {
public class ColorHistory: Gtk.DrawingArea {
@@ -56,8 +57,7 @@ namespace ColorPicker {
}
private void restore_colors () {
var settings = new Settings ("com.github.ronnydo.colorpicker");
var color_array = settings.get_strv ("color-history");
var color_array = settings.color_history;
if (color_array != null) {
// if more colors should be saved as allowed, drop the oldest ones.
@@ -85,8 +85,7 @@ namespace ColorPicker {
c_array[i] = c_list.get (i).to_string ();
}
var settings = new Settings ("com.github.ronnydo.colorpicker");
settings.set_strv ("color-history", c_array);
settings.color_history = c_array;
}
public void add_color (Gdk.RGBA color) {
@@ -220,8 +219,6 @@ namespace ColorPicker {
public override bool button_release_event (Gdk.EventButton e) {
stdout.printf("clicked");
if (e.button != 1) {
return true;
}
+1
View File
@@ -22,6 +22,7 @@
namespace ColorPicker.Widgets {
public class MousePosition : Granite.Widgets.CompositedWindow {
public signal void picked (Gdk.RGBA color);
public signal void cancelled ();
public signal void moved (Gdk.RGBA color);