Commit 4fd3fdae authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

use a location chooser instead of a label for the current location

bring back the location chooser but instead of placing it above
the folder list, put it in place of the location label above the
file list.
parent 3d4c3bda
......@@ -99,7 +99,10 @@ gth_search_editor_construct (GthSearchEditor *self,
gtk_container_set_border_width (GTK_CONTAINER (content), 0);
gtk_box_pack_start (GTK_BOX (self), content, TRUE, TRUE, 0);
self->priv->location_chooser = gth_location_chooser_new ();
self->priv->location_chooser = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", TRUE,
"relief", GTK_RELIEF_NORMAL,
NULL);
gtk_widget_show (self->priv->location_chooser);
gtk_box_pack_start (GTK_BOX (GET_WIDGET ("location_box")), self->priv->location_chooser, TRUE, TRUE, 0);
......
......@@ -172,7 +172,10 @@ gedit_message_area_init (GeditMessageArea *message_area)
message_area->priv->main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); /* FIXME: use style properties */
gtk_widget_show (message_area->priv->main_hbox);
gtk_container_set_border_width (GTK_CONTAINER (message_area->priv->main_hbox), 3); /* FIXME: use style properties */
gtk_container_set_border_width (GTK_CONTAINER (message_area->priv->main_hbox), 0); /* FIXME: use style properties */
gtk_widget_set_margin_top (message_area->priv->main_hbox, 3);
gtk_widget_set_margin_bottom (message_area->priv->main_hbox, 3);
gtk_widget_set_margin_right (message_area->priv->main_hbox, 3);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_show (vbox);
......
......@@ -588,13 +588,7 @@ void
gth_browser_update_extra_widget (GthBrowser *browser)
{
gedit_message_area_clear_action_area (GEDIT_MESSAGE_AREA (browser->priv->list_extra_widget));
if (g_file_info_get_icon (browser->priv->location->info) != NULL)
gth_embedded_dialog_set_gicon (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget),
g_file_info_get_icon (browser->priv->location->info),
GTK_ICON_SIZE_MENU);
if (g_file_info_get_display_name (browser->priv->location->info) != NULL)
gth_embedded_dialog_set_primary_text (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget),
g_file_info_get_display_name (browser->priv->location->info));
gth_embedded_dialog_set_from_file (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget), browser->priv->location->file);
gth_hook_invoke ("gth-browser-update-extra-widget", browser);
}
......@@ -603,6 +597,8 @@ static void
_gth_browser_set_location (GthBrowser *browser,
GthFileData *location)
{
GtkWidget *location_chooser;
if (location == NULL)
return;
......@@ -614,6 +610,11 @@ _gth_browser_set_location (GthBrowser *browser,
_gth_browser_update_parent_list (browser);
gth_browser_update_sensitivity (browser);
gth_browser_update_extra_widget (browser);
location_chooser = gth_embedded_dialog_get_chooser (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget));
g_signal_handlers_block_by_data (location_chooser, browser);
gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (location_chooser), browser->priv->location->file);
g_signal_handlers_unblock_by_data (location_chooser, browser);
}
......@@ -3352,6 +3353,14 @@ gth_file_list_popup_menu (GthBrowser *browser,
}
static void
location_chooser_changed_cb (GthLocationChooser *chooser,
gpointer user_data)
{
gth_browser_go_to (GTH_BROWSER (user_data), gth_location_chooser_get_current (chooser), NULL);
}
static gboolean
gth_file_list_button_press_cb (GtkWidget *widget,
GdkEventButton *event,
......@@ -4388,6 +4397,11 @@ gth_browser_init (GthBrowser *browser)
gtk_widget_show (browser->priv->list_extra_widget);
gtk_container_add (GTK_CONTAINER (browser->priv->list_extra_widget_container), browser->priv->list_extra_widget);
g_signal_connect (gth_embedded_dialog_get_chooser (GTH_EMBEDDED_DIALOG (browser->priv->list_extra_widget)),
"changed",
G_CALLBACK (location_chooser_changed_cb),
browser);
/* the file list */
browser->priv->file_list = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_TYPE_NORMAL, TRUE);
......
......@@ -22,12 +22,15 @@
#include <config.h>
#include <gtk/gtk.h>
#include "gth-embedded-dialog.h"
#include "gth-location-chooser.h"
struct _GthEmbeddedDialogPrivate {
GtkWidget *icon_image;
GtkWidget *primary_text_label;
GtkWidget *secondary_text_label;
GtkWidget *info_box;
GtkWidget *location_chooser;
};
......@@ -55,13 +58,16 @@ gth_embedded_dialog_init (GthEmbeddedDialog *self)
hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_widget_show (hbox_content);
self->priv->info_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_box_pack_start (GTK_BOX (hbox_content), self->priv->info_box, TRUE, TRUE, 0);
self->priv->icon_image = image = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (self->priv->info_box), image, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.5);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_show (vbox);
gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (self->priv->info_box), vbox, TRUE, TRUE, 0);
self->priv->primary_text_label = primary_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
......@@ -82,6 +88,12 @@ gth_embedded_dialog_init (GthEmbeddedDialog *self)
gtk_label_set_ellipsize (GTK_LABEL (secondary_label), PANGO_ELLIPSIZE_END);
gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);
self->priv->location_chooser = g_object_new (GTH_TYPE_LOCATION_CHOOSER,
"show-entry-points", FALSE,
"relief", GTK_RELIEF_NONE,
NULL);
gtk_box_pack_start (GTK_BOX (hbox_content), self->priv->location_chooser, FALSE, FALSE, 0);
gedit_message_area_set_contents (GEDIT_MESSAGE_AREA (self), hbox_content);
}
......@@ -94,51 +106,54 @@ gth_embedded_dialog_new (void)
void
gth_embedded_dialog_set_icon (GthEmbeddedDialog *dialog,
gth_embedded_dialog_set_icon (GthEmbeddedDialog *self,
const char *icon_stock_id,
GtkIconSize size)
{
if (icon_stock_id == NULL) {
gtk_widget_hide (dialog->priv->icon_image);
gtk_widget_hide (self->priv->icon_image);
return;
}
gtk_image_set_from_stock (GTK_IMAGE (dialog->priv->icon_image), icon_stock_id, size);
gtk_widget_show (dialog->priv->icon_image);
gtk_image_set_from_stock (GTK_IMAGE (self->priv->icon_image), icon_stock_id, size);
gtk_widget_show (self->priv->icon_image);
}
void
gth_embedded_dialog_set_gicon (GthEmbeddedDialog *dialog,
gth_embedded_dialog_set_gicon (GthEmbeddedDialog *self,
GIcon *icon,
GtkIconSize size)
{
if (icon == NULL) {
gtk_widget_hide (dialog->priv->icon_image);
gtk_widget_hide (self->priv->icon_image);
return;
}
gtk_image_set_from_gicon (GTK_IMAGE (dialog->priv->icon_image), icon, size);
gtk_widget_show (dialog->priv->icon_image);
gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon_image), icon, size);
gtk_widget_show (self->priv->icon_image);
}
void
gth_embedded_dialog_set_primary_text (GthEmbeddedDialog *dialog,
gth_embedded_dialog_set_primary_text (GthEmbeddedDialog *self,
const char *text)
{
char *escaped;
char *markup;
gtk_widget_hide (self->priv->location_chooser);
gtk_widget_show (self->priv->info_box);
if (text == NULL) {
gtk_widget_hide (dialog->priv->primary_text_label);
gtk_widget_hide (self->priv->primary_text_label);
return;
}
escaped = g_markup_escape_text (text, -1);
markup = g_strdup_printf ("<b>%s</b>", escaped);
gtk_label_set_markup (GTK_LABEL (dialog->priv->primary_text_label), markup);
gtk_widget_show (dialog->priv->primary_text_label);
gtk_label_set_markup (GTK_LABEL (self->priv->primary_text_label), markup);
gtk_widget_show (self->priv->primary_text_label);
g_free (markup);
g_free (escaped);
......@@ -146,22 +161,39 @@ gth_embedded_dialog_set_primary_text (GthEmbeddedDialog *dialog,
void
gth_embedded_dialog_set_secondary_text (GthEmbeddedDialog *dialog,
gth_embedded_dialog_set_secondary_text (GthEmbeddedDialog *self,
const char *text)
{
char *escaped;
char *markup;
if (text == NULL) {
gtk_widget_hide (dialog->priv->secondary_text_label);
gtk_widget_hide (self->priv->secondary_text_label);
return;
}
escaped = g_markup_escape_text (text, -1);
markup = g_strdup_printf ("<small>%s</small>", escaped);
gtk_label_set_markup (GTK_LABEL (dialog->priv->secondary_text_label), markup);
gtk_widget_show (dialog->priv->secondary_text_label);
gtk_label_set_markup (GTK_LABEL (self->priv->secondary_text_label), markup);
gtk_widget_show (self->priv->secondary_text_label);
g_free (markup);
g_free (escaped);
}
void
gth_embedded_dialog_set_from_file (GthEmbeddedDialog *self,
GFile *file)
{
gtk_widget_hide (self->priv->info_box);
gtk_widget_show (self->priv->location_chooser);
gth_location_chooser_set_current (GTH_LOCATION_CHOOSER (self->priv->location_chooser), file);
}
GtkWidget *
gth_embedded_dialog_get_chooser (GthEmbeddedDialog *self)
{
return self->priv->location_chooser;
}
......@@ -61,6 +61,9 @@ void gth_embedded_dialog_set_primary_text (GthEmbeddedDialog *dialog,
const char *primary_text);
void gth_embedded_dialog_set_secondary_text (GthEmbeddedDialog *dialog,
const char *secondary_text);
void gth_embedded_dialog_set_from_file (GthEmbeddedDialog *dialog,
GFile *file);
GtkWidget * gth_embedded_dialog_get_chooser (GthEmbeddedDialog *dialog);
G_END_DECLS
......
......@@ -56,6 +56,13 @@ enum {
N_COLUMNS
};
enum {
PROP_0,
PROP_SHOW_ENTRY_POINTS,
PROP_RELIEF
};
enum {
CHANGED,
LAST_SIGNAL
......@@ -63,20 +70,71 @@ enum {
struct _GthLocationChooserPrivate
{
GtkWidget *combo;
GtkTreeStore *model;
GFile *location;
GthIconCache *icon_cache;
GthFileSource *file_source;
gulong entry_points_changed_id;
guint update_entry_list_id;
guint update_location_list_id;
GtkWidget *combo;
GtkWidget *arrow;
GtkTreeStore *model;
GFile *location;
GthIconCache *icon_cache;
GthFileSource *file_source;
gulong entry_points_changed_id;
guint update_entry_list_id;
guint update_location_list_id;
gboolean show_entry_points;
GtkReliefStyle relief;
};
static guint gth_location_chooser_signals[LAST_SIGNAL] = { 0 };
static void
gth_location_chooser_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GthLocationChooser *self;
self = GTH_LOCATION_CHOOSER (object);
switch (property_id) {
case PROP_SHOW_ENTRY_POINTS:
gth_location_chooser_set_show_entry_points (self, g_value_get_boolean (value));
break;
case PROP_RELIEF:
gth_location_chooser_set_relief (self, g_value_get_enum (value));
break;
default:
break;
}
}
static void
gth_location_chooser_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GthLocationChooser *self;
self = GTH_LOCATION_CHOOSER (object);
switch (property_id) {
case PROP_SHOW_ENTRY_POINTS:
g_value_set_boolean (value, self->priv->show_entry_points);
break;
case PROP_RELIEF:
g_value_set_enum (value, self->priv->relief);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gth_location_chooser_finalize (GObject *object)
{
......@@ -211,15 +269,10 @@ add_file_source_entries (GthLocationChooser *self,
static void
update_entry_point_list (GthLocationChooser *self)
clear_entry_point_list (GthLocationChooser *self)
{
int first_position;
int i;
int position;
GList *entry_points;
GList *scan;
self->priv->update_entry_list_id = 0;
int first_position;
int i;
if (! get_nth_separator_pos (self, 1, &first_position))
return;
......@@ -236,6 +289,37 @@ update_entry_point_list (GthLocationChooser *self)
gtk_tree_path_free (path);
}
}
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];
gtk_tree_path_free (path);
}
position = first_position + 1;
entry_points = gth_main_get_all_entry_points ();
......@@ -275,6 +359,8 @@ static void
entry_points_changed_cb (GthMonitor *monitor,
GthLocationChooser *self)
{
if (! self->priv->show_entry_points)
return;
if (self->priv->update_entry_list_id != 0)
return;
self->priv->update_entry_list_id = call_when_idle ((DataFunc) update_entry_point_list, self);
......@@ -432,6 +518,8 @@ gth_location_chooser_class_init (GthLocationChooserClass *klass)
g_type_class_add_private (klass, sizeof (GthLocationChooserPrivate));
object_class = (GObjectClass*) klass;
object_class->set_property = gth_location_chooser_set_property;
object_class->get_property = gth_location_chooser_get_property;
object_class->finalize = gth_location_chooser_finalize;
widget_class = (GtkWidgetClass *) klass;
......@@ -439,6 +527,27 @@ gth_location_chooser_class_init (GthLocationChooserClass *klass)
widget_class->realize = gth_location_chooser_realize;
widget_class->unrealize = gth_location_chooser_unrealize;
/* properties */
g_object_class_install_property (object_class,
PROP_SHOW_ENTRY_POINTS,
g_param_spec_boolean ("show-entry-points",
"Show entry points",
"Whether to show the entry points in the list",
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_RELIEF,
g_param_spec_enum ("relief",
"Border relief",
"The border relief style",
GTK_TYPE_RELIEF_STYLE,
GTK_RELIEF_NORMAL,
G_PARAM_READWRITE));
/* signals */
gth_location_chooser_signals[CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (klass),
......@@ -451,17 +560,30 @@ gth_location_chooser_class_init (GthLocationChooserClass *klass)
}
static void
get_combo_box_button (GtkWidget *widget,
gpointer data)
{
GtkWidget **p_child = data;
if (GTK_IS_BUTTON (widget))
*p_child = widget;
}
static void
gth_location_chooser_init (GthLocationChooser *self)
{
GtkCellRenderer *renderer;
GtkTreeIter iter;
gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_LOCATION_CHOOSER, GthLocationChooserPrivate);
self->priv->icon_cache = NULL;
self->priv->entry_points_changed_id = 0;
self->priv->arrow = NULL;
self->priv->show_entry_points = TRUE;
self->priv->relief = GTK_RELIEF_NORMAL;
self->priv->model = gtk_tree_store_new (N_COLUMNS,
GDK_TYPE_PIXBUF,
......@@ -508,30 +630,123 @@ gth_location_chooser_init (GthLocationChooser *self)
gtk_widget_show (self->priv->combo);
gtk_box_pack_start (GTK_BOX (self), self->priv->combo, TRUE, TRUE, 0);
}
/* Add standard items. */
/* separator #1 */
GtkWidget *
gth_location_chooser_new (void)
{
return GTK_WIDGET (g_object_new (GTH_TYPE_LOCATION_CHOOSER, NULL));
}
gtk_tree_store_append (self->priv->model, &iter, NULL);
gtk_tree_store_set (self->priv->model, &iter,
TYPE_COLUMN, ITEM_TYPE_SEPARATOR,
-1);
/**/
/* -- gth_location_chooser_set_relief -- */
self->priv->entry_points_changed_id =
g_signal_connect (gth_main_get_default_monitor (),
"entry-points-changed",
G_CALLBACK (entry_points_changed_cb),
self);
static void
get_combo_box_arrow (GtkWidget *widget,
gpointer data)
{
GtkWidget **p_child = data;
if (GTK_IS_ARROW (widget))
*p_child = widget;
}
GtkWidget *
gth_location_chooser_new (void)
static gboolean
show_combo_box_arrow (GthLocationChooser *self)
{
return GTK_WIDGET (g_object_new (GTH_TYPE_LOCATION_CHOOSER, NULL));
if (self->priv->relief == GTK_RELIEF_NONE)
gtk_widget_show (self->priv->arrow);
return FALSE;
}
static gboolean
hide_combo_box_arrow (GthLocationChooser *self)
{
if (self->priv->relief == GTK_RELIEF_NONE)
gtk_widget_hide (self->priv->arrow);
return FALSE;
}
void
gth_location_chooser_set_relief (GthLocationChooser *self,
GtkReliefStyle value)
{
GtkWidget *button;
if (self->priv->relief == value)
return;
self->priv->relief = value;
button = NULL;
gtk_container_forall (GTK_CONTAINER (self->priv->combo), get_combo_box_button, &button);
if (button != NULL) {
gtk_button_set_relief (GTK_BUTTON (button), self->priv->relief);
/* show the arrow only when the pointer is over the combo_box */
if (self->priv->arrow == NULL) {
gtk_container_forall (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (button))), get_combo_box_arrow, &self->priv->arrow);
g_signal_connect_swapped (button,
"enter-notify-event",
G_CALLBACK (show_combo_box_arrow),
self);
g_signal_connect_swapped (button,
"leave-notify-event",
G_CALLBACK (hide_combo_box_arrow),
self);
}
gtk_widget_set_visible (self->priv->arrow, self->priv->relief != GTK_RELIEF_NONE);
}
g_object_notify (G_OBJECT (self), "relief");
}
GtkReliefStyle
gth_location_chooser_get_relief (GthLocationChooser *self)
{
return self->priv->relief;
}
void
gth_location_chooser_set_show_entry_points (GthLocationChooser *self,
gboolean value)
{
self->priv->show_entry_points = value;
if (self->priv->show_entry_points) {
if (self->priv->entry_points_changed_id == 0)
self->priv->entry_points_changed_id =
g_signal_connect (gth_main_get_default_monitor (),
"entry-points-changed",
G_CALLBACK (entry_points_changed_cb),
self);
entry_points_changed_cb (NULL, self);
}
else {
if (self->priv->entry_points_changed_id != 0)
g_source_remove (self->priv->entry_points_changed_id);
clear_entry_point_list (self);
}
g_object_notify (G_OBJECT (self), "show-entry-points");
}
gboolean
gth_location_chooser_get_show_entry_points (GthLocationChooser *self)
{
return self->priv->show_entry_points;
}
......