Permalink
Browse files

first attempt at fifo option

  • Loading branch information...
1 parent 045d42a commit ade534859e3e5d0b1dc2db25de9bd3a5730e6ac1 whyoh committed Apr 16, 2012
@@ -77,6 +77,14 @@
</_description>
</key>
+ <key name="fifo" type="b">
+ <default>false</default>
+ <_summary>Copy new items to the end of the list so that they are pasted last?</_summary>
+ <_description>
+ By default new items are added to the top of the list so that they are pasted first.
+ </_description>
+ </key>
+
<key name="show-history" type="s">
<default>'&lt;Ctrl&gt;&lt;Alt&gt;H'</default>
<_summary>The keyboard shortcut to display the menu</_summary>
View
@@ -98,17 +98,28 @@ g_paste_history_add (GPasteHistory *self,
}
}
}
- history = priv->history = g_slist_prepend (priv->history, g_object_ref (item));
+ gboolean fifo = g_paste_settings_get_fifo (priv->settings);
+ history = priv->history = fifo ?
+ g_slist_append (priv->history, g_object_ref (item)) :
+ g_slist_prepend (priv->history, g_object_ref (item));
guint max_history_size = g_paste_settings_get_max_history_size (priv->settings);
if (g_slist_length (history) > max_history_size)
{
- for (guint i = 0; i < max_history_size - 1; ++i)
- history = g_slist_next (history);
- g_slist_free_full (g_slist_next (history),
- g_object_unref);
- history->next = NULL;
+ if (fifo) {
+ /* start the shortened list at the right place */
+ priv->history = g_slist_nth(history, g_slist_length(history) - max_history_size);
+ /* terminate the original list so that it can be freed (below) */
+ g_slist_nth(history, g_slist_length(history) - max_history_size - 1)->next = NULL;
+ }
+ else {
+ for (guint i = 0; i < max_history_size - 1; ++i)
+ history = g_slist_next (history);
+ }
+ g_slist_free_full (g_slist_next (history),
+ g_object_unref);
+ history->next = NULL;
}
g_signal_emit (self,
@@ -36,6 +36,7 @@
#define MAX_TEXT_ITEM_SIZE_KEY "max-text-item-size"
#define SHOW_HISTORY_KEY "show-history"
#define PASTE_AND_POP_KEY "paste-and-pop"
+#define FIFO_KEY "fifo"
G_DEFINE_TYPE (GPasteSettings, g_paste_settings, G_TYPE_OBJECT)
@@ -49,6 +50,7 @@ struct _GPasteSettingsPrivate
gboolean synchronize_clipboards;
gboolean save_history;
gboolean trim_items;
+ gboolean fifo;
guint max_history_size;
guint max_displayed_history_size;
guint element_size;
@@ -352,6 +354,53 @@ g_paste_settings_set_trim_items (GPasteSettings *self,
}
/**
+ * g_paste_settings_get_fifo:
+ * @self: a #GPasteSettings instance
+ *
+ * Get the FIFO_KEY setting
+ *
+ * Returns: the value of the FIFO_KEY setting
+ */
+G_PASTE_VISIBLE gboolean
+g_paste_settings_get_fifo (GPasteSettings *self)
+{
+ g_return_val_if_fail (G_PASTE_IS_SETTINGS (self), FALSE);
+
+ return self->priv->fifo;
+}
+
+static void
+g_paste_settings_set_fifo_from_dconf (GPasteSettings *self)
+{
+ g_return_if_fail (G_PASTE_IS_SETTINGS (self));
+
+ GPasteSettingsPrivate *priv = self->priv;
+
+ priv->fifo = g_settings_get_boolean (priv->settings, FIFO_KEY);
+}
+
+/**
+ * g_paste_settings_set_fifo:
+ * @self: a #GPasteSettings instance
+ * @value: whether to trim or not textual items
+ *
+ * Change the FIFO_KEY setting
+ *
+ * Returns:
+ */
+G_PASTE_VISIBLE void
+g_paste_settings_set_fifo (GPasteSettings *self,
+ gboolean value)
+{
+ g_return_if_fail (G_PASTE_IS_SETTINGS (self));
+
+ GPasteSettingsPrivate *priv = self->priv;
+
+ priv->fifo = value;
+ g_settings_set_boolean (priv->settings, FIFO_KEY, value);
+}
+
+/**
* g_paste_settings_get_max_history_size:
* @self: a #GPasteSettings instance
*
@@ -771,6 +820,8 @@ g_paste_settings_settings_changed (GSettings *settings G_GNUC_UNUSED,
g_paste_settings_set_save_history_from_dconf (self);
else if (g_strcmp0 (key, TRIM_ITEMS_KEY) == 0)
g_paste_settings_set_trim_items_from_dconf (self);
+ else if (g_strcmp0 (key, FIFO_KEY) == 0)
+ g_paste_settings_set_fifo_from_dconf (self);
else if (g_strcmp0 (key, MAX_HISTORY_SIZE_KEY) == 0)
g_paste_settings_set_max_history_size_from_dconf (self);
else if (g_strcmp0 (key, MAX_DISPLAYED_HISTORY_SIZE_KEY) == 0)
@@ -820,6 +871,7 @@ g_paste_settings_init (GPasteSettings *self)
g_paste_settings_set_synchronize_clipboards_from_dconf (self);
g_paste_settings_set_save_history_from_dconf (self);
g_paste_settings_set_trim_items_from_dconf (self);
+ g_paste_settings_set_fifo_from_dconf (self);
g_paste_settings_set_max_history_size_from_dconf (self);
g_paste_settings_set_max_displayed_history_size_from_dconf (self);
g_paste_settings_set_element_size_from_dconf (self);
@@ -53,6 +53,7 @@ gboolean g_paste_settings_get_primary_to_history (GPasteSettings *se
gboolean g_paste_settings_get_synchronize_clipboards (GPasteSettings *self);
gboolean g_paste_settings_get_save_history (GPasteSettings *self);
gboolean g_paste_settings_get_trim_items (GPasteSettings *self);
+gboolean g_paste_settings_get_fifo (GPasteSettings *self);
guint g_paste_settings_get_max_history_size (GPasteSettings *self);
guint g_paste_settings_get_max_displayed_history_size (GPasteSettings *self);
guint g_paste_settings_get_element_size (GPasteSettings *self);
@@ -73,6 +74,8 @@ void g_paste_settings_set_save_history (GPasteSettings *self,
gboolean value);
void g_paste_settings_set_trim_items (GPasteSettings *self,
gboolean value);
+void g_paste_settings_set_fifo (GPasteSettings *self,
+ gboolean value);
void g_paste_settings_set_max_history_size (GPasteSettings *self,
guint value);
void g_paste_settings_set_max_displayed_history_size (GPasteSettings *self,
View
@@ -75,6 +75,7 @@ global:
g_paste_settings_get_max_text_item_size;
g_paste_settings_get_show_history;
g_paste_settings_get_paste_and_pop;
+ g_paste_settings_get_fifo;
g_paste_settings_set_track_changes;
g_paste_settings_set_track_extension_state;
g_paste_settings_set_primary_to_history;
@@ -88,6 +89,7 @@ global:
g_paste_settings_set_max_text_item_size;
g_paste_settings_set_show_history;
g_paste_settings_set_paste_and_pop;
+ g_paste_settings_set_fifo;
g_paste_settings_new;
g_paste_xcb_wrapper_get_type;
@@ -24,6 +24,7 @@ public class Window : Gtk.Window {
private Gtk.CheckButton synchronize_clipboards_button;
private Gtk.CheckButton save_history_button;
private Gtk.CheckButton trim_items_button;
+ private Gtk.CheckButton fifo_button;
private Gtk.SpinButton max_history_size_button;
private Gtk.SpinButton max_displayed_history_size_button;
private Gtk.SpinButton element_size_button;
@@ -86,6 +87,15 @@ public class Window : Gtk.Window {
}
}
+ public bool fifo {
+ get {
+ return this.fifo_button.get_active ();
+ }
+ set {
+ this.fifo_button.set_active (value);
+ }
+ }
+
public uint32 max_history_size {
get {
return (uint32)this.max_history_size_button.get_value_as_int ();
@@ -213,6 +223,13 @@ public class Window : Gtk.Window {
});
grid.attach (trim_items_button, 0, current_line++, 2, 1);
+ this.fifo_button = new Gtk.CheckButton.with_mnemonic (_("_Copy to end of history"));
+ this.fifo = app.settings.get_fifo ();
+ this.fifo_button.toggled.connect (() => {
+ app.settings.set_fifo (this.fifo);
+ });
+ grid.attach (fifo_button, 0, current_line++, 2, 1);
+
grid.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, current_line++, 2, 1);
var max_history_size_label = new Gtk.Label (_("Max history size: "));
@@ -326,6 +343,9 @@ public class Main : Gtk.Application {
case "trim-items":
this.window.trim_items = this.settings.get_trim_items ();
break;
+ case "fifo":
+ this.window.fifo = this.settings.get_fifo ();
+ break;
case "max-history-size":
this.window.max_history_size = this.settings.get_max_history_size ();
break;

0 comments on commit ade5348

Please sign in to comment.