2006-11-08 19:46:56 +00:00
|
|
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
|
2004-09-26 05:47:11 +00:00
|
|
|
/* gtkpathbar.c
|
2004-02-20 01:10:28 +00:00
|
|
|
* Copyright (C) 2004 Red Hat, Inc., Jonathan Blandford <jrb@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-20 01:10:28 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2022-10-06 02:59:51 +00:00
|
|
|
#include "gtkpathbarprivate.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtkbox.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
#include "gtkdragsource.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtkicontheme.h"
|
2004-03-08 09:56:34 +00:00
|
|
|
#include "gtkimage.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2004-02-20 01:10:28 +00:00
|
|
|
#include "gtklabel.h"
|
2004-02-23 07:11:31 +00:00
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkmarshalers.h"
|
2022-11-24 19:17:30 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtktogglebutton.h"
|
2012-03-21 08:37:09 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2017-09-15 11:53:43 +00:00
|
|
|
#include "gtkeventcontrollerscroll.h"
|
2019-12-31 18:13:17 +00:00
|
|
|
#include "gtkdragsource.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include "gtkprivate.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
struct _GtkPathBar
|
2013-03-30 07:35:39 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
GtkWidget *buttons_box;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
|
2013-03-30 07:35:39 +00:00
|
|
|
GFile *root_file;
|
|
|
|
GFile *home_file;
|
|
|
|
GFile *desktop_file;
|
|
|
|
|
2017-10-27 22:04:02 +00:00
|
|
|
/* List of running GCancellable. When we cancel one, we remove it from this list.
|
|
|
|
* The pathbar cancels all outstanding cancellables when it is disposed.
|
|
|
|
*
|
|
|
|
* In code that queues async I/O operations:
|
|
|
|
*
|
|
|
|
* - Obtain a cancellable from the async I/O APIs, and call add_cancellable().
|
|
|
|
*
|
|
|
|
* To cancel a cancellable:
|
|
|
|
*
|
|
|
|
* - Call cancel_cancellable().
|
|
|
|
*
|
|
|
|
* In async I/O callbacks:
|
|
|
|
*
|
|
|
|
* - Check right away if g_cancellable_is_cancelled(): if true, just
|
|
|
|
* g_object_unref() the cancellable and return early (also free your
|
|
|
|
* closure data if you have one).
|
|
|
|
*
|
|
|
|
* - If it was not cancelled, call cancellable_async_done(). This will
|
|
|
|
* unref the cancellable and unqueue it from the pathbar's outstanding
|
|
|
|
* cancellables. Do your normal work to process the async result and free
|
|
|
|
* your closure data if you have one.
|
|
|
|
*/
|
|
|
|
GList *cancellables;
|
|
|
|
|
2013-03-30 07:35:39 +00:00
|
|
|
GCancellable *get_info_cancellable;
|
|
|
|
|
2015-09-04 06:09:43 +00:00
|
|
|
GIcon *root_icon;
|
|
|
|
GIcon *home_icon;
|
|
|
|
GIcon *desktop_icon;
|
2013-03-30 07:35:39 +00:00
|
|
|
|
|
|
|
GList *button_list;
|
|
|
|
GList *fake_root;
|
2020-07-11 21:23:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GtkPathBarClass GtkPathBarClass;
|
|
|
|
|
|
|
|
struct _GtkPathBarClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
void (* path_clicked) (GtkPathBar *path_bar,
|
|
|
|
GFile *file,
|
|
|
|
GFile *child_file,
|
|
|
|
gboolean child_is_hidden);
|
|
|
|
};
|
2004-02-23 07:11:31 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PATH_CLICKED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-08 09:56:34 +00:00
|
|
|
typedef enum {
|
|
|
|
NORMAL_BUTTON,
|
|
|
|
ROOT_BUTTON,
|
|
|
|
HOME_BUTTON,
|
2022-10-26 16:38:23 +00:00
|
|
|
DESKTOP_BUTTON,
|
|
|
|
RECENT_BUTTON,
|
2004-03-08 09:56:34 +00:00
|
|
|
} ButtonType;
|
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
#define BUTTON_DATA(x) ((ButtonData *)(x))
|
|
|
|
|
2004-02-23 07:11:31 +00:00
|
|
|
static guint path_bar_signals [LAST_SIGNAL] = { 0 };
|
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
typedef struct _ButtonData ButtonData;
|
|
|
|
|
|
|
|
struct _ButtonData
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
ButtonType type;
|
|
|
|
char *dir_name;
|
2008-06-10 00:39:35 +00:00
|
|
|
GFile *file;
|
2004-03-09 21:29:59 +00:00
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
2008-06-10 00:39:35 +00:00
|
|
|
GCancellable *cancellable;
|
2004-10-28 15:00:05 +00:00
|
|
|
guint ignore_changes : 1;
|
|
|
|
guint file_is_hidden : 1;
|
2004-03-09 21:29:59 +00:00
|
|
|
};
|
2005-06-13 19:18:54 +00:00
|
|
|
/* This macro is used to check if a button can be used as a fake root.
|
|
|
|
* All buttons in front of a fake root are automatically hidden when in a
|
|
|
|
* directory below a fake root and replaced with the "<" arrow button.
|
|
|
|
*/
|
2022-10-26 16:38:23 +00:00
|
|
|
#define BUTTON_IS_FAKE_ROOT(button) ((button)->type == HOME_BUTTON || (button)->type == RECENT_BUTTON)
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
G_DEFINE_TYPE (GtkPathBar, gtk_path_bar, GTK_TYPE_WIDGET)
|
2004-02-20 01:10:28 +00:00
|
|
|
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
static void gtk_path_bar_finalize (GObject *object);
|
|
|
|
static void gtk_path_bar_dispose (GObject *object);
|
|
|
|
static void gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
|
|
|
|
ButtonData *button_data,
|
|
|
|
gboolean current_dir);
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2017-10-27 22:04:02 +00:00
|
|
|
static void
|
|
|
|
add_cancellable (GtkPathBar *path_bar,
|
2020-07-11 21:59:36 +00:00
|
|
|
GCancellable *cancellable)
|
2017-10-27 22:04:02 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
g_assert (g_list_find (path_bar->cancellables, cancellable) == NULL);
|
|
|
|
path_bar->cancellables = g_list_prepend (path_bar->cancellables, cancellable);
|
2017-10-27 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drop_node_for_cancellable (GtkPathBar *path_bar,
|
2020-07-11 21:59:36 +00:00
|
|
|
GCancellable *cancellable)
|
2017-10-27 22:04:02 +00:00
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
node = g_list_find (path_bar->cancellables, cancellable);
|
2017-10-27 22:04:02 +00:00
|
|
|
g_assert (node != NULL);
|
|
|
|
node->data = NULL;
|
2020-07-11 21:23:55 +00:00
|
|
|
path_bar->cancellables = g_list_delete_link (path_bar->cancellables, node);
|
2017-10-27 22:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cancel_cancellable (GtkPathBar *path_bar,
|
2020-07-11 21:59:36 +00:00
|
|
|
GCancellable *cancellable)
|
2017-10-27 22:04:02 +00:00
|
|
|
{
|
|
|
|
drop_node_for_cancellable (path_bar, cancellable);
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cancellable_async_done (GtkPathBar *path_bar,
|
2020-07-11 21:59:36 +00:00
|
|
|
GCancellable *cancellable)
|
2017-10-27 22:04:02 +00:00
|
|
|
{
|
|
|
|
drop_node_for_cancellable (path_bar, cancellable);
|
|
|
|
g_object_unref (cancellable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cancel_all_cancellables (GtkPathBar *path_bar)
|
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
while (path_bar->cancellables)
|
2017-10-27 22:04:02 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
GCancellable *cancellable = path_bar->cancellables->data;
|
2017-10-27 22:04:02 +00:00
|
|
|
cancel_cancellable (path_bar, cancellable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 07:35:39 +00:00
|
|
|
static void
|
|
|
|
gtk_path_bar_init (GtkPathBar *path_bar)
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2020-07-11 21:59:36 +00:00
|
|
|
const char *home;
|
2013-08-16 16:53:39 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
path_bar->scrolled_window = gtk_scrolled_window_new ();
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (path_bar->scrolled_window),
|
|
|
|
GTK_POLICY_EXTERNAL, GTK_POLICY_NEVER);
|
|
|
|
gtk_widget_set_hexpand (path_bar->scrolled_window, TRUE);
|
|
|
|
gtk_widget_set_parent (path_bar->scrolled_window, GTK_WIDGET (path_bar));
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
path_bar->buttons_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_add_css_class (path_bar->buttons_box, "linked");
|
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (path_bar->scrolled_window),
|
|
|
|
path_bar->buttons_box);
|
2011-11-28 19:41:02 +00:00
|
|
|
|
2013-08-16 16:53:39 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
path_bar->get_info_cancellable = NULL;
|
|
|
|
path_bar->cancellables = NULL;
|
2017-09-15 11:53:43 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
home = g_get_home_dir ();
|
|
|
|
if (home != NULL)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *desktop;
|
2020-07-11 21:59:36 +00:00
|
|
|
|
|
|
|
path_bar->home_file = g_file_new_for_path (home);
|
|
|
|
/* FIXME: Need file system backend specific way of getting the
|
|
|
|
* Desktop path.
|
|
|
|
*/
|
|
|
|
desktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
|
|
|
if (desktop != NULL)
|
|
|
|
path_bar->desktop_file = g_file_new_for_path (desktop);
|
|
|
|
else
|
|
|
|
path_bar->desktop_file = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path_bar->home_file = NULL;
|
|
|
|
path_bar->desktop_file = NULL;
|
|
|
|
}
|
|
|
|
path_bar->root_file = g_file_new_for_path ("/");
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_path_bar_class_init (GtkPathBarClass *path_bar_class)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) path_bar_class;
|
|
|
|
widget_class = (GtkWidgetClass *) path_bar_class;
|
|
|
|
|
2004-02-23 07:11:31 +00:00
|
|
|
gobject_class->finalize = gtk_path_bar_finalize;
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
gobject_class->dispose = gtk_path_bar_dispose;
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2004-02-23 07:11:31 +00:00
|
|
|
path_bar_signals [PATH_CLICKED] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("path-clicked"),
|
2010-09-18 23:55:42 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
2004-02-23 07:11:31 +00:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkPathBarClass, path_clicked),
|
|
|
|
NULL, NULL,
|
2021-10-04 00:45:03 +00:00
|
|
|
_gtk_marshal_VOID__OBJECT_OBJECT_BOOLEAN,
|
2005-11-10 15:17:40 +00:00
|
|
|
G_TYPE_NONE, 3,
|
2021-08-29 02:47:50 +00:00
|
|
|
G_TYPE_FILE,
|
|
|
|
G_TYPE_FILE,
|
2004-04-02 00:35:07 +00:00
|
|
|
G_TYPE_BOOLEAN);
|
2013-03-30 07:35:39 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2020-01-23 04:53:55 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, "pathbar");
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-02-23 07:11:31 +00:00
|
|
|
gtk_path_bar_finalize (GObject *object)
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2018-07-20 18:18:20 +00:00
|
|
|
GtkPathBar *path_bar = GTK_PATH_BAR (object);
|
2005-02-11 17:30:33 +00:00
|
|
|
|
2017-10-27 22:04:02 +00:00
|
|
|
cancel_all_cancellables (path_bar);
|
2005-02-11 17:30:33 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
g_list_free (path_bar->button_list);
|
|
|
|
g_clear_object (&path_bar->root_file);
|
|
|
|
g_clear_object (&path_bar->home_file);
|
|
|
|
g_clear_object (&path_bar->desktop_file);
|
2015-09-04 06:09:43 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
g_clear_object (&path_bar->root_icon);
|
|
|
|
g_clear_object (&path_bar->home_icon);
|
|
|
|
g_clear_object (&path_bar->desktop_icon);
|
2015-09-04 06:09:43 +00:00
|
|
|
|
2004-02-23 07:31:44 +00:00
|
|
|
G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
static void
|
|
|
|
gtk_path_bar_dispose (GObject *object)
|
|
|
|
{
|
2006-05-01 21:41:12 +00:00
|
|
|
GtkPathBar *path_bar = GTK_PATH_BAR (object);
|
2020-02-21 14:24:19 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
g_clear_pointer (&path_bar->scrolled_window, gtk_widget_unparent);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
path_bar->get_info_cancellable = NULL;
|
2017-10-27 22:04:02 +00:00
|
|
|
cancel_all_cancellables (path_bar);
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-02-20 01:10:28 +00:00
|
|
|
static void
|
2022-11-24 19:17:30 +00:00
|
|
|
gtk_path_bar_clear_buttons (GtkPathBar *path_bar)
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2022-11-24 19:17:30 +00:00
|
|
|
GtkWidget *w;
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
while ((w = gtk_widget_get_first_child (path_bar->buttons_box)) != NULL)
|
|
|
|
gtk_box_remove (GTK_BOX (path_bar->buttons_box), w);
|
2018-07-18 13:34:39 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
path_bar->fake_root = NULL;
|
2008-03-03 21:15:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 23:21:01 +00:00
|
|
|
static void
|
2022-11-24 19:17:30 +00:00
|
|
|
update_visibility_up_to_next_root (GtkPathBar *path_bar,
|
|
|
|
GList *start_from_button)
|
2004-02-20 23:21:01 +00:00
|
|
|
{
|
2022-11-24 19:17:30 +00:00
|
|
|
gboolean fake_root_found = FALSE;
|
|
|
|
GList *l;
|
2009-06-05 19:07:10 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
for (l = start_from_button; l; l = l->next)
|
2004-02-20 23:21:01 +00:00
|
|
|
{
|
2022-11-24 19:17:30 +00:00
|
|
|
GtkWidget *button = BUTTON_DATA (l->data)->button;
|
2004-02-20 23:21:01 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
gtk_widget_set_visible (button, !fake_root_found);
|
2004-02-20 23:21:01 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
fake_root_found |= BUTTON_IS_FAKE_ROOT (BUTTON_DATA (l->data));
|
2004-02-20 23:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-23 07:11:31 +00:00
|
|
|
static void
|
|
|
|
button_clicked_cb (GtkWidget *button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-04-02 00:35:07 +00:00
|
|
|
GtkPathBar *path_bar;
|
2018-07-20 18:18:20 +00:00
|
|
|
ButtonData *button_data;
|
2004-04-02 00:35:07 +00:00
|
|
|
GList *button_list;
|
|
|
|
gboolean child_is_hidden;
|
2008-06-10 00:39:35 +00:00
|
|
|
GFile *child_file;
|
2004-03-09 21:29:59 +00:00
|
|
|
|
|
|
|
button_data = BUTTON_DATA (data);
|
|
|
|
if (button_data->ignore_changes)
|
|
|
|
return;
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
path_bar = GTK_PATH_BAR (gtk_widget_get_ancestor (button, GTK_TYPE_PATH_BAR));
|
2004-04-02 00:35:07 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
button_list = g_list_find (path_bar->button_list, button_data);
|
2004-04-02 00:35:07 +00:00
|
|
|
g_assert (button_list != NULL);
|
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
g_signal_handlers_block_by_func (button,
|
|
|
|
G_CALLBACK (button_clicked_cb), data);
|
2004-03-04 06:47:54 +00:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
2006-05-01 21:41:12 +00:00
|
|
|
g_signal_handlers_unblock_by_func (button,
|
|
|
|
G_CALLBACK (button_clicked_cb), data);
|
2004-03-04 06:47:54 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
update_visibility_up_to_next_root (path_bar, button_list);
|
|
|
|
|
2004-04-02 00:35:07 +00:00
|
|
|
if (button_list->prev)
|
|
|
|
{
|
|
|
|
ButtonData *child_data;
|
|
|
|
|
|
|
|
child_data = BUTTON_DATA (button_list->prev->data);
|
2008-06-10 00:39:35 +00:00
|
|
|
child_file = child_data->file;
|
2004-04-02 00:35:07 +00:00
|
|
|
child_is_hidden = child_data->file_is_hidden;
|
|
|
|
}
|
|
|
|
else
|
2005-11-10 15:17:40 +00:00
|
|
|
{
|
2008-06-10 00:39:35 +00:00
|
|
|
child_file = NULL;
|
2005-11-10 15:17:40 +00:00
|
|
|
child_is_hidden = FALSE;
|
|
|
|
}
|
2004-04-02 00:35:07 +00:00
|
|
|
|
2005-11-10 15:17:40 +00:00
|
|
|
g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0,
|
2008-06-10 00:39:35 +00:00
|
|
|
button_data->file, child_file, child_is_hidden);
|
2004-02-23 07:11:31 +00:00
|
|
|
}
|
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
struct SetButtonImageData
|
|
|
|
{
|
|
|
|
GtkPathBar *path_bar;
|
|
|
|
ButtonData *button_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-07-11 21:59:36 +00:00
|
|
|
set_button_image_get_info_cb (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2020-07-11 21:59:36 +00:00
|
|
|
GFile *file = G_FILE (source);
|
2006-05-01 21:41:12 +00:00
|
|
|
struct SetButtonImageData *data = user_data;
|
2020-07-11 21:59:36 +00:00
|
|
|
GFileInfo *info;
|
|
|
|
GIcon *icon;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
|
|
|
if (!info)
|
|
|
|
goto out;
|
2006-09-04 19:32:13 +00:00
|
|
|
|
2017-10-27 22:04:02 +00:00
|
|
|
g_assert (GTK_IS_PATH_BAR (data->path_bar));
|
|
|
|
g_assert (G_OBJECT (data->path_bar)->ref_count > 0);
|
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
cancellable_async_done (data->path_bar, data->button_data->cancellable);
|
2017-10-27 22:04:02 +00:00
|
|
|
data->button_data->cancellable = NULL;
|
|
|
|
|
2015-09-04 06:09:43 +00:00
|
|
|
icon = g_file_info_get_symbolic_icon (info);
|
2017-11-15 00:43:13 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (data->button_data->image), icon);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
|
|
switch (data->button_data->type)
|
|
|
|
{
|
|
|
|
case HOME_BUTTON:
|
2020-07-11 21:23:55 +00:00
|
|
|
g_set_object (&data->path_bar->home_icon, icon);
|
2020-07-11 21:59:36 +00:00
|
|
|
break;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
|
|
case DESKTOP_BUTTON:
|
2020-07-11 21:23:55 +00:00
|
|
|
g_set_object (&data->path_bar->desktop_icon, icon);
|
2020-07-11 21:59:36 +00:00
|
|
|
break;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2022-10-26 16:38:23 +00:00
|
|
|
case RECENT_BUTTON:
|
2017-10-06 19:19:42 +00:00
|
|
|
case NORMAL_BUTTON:
|
|
|
|
case ROOT_BUTTON:
|
2006-05-01 21:41:12 +00:00
|
|
|
default:
|
2020-07-11 21:59:36 +00:00
|
|
|
break;
|
2006-05-01 21:41:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_button_image (GtkPathBar *path_bar,
|
2020-07-11 21:59:36 +00:00
|
|
|
ButtonData *button_data)
|
2004-03-08 09:56:34 +00:00
|
|
|
{
|
2006-05-01 21:41:12 +00:00
|
|
|
struct SetButtonImageData *data;
|
2020-07-11 21:59:36 +00:00
|
|
|
GMount *mount;
|
2004-03-10 06:20:48 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
switch (button_data->type)
|
2004-03-08 09:56:34 +00:00
|
|
|
{
|
2004-03-10 06:20:48 +00:00
|
|
|
case ROOT_BUTTON:
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->root_icon != NULL)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->root_icon);
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-10 00:39:35 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
mount = g_file_find_enclosing_mount (button_data->file, NULL, NULL);
|
|
|
|
|
|
|
|
if (!mount && g_file_is_native (button_data->file))
|
|
|
|
path_bar->root_icon = g_themed_icon_new ("drive-harddisk-symbolic");
|
|
|
|
else if (mount)
|
|
|
|
path_bar->root_icon = g_mount_get_symbolic_icon (mount);
|
|
|
|
else
|
|
|
|
path_bar->root_icon = NULL;
|
|
|
|
|
|
|
|
g_clear_object (&mount);
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->root_icon);
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-10 06:20:48 +00:00
|
|
|
case HOME_BUTTON:
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->home_icon != NULL)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->home_icon);
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = g_new0 (struct SetButtonImageData, 1);
|
|
|
|
data->path_bar = path_bar;
|
|
|
|
data->button_data = button_data;
|
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
if (button_data->cancellable)
|
2020-07-11 21:59:36 +00:00
|
|
|
{
|
|
|
|
cancel_cancellable (path_bar, button_data->cancellable);
|
|
|
|
g_clear_object (&button_data->cancellable);
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
button_data->cancellable = g_cancellable_new ();
|
|
|
|
g_file_query_info_async (path_bar->home_file,
|
|
|
|
"standard::symbolic-icon",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
button_data->cancellable,
|
|
|
|
set_button_image_get_info_cb,
|
|
|
|
data);
|
2017-10-27 22:04:02 +00:00
|
|
|
add_cancellable (path_bar, button_data->cancellable);
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
|
|
|
|
2004-03-10 06:20:48 +00:00
|
|
|
case DESKTOP_BUTTON:
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->desktop_icon != NULL)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), path_bar->desktop_icon);
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = g_new0 (struct SetButtonImageData, 1);
|
|
|
|
data->path_bar = path_bar;
|
|
|
|
data->button_data = button_data;
|
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
if (button_data->cancellable)
|
2020-07-11 21:59:36 +00:00
|
|
|
{
|
|
|
|
cancel_cancellable (path_bar, button_data->cancellable);
|
|
|
|
g_clear_object (&button_data->cancellable);
|
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
button_data->cancellable = g_cancellable_new ();
|
|
|
|
g_file_query_info_async (path_bar->desktop_file,
|
|
|
|
"standard::symbolic-icon",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
button_data->cancellable,
|
|
|
|
set_button_image_get_info_cb,
|
|
|
|
data);
|
2017-10-27 22:04:02 +00:00
|
|
|
add_cancellable (path_bar, button_data->cancellable);
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
2022-10-26 16:38:23 +00:00
|
|
|
case RECENT_BUTTON:
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (button_data->image),
|
|
|
|
"document-open-recent-symbolic");
|
|
|
|
break;
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
case NORMAL_BUTTON:
|
2004-03-10 06:20:48 +00:00
|
|
|
default:
|
2006-05-01 21:41:12 +00:00
|
|
|
break;
|
2004-03-08 09:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
static void
|
|
|
|
button_data_free (ButtonData *button_data)
|
|
|
|
{
|
2019-12-31 18:13:17 +00:00
|
|
|
g_clear_object (&button_data->file);
|
2007-03-09 21:57:37 +00:00
|
|
|
g_free (button_data->dir_name);
|
2017-10-27 22:04:02 +00:00
|
|
|
g_free (button_data);
|
2004-03-09 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 20:56:50 +00:00
|
|
|
static const char *
|
|
|
|
get_dir_name (ButtonData *button_data)
|
|
|
|
{
|
2005-10-04 20:08:32 +00:00
|
|
|
return button_data->dir_name;
|
2004-04-13 20:56:50 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 06:47:54 +00:00
|
|
|
static void
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
gtk_path_bar_update_button_appearance (GtkPathBar *path_bar,
|
|
|
|
ButtonData *button_data,
|
|
|
|
gboolean current_dir)
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *dir_name = get_dir_name (button_data);
|
2014-07-23 16:42:27 +00:00
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (button_data->button, "text-button");
|
|
|
|
gtk_widget_remove_css_class (button_data->button, "image-button");
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
if (button_data->label != NULL)
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2013-08-31 21:20:50 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
|
2014-07-23 16:42:27 +00:00
|
|
|
if (button_data->image == NULL)
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (button_data->button, "text-button");
|
2004-02-23 07:11:31 +00:00
|
|
|
}
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
if (button_data->image != NULL)
|
2004-02-23 07:11:31 +00:00
|
|
|
{
|
2006-05-01 21:41:12 +00:00
|
|
|
set_button_image (path_bar, button_data);
|
2014-07-23 16:42:27 +00:00
|
|
|
if (button_data->label == NULL)
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (button_data->button, "image-button");
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->ignore_changes = TRUE;
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
|
|
|
|
button_data->ignore_changes = FALSE;
|
2004-03-04 06:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 16:38:23 +00:00
|
|
|
static gboolean
|
|
|
|
file_is_recent_uri (GFile *file)
|
|
|
|
{
|
|
|
|
GFile *recent;
|
|
|
|
gboolean same;
|
|
|
|
|
|
|
|
recent = g_file_new_for_uri ("recent:///");
|
|
|
|
same = g_file_equal (file, recent);
|
|
|
|
g_object_unref (recent);
|
|
|
|
|
|
|
|
return same;
|
|
|
|
}
|
|
|
|
|
2004-03-10 06:20:48 +00:00
|
|
|
static ButtonType
|
|
|
|
find_button_type (GtkPathBar *path_bar,
|
2008-06-10 00:39:35 +00:00
|
|
|
GFile *file)
|
2004-03-10 06:20:48 +00:00
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->root_file != NULL &&
|
|
|
|
g_file_equal (file, path_bar->root_file))
|
2004-03-10 06:20:48 +00:00
|
|
|
return ROOT_BUTTON;
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->home_file != NULL &&
|
|
|
|
g_file_equal (file, path_bar->home_file))
|
2004-03-10 06:20:48 +00:00
|
|
|
return HOME_BUTTON;
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->desktop_file != NULL &&
|
|
|
|
g_file_equal (file, path_bar->desktop_file))
|
2004-03-10 06:20:48 +00:00
|
|
|
return DESKTOP_BUTTON;
|
2022-10-26 16:38:23 +00:00
|
|
|
if (file_is_recent_uri (file))
|
|
|
|
return RECENT_BUTTON;
|
2004-03-10 06:20:48 +00:00
|
|
|
|
|
|
|
return NORMAL_BUTTON;
|
|
|
|
}
|
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
static ButtonData *
|
2004-03-08 09:56:34 +00:00
|
|
|
make_directory_button (GtkPathBar *path_bar,
|
|
|
|
const char *dir_name,
|
2008-06-10 00:39:35 +00:00
|
|
|
GFile *file,
|
2004-04-02 00:35:07 +00:00
|
|
|
gboolean current_dir,
|
|
|
|
gboolean file_is_hidden)
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
2004-03-08 09:56:34 +00:00
|
|
|
GtkWidget *child = NULL;
|
2004-03-09 21:29:59 +00:00
|
|
|
ButtonData *button_data;
|
2019-12-31 18:13:17 +00:00
|
|
|
GdkContentProvider *content;
|
|
|
|
GtkDragSource *source;
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2004-08-25 19:19:43 +00:00
|
|
|
file_is_hidden = !! file_is_hidden;
|
2004-03-08 09:56:34 +00:00
|
|
|
/* Is it a special button? */
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data = g_new0 (ButtonData, 1);
|
2008-06-10 00:39:35 +00:00
|
|
|
button_data->type = find_button_type (path_bar, file);
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->button = gtk_toggle_button_new ();
|
2015-10-23 20:13:30 +00:00
|
|
|
gtk_widget_set_focus_on_click (button_data->button, FALSE);
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
switch (button_data->type)
|
2004-03-08 09:56:34 +00:00
|
|
|
{
|
|
|
|
case ROOT_BUTTON:
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->image = gtk_image_new ();
|
|
|
|
child = button_data->image;
|
2007-07-20 11:10:07 +00:00
|
|
|
button_data->label = NULL;
|
2004-03-08 09:56:34 +00:00
|
|
|
break;
|
|
|
|
case HOME_BUTTON:
|
2004-03-10 06:20:48 +00:00
|
|
|
case DESKTOP_BUTTON:
|
2022-10-26 16:38:23 +00:00
|
|
|
case RECENT_BUTTON:
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->image = gtk_image_new ();
|
|
|
|
button_data->label = gtk_label_new (NULL);
|
2014-08-13 13:31:34 +00:00
|
|
|
child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (child), button_data->image);
|
|
|
|
gtk_box_append (GTK_BOX (child), button_data->label);
|
2004-03-08 09:56:34 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_BUTTON:
|
2004-03-10 06:20:48 +00:00
|
|
|
default:
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->label = gtk_label_new (NULL);
|
2011-06-07 16:59:11 +00:00
|
|
|
child = button_data->label;
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->image = NULL;
|
2004-03-08 09:56:34 +00:00
|
|
|
}
|
2004-03-04 06:47:54 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data->dir_name = g_strdup (dir_name);
|
2008-06-10 00:39:35 +00:00
|
|
|
button_data->file = g_object_ref (file);
|
2004-04-02 00:35:07 +00:00
|
|
|
button_data->file_is_hidden = file_is_hidden;
|
2008-06-10 00:39:35 +00:00
|
|
|
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_button_set_child (GTK_BUTTON (button_data->button), child);
|
2004-02-20 01:10:28 +00:00
|
|
|
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
gtk_path_bar_update_button_appearance (path_bar, button_data, current_dir);
|
2004-03-04 06:47:54 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
g_signal_connect (button_data->button, "clicked",
|
|
|
|
G_CALLBACK (button_clicked_cb),
|
|
|
|
button_data);
|
2004-03-10 06:20:48 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (button_data->button),
|
|
|
|
(GWeakNotify) button_data_free, button_data);
|
2004-03-09 21:29:59 +00:00
|
|
|
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
2020-02-16 13:24:03 +00:00
|
|
|
content = gdk_content_provider_new_typed (G_TYPE_FILE, button_data->file);
|
2020-01-06 19:46:14 +00:00
|
|
|
gtk_drag_source_set_content (source, content);
|
2019-12-31 18:13:17 +00:00
|
|
|
g_object_unref (content);
|
2020-01-07 06:08:51 +00:00
|
|
|
gtk_widget_add_controller (button_data->button, GTK_EVENT_CONTROLLER (source));
|
2004-11-20 04:52:57 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
return button_data;
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 06:47:54 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_path_bar_check_parent_path (GtkPathBar *path_bar,
|
2011-11-28 17:34:37 +00:00
|
|
|
GFile *file)
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GList *current_path = NULL;
|
2005-06-13 19:18:54 +00:00
|
|
|
gboolean need_new_fake_root = FALSE;
|
2004-03-04 06:47:54 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
for (list = path_bar->button_list; list; list = list->next)
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
2004-03-09 21:29:59 +00:00
|
|
|
ButtonData *button_data;
|
2004-03-04 06:47:54 +00:00
|
|
|
|
2004-03-09 21:29:59 +00:00
|
|
|
button_data = list->data;
|
2008-06-10 00:39:35 +00:00
|
|
|
if (g_file_equal (file, button_data->file))
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
|
|
|
current_path = list;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-11 21:23:55 +00:00
|
|
|
if (list == path_bar->fake_root)
|
2005-06-13 19:18:54 +00:00
|
|
|
need_new_fake_root = TRUE;
|
2004-03-04 06:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_path)
|
|
|
|
{
|
2005-06-13 19:18:54 +00:00
|
|
|
if (need_new_fake_root)
|
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
path_bar->fake_root = NULL;
|
2005-06-13 19:18:54 +00:00
|
|
|
for (list = current_path; list; list = list->next)
|
|
|
|
{
|
|
|
|
ButtonData *button_data;
|
|
|
|
|
|
|
|
button_data = list->data;
|
|
|
|
if (BUTTON_IS_FAKE_ROOT (button_data))
|
|
|
|
{
|
2020-07-11 21:23:55 +00:00
|
|
|
path_bar->fake_root = list;
|
2005-06-13 19:18:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
for (list = path_bar->button_list; list; list = list->next)
|
2004-03-04 06:47:54 +00:00
|
|
|
{
|
Support changes in icon themes.
Wed Mar 10 02:41:05 2004 Jonathan Blandford <jrb@gnome.org>
* gtk/gtkpathbar.c: (gtk_path_bar_init), (gtk_path_bar_class_init),
(remove_settings_signal), (gtk_path_bar_dispose),
(gtk_path_bar_style_set), (gtk_path_bar_screen_changed),
(gtk_path_bar_scroll_up), (reload_icons), (change_icon_theme),
(settings_notify_cb), (gtk_path_bar_check_icon_theme),
(get_button_image), (gtk_path_bar_update_button_appearance),
(make_directory_button), (gtk_path_bar_check_parent_path): Support
changes in icon themes.
* gtk/gtkpathbar.h: add two elements
* tests/testfilechooser.c: (main): use gnome-vfs method again to
get more testing.
2004-03-10 07:42:20 +00:00
|
|
|
gtk_path_bar_update_button_appearance (path_bar,
|
|
|
|
BUTTON_DATA (list->data),
|
|
|
|
(list == current_path) ? TRUE : FALSE);
|
2004-03-04 06:47:54 +00:00
|
|
|
}
|
2004-09-26 05:54:59 +00:00
|
|
|
|
2004-09-26 05:47:11 +00:00
|
|
|
if (!gtk_widget_get_child_visible (BUTTON_DATA (current_path->data)->button))
|
|
|
|
{
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (path_bar));
|
|
|
|
}
|
2004-09-26 05:54:59 +00:00
|
|
|
|
2004-03-04 06:47:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-02-23 07:11:31 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
struct SetFileInfo
|
2004-02-20 01:10:28 +00:00
|
|
|
{
|
2008-06-10 00:39:35 +00:00
|
|
|
GFile *file;
|
|
|
|
GFile *parent_file;
|
2006-05-01 21:41:12 +00:00
|
|
|
GtkPathBar *path_bar;
|
|
|
|
GList *new_buttons;
|
|
|
|
GList *fake_root;
|
2020-07-11 21:59:36 +00:00
|
|
|
GCancellable *cancellable;
|
2006-05-01 21:41:12 +00:00
|
|
|
gboolean first_directory;
|
|
|
|
};
|
2004-03-08 22:53:35 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
static void
|
2008-06-10 00:39:35 +00:00
|
|
|
gtk_path_bar_set_file_finish (struct SetFileInfo *info,
|
|
|
|
gboolean result)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
GList *l;
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
gtk_path_bar_clear_buttons (info->path_bar);
|
2020-07-11 21:23:55 +00:00
|
|
|
info->path_bar->button_list = g_list_reverse (info->new_buttons);
|
|
|
|
info->path_bar->fake_root = info->fake_root;
|
2004-02-25 08:55:48 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
for (l = info->path_bar->button_list; l; l = l->next)
|
2004-02-23 07:11:31 +00:00
|
|
|
{
|
2006-05-01 21:41:12 +00:00
|
|
|
GtkWidget *button = BUTTON_DATA (l->data)->button;
|
2022-11-24 19:17:30 +00:00
|
|
|
gtk_box_prepend (GTK_BOX (info->path_bar->buttons_box), button);
|
2004-02-23 07:11:31 +00:00
|
|
|
}
|
2022-11-24 19:17:30 +00:00
|
|
|
|
|
|
|
update_visibility_up_to_next_root (info->path_bar,
|
|
|
|
info->path_bar->button_list);
|
2006-05-01 21:41:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GList *l;
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
for (l = info->new_buttons; l; l = l->next)
|
2020-02-21 14:24:19 +00:00
|
|
|
{
|
|
|
|
ButtonData *button_data = BUTTON_DATA (l->data);
|
2004-02-23 20:24:01 +00:00
|
|
|
|
2022-11-24 19:17:30 +00:00
|
|
|
gtk_box_remove (GTK_BOX (info->path_bar->buttons_box), button_data->button);
|
2020-02-21 14:24:19 +00:00
|
|
|
}
|
2004-03-01 19:48:28 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
g_list_free (info->new_buttons);
|
|
|
|
}
|
2004-02-20 01:10:28 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
if (info->file)
|
|
|
|
g_object_unref (info->file);
|
|
|
|
if (info->parent_file)
|
|
|
|
g_object_unref (info->parent_file);
|
2011-09-05 16:12:13 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
g_free (info);
|
|
|
|
}
|
2004-02-23 07:11:31 +00:00
|
|
|
|
2006-05-01 21:41:12 +00:00
|
|
|
static void
|
2020-07-11 21:59:36 +00:00
|
|
|
gtk_path_bar_get_info_callback (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer data)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2020-07-11 21:59:36 +00:00
|
|
|
GFile *file = G_FILE (source);
|
2008-06-10 00:39:35 +00:00
|
|
|
struct SetFileInfo *file_info = data;
|
2020-07-11 21:59:36 +00:00
|
|
|
GFileInfo *info;
|
2006-05-01 21:41:12 +00:00
|
|
|
ButtonData *button_data;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *display_name;
|
2006-05-01 21:41:12 +00:00
|
|
|
gboolean is_hidden;
|
2004-03-08 09:56:34 +00:00
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
|
|
|
if (!info)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2008-06-10 00:39:35 +00:00
|
|
|
gtk_path_bar_set_file_finish (file_info, FALSE);
|
2006-05-01 21:41:12 +00:00
|
|
|
return;
|
2004-02-20 01:10:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-27 22:04:02 +00:00
|
|
|
g_assert (GTK_IS_PATH_BAR (file_info->path_bar));
|
|
|
|
g_assert (G_OBJECT (file_info->path_bar)->ref_count > 0);
|
|
|
|
|
2020-07-11 21:59:36 +00:00
|
|
|
cancellable_async_done (file_info->path_bar, file_info->cancellable);
|
|
|
|
if (file_info->path_bar->get_info_cancellable == file_info->cancellable)
|
|
|
|
file_info->path_bar->get_info_cancellable = NULL;
|
|
|
|
file_info->cancellable = NULL;
|
2004-03-08 16:16:26 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
display_name = g_file_info_get_display_name (info);
|
2009-06-12 00:58:51 +00:00
|
|
|
is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
|
2004-03-08 16:16:26 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
button_data = make_directory_button (file_info->path_bar, display_name,
|
|
|
|
file_info->file,
|
2020-07-11 21:59:36 +00:00
|
|
|
file_info->first_directory, is_hidden);
|
2017-10-27 22:04:02 +00:00
|
|
|
g_clear_object (&file_info->file);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
file_info->new_buttons = g_list_prepend (file_info->new_buttons, button_data);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
|
|
if (BUTTON_IS_FAKE_ROOT (button_data))
|
2008-06-10 00:39:35 +00:00
|
|
|
file_info->fake_root = file_info->new_buttons;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2011-11-28 18:03:02 +00:00
|
|
|
/* We have assigned the info for the innermost button, i.e. the deepest directory.
|
|
|
|
* Now, go on to fetch the info for this directory's parent.
|
|
|
|
*/
|
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
file_info->file = file_info->parent_file;
|
|
|
|
file_info->first_directory = FALSE;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
if (!file_info->file)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2011-11-28 18:03:02 +00:00
|
|
|
/* No parent? Okay, we are done. */
|
2008-06-10 00:39:35 +00:00
|
|
|
gtk_path_bar_set_file_finish (file_info, TRUE);
|
2006-05-01 21:41:12 +00:00
|
|
|
return;
|
2004-03-08 16:16:26 +00:00
|
|
|
}
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
file_info->parent_file = g_file_get_parent (file_info->file);
|
2004-02-25 08:55:48 +00:00
|
|
|
|
2011-11-28 18:03:02 +00:00
|
|
|
/* Recurse asynchronously */
|
2020-07-11 21:59:36 +00:00
|
|
|
file_info->cancellable = g_cancellable_new ();
|
|
|
|
file_info->path_bar->get_info_cancellable = file_info->cancellable;
|
|
|
|
g_file_query_info_async (file_info->file,
|
|
|
|
"standard::display-name,"
|
|
|
|
"standard::is-hidden,"
|
|
|
|
"standard::is-backup",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
file_info->cancellable,
|
|
|
|
gtk_path_bar_get_info_callback,
|
|
|
|
file_info);
|
|
|
|
add_cancellable (file_info->path_bar, file_info->cancellable);
|
2006-05-01 21:41:12 +00:00
|
|
|
}
|
2004-04-06 01:23:26 +00:00
|
|
|
|
2011-11-29 21:07:01 +00:00
|
|
|
void
|
2015-02-19 13:44:56 +00:00
|
|
|
_gtk_path_bar_set_file (GtkPathBar *path_bar,
|
|
|
|
GFile *file,
|
|
|
|
gboolean keep_trail)
|
2006-05-01 21:41:12 +00:00
|
|
|
{
|
2008-06-10 00:39:35 +00:00
|
|
|
struct SetFileInfo *info;
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2011-11-29 21:07:01 +00:00
|
|
|
g_return_if_fail (GTK_IS_PATH_BAR (path_bar));
|
|
|
|
g_return_if_fail (G_IS_FILE (file));
|
2006-05-01 21:41:12 +00:00
|
|
|
|
|
|
|
/* Check whether the new path is already present in the pathbar as buttons.
|
|
|
|
* This could be a parent directory or a previous selected subdirectory.
|
|
|
|
*/
|
2011-11-28 17:34:37 +00:00
|
|
|
if (keep_trail && gtk_path_bar_check_parent_path (path_bar, file))
|
2011-11-29 21:07:01 +00:00
|
|
|
return;
|
2004-03-08 16:16:26 +00:00
|
|
|
|
2008-06-10 00:39:35 +00:00
|
|
|
info = g_new0 (struct SetFileInfo, 1);
|
|
|
|
info->file = g_object_ref (file);
|
2006-05-01 21:41:12 +00:00
|
|
|
info->path_bar = path_bar;
|
|
|
|
info->first_directory = TRUE;
|
2008-06-10 00:39:35 +00:00
|
|
|
info->parent_file = g_file_get_parent (info->file);
|
2006-05-01 21:41:12 +00:00
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
if (path_bar->get_info_cancellable)
|
2020-07-11 21:59:36 +00:00
|
|
|
cancel_cancellable (path_bar, path_bar->get_info_cancellable);
|
|
|
|
|
|
|
|
info->cancellable = g_cancellable_new ();
|
|
|
|
path_bar->get_info_cancellable = info->cancellable;
|
|
|
|
g_file_query_info_async (info->file,
|
|
|
|
"standard::display-name,"
|
|
|
|
"standard::is-hidden,"
|
|
|
|
"standard::is-backup",
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
info->cancellable,
|
|
|
|
gtk_path_bar_get_info_callback,
|
|
|
|
info);
|
|
|
|
add_cancellable (path_bar, info->cancellable);
|
2004-03-04 06:47:54 +00:00
|
|
|
}
|
2004-03-15 02:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* _gtk_path_bar_up:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @path_bar: a `GtkPathBar`
|
2004-03-15 02:12:08 +00:00
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* If the selected button in the pathbar is not the furthest button “up” (in the
|
2004-03-15 02:12:08 +00:00
|
|
|
* root direction), act as if the user clicked on the next button up.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
_gtk_path_bar_up (GtkPathBar *path_bar)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
for (l = path_bar->button_list; l; l = l->next)
|
2004-03-15 02:12:08 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button = BUTTON_DATA (l->data)->button;
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
|
|
|
{
|
|
|
|
if (l->next)
|
|
|
|
{
|
|
|
|
GtkWidget *next_button = BUTTON_DATA (l->next->data)->button;
|
|
|
|
button_clicked_cb (next_button, l->next->data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _gtk_path_bar_down:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @path_bar: a `GtkPathBar`
|
2004-03-15 02:12:08 +00:00
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* If the selected button in the pathbar is not the furthest button “down” (in the
|
2004-03-15 02:12:08 +00:00
|
|
|
* leaf direction), act as if the user clicked on the next button down.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
_gtk_path_bar_down (GtkPathBar *path_bar)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
2020-07-11 21:23:55 +00:00
|
|
|
for (l = path_bar->button_list; l; l = l->next)
|
2004-03-15 02:12:08 +00:00
|
|
|
{
|
|
|
|
GtkWidget *button = BUTTON_DATA (l->data)->button;
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
|
|
|
|
{
|
|
|
|
if (l->prev)
|
|
|
|
{
|
|
|
|
GtkWidget *prev_button = BUTTON_DATA (l->prev->data)->button;
|
|
|
|
button_clicked_cb (prev_button, l->prev->data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|