2003-03-21 20:34:02 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2003-10-23 00:26:15 +00:00
|
|
|
* gtkfilechooserdefault.c: Default implementation of GtkFileChooser
|
2003-03-21 20:34:02 +00:00
|
|
|
* Copyright (C) 2003, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkalignment.h"
|
2003-10-23 05:10:47 +00:00
|
|
|
#include "gtkbutton.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkcellrendererpixbuf.h"
|
2003-10-09 01:12:24 +00:00
|
|
|
#include "gtkcellrendererseptext.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkcellrenderertext.h"
|
2003-10-23 05:10:47 +00:00
|
|
|
#include "gtkcombobox.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkentry.h"
|
|
|
|
#include "gtkfilechooserdefault.h"
|
2003-03-25 00:11:06 +00:00
|
|
|
#include "gtkfilechooserentry.h"
|
2003-03-21 20:34:02 +00:00
|
|
|
#include "gtkfilechooserutils.h"
|
|
|
|
#include "gtkfilechooser.h"
|
|
|
|
#include "gtkfilesystemmodel.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkframe.h"
|
|
|
|
#include "gtkhbox.h"
|
|
|
|
#include "gtkhpaned.h"
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
#include "gtkimage.h"
|
2003-11-03 20:24:04 +00:00
|
|
|
#include "gtkintl.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmenuitem.h"
|
2003-11-03 00:50:33 +00:00
|
|
|
#include "gtkmessagedialog.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
2003-12-01 18:57:17 +00:00
|
|
|
#include "gtksizegroup.h"
|
2003-10-23 04:22:32 +00:00
|
|
|
#include "gtkstock.h"
|
|
|
|
#include "gtktable.h"
|
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtktreemodelsort.h"
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtktreestore.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkvbox.h"
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-03-24 15:41:40 +00:00
|
|
|
#include <string.h>
|
2003-09-09 15:18:29 +00:00
|
|
|
#include <time.h>
|
2003-03-24 15:41:40 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
typedef struct _GtkFileChooserDefaultClass GtkFileChooserDefaultClass;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
#define GTK_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
|
|
|
|
#define GTK_IS_FILE_CHOOSER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_CHOOSER_DEFAULT))
|
|
|
|
#define GTK_FILE_CHOOSER_DEFAULT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_CHOOSER_DEFAULT, GtkFileChooserDefaultClass))
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
struct _GtkFileChooserDefaultClass
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
|
|
|
GtkVBoxClass parent_class;
|
|
|
|
};
|
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
struct _GtkFileChooserDefault
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
|
|
|
GtkVBox parent_instance;
|
|
|
|
|
|
|
|
GtkFileSystem *file_system;
|
|
|
|
GtkFileSystemModel *tree_model;
|
2003-10-01 00:53:59 +00:00
|
|
|
GtkTreeStore *shortcuts_model;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkFileSystemModel *list_model;
|
2003-03-21 23:59:22 +00:00
|
|
|
GtkTreeModelSort *sort_model;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
|
|
GtkFileChooserAction action;
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
GtkFileFilter *current_filter;
|
|
|
|
GSList *filters;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
gboolean has_home;
|
|
|
|
gboolean has_desktop;
|
2003-12-17 05:55:16 +00:00
|
|
|
|
|
|
|
int num_volumes;
|
2003-10-18 04:29:40 +00:00
|
|
|
int num_shortcuts;
|
|
|
|
int num_bookmarks;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
guint volumes_changed_id;
|
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
guint bookmarks_changed_id;
|
|
|
|
|
2004-01-16 03:35:33 +00:00
|
|
|
GtkFilePath *current_volume_path;
|
2003-04-04 22:43:12 +00:00
|
|
|
GtkFilePath *current_folder;
|
2003-07-23 22:30:32 +00:00
|
|
|
GtkFilePath *preview_path;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *up_button;
|
2004-01-17 04:34:49 +00:00
|
|
|
GtkWidget *new_folder_button;
|
2003-11-03 18:46:18 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
GtkWidget *preview_frame;
|
2003-03-24 15:41:40 +00:00
|
|
|
|
2003-10-23 05:10:47 +00:00
|
|
|
GtkWidget *filter_combo;
|
2003-12-10 20:49:44 +00:00
|
|
|
GtkWidget *folder_label;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkWidget *tree_scrollwin;
|
|
|
|
GtkWidget *tree;
|
2003-10-01 00:53:59 +00:00
|
|
|
GtkWidget *shortcuts_scrollwin;
|
|
|
|
GtkWidget *shortcuts_tree;
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkWidget *add_bookmark_button;
|
2003-10-15 03:06:55 +00:00
|
|
|
GtkWidget *remove_bookmark_button;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkWidget *list_scrollwin;
|
|
|
|
GtkWidget *list;
|
2003-03-25 00:11:06 +00:00
|
|
|
GtkWidget *entry;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkWidget *preview_widget;
|
2003-09-03 05:52:35 +00:00
|
|
|
GtkWidget *extra_widget;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
GtkTreeViewColumn *list_name_column;
|
|
|
|
GtkCellRenderer *list_name_renderer;
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
guint folder_mode : 1;
|
|
|
|
guint local_only : 1;
|
|
|
|
guint preview_widget_active : 1;
|
|
|
|
guint select_multiple : 1;
|
|
|
|
guint show_hidden : 1;
|
2003-10-01 19:42:50 +00:00
|
|
|
guint list_sort_ascending : 1;
|
2003-12-02 04:23:06 +00:00
|
|
|
guint changing_folder : 1;
|
2003-10-01 00:53:59 +00:00
|
|
|
};
|
|
|
|
|
2003-10-09 01:12:24 +00:00
|
|
|
/* Column numbers for the shortcuts tree. Keep these in sync with create_shortcuts_model() */
|
2003-10-01 00:53:59 +00:00
|
|
|
enum {
|
|
|
|
SHORTCUTS_COL_PIXBUF,
|
|
|
|
SHORTCUTS_COL_NAME,
|
|
|
|
SHORTCUTS_COL_PATH,
|
2004-01-07 17:07:18 +00:00
|
|
|
SHORTCUTS_COL_REMOVABLE,
|
2003-10-01 00:53:59 +00:00
|
|
|
SHORTCUTS_COL_NUM_COLUMNS
|
2003-03-21 20:34:02 +00:00
|
|
|
};
|
|
|
|
|
2003-10-01 19:42:50 +00:00
|
|
|
/* Column numbers for the file list */
|
|
|
|
enum {
|
|
|
|
FILE_LIST_COL_NAME,
|
|
|
|
FILE_LIST_COL_SIZE,
|
|
|
|
FILE_LIST_COL_MTIME,
|
|
|
|
FILE_LIST_COL_NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
/* Identifiers for target types */
|
|
|
|
enum {
|
|
|
|
TEXT_URI_LIST
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Target types for DnD in the shortcuts list */
|
|
|
|
static GtkTargetEntry shortcuts_targets[] = {
|
|
|
|
{ "text/uri-list", 0, TEXT_URI_LIST }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int num_shortcuts_targets = sizeof (shortcuts_targets) / sizeof (shortcuts_targets[0]);
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
/* Interesting places in the shortcuts bar */
|
|
|
|
typedef enum {
|
|
|
|
SHORTCUTS_HOME,
|
|
|
|
SHORTCUTS_DESKTOP,
|
|
|
|
SHORTCUTS_VOLUMES,
|
|
|
|
SHORTCUTS_SHORTCUTS,
|
|
|
|
SHORTCUTS_SEPARATOR,
|
|
|
|
SHORTCUTS_BOOKMARKS
|
|
|
|
} ShortcutsIndex;
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
/* Standard icon size */
|
2003-11-19 17:03:32 +00:00
|
|
|
/* FIXME: maybe this should correspond to the font size in the tree views... */
|
|
|
|
#define ICON_SIZE 20
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
static void gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class);
|
|
|
|
static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
|
|
|
|
static void gtk_file_chooser_default_init (GtkFileChooserDefault *impl);
|
|
|
|
|
|
|
|
static GObject* gtk_file_chooser_default_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_params);
|
|
|
|
static void gtk_file_chooser_default_finalize (GObject *object);
|
|
|
|
static void gtk_file_chooser_default_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_file_chooser_default_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_file_chooser_default_show_all (GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
const GtkFilePath *path);
|
2003-10-23 00:26:15 +00:00
|
|
|
static GtkFilePath * gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser);
|
|
|
|
static void gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
const gchar *name);
|
2003-10-23 00:26:15 +00:00
|
|
|
static void gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
const GtkFilePath *path);
|
2003-10-23 00:26:15 +00:00
|
|
|
static void gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
const GtkFilePath *path);
|
2003-10-23 00:26:15 +00:00
|
|
|
static void gtk_file_chooser_default_select_all (GtkFileChooser *chooser);
|
|
|
|
static void gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser);
|
|
|
|
static GSList * gtk_file_chooser_default_get_paths (GtkFileChooser *chooser);
|
|
|
|
static GtkFilePath * gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser);
|
|
|
|
static GtkFileSystem *gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser);
|
|
|
|
static void gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkFileFilter *filter);
|
2003-10-23 00:26:15 +00:00
|
|
|
static void gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkFileFilter *filter);
|
2003-10-23 00:26:15 +00:00
|
|
|
static GSList * gtk_file_chooser_default_list_filters (GtkFileChooser *chooser);
|
|
|
|
static gboolean gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error);
|
|
|
|
static gboolean gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error);
|
|
|
|
static GSList * gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser);
|
|
|
|
|
|
|
|
static void set_current_filter (GtkFileChooserDefault *impl,
|
|
|
|
GtkFileFilter *filter);
|
|
|
|
static void check_preview_change (GtkFileChooserDefault *impl);
|
|
|
|
|
2003-10-23 05:10:47 +00:00
|
|
|
static void filter_combo_changed (GtkComboBox *combo_box,
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl);
|
|
|
|
static void tree_selection_changed (GtkTreeSelection *tree_selection,
|
|
|
|
GtkFileChooserDefault *impl);
|
2003-11-01 20:17:37 +00:00
|
|
|
|
2003-12-10 03:46:30 +00:00
|
|
|
static void shortcuts_row_activated_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GtkFileChooserDefault *impl);
|
2003-11-01 20:17:37 +00:00
|
|
|
static gboolean shortcuts_select_func (GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gboolean path_currentlny_selected,
|
|
|
|
gpointer data);
|
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
static void list_selection_changed (GtkTreeSelection *tree_selection,
|
|
|
|
GtkFileChooserDefault *impl);
|
|
|
|
static void list_row_activated (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GtkFileChooserDefault *impl);
|
|
|
|
static void entry_activate (GtkEntry *entry,
|
|
|
|
GtkFileChooserDefault *impl);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
static void add_bookmark_button_clicked_cb (GtkButton *button,
|
|
|
|
GtkFileChooserDefault *impl);
|
|
|
|
static void remove_bookmark_button_clicked_cb (GtkButton *button,
|
|
|
|
GtkFileChooserDefault *impl);
|
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
static void tree_name_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2003-07-16 21:07:38 +00:00
|
|
|
static void list_icon_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2003-03-26 17:09:26 +00:00
|
|
|
static void list_name_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2003-09-09 15:18:29 +00:00
|
|
|
#if 0
|
2003-03-26 17:09:26 +00:00
|
|
|
static void list_size_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2003-09-09 15:18:29 +00:00
|
|
|
#endif
|
|
|
|
static void list_mtime_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
2003-07-16 21:07:38 +00:00
|
|
|
static GObjectClass *parent_class;
|
2003-03-26 17:09:26 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
GType
|
2003-10-23 00:26:15 +00:00
|
|
|
_gtk_file_chooser_default_get_type (void)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
static GType file_chooser_default_type = 0;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
if (!file_chooser_default_type)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
static const GTypeInfo file_chooser_default_info =
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
sizeof (GtkFileChooserDefaultClass),
|
2003-03-21 20:34:02 +00:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-10-23 00:26:15 +00:00
|
|
|
(GClassInitFunc) gtk_file_chooser_default_class_init,
|
2003-03-21 20:34:02 +00:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-10-23 00:26:15 +00:00
|
|
|
sizeof (GtkFileChooserDefault),
|
2003-03-21 20:34:02 +00:00
|
|
|
0, /* n_preallocs */
|
2003-10-23 00:26:15 +00:00
|
|
|
(GInstanceInitFunc) gtk_file_chooser_default_init,
|
2003-03-21 20:34:02 +00:00
|
|
|
};
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static const GInterfaceInfo file_chooser_info =
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
(GInterfaceInitFunc) gtk_file_chooser_default_iface_init, /* interface_init */
|
2003-03-21 20:34:02 +00:00
|
|
|
NULL, /* interface_finalize */
|
|
|
|
NULL /* interface_data */
|
|
|
|
};
|
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
file_chooser_default_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserDefault",
|
|
|
|
&file_chooser_default_info, 0);
|
|
|
|
g_type_add_interface_static (file_chooser_default_type,
|
2003-03-21 20:34:02 +00:00
|
|
|
GTK_TYPE_FILE_CHOOSER,
|
|
|
|
&file_chooser_info);
|
|
|
|
}
|
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
return file_chooser_default_type;
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
2003-07-23 15:31:10 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-07-16 21:07:38 +00:00
|
|
|
parent_class = g_type_class_peek_parent (class);
|
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
gobject_class->finalize = gtk_file_chooser_default_finalize;
|
|
|
|
gobject_class->constructor = gtk_file_chooser_default_constructor;
|
|
|
|
gobject_class->set_property = gtk_file_chooser_default_set_property;
|
|
|
|
gobject_class->get_property = gtk_file_chooser_default_get_property;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-10-23 00:26:15 +00:00
|
|
|
widget_class->show_all = gtk_file_chooser_default_show_all;
|
2003-07-23 15:31:10 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
_gtk_file_chooser_install_properties (gobject_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface)
|
|
|
|
{
|
|
|
|
iface->select_path = gtk_file_chooser_default_select_path;
|
|
|
|
iface->unselect_path = gtk_file_chooser_default_unselect_path;
|
|
|
|
iface->select_all = gtk_file_chooser_default_select_all;
|
|
|
|
iface->unselect_all = gtk_file_chooser_default_unselect_all;
|
|
|
|
iface->get_paths = gtk_file_chooser_default_get_paths;
|
|
|
|
iface->get_preview_path = gtk_file_chooser_default_get_preview_path;
|
|
|
|
iface->get_file_system = gtk_file_chooser_default_get_file_system;
|
|
|
|
iface->set_current_folder = gtk_file_chooser_default_set_current_folder;
|
|
|
|
iface->get_current_folder = gtk_file_chooser_default_get_current_folder;
|
|
|
|
iface->set_current_name = gtk_file_chooser_default_set_current_name;
|
|
|
|
iface->add_filter = gtk_file_chooser_default_add_filter;
|
|
|
|
iface->remove_filter = gtk_file_chooser_default_remove_filter;
|
|
|
|
iface->list_filters = gtk_file_chooser_default_list_filters;
|
|
|
|
iface->add_shortcut_folder = gtk_file_chooser_default_add_shortcut_folder;
|
|
|
|
iface->remove_shortcut_folder = gtk_file_chooser_default_remove_shortcut_folder;
|
|
|
|
iface->list_shortcut_folders = gtk_file_chooser_default_list_shortcut_folders;
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-03-26 17:09:26 +00:00
|
|
|
impl->folder_mode = FALSE;
|
|
|
|
impl->local_only = TRUE;
|
|
|
|
impl->preview_widget_active = TRUE;
|
|
|
|
impl->select_multiple = FALSE;
|
|
|
|
impl->show_hidden = FALSE;
|
|
|
|
|
2003-11-03 00:50:33 +00:00
|
|
|
gtk_box_set_spacing (GTK_BOX (impl), 12);
|
2003-03-26 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_finalize (GObject *object)
|
2003-03-26 17:09:26 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
|
|
|
|
impl->volumes_changed_id = 0;
|
2003-10-08 04:14:55 +00:00
|
|
|
g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
|
|
|
|
impl->bookmarks_changed_id = 0;
|
2003-03-26 17:09:26 +00:00
|
|
|
g_object_unref (impl->file_system);
|
|
|
|
|
2004-01-22 02:39:31 +00:00
|
|
|
/* FIXME: Free impl->filters -- what's the memory management there? */
|
|
|
|
|
|
|
|
if (impl->current_volume_path)
|
|
|
|
gtk_file_path_free (impl->current_volume_path);
|
|
|
|
|
|
|
|
if (impl->current_folder)
|
|
|
|
gtk_file_path_free (impl->current_folder);
|
|
|
|
|
|
|
|
if (impl->preview_path)
|
|
|
|
gtk_file_path_free (impl->preview_path);
|
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
/* Shows an error dialog */
|
2003-11-03 00:50:33 +00:00
|
|
|
static void
|
2003-11-04 01:56:56 +00:00
|
|
|
error_message (GtkFileChooserDefault *impl,
|
|
|
|
const char *msg)
|
2003-11-03 00:50:33 +00:00
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
|
2003-11-19 22:38:31 +00:00
|
|
|
if (!GTK_WIDGET_TOPLEVEL (toplevel))
|
|
|
|
toplevel = NULL;
|
2003-11-03 00:50:33 +00:00
|
|
|
|
2003-11-19 22:38:31 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
|
2003-11-03 00:50:33 +00:00
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
2003-11-04 01:56:56 +00:00
|
|
|
"%s",
|
|
|
|
msg);
|
2003-11-03 00:50:33 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
/* Shows a simple error dialog relative to a path. Frees the GError as well. */
|
|
|
|
static void
|
|
|
|
error_dialog (GtkFileChooserDefault *impl,
|
|
|
|
const char *msg,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError *error)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = g_strdup_printf (msg,
|
|
|
|
gtk_file_path_get_string (path),
|
|
|
|
error->message);
|
|
|
|
error_message (impl, text);
|
|
|
|
g_free (text);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
/* Displays an error message about not being able to get information for a file.
|
|
|
|
* Frees the GError as well.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
error_getting_info_dialog (GtkFileChooserDefault *impl,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError *error)
|
|
|
|
{
|
|
|
|
error_dialog (impl,
|
|
|
|
_("Could not retrieve information about %s:\n%s"),
|
|
|
|
path, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shows an error dialog about not being able to add a bookmark */
|
|
|
|
static void
|
|
|
|
error_could_not_add_bookmark_dialog (GtkFileChooserDefault *impl,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError *error)
|
|
|
|
{
|
|
|
|
error_dialog (impl,
|
|
|
|
_("Could not add a bookmark for %s:\n%s"),
|
|
|
|
path, error);
|
|
|
|
}
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
/* Shows an error dialog about not being able to compose a filename */
|
|
|
|
static void
|
|
|
|
error_building_filename_dialog (GtkFileChooserDefault *impl,
|
|
|
|
const GtkFilePath *base_path,
|
|
|
|
const char *file_part,
|
|
|
|
GError *error)
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
msg = g_strdup_printf (_("Could not build file name from '%s' and '%s':\n%s"),
|
|
|
|
gtk_file_path_get_string (base_path),
|
|
|
|
file_part,
|
|
|
|
error->message);
|
|
|
|
error_message (impl, msg);
|
|
|
|
g_free (msg);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
update_preview_widget_visibility (GtkFileChooserDefault *impl)
|
2003-07-23 22:30:32 +00:00
|
|
|
{
|
|
|
|
if (impl->preview_widget_active && impl->preview_widget)
|
|
|
|
gtk_widget_show (impl->preview_frame);
|
|
|
|
else
|
|
|
|
gtk_widget_hide (impl->preview_frame);
|
|
|
|
}
|
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
set_preview_widget (GtkFileChooserDefault *impl,
|
|
|
|
GtkWidget *preview_widget)
|
2003-03-26 17:09:26 +00:00
|
|
|
{
|
|
|
|
if (preview_widget == impl->preview_widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (impl->preview_widget)
|
2003-09-03 05:52:35 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (impl->preview_frame),
|
|
|
|
impl->preview_widget);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
|
|
|
impl->preview_widget = preview_widget;
|
|
|
|
if (impl->preview_widget)
|
|
|
|
{
|
2003-12-29 20:55:01 +00:00
|
|
|
gtk_widget_show_all (impl->preview_widget);
|
2003-07-23 22:30:32 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (impl->preview_frame),
|
|
|
|
impl->preview_widget);
|
2003-03-26 17:09:26 +00:00
|
|
|
}
|
2003-07-23 22:30:32 +00:00
|
|
|
|
|
|
|
update_preview_widget_visibility (impl);
|
2003-03-26 17:09:26 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 18:46:18 +00:00
|
|
|
/* Clears the selection in the shortcuts tree */
|
|
|
|
static void
|
|
|
|
shortcuts_unselect_all (GtkFileChooserDefault *impl)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkTreeSelection *selection;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
|
2003-11-03 18:46:18 +00:00
|
|
|
gtk_tree_selection_unselect_all (selection);
|
2003-10-01 00:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convenience function to get the display name and icon info for a path */
|
|
|
|
static GtkFileInfo *
|
2003-10-18 04:29:40 +00:00
|
|
|
get_file_info (GtkFileSystem *file_system, const GtkFilePath *path, GError **error)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
|
|
|
GtkFilePath *parent_path;
|
|
|
|
GtkFileFolder *parent_folder;
|
|
|
|
GtkFileInfo *info;
|
|
|
|
|
|
|
|
if (!gtk_file_system_get_parent (file_system, path, &parent_path, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
parent_folder = gtk_file_system_get_folder (file_system, parent_path,
|
2003-12-01 15:33:37 +00:00
|
|
|
GTK_FILE_INFO_DISPLAY_NAME
|
2003-11-19 17:03:32 +00:00
|
|
|
#if 0
|
2003-12-01 15:33:37 +00:00
|
|
|
| GTK_FILE_INFO_ICON
|
2003-11-19 17:03:32 +00:00
|
|
|
#endif
|
2003-12-01 15:33:37 +00:00
|
|
|
| GTK_FILE_INFO_IS_FOLDER,
|
2003-10-01 00:53:59 +00:00
|
|
|
error);
|
|
|
|
gtk_file_path_free (parent_path);
|
|
|
|
|
|
|
|
if (!parent_folder)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
info = gtk_file_folder_get_info (parent_folder, path, error);
|
|
|
|
g_object_unref (parent_folder);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
/* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
|
|
|
|
* inserts a volume. A position of -1 indicates the end of the tree.
|
2003-10-08 04:14:55 +00:00
|
|
|
*/
|
2003-10-18 04:29:40 +00:00
|
|
|
static gboolean
|
2003-10-23 00:26:15 +00:00
|
|
|
shortcuts_insert_path (GtkFileChooserDefault *impl,
|
|
|
|
int pos,
|
2003-12-17 05:55:16 +00:00
|
|
|
gboolean is_volume,
|
|
|
|
GtkFileSystemVolume *volume,
|
2003-10-23 00:26:15 +00:00
|
|
|
const GtkFilePath *path,
|
|
|
|
const char *label,
|
2004-01-07 17:07:18 +00:00
|
|
|
gboolean removable,
|
2003-10-23 00:26:15 +00:00
|
|
|
GError **error)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
char *label_copy;
|
2003-10-08 04:14:55 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
2003-12-17 05:55:16 +00:00
|
|
|
gpointer data;
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
if (is_volume)
|
|
|
|
{
|
|
|
|
data = volume;
|
|
|
|
label_copy = gtk_file_system_volume_get_display_name (impl->file_system, volume);
|
|
|
|
pixbuf = gtk_file_system_volume_render_icon (impl->file_system,
|
|
|
|
volume,
|
|
|
|
GTK_WIDGET (impl),
|
|
|
|
ICON_SIZE,
|
|
|
|
NULL);
|
|
|
|
}
|
2003-10-08 04:14:55 +00:00
|
|
|
else
|
2003-12-17 05:55:16 +00:00
|
|
|
{
|
|
|
|
GtkFileInfo *info;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
info = get_file_info (impl->file_system, path, error);
|
|
|
|
if (!info)
|
|
|
|
return FALSE;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
data = gtk_file_path_copy (path);
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
label_copy = g_strdup (label);
|
|
|
|
else
|
|
|
|
label_copy = g_strdup (gtk_file_info_get_display_name (info));
|
|
|
|
|
|
|
|
pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl), ICON_SIZE, NULL);
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
gtk_file_info_free (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_store_insert (impl->shortcuts_model, &iter, NULL, pos);
|
2003-10-08 04:14:55 +00:00
|
|
|
|
|
|
|
gtk_tree_store_set (impl->shortcuts_model, &iter,
|
|
|
|
SHORTCUTS_COL_PIXBUF, pixbuf,
|
2003-12-17 05:55:16 +00:00
|
|
|
SHORTCUTS_COL_NAME, label_copy,
|
|
|
|
SHORTCUTS_COL_PATH, data,
|
2004-01-07 17:07:18 +00:00
|
|
|
SHORTCUTS_COL_REMOVABLE, removable,
|
2003-10-08 04:14:55 +00:00
|
|
|
-1);
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
g_free (label_copy);
|
2003-10-21 01:06:30 +00:00
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
2003-10-18 04:29:40 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
/* Appends an item for the user's home directory to the shortcuts model */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
shortcuts_append_home (GtkFileChooserDefault *impl)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
|
|
|
const char *home;
|
|
|
|
GtkFilePath *home_path;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
|
|
|
home = g_get_home_dir ();
|
|
|
|
home_path = gtk_file_system_filename_to_path (impl->file_system, home);
|
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
error = NULL;
|
2004-01-07 17:07:18 +00:00
|
|
|
impl->has_home = shortcuts_insert_path (impl, -1, FALSE, NULL, home_path, _("Home"), FALSE, &error);
|
2003-11-04 01:56:56 +00:00
|
|
|
if (!impl->has_home)
|
|
|
|
error_getting_info_dialog (impl, home_path, error);
|
2003-10-01 00:53:59 +00:00
|
|
|
|
|
|
|
gtk_file_path_free (home_path);
|
|
|
|
}
|
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
/* Appends the ~/Desktop directory to the shortcuts model */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
shortcuts_append_desktop (GtkFileChooserDefault *impl)
|
2003-10-18 04:29:40 +00:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
GtkFilePath *path;
|
|
|
|
|
|
|
|
/* FIXME: What is the Right Way of finding the desktop directory? */
|
|
|
|
|
2003-11-03 20:24:04 +00:00
|
|
|
name = g_build_filename (g_get_home_dir (), _("Desktop"), NULL);
|
2003-10-18 04:29:40 +00:00
|
|
|
path = gtk_file_system_filename_to_path (impl->file_system, name);
|
|
|
|
g_free (name);
|
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
impl->has_desktop = shortcuts_insert_path (impl, -1, FALSE, NULL, path, NULL, FALSE, NULL);
|
2003-11-19 22:38:31 +00:00
|
|
|
/* We do not actually pop up an error dialog if there is no desktop directory
|
|
|
|
* because some people may really not want to have one.
|
|
|
|
*/
|
2003-11-04 01:56:56 +00:00
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
gtk_file_path_free (path);
|
|
|
|
}
|
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
/* Appends a list of GtkFilePath to the shortcuts model; returns how many were inserted */
|
|
|
|
static int
|
|
|
|
shortcuts_append_paths (GtkFileChooserDefault *impl,
|
2003-12-17 05:55:16 +00:00
|
|
|
GSList *paths)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
2003-11-04 01:56:56 +00:00
|
|
|
int num_inserted;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
num_inserted = 0;
|
2003-10-18 04:29:40 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
for (; paths; paths = paths->next)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
2003-10-08 04:14:55 +00:00
|
|
|
GtkFilePath *path;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
|
|
|
|
|
|
|
path = paths->data;
|
|
|
|
error = NULL;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2004-01-06 05:13:31 +00:00
|
|
|
/* NULL GError, but we don't really want to show error boxes here */
|
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
if (shortcuts_insert_path (impl, -1, FALSE, NULL, path, NULL, TRUE, NULL))
|
2003-11-04 01:56:56 +00:00
|
|
|
num_inserted++;
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
return num_inserted;
|
|
|
|
}
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
/* Returns the index for the corresponding item in the shortcuts bar */
|
|
|
|
static int
|
|
|
|
shortcuts_get_index (GtkFileChooserDefault *impl,
|
|
|
|
ShortcutsIndex where)
|
2003-11-04 01:56:56 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
n = 0;
|
2003-11-04 01:56:56 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
if (where == SHORTCUTS_HOME)
|
|
|
|
goto out;
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
n += impl->has_home ? 1 : 0;
|
|
|
|
|
|
|
|
if (where == SHORTCUTS_DESKTOP)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
n += impl->has_desktop ? 1 : 0;
|
|
|
|
|
|
|
|
if (where == SHORTCUTS_VOLUMES)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
n += impl->num_volumes;
|
|
|
|
|
|
|
|
if (where == SHORTCUTS_SHORTCUTS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
n += impl->num_shortcuts;
|
|
|
|
|
|
|
|
if (where == SHORTCUTS_SEPARATOR)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
n += 1;
|
|
|
|
|
|
|
|
if (where == SHORTCUTS_BOOKMARKS)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
out:
|
2003-11-04 01:56:56 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
return n;
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
typedef void (* RemoveFunc) (GtkFileChooserDefault *impl, gpointer data);
|
|
|
|
|
|
|
|
/* Removes the specified number of rows from the shortcuts list */
|
2003-10-15 03:06:55 +00:00
|
|
|
static void
|
2003-12-17 05:55:16 +00:00
|
|
|
shortcuts_remove_rows (GtkFileChooserDefault *impl,
|
|
|
|
int start_row,
|
|
|
|
int n_rows,
|
|
|
|
RemoveFunc remove_fn)
|
2003-10-15 03:06:55 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
path = gtk_tree_path_new_from_indices (start_row, -1);
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
for (; n_rows; n_rows--)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
|
|
|
|
g_assert_not_reached ();
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
if (remove_fn)
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
|
|
|
|
(* remove_fn) (impl, data);
|
|
|
|
}
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
gtk_tree_store_remove (impl->shortcuts_model, &iter);
|
|
|
|
}
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
gtk_tree_path_free (path);
|
2003-10-15 03:06:55 +00:00
|
|
|
}
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
/* Used from shortcuts_remove_rows() */
|
2003-10-08 04:14:55 +00:00
|
|
|
static void
|
2003-12-17 05:55:16 +00:00
|
|
|
volume_remove_cb (GtkFileChooserDefault *impl, gpointer data)
|
|
|
|
{
|
|
|
|
GtkFileSystemVolume *volume;
|
|
|
|
|
|
|
|
volume = data;
|
|
|
|
gtk_file_system_volume_free (impl->file_system, volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adds all the file system volumes to the shortcuts model */
|
|
|
|
static void
|
|
|
|
shortcuts_add_volumes (GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
int start_row;
|
|
|
|
GSList *list, *l;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
|
|
|
|
shortcuts_remove_rows (impl, start_row, impl->num_volumes, volume_remove_cb);
|
|
|
|
impl->num_volumes = 0;
|
|
|
|
|
|
|
|
list = gtk_file_system_list_volumes (impl->file_system);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
GtkFileSystemVolume *volume;
|
|
|
|
|
|
|
|
volume = l->data;
|
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
shortcuts_insert_path (impl, start_row + n, TRUE, volume, NULL, NULL, FALSE, NULL);
|
2003-12-17 05:55:16 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl->num_volumes = n;
|
2004-02-06 16:21:39 +00:00
|
|
|
|
|
|
|
g_slist_free (list);
|
2003-12-17 05:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Used from shortcuts_remove_rows() */
|
|
|
|
static void
|
|
|
|
remove_bookmark_cb (GtkFileChooserDefault *impl, gpointer data)
|
|
|
|
{
|
|
|
|
GtkFilePath *path;
|
|
|
|
|
|
|
|
path = data;
|
|
|
|
gtk_file_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Updates the list of bookmarks */
|
|
|
|
static void
|
|
|
|
shortcuts_add_bookmarks (GtkFileChooserDefault *impl)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-11-04 01:56:56 +00:00
|
|
|
GSList *bookmarks;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
shortcuts_remove_rows (impl,
|
|
|
|
shortcuts_get_index (impl, SHORTCUTS_BOOKMARKS),
|
|
|
|
impl->num_bookmarks,
|
|
|
|
remove_bookmark_cb);
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
bookmarks = gtk_file_system_list_bookmarks (impl->file_system);
|
|
|
|
impl->num_bookmarks = shortcuts_append_paths (impl, bookmarks);
|
|
|
|
gtk_file_paths_free (bookmarks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Appends the bookmarks separator node and the bookmarks from the file system. */
|
|
|
|
static void
|
|
|
|
shortcuts_append_bookmarks (GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
gtk_tree_store_append (impl->shortcuts_model, &iter, NULL);
|
|
|
|
gtk_tree_store_set (impl->shortcuts_model, &iter,
|
2003-10-09 01:12:24 +00:00
|
|
|
SHORTCUTS_COL_PIXBUF, NULL,
|
|
|
|
SHORTCUTS_COL_NAME, NULL,
|
2003-10-08 04:14:55 +00:00
|
|
|
SHORTCUTS_COL_PATH, NULL,
|
|
|
|
-1);
|
2004-01-06 05:13:31 +00:00
|
|
|
shortcuts_add_bookmarks (impl);
|
2003-10-01 00:53:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates the GtkTreeStore used as the shortcuts model */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
create_shortcuts_model (GtkFileChooserDefault *impl)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
2003-10-08 04:14:55 +00:00
|
|
|
if (impl->shortcuts_model)
|
|
|
|
g_object_unref (impl->shortcuts_model);
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-10-09 01:12:24 +00:00
|
|
|
/* Keep this order in sync with the SHORCUTS_COL_* enum values */
|
2003-10-01 00:53:59 +00:00
|
|
|
impl->shortcuts_model = gtk_tree_store_new (SHORTCUTS_COL_NUM_COLUMNS,
|
|
|
|
GDK_TYPE_PIXBUF, /* pixbuf */
|
|
|
|
G_TYPE_STRING, /* name */
|
2004-01-07 17:07:18 +00:00
|
|
|
G_TYPE_POINTER, /* path or volume */
|
|
|
|
G_TYPE_BOOLEAN); /* removable */
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
if (impl->file_system)
|
|
|
|
{
|
|
|
|
shortcuts_append_home (impl);
|
2003-10-18 04:29:40 +00:00
|
|
|
shortcuts_append_desktop (impl);
|
2003-12-17 05:55:16 +00:00
|
|
|
shortcuts_add_volumes (impl);
|
2003-10-08 04:14:55 +00:00
|
|
|
shortcuts_append_bookmarks (impl);
|
|
|
|
}
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model));
|
2003-10-01 00:53:59 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 00:50:33 +00:00
|
|
|
/* Callback used when the "Up" toolbar button is clicked */
|
|
|
|
static void
|
2004-01-17 04:34:49 +00:00
|
|
|
up_button_clicked_cb (GtkButton *button,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-11-03 00:50:33 +00:00
|
|
|
{
|
|
|
|
GtkFilePath *parent_path;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
if (gtk_file_system_get_parent (impl->file_system, impl->current_folder, &parent_path, &error))
|
|
|
|
{
|
|
|
|
if (parent_path) /* If we were on a root, parent_path will be NULL */
|
|
|
|
{
|
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), parent_path);
|
|
|
|
gtk_file_path_free (parent_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2003-11-04 01:56:56 +00:00
|
|
|
error_dialog (impl,
|
|
|
|
_("Could not go to the parent folder of %s:\n%s"),
|
|
|
|
impl->current_folder,
|
|
|
|
error);
|
2003-11-03 00:50:33 +00:00
|
|
|
}
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
/* Callback used when the "New Folder" toolbar button is clicked */
|
|
|
|
static void
|
|
|
|
new_folder_button_clicked (GtkButton *button,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
/* FIXME: this doesn't work for folder mode, just for file mode */
|
|
|
|
|
|
|
|
_gtk_file_system_model_add_editable (impl->list_model, &iter);
|
|
|
|
g_object_set (impl->list_name_renderer, "editable", TRUE, NULL);
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->list_model), &iter);
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->list),
|
|
|
|
path,
|
|
|
|
impl->list_name_column,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used from the text cell renderer when the new folder is named */
|
|
|
|
static void
|
|
|
|
renderer_edited_cb (GtkCellRendererText *cell_renderer_text,
|
|
|
|
const gchar *path,
|
|
|
|
const gchar *new_text,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
GError *error;
|
|
|
|
GtkFilePath *file_path;
|
|
|
|
|
|
|
|
_gtk_file_system_model_remove_editable (impl->list_model);
|
|
|
|
g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
file_path = gtk_file_system_make_path (impl->file_system, impl->current_folder, new_text, &error);
|
|
|
|
if (!file_path)
|
|
|
|
{
|
|
|
|
error_building_filename_dialog (impl, impl->current_folder, new_text, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
if (!gtk_file_system_create_folder (impl->file_system, file_path, &error))
|
|
|
|
error_dialog (impl,
|
|
|
|
_("Could not create folder %s:\n%s"),
|
|
|
|
file_path, error);
|
|
|
|
|
|
|
|
gtk_file_path_free (file_path);
|
|
|
|
|
|
|
|
/* FIXME: scroll to the new folder and select it */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used from the text cell renderer when the new folder edition gets
|
|
|
|
* canceled.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
renderer_editing_canceled_cb (GtkCellRendererText *cell_renderer_text,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
_gtk_file_system_model_remove_editable (impl->list_model);
|
|
|
|
g_object_set (impl->list_name_renderer, "editable", FALSE, NULL);
|
|
|
|
}
|
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Creates the widgets for the filter combo box */
|
|
|
|
static GtkWidget *
|
|
|
|
filter_create (GtkFileChooserDefault *impl)
|
2003-11-03 00:50:33 +00:00
|
|
|
{
|
2004-01-06 04:18:42 +00:00
|
|
|
impl->filter_combo = gtk_combo_box_new_text ();
|
|
|
|
g_signal_connect (impl->filter_combo, "changed",
|
|
|
|
G_CALLBACK (filter_combo_changed), impl);
|
2003-11-03 18:46:18 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
return impl->filter_combo;
|
2003-11-03 00:50:33 +00:00
|
|
|
}
|
|
|
|
|
2003-12-10 20:49:44 +00:00
|
|
|
static GtkWidget *
|
2004-01-06 04:18:42 +00:00
|
|
|
toolbar_button_new (GtkFileChooserDefault *impl,
|
|
|
|
const char *text,
|
|
|
|
const char *stock_id,
|
|
|
|
gboolean sensitive,
|
2004-01-17 04:34:49 +00:00
|
|
|
gboolean show,
|
2004-01-06 04:18:42 +00:00
|
|
|
GCallback callback)
|
2003-12-10 20:49:44 +00:00
|
|
|
{
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *button;
|
2003-12-10 20:49:44 +00:00
|
|
|
GtkWidget *hbox;
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *widget;
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
button = gtk_button_new ();
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), hbox);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
widget = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
widget = gtk_label_new (text);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_widget_set_sensitive (button, sensitive);
|
|
|
|
g_signal_connect (button, "clicked", callback, impl);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_widget_show_all (hbox);
|
|
|
|
|
|
|
|
if (show)
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
return button;
|
2003-12-10 20:49:44 +00:00
|
|
|
}
|
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Creates the widgets in the toolbar */
|
2003-11-03 00:50:33 +00:00
|
|
|
static GtkWidget *
|
|
|
|
toolbar_create (GtkFileChooserDefault *impl)
|
|
|
|
{
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *hbox;
|
2003-11-19 17:03:32 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 12);
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_widget_show (hbox);
|
2004-01-06 04:18:42 +00:00
|
|
|
|
|
|
|
/* Add bookmark button */
|
2003-11-03 00:50:33 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
impl->add_bookmark_button = toolbar_button_new (impl,
|
|
|
|
_("Add"),
|
|
|
|
GTK_STOCK_ADD,
|
|
|
|
FALSE,
|
2004-01-17 04:34:49 +00:00
|
|
|
TRUE,
|
2004-01-06 04:18:42 +00:00
|
|
|
G_CALLBACK (add_bookmark_button_clicked_cb));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->add_bookmark_button, FALSE, FALSE, 0);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Remove bookmark button */
|
|
|
|
|
|
|
|
impl->remove_bookmark_button = toolbar_button_new (impl,
|
|
|
|
_("Remove"),
|
|
|
|
GTK_STOCK_REMOVE,
|
|
|
|
FALSE,
|
2004-01-17 04:34:49 +00:00
|
|
|
TRUE,
|
2004-01-06 04:18:42 +00:00
|
|
|
G_CALLBACK (remove_bookmark_button_clicked_cb));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->remove_bookmark_button, FALSE, FALSE, 0);
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Up button */
|
|
|
|
|
|
|
|
impl->up_button = toolbar_button_new (impl,
|
|
|
|
_("Up"),
|
|
|
|
GTK_STOCK_GO_UP,
|
|
|
|
FALSE,
|
2004-01-17 04:34:49 +00:00
|
|
|
TRUE,
|
|
|
|
G_CALLBACK (up_button_clicked_cb));
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->up_button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* Current folder label */
|
|
|
|
|
|
|
|
impl->folder_label = gtk_label_new (NULL);
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (impl->folder_label), 0.0, 0.5);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->folder_label, FALSE, FALSE, 0);
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_widget_show (impl->folder_label);
|
2004-01-06 04:18:42 +00:00
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
/* New folder button for save mode */
|
|
|
|
|
|
|
|
impl->new_folder_button = gtk_button_new_from_stock (GTK_STOCK_NEW);
|
|
|
|
g_signal_connect (impl->new_folder_button, "clicked",
|
|
|
|
G_CALLBACK (new_folder_button_clicked), impl);
|
|
|
|
gtk_box_pack_end (GTK_BOX (hbox), impl->new_folder_button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
|
|
|
gtk_widget_show (impl->new_folder_button);
|
2004-01-06 04:18:42 +00:00
|
|
|
|
|
|
|
return hbox;
|
2003-11-03 00:50:33 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 18:46:18 +00:00
|
|
|
/* Sets the sensitivity of the toolbar buttons */
|
|
|
|
static void
|
|
|
|
toolbar_check_sensitivity (GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
GtkFilePath *parent_path;
|
|
|
|
gboolean has_parent;
|
|
|
|
|
|
|
|
has_parent = FALSE;
|
|
|
|
|
|
|
|
/* I don't think we need to check GError here, do we? */
|
|
|
|
if (gtk_file_system_get_parent (impl->file_system, impl->current_folder, &parent_path, NULL))
|
|
|
|
{
|
|
|
|
if (parent_path)
|
|
|
|
{
|
|
|
|
gtk_file_path_free (parent_path);
|
|
|
|
has_parent = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (impl->up_button), has_parent);
|
|
|
|
}
|
|
|
|
|
2003-09-11 00:33:28 +00:00
|
|
|
/* Creates the widgets for the folder tree */
|
2003-09-06 00:50:33 +00:00
|
|
|
static GtkWidget *
|
2003-10-23 00:26:15 +00:00
|
|
|
create_folder_tree (GtkFileChooserDefault *impl)
|
2003-09-06 00:50:33 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
/* Scrolled window */
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
|
|
impl->tree_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->tree_scrollwin),
|
|
|
|
GTK_SHADOW_IN);
|
2003-10-13 02:31:09 +00:00
|
|
|
if (impl->folder_mode)
|
|
|
|
gtk_widget_show (impl->tree_scrollwin);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
/* Tree */
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
impl->tree = gtk_tree_view_new ();
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->tree), FALSE);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
|
|
|
|
g_signal_connect (selection, "changed",
|
|
|
|
G_CALLBACK (tree_selection_changed), impl);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (impl->tree_scrollwin), impl->tree);
|
|
|
|
gtk_widget_show (impl->tree);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
/* Column */
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (impl->tree), 0,
|
2003-11-03 20:24:04 +00:00
|
|
|
_("File name"),
|
2003-09-06 00:50:33 +00:00
|
|
|
gtk_cell_renderer_text_new (),
|
|
|
|
tree_name_data_func, impl, NULL);
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->tree),
|
|
|
|
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
|
|
|
|
|
|
|
|
return impl->tree_scrollwin;
|
|
|
|
}
|
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
/* Tries to add a bookmark from a path name */
|
2003-10-08 04:14:55 +00:00
|
|
|
static void
|
2003-12-01 15:33:37 +00:00
|
|
|
shortcuts_add_bookmark_from_path (GtkFileChooserDefault *impl,
|
|
|
|
const GtkFilePath *path)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-12-01 15:33:37 +00:00
|
|
|
GtkFileInfo *info;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
2003-12-01 15:33:37 +00:00
|
|
|
info = get_file_info (impl->file_system, path, &error);
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
error_getting_info_dialog (impl, path, error);
|
|
|
|
else if (!gtk_file_info_get_is_folder (info))
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
msg = g_strdup_printf (_("Could not add bookmark for %s because it is not a folder."),
|
|
|
|
gtk_file_path_get_string (path));
|
|
|
|
error_message (impl, msg);
|
|
|
|
g_free (msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error = NULL;
|
|
|
|
if (!gtk_file_system_add_bookmark (impl->file_system, path, &error))
|
|
|
|
error_could_not_add_bookmark_dialog (impl, path, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used when the "Add bookmark" button is clicked */
|
|
|
|
static void
|
|
|
|
add_bookmark_button_clicked_cb (GtkButton *button,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
shortcuts_add_bookmark_from_path (impl, impl->current_folder);
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2003-10-15 03:06:55 +00:00
|
|
|
/* Callback used when the "Remove bookmark" button is clicked */
|
|
|
|
static void
|
|
|
|
remove_bookmark_button_clicked_cb (GtkButton *button,
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl)
|
2003-10-15 03:06:55 +00:00
|
|
|
{
|
2004-01-06 05:13:31 +00:00
|
|
|
GtkTreeSelection *selection;
|
2003-10-15 03:06:55 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkFilePath *path;
|
2004-01-07 17:07:18 +00:00
|
|
|
gboolean removable;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2004-01-06 05:13:31 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
|
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
|
|
|
|
SHORTCUTS_COL_PATH, &path,
|
|
|
|
SHORTCUTS_COL_REMOVABLE, &removable, -1);
|
|
|
|
if (!removable)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return;
|
|
|
|
}
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
error = NULL;
|
|
|
|
if (!gtk_file_system_remove_bookmark (impl->file_system, path, &error))
|
|
|
|
error_dialog (impl,
|
|
|
|
_("Could not remove bookmark for %s:\n%s"),
|
|
|
|
path,
|
|
|
|
error);
|
|
|
|
}
|
2003-10-15 03:06:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sensitize the "add bookmark" button if the current folder is not in the
|
|
|
|
* bookmarks list, or de-sensitize it otherwise.
|
|
|
|
*/
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
bookmarks_check_add_sensitivity (GtkFileChooserDefault *impl)
|
2003-10-15 03:06:55 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean exists;
|
2003-12-17 05:55:16 +00:00
|
|
|
int volumes_idx;
|
|
|
|
int separator_idx;
|
2003-10-15 03:06:55 +00:00
|
|
|
|
|
|
|
exists = FALSE;
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
|
2003-12-17 05:55:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
separator_idx = shortcuts_get_index (impl, SHORTCUTS_SEPARATOR);
|
|
|
|
volumes_idx = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
i = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
if (i == separator_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
|
|
|
|
|
|
|
|
if (i >= volumes_idx && i < volumes_idx + impl->num_volumes)
|
|
|
|
{
|
|
|
|
GtkFileSystemVolume *volume;
|
|
|
|
GtkFilePath *base_path;
|
|
|
|
|
|
|
|
volume = data;
|
|
|
|
base_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
|
|
|
|
|
|
|
|
exists = strcmp (gtk_file_path_get_string (impl->current_folder),
|
|
|
|
gtk_file_path_get_string (base_path)) == 0;
|
|
|
|
g_free (base_path);
|
|
|
|
|
|
|
|
if (exists)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkFilePath *path;
|
|
|
|
|
|
|
|
path = data;
|
|
|
|
|
|
|
|
if (path && gtk_file_path_compare (path, impl->current_folder) == 0)
|
|
|
|
{
|
|
|
|
exists = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter));
|
|
|
|
}
|
2003-10-15 03:06:55 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (impl->add_bookmark_button, !exists);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the sensitivity of the "remove bookmark" button depending on whether a
|
|
|
|
* bookmark row is selected in the shortcuts tree.
|
|
|
|
*/
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
bookmarks_check_remove_sensitivity (GtkFileChooserDefault *impl)
|
2003-10-15 03:06:55 +00:00
|
|
|
{
|
2004-01-07 17:07:18 +00:00
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean removable = FALSE;
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter,
|
|
|
|
SHORTCUTS_COL_REMOVABLE, &removable,
|
|
|
|
-1);
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
gtk_widget_set_sensitive (impl->remove_bookmark_button, removable);
|
2003-10-15 03:06:55 +00:00
|
|
|
}
|
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
/* Converts raw selection data from text/uri-list to a list of strings */
|
|
|
|
static GSList *
|
|
|
|
split_uris (const char *data)
|
|
|
|
{
|
|
|
|
GSList *uris;
|
|
|
|
const char *p, *start;
|
|
|
|
|
|
|
|
uris = NULL;
|
|
|
|
|
|
|
|
start = data;
|
|
|
|
|
|
|
|
for (p = start; *p != 0; p++)
|
|
|
|
if (*p == '\r' && *(p + 1) == '\n')
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = g_strndup (start, p - start);
|
|
|
|
uris = g_slist_prepend (uris, name);
|
|
|
|
|
|
|
|
start = p + 2;
|
|
|
|
p = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
uris = g_slist_reverse (uris);
|
|
|
|
return uris;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used when we get the drag data for the bookmarks list. We add the
|
|
|
|
* received URIs as bookmarks if they are folders.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shortcuts_drag_data_received_cb (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time_,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFileChooserDefault *impl;
|
|
|
|
GSList *uris, *l;
|
|
|
|
|
|
|
|
impl = GTK_FILE_CHOOSER_DEFAULT (data);
|
|
|
|
|
|
|
|
uris = split_uris (selection_data->data);
|
|
|
|
|
|
|
|
for (l = uris; l; l = l->next)
|
|
|
|
{
|
|
|
|
char *uri;
|
|
|
|
GtkFilePath *path;
|
|
|
|
|
|
|
|
uri = l->data;
|
|
|
|
path = gtk_file_system_uri_to_path (impl->file_system, uri);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
shortcuts_add_bookmark_from_path (impl, path);
|
|
|
|
gtk_file_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
msg = g_strdup_printf (_("Could not add a bookmark for %s because it is an invalid path name."),
|
|
|
|
uri);
|
|
|
|
error_message (impl, msg);
|
|
|
|
g_free (msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (uris);
|
|
|
|
}
|
|
|
|
|
2003-12-10 03:46:30 +00:00
|
|
|
/* Callback used when the selection in the shortcuts tree changes */
|
|
|
|
static void
|
|
|
|
shortcuts_selection_changed_cb (GtkTreeSelection *selection,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
bookmarks_check_remove_sensitivity (impl);
|
|
|
|
}
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
/* Creates the widgets for the shortcuts and bookmarks tree */
|
|
|
|
static GtkWidget *
|
2003-10-23 00:26:15 +00:00
|
|
|
create_shortcuts_tree (GtkFileChooserDefault *impl)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
/* Scrolled window */
|
|
|
|
|
|
|
|
impl->shortcuts_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->shortcuts_scrollwin),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
gtk_widget_show (impl->shortcuts_scrollwin);
|
|
|
|
|
|
|
|
/* Tree */
|
|
|
|
|
|
|
|
impl->shortcuts_tree = gtk_tree_view_new ();
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE);
|
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
gtk_drag_dest_set (impl->shortcuts_tree,
|
|
|
|
GTK_DEST_DEFAULT_ALL,
|
|
|
|
shortcuts_targets,
|
|
|
|
num_shortcuts_targets,
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree));
|
2003-11-03 00:50:33 +00:00
|
|
|
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
|
2003-11-01 20:17:37 +00:00
|
|
|
gtk_tree_selection_set_select_function (selection,
|
|
|
|
shortcuts_select_func,
|
|
|
|
impl, NULL);
|
2003-12-10 03:46:30 +00:00
|
|
|
|
|
|
|
g_signal_connect (selection, "changed",
|
|
|
|
G_CALLBACK (shortcuts_selection_changed_cb), impl);
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
g_signal_connect (impl->shortcuts_tree, "row-activated",
|
2003-12-10 03:46:30 +00:00
|
|
|
G_CALLBACK (shortcuts_row_activated_cb), impl);
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-12-01 15:33:37 +00:00
|
|
|
g_signal_connect (impl->shortcuts_tree, "drag-data-received",
|
|
|
|
G_CALLBACK (shortcuts_drag_data_received_cb), impl);
|
|
|
|
|
2003-10-01 00:53:59 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (impl->shortcuts_scrollwin), impl->shortcuts_tree);
|
|
|
|
gtk_widget_show (impl->shortcuts_tree);
|
|
|
|
|
|
|
|
/* Model */
|
|
|
|
|
|
|
|
create_shortcuts_model (impl);
|
|
|
|
|
|
|
|
/* Column */
|
|
|
|
|
|
|
|
column = gtk_tree_view_column_new ();
|
2003-11-03 20:24:04 +00:00
|
|
|
gtk_tree_view_column_set_title (column, _("Folder"));
|
2003-10-01 00:53:59 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
2003-10-08 04:14:55 +00:00
|
|
|
gtk_tree_view_column_pack_start (column, renderer, FALSE);
|
2003-10-01 00:53:59 +00:00
|
|
|
gtk_tree_view_column_set_attributes (column, renderer,
|
2003-10-09 01:12:24 +00:00
|
|
|
"pixbuf", SHORTCUTS_COL_PIXBUF,
|
2003-10-01 00:53:59 +00:00
|
|
|
NULL);
|
|
|
|
|
2003-10-09 01:12:24 +00:00
|
|
|
renderer = _gtk_cell_renderer_sep_text_new ();
|
2003-10-01 00:53:59 +00:00
|
|
|
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_set_attributes (column, renderer,
|
2003-10-09 01:12:24 +00:00
|
|
|
"text", SHORTCUTS_COL_NAME,
|
2003-10-01 00:53:59 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->shortcuts_tree), column);
|
|
|
|
|
2003-12-01 18:57:17 +00:00
|
|
|
return impl->shortcuts_scrollwin;
|
|
|
|
}
|
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
/* Creates the widgets for the file list */
|
2003-09-06 00:50:33 +00:00
|
|
|
static GtkWidget *
|
2003-10-23 00:26:15 +00:00
|
|
|
create_file_list (GtkFileChooserDefault *impl)
|
2003-09-06 00:50:33 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
|
|
|
/* Scrolled window */
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
impl->list_scrollwin = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (impl->list_scrollwin),
|
|
|
|
GTK_SHADOW_IN);
|
2003-10-13 02:31:09 +00:00
|
|
|
if (!impl->folder_mode)
|
|
|
|
gtk_widget_show (impl->list_scrollwin);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
/* Tree/list view */
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
impl->list = gtk_tree_view_new ();
|
2004-01-16 03:35:33 +00:00
|
|
|
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (impl->list), TRUE);
|
2003-03-21 20:34:02 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (impl->list_scrollwin), impl->list);
|
2003-09-11 00:33:28 +00:00
|
|
|
g_signal_connect (impl->list, "row_activated",
|
|
|
|
G_CALLBACK (list_row_activated), impl);
|
2003-03-21 20:34:02 +00:00
|
|
|
gtk_widget_show (impl->list);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
g_signal_connect (selection, "changed",
|
|
|
|
G_CALLBACK (list_selection_changed), impl);
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-09-06 00:50:33 +00:00
|
|
|
/* Filename column */
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
impl->list_name_column = gtk_tree_view_column_new ();
|
2004-02-07 17:28:36 +00:00
|
|
|
gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_tree_view_column_set_title (impl->list_name_column, _("File name"));
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_name_column, FILE_LIST_COL_NAME);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
2004-02-07 17:28:36 +00:00
|
|
|
gtk_tree_view_column_pack_start (impl->list_name_column, renderer, FALSE);
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_tree_view_column_set_cell_data_func (impl->list_name_column, renderer,
|
2003-09-06 00:50:33 +00:00
|
|
|
list_icon_data_func, impl, NULL);
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
impl->list_name_renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_signal_connect (impl->list_name_renderer, "edited",
|
|
|
|
G_CALLBACK (renderer_edited_cb), impl);
|
|
|
|
g_signal_connect (impl->list_name_renderer, "editing-canceled",
|
|
|
|
G_CALLBACK (renderer_editing_canceled_cb), impl);
|
|
|
|
gtk_tree_view_column_pack_start (impl->list_name_column, impl->list_name_renderer, TRUE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (impl->list_name_column, impl->list_name_renderer,
|
2003-09-06 00:50:33 +00:00
|
|
|
list_name_data_func, impl, NULL);
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), impl->list_name_column);
|
2003-09-09 15:18:29 +00:00
|
|
|
#if 0
|
2003-09-06 00:50:33 +00:00
|
|
|
/* Size column */
|
|
|
|
|
|
|
|
column = gtk_tree_view_column_new ();
|
2003-11-03 20:24:04 +00:00
|
|
|
gtk_tree_view_column_set_title (column, _("Size"));
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer,
|
|
|
|
list_size_data_func, impl, NULL);
|
2003-10-01 19:42:50 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
|
2003-09-06 00:50:33 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
2003-09-09 15:18:29 +00:00
|
|
|
#endif
|
|
|
|
/* Modification time column */
|
|
|
|
|
|
|
|
column = gtk_tree_view_column_new ();
|
2003-11-03 20:24:04 +00:00
|
|
|
gtk_tree_view_column_set_title (column, _("Modified"));
|
2003-09-09 15:18:29 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_set_cell_data_func (column, renderer,
|
|
|
|
list_mtime_data_func, impl, NULL);
|
2003-10-01 19:42:50 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_MTIME);
|
2003-09-09 15:18:29 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
return impl->list_scrollwin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2004-01-06 04:18:42 +00:00
|
|
|
create_filename_entry_and_filter_combo (GtkFileChooserDefault *impl)
|
2003-09-06 00:50:33 +00:00
|
|
|
{
|
|
|
|
GtkWidget *hbox;
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *widget;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-11-19 20:45:17 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 12);
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Label and entry */
|
|
|
|
|
|
|
|
widget = gtk_label_new_with_mnemonic (_("_Filename:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (widget);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
impl->entry = _gtk_file_chooser_entry_new ();
|
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (impl->entry), TRUE);
|
|
|
|
g_signal_connect (impl->entry, "activate",
|
|
|
|
G_CALLBACK (entry_activate), impl);
|
2003-09-06 00:50:33 +00:00
|
|
|
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->entry),
|
|
|
|
impl->file_system);
|
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->entry, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (impl->entry);
|
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->entry);
|
|
|
|
|
|
|
|
/* Filter combo */
|
|
|
|
|
|
|
|
widget = filter_create (impl);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-09-06 00:50:33 +00:00
|
|
|
return hbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject*
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_constructor (GType type,
|
|
|
|
guint n_construct_properties,
|
|
|
|
GObjectConstructParam *construct_params)
|
2003-09-06 00:50:33 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl;
|
2003-09-06 00:50:33 +00:00
|
|
|
GObject *object;
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *vbox;
|
2003-09-06 00:50:33 +00:00
|
|
|
GtkWidget *hpaned;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GList *focus_chain;
|
2003-10-01 00:53:59 +00:00
|
|
|
GtkWidget *hbox;
|
2004-01-06 04:18:42 +00:00
|
|
|
GtkWidget *entry_widget;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
object = parent_class->constructor (type,
|
|
|
|
n_construct_properties,
|
|
|
|
construct_params);
|
2003-10-23 00:26:15 +00:00
|
|
|
impl = GTK_FILE_CHOOSER_DEFAULT (object);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
g_assert (impl->file_system);
|
|
|
|
|
|
|
|
gtk_widget_push_composite_child ();
|
|
|
|
|
2003-11-03 00:50:33 +00:00
|
|
|
/* Toolbar */
|
|
|
|
widget = toolbar_create (impl);
|
|
|
|
gtk_box_pack_start (GTK_BOX (impl), widget, FALSE, FALSE, 0);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Basic box */
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
vbox = gtk_vbox_new (FALSE, 12);
|
|
|
|
gtk_box_pack_start (GTK_BOX (impl), vbox, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (vbox);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
/* Paned widget */
|
|
|
|
|
|
|
|
hpaned = gtk_hpaned_new ();
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hpaned, TRUE, TRUE, 0);
|
2003-09-06 00:50:33 +00:00
|
|
|
gtk_paned_set_position (GTK_PANED (hpaned), 200); /* FIXME: this sucks */
|
|
|
|
gtk_widget_show (hpaned);
|
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
/* Shortcuts list */
|
|
|
|
|
|
|
|
widget = create_shortcuts_tree (impl);
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_paned_pack1 (GTK_PANED (hpaned), widget, FALSE, FALSE);
|
2003-10-13 02:31:09 +00:00
|
|
|
|
2003-09-11 00:33:28 +00:00
|
|
|
/* Folder tree */
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
hbox = gtk_hbox_new (FALSE, 12);
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_paned_pack2 (GTK_PANED (hpaned), hbox, TRUE, FALSE);
|
2003-10-01 00:53:59 +00:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2003-09-11 00:33:28 +00:00
|
|
|
widget = create_folder_tree (impl);
|
2003-10-01 00:53:59 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
|
|
|
|
|
2003-09-06 00:50:33 +00:00
|
|
|
/* File list */
|
|
|
|
|
|
|
|
widget = create_file_list (impl);
|
2003-10-13 02:31:09 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
|
|
|
/* Preview */
|
|
|
|
|
2003-11-03 20:24:04 +00:00
|
|
|
impl->preview_frame = gtk_frame_new (_("Preview"));
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), impl->preview_frame, FALSE, FALSE, 0);
|
2003-07-23 22:30:32 +00:00
|
|
|
/* Don't show preview frame initially */
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-06 04:18:42 +00:00
|
|
|
/* Filename entry and filter combo */
|
|
|
|
|
|
|
|
entry_widget = create_filename_entry_and_filter_combo (impl);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), entry_widget, FALSE, FALSE, 0);
|
|
|
|
|
2003-11-01 20:17:37 +00:00
|
|
|
/* Make the entry the first widget in the focus chain
|
|
|
|
*/
|
|
|
|
focus_chain = g_list_append (NULL, entry_widget);
|
|
|
|
focus_chain = g_list_append (focus_chain, hpaned);
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_container_set_focus_chain (GTK_CONTAINER (vbox), focus_chain);
|
2003-03-25 00:11:06 +00:00
|
|
|
g_list_free (focus_chain);
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-09-06 00:50:33 +00:00
|
|
|
gtk_widget_pop_composite_child ();
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
return object;
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 05:52:35 +00:00
|
|
|
/* Sets the extra_widget by packing it in the appropriate place */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
set_extra_widget (GtkFileChooserDefault *impl,
|
|
|
|
GtkWidget *extra_widget)
|
2003-09-03 05:52:35 +00:00
|
|
|
{
|
|
|
|
if (extra_widget == impl->extra_widget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (impl->extra_widget)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (impl), impl->extra_widget);
|
|
|
|
|
|
|
|
impl->extra_widget = extra_widget;
|
|
|
|
if (impl->extra_widget)
|
|
|
|
{
|
2003-12-29 20:55:01 +00:00
|
|
|
gtk_widget_show_all (impl->extra_widget);
|
2003-09-03 05:52:35 +00:00
|
|
|
gtk_box_pack_end (GTK_BOX (impl), impl->extra_widget, FALSE, FALSE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
static void
|
|
|
|
volumes_changed_cb (GtkFileSystem *file_system,
|
|
|
|
GtkFileChooserDefault *impl)
|
|
|
|
{
|
|
|
|
shortcuts_add_volumes (impl);
|
|
|
|
}
|
|
|
|
|
2003-10-08 04:14:55 +00:00
|
|
|
/* Callback used when the set of bookmarks changes in the file system */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
bookmarks_changed_cb (GtkFileSystem *file_system,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
shortcuts_add_bookmarks (impl);
|
2003-10-15 03:06:55 +00:00
|
|
|
|
|
|
|
bookmarks_check_add_sensitivity (impl);
|
|
|
|
bookmarks_check_remove_sensitivity (impl);
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2004-01-20 02:44:58 +00:00
|
|
|
/* Sets the file chooser to multiple selection mode */
|
|
|
|
static void
|
2004-01-23 20:15:05 +00:00
|
|
|
set_select_multiple (GtkFileChooserDefault *impl,
|
|
|
|
gboolean select_multiple,
|
|
|
|
gboolean property_notify)
|
2004-01-20 02:44:58 +00:00
|
|
|
{
|
2004-01-23 20:15:05 +00:00
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkSelectionMode mode;
|
|
|
|
|
|
|
|
if (select_multiple == impl->select_multiple)
|
|
|
|
return;
|
2004-01-20 02:44:58 +00:00
|
|
|
|
|
|
|
impl->select_multiple = select_multiple;
|
2004-01-23 20:15:05 +00:00
|
|
|
|
|
|
|
mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
|
|
|
|
gtk_tree_selection_set_mode (selection, mode);
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
gtk_tree_selection_set_mode (selection, mode);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (impl), "select-multiple");
|
|
|
|
|
|
|
|
/* FIXME #132255: See note in check_preview_change() */
|
2004-01-20 02:44:58 +00:00
|
|
|
check_preview_change (impl);
|
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case GTK_FILE_CHOOSER_PROP_ACTION:
|
|
|
|
impl->action = g_value_get_enum (value);
|
2004-01-17 04:34:49 +00:00
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2004-01-20 02:44:58 +00:00
|
|
|
{
|
|
|
|
gtk_widget_show (impl->new_folder_button);
|
|
|
|
|
|
|
|
if (impl->select_multiple)
|
|
|
|
{
|
|
|
|
g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
|
|
|
|
"Re-setting to single selection mode.");
|
2004-01-23 20:15:05 +00:00
|
|
|
set_select_multiple (impl, FALSE, TRUE);
|
2004-01-20 02:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-17 04:34:49 +00:00
|
|
|
else
|
|
|
|
gtk_widget_hide (impl->new_folder_button);
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
break;
|
2003-03-26 17:09:26 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
|
|
|
|
{
|
|
|
|
GtkFileSystem *file_system = g_value_get_object (value);
|
|
|
|
if (impl->file_system != file_system)
|
|
|
|
{
|
|
|
|
if (impl->file_system)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
g_signal_handler_disconnect (impl->file_system, impl->volumes_changed_id);
|
|
|
|
impl->volumes_changed_id = 0;
|
2003-10-08 04:14:55 +00:00
|
|
|
g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
|
|
|
|
impl->bookmarks_changed_id = 0;
|
|
|
|
g_object_unref (impl->file_system);
|
|
|
|
}
|
2003-03-26 17:09:26 +00:00
|
|
|
impl->file_system = file_system;
|
|
|
|
if (impl->file_system)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
|
|
|
g_object_ref (impl->file_system);
|
2003-12-17 05:55:16 +00:00
|
|
|
impl->volumes_changed_id = g_signal_connect (impl->file_system, "volumes-changed",
|
|
|
|
G_CALLBACK (volumes_changed_cb),
|
|
|
|
impl);
|
2003-10-08 04:14:55 +00:00
|
|
|
impl->bookmarks_changed_id = g_signal_connect (impl->file_system, "bookmarks-changed",
|
|
|
|
G_CALLBACK (bookmarks_changed_cb),
|
|
|
|
impl);
|
|
|
|
}
|
2003-03-26 17:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-07-23 15:31:10 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_FILTER:
|
|
|
|
set_current_filter (impl, g_value_get_object (value));
|
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
|
2003-09-06 00:50:33 +00:00
|
|
|
{
|
2003-03-21 20:34:02 +00:00
|
|
|
gboolean folder_mode = g_value_get_boolean (value);
|
|
|
|
if (folder_mode != impl->folder_mode)
|
|
|
|
{
|
|
|
|
impl->folder_mode = folder_mode;
|
|
|
|
if (impl->folder_mode)
|
2003-10-13 19:59:37 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (impl->list_scrollwin);
|
|
|
|
gtk_widget_show (impl->tree_scrollwin);
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
else
|
2003-10-13 19:59:37 +00:00
|
|
|
{
|
|
|
|
gtk_widget_hide (impl->tree_scrollwin);
|
|
|
|
gtk_widget_show (impl->list_scrollwin);
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
|
|
|
|
impl->local_only = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
|
|
|
|
set_preview_widget (impl, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
|
|
|
|
impl->preview_widget_active = g_value_get_boolean (value);
|
2003-07-23 22:30:32 +00:00
|
|
|
update_preview_widget_visibility (impl);
|
2003-03-21 20:34:02 +00:00
|
|
|
break;
|
2003-09-03 05:52:35 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
|
|
|
|
set_extra_widget (impl, g_value_get_object (value));
|
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
|
|
|
|
{
|
|
|
|
gboolean select_multiple = g_value_get_boolean (value);
|
2004-01-16 05:12:21 +00:00
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE && select_multiple)
|
|
|
|
{
|
|
|
|
g_warning ("Multiple selection mode is not allowed in Save mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-23 20:15:05 +00:00
|
|
|
set_select_multiple (impl, select_multiple, FALSE);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
|
|
|
|
{
|
|
|
|
gboolean show_hidden = g_value_get_boolean (value);
|
|
|
|
if (show_hidden != impl->show_hidden)
|
|
|
|
{
|
|
|
|
impl->show_hidden = show_hidden;
|
|
|
|
_gtk_file_system_model_set_show_hidden (impl->tree_model, show_hidden);
|
|
|
|
_gtk_file_system_model_set_show_hidden (impl->list_model, show_hidden);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2003-09-06 00:50:33 +00:00
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (object);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case GTK_FILE_CHOOSER_PROP_ACTION:
|
|
|
|
g_value_set_enum (value, impl->action);
|
|
|
|
break;
|
2003-07-23 15:31:10 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_FILTER:
|
|
|
|
g_value_set_object (value, impl->current_filter);
|
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_FOLDER_MODE:
|
|
|
|
g_value_set_boolean (value, impl->folder_mode);
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_LOCAL_ONLY:
|
|
|
|
g_value_set_boolean (value, impl->local_only);
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET:
|
|
|
|
g_value_set_object (value, impl->preview_widget);
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_PREVIEW_WIDGET_ACTIVE:
|
|
|
|
g_value_set_boolean (value, impl->preview_widget_active);
|
|
|
|
break;
|
2003-09-03 05:52:35 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_EXTRA_WIDGET:
|
|
|
|
g_value_set_object (value, impl->extra_widget);
|
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
|
|
|
|
g_value_set_boolean (value, impl->select_multiple);
|
|
|
|
break;
|
|
|
|
case GTK_FILE_CHOOSER_PROP_SHOW_HIDDEN:
|
|
|
|
g_value_set_boolean (value, impl->show_hidden);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2003-09-06 00:50:33 +00:00
|
|
|
break;
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
/* We override show-all since we have internal widgets that
|
|
|
|
* shouldn't be shown when you call show_all(), like the filter
|
2003-10-23 05:10:47 +00:00
|
|
|
* combo box.
|
2003-07-23 15:31:10 +00:00
|
|
|
*/
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_show_all (GtkWidget *widget)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
|
|
|
expand_and_select_func (GtkFileSystemModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = user_data;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
|
|
|
if (model == impl->tree_model)
|
|
|
|
tree_view = GTK_TREE_VIEW (impl->tree);
|
|
|
|
else
|
|
|
|
tree_view = GTK_TREE_VIEW (impl->list);
|
|
|
|
|
|
|
|
gtk_tree_view_expand_to_path (tree_view, path);
|
|
|
|
gtk_tree_view_expand_row (tree_view, path, FALSE);
|
|
|
|
gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
|
2003-03-25 00:11:06 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), path, NULL, TRUE, 0.3, 0.5);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
static gboolean
|
|
|
|
list_model_filter_func (GtkFileSystemModel *model,
|
|
|
|
GtkFilePath *path,
|
|
|
|
const GtkFileInfo *file_info,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = user_data;
|
2003-10-13 02:31:09 +00:00
|
|
|
GtkFileFilterInfo filter_info;
|
|
|
|
GtkFileFilterFlags needed;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
if (!impl->current_filter)
|
|
|
|
return TRUE;
|
|
|
|
|
2003-11-19 22:38:31 +00:00
|
|
|
if (gtk_file_info_get_is_folder (file_info))
|
|
|
|
return TRUE;
|
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
filter_info.contains = GTK_FILE_FILTER_DISPLAY_NAME | GTK_FILE_FILTER_MIME_TYPE;
|
|
|
|
|
|
|
|
needed = gtk_file_filter_get_needed (impl->current_filter);
|
|
|
|
|
|
|
|
filter_info.display_name = gtk_file_info_get_display_name (file_info);
|
|
|
|
filter_info.mime_type = gtk_file_info_get_mime_type (file_info);
|
|
|
|
|
|
|
|
if (needed & GTK_FILE_FILTER_FILENAME)
|
|
|
|
{
|
|
|
|
filter_info.filename = gtk_file_system_path_to_filename (impl->file_system, path);
|
|
|
|
if (filter_info.filename)
|
|
|
|
filter_info.contains |= GTK_FILE_FILTER_FILENAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filter_info.filename = NULL;
|
|
|
|
|
|
|
|
if (needed & GTK_FILE_FILTER_URI)
|
|
|
|
{
|
|
|
|
filter_info.uri = gtk_file_system_path_to_uri (impl->file_system, path);
|
|
|
|
if (filter_info.filename)
|
|
|
|
filter_info.contains |= GTK_FILE_FILTER_URI;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filter_info.uri = NULL;
|
|
|
|
|
|
|
|
result = gtk_file_filter_filter (impl->current_filter, &filter_info);
|
|
|
|
|
|
|
|
if (filter_info.filename)
|
|
|
|
g_free ((gchar *)filter_info.filename);
|
|
|
|
if (filter_info.uri)
|
|
|
|
g_free ((gchar *)filter_info.uri);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
install_list_model_filter (GtkFileChooserDefault *impl)
|
2003-10-13 02:31:09 +00:00
|
|
|
{
|
|
|
|
if (impl->current_filter)
|
|
|
|
_gtk_file_system_model_set_filter (impl->list_model,
|
|
|
|
list_model_filter_func,
|
|
|
|
impl);
|
|
|
|
}
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
#define COMPARE_DIRECTORIES \
|
|
|
|
GtkFileChooserDefault *impl = user_data; \
|
|
|
|
const GtkFileInfo *info_a = _gtk_file_system_model_get_info (impl->list_model, a); \
|
|
|
|
const GtkFileInfo *info_b = _gtk_file_system_model_get_info (impl->list_model, b); \
|
|
|
|
gboolean dir_a, dir_b; \
|
|
|
|
\
|
|
|
|
if (info_a) \
|
|
|
|
dir_a = gtk_file_info_get_is_folder (info_a); \
|
|
|
|
else \
|
|
|
|
return impl->list_sort_ascending ? -1 : 1; \
|
|
|
|
\
|
|
|
|
if (info_b) \
|
|
|
|
dir_b = gtk_file_info_get_is_folder (info_b); \
|
|
|
|
else \
|
|
|
|
return impl->list_sort_ascending ? 1 : -1; \
|
|
|
|
\
|
|
|
|
if (dir_a != dir_b) \
|
2003-10-13 02:31:09 +00:00
|
|
|
return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1) /* Directories *always* go first */
|
|
|
|
|
|
|
|
/* Sort callback for the filename column */
|
|
|
|
static gint
|
|
|
|
name_sort_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
COMPARE_DIRECTORIES;
|
|
|
|
else
|
|
|
|
return strcmp (gtk_file_info_get_display_key (info_a), gtk_file_info_get_display_key (info_b));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort callback for the size column */
|
|
|
|
static gint
|
|
|
|
size_sort_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
COMPARE_DIRECTORIES;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint64 size_a = gtk_file_info_get_size (info_a);
|
|
|
|
gint64 size_b = gtk_file_info_get_size (info_b);
|
|
|
|
|
|
|
|
return size_a > size_b ? -1 : (size_a == size_b ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort callback for the mtime column */
|
|
|
|
static gint
|
|
|
|
mtime_sort_func (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *a,
|
|
|
|
GtkTreeIter *b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
COMPARE_DIRECTORIES;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkFileTime ta = gtk_file_info_get_modification_time (info_a);
|
|
|
|
GtkFileTime tb = gtk_file_info_get_modification_time (info_b);
|
|
|
|
|
|
|
|
return ta > tb ? -1 : (ta == tb ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback used when the sort column changes. We cache the sort order for use
|
|
|
|
* in name_sort_func().
|
|
|
|
*/
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
list_sort_column_changed_cb (GtkTreeSortable *sortable,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-10-13 02:31:09 +00:00
|
|
|
{
|
|
|
|
GtkSortType sort_type;
|
|
|
|
|
|
|
|
if (gtk_tree_sortable_get_sort_column_id (sortable, NULL, &sort_type))
|
|
|
|
impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gets rid of the old list model and creates a new one for the current folder */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
set_list_model (GtkFileChooserDefault *impl)
|
2003-10-13 02:31:09 +00:00
|
|
|
{
|
|
|
|
if (impl->list_model)
|
|
|
|
{
|
|
|
|
g_object_unref (impl->list_model);
|
|
|
|
g_object_unref (impl->sort_model);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl->list_model = _gtk_file_system_model_new (impl->file_system,
|
|
|
|
impl->current_folder, 0,
|
2004-02-09 21:58:26 +00:00
|
|
|
GTK_FILE_INFO_ALL);
|
2004-01-16 03:35:33 +00:00
|
|
|
_gtk_file_system_model_set_show_hidden (impl->list_model, impl->show_hidden);
|
2003-10-13 02:31:09 +00:00
|
|
|
install_list_model_filter (impl);
|
|
|
|
|
|
|
|
impl->sort_model = (GtkTreeModelSort *)gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (impl->list_model));
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, name_sort_func, impl, NULL);
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_SIZE, size_sort_func, impl, NULL);
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_MTIME, mtime_sort_func, impl, NULL);
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->sort_model), NULL, NULL, NULL);
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->sort_model), FILE_LIST_COL_NAME, GTK_SORT_ASCENDING);
|
|
|
|
impl->list_sort_ascending = TRUE;
|
|
|
|
|
|
|
|
g_signal_connect (impl->sort_model, "sort_column_changed",
|
|
|
|
G_CALLBACK (list_sort_column_changed_cb), impl);
|
|
|
|
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->list),
|
|
|
|
GTK_TREE_MODEL (impl->sort_model));
|
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->list));
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->list),
|
|
|
|
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME);
|
|
|
|
}
|
|
|
|
|
2004-01-16 03:35:33 +00:00
|
|
|
/* Gets rid of the old folder tree model and creates a new one for the volume
|
|
|
|
* corresponding to the specified path.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_tree_model (GtkFileChooserDefault *impl, const GtkFilePath *path)
|
|
|
|
{
|
|
|
|
GtkFileSystemVolume *volume;
|
|
|
|
GtkFilePath *volume_path;
|
|
|
|
|
|
|
|
volume = gtk_file_system_get_volume_for_path (impl->file_system, path);
|
|
|
|
volume_path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
|
|
|
|
|
|
|
|
if (impl->current_volume_path && gtk_file_path_compare (volume_path, impl->current_volume_path) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (impl->tree_model)
|
|
|
|
g_object_unref (impl->tree_model);
|
|
|
|
|
|
|
|
impl->current_volume_path = gtk_file_path_copy (volume_path);
|
|
|
|
|
|
|
|
impl->tree_model = _gtk_file_system_model_new (impl->file_system, impl->current_volume_path, -1,
|
|
|
|
GTK_FILE_INFO_DISPLAY_NAME);
|
|
|
|
_gtk_file_system_model_set_show_files (impl->tree_model, FALSE);
|
|
|
|
_gtk_file_system_model_set_show_hidden (impl->tree_model, impl->show_hidden);
|
|
|
|
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->tree),
|
|
|
|
GTK_TREE_MODEL (impl->tree_model));
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
gtk_file_path_free (volume_path);
|
|
|
|
gtk_file_system_volume_free (impl->file_system, volume);
|
|
|
|
}
|
|
|
|
|
2003-10-13 02:31:09 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
update_chooser_entry (GtkFileChooserDefault *impl)
|
2003-10-13 02:31:09 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
const GtkFileInfo *info;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
2004-01-23 20:15:05 +00:00
|
|
|
/* FIXME #132255: Fixing this for multiple selection involves getting the full
|
|
|
|
* selection and diffing to find out what the most recently selected file is;
|
|
|
|
* there is logic in GtkFileSelection that probably can be copied;
|
|
|
|
* check_preview_change() is similar.
|
2003-10-13 02:31:09 +00:00
|
|
|
*/
|
2004-01-23 20:15:05 +00:00
|
|
|
if (impl->select_multiple
|
|
|
|
|| !gtk_tree_selection_get_selected (selection, NULL, &iter))
|
2003-10-13 02:31:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
|
|
|
|
&child_iter,
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
|
|
|
|
|
|
|
|
_gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry),
|
|
|
|
gtk_file_info_get_display_name (info));
|
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_set_current_folder (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-12-10 20:49:44 +00:00
|
|
|
char *str;
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-12-02 04:23:06 +00:00
|
|
|
if (impl->current_folder)
|
|
|
|
gtk_file_path_free (impl->current_folder);
|
|
|
|
|
|
|
|
impl->current_folder = gtk_file_path_copy (path);
|
|
|
|
|
2003-12-10 20:49:44 +00:00
|
|
|
/* Change the current folder label */
|
|
|
|
|
|
|
|
str = g_strdup_printf (_("Current folder: %s"), gtk_file_path_get_string (path));
|
|
|
|
gtk_label_set_text (GTK_LABEL (impl->folder_label), str);
|
|
|
|
g_free (str);
|
|
|
|
|
2004-01-16 03:35:33 +00:00
|
|
|
/* Update the folder tree */
|
2003-12-02 04:23:06 +00:00
|
|
|
|
|
|
|
if (!impl->changing_folder)
|
|
|
|
{
|
|
|
|
impl->changing_folder = TRUE;
|
2004-01-16 03:35:33 +00:00
|
|
|
set_tree_model (impl, impl->current_folder);
|
2003-12-02 04:23:06 +00:00
|
|
|
_gtk_file_system_model_path_do (impl->tree_model, path,
|
|
|
|
expand_and_select_func, impl);
|
|
|
|
impl->changing_folder = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify the location entry */
|
|
|
|
|
|
|
|
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->entry), impl->current_folder);
|
|
|
|
|
|
|
|
/* Create a new list model */
|
|
|
|
set_list_model (impl);
|
|
|
|
|
|
|
|
/* Refresh controls */
|
|
|
|
|
|
|
|
shortcuts_unselect_all (impl);
|
|
|
|
toolbar_check_sensitivity (impl);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (impl, "current-folder-changed", 0);
|
|
|
|
|
|
|
|
update_chooser_entry (impl);
|
|
|
|
check_preview_change (impl);
|
|
|
|
bookmarks_check_add_sensitivity (impl);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (impl, "selection-changed", 0);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
static GtkFilePath *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_get_current_folder (GtkFileChooser *chooser)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
return gtk_file_path_copy (impl->current_folder);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-07-11 19:18:36 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_set_current_name (GtkFileChooser *chooser,
|
|
|
|
const gchar *name)
|
2003-07-11 19:18:36 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-07-11 19:18:36 +00:00
|
|
|
|
|
|
|
_gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->entry), name);
|
|
|
|
}
|
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
static void
|
|
|
|
select_func (GtkFileSystemModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = user_data;
|
2003-03-21 23:59:22 +00:00
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
|
|
|
|
GtkTreePath *sorted_path;
|
|
|
|
|
|
|
|
sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model, path);
|
|
|
|
gtk_tree_view_set_cursor (tree_view, sorted_path, NULL, FALSE);
|
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (impl->tree), sorted_path, NULL, TRUE, 0.3, 0.0);
|
|
|
|
gtk_tree_path_free (sorted_path);
|
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_select_path (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-04-04 22:43:12 +00:00
|
|
|
GtkFilePath *parent_path;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
error = NULL;
|
|
|
|
if (!gtk_file_system_get_parent (impl->file_system, path, &parent_path, &error))
|
|
|
|
{
|
|
|
|
error_getting_info_dialog (impl, path, error);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
if (!parent_path)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-07-11 19:18:36 +00:00
|
|
|
_gtk_file_chooser_set_current_folder_path (chooser, path);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-11 19:18:36 +00:00
|
|
|
_gtk_file_chooser_set_current_folder_path (chooser, parent_path);
|
2003-04-04 22:43:12 +00:00
|
|
|
gtk_file_path_free (parent_path);
|
|
|
|
_gtk_file_system_model_path_do (impl->list_model, path,
|
2003-07-23 15:31:10 +00:00
|
|
|
select_func, impl);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unselect_func (GtkFileSystemModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = user_data;
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkTreeView *tree_view = GTK_TREE_VIEW (impl->list);
|
2003-03-21 23:59:22 +00:00
|
|
|
GtkTreePath *sorted_path;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
sorted_path = gtk_tree_model_sort_convert_child_path_to_path (impl->sort_model,
|
|
|
|
path);
|
2003-03-21 20:34:02 +00:00
|
|
|
gtk_tree_selection_unselect_path (gtk_tree_view_get_selection (tree_view),
|
2003-03-21 23:59:22 +00:00
|
|
|
sorted_path);
|
|
|
|
gtk_tree_path_free (sorted_path);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_unselect_path (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
_gtk_file_system_model_path_do (impl->list_model, path,
|
2003-03-21 20:34:02 +00:00
|
|
|
unselect_func, impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_select_all (GtkFileChooser *chooser)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-03-21 20:34:02 +00:00
|
|
|
if (impl->select_multiple)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
gtk_tree_selection_select_all (selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_unselect_all (GtkFileChooser *chooser)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
}
|
|
|
|
|
2003-12-08 23:38:57 +00:00
|
|
|
struct get_paths_closure {
|
|
|
|
GtkFileChooserDefault *impl;
|
2004-02-09 20:31:38 +00:00
|
|
|
GSList *result;
|
|
|
|
GtkFilePath *path_from_entry;
|
2003-12-08 23:38:57 +00:00
|
|
|
};
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-04-04 22:43:12 +00:00
|
|
|
get_paths_foreach (GtkTreeModel *model,
|
2004-01-16 05:12:21 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-12-08 23:38:57 +00:00
|
|
|
struct get_paths_closure *info;
|
2004-01-16 05:12:21 +00:00
|
|
|
const GtkFilePath *file_path;
|
|
|
|
GtkFileSystemModel *fs_model;
|
|
|
|
GtkTreeIter sel_iter;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-12-08 23:38:57 +00:00
|
|
|
info = data;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-16 05:12:21 +00:00
|
|
|
if (info->impl->folder_mode)
|
|
|
|
{
|
|
|
|
fs_model = info->impl->tree_model;
|
|
|
|
sel_iter = *iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fs_model = info->impl->list_model;
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (info->impl->sort_model, &sel_iter, iter);
|
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-01-16 05:12:21 +00:00
|
|
|
file_path = _gtk_file_system_model_get_path (fs_model, &sel_iter);
|
2004-02-09 20:31:38 +00:00
|
|
|
|
|
|
|
if (!info->path_from_entry
|
|
|
|
|| gtk_file_path_compare (info->path_from_entry, file_path) != 0)
|
|
|
|
info->result = g_slist_prepend (info->result, gtk_file_path_copy (file_path));
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_get_paths (GtkFileChooser *chooser)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2004-02-09 20:31:38 +00:00
|
|
|
GtkFileChooserEntry *chooser_entry;
|
|
|
|
const GtkFilePath *folder_path;
|
|
|
|
const gchar *file_part;
|
2003-12-08 23:38:57 +00:00
|
|
|
struct get_paths_closure info;
|
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
info.impl = impl;
|
|
|
|
info.result = NULL;
|
|
|
|
info.path_from_entry = NULL;
|
2003-12-08 23:38:57 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->entry);
|
|
|
|
folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
|
|
|
|
file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
if (file_part != NULL && file_part[0] != '\0')
|
|
|
|
{
|
|
|
|
GtkFilePath *selected;
|
|
|
|
GError *error = NULL;
|
2003-12-08 23:38:57 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
selected = gtk_file_system_make_path (impl->file_system, folder_path, file_part, &error);
|
2004-01-16 05:12:21 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
if (!selected)
|
|
|
|
{
|
|
|
|
error_building_filename_dialog (impl, folder_path, file_part, error);
|
|
|
|
return NULL;
|
2003-12-08 23:38:57 +00:00
|
|
|
}
|
2004-02-09 20:31:38 +00:00
|
|
|
|
|
|
|
info.path_from_entry = selected;
|
2003-12-08 23:38:57 +00:00
|
|
|
}
|
2003-03-24 15:41:40 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
if (!info.path_from_entry || impl->select_multiple)
|
2004-01-16 05:12:21 +00:00
|
|
|
{
|
2004-02-09 20:31:38 +00:00
|
|
|
GtkTreeSelection *selection;
|
2003-03-24 15:41:40 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
selection = NULL;
|
2004-01-16 05:12:21 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
if (impl->folder_mode)
|
|
|
|
{
|
|
|
|
if (impl->tree_model)
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->tree));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (impl->sort_model)
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selection)
|
|
|
|
gtk_tree_selection_selected_foreach (selection, get_paths_foreach, &info);
|
2004-01-16 05:12:21 +00:00
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2004-02-09 20:31:38 +00:00
|
|
|
if (info.path_from_entry)
|
|
|
|
info.result = g_slist_prepend (info.result, info.path_from_entry);
|
2003-12-08 23:38:57 +00:00
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
return g_slist_reverse (info.result);
|
|
|
|
}
|
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
static GtkFilePath *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_get_preview_path (GtkFileChooser *chooser)
|
2003-07-23 22:30:32 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
if (impl->preview_path)
|
|
|
|
return gtk_file_path_copy (impl->preview_path);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
static GtkFileSystem *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_get_file_system (GtkFileChooser *chooser)
|
2003-04-04 22:43:12 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-04-04 22:43:12 +00:00
|
|
|
|
|
|
|
return impl->file_system;
|
|
|
|
}
|
|
|
|
|
2003-12-10 20:49:44 +00:00
|
|
|
/* Shows or hides the filter widgets */
|
|
|
|
static void
|
|
|
|
toolbar_show_filters (GtkFileChooserDefault *impl,
|
|
|
|
gboolean show)
|
|
|
|
{
|
|
|
|
if (show)
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_widget_show (impl->filter_combo);
|
2003-12-10 20:49:44 +00:00
|
|
|
else
|
2004-01-06 04:18:42 +00:00
|
|
|
gtk_widget_hide (impl->filter_combo);
|
2004-01-20 02:44:58 +00:00
|
|
|
}
|
2003-12-10 20:49:44 +00:00
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_add_filter (GtkFileChooser *chooser,
|
|
|
|
GtkFileFilter *filter)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-07-23 15:31:10 +00:00
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
if (g_slist_find (impl->filters, filter))
|
|
|
|
{
|
|
|
|
g_warning ("gtk_file_chooser_add_filter() called on filter already in list\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_ref (filter);
|
|
|
|
gtk_object_sink (GTK_OBJECT (filter));
|
|
|
|
impl->filters = g_slist_append (impl->filters, filter);
|
|
|
|
|
|
|
|
name = gtk_file_filter_get_name (filter);
|
|
|
|
if (!name)
|
|
|
|
name = "Untitled filter"; /* Place-holder, doesn't need to be marked for translation */
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-10-23 05:10:47 +00:00
|
|
|
gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
|
2003-07-23 15:31:10 +00:00
|
|
|
|
|
|
|
if (!g_slist_find (impl->filters, impl->current_filter))
|
|
|
|
set_current_filter (impl, filter);
|
|
|
|
|
2003-12-10 20:49:44 +00:00
|
|
|
toolbar_show_filters (impl, TRUE);
|
2003-07-23 15:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_remove_filter (GtkFileChooser *chooser,
|
|
|
|
GtkFileFilter *filter)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-10-23 05:10:47 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint filter_index;
|
|
|
|
|
|
|
|
filter_index = g_slist_index (impl->filters, filter);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-10-28 14:13:01 +00:00
|
|
|
if (filter_index < 0)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
|
|
|
g_warning ("gtk_file_chooser_remove_filter() called on filter not in list\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl->filters = g_slist_remove (impl->filters, filter);
|
|
|
|
|
|
|
|
if (filter == impl->current_filter)
|
|
|
|
{
|
|
|
|
if (impl->filters)
|
|
|
|
set_current_filter (impl, impl->filters->data);
|
|
|
|
else
|
|
|
|
set_current_filter (impl, NULL);
|
|
|
|
}
|
|
|
|
|
2003-10-23 05:10:47 +00:00
|
|
|
/* Remove row from the combo box */
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
|
|
|
|
gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_index);
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
g_object_unref (filter);
|
|
|
|
|
|
|
|
if (!impl->filters)
|
2003-12-10 20:49:44 +00:00
|
|
|
toolbar_show_filters (impl, FALSE);
|
2003-07-23 15:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_list_filters (GtkFileChooser *chooser)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-07-23 15:31:10 +00:00
|
|
|
|
|
|
|
return g_slist_copy (impl->filters);
|
|
|
|
}
|
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
/* Returns the position in the shortcuts tree where the nth specified shortcut would appear */
|
|
|
|
static int
|
2003-10-23 00:26:15 +00:00
|
|
|
shortcuts_get_pos_for_shortcut_folder (GtkFileChooserDefault *impl,
|
|
|
|
int pos)
|
2003-10-18 04:29:40 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
return pos + shortcuts_get_index (impl, SHORTCUTS_SHORTCUTS);
|
2003-10-18 04:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_add_shortcut_folder (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-10-18 04:29:40 +00:00
|
|
|
gboolean result;
|
|
|
|
int pos;
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
pos = shortcuts_get_pos_for_shortcut_folder (impl, impl->num_shortcuts);
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2004-01-07 17:07:18 +00:00
|
|
|
result = shortcuts_insert_path (impl, pos, FALSE, NULL, path, NULL, FALSE, error);
|
2003-10-18 04:29:40 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
impl->num_shortcuts++;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_remove_shortcut_folder (GtkFileChooser *chooser,
|
|
|
|
const GtkFilePath *path,
|
|
|
|
GError **error)
|
2003-10-18 04:29:40 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-10-18 04:29:40 +00:00
|
|
|
int pos;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (impl->num_shortcuts == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
|
|
|
|
if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
for (i = 0; i < impl->num_shortcuts; i++)
|
|
|
|
{
|
|
|
|
GtkFilePath *shortcut;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
|
|
|
|
g_assert (shortcut != NULL);
|
|
|
|
|
|
|
|
if (gtk_file_path_compare (shortcut, path) == 0)
|
|
|
|
{
|
|
|
|
/* The other columns are freed by the GtkTreeStore */
|
|
|
|
gtk_file_path_free (shortcut);
|
|
|
|
gtk_tree_store_remove (impl->shortcuts_model, &iter);
|
|
|
|
impl->num_shortcuts--;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
g_set_error (error,
|
|
|
|
GTK_FILE_CHOOSER_ERROR,
|
|
|
|
GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
|
2003-11-03 20:24:04 +00:00
|
|
|
_("shortcut %s does not exist"),
|
2003-10-18 04:29:40 +00:00
|
|
|
gtk_file_path_get_string (path));
|
|
|
|
|
|
|
|
return FALSE;
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2003-10-23 00:26:15 +00:00
|
|
|
gtk_file_chooser_default_list_shortcut_folders (GtkFileChooser *chooser)
|
2003-10-08 04:14:55 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (chooser);
|
2003-10-18 04:29:40 +00:00
|
|
|
int pos;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
int i;
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
pos = shortcuts_get_pos_for_shortcut_folder (impl, 0);
|
|
|
|
if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (impl->shortcuts_model), &iter, NULL, pos))
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < impl->num_shortcuts; i++)
|
|
|
|
{
|
|
|
|
GtkFilePath *shortcut;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &shortcut, -1);
|
|
|
|
g_assert (shortcut != NULL);
|
|
|
|
|
|
|
|
list = g_slist_prepend (list, gtk_file_path_copy (shortcut));
|
|
|
|
|
|
|
|
if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (impl->shortcuts_model), &iter))
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2003-10-08 04:14:55 +00:00
|
|
|
|
2003-10-18 04:29:40 +00:00
|
|
|
return g_slist_reverse (list);
|
2003-10-08 04:14:55 +00:00
|
|
|
}
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
set_current_filter (GtkFileChooserDefault *impl,
|
|
|
|
GtkFileFilter *filter)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
|
|
|
if (impl->current_filter != filter)
|
|
|
|
{
|
2003-10-23 05:10:47 +00:00
|
|
|
int filter_index;
|
2003-07-23 15:31:10 +00:00
|
|
|
|
|
|
|
/* If we have filters, new filter must be one of them
|
|
|
|
*/
|
2003-10-23 05:10:47 +00:00
|
|
|
filter_index = g_slist_index (impl->filters, filter);
|
|
|
|
if (impl->filters && filter_index < 0)
|
2003-07-23 15:31:10 +00:00
|
|
|
return;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
if (impl->current_filter)
|
|
|
|
g_object_unref (impl->current_filter);
|
|
|
|
impl->current_filter = filter;
|
|
|
|
if (impl->current_filter)
|
|
|
|
{
|
|
|
|
g_object_ref (impl->current_filter);
|
|
|
|
gtk_object_sink (GTK_OBJECT (filter));
|
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
if (impl->filters)
|
2003-10-23 05:10:47 +00:00
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
|
|
|
|
filter_index);
|
2003-07-23 15:31:10 +00:00
|
|
|
|
|
|
|
install_list_model_filter (impl);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (impl), "filter");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
static void
|
|
|
|
open_and_close (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *target_path)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
gtk_tree_path_append_index (path, 0);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (gtk_tree_path_is_ancestor (path, target_path) ||
|
|
|
|
gtk_tree_path_compare (path, target_path) == 0)
|
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
gtk_tree_view_expand_row (tree_view, path, FALSE);
|
|
|
|
if (gtk_tree_model_iter_children (model, &child_iter, &iter))
|
|
|
|
{
|
|
|
|
iter = child_iter;
|
|
|
|
gtk_tree_path_down (path);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_tree_view_collapse_row (tree_view, path);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
GtkTreeIter parent_iter;
|
|
|
|
GtkTreeIter next_iter;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
next_iter = iter;
|
|
|
|
if (gtk_tree_model_iter_next (model, &next_iter))
|
|
|
|
{
|
|
|
|
iter = next_iter;
|
|
|
|
gtk_tree_path_next (path);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_tree_model_iter_parent (model, &parent_iter, &iter))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
iter = parent_iter;
|
|
|
|
gtk_tree_path_up (path);
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
;
|
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
out:
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2003-07-23 15:31:10 +00:00
|
|
|
static void
|
2003-10-23 05:10:47 +00:00
|
|
|
filter_combo_changed (GtkComboBox *combo_box,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-07-23 15:31:10 +00:00
|
|
|
{
|
2003-10-23 05:10:47 +00:00
|
|
|
gint new_index = gtk_combo_box_get_active (combo_box);
|
2003-07-23 15:31:10 +00:00
|
|
|
GtkFileFilter *new_filter = g_slist_nth_data (impl->filters, new_index);
|
|
|
|
|
|
|
|
set_current_filter (impl, new_filter);
|
|
|
|
}
|
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
check_preview_change (GtkFileChooserDefault *impl)
|
2003-07-23 22:30:32 +00:00
|
|
|
{
|
|
|
|
const GtkFilePath *new_path = NULL;
|
|
|
|
|
2004-01-23 20:15:05 +00:00
|
|
|
/* FIXME #132255: Fixing preview for multiple selection involves getting the
|
|
|
|
* full selection and diffing to find out what the most recently selected file
|
|
|
|
* is; there is logic in GtkFileSelection that probably can be
|
|
|
|
* copied. update_chooser_entry() is similar.
|
2003-07-23 22:30:32 +00:00
|
|
|
*/
|
|
|
|
if (impl->sort_model && !impl->select_multiple)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
|
|
|
|
&child_iter, &iter);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
new_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
|
|
|
|
}
|
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
if (new_path != impl->preview_path &&
|
|
|
|
!(new_path && impl->preview_path &&
|
|
|
|
gtk_file_path_compare (new_path, impl->preview_path) == 0))
|
|
|
|
{
|
|
|
|
if (impl->preview_path)
|
|
|
|
gtk_file_path_free (impl->preview_path);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
if (new_path)
|
|
|
|
impl->preview_path = gtk_file_path_copy (new_path);
|
|
|
|
else
|
|
|
|
impl->preview_path = NULL;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-23 22:30:32 +00:00
|
|
|
g_signal_emit_by_name (impl, "update-preview");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
tree_selection_changed (GtkTreeSelection *selection,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2003-04-04 22:43:12 +00:00
|
|
|
const GtkFilePath *file_path;
|
2003-03-24 15:41:40 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
|
2004-01-23 20:15:05 +00:00
|
|
|
/* FIXME #132255: Fixing this for multiple selection involves getting the full
|
|
|
|
* selection and diffing to find out what the most recently selected file is;
|
|
|
|
* there is logic in GtkFileSelection that probably can be copied;
|
|
|
|
* check_preview_change() is similar.
|
|
|
|
*/
|
|
|
|
if (impl->select_multiple
|
|
|
|
|| !gtk_tree_selection_get_selected (selection, NULL, &iter))
|
2003-03-24 15:41:40 +00:00
|
|
|
return;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
file_path = _gtk_file_system_model_get_path (impl->tree_model, &iter);
|
|
|
|
if (impl->current_folder && gtk_file_path_compare (file_path, impl->current_folder) == 0)
|
2003-03-24 15:41:40 +00:00
|
|
|
return;
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-03-24 15:41:40 +00:00
|
|
|
/* Close the tree up to only the parents of the newly selected
|
|
|
|
* node and it's immediate children are visible.
|
|
|
|
*/
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->tree_model), &iter);
|
|
|
|
open_and_close (GTK_TREE_VIEW (impl->tree), path);
|
|
|
|
gtk_tree_path_free (path);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-12-02 04:23:06 +00:00
|
|
|
if (!impl->changing_folder)
|
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
/* Activates a volume by mounting it if necessary and then switching to its
|
|
|
|
* base path.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
shortcuts_activate_volume (GtkFileChooserDefault *impl,
|
|
|
|
GtkFileSystemVolume *volume)
|
|
|
|
{
|
|
|
|
GtkFilePath *path;
|
|
|
|
|
|
|
|
if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
|
|
|
|
{
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
if (!gtk_file_system_volume_mount (impl->file_system, volume, &error))
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
msg = g_strdup_printf ("Could not mount %s:\n%s",
|
|
|
|
gtk_file_system_volume_get_display_name (impl->file_system, volume),
|
|
|
|
error->message);
|
|
|
|
error_message (impl, msg);
|
|
|
|
g_free (msg);
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_file_system_volume_get_base_path (impl->file_system, volume);
|
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), path);
|
|
|
|
gtk_file_path_free (path);
|
|
|
|
}
|
|
|
|
|
2003-11-01 20:17:37 +00:00
|
|
|
/* Callback used when a row in the shortcuts list is activated */
|
2003-10-01 00:53:59 +00:00
|
|
|
static void
|
2003-12-10 03:46:30 +00:00
|
|
|
shortcuts_row_activated_cb (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-10-01 00:53:59 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2003-12-17 05:55:16 +00:00
|
|
|
int selected, start_row;
|
|
|
|
gpointer data;
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-11-01 20:17:37 +00:00
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->shortcuts_model), &iter, path))
|
2003-10-01 00:53:59 +00:00
|
|
|
return;
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
selected = *gtk_tree_path_get_indices (path);
|
2003-10-15 03:06:55 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
if (selected == shortcuts_get_index (impl, SHORTCUTS_SEPARATOR))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->shortcuts_model), &iter, SHORTCUTS_COL_PATH, &data, -1);
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
start_row = shortcuts_get_index (impl, SHORTCUTS_VOLUMES);
|
|
|
|
if (selected >= start_row && selected < start_row + impl->num_volumes)
|
2003-10-09 01:12:24 +00:00
|
|
|
{
|
2003-12-17 05:55:16 +00:00
|
|
|
GtkFileSystemVolume *volume;
|
|
|
|
|
|
|
|
volume = data;
|
|
|
|
shortcuts_activate_volume (impl, volume);
|
2003-10-09 01:12:24 +00:00
|
|
|
}
|
2003-12-17 05:55:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkFilePath *file_path;
|
2003-10-01 00:53:59 +00:00
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
file_path = data;
|
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
|
|
|
|
}
|
2003-10-01 00:53:59 +00:00
|
|
|
}
|
|
|
|
|
2003-11-01 20:17:37 +00:00
|
|
|
static gboolean
|
|
|
|
shortcuts_select_func (GtkTreeSelection *selection,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gboolean path_currently_selected,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkFileChooserDefault *impl = data;
|
|
|
|
|
2003-12-17 05:55:16 +00:00
|
|
|
return (*gtk_tree_path_get_indices (path) != shortcuts_get_index (impl, SHORTCUTS_SEPARATOR));
|
2003-11-01 20:17:37 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
list_selection_changed (GtkTreeSelection *selection,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2004-01-23 20:15:05 +00:00
|
|
|
/* See if we are in the new folder editable row for Save mode */
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2004-01-17 04:34:49 +00:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter, child_iter;
|
|
|
|
const GtkFileInfo *info;
|
|
|
|
|
2004-01-23 20:15:05 +00:00
|
|
|
g_assert (!impl->select_multiple);
|
2004-01-17 04:34:49 +00:00
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->list));
|
|
|
|
if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
|
|
|
|
&child_iter,
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
|
|
|
|
if (!info)
|
|
|
|
return; /* We are on the editable row for New Folder */
|
|
|
|
}
|
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
update_chooser_entry (impl);
|
2003-07-23 22:30:32 +00:00
|
|
|
check_preview_change (impl);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-11 19:18:36 +00:00
|
|
|
g_signal_emit_by_name (impl, "selection-changed", 0);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 00:33:28 +00:00
|
|
|
/* Callback used when a row in the file list is activated */
|
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
list_row_activated (GtkTreeView *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-09-11 00:33:28 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter, child_iter;
|
|
|
|
const GtkFileInfo *info;
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->sort_model), &iter, path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model, &child_iter, &iter);
|
|
|
|
|
|
|
|
info = _gtk_file_system_model_get_info (impl->list_model, &child_iter);
|
|
|
|
|
|
|
|
if (gtk_file_info_get_is_folder (info))
|
|
|
|
{
|
|
|
|
const GtkFilePath *file_path;
|
|
|
|
|
|
|
|
file_path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
|
2003-10-01 00:53:59 +00:00
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), file_path);
|
2003-09-11 00:33:28 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_emit_by_name (impl, "file-activated");
|
|
|
|
}
|
|
|
|
|
2003-03-25 00:11:06 +00:00
|
|
|
static void
|
2003-10-23 00:26:15 +00:00
|
|
|
entry_activate (GtkEntry *entry,
|
|
|
|
GtkFileChooserDefault *impl)
|
2003-03-25 00:11:06 +00:00
|
|
|
{
|
|
|
|
GtkFileChooserEntry *chooser_entry = GTK_FILE_CHOOSER_ENTRY (entry);
|
2003-04-04 22:43:12 +00:00
|
|
|
const GtkFilePath *folder_path = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
|
2003-03-25 00:11:06 +00:00
|
|
|
const gchar *file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
|
2003-04-04 22:43:12 +00:00
|
|
|
GtkFilePath *new_folder = NULL;
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2004-01-20 02:44:58 +00:00
|
|
|
if (!folder_path)
|
|
|
|
return; /* The entry got a nonexistent path */
|
|
|
|
|
|
|
|
if (file_part[0] == '\0')
|
|
|
|
{
|
|
|
|
if (gtk_file_path_compare (impl->current_folder, folder_path) != 0)
|
|
|
|
new_folder = gtk_file_path_copy (folder_path);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2003-03-25 00:11:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkFileFolder *folder = NULL;
|
2003-04-04 22:43:12 +00:00
|
|
|
GtkFilePath *subfolder_path = NULL;
|
2003-03-25 00:11:06 +00:00
|
|
|
GtkFileInfo *info = NULL;
|
2003-11-04 01:56:56 +00:00
|
|
|
GError *error;
|
|
|
|
|
2004-01-20 02:44:58 +00:00
|
|
|
/* If the file part is non-empty, we need to figure out if it
|
|
|
|
* refers to a folder within folder. We could optimize the case
|
|
|
|
* here where the folder is already loaded for one of our tree models.
|
|
|
|
*/
|
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
error = NULL;
|
|
|
|
folder = gtk_file_system_get_folder (impl->file_system, folder_path, GTK_FILE_INFO_IS_FOLDER, &error);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
if (!folder)
|
|
|
|
{
|
|
|
|
error_getting_info_dialog (impl, folder_path, error);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
error = NULL;
|
|
|
|
subfolder_path = gtk_file_system_make_path (impl->file_system, folder_path, file_part, &error);
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
if (!subfolder_path)
|
|
|
|
{
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
msg = g_strdup_printf (_("Could not build file name from '%s' and '%s':\n%s"),
|
|
|
|
gtk_file_path_get_string (folder_path),
|
|
|
|
file_part,
|
|
|
|
error->message);
|
|
|
|
error_message (impl, msg);
|
|
|
|
g_free (msg);
|
|
|
|
g_object_unref (folder);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
error = NULL;
|
|
|
|
info = gtk_file_folder_get_info (folder, subfolder_path, &error);
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
if (!info)
|
|
|
|
{
|
2004-01-23 20:15:05 +00:00
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2003-12-08 23:38:57 +00:00
|
|
|
{
|
|
|
|
g_object_unref (folder);
|
|
|
|
gtk_file_path_free (subfolder_path);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-04 01:56:56 +00:00
|
|
|
error_getting_info_dialog (impl, subfolder_path, error);
|
|
|
|
g_object_unref (folder);
|
|
|
|
gtk_file_path_free (subfolder_path);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
if (gtk_file_info_get_is_folder (info))
|
|
|
|
new_folder = gtk_file_path_copy (subfolder_path);
|
2003-03-25 00:11:06 +00:00
|
|
|
|
2003-11-04 01:56:56 +00:00
|
|
|
g_object_unref (folder);
|
|
|
|
gtk_file_path_free (subfolder_path);
|
|
|
|
gtk_file_info_free (info);
|
2003-03-25 00:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (new_folder)
|
|
|
|
{
|
|
|
|
g_signal_stop_emission_by_name (entry, "activate");
|
|
|
|
|
2003-07-11 19:18:36 +00:00
|
|
|
_gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), new_folder);
|
2003-03-25 00:11:06 +00:00
|
|
|
_gtk_file_chooser_entry_set_file_part (chooser_entry, "");
|
|
|
|
|
2003-04-04 22:43:12 +00:00
|
|
|
gtk_file_path_free (new_folder);
|
2003-03-25 00:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-16 21:07:38 +00:00
|
|
|
static const GtkFileInfo *
|
2003-10-23 00:26:15 +00:00
|
|
|
get_list_file_info (GtkFileChooserDefault *impl,
|
|
|
|
GtkTreeIter *iter)
|
2003-03-21 23:59:22 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
|
|
|
|
&child_iter,
|
|
|
|
iter);
|
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
return _gtk_file_system_model_get_info (impl->list_model, &child_iter);
|
2003-03-21 23:59:22 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 21:26:38 +00:00
|
|
|
static void
|
2003-03-21 23:59:22 +00:00
|
|
|
tree_name_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = data;
|
2003-03-21 20:34:02 +00:00
|
|
|
const GtkFileInfo *info = _gtk_file_system_model_get_info (impl->tree_model, iter);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
g_object_set (cell,
|
|
|
|
"text", gtk_file_info_get_display_name (info),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-16 21:07:38 +00:00
|
|
|
static void
|
|
|
|
list_icon_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = data;
|
2003-11-19 17:03:32 +00:00
|
|
|
GtkTreeIter child_iter;
|
|
|
|
const GtkFilePath *path;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (impl->sort_model,
|
|
|
|
&child_iter,
|
|
|
|
iter);
|
|
|
|
path = _gtk_file_system_model_get_path (impl->list_model, &child_iter);
|
2004-01-17 04:34:49 +00:00
|
|
|
if (!path)
|
|
|
|
return;
|
2003-11-19 17:03:32 +00:00
|
|
|
|
|
|
|
/* FIXME: NULL GError */
|
|
|
|
pixbuf = gtk_file_system_render_icon (impl->file_system, path, GTK_WIDGET (impl), ICON_SIZE, NULL);
|
|
|
|
g_object_set (cell,
|
|
|
|
"pixbuf", pixbuf,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
2004-01-20 02:44:58 +00:00
|
|
|
|
2003-11-19 17:03:32 +00:00
|
|
|
#if 0
|
2003-07-16 21:07:38 +00:00
|
|
|
const GtkFileInfo *info = get_list_file_info (impl, iter);
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_TREE_VIEW_COLUMN (tree_column)->tree_view;
|
2003-10-01 00:53:59 +00:00
|
|
|
GdkPixbuf *pixbuf = gtk_file_info_render_icon (info, widget, ICON_SIZE);
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-07-16 21:07:38 +00:00
|
|
|
g_object_set (cell,
|
|
|
|
"pixbuf", pixbuf,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
2003-11-19 17:03:32 +00:00
|
|
|
#endif
|
2003-07-16 21:07:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
/* Sets a cellrenderer's text, making it bold if the GtkFileInfo is a folder */
|
|
|
|
static void
|
|
|
|
set_cell_text_bold_if_folder (const GtkFileInfo *info, GtkCellRenderer *cell, const char *text)
|
|
|
|
{
|
2003-09-10 01:26:13 +00:00
|
|
|
g_object_set (cell,
|
|
|
|
"text", text,
|
|
|
|
"weight", gtk_file_info_get_is_folder (info) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
|
|
|
|
NULL);
|
2003-09-09 17:50:23 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 23:59:22 +00:00
|
|
|
static void
|
|
|
|
list_name_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = data;
|
2003-03-21 23:59:22 +00:00
|
|
|
const GtkFileInfo *info = get_list_file_info (impl, iter);
|
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
if (!info)
|
2004-01-17 04:34:49 +00:00
|
|
|
{
|
|
|
|
g_object_set (cell,
|
|
|
|
"text", _("Type name of new folder"),
|
|
|
|
NULL);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-09 17:50:23 +00:00
|
|
|
|
|
|
|
set_cell_text_bold_if_folder (info, cell, gtk_file_info_get_display_name (info));
|
2003-03-21 23:59:22 +00:00
|
|
|
}
|
|
|
|
|
2003-09-09 15:18:29 +00:00
|
|
|
#if 0
|
2003-03-21 23:59:22 +00:00
|
|
|
static void
|
|
|
|
list_size_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl = data;
|
2003-03-21 23:59:22 +00:00
|
|
|
const GtkFileInfo *info = get_list_file_info (impl, iter);
|
2004-01-17 04:34:49 +00:00
|
|
|
gint64 size;
|
2003-09-09 17:50:23 +00:00
|
|
|
gchar *str;
|
2003-03-21 23:59:22 +00:00
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
if (!info || gtk_file_info_get_is_folder (info))
|
|
|
|
return;
|
2003-03-21 23:59:22 +00:00
|
|
|
|
2004-01-17 04:34:49 +00:00
|
|
|
size = gtk_file_info_get_size (info);
|
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
if (size < (gint64)1024)
|
2003-12-31 16:02:22 +00:00
|
|
|
str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
|
2003-09-09 17:50:23 +00:00
|
|
|
else if (size < (gint64)1024*1024)
|
2003-11-03 20:24:04 +00:00
|
|
|
str = g_strdup_printf (_("%.1f K"), size / (1024.));
|
2003-09-09 17:50:23 +00:00
|
|
|
else if (size < (gint64)1024*1024*1024)
|
2003-11-03 20:24:04 +00:00
|
|
|
str = g_strdup_printf (_("%.1f M"), size / (1024.*1024.));
|
2003-09-09 17:50:23 +00:00
|
|
|
else
|
2003-11-03 20:24:04 +00:00
|
|
|
str = g_strdup_printf (_("%.1f G"), size / (1024.*1024.*1024.));
|
2003-09-06 00:50:33 +00:00
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
g_object_set (cell,
|
|
|
|
"text", str,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (str);
|
2003-09-09 15:18:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Tree column data callback for the file list; fetches the mtime of a file */
|
|
|
|
static void
|
|
|
|
list_mtime_data_func (GtkTreeViewColumn *tree_column,
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
GtkFileChooserDefault *impl;
|
2003-09-09 15:18:29 +00:00
|
|
|
const GtkFileInfo *info;
|
2003-12-19 17:38:54 +00:00
|
|
|
GtkFileTime time_mtime, time_now;
|
|
|
|
GDate mtime, now;
|
|
|
|
int days_diff;
|
2003-09-09 15:18:29 +00:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
impl = data;
|
|
|
|
|
|
|
|
info = get_list_file_info (impl, iter);
|
|
|
|
if (!info)
|
2004-01-17 04:34:49 +00:00
|
|
|
{
|
|
|
|
g_object_set (cell,
|
|
|
|
"text", "",
|
|
|
|
NULL);
|
|
|
|
return;
|
|
|
|
}
|
2003-09-09 15:18:29 +00:00
|
|
|
|
2003-12-19 17:38:54 +00:00
|
|
|
time_mtime = gtk_file_info_get_modification_time (info);
|
|
|
|
g_date_set_time (&mtime, (GTime) time_mtime);
|
2003-09-09 15:18:29 +00:00
|
|
|
|
2003-12-19 17:38:54 +00:00
|
|
|
time_now = (GTime ) time (NULL);
|
|
|
|
g_date_set_time (&now, (GTime) time_now);
|
2003-09-09 15:18:29 +00:00
|
|
|
|
2003-12-19 17:38:54 +00:00
|
|
|
days_diff = g_date_get_julian (&now) - g_date_get_julian (&mtime);
|
|
|
|
|
|
|
|
if (days_diff == 0)
|
2003-11-03 20:24:04 +00:00
|
|
|
strcpy (buf, _("Today"));
|
2003-12-19 17:38:54 +00:00
|
|
|
else if (days_diff == 1)
|
|
|
|
strcpy (buf, _("Yesterday"));
|
2003-09-09 15:18:29 +00:00
|
|
|
else
|
|
|
|
{
|
2003-12-19 17:38:54 +00:00
|
|
|
char *format;
|
2003-09-09 15:18:29 +00:00
|
|
|
|
2003-12-19 17:38:54 +00:00
|
|
|
if (days_diff > 1 && days_diff < 7)
|
|
|
|
format = "%A"; /* Days from last week */
|
|
|
|
else
|
|
|
|
format = _("%d/%b/%Y"); /* Any other date */
|
2003-09-09 15:18:29 +00:00
|
|
|
|
2003-12-19 17:38:54 +00:00
|
|
|
if (g_date_strftime (buf, sizeof (buf), format, &mtime) == 0)
|
|
|
|
strcpy (buf, _("Unknown"));
|
2003-09-09 15:18:29 +00:00
|
|
|
}
|
2003-03-21 23:59:22 +00:00
|
|
|
|
2003-09-09 17:50:23 +00:00
|
|
|
set_cell_text_bold_if_folder (info, cell, buf);
|
2003-03-21 23:59:22 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
GtkWidget *
|
2003-10-23 00:26:15 +00:00
|
|
|
_gtk_file_chooser_default_new (GtkFileSystem *file_system)
|
2003-03-21 20:34:02 +00:00
|
|
|
{
|
2003-10-23 00:26:15 +00:00
|
|
|
return g_object_new (GTK_TYPE_FILE_CHOOSER_DEFAULT,
|
2003-03-26 17:09:26 +00:00
|
|
|
"file-system", file_system,
|
|
|
|
NULL);
|
2003-03-21 20:34:02 +00:00
|
|
|
}
|