[gthumb] location chooser: allow to show 'other' without the entry points
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] location chooser: allow to show 'other' without the entry points
- Date: Wed, 11 Dec 2019 16:50:23 +0000 (UTC)
commit e30ac590570cec72319820459457de77b7cfd2fd
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Dec 7 19:55:32 2019 +0100
location chooser: allow to show 'other' without the entry points
extensions/find_duplicates/dlg-find-duplicates.c | 1 +
extensions/search/gth-search-source-selector.c | 1 +
gthumb/dlg-preferences-general.c | 3 +-
gthumb/gth-location-bar.c | 1 +
gthumb/gth-location-chooser-dialog.c | 1 +
gthumb/gth-location-chooser.c | 185 +++++++++++++++--------
6 files changed, 128 insertions(+), 64 deletions(-)
---
diff --git a/extensions/find_duplicates/dlg-find-duplicates.c
b/extensions/find_duplicates/dlg-find-duplicates.c
index f90dd9a6..0d1440fd 100644
--- a/extensions/find_duplicates/dlg-find-duplicates.c
+++ b/extensions/find_duplicates/dlg-find-duplicates.c
@@ -113,6 +113,7 @@ dlg_find_duplicates (GthBrowser *browser)
data->location_chooser = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", TRUE,
+ "show-other", TRUE,
"relief", GTK_RELIEF_NORMAL,
NULL);
gtk_widget_show (data->location_chooser);
diff --git a/extensions/search/gth-search-source-selector.c b/extensions/search/gth-search-source-selector.c
index 9f80183e..e86afed9 100644
--- a/extensions/search/gth-search-source-selector.c
+++ b/extensions/search/gth-search-source-selector.c
@@ -115,6 +115,7 @@ gth_search_source_selector_construct (GthSearchSourceSelector *self)
self->priv->location_chooser = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", TRUE,
+ "show-other", TRUE,
"relief", GTK_RELIEF_NORMAL,
NULL);
gtk_widget_show (self->priv->location_chooser);
diff --git a/gthumb/dlg-preferences-general.c b/gthumb/dlg-preferences-general.c
index 0e772d76..03203a9e 100644
--- a/gthumb/dlg-preferences-general.c
+++ b/gthumb/dlg-preferences-general.c
@@ -154,7 +154,8 @@ general__dlg_preferences_construct_cb (GtkWidget *dialog,
data->starup_location_chooser = g_object_new (
GTH_TYPE_LOCATION_CHOOSER,
- "show-entry-points", TRUE,
+ "show-entry-points", FALSE,
+ "show-other", TRUE,
"relief", GTK_RELIEF_NORMAL,
NULL);
gtk_widget_show (data->starup_location_chooser);
diff --git a/gthumb/gth-location-bar.c b/gthumb/gth-location-bar.c
index ffac1f93..949f6dbd 100644
--- a/gthumb/gth-location-bar.c
+++ b/gthumb/gth-location-bar.c
@@ -68,6 +68,7 @@ gth_location_bar_init (GthLocationBar *self)
gtk_widget_show (box);
self->priv->location_chooser = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", FALSE,
+ "show-other", FALSE,
"relief", GTK_RELIEF_NONE,
NULL);
gtk_widget_show (self->priv->location_chooser);
diff --git a/gthumb/gth-location-chooser-dialog.c b/gthumb/gth-location-chooser-dialog.c
index 285a5327..63caf312 100644
--- a/gthumb/gth-location-chooser-dialog.c
+++ b/gthumb/gth-location-chooser-dialog.c
@@ -150,6 +150,7 @@ _gth_location_chooser_dialog_construct (GthLocationChooserDialog *self)
self->priv->entry = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", FALSE,
+ "show-other", FALSE,
"show-root", TRUE,
NULL);
self->priv->entry_changed_id =
diff --git a/gthumb/gth-location-chooser.c b/gthumb/gth-location-chooser.c
index a13cbaa7..684b6d1a 100644
--- a/gthumb/gth-location-chooser.c
+++ b/gthumb/gth-location-chooser.c
@@ -38,13 +38,13 @@
#define MIN_WIDTH 200
-enum {
+typedef enum {
ITEM_TYPE_NONE,
ITEM_TYPE_SEPARATOR,
ITEM_TYPE_LOCATION,
ITEM_TYPE_ENTRY_POINT,
ITEM_TYPE_CHOOSE_LOCATION
-};
+} ItemType;
enum {
ICON_COLUMN,
@@ -58,6 +58,7 @@ enum {
enum {
PROP_0,
PROP_SHOW_ENTRY_POINTS,
+ PROP_SHOW_OTHER,
PROP_SHOW_ROOT,
PROP_RELIEF
};
@@ -78,6 +79,7 @@ struct _GthLocationChooserPrivate {
guint update_location_list_id;
gboolean show_entry_points;
gboolean show_root;
+ gboolean show_other;
GtkReliefStyle relief;
gboolean reload;
};
@@ -109,6 +111,9 @@ gth_location_chooser_set_property (GObject *object,
case PROP_SHOW_ROOT:
self->priv->show_root = g_value_get_boolean (value);
break;
+ case PROP_SHOW_OTHER:
+ self->priv->show_other = g_value_get_boolean (value);
+ break;
case PROP_RELIEF:
gth_location_chooser_set_relief (self, g_value_get_enum (value));
break;
@@ -135,6 +140,9 @@ gth_location_chooser_get_property (GObject *object,
case PROP_SHOW_ROOT:
g_value_set_boolean (value, self->priv->show_root);
break;
+ case PROP_SHOW_OTHER:
+ g_value_set_boolean (value, self->priv->show_other);
+ break;
case PROP_RELIEF:
g_value_set_enum (value, self->priv->relief);
break;
@@ -362,42 +370,100 @@ clear_items_from_separator (GthLocationChooser *self,
static void
-clear_entry_point_list (GthLocationChooser *self)
+delete_section_by_type (GthLocationChooser *self,
+ ItemType type_to_delete)
+{
+ GtkTreeIter iter;
+ gboolean valid;
+ gboolean prev_matched;
+
+ if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->model), &iter))
+ return;
+
+ prev_matched = FALSE;
+ do {
+ int item_type = ITEM_TYPE_NONE;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self->priv->model),
+ &iter,
+ TYPE_COLUMN, &item_type,
+ -1);
+
+ if (item_type == type_to_delete) {
+ valid = gtk_tree_store_remove (self->priv->model, &iter);
+ prev_matched = TRUE;
+ }
+ else {
+ if (prev_matched && (item_type == ITEM_TYPE_SEPARATOR))
+ valid = gtk_tree_store_remove (self->priv->model, &iter);
+ else
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->model), &iter);
+ prev_matched = FALSE;
+ }
+ }
+ while (valid);
+}
+
+
+static gboolean
+get_section_end_by_type (GthLocationChooser *self,
+ ItemType item_to_search,
+ int *p_pos)
{
- clear_items_from_separator (self, 1, TRUE);
+ GtkTreeIter iter;
+ int pos;
+ gboolean valid;
+ gboolean prev_matched;
+
+ if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->model), &iter))
+ return FALSE;
+
+ pos = 0;
+ valid = FALSE;
+ prev_matched = FALSE;
+ do {
+ int item_type = ITEM_TYPE_NONE;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (self->priv->model),
+ &iter,
+ TYPE_COLUMN, &item_type,
+ -1);
+
+ if (item_type == item_to_search) {
+ *p_pos = pos;
+ valid = TRUE;
+ prev_matched = TRUE;
+ }
+ else {
+ if ((item_type == ITEM_TYPE_SEPARATOR) && prev_matched)
+ *p_pos = pos;
+ prev_matched = FALSE;
+ }
+
+ pos++;
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->model), &iter));
+
+ return valid;
}
static void
update_entry_point_list (GthLocationChooser *self)
{
- int first_position;
int position;
GList *entry_points;
GList *scan;
self->priv->update_entry_list_id = 0;
- clear_entry_point_list (self);
-
- if (! get_nth_separator_pos (self, 1, &first_position)) {
- GtkTreeIter iter;
- GtkTreePath *path;
-
- gtk_tree_store_append (self->priv->model, &iter, NULL);
- gtk_tree_store_set (self->priv->model, &iter,
- TYPE_COLUMN, ITEM_TYPE_SEPARATOR,
- -1);
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (self->priv->model), &iter);
- if (path == NULL)
- return;
- first_position = gtk_tree_path_get_indices(path)[0];
+ delete_section_by_type (self, ITEM_TYPE_ENTRY_POINT);
- gtk_tree_path_free (path);
- }
+ if (get_section_end_by_type (self, ITEM_TYPE_LOCATION, &position))
+ position = position + 1;
+ else
+ position = 0;
- position = first_position + 1;
entry_points = gth_main_get_all_entry_points ();
for (scan = entry_points; scan; scan = scan->next) {
GthFileData *file_data = scan->data;
@@ -411,20 +477,13 @@ update_entry_point_list (GthLocationChooser *self)
ITEM_TYPE_ENTRY_POINT);
}
- if (! get_nth_separator_pos (self, 2, &first_position)) {
+ if (self->priv->show_other) {
GtkTreeIter iter;
- gtk_tree_store_append (self->priv->model, &iter, NULL);
+ gtk_tree_store_insert (self->priv->model, &iter, NULL, position);
gtk_tree_store_set (self->priv->model, &iter,
TYPE_COLUMN, ITEM_TYPE_SEPARATOR,
-1);
-
- gtk_tree_store_append (self->priv->model, &iter, NULL);
- gtk_tree_store_set (self->priv->model, &iter,
- TYPE_COLUMN, ITEM_TYPE_CHOOSE_LOCATION,
- NAME_COLUMN, _("Other…"),
- ELLIPSIZE_COLUMN, FALSE,
- -1);
}
_g_object_list_unref (entry_points);
@@ -459,31 +518,6 @@ entry_points_changed_cb (GthMonitor *monitor,
}
-static gboolean
-delete_current_file_entries (GthLocationChooser *self)
-{
- gboolean found = FALSE;
- GtkTreeIter iter;
-
- if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->priv->model), &iter))
- return FALSE;
-
- do {
- int item_type = ITEM_TYPE_NONE;
-
- gtk_tree_model_get (GTK_TREE_MODEL (self->priv->model),
- &iter,
- TYPE_COLUMN, &item_type,
- -1);
- if (item_type == ITEM_TYPE_SEPARATOR)
- break;
- }
- while (gtk_tree_store_remove (self->priv->model, &iter));
-
- return found;
-}
-
-
static void
update_location_list (gpointer user_data)
{
@@ -505,7 +539,7 @@ update_location_list (gpointer user_data)
GList *scan;
int position = 0;
- delete_current_file_entries (self);
+ delete_section_by_type (self, ITEM_TYPE_LOCATION);
list = gth_file_source_get_current_list (self->priv->file_source, self->priv->location);
for (scan = list; scan; scan = scan->next) {
@@ -531,10 +565,7 @@ update_location_list (gpointer user_data)
GIcon *icon;
icon = g_themed_icon_new ("computer-symbolic");
- gtk_tree_store_insert (self->priv->model,
- &iter,
- NULL,
- position++);
+ gtk_tree_store_insert (self->priv->model, &iter, NULL, position++);
gtk_tree_store_set (self->priv->model, &iter,
TYPE_COLUMN, ITEM_TYPE_LOCATION,
ICON_COLUMN, icon,
@@ -545,6 +576,15 @@ update_location_list (gpointer user_data)
_g_object_unref (icon);
}
+ if (self->priv->show_other || self->priv->show_entry_points) {
+ GtkTreeIter iter;
+
+ gtk_tree_store_insert (self->priv->model, &iter, NULL, position);
+ gtk_tree_store_set (self->priv->model, &iter,
+ TYPE_COLUMN, ITEM_TYPE_SEPARATOR,
+ -1);
+ }
+
_g_object_list_unref (list);
}
@@ -567,6 +607,17 @@ gth_location_chooser_realize (GtkWidget *widget)
GthLocationChooser *self = GTH_LOCATION_CHOOSER (widget);
GTK_WIDGET_CLASS (gth_location_chooser_parent_class)->realize (widget);
+
+ if (self->priv->show_other) {
+ GtkTreeIter iter;
+
+ gtk_tree_store_append (self->priv->model, &iter, NULL);
+ gtk_tree_store_set (self->priv->model, &iter,
+ TYPE_COLUMN, ITEM_TYPE_CHOOSE_LOCATION,
+ NAME_COLUMN, _("Other…"),
+ ELLIPSIZE_COLUMN, FALSE,
+ -1);
+ }
entry_points_changed_cb (NULL, self);
current_location_changed (self);
}
@@ -602,6 +653,13 @@ gth_location_chooser_class_init (GthLocationChooserClass *klass)
"Whether to show the VFS root in the list",
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SHOW_OTHER,
+ g_param_spec_boolean ("show-other",
+ "Show the Other... entry",
+ "Whether to show a special entry to choose a
location from a dialog",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_RELIEF,
g_param_spec_enum ("relief",
@@ -637,6 +695,7 @@ gth_location_chooser_init (GthLocationChooser *self)
self->priv->entry_points_changed_id = 0;
self->priv->show_entry_points = TRUE;
self->priv->show_root = FALSE;
+ self->priv->show_other = TRUE;
self->priv->relief = GTK_RELIEF_NORMAL;
self->priv->reload = FALSE;
@@ -740,7 +799,7 @@ gth_location_chooser_set_show_entry_points (GthLocationChooser *self,
g_source_remove (self->priv->entry_points_changed_id);
self->priv->entry_points_changed_id = 0;
}
- clear_items_from_separator (self, 1, FALSE);
+ clear_items_from_separator (self, 1, TRUE);
}
g_object_notify (G_OBJECT (self), "show-entry-points");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]