2014-01-28 09:30:33 +00:00
|
|
|
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
|
2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2003-03-21 20:34:02 +00:00
|
|
|
|
* gtkfilechooserwidget.c: Embeddable file selector widget
|
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-03-21 20:34:02 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2006-05-02 23:56:43 +00:00
|
|
|
|
|
2003-03-21 20:34:02 +00:00
|
|
|
|
#include "gtkfilechooserwidget.h"
|
2015-06-27 04:07:59 +00:00
|
|
|
|
#include "gtkfilechooserwidgetprivate.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-09-10 11:11:03 +00:00
|
|
|
|
#include "gtkbookmarksmanagerprivate.h"
|
2015-01-28 15:35:49 +00:00
|
|
|
|
#include "gtkbutton.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
|
|
|
|
#include "gtkcellrenderertext.h"
|
2019-12-22 01:12:11 +00:00
|
|
|
|
#include "gtkdropdown.h"
|
2016-09-30 03:14:53 +00:00
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
|
#include "gtkdragsource.h"
|
2020-02-29 02:47:17 +00:00
|
|
|
|
#include "gtkdroptarget.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include "gtkentry.h"
|
|
|
|
|
#include "gtkfilechooserprivate.h"
|
|
|
|
|
#include "gtkfilechooserdialog.h"
|
|
|
|
|
#include "gtkfilechooserentry.h"
|
|
|
|
|
#include "gtkfilechooserutils.h"
|
|
|
|
|
#include "gtkfilechooser.h"
|
|
|
|
|
#include "gtkfilesystemmodel.h"
|
|
|
|
|
#include "gtkgrid.h"
|
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
#include "gtkmessagedialog.h"
|
|
|
|
|
#include "gtkmountoperation.h"
|
|
|
|
|
#include "gtkpaned.h"
|
|
|
|
|
#include "gtkpathbar.h"
|
2015-06-27 01:14:37 +00:00
|
|
|
|
#include "gtkplacessidebarprivate.h"
|
2015-07-14 17:48:49 +00:00
|
|
|
|
#include "gtkplacesviewprivate.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
|
#include "gtkrecentmanager.h"
|
2019-04-05 03:34:42 +00:00
|
|
|
|
#include "gtksearchentryprivate.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include "gtksettings.h"
|
|
|
|
|
#include "gtksizegroup.h"
|
|
|
|
|
#include "gtksizerequest.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
|
#include "gtkstack.h"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include "gtktooltip.h"
|
|
|
|
|
#include "gtktreednd.h"
|
|
|
|
|
#include "gtktreeprivate.h"
|
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
|
#include "gtkbox.h"
|
2016-07-06 02:11:44 +00:00
|
|
|
|
#include "gtkcheckbutton.h"
|
2014-06-04 10:18:03 +00:00
|
|
|
|
#include "gtkwindowgroup.h"
|
2005-09-01 05:11:46 +00:00
|
|
|
|
#include "gtkintl.h"
|
2015-02-12 04:34:04 +00:00
|
|
|
|
#include "gtkshow.h"
|
|
|
|
|
#include "gtkmain.h"
|
2015-03-02 21:22:56 +00:00
|
|
|
|
#include "gtkscrollable.h"
|
2016-09-30 03:14:53 +00:00
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2015-04-17 04:14:28 +00:00
|
|
|
|
#include "gtkpopover.h"
|
2015-06-17 03:46:34 +00:00
|
|
|
|
#include "gtkrevealer.h"
|
2015-07-03 06:08:59 +00:00
|
|
|
|
#include "gtkspinner.h"
|
2015-07-16 14:45:14 +00:00
|
|
|
|
#include "gtkseparator.h"
|
2019-11-11 10:58:43 +00:00
|
|
|
|
#include "gtkmodelbuttonprivate.h"
|
2015-07-16 14:45:14 +00:00
|
|
|
|
#include "gtkgesturelongpress.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
|
#include "gtkgestureclick.h"
|
2018-01-25 07:27:43 +00:00
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2015-07-31 11:03:25 +00:00
|
|
|
|
#include "gtkdebug.h"
|
2017-05-09 07:52:00 +00:00
|
|
|
|
#include "gtkfilechoosererrorstackprivate.h"
|
2018-06-08 17:05:28 +00:00
|
|
|
|
#include "gtkentryprivate.h"
|
2019-03-02 13:49:00 +00:00
|
|
|
|
#include "gtkroot.h"
|
2019-04-29 09:21:53 +00:00
|
|
|
|
#include "gtkbinlayout.h"
|
2020-01-27 14:10:47 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
2020-02-19 08:12:12 +00:00
|
|
|
|
#include "gtkpopovermenuprivate.h"
|
2020-03-22 00:00:15 +00:00
|
|
|
|
#include "gtknative.h"
|
2020-03-19 04:07:45 +00:00
|
|
|
|
#include "gtkshortcutcontroller.h"
|
|
|
|
|
#include "gtkshortcuttrigger.h"
|
|
|
|
|
#include "gtkshortcutaction.h"
|
|
|
|
|
#include "gtkshortcut.h"
|
2020-07-12 14:20:52 +00:00
|
|
|
|
#include "gtkstringlist.h"
|
2003-12-16 22:58:58 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#include <cairo-gobject.h>
|
2011-04-11 02:09:38 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-02-20 00:36:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkfilechooserwidget
|
2014-05-20 02:47:59 +00:00
|
|
|
|
* @Short_description: A file chooser widget
|
2014-02-20 00:36:55 +00:00
|
|
|
|
* @Title: GtkFileChooserWidget
|
|
|
|
|
* @See_also: #GtkFileChooserDialog
|
|
|
|
|
*
|
|
|
|
|
* #GtkFileChooserWidget is a widget for choosing files.
|
|
|
|
|
* It exposes the #GtkFileChooser interface, and you should
|
|
|
|
|
* use the methods of this interface to interact with the
|
|
|
|
|
* widget.
|
2016-01-14 04:35:22 +00:00
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* GtkFileChooserWidget has a single CSS node with name filechooser.
|
2014-02-20 00:36:55 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2014-02-28 20:19:00 +00:00
|
|
|
|
/* 150 mseconds of delay */
|
|
|
|
|
#define LOCATION_CHANGED_TIMEOUT 150
|
|
|
|
|
|
2015-01-28 20:00:08 +00:00
|
|
|
|
enum {
|
2015-06-27 01:14:37 +00:00
|
|
|
|
PROP_SEARCH_MODE = 1,
|
|
|
|
|
PROP_SUBTITLE
|
2015-01-28 20:00:08 +00:00
|
|
|
|
};
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
typedef enum {
|
2015-07-04 00:53:54 +00:00
|
|
|
|
LOAD_EMPTY, /* There is no model */
|
|
|
|
|
LOAD_PRELOAD, /* Model is loading and a timer is running; model isn't inserted into the tree yet */
|
|
|
|
|
LOAD_LOADING, /* Timeout expired, model is inserted into the tree, but not fully loaded yet */
|
|
|
|
|
LOAD_FINISHED /* Model is fully loaded and inserted into the tree */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
} LoadState;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
2015-07-04 00:53:54 +00:00
|
|
|
|
RELOAD_EMPTY, /* No folder has been set */
|
|
|
|
|
RELOAD_HAS_FOLDER /* We have a folder, although it may not be completely loaded yet; no need to reload */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
} ReloadState;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
LOCATION_MODE_PATH_BAR,
|
|
|
|
|
LOCATION_MODE_FILENAME_ENTRY
|
|
|
|
|
} LocationMode;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
OPERATION_MODE_BROWSE,
|
|
|
|
|
OPERATION_MODE_SEARCH,
|
2014-04-09 17:49:54 +00:00
|
|
|
|
OPERATION_MODE_ENTER_LOCATION,
|
2015-07-14 17:48:49 +00:00
|
|
|
|
OPERATION_MODE_OTHER_LOCATIONS,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
OPERATION_MODE_RECENT
|
|
|
|
|
} OperationMode;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
STARTUP_MODE_RECENT,
|
|
|
|
|
STARTUP_MODE_CWD
|
|
|
|
|
} StartupMode;
|
|
|
|
|
|
2015-07-02 21:47:30 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
CLOCK_FORMAT_24,
|
|
|
|
|
CLOCK_FORMAT_12
|
|
|
|
|
} ClockFormat;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
DATE_FORMAT_REGULAR,
|
|
|
|
|
DATE_FORMAT_WITH_TIME
|
|
|
|
|
} DateFormat;
|
|
|
|
|
|
2019-06-06 23:02:11 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
TYPE_FORMAT_MIME,
|
|
|
|
|
TYPE_FORMAT_DESCRIPTION,
|
|
|
|
|
TYPE_FORMAT_CATEGORY
|
|
|
|
|
} TypeFormat;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
typedef struct _GtkFileChooserWidgetClass GtkFileChooserWidgetClass;
|
|
|
|
|
|
|
|
|
|
struct _GtkFileChooserWidget
|
|
|
|
|
{
|
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkFileChooserAction action;
|
|
|
|
|
|
2017-03-25 19:36:10 +00:00
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
2019-06-15 22:24:26 +00:00
|
|
|
|
GActionGroup *item_actions;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Save mode widgets */
|
|
|
|
|
GtkWidget *save_widgets;
|
|
|
|
|
GtkWidget *save_widgets_table;
|
|
|
|
|
|
|
|
|
|
/* The file browsing widgets */
|
|
|
|
|
GtkWidget *browse_widgets_hpaned;
|
2015-06-17 03:46:34 +00:00
|
|
|
|
GtkWidget *browse_header_revealer;
|
2014-04-08 17:13:01 +00:00
|
|
|
|
GtkWidget *browse_header_stack;
|
2015-05-02 03:04:35 +00:00
|
|
|
|
GtkWidget *browse_files_stack;
|
2015-07-14 17:48:49 +00:00
|
|
|
|
GtkWidget *browse_files_swin;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkWidget *browse_files_tree_view;
|
2015-07-24 20:26:32 +00:00
|
|
|
|
GtkWidget *remote_warning_bar;
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget *browse_files_popover;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkWidget *browse_new_folder_button;
|
|
|
|
|
GtkSizeGroup *browse_path_bar_size_group;
|
|
|
|
|
GtkWidget *browse_path_bar;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
GtkWidget *new_folder_name_entry;
|
|
|
|
|
GtkWidget *new_folder_create_button;
|
2017-05-09 07:52:00 +00:00
|
|
|
|
GtkWidget *new_folder_error_stack;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
GtkWidget *new_folder_popover;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
GtkWidget *rename_file_name_entry;
|
|
|
|
|
GtkWidget *rename_file_rename_button;
|
2017-05-09 07:52:00 +00:00
|
|
|
|
GtkWidget *rename_file_error_stack;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
GtkWidget *rename_file_popover;
|
|
|
|
|
GFile *rename_file_source_file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
GtkFileSystemModel *browse_files_model;
|
|
|
|
|
char *browse_files_last_selected_name;
|
|
|
|
|
|
|
|
|
|
GtkWidget *places_sidebar;
|
2015-07-14 17:48:49 +00:00
|
|
|
|
GtkWidget *places_view;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
StartupMode startup_mode;
|
|
|
|
|
|
|
|
|
|
/* OPERATION_MODE_SEARCH */
|
|
|
|
|
GtkWidget *search_entry;
|
2015-07-03 06:08:59 +00:00
|
|
|
|
GtkWidget *search_spinner;
|
|
|
|
|
guint show_progress_timeout;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkSearchEngine *search_engine;
|
|
|
|
|
GtkQuery *search_query;
|
|
|
|
|
GtkFileSystemModel *search_model;
|
2015-07-01 19:51:20 +00:00
|
|
|
|
GtkFileSystemModel *model_for_search;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* OPERATION_MODE_RECENT */
|
|
|
|
|
GtkRecentManager *recent_manager;
|
|
|
|
|
GtkFileSystemModel *recent_model;
|
|
|
|
|
|
2014-05-24 04:00:00 +00:00
|
|
|
|
GtkWidget *extra_and_filters;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkWidget *filter_combo_hbox;
|
|
|
|
|
GtkWidget *filter_combo;
|
|
|
|
|
GtkWidget *extra_align;
|
|
|
|
|
GtkWidget *extra_widget;
|
|
|
|
|
|
|
|
|
|
GtkWidget *location_entry_box;
|
|
|
|
|
GtkWidget *location_entry;
|
|
|
|
|
LocationMode location_mode;
|
|
|
|
|
|
2015-06-27 04:07:59 +00:00
|
|
|
|
GtkWidget *external_entry;
|
|
|
|
|
|
2016-07-06 02:11:44 +00:00
|
|
|
|
GtkWidget *choice_box;
|
|
|
|
|
GHashTable *choices;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Handles */
|
|
|
|
|
GCancellable *file_list_drag_data_received_cancellable;
|
|
|
|
|
GCancellable *update_current_folder_cancellable;
|
|
|
|
|
GCancellable *should_respond_get_info_cancellable;
|
|
|
|
|
GCancellable *file_exists_get_info_cancellable;
|
|
|
|
|
|
|
|
|
|
LoadState load_state;
|
|
|
|
|
ReloadState reload_state;
|
|
|
|
|
guint load_timeout_id;
|
|
|
|
|
|
|
|
|
|
OperationMode operation_mode;
|
|
|
|
|
|
|
|
|
|
GSList *pending_select_files;
|
|
|
|
|
|
|
|
|
|
GtkFileFilter *current_filter;
|
2019-12-22 01:12:11 +00:00
|
|
|
|
GListStore *filters;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
GtkBookmarksManager *bookmarks_manager;
|
|
|
|
|
|
|
|
|
|
GFile *current_folder;
|
2019-08-12 21:32:56 +00:00
|
|
|
|
GFile *renamed_file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
GtkTreeViewColumn *list_name_column;
|
|
|
|
|
GtkCellRenderer *list_name_renderer;
|
|
|
|
|
GtkCellRenderer *list_pixbuf_renderer;
|
2015-07-01 21:04:17 +00:00
|
|
|
|
GtkTreeViewColumn *list_time_column;
|
2015-07-02 09:37:59 +00:00
|
|
|
|
GtkCellRenderer *list_date_renderer;
|
2015-07-01 21:04:17 +00:00
|
|
|
|
GtkCellRenderer *list_time_renderer;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeViewColumn *list_size_column;
|
2015-07-01 21:04:17 +00:00
|
|
|
|
GtkCellRenderer *list_size_renderer;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
GtkTreeViewColumn *list_type_column;
|
|
|
|
|
GtkCellRenderer *list_type_renderer;
|
2015-02-14 04:50:06 +00:00
|
|
|
|
GtkTreeViewColumn *list_location_column;
|
2015-07-01 21:04:17 +00:00
|
|
|
|
GtkCellRenderer *list_location_renderer;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2014-02-28 20:19:00 +00:00
|
|
|
|
guint location_changed_id;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gulong settings_signal_id;
|
|
|
|
|
|
|
|
|
|
GSource *focus_entry_idle;
|
|
|
|
|
|
|
|
|
|
gulong toplevel_set_focus_id;
|
2019-03-03 13:06:53 +00:00
|
|
|
|
GtkWidget *toplevel_current_focus_widget;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkWidget *toplevel_last_focus_widget;
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkSortType sort_order;
|
|
|
|
|
|
2019-04-30 04:43:42 +00:00
|
|
|
|
ClockFormat clock_format;
|
|
|
|
|
|
2019-06-06 23:02:11 +00:00
|
|
|
|
TypeFormat type_format;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Flags */
|
|
|
|
|
|
|
|
|
|
guint select_multiple : 1;
|
|
|
|
|
guint show_hidden : 1;
|
|
|
|
|
guint sort_directories_first : 1;
|
2015-07-02 17:44:19 +00:00
|
|
|
|
guint show_time : 1;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
guint list_sort_ascending : 1;
|
|
|
|
|
guint shortcuts_current_folder_active : 1;
|
|
|
|
|
guint show_size_column : 1;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
guint show_type_column : 1;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
guint create_folders : 1;
|
|
|
|
|
guint auto_selecting_first_row : 1;
|
2019-04-28 15:17:32 +00:00
|
|
|
|
guint starting_search : 1;
|
2020-04-14 20:01:12 +00:00
|
|
|
|
guint browse_files_interaction_frozen : 1;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
struct _GtkFileChooserWidgetClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#define MAX_LOADING_TIME 500
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_NEW_FOLDER_NAME _("Type name of new folder")
|
|
|
|
|
|
|
|
|
|
/* Signal IDs */
|
|
|
|
|
enum {
|
|
|
|
|
LOCATION_POPUP,
|
|
|
|
|
LOCATION_POPUP_ON_PASTE,
|
|
|
|
|
UP_FOLDER,
|
|
|
|
|
DOWN_FOLDER,
|
|
|
|
|
HOME_FOLDER,
|
|
|
|
|
DESKTOP_FOLDER,
|
|
|
|
|
QUICK_BOOKMARK,
|
|
|
|
|
LOCATION_TOGGLE_POPUP,
|
|
|
|
|
SHOW_HIDDEN,
|
|
|
|
|
SEARCH_SHORTCUT,
|
|
|
|
|
RECENT_SHORTCUT,
|
2015-07-07 04:24:19 +00:00
|
|
|
|
PLACES_SHORTCUT,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
#define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \
|
|
|
|
|
"standard::is-hidden,standard::is-backup,standard::size," \
|
2020-02-28 15:59:19 +00:00
|
|
|
|
"standard::content-type,standard::fast-content-type,time::modified,time::access," \
|
2015-07-07 02:57:40 +00:00
|
|
|
|
"access::can-rename,access::can-delete,access::can-trash," \
|
|
|
|
|
"standard::target-uri"
|
2014-01-28 09:30:33 +00:00
|
|
|
|
enum {
|
2019-06-06 23:02:11 +00:00
|
|
|
|
/* the first 4 must be these due to settings caching sort column */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
MODEL_COL_NAME,
|
|
|
|
|
MODEL_COL_SIZE,
|
2019-06-06 23:02:11 +00:00
|
|
|
|
MODEL_COL_TYPE,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
MODEL_COL_TIME,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
MODEL_COL_FILE,
|
|
|
|
|
MODEL_COL_NAME_COLLATED,
|
|
|
|
|
MODEL_COL_IS_FOLDER,
|
|
|
|
|
MODEL_COL_IS_SENSITIVE,
|
2017-11-09 02:52:50 +00:00
|
|
|
|
MODEL_COL_ICON,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
MODEL_COL_SIZE_TEXT,
|
2015-07-02 09:37:59 +00:00
|
|
|
|
MODEL_COL_DATE_TEXT,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
MODEL_COL_TIME_TEXT,
|
2015-02-14 04:50:06 +00:00
|
|
|
|
MODEL_COL_LOCATION_TEXT,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
MODEL_COL_ELLIPSIZE,
|
|
|
|
|
MODEL_COL_NUM_COLUMNS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This list of types is passed to _gtk_file_system_model_new*() */
|
2015-07-04 00:53:54 +00:00
|
|
|
|
#define MODEL_COLUMN_TYPES \
|
|
|
|
|
MODEL_COL_NUM_COLUMNS, \
|
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_NAME */ \
|
|
|
|
|
G_TYPE_INT64, /* MODEL_COL_SIZE */ \
|
2019-06-06 23:02:11 +00:00
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_TYPE */ \
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_TYPE_LONG, /* MODEL_COL_TIME */ \
|
|
|
|
|
G_TYPE_FILE, /* MODEL_COL_FILE */ \
|
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_NAME_COLLATED */ \
|
|
|
|
|
G_TYPE_BOOLEAN, /* MODEL_COL_IS_FOLDER */ \
|
|
|
|
|
G_TYPE_BOOLEAN, /* MODEL_COL_IS_SENSITIVE */ \
|
2017-11-09 02:52:50 +00:00
|
|
|
|
G_TYPE_ICON, /* MODEL_COL_ICON */ \
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_SIZE_TEXT */ \
|
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_DATE_TEXT */ \
|
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_TIME_TEXT */ \
|
|
|
|
|
G_TYPE_STRING, /* MODEL_COL_LOCATION_TEXT */ \
|
|
|
|
|
PANGO_TYPE_ELLIPSIZE_MODE /* MODEL_COL_ELLIPSIZE */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
#define DEFAULT_RECENT_FILES_LIMIT 50
|
|
|
|
|
|
2017-11-15 00:48:59 +00:00
|
|
|
|
#define ICON_SIZE 16
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface);
|
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void gtk_file_chooser_widget_constructed (GObject *object);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void gtk_file_chooser_widget_finalize (GObject *object);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
static void gtk_file_chooser_widget_set_property (GObject *object,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
static void gtk_file_chooser_widget_get_property (GObject *object,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void gtk_file_chooser_widget_dispose (GObject *object);
|
|
|
|
|
static void gtk_file_chooser_widget_map (GtkWidget *widget);
|
|
|
|
|
static void gtk_file_chooser_widget_unmap (GtkWidget *widget);
|
2019-02-23 06:02:25 +00:00
|
|
|
|
static void gtk_file_chooser_widget_root (GtkWidget *widget);
|
|
|
|
|
static void gtk_file_chooser_widget_unroot (GtkWidget *widget);
|
2020-02-05 01:46:13 +00:00
|
|
|
|
static void gtk_file_chooser_widget_css_changed (GtkWidget *widget,
|
|
|
|
|
GtkCssStyleChange *change);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
static gboolean gtk_file_chooser_widget_set_current_folder (GtkFileChooser *chooser,
|
|
|
|
|
GFile *folder,
|
|
|
|
|
GError **error);
|
|
|
|
|
static gboolean gtk_file_chooser_widget_update_current_folder (GtkFileChooser *chooser,
|
|
|
|
|
GFile *folder,
|
|
|
|
|
gboolean keep_trail,
|
|
|
|
|
gboolean clear_entry,
|
|
|
|
|
GError **error);
|
|
|
|
|
static GFile * gtk_file_chooser_widget_get_current_folder (GtkFileChooser *chooser);
|
|
|
|
|
static void gtk_file_chooser_widget_set_current_name (GtkFileChooser *chooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name);
|
|
|
|
|
static char * gtk_file_chooser_widget_get_current_name (GtkFileChooser *chooser);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
static gboolean gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error);
|
|
|
|
|
static void gtk_file_chooser_widget_unselect_file (GtkFileChooser *chooser,
|
|
|
|
|
GFile *file);
|
|
|
|
|
static void gtk_file_chooser_widget_select_all (GtkFileChooser *chooser);
|
|
|
|
|
static void gtk_file_chooser_widget_unselect_all (GtkFileChooser *chooser);
|
2020-07-09 05:29:20 +00:00
|
|
|
|
static GListModel * gtk_file_chooser_widget_get_files (GtkFileChooser *chooser);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
static void gtk_file_chooser_widget_add_filter (GtkFileChooser *chooser,
|
|
|
|
|
GtkFileFilter *filter);
|
|
|
|
|
static void gtk_file_chooser_widget_remove_filter (GtkFileChooser *chooser,
|
|
|
|
|
GtkFileFilter *filter);
|
2020-07-04 16:15:47 +00:00
|
|
|
|
static GListModel * gtk_file_chooser_widget_get_filters (GtkFileChooser *chooser);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static gboolean gtk_file_chooser_widget_add_shortcut_folder (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static gboolean gtk_file_chooser_widget_remove_shortcut_folder (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error);
|
2020-07-05 02:08:33 +00:00
|
|
|
|
static GListModel * gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2016-07-06 02:11:44 +00:00
|
|
|
|
static void gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id,
|
|
|
|
|
const char *label,
|
|
|
|
|
const char **options,
|
|
|
|
|
const char **option_labels);
|
|
|
|
|
static void gtk_file_chooser_widget_remove_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id);
|
|
|
|
|
static void gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id,
|
|
|
|
|
const char *option);
|
|
|
|
|
static const char *gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id);
|
|
|
|
|
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void add_selection_to_recent_list (GtkFileChooserWidget *impl);
|
|
|
|
|
|
|
|
|
|
static void location_popup_handler (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *path);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void location_popup_on_paste_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void location_toggle_popup_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void up_folder_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void down_folder_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void home_folder_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void desktop_folder_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void quick_bookmark_handler (GtkFileChooserWidget *impl,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int bookmark_index);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void show_hidden_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void search_shortcut_handler (GtkFileChooserWidget *impl);
|
|
|
|
|
static void recent_shortcut_handler (GtkFileChooserWidget *impl);
|
2015-07-07 04:24:19 +00:00
|
|
|
|
static void places_shortcut_handler (GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void update_appearance (GtkFileChooserWidget *impl);
|
2019-05-02 00:08:49 +00:00
|
|
|
|
static void check_icon_theme (GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void operation_mode_set (GtkFileChooserWidget *impl, OperationMode mode);
|
2014-04-08 17:13:01 +00:00
|
|
|
|
static void location_mode_set (GtkFileChooserWidget *impl, LocationMode new_mode);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void set_current_filter (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileFilter *filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
static void filter_combo_changed (GtkDropDown *dropdown,
|
|
|
|
|
GParamSpec *pspec,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static gboolean list_select_func (GtkTreeSelection *selection,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean path_currently_selected,
|
|
|
|
|
gpointer data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void list_selection_changed (GtkTreeSelection *tree_selection,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void list_row_activated (GtkTreeView *tree_view,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
|
GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void path_bar_clicked (GtkPathBar *path_bar,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *child,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean child_is_hidden,
|
|
|
|
|
GtkFileChooserWidget *impl);
|
|
|
|
|
|
|
|
|
|
static void update_cell_renderer_attributes (GtkFileChooserWidget *impl);
|
|
|
|
|
|
|
|
|
|
static void load_remove_timer (GtkFileChooserWidget *impl, LoadState new_load_state);
|
|
|
|
|
static void browse_files_center_selected_row (GtkFileChooserWidget *impl);
|
|
|
|
|
|
|
|
|
|
static void location_switch_to_path_bar (GtkFileChooserWidget *impl);
|
|
|
|
|
|
|
|
|
|
static void stop_loading_and_clear_list_model (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean remove_from_treeview);
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
static GSList *get_selected_files (GtkFileChooserWidget *impl);
|
|
|
|
|
static GSList *get_selected_infos (GtkFileChooserWidget *impl);
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void search_setup_widgets (GtkFileChooserWidget *impl);
|
|
|
|
|
static void search_stop_searching (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean remove_query);
|
|
|
|
|
static void search_clear_model (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean remove_from_treeview);
|
2015-01-28 21:02:03 +00:00
|
|
|
|
static void search_entry_activate_cb (GtkFileChooserWidget *impl);
|
2015-01-28 21:06:02 +00:00
|
|
|
|
static void search_entry_stop_cb (GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void settings_load (GtkFileChooserWidget *impl);
|
|
|
|
|
|
2015-01-09 15:31:08 +00:00
|
|
|
|
static void show_filters (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean show);
|
|
|
|
|
|
2015-07-01 15:40:15 +00:00
|
|
|
|
static gboolean recent_files_setting_is_enabled (GtkFileChooserWidget *impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void recent_start_loading (GtkFileChooserWidget *impl);
|
|
|
|
|
static void recent_clear_model (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean remove_from_treeview);
|
|
|
|
|
static gboolean recent_should_respond (GtkFileChooserWidget *impl);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
static void clear_model_cache (GtkFileChooserWidget *impl,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int column);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
static void set_model_filter (GtkFileChooserWidget *impl,
|
|
|
|
|
GtkFileFilter *filter);
|
2016-02-16 03:06:17 +00:00
|
|
|
|
static void switch_to_home_dir (GtkFileChooserWidget *impl);
|
2020-02-26 10:06:22 +00:00
|
|
|
|
static void set_show_hidden (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean show_hidden);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2003-03-26 17:09:26 +00:00
|
|
|
|
|
2017-03-25 19:36:10 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_WIDGET,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
|
2020-07-12 14:34:27 +00:00
|
|
|
|
gtk_file_chooser_widget_iface_init))
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2014-01-28 09:30:33 +00:00
|
|
|
|
iface->select_file = gtk_file_chooser_widget_select_file;
|
|
|
|
|
iface->unselect_file = gtk_file_chooser_widget_unselect_file;
|
|
|
|
|
iface->select_all = gtk_file_chooser_widget_select_all;
|
|
|
|
|
iface->unselect_all = gtk_file_chooser_widget_unselect_all;
|
|
|
|
|
iface->get_files = gtk_file_chooser_widget_get_files;
|
|
|
|
|
iface->set_current_folder = gtk_file_chooser_widget_set_current_folder;
|
|
|
|
|
iface->get_current_folder = gtk_file_chooser_widget_get_current_folder;
|
|
|
|
|
iface->set_current_name = gtk_file_chooser_widget_set_current_name;
|
|
|
|
|
iface->get_current_name = gtk_file_chooser_widget_get_current_name;
|
|
|
|
|
iface->add_filter = gtk_file_chooser_widget_add_filter;
|
|
|
|
|
iface->remove_filter = gtk_file_chooser_widget_remove_filter;
|
2020-07-04 16:15:47 +00:00
|
|
|
|
iface->get_filters = gtk_file_chooser_widget_get_filters;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
iface->add_shortcut_folder = gtk_file_chooser_widget_add_shortcut_folder;
|
|
|
|
|
iface->remove_shortcut_folder = gtk_file_chooser_widget_remove_shortcut_folder;
|
2020-07-05 02:08:33 +00:00
|
|
|
|
iface->get_shortcut_folders = gtk_file_chooser_widget_get_shortcut_folders;
|
2016-07-06 02:11:44 +00:00
|
|
|
|
iface->add_choice = gtk_file_chooser_widget_add_choice;
|
|
|
|
|
iface->remove_choice = gtk_file_chooser_widget_remove_choice;
|
|
|
|
|
iface->set_choice = gtk_file_chooser_widget_set_choice;
|
|
|
|
|
iface->get_choice = gtk_file_chooser_widget_get_choice;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
pending_select_files_free (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_slist_free_full (impl->pending_select_files, g_object_unref);
|
|
|
|
|
impl->pending_select_files = NULL;
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-01-28 09:30:33 +00:00
|
|
|
|
pending_select_files_add (GtkFileChooserWidget *impl,
|
2019-05-28 03:02:33 +00:00
|
|
|
|
GFile *file)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->pending_select_files =
|
|
|
|
|
g_slist_prepend (impl->pending_select_files, g_object_ref (file));
|
2003-03-26 17:09:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_finalize (GObject *object)
|
2003-03-26 17:09:26 +00:00
|
|
|
|
{
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (object);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->item_actions);
|
2019-06-15 22:24:26 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_pointer (&impl->choices, g_hash_table_unref);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_changed_id > 0)
|
|
|
|
|
g_source_remove (impl->location_changed_id);
|
2014-02-28 20:19:00 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_free (impl->browse_files_last_selected_name);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
g_clear_object (&impl->filters);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->current_filter);
|
|
|
|
|
g_clear_object (&impl->current_folder);
|
|
|
|
|
g_clear_object (&impl->browse_path_bar_size_group);
|
|
|
|
|
g_clear_object (&impl->renamed_file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Free all the Models we have */
|
|
|
|
|
stop_loading_and_clear_list_model (impl, FALSE);
|
|
|
|
|
search_clear_model (impl, FALSE);
|
|
|
|
|
recent_clear_model (impl, FALSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->model_for_search);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* stopping the load above should have cleared this */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_timeout_id == 0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 09:15:19 +00:00
|
|
|
|
/* Returns a toplevel GtkWindow, or NULL if none */
|
|
|
|
|
static GtkWindow *
|
|
|
|
|
get_toplevel (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2019-05-20 03:31:03 +00:00
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
2019-04-29 09:15:19 +00:00
|
|
|
|
return GTK_WINDOW (toplevel);
|
2019-05-20 03:31:03 +00:00
|
|
|
|
else
|
|
|
|
|
return NULL;
|
2019-04-29 09:15:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 05:13:25 +00:00
|
|
|
|
/* Extracts the parent folders out of the supplied list of GtkRecentInfo* items, and returns
|
|
|
|
|
* a list of GFile* for those unique parents.
|
|
|
|
|
*/
|
|
|
|
|
static GList *
|
|
|
|
|
_gtk_file_chooser_extract_recent_folders (GList *infos)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
GList *result;
|
|
|
|
|
GHashTable *folders;
|
|
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
|
|
folders = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
|
|
|
|
|
|
|
|
|
|
for (l = infos; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info = l->data;
|
|
|
|
|
const char *uri;
|
|
|
|
|
GFile *parent;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
uri = gtk_recent_info_get_uri (info);
|
|
|
|
|
|
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
parent = g_file_get_parent (file);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
|
{
|
|
|
|
|
if (!g_hash_table_lookup (folders, parent))
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_insert (folders, parent, (gpointer) 1);
|
|
|
|
|
result = g_list_prepend (result, g_object_ref (parent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = g_list_reverse (result);
|
|
|
|
|
|
|
|
|
|
g_hash_table_destroy (folders);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 09:15:19 +00:00
|
|
|
|
/* Shows an error dialog for the file chooser */
|
2003-03-21 20:34:02 +00:00
|
|
|
|
static void
|
2019-04-29 09:15:19 +00:00
|
|
|
|
error_message (GtkFileChooserWidget *impl,
|
|
|
|
|
const char *msg,
|
|
|
|
|
const char *detail)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2019-04-29 09:15:19 +00:00
|
|
|
|
GtkWindow *parent = get_toplevel (GTK_WIDGET (impl));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkWidget *dialog;
|
2003-03-26 17:09:26 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
dialog = gtk_message_dialog_new (parent,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
|
"%s",
|
|
|
|
|
msg);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"%s", detail);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (parent && gtk_window_has_group (parent))
|
|
|
|
|
gtk_window_group_add_window (gtk_window_get_group (parent),
|
|
|
|
|
GTK_WINDOW (dialog));
|
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
|
G_CALLBACK (gtk_window_destroy),
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows a simple error dialog relative to a path. Frees the GError as well. */
|
|
|
|
|
static void
|
|
|
|
|
error_dialog (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
const char *msg,
|
|
|
|
|
GError *error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (error)
|
2003-03-26 17:09:26 +00:00
|
|
|
|
{
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_message (impl, msg, error->message);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_error_free (error);
|
2003-03-26 17:09:26 +00:00
|
|
|
|
}
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Shows an error dialog about not being able to create a folder */
|
2003-03-21 20:34:02 +00:00
|
|
|
|
static void
|
2014-01-28 09:30:33 +00:00
|
|
|
|
error_creating_folder_dialog (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError *error)
|
2003-03-21 20:34:02 +00:00
|
|
|
|
{
|
2014-01-28 09:30:33 +00:00
|
|
|
|
error_dialog (impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
_("The folder could not be created"),
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
error_with_file_under_nonfolder (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *parent_file)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GError *error;
|
2016-04-04 12:32:56 +00:00
|
|
|
|
char *uri, *msg;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
_("You need to choose a valid filename."));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2016-04-04 12:32:56 +00:00
|
|
|
|
uri = g_file_get_uri (parent_file);
|
|
|
|
|
msg = g_strdup_printf (_("Cannot create a file under %s as it is not a folder"), uri);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
error_dialog (impl, msg, error);
|
|
|
|
|
g_free (msg);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
error_filename_to_long_dialog (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
error_message (impl,
|
|
|
|
|
_("Cannot create file as the filename is too long"),
|
|
|
|
|
_("Try using a shorter name."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an error about not being able to select a folder because a file with
|
|
|
|
|
* the same name is already there.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
error_selecting_folder_over_existing_file_dialog (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
error_message (impl,
|
|
|
|
|
_("You may only select folders"),
|
|
|
|
|
_("The item that you selected is not a folder try using a different item."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an error dialog about not being able to create a filename */
|
|
|
|
|
static void
|
|
|
|
|
error_building_filename_dialog (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GError *error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_dialog (impl, _("Invalid file name"), error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows an error dialog when we cannot switch to a folder */
|
|
|
|
|
static void
|
|
|
|
|
error_changing_folder_dialog (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError *error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_dialog (impl, _("The folder contents could not be displayed"), error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 03:46:11 +00:00
|
|
|
|
static void
|
|
|
|
|
error_deleting_file (GtkFileChooserWidget *impl,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GError *error)
|
|
|
|
|
{
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_dialog (impl, _("The file could not be deleted"), error);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 02:57:40 +00:00
|
|
|
|
static void
|
|
|
|
|
error_trashing_file (GtkFileChooserWidget *impl,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GError *error)
|
|
|
|
|
{
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_dialog (impl, _("The file could not be moved to the Trash"), error);
|
2015-07-07 02:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Changes folders, displaying an error dialog if this fails */
|
|
|
|
|
static gboolean
|
|
|
|
|
change_folder_and_display_error (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
gboolean clear_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GError *error;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
|
|
|
|
|
|
|
|
|
/* We copy the path because of this case:
|
|
|
|
|
*
|
|
|
|
|
* list_row_activated()
|
|
|
|
|
* fetches path from model; path belongs to the model (*)
|
|
|
|
|
* calls change_folder_and_display_error()
|
2020-02-21 15:11:15 +00:00
|
|
|
|
* calls gtk_file_chooser_set_current_folder()
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* changing folders fails, sets model to NULL, thus freeing the path in (*)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
result = gtk_file_chooser_widget_update_current_folder (GTK_FILE_CHOOSER (impl), file, TRUE, clear_entry, &error);
|
|
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
|
error_changing_folder_dialog (impl, file, error);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-10 00:56:54 +00:00
|
|
|
|
static void
|
|
|
|
|
new_folder_popover_active (GtkWidget *button,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->new_folder_name_entry), "");
|
|
|
|
|
gtk_widget_set_sensitive (impl->new_folder_create_button, FALSE);
|
|
|
|
|
gtk_file_chooser_error_stack_set_error (GTK_FILE_CHOOSER_ERROR_STACK (impl->new_folder_error_stack),
|
2017-05-09 07:52:00 +00:00
|
|
|
|
FALSE,
|
|
|
|
|
"no-error");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct FileExistsData
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
gboolean file_exists_and_is_not_folder;
|
|
|
|
|
GFile *parent_file;
|
|
|
|
|
GFile *file;
|
2017-05-09 07:52:00 +00:00
|
|
|
|
GtkWidget *error_stack;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
GtkWidget *button;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
name_exists_get_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-04-10 00:56:54 +00:00
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
struct FileExistsData *data = user_data;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFileInfo *info;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_exists_get_info_cancellable);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
if (info != NULL)
|
|
|
|
|
{
|
2015-07-05 01:16:55 +00:00
|
|
|
|
gtk_widget_set_sensitive (data->button, FALSE);
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (GTK_FILE_CHOOSER_ERROR_STACK (data->error_stack),
|
|
|
|
|
_gtk_file_info_consider_as_directory (info),
|
|
|
|
|
"name-already-exists");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-05 01:16:55 +00:00
|
|
|
|
gtk_widget_set_sensitive (data->button, TRUE);
|
2015-07-05 00:12:00 +00:00
|
|
|
|
/* Don't clear the label here, it may contain a warning */
|
2015-04-10 00:56:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (impl);
|
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
g_free (data);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&info);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 01:35:03 +00:00
|
|
|
|
check_valid_child_name (GtkFileChooserWidget *impl,
|
|
|
|
|
GFile *parent,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name,
|
2015-07-07 01:35:03 +00:00
|
|
|
|
gboolean is_folder,
|
2015-07-07 01:39:39 +00:00
|
|
|
|
GFile *original,
|
2017-05-09 07:52:00 +00:00
|
|
|
|
GtkWidget *error_stack,
|
2015-07-07 01:35:03 +00:00
|
|
|
|
GtkWidget *button)
|
2015-04-10 00:56:54 +00:00
|
|
|
|
{
|
2017-05-09 07:52:00 +00:00
|
|
|
|
GtkFileChooserErrorStack *stack = GTK_FILE_CHOOSER_ERROR_STACK (error_stack);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
2015-07-05 01:16:55 +00:00
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
|
|
|
|
if (name[0] == '\0')
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, FALSE, "no-error");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
else if (strcmp (name, ".") == 0)
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "cannot-be-called-dot");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
else if (strcmp (name, "..") == 0)
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "cannot-be-called-dot-dot");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
else if (strchr (name, '/') != NULL)
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "name-cannot-contain-slash");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2015-07-05 01:16:55 +00:00
|
|
|
|
file = g_file_get_child_for_display_name (parent, name, &error);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
if (file == NULL)
|
|
|
|
|
{
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_custom_error (stack, error->message);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2015-07-07 01:39:39 +00:00
|
|
|
|
else if (original && g_file_equal (original, file))
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_set_sensitive (button, TRUE);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
2015-04-10 00:56:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
struct FileExistsData *data;
|
|
|
|
|
|
2015-07-05 00:12:00 +00:00
|
|
|
|
/* Warn the user about questionable names that are technically valid */
|
|
|
|
|
if (g_ascii_isspace (name[0]))
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "name-should-not-begin-with-space");
|
2015-07-05 00:12:00 +00:00
|
|
|
|
else if (g_ascii_isspace (name[strlen (name) - 1]))
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "name-should-not-end-with-space");
|
2015-07-05 00:12:00 +00:00
|
|
|
|
else if (name[0] == '.')
|
2017-05-09 07:52:00 +00:00
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, is_folder, "name-with-dot-is-hidden");
|
|
|
|
|
else
|
|
|
|
|
gtk_file_chooser_error_stack_set_error (stack, FALSE, "no-error");
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
|
|
|
|
data = g_new0 (struct FileExistsData, 1);
|
|
|
|
|
data->impl = g_object_ref (impl);
|
|
|
|
|
data->file = g_object_ref (file);
|
2017-05-09 07:52:00 +00:00
|
|
|
|
data->error_stack = error_stack;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
data->button = button;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->file_exists_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_exists_get_info_cancellable);
|
|
|
|
|
|
|
|
|
|
impl->file_exists_get_info_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
"standard::type",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->file_exists_get_info_cancellable,
|
|
|
|
|
name_exists_get_info_cb,
|
|
|
|
|
data);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-03-02 04:28:55 +00:00
|
|
|
|
new_folder_name_changed (GtkEditable *editable,
|
2015-04-10 00:56:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2015-07-07 01:35:03 +00:00
|
|
|
|
check_valid_child_name (impl,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->current_folder,
|
2019-03-02 04:28:55 +00:00
|
|
|
|
gtk_editable_get_text (editable),
|
2015-07-07 01:35:03 +00:00
|
|
|
|
TRUE,
|
2015-07-07 01:39:39 +00:00
|
|
|
|
NULL,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->new_folder_error_stack,
|
|
|
|
|
impl->new_folder_create_button);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
new_folder_create_clicked (GtkButton *button,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GFile *file;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name;
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
name = gtk_editable_get_text (GTK_EDITABLE (impl->new_folder_name_entry));
|
|
|
|
|
file = g_file_get_child_for_display_name (impl->current_folder, name, &error);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (impl->new_folder_popover));
|
2015-04-10 00:56:54 +00:00
|
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
if (g_file_make_directory (file, NULL, &error))
|
|
|
|
|
change_folder_and_display_error (impl, file, FALSE);
|
|
|
|
|
else
|
|
|
|
|
error_creating_folder_dialog (impl, file, error);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
error_creating_folder_dialog (impl, file, error);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
struct selection_check_closure {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
int num_selected;
|
|
|
|
|
gboolean all_files;
|
|
|
|
|
gboolean all_folders;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Used from gtk_tree_selection_selected_foreach() */
|
|
|
|
|
static void
|
|
|
|
|
selection_check_foreach_cb (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct selection_check_closure *closure;
|
|
|
|
|
gboolean is_folder;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
MODEL_COL_FILE, &file,
|
|
|
|
|
MODEL_COL_IS_FOLDER, &is_folder,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
|
|
closure = data;
|
|
|
|
|
closure->num_selected++;
|
|
|
|
|
|
|
|
|
|
closure->all_folders = closure->all_folders && is_folder;
|
|
|
|
|
closure->all_files = closure->all_files && !is_folder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Checks whether the selected items in the file list are all files or all folders */
|
|
|
|
|
static void
|
|
|
|
|
selection_check (GtkFileChooserWidget *impl,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *num_selected,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean *all_files,
|
|
|
|
|
gboolean *all_folders)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct selection_check_closure closure;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
closure.impl = impl;
|
|
|
|
|
closure.num_selected = 0;
|
|
|
|
|
closure.all_files = TRUE;
|
|
|
|
|
closure.all_folders = TRUE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
selection_check_foreach_cb,
|
|
|
|
|
&closure);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_assert (closure.num_selected == 0 || !(closure.all_files && closure.all_folders));
|
|
|
|
|
|
|
|
|
|
if (num_selected)
|
|
|
|
|
*num_selected = closure.num_selected;
|
|
|
|
|
|
|
|
|
|
if (all_files)
|
|
|
|
|
*all_files = closure.all_files;
|
|
|
|
|
|
|
|
|
|
if (all_folders)
|
|
|
|
|
*all_folders = closure.all_folders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
file_is_recent_uri (GFile *file)
|
|
|
|
|
{
|
|
|
|
|
GFile *recent;
|
|
|
|
|
gboolean same;
|
|
|
|
|
|
|
|
|
|
recent = g_file_new_for_uri ("recent:///");
|
|
|
|
|
same = g_file_equal (file, recent);
|
|
|
|
|
g_object_unref (recent);
|
|
|
|
|
|
|
|
|
|
return same;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-06-27 01:14:37 +00:00
|
|
|
|
places_sidebar_open_location_cb (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location,
|
|
|
|
|
GtkPlacesOpenFlags open_flags,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean clear_entry;
|
|
|
|
|
|
2015-06-04 19:14:04 +00:00
|
|
|
|
/* In the Save modes, we want to preserve what the user typed in the filename
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* entry, so that he may choose another folder without erasing his typed name.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry && impl->action != GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
clear_entry = TRUE;
|
|
|
|
|
else
|
|
|
|
|
clear_entry = FALSE;
|
|
|
|
|
|
2014-04-08 17:13:01 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_PATH_BAR);
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (file_is_recent_uri (location))
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_RECENT);
|
|
|
|
|
else
|
|
|
|
|
change_folder_and_display_error (impl, location, clear_entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the places sidebar needs us to display an error message */
|
|
|
|
|
static void
|
|
|
|
|
places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
const char *primary,
|
|
|
|
|
const char *secondary,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
error_message (impl, primary, secondary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2018-08-26 16:39:51 +00:00
|
|
|
|
trigger_location_entry (GtkWidget *widget,
|
|
|
|
|
GVariant *arguments,
|
|
|
|
|
gpointer unused)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2018-08-26 16:39:51 +00:00
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2015-10-16 00:53:43 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action != GTK_FILE_CHOOSER_ACTION_OPEN &&
|
|
|
|
|
impl->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2018-08-26 16:39:51 +00:00
|
|
|
|
return FALSE;
|
2020-03-19 22:03:16 +00:00
|
|
|
|
|
2018-08-26 16:39:51 +00:00
|
|
|
|
location_popup_handler (impl, g_variant_get_string (arguments, NULL));
|
|
|
|
|
return TRUE;
|
2015-06-27 17:44:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Callback used from gtk_tree_selection_selected_foreach(); adds a bookmark for
|
|
|
|
|
* each selected item in the file list.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
add_bookmark_foreach_cb (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) data;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
MODEL_COL_FILE, &file,
|
|
|
|
|
-1);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_bookmarks_manager_insert_bookmark (impl->bookmarks_manager, file, 0, NULL); /* NULL-GError */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the "Add to Bookmarks" menu item is activated */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
add_to_shortcuts_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_selection_selected_foreach (selection,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
add_bookmark_foreach_cb,
|
|
|
|
|
impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
GFile *file;
|
|
|
|
|
} ConfirmDeleteData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_confirm_delete_response (GtkWidget *dialog,
|
|
|
|
|
int response,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
ConfirmDeleteData *data = user_data;
|
|
|
|
|
|
|
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
|
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_file_delete (data->file, NULL, &error))
|
|
|
|
|
error_deleting_file (data->impl, data->file, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-05 03:46:11 +00:00
|
|
|
|
confirm_delete (GtkFileChooserWidget *impl,
|
2020-04-30 13:41:57 +00:00
|
|
|
|
GFile *file,
|
2015-07-05 03:46:11 +00:00
|
|
|
|
GFileInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
GtkWidget *dialog;
|
2020-04-30 13:41:57 +00:00
|
|
|
|
const char *name;
|
|
|
|
|
ConfirmDeleteData *data;
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
|
|
|
|
name = g_file_info_get_display_name (info);
|
|
|
|
|
|
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (toplevel,
|
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
|
GTK_BUTTONS_NONE,
|
2015-07-07 03:03:56 +00:00
|
|
|
|
_("Are you sure you want to permanently delete “%s”?"),
|
2015-07-05 03:46:11 +00:00
|
|
|
|
name);
|
2015-07-07 03:03:56 +00:00
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
|
_("If you delete an item, it will be permanently lost."));
|
2015-07-05 03:46:11 +00:00
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
|
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Delete"), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
|
|
if (gtk_window_has_group (toplevel))
|
|
|
|
|
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
|
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
gtk_widget_show (dialog);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
data = g_new (ConfirmDeleteData, 1);
|
|
|
|
|
data->impl = impl;
|
|
|
|
|
data->file = file;
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
|
G_CALLBACK (on_confirm_delete_response),
|
|
|
|
|
data);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
static void
|
|
|
|
|
delete_selected_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
GFile *file;
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
|
|
file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
|
|
|
|
|
info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), iter);
|
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
confirm_delete (impl, file, info);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 03:46:11 +00:00
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
delete_file_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2015-07-05 03:46:11 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-07-05 03:46:11 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, delete_selected_cb, impl);
|
|
|
|
|
}
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
static void
|
|
|
|
|
trash_selected_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
GFile *file;
|
|
|
|
|
GError *error = NULL;
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
if (!g_file_trash (file, NULL, &error))
|
|
|
|
|
error_trashing_file (impl, file, error);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
|
2015-07-07 02:57:40 +00:00
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
trash_file_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2015-07-07 02:57:40 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-07-07 02:57:40 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, trash_selected_cb, impl);
|
2015-07-07 02:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 01:16:55 +00:00
|
|
|
|
static void
|
|
|
|
|
rename_file_name_changed (GtkEntry *entry,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GFileType file_type;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
file_type = g_file_query_file_type (impl->rename_file_source_file,
|
2015-07-05 01:16:55 +00:00
|
|
|
|
G_FILE_QUERY_INFO_NONE, NULL);
|
|
|
|
|
|
2015-07-07 01:35:03 +00:00
|
|
|
|
check_valid_child_name (impl,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->current_folder,
|
2019-02-28 19:31:36 +00:00
|
|
|
|
gtk_editable_get_text (GTK_EDITABLE (entry)),
|
2015-07-07 01:35:03 +00:00
|
|
|
|
file_type == G_FILE_TYPE_DIRECTORY,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->rename_file_source_file,
|
|
|
|
|
impl->rename_file_error_stack,
|
|
|
|
|
impl->rename_file_rename_button);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rename_file_end (GtkPopover *popover,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_object_unref (impl->rename_file_source_file);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rename_file_rename_clicked (GtkButton *button,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GFile *dest;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char * new_name;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (impl->rename_file_popover));
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
new_name = gtk_editable_get_text (GTK_EDITABLE (impl->rename_file_name_entry));
|
|
|
|
|
dest = g_file_get_parent (impl->rename_file_source_file);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->renamed_file);
|
2019-08-12 21:32:56 +00:00
|
|
|
|
|
2015-07-05 01:16:55 +00:00
|
|
|
|
if (dest)
|
|
|
|
|
{
|
|
|
|
|
GFile *child;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
child = g_file_get_child (dest, new_name);
|
|
|
|
|
if (child)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!g_file_move (impl->rename_file_source_file, child, G_FILE_COPY_NONE,
|
2015-07-05 01:16:55 +00:00
|
|
|
|
NULL, NULL, NULL, &error))
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error_dialog (impl, _("The file could not be renamed"), error);
|
2019-08-12 21:32:56 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Rename succeded, save renamed file so it will
|
|
|
|
|
* be revealed by our "row-changed" handler */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->renamed_file = g_object_ref (child);
|
2019-08-12 21:32:56 +00:00
|
|
|
|
}
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (child);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (dest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-09 01:31:40 +00:00
|
|
|
|
rename_selected_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2015-07-05 01:16:55 +00:00
|
|
|
|
{
|
2015-07-09 01:31:40 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
GdkRectangle rect;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *filename;
|
2020-05-17 21:08:01 +00:00
|
|
|
|
double x, y;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_model_get (model, iter,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
MODEL_COL_FILE, &impl->rename_file_source_file,
|
2015-07-09 01:31:40 +00:00
|
|
|
|
-1);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
|
|
|
|
path, impl->list_name_column, &rect);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2020-03-22 00:14:23 +00:00
|
|
|
|
rect.x, rect.y,
|
|
|
|
|
&rect.x, &rect.y);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_translate_coordinates (impl->browse_files_tree_view,
|
2020-03-22 00:14:23 +00:00
|
|
|
|
GTK_WIDGET (impl),
|
|
|
|
|
rect.x, rect.y,
|
2020-05-17 21:08:01 +00:00
|
|
|
|
&x, &y);
|
|
|
|
|
rect.x = x;
|
|
|
|
|
rect.y = y;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
filename = g_file_get_basename (impl->rename_file_source_file);
|
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->rename_file_name_entry), filename);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
g_free (filename);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (impl->rename_file_popover), &rect);
|
|
|
|
|
gtk_popover_popup (GTK_POPOVER (impl->rename_file_popover));
|
|
|
|
|
gtk_widget_grab_focus (impl->rename_file_popover);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
rename_file_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2015-07-09 01:31:40 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-07-09 01:31:40 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
/* insensitive until we change the name */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->rename_file_rename_button, FALSE);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, rename_selected_cb, impl);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Callback used when the "Copy file’s location" menu item is activated */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
copy_file_location_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GSList *selected_files = NULL;
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
selected_files = get_selected_files (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (selected_files)
|
|
|
|
|
{
|
2017-11-29 08:52:38 +00:00
|
|
|
|
GdkClipboard *clipboard;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2017-11-29 08:52:38 +00:00
|
|
|
|
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl));
|
2017-12-05 04:16:49 +00:00
|
|
|
|
gdk_clipboard_set (clipboard, GDK_TYPE_FILE_LIST, selected_files);
|
|
|
|
|
g_slist_free_full (selected_files, g_object_unref);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the "Visit this file" menu item is activated */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
visit_file_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GSList *files;
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
files = get_selected_files (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Sigh, just use the first one */
|
|
|
|
|
if (files)
|
|
|
|
|
{
|
|
|
|
|
GFile *file = files->data;
|
|
|
|
|
|
|
|
|
|
gtk_file_chooser_widget_select_file (GTK_FILE_CHOOSER (impl), file, NULL); /* NULL-GError */
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-31 21:57:04 +00:00
|
|
|
|
g_slist_free_full (files, g_object_unref);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 04:34:04 +00:00
|
|
|
|
/* Callback used when the "Open this folder" menu item is activated */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
open_folder_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2015-02-12 04:34:04 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2019-05-20 04:47:50 +00:00
|
|
|
|
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (impl)));
|
2015-02-12 04:34:04 +00:00
|
|
|
|
GSList *files;
|
|
|
|
|
|
2015-07-09 01:31:40 +00:00
|
|
|
|
files = get_selected_files (impl);
|
2015-02-12 04:34:04 +00:00
|
|
|
|
|
|
|
|
|
/* Sigh, just use the first one */
|
2019-05-20 03:31:03 +00:00
|
|
|
|
if (files && GTK_IS_WINDOW (toplevel))
|
2015-02-12 04:34:04 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file = files->data;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *uri;
|
2015-02-12 04:34:04 +00:00
|
|
|
|
|
|
|
|
|
uri = g_file_get_uri (file);
|
2020-04-12 01:58:19 +00:00
|
|
|
|
gtk_show_uri (GTK_WINDOW (toplevel), uri, GDK_CURRENT_TIME);
|
2015-02-12 04:34:04 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-31 21:57:04 +00:00
|
|
|
|
g_slist_free_full (files, g_object_unref);
|
2015-02-12 04:34:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* callback used when the "Show Hidden Files" menu item is toggled */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
change_show_hidden_state (GSimpleAction *action,
|
|
|
|
|
GVariant *state,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
|
|
|
|
|
g_simple_action_set_state (action, state);
|
2020-02-26 10:06:22 +00:00
|
|
|
|
set_show_hidden (impl, g_variant_get_boolean (state));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the "Show Size Column" menu item is toggled */
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
change_show_size_state (GSimpleAction *action,
|
|
|
|
|
GVariant *state,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_state (action, state);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_size_column = g_variant_get_boolean (state);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_visible (impl->list_size_column,
|
|
|
|
|
impl->show_size_column);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 23:02:11 +00:00
|
|
|
|
/* Callback used when the "Show Type Column" menu item is toggled */
|
|
|
|
|
static void
|
|
|
|
|
change_show_type_state (GSimpleAction *action,
|
|
|
|
|
GVariant *state,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
|
|
|
|
|
g_simple_action_set_state (action, state);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_type_column = g_variant_get_boolean (state);
|
2019-06-06 23:02:11 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_visible (impl->list_type_column,
|
|
|
|
|
impl->show_type_column);
|
2019-06-06 23:02:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 05:02:13 +00:00
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
change_sort_directories_first_state (GSimpleAction *action,
|
|
|
|
|
GVariant *state,
|
|
|
|
|
gpointer data)
|
2014-11-03 05:02:13 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-11-03 05:02:13 +00:00
|
|
|
|
GtkTreeSortable *sortable;
|
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_state (action, state);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->sort_directories_first = g_variant_get_boolean (state);
|
2014-11-03 05:02:13 +00:00
|
|
|
|
|
|
|
|
|
/* force resorting */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
sortable = GTK_TREE_SORTABLE (impl->browse_files_model);
|
2014-11-03 05:02:13 +00:00
|
|
|
|
if (sortable == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id (sortable,
|
|
|
|
|
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->sort_order);
|
2014-11-03 05:02:13 +00:00
|
|
|
|
gtk_tree_sortable_set_sort_column_id (sortable,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->sort_column,
|
|
|
|
|
impl->sort_order);
|
2014-11-03 05:02:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 21:31:29 +00:00
|
|
|
|
static void
|
|
|
|
|
clear_model_cache (GtkFileChooserWidget *impl,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int column)
|
2015-07-02 21:31:29 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_model)
|
|
|
|
|
_gtk_file_system_model_clear_cache (impl->browse_files_model, column);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_model)
|
|
|
|
|
_gtk_file_system_model_clear_cache (impl->search_model, column);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->recent_model)
|
|
|
|
|
_gtk_file_system_model_clear_cache (impl->recent_model, column);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_model_filter (GtkFileChooserWidget *impl,
|
|
|
|
|
GtkFileFilter *filter)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_model)
|
|
|
|
|
_gtk_file_system_model_set_filter (impl->browse_files_model, filter);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_model)
|
|
|
|
|
_gtk_file_system_model_set_filter (impl->search_model, filter);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->recent_model)
|
|
|
|
|
_gtk_file_system_model_set_filter (impl->recent_model, filter);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-02 17:44:19 +00:00
|
|
|
|
static void
|
|
|
|
|
update_time_renderer_visible (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_object_set (impl->list_time_renderer,
|
|
|
|
|
"visible", impl->show_time,
|
2015-07-02 17:44:19 +00:00
|
|
|
|
NULL);
|
2015-07-02 21:31:29 +00:00
|
|
|
|
clear_model_cache (impl, MODEL_COL_DATE_TEXT);
|
|
|
|
|
clear_model_cache (impl, MODEL_COL_TIME_TEXT);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_queue_draw (impl->browse_files_tree_view);
|
2015-07-02 17:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
change_show_time_state (GSimpleAction *action,
|
|
|
|
|
GVariant *state,
|
|
|
|
|
gpointer data)
|
2015-07-02 17:44:19 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-07-02 17:44:19 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_state (action, state);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_time = g_variant_get_boolean (state);
|
2015-07-02 17:44:19 +00:00
|
|
|
|
update_time_renderer_visible (impl);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Shows an error dialog about not being able to select a dragged file */
|
|
|
|
|
static void
|
|
|
|
|
error_selecting_dragged_file_dialog (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError *error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
error_dialog (impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
_("Could not select file"),
|
2016-04-04 12:32:56 +00:00
|
|
|
|
error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-22 16:16:56 +00:00
|
|
|
|
file_list_drag_data_select_files (GtkFileChooserWidget *impl,
|
|
|
|
|
GSList *files)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
|
2020-02-22 16:16:56 +00:00
|
|
|
|
GSList *l;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-22 16:16:56 +00:00
|
|
|
|
for (l = files; l; l = l->next)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-02-22 16:16:56 +00:00
|
|
|
|
GFile *file = l->data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
gtk_file_chooser_widget_select_file (chooser, file, &error);
|
|
|
|
|
if (error)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
error_selecting_dragged_file_dialog (impl, file, error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-22 16:16:56 +00:00
|
|
|
|
typedef struct
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl;
|
2020-02-22 16:16:56 +00:00
|
|
|
|
GSList *files;
|
|
|
|
|
} FileListDragData;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
file_list_drag_data_received_get_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
2020-02-22 16:16:56 +00:00
|
|
|
|
FileListDragData *data = user_data;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFileInfo *info;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
|
|
|
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_list_drag_data_received_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
|
|
|
|
if (!info)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) &&
|
2020-07-12 03:17:40 +00:00
|
|
|
|
data->files->next == NULL && _gtk_file_info_consider_as_directory (info))
|
2020-02-22 16:16:56 +00:00
|
|
|
|
change_folder_and_display_error (data->impl, data->files->data, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-05-31 01:25:48 +00:00
|
|
|
|
GError *local_error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
gtk_file_chooser_widget_unselect_all (chooser);
|
2020-02-22 16:16:56 +00:00
|
|
|
|
gtk_file_chooser_widget_select_file (chooser, data->files->data, &local_error);
|
2015-05-31 01:25:48 +00:00
|
|
|
|
if (local_error)
|
2020-02-22 16:16:56 +00:00
|
|
|
|
error_selecting_dragged_file_dialog (data->impl, data->files->data, local_error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
browse_files_center_selected_row (data->impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->select_multiple)
|
2020-02-22 16:16:56 +00:00
|
|
|
|
file_list_drag_data_select_files (data->impl, data->files->next);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_object_unref (data->impl);
|
2020-02-22 16:16:56 +00:00
|
|
|
|
g_slist_free_full (data->files, g_object_unref);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_free (data);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&info);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
file_list_drag_drop_cb (GtkDropTarget *dest,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-02-22 16:16:56 +00:00
|
|
|
|
GSList *files;
|
|
|
|
|
FileListDragData *data;
|
2018-05-16 02:50:24 +00:00
|
|
|
|
|
2020-02-22 16:16:56 +00:00
|
|
|
|
files = g_value_get_boxed (value);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-22 16:16:56 +00:00
|
|
|
|
data = g_new0 (FileListDragData, 1);
|
|
|
|
|
data->impl = g_object_ref (impl);
|
|
|
|
|
data->files = g_slist_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->file_list_drag_data_received_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_list_drag_data_received_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
impl->file_list_drag_data_received_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (data->files->data,
|
|
|
|
|
"standard::type",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->file_list_drag_data_received_cancellable,
|
|
|
|
|
file_list_drag_data_received_get_info_cb,
|
|
|
|
|
data);
|
2020-02-22 16:16:56 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sensitizes the "Copy file’s location" and other context menu items if there is actually
|
|
|
|
|
* a selection active.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
check_file_list_popover_sensitivity (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int num_selected;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean all_files;
|
|
|
|
|
gboolean all_folders;
|
|
|
|
|
gboolean active;
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GAction *action, *action2;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
selection_check (impl, &num_selected, &all_files, &all_folders);
|
|
|
|
|
|
|
|
|
|
active = (num_selected != 0);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "copy-location");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "add-shortcut");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active && all_folders);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "visit");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "open");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (num_selected == 1) && all_folders);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "rename");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
if (num_selected == 1)
|
2015-07-05 03:46:11 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GSList *infos;
|
|
|
|
|
GFileInfo *info;
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
infos = get_selected_infos (impl);
|
|
|
|
|
info = G_FILE_INFO (infos->data);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
|
|
|
|
|
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME));
|
|
|
|
|
|
|
|
|
|
g_slist_free_full (infos, g_object_unref);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
|
2015-07-09 01:31:40 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "delete");
|
|
|
|
|
action2 = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "trash");
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
|
|
|
|
if (num_selected == 1)
|
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
GSimpleAction *delete_action = G_SIMPLE_ACTION (action);
|
|
|
|
|
GSimpleAction *trash_action = G_SIMPLE_ACTION (action2);
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GSList *infos;
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
|
|
infos = get_selected_infos (impl);
|
|
|
|
|
info = G_FILE_INFO (infos->data);
|
|
|
|
|
|
|
|
|
|
if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH))
|
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (trash_action, TRUE);
|
|
|
|
|
g_simple_action_set_enabled (delete_action, FALSE);
|
2015-07-16 14:45:14 +00:00
|
|
|
|
}
|
|
|
|
|
else if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE))
|
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (delete_action, TRUE);
|
|
|
|
|
g_simple_action_set_enabled (trash_action, FALSE);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-07-07 02:57:40 +00:00
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (trash_action, FALSE);
|
|
|
|
|
g_simple_action_set_enabled (delete_action, FALSE);
|
2015-07-07 02:57:40 +00:00
|
|
|
|
}
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
|
|
|
|
g_slist_free_full (infos, g_object_unref);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
}
|
2015-07-16 14:45:14 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
|
2015-07-16 14:45:14 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action2), FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GActionEntry entries[] = {
|
|
|
|
|
{ "visit", visit_file_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "open", open_folder_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "copy-location", copy_file_location_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "add-shortcut", add_to_shortcuts_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "rename", rename_file_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "delete", delete_file_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "trash", trash_file_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "toggle-show-hidden", NULL, NULL, "false", change_show_hidden_state },
|
|
|
|
|
{ "toggle-show-size", NULL, NULL, "false", change_show_size_state },
|
2019-06-06 23:02:11 +00:00
|
|
|
|
{ "toggle-show-type", NULL, NULL, "false", change_show_type_state },
|
2015-07-16 14:45:14 +00:00
|
|
|
|
{ "toggle-show-time", NULL, NULL, "false", change_show_time_state },
|
|
|
|
|
{ "toggle-sort-dirs-first", NULL, NULL, "false", change_sort_directories_first_state }
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
static void
|
|
|
|
|
file_list_build_popover (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-02-19 08:12:12 +00:00
|
|
|
|
GMenu *menu, *section;
|
|
|
|
|
GMenuItem *item;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_popover)
|
2020-02-19 08:12:12 +00:00
|
|
|
|
return;
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
menu = g_menu_new ();
|
|
|
|
|
section = g_menu_new ();
|
|
|
|
|
item = g_menu_item_new (_("_Visit File"), "item.visit");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("_Open With File Manager"), "item.open");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("_Copy Location"), "item.copy-location");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("_Add to Bookmarks"), "item.add-shortcut");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("_Rename"), "item.rename");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("_Delete"), "item.delete");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
|
|
item = g_menu_item_new (_("_Move to Trash"), "item.trash");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
|
|
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
|
|
|
|
|
g_object_unref (section);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
section = g_menu_new ();
|
|
|
|
|
item = g_menu_item_new (_("Show _Hidden Files"), "item.toggle-show-hidden");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
|
|
item = g_menu_item_new (_("Show _Size Column"), "item.toggle-show-size");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
|
|
|
|
|
|
|
|
|
item = g_menu_item_new (_("Show T_ype Column"), "item.toggle-show-type");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("Show _Time"), "item.toggle-show-time");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
item = g_menu_item_new (_("Sort _Folders Before Files"), "item.toggle-sort-dirs-first");
|
|
|
|
|
g_menu_append_item (section, item);
|
|
|
|
|
g_object_unref (item);
|
2015-07-05 03:46:11 +00:00
|
|
|
|
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
|
|
|
|
|
g_object_unref (section);
|
2015-07-07 02:57:40 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->browse_files_popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu));
|
|
|
|
|
gtk_widget_set_parent (impl->browse_files_popover, GTK_WIDGET (impl));
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_object_unref (menu);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
/* Updates the popover for the file list, creating it if necessary */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
file_list_update_popover (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GAction *action;
|
2020-02-19 08:12:12 +00:00
|
|
|
|
gboolean state;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
file_list_build_popover (impl);
|
|
|
|
|
check_file_list_popover_sensitivity (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* The sensitivity of the Add to Bookmarks item is set in
|
|
|
|
|
* bookmarks_check_add_sensitivity()
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
state = impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
|
|
|
|
|
impl->operation_mode != OPERATION_MODE_BROWSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "rename");
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !state);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "delete");
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !state);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "trash");
|
2020-02-19 08:12:12 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !state);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "visit");
|
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (impl->operation_mode != OPERATION_MODE_BROWSE));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "toggle-show-hidden");
|
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (impl->show_hidden));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "toggle-show-size");
|
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (impl->show_size_column));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "toggle-show-type");
|
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (impl->show_type_column));
|
2019-06-06 23:02:11 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "toggle-show-time");
|
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (impl->show_time));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (impl->item_actions), "toggle-sort-dirs-first");
|
|
|
|
|
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (impl->sort_directories_first));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 14:45:14 +00:00
|
|
|
|
file_list_show_popover (GtkFileChooserWidget *impl,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double x,
|
|
|
|
|
double y)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-17 12:56:06 +00:00
|
|
|
|
GdkRectangle rect;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GList *list;
|
|
|
|
|
GtkTreePath *path;
|
2019-04-29 09:46:54 +00:00
|
|
|
|
graphene_rect_t bounds;
|
2015-07-17 12:56:06 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!gtk_widget_compute_bounds (impl->browse_files_tree_view,
|
|
|
|
|
impl->browse_files_tree_view,
|
2019-04-29 09:46:54 +00:00
|
|
|
|
&bounds))
|
|
|
|
|
return;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
file_list_update_popover (impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-17 12:56:06 +00:00
|
|
|
|
list = gtk_tree_selection_get_selected_rows (selection, &model);
|
2015-09-16 14:39:19 +00:00
|
|
|
|
if (list)
|
|
|
|
|
{
|
|
|
|
|
path = list->data;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, &rect);
|
|
|
|
|
gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2020-03-22 00:00:15 +00:00
|
|
|
|
rect.x, rect.y,
|
|
|
|
|
&rect.x, &rect.y);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_translate_coordinates (impl->browse_files_tree_view,
|
2020-03-22 00:00:15 +00:00
|
|
|
|
GTK_WIDGET (impl),
|
|
|
|
|
rect.x, rect.y,
|
2020-05-17 21:08:01 +00:00
|
|
|
|
&x, &y);
|
2015-07-17 12:56:06 +00:00
|
|
|
|
|
2019-04-29 09:46:54 +00:00
|
|
|
|
rect.x = CLAMP (x - 20, 0, bounds.size.width - 40);
|
2020-05-17 21:08:01 +00:00
|
|
|
|
rect.y = y;
|
2015-09-16 14:39:19 +00:00
|
|
|
|
rect.width = 40;
|
2015-07-17 12:56:06 +00:00
|
|
|
|
|
2015-09-16 14:39:19 +00:00
|
|
|
|
g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rect.x = x;
|
|
|
|
|
rect.y = y;
|
|
|
|
|
rect.width = 1;
|
|
|
|
|
rect.height = 1;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (impl->browse_files_popover), &rect);
|
|
|
|
|
gtk_popover_popup (GTK_POPOVER (impl->browse_files_popover));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 04:07:45 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
list_popup_menu_cb (GtkWidget *widget,
|
|
|
|
|
GVariant *args,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (user_data);
|
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_widget_compute_bounds (impl->browse_files_tree_view,
|
|
|
|
|
impl->browse_files_tree_view,
|
2020-03-19 04:07:45 +00:00
|
|
|
|
&bounds))
|
|
|
|
|
{
|
|
|
|
|
file_list_show_popover (impl, 0.5 * bounds.size.width, 0.5 * bounds.size.height);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
files_list_clicked (GtkGesture *gesture,
|
|
|
|
|
int n_press,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
list_popup_menu_cb (NULL, NULL, impl);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-14 20:01:12 +00:00
|
|
|
|
static void
|
|
|
|
|
files_list_restrict_clicking (GtkGestureClick *gesture,
|
|
|
|
|
int n_press,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
if (impl->browse_files_interaction_frozen)
|
|
|
|
|
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
files_list_restrict_key_presses (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
if (impl->browse_files_interaction_frozen)
|
|
|
|
|
{
|
|
|
|
|
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (controller));
|
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Callback used when a button is pressed on the file list. We trap button 3 to
|
|
|
|
|
* bring up a popup menu.
|
|
|
|
|
*/
|
2018-01-08 00:33:27 +00:00
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
2018-01-07 17:54:06 +00:00
|
|
|
|
double x;
|
|
|
|
|
double y;
|
2018-01-08 00:33:27 +00:00
|
|
|
|
} PopoverData;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
file_list_show_popover_in_idle (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
PopoverData *pd = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
file_list_show_popover (pd->impl, pd->x, pd->y);
|
|
|
|
|
g_free (data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
|
click_cb (GtkGesture *gesture,
|
|
|
|
|
int n_press,
|
|
|
|
|
double x,
|
|
|
|
|
double y,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2018-01-08 00:33:27 +00:00
|
|
|
|
{
|
|
|
|
|
PopoverData *pd;
|
2018-01-07 17:54:06 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
pd = g_new (PopoverData, 1);
|
|
|
|
|
pd->impl = impl;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_translate_coordinates (impl->browse_files_tree_view,
|
2020-03-22 00:00:15 +00:00
|
|
|
|
GTK_WIDGET (impl),
|
2020-05-17 21:08:01 +00:00
|
|
|
|
x, y, &x, &y);
|
|
|
|
|
pd->x = x;
|
|
|
|
|
pd->y = y;
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
2018-01-08 00:33:27 +00:00
|
|
|
|
g_idle_add (file_list_show_popover_in_idle, pd);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 14:45:14 +00:00
|
|
|
|
static void
|
|
|
|
|
long_press_cb (GtkGesture *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
|
double x,
|
|
|
|
|
double y,
|
2015-07-16 14:45:14 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2015-07-17 12:56:06 +00:00
|
|
|
|
file_list_show_popover (impl, x, y);
|
2015-07-16 14:45:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
OperationMode operation_mode;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int general_column;
|
|
|
|
|
int model_column;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
} ColumnMap;
|
|
|
|
|
|
|
|
|
|
/* Sets the sort column IDs for the file list; needs to be done whenever we
|
|
|
|
|
* change the model on the treeview.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
file_list_set_sort_column_ids (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view), -1);
|
2015-03-03 23:02:09 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_name_column, MODEL_COL_NAME);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_time_column, MODEL_COL_TIME);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_size_column, MODEL_COL_SIZE);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_type_column, MODEL_COL_TYPE);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_location_column, MODEL_COL_LOCATION_TEXT);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
file_list_query_tooltip_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int x,
|
|
|
|
|
int y,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean keyboard_tip,
|
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GFile *file;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *filename;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_BROWSE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2014-01-28 09:30:33 +00:00
|
|
|
|
&x, &y,
|
|
|
|
|
keyboard_tip,
|
|
|
|
|
&model, &path, &iter))
|
|
|
|
|
return FALSE;
|
2015-08-03 00:58:19 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
MODEL_COL_FILE, &file,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (file == NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filename = g_file_get_path (file);
|
|
|
|
|
gtk_tooltip_set_text (tooltip, filename);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2014-01-28 09:30:33 +00:00
|
|
|
|
tooltip,
|
|
|
|
|
path);
|
|
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_icon_cell_renderer_fixed_size (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int xpad, ypad;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_cell_renderer_get_padding (impl->list_pixbuf_renderer, &xpad, &ypad);
|
|
|
|
|
gtk_cell_renderer_set_fixed_size (impl->list_pixbuf_renderer,
|
2017-11-15 00:48:59 +00:00
|
|
|
|
xpad * 2 + ICON_SIZE,
|
|
|
|
|
ypad * 2 + ICON_SIZE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 06:06:31 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
get_accept_action_widget (GtkDialog *dialog,
|
|
|
|
|
gboolean sensitive_only)
|
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int response[] = {
|
2020-07-09 06:06:31 +00:00
|
|
|
|
GTK_RESPONSE_ACCEPT,
|
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
|
GTK_RESPONSE_YES,
|
|
|
|
|
GTK_RESPONSE_APPLY
|
|
|
|
|
};
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2020-07-09 06:06:31 +00:00
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (response); i++)
|
|
|
|
|
{
|
|
|
|
|
widget = gtk_dialog_get_widget_for_response (dialog, response[i]);
|
|
|
|
|
if (widget)
|
|
|
|
|
{
|
|
|
|
|
if (!sensitive_only)
|
|
|
|
|
return widget;
|
|
|
|
|
|
|
|
|
|
if (gtk_widget_is_sensitive (widget))
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_default (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
GtkWidget *button;
|
|
|
|
|
GListModel *files;
|
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
|
|
dialog = gtk_widget_get_ancestor (GTK_WIDGET (impl), GTK_TYPE_DIALOG);
|
|
|
|
|
if (dialog == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
button = get_accept_action_widget (GTK_DIALOG (dialog), FALSE);
|
|
|
|
|
if (button == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (impl));
|
|
|
|
|
sensitive = (g_list_model_get_n_items (files) > 0);
|
|
|
|
|
gtk_widget_set_sensitive (button, sensitive);
|
|
|
|
|
|
|
|
|
|
g_object_unref (files);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 20:19:00 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
location_changed_timeout_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
|
|
|
|
|
|
|
|
|
gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (impl));
|
|
|
|
|
|
2020-07-09 06:06:31 +00:00
|
|
|
|
update_default (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_changed_id = 0;
|
2014-02-28 20:19:00 +00:00
|
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-03-22 02:06:24 +00:00
|
|
|
|
location_entry_changed_cb (GtkEditable *editable,
|
2014-02-28 20:19:00 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2016-02-16 03:06:17 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
change_folder_and_display_error (impl, impl->current_folder, FALSE);
|
2016-02-16 03:06:17 +00:00
|
|
|
|
else
|
|
|
|
|
switch_to_home_dir (impl);
|
|
|
|
|
}
|
2016-02-13 03:05:40 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2019-07-19 08:14:54 +00:00
|
|
|
|
{
|
|
|
|
|
/* Reset location timeout */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_changed_id > 0)
|
|
|
|
|
g_source_remove (impl->location_changed_id);
|
2019-07-19 08:14:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_changed_id = g_timeout_add (LOCATION_CHANGED_TIMEOUT,
|
2019-07-19 08:14:54 +00:00
|
|
|
|
location_changed_timeout_cb,
|
|
|
|
|
impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_source_set_name_by_id (impl->location_changed_id, "[gtk] location_changed_timeout_cb");
|
2019-07-19 08:14:54 +00:00
|
|
|
|
}
|
2014-02-28 20:19:00 +00:00
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-06-27 05:40:04 +00:00
|
|
|
|
static void
|
|
|
|
|
location_entry_close_clicked (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
location_mode_set (impl, LOCATION_MODE_PATH_BAR);
|
2019-04-28 16:08:21 +00:00
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (impl));
|
2015-06-27 05:40:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
2015-06-27 04:07:59 +00:00
|
|
|
|
location_entry_setup (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
|
|
|
gtk_entry_set_placeholder_text (GTK_ENTRY (impl->location_entry), _("Location"));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->location_entry, "changed",
|
2015-06-27 04:07:59 +00:00
|
|
|
|
G_CALLBACK (location_entry_changed_cb), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect_swapped (impl->location_entry, "hide-entry",
|
2015-06-27 05:40:04 +00:00
|
|
|
|
G_CALLBACK (location_entry_close_clicked), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
|
|
|
|
|
_gtk_file_chooser_entry_set_file_filter (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
|
|
|
|
|
impl->current_filter);
|
|
|
|
|
gtk_editable_set_width_chars (GTK_EDITABLE (impl->location_entry), 45);
|
|
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
|
|
|
|
|
gtk_widget_set_hexpand (impl->location_entry, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 04:07:59 +00:00
|
|
|
|
static void
|
|
|
|
|
location_entry_disconnect (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry)
|
|
|
|
|
g_signal_handlers_disconnect_by_func (impl->location_entry, location_entry_changed_cb, impl);
|
2015-06-27 04:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
location_entry_create (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->location_entry)
|
2015-06-27 04:07:59 +00:00
|
|
|
|
{
|
2016-01-30 00:12:51 +00:00
|
|
|
|
gboolean eat_escape;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
eat_escape = impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
2016-01-30 00:12:51 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_entry = _gtk_file_chooser_entry_new (TRUE, eat_escape);
|
2015-06-27 04:07:59 +00:00
|
|
|
|
location_entry_setup (impl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-17 03:36:51 +00:00
|
|
|
|
static gboolean
|
2018-06-08 17:05:28 +00:00
|
|
|
|
forward_key (GtkEventControllerKey *key,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType modifiers,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2015-07-17 03:36:51 +00:00
|
|
|
|
{
|
|
|
|
|
/* Since the entry is not a descendent of the file chooser widget
|
|
|
|
|
* in this case, we need to manually make our bindings apply.
|
|
|
|
|
*/
|
2018-06-08 17:05:28 +00:00
|
|
|
|
return gtk_event_controller_key_forward (key, GTK_WIDGET (impl));
|
2015-07-17 03:36:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Creates the widgets specific to Save mode */
|
|
|
|
|
static void
|
|
|
|
|
save_widgets_create (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->save_widgets != NULL ||
|
|
|
|
|
(impl->external_entry && impl->location_entry == impl->external_entry))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
location_switch_to_path_bar (impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder);
|
2015-07-14 17:48:49 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->external_entry)
|
2015-06-27 04:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
location_entry_disconnect (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_entry = impl->external_entry;
|
2015-06-27 04:07:59 +00:00
|
|
|
|
location_entry_setup (impl);
|
2015-07-17 03:36:51 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect_after (gtk_entry_get_key_controller (GTK_ENTRY (impl->external_entry)),
|
2018-06-08 17:05:28 +00:00
|
|
|
|
"key-pressed",
|
|
|
|
|
G_CALLBACK (forward_key), impl);
|
2015-06-27 04:07:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2020-04-10 16:08:16 +00:00
|
|
|
|
gtk_widget_add_css_class (vbox, "search-bar");
|
2014-04-08 17:26:08 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->save_widgets_table = gtk_grid_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (vbox), impl->save_widgets_table);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (impl->save_widgets_table), 12);
|
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (impl->save_widgets_table), 12);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Label */
|
|
|
|
|
|
|
|
|
|
widget = gtk_label_new_with_mnemonic (_("_Name:"));
|
|
|
|
|
gtk_widget_set_halign (widget, GTK_ALIGN_START);
|
|
|
|
|
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_grid_attach (GTK_GRID (impl->save_widgets_table), widget, 0, 0, 1, 1);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Location entry */
|
|
|
|
|
|
|
|
|
|
location_entry_create (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_hexpand (impl->location_entry, TRUE);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (impl->save_widgets_table), impl->location_entry, 1, 0, 1, 1);
|
|
|
|
|
gtk_widget_show (impl->location_entry);
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (widget), impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->save_widgets = vbox;
|
|
|
|
|
gtk_box_insert_child_after (GTK_BOX (impl->box), impl->save_widgets, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Destroys the widgets specific to Save mode */
|
|
|
|
|
static void
|
|
|
|
|
save_widgets_destroy (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->external_entry && impl->external_entry == impl->location_entry)
|
2015-06-27 04:07:59 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_entry_get_key_controller (GTK_ENTRY (impl->external_entry)),
|
2018-06-08 17:05:28 +00:00
|
|
|
|
forward_key, impl);
|
2015-07-17 03:36:51 +00:00
|
|
|
|
|
2015-06-27 04:07:59 +00:00
|
|
|
|
location_entry_disconnect (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_entry = NULL;
|
2015-06-27 04:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->save_widgets == NULL)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_remove (GTK_BOX (impl->box), impl->save_widgets);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->save_widgets = NULL;
|
|
|
|
|
impl->save_widgets_table = NULL;
|
|
|
|
|
impl->location_entry = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Turns on the path bar widget. Can be called even if we are already in that
|
|
|
|
|
* mode.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
location_switch_to_path_bar (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
|
g_clear_pointer (&impl->location_entry, gtk_widget_unparent);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "pathbar");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Turns on the location entry. Can be called even if we are already in that
|
|
|
|
|
* mode.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
location_switch_to_filename_entry (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-02-19 06:35:40 +00:00
|
|
|
|
/* when in search mode, we are not showing the
|
2014-04-07 21:18:56 +00:00
|
|
|
|
* browse_header_box container, so there's no point in switching
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* to it.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
location_entry_create (impl);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (impl->location_entry_box), impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_show (impl->location_entry);
|
2014-04-08 17:13:01 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "location");
|
2014-04-08 17:13:01 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 17:13:01 +00:00
|
|
|
|
/* Sets a new location mode.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
location_mode_set (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
LocationMode new_mode)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
GtkWidget *current_focus;
|
|
|
|
|
gboolean switch_to_file_list;
|
|
|
|
|
|
|
|
|
|
switch (new_mode)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
case LOCATION_MODE_PATH_BAR:
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* The location_entry will disappear when we switch to path bar mode. So,
|
|
|
|
|
* we'll focus the file list in that case, to avoid having a window with
|
|
|
|
|
* no focused widget.
|
|
|
|
|
*/
|
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
|
|
|
|
switch_to_file_list = FALSE;
|
|
|
|
|
if (toplevel)
|
|
|
|
|
{
|
2019-03-02 13:49:00 +00:00
|
|
|
|
current_focus = gtk_root_get_focus (GTK_ROOT (toplevel));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!current_focus || current_focus == impl->location_entry)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
switch_to_file_list = TRUE;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
location_switch_to_path_bar (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (switch_to_file_list)
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->browse_files_tree_view);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
break;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
case LOCATION_MODE_FILENAME_ENTRY:
|
|
|
|
|
location_switch_to_filename_entry (impl);
|
|
|
|
|
break;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->location_mode = new_mode;
|
2015-06-27 01:14:37 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "subtitle");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:48:49 +00:00
|
|
|
|
/* Callback used when the places sidebar asks us to show other locations */
|
|
|
|
|
static void
|
2016-02-29 22:13:51 +00:00
|
|
|
|
places_sidebar_show_other_locations_with_flags_cb (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesOpenFlags open_flags,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2015-07-14 17:48:49 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_OTHER_LOCATIONS);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
location_toggle_popup_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if ((impl->operation_mode == OPERATION_MODE_RECENT ||
|
|
|
|
|
impl->operation_mode == OPERATION_MODE_SEARCH) &&
|
|
|
|
|
(impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER))
|
2015-01-18 22:21:14 +00:00
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
|
|
|
|
|
2015-06-27 19:54:49 +00:00
|
|
|
|
/* If the file entry is not visible, show it (it is _always_
|
|
|
|
|
* visible in save modes, handle these first).
|
|
|
|
|
* If it is visible, turn it off only if it is focused.
|
|
|
|
|
* Otherwise, switch to the entry.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-06-27 19:54:49 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->location_entry);
|
2015-06-27 19:54:49 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->location_mode == LOCATION_MODE_PATH_BAR)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-04-08 17:13:01 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_widget_has_focus (impl->location_entry))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-04-08 17:13:01 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_PATH_BAR);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_constructed (GObject *object)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-06-26 22:22:42 +00:00
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (object);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructed (object);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
update_appearance (impl);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-24 04:00:00 +00:00
|
|
|
|
static void
|
|
|
|
|
update_extra_and_filters (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_visible (impl->extra_and_filters,
|
|
|
|
|
gtk_widget_get_visible (impl->extra_align) ||
|
|
|
|
|
gtk_widget_get_visible (impl->filter_combo_hbox));
|
2014-05-24 04:00:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Sets the extra_widget by packing it in the appropriate place */
|
|
|
|
|
static void
|
|
|
|
|
set_extra_widget (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkWidget *extra_widget)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (extra_widget)
|
2017-03-13 11:45:38 +00:00
|
|
|
|
g_object_ref (extra_widget);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->extra_widget)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_remove (GTK_BOX (impl->extra_align), impl->extra_widget);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_object_unref (impl->extra_widget);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->extra_widget = extra_widget;
|
|
|
|
|
if (impl->extra_widget)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (impl->extra_align), impl->extra_widget);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_show (impl->extra_align);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_hide (impl->extra_align);
|
2014-05-24 04:00:00 +00:00
|
|
|
|
|
2015-01-09 15:31:08 +00:00
|
|
|
|
/* Calls update_extra_and_filters */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
show_filters (impl, impl->filters != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
switch_to_home_dir (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *home = g_get_home_dir ();
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *home_file;
|
|
|
|
|
|
|
|
|
|
if (home == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
home_file = g_file_new_for_path (home);
|
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), home_file, NULL); /* NULL-GError */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (home_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets the file chooser to multiple selection mode */
|
|
|
|
|
static void
|
|
|
|
|
set_select_multiple (GtkFileChooserWidget *impl,
|
2019-10-20 11:03:52 +00:00
|
|
|
|
gboolean select_multiple)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkSelectionMode mode;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (select_multiple == impl->select_multiple)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mode = select_multiple ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_set_mode (selection, mode);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (impl->browse_files_tree_view), select_multiple);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->select_multiple = select_multiple;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "select-multiple");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Takes the folder stored in a row in the recent_model, and puts it in the pathbar */
|
|
|
|
|
static void
|
|
|
|
|
put_recent_folder_in_pathbar (GtkFileChooserWidget *impl, GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), iter,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
MODEL_COL_FILE, &file,
|
|
|
|
|
-1);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar), file, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 16:18:37 +00:00
|
|
|
|
/* Sets the location bar in the appropriate mode according to the
|
|
|
|
|
* current operation mode and action. This is the central function
|
|
|
|
|
* for dealing with the pathbar’s widgets; as long as impl->action and
|
|
|
|
|
* impl->operation_mode are set correctly, then calling this function
|
|
|
|
|
* will update all the pathbar’s widgets.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2014-04-09 16:18:37 +00:00
|
|
|
|
location_bar_update (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-04-09 16:18:37 +00:00
|
|
|
|
gboolean visible = TRUE;
|
|
|
|
|
gboolean create_folder_visible = FALSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
switch (impl->operation_mode)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-04-09 17:49:54 +00:00
|
|
|
|
case OPERATION_MODE_ENTER_LOCATION:
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-14 17:48:49 +00:00
|
|
|
|
case OPERATION_MODE_OTHER_LOCATIONS:
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case OPERATION_MODE_BROWSE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPERATION_MODE_RECENT:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
gboolean have_selected;
|
|
|
|
|
GtkTreeIter iter;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Save mode means single-selection mode, so the following is valid */
|
|
|
|
|
have_selected = gtk_tree_selection_get_selected (selection, NULL, &iter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (have_selected)
|
2015-07-09 00:32:03 +00:00
|
|
|
|
put_recent_folder_in_pathbar (impl, &iter);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
}
|
2014-04-09 16:18:37 +00:00
|
|
|
|
visible = FALSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPERATION_MODE_SEARCH:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 16:18:37 +00:00
|
|
|
|
if (visible)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->create_folders
|
|
|
|
|
&& impl->action != GTK_FILE_CHOOSER_ACTION_OPEN
|
|
|
|
|
&& impl->operation_mode != OPERATION_MODE_RECENT)
|
2014-04-09 16:18:37 +00:00
|
|
|
|
create_folder_visible = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_visible (impl->browse_new_folder_button, create_folder_visible);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 23:12:55 +00:00
|
|
|
|
operation_mode_stop (GtkFileChooserWidget *impl,
|
|
|
|
|
OperationMode mode)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-02 23:12:55 +00:00
|
|
|
|
if (mode == OPERATION_MODE_SEARCH)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->model_for_search);
|
2015-07-07 00:50:08 +00:00
|
|
|
|
search_stop_searching (impl, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
search_clear_model (impl, TRUE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_hide (impl->remote_warning_bar);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 17:49:54 +00:00
|
|
|
|
static void
|
|
|
|
|
operation_mode_set_enter_location (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "list");
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "location");
|
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), TRUE);
|
2014-04-09 17:49:54 +00:00
|
|
|
|
location_bar_update (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->filter_combo, TRUE);
|
2015-01-19 00:42:58 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY);
|
2014-04-09 17:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
operation_mode_set_browse (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2019-07-19 07:36:25 +00:00
|
|
|
|
GtkRevealerTransitionType old_revealer_transition_type;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder);
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "list");
|
2015-07-08 21:42:34 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_PATH_BAR);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "pathbar");
|
2019-07-19 07:36:25 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
old_revealer_transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (impl->browse_header_revealer));
|
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2019-07-19 07:36:25 +00:00
|
|
|
|
GTK_REVEALER_TRANSITION_TYPE_NONE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), TRUE);
|
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2019-07-19 07:36:25 +00:00
|
|
|
|
old_revealer_transition_type);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->filter_combo, TRUE);
|
2015-07-08 21:42:34 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "subtitle");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
operation_mode_set_search (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2015-07-14 17:48:49 +00:00
|
|
|
|
GtkWidget *visible_widget;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->search_model == NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
visible_widget = gtk_stack_get_visible_child (GTK_STACK (impl->browse_files_stack));
|
2015-07-14 17:48:49 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (visible_widget != impl->places_view &&
|
|
|
|
|
visible_widget != impl->browse_files_swin)
|
2015-07-14 17:48:49 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "list");
|
2015-07-14 17:48:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->search_entry);
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "search");
|
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), TRUE);
|
2015-01-18 23:59:43 +00:00
|
|
|
|
location_bar_update (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
search_setup_widgets (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->filter_combo, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
operation_mode_set_recent (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2015-01-18 21:57:21 +00:00
|
|
|
|
GFile *file;
|
2019-07-19 07:36:25 +00:00
|
|
|
|
GtkRevealerTransitionType old_revealer_transition_type;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->recent_manager)
|
|
|
|
|
impl->recent_manager = gtk_recent_manager_get_default ();
|
2019-08-30 05:37:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "list");
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "pathbar");
|
2019-07-19 07:36:25 +00:00
|
|
|
|
|
|
|
|
|
/* Hide browse_header without a transition */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
old_revealer_transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (impl->browse_header_revealer));
|
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2019-07-19 07:36:25 +00:00
|
|
|
|
GTK_REVEALER_TRANSITION_TYPE_NONE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), FALSE);
|
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2019-07-19 07:36:25 +00:00
|
|
|
|
old_revealer_transition_type);
|
|
|
|
|
|
2015-01-18 21:57:21 +00:00
|
|
|
|
location_bar_update (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
recent_start_loading (impl);
|
2015-01-18 21:57:21 +00:00
|
|
|
|
file = g_file_new_for_uri ("recent:///");
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), file);
|
2015-07-08 21:42:34 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "subtitle");
|
2015-01-18 21:57:21 +00:00
|
|
|
|
g_object_unref (file);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->filter_combo, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:48:49 +00:00
|
|
|
|
static void
|
|
|
|
|
operation_mode_set_other_locations (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "other_locations");
|
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_header_stack), "pathbar");
|
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (impl->browse_header_revealer), FALSE);
|
2015-07-14 17:48:49 +00:00
|
|
|
|
location_bar_update (impl);
|
|
|
|
|
stop_loading_and_clear_list_model (impl, TRUE);
|
|
|
|
|
search_stop_searching (impl, TRUE);
|
|
|
|
|
recent_clear_model (impl, TRUE);
|
|
|
|
|
search_clear_model (impl, TRUE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_sensitive (impl->filter_combo, FALSE);
|
2015-07-14 17:48:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
operation_mode_set (GtkFileChooserWidget *impl, OperationMode mode)
|
|
|
|
|
{
|
2015-01-28 20:00:08 +00:00
|
|
|
|
OperationMode old_mode;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
operation_mode_stop (impl, impl->operation_mode);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
old_mode = impl->operation_mode;
|
|
|
|
|
impl->operation_mode = mode;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
switch (impl->operation_mode)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2014-04-09 17:49:54 +00:00
|
|
|
|
case OPERATION_MODE_ENTER_LOCATION:
|
|
|
|
|
operation_mode_set_enter_location (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-14 17:48:49 +00:00
|
|
|
|
case OPERATION_MODE_OTHER_LOCATIONS:
|
|
|
|
|
operation_mode_set_other_locations (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case OPERATION_MODE_BROWSE:
|
|
|
|
|
operation_mode_set_browse (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPERATION_MODE_SEARCH:
|
|
|
|
|
operation_mode_set_search (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPERATION_MODE_RECENT:
|
|
|
|
|
operation_mode_set_recent (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-01-28 20:00:08 +00:00
|
|
|
|
|
|
|
|
|
if ((old_mode == OPERATION_MODE_SEARCH) != (mode == OPERATION_MODE_SEARCH))
|
|
|
|
|
g_object_notify (G_OBJECT (impl), "search-mode");
|
2015-06-27 01:14:37 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (impl), "subtitle");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This function is basically a do_all function.
|
|
|
|
|
*
|
|
|
|
|
* It sets the visibility on all the widgets based on the current state, and
|
|
|
|
|
* moves the custom_widget if needed.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
update_appearance (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
save_widgets_create (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_show_recent (GTK_PLACES_SIDEBAR (impl->places_sidebar), FALSE);
|
|
|
|
|
gtk_places_sidebar_set_show_trash (GTK_PLACES_SIDEBAR (impl->places_sidebar), FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->select_multiple)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
g_warning ("Save mode cannot be set in conjunction with multiple selection mode. "
|
|
|
|
|
"Re-setting to single selection mode.");
|
2019-10-20 11:03:52 +00:00
|
|
|
|
set_select_multiple (impl, FALSE);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
}
|
2015-07-01 15:40:15 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
save_widgets_destroy (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_show_recent (GTK_PLACES_SIDEBAR (impl->places_sidebar), recent_files_setting_is_enabled (impl));
|
|
|
|
|
location_mode_set (impl, impl->location_mode);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry)
|
|
|
|
|
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2014-04-09 16:18:37 +00:00
|
|
|
|
location_bar_update (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* This *is* needed; we need to redraw the file list because the "sensitivity"
|
|
|
|
|
* of files may change depending whether we are in a file or folder-only mode.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_queue_draw (impl->browse_files_tree_view);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
2015-06-27 01:14:37 +00:00
|
|
|
|
gtk_file_chooser_widget_get_subtitle (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *subtitle = NULL;
|
2015-06-27 01:14:37 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2015-06-27 01:14:37 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *location;
|
2015-06-27 01:14:37 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
location = gtk_places_sidebar_get_location_title (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
2015-07-15 03:48:09 +00:00
|
|
|
|
if (location)
|
|
|
|
|
{
|
|
|
|
|
subtitle = g_strdup_printf (_("Searching in %s"), location);
|
|
|
|
|
g_free (location);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->current_folder)
|
2015-07-15 03:48:09 +00:00
|
|
|
|
{
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
info = g_file_query_info (impl->current_folder,
|
2015-07-15 03:48:09 +00:00
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
subtitle = g_strdup_printf (_("Searching in %s"), g_file_info_get_display_name (info));
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-13 00:19:51 +00:00
|
|
|
|
|
|
|
|
|
if (subtitle == NULL)
|
|
|
|
|
subtitle = g_strdup (_("Searching"));
|
2015-06-27 01:14:37 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->operation_mode == OPERATION_MODE_ENTER_LOCATION ||
|
|
|
|
|
(impl->operation_mode == OPERATION_MODE_BROWSE &&
|
|
|
|
|
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY))
|
2015-06-27 01:14:37 +00:00
|
|
|
|
{
|
2020-02-21 16:44:39 +00:00
|
|
|
|
subtitle = g_strdup (_("Enter location or URL"));
|
2015-06-27 01:14:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return subtitle;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 01:54:47 +00:00
|
|
|
|
static void
|
|
|
|
|
set_show_hidden (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean show_hidden)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->show_hidden != show_hidden)
|
2015-07-24 01:54:47 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_hidden = show_hidden;
|
2015-07-24 01:54:47 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_model)
|
|
|
|
|
_gtk_file_system_model_set_show_hidden (impl->browse_files_model, show_hidden);
|
2015-07-24 01:54:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_set_property (GObject *object,
|
2015-06-27 01:14:37 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2015-01-28 20:00:08 +00:00
|
|
|
|
case PROP_SEARCH_MODE:
|
|
|
|
|
if (g_value_get_boolean (value))
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_SEARCH);
|
|
|
|
|
else
|
2015-01-28 23:15:19 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_stack_get_visible_child (GTK_STACK (impl->browse_files_stack)) != impl->places_view)
|
2015-07-14 17:48:49 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
change_folder_and_display_error (impl, impl->current_folder, FALSE);
|
2015-07-14 17:48:49 +00:00
|
|
|
|
else
|
|
|
|
|
switch_to_home_dir (impl);
|
|
|
|
|
}
|
2015-01-28 23:15:19 +00:00
|
|
|
|
else
|
2015-07-14 17:48:49 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_OTHER_LOCATIONS);
|
|
|
|
|
}
|
2015-01-28 23:15:19 +00:00
|
|
|
|
}
|
2015-01-28 20:00:08 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case GTK_FILE_CHOOSER_PROP_ACTION:
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserAction action = g_value_get_enum (value);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (action != impl->action)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_file_chooser_widget_unselect_all (GTK_FILE_CHOOSER (impl));
|
2015-08-03 00:58:19 +00:00
|
|
|
|
|
2020-02-22 14:54:48 +00:00
|
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SAVE &&
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->select_multiple)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-02-22 14:54:48 +00:00
|
|
|
|
g_warning ("Tried to change the file chooser action to SAVE, "
|
|
|
|
|
"but this is not allowed in multiple selection "
|
|
|
|
|
"mode. Resetting the file chooser to single "
|
|
|
|
|
"selection mode.");
|
2019-10-20 11:03:52 +00:00
|
|
|
|
set_select_multiple (impl, FALSE);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->action = action;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
update_cell_renderer_attributes (impl);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
update_appearance (impl);
|
|
|
|
|
settings_load (impl);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_FILTER:
|
|
|
|
|
set_current_filter (impl, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean select_multiple = g_value_get_boolean (value);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE &&
|
2020-02-22 14:54:48 +00:00
|
|
|
|
select_multiple)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-02-22 14:54:48 +00:00
|
|
|
|
g_warning ("Tried to set the file chooser to multiple selection "
|
|
|
|
|
"mode, but this is not allowed in SAVE mode. Ignoring "
|
|
|
|
|
"the change and leaving the file chooser in single "
|
|
|
|
|
"selection mode.");
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 11:03:52 +00:00
|
|
|
|
set_select_multiple (impl, select_multiple);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
|
|
|
|
|
{
|
|
|
|
|
gboolean create_folders = g_value_get_boolean (value);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->create_folders = create_folders;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
update_appearance (impl);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_get_property (GObject *object,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
2015-01-28 20:00:08 +00:00
|
|
|
|
case PROP_SEARCH_MODE:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_value_set_boolean (value, impl->operation_mode == OPERATION_MODE_SEARCH);
|
2015-01-28 20:00:08 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2015-06-27 01:14:37 +00:00
|
|
|
|
case PROP_SUBTITLE:
|
|
|
|
|
g_value_take_string (value, gtk_file_chooser_widget_get_subtitle (impl));
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case GTK_FILE_CHOOSER_PROP_ACTION:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_value_set_enum (value, impl->action);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_FILTER:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_value_set_object (value, impl->current_filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_SELECT_MULTIPLE:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_value_set_boolean (value, impl->select_multiple);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_FILE_CHOOSER_PROP_CREATE_FOLDERS:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_value_set_boolean (value, impl->create_folders);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2020-07-06 14:34:33 +00:00
|
|
|
|
case GTK_FILE_CHOOSER_PROP_FILTERS:
|
|
|
|
|
g_value_set_object (value, impl->filters);
|
|
|
|
|
break;
|
|
|
|
|
|
2020-07-06 15:03:02 +00:00
|
|
|
|
case GTK_FILE_CHOOSER_PROP_SHORTCUT_FOLDERS:
|
|
|
|
|
g_value_take_object (value, gtk_file_chooser_get_shortcut_folders (GTK_FILE_CHOOSER (impl)));
|
|
|
|
|
break;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This cancels everything that may be going on in the background. */
|
|
|
|
|
static void
|
|
|
|
|
cancel_all_operations (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
pending_select_files_free (impl);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
if (impl->file_list_drag_data_received_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->file_list_drag_data_received_cancellable);
|
|
|
|
|
g_clear_object (&impl->file_list_drag_data_received_cancellable);
|
|
|
|
|
if (impl->update_current_folder_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->update_current_folder_cancellable);
|
|
|
|
|
g_clear_object (&impl->update_current_folder_cancellable);
|
|
|
|
|
if (impl->should_respond_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
|
|
|
|
|
g_clear_object (&impl->should_respond_get_info_cancellable);
|
|
|
|
|
if (impl->file_exists_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
|
|
|
|
|
g_clear_object (&impl->file_exists_get_info_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
search_stop_searching (impl, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Removes the settings signal handler. It's safe to call multiple times */
|
|
|
|
|
static void
|
|
|
|
|
remove_settings_signal (GtkFileChooserWidget *impl,
|
2017-10-30 21:19:02 +00:00
|
|
|
|
GdkDisplay *display)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->settings_signal_id)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
|
2017-10-30 21:19:02 +00:00
|
|
|
|
settings = gtk_settings_get_for_display (display);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_signal_handler_disconnect (settings,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->settings_signal_id);
|
|
|
|
|
impl->settings_signal_id = 0;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = (GtkFileChooserWidget *) object;
|
|
|
|
|
|
|
|
|
|
cancel_all_operations (impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_pointer (&impl->rename_file_popover, gtk_widget_unparent);
|
2020-05-09 14:33:02 +00:00
|
|
|
|
g_clear_pointer (&impl->browse_files_popover, gtk_widget_unparent);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->extra_widget);
|
|
|
|
|
g_clear_pointer (&impl->bookmarks_manager, _gtk_bookmarks_manager_free);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->external_entry && impl->location_entry == impl->external_entry)
|
2015-06-27 04:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
location_entry_disconnect (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->external_entry = NULL;
|
2015-06-27 04:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_pointer (&impl->box, gtk_widget_unparent);
|
2017-03-25 19:36:10 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for GtkWindow::set-focus; this is where we save the last-focused
|
|
|
|
|
* widget on our toplevel. See gtk_file_chooser_widget_hierarchy_changed()
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2019-03-03 13:06:53 +00:00
|
|
|
|
toplevel_set_focus_cb (GtkWindow *window,
|
|
|
|
|
GParamSpec *pspec,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->toplevel_last_focus_widget = impl->toplevel_current_focus_widget;
|
|
|
|
|
impl->toplevel_current_focus_widget = gtk_root_get_focus (GTK_ROOT (window));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We monitor the focus widget on our toplevel to be able to know which widget
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* was last focused at the time our “should_respond” method gets called.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2019-02-23 06:02:25 +00:00
|
|
|
|
gtk_file_chooser_widget_root (GtkWidget *widget)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
2019-02-23 06:02:25 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->root (widget);
|
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->toplevel_set_focus_id == 0);
|
|
|
|
|
impl->toplevel_set_focus_id = g_signal_connect (toplevel, "notify::focus-widget",
|
2019-02-23 06:02:25 +00:00
|
|
|
|
G_CALLBACK (toplevel_set_focus_cb), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->toplevel_last_focus_widget = NULL;
|
|
|
|
|
impl->toplevel_current_focus_widget = gtk_root_get_focus (GTK_ROOT (toplevel));
|
2019-02-23 06:02:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_unroot (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (toplevel && impl->toplevel_set_focus_id != 0)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_handler_disconnect (toplevel, impl->toplevel_set_focus_id);
|
|
|
|
|
impl->toplevel_set_focus_id = 0;
|
|
|
|
|
impl->toplevel_last_focus_widget = NULL;
|
|
|
|
|
impl->toplevel_current_focus_widget = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 06:02:25 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->unroot (widget);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Changes the icons wherever it is needed */
|
|
|
|
|
static void
|
|
|
|
|
change_icon_theme (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
/* the first cell in the first column is the icon column, and we have a fixed size there */
|
|
|
|
|
set_icon_cell_renderer_fixed_size (impl);
|
|
|
|
|
|
2017-11-09 02:52:50 +00:00
|
|
|
|
clear_model_cache (impl, MODEL_COL_ICON);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_queue_resize (impl->browse_files_tree_view);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when a GtkSettings value changes */
|
|
|
|
|
static void
|
|
|
|
|
settings_notify_cb (GObject *object,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
name = g_param_spec_get_name (pspec);
|
|
|
|
|
|
|
|
|
|
if (strcmp (name, "gtk-icon-theme-name") == 0)
|
|
|
|
|
change_icon_theme (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Installs a signal handler for GtkSettings so that we can monitor changes in
|
|
|
|
|
* the icon theme.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
check_icon_theme (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->settings_signal_id)
|
2020-07-12 14:05:57 +00:00
|
|
|
|
return;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2017-10-31 07:17:37 +00:00
|
|
|
|
settings = gtk_widget_get_settings (GTK_WIDGET (impl));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->settings_signal_id = g_signal_connect (settings, "notify",
|
2017-10-31 02:19:29 +00:00
|
|
|
|
G_CALLBACK (settings_notify_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2017-10-31 02:19:29 +00:00
|
|
|
|
change_icon_theme (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-05 01:46:13 +00:00
|
|
|
|
gtk_file_chooser_widget_css_changed (GtkWidget *widget,
|
|
|
|
|
GtkCssStyleChange *change)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
|
|
|
|
|
impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
|
2020-02-05 01:46:13 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->css_changed (widget, change);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2017-10-31 02:19:29 +00:00
|
|
|
|
change_icon_theme (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_sort_column (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSortable *sortable;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* can happen when we're still populating the model */
|
|
|
|
|
if (sortable == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_tree_sortable_set_sort_column_id (sortable,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->sort_column,
|
|
|
|
|
impl->sort_order);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
settings_load (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
gboolean show_hidden;
|
|
|
|
|
gboolean show_size_column;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
gboolean show_type_column;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean sort_directories_first;
|
2015-07-02 21:47:30 +00:00
|
|
|
|
DateFormat date_format;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
TypeFormat type_format;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkSortType sort_order;
|
|
|
|
|
StartupMode startup_mode;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sidebar_width;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GSettings *settings;
|
|
|
|
|
|
|
|
|
|
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
show_hidden = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN);
|
|
|
|
|
show_size_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
|
2019-06-06 23:02:11 +00:00
|
|
|
|
show_type_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_TYPE_COLUMN);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
sort_column = g_settings_get_enum (settings, SETTINGS_KEY_SORT_COLUMN);
|
|
|
|
|
sort_order = g_settings_get_enum (settings, SETTINGS_KEY_SORT_ORDER);
|
|
|
|
|
sidebar_width = g_settings_get_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH);
|
|
|
|
|
startup_mode = g_settings_get_enum (settings, SETTINGS_KEY_STARTUP_MODE);
|
|
|
|
|
sort_directories_first = g_settings_get_boolean (settings, SETTINGS_KEY_SORT_DIRECTORIES_FIRST);
|
2015-07-02 21:47:30 +00:00
|
|
|
|
date_format = g_settings_get_enum (settings, SETTINGS_KEY_DATE_FORMAT);
|
2019-06-06 23:02:11 +00:00
|
|
|
|
type_format = g_settings_get_enum (settings, SETTINGS_KEY_TYPE_FORMAT);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-21 16:28:31 +00:00
|
|
|
|
set_show_hidden (impl, show_hidden);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_size_column = show_size_column;
|
|
|
|
|
gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
|
|
|
|
|
impl->show_type_column = show_type_column;
|
|
|
|
|
gtk_tree_view_column_set_visible (impl->list_type_column, show_type_column);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->sort_column = sort_column;
|
|
|
|
|
impl->sort_order = sort_order;
|
|
|
|
|
impl->startup_mode = startup_mode;
|
|
|
|
|
impl->sort_directories_first = sort_directories_first;
|
|
|
|
|
impl->show_time = date_format == DATE_FORMAT_WITH_TIME;
|
|
|
|
|
impl->clock_format = g_settings_get_enum (settings, "clock-format");
|
|
|
|
|
impl->type_format = type_format;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* We don't call set_sort_column() here as the models may not have been
|
|
|
|
|
* created yet. The individual functions that create and set the models will
|
|
|
|
|
* call set_sort_column() themselves.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-02 17:44:19 +00:00
|
|
|
|
update_time_renderer_visible (impl);
|
2019-04-29 06:40:58 +00:00
|
|
|
|
if (sidebar_width < 0)
|
|
|
|
|
{
|
2020-05-07 12:30:39 +00:00
|
|
|
|
GtkWidget *sidebar = gtk_paned_get_start_child (GTK_PANED (impl->browse_widgets_hpaned));
|
2019-04-29 06:40:58 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_measure (sidebar, GTK_ORIENTATION_HORIZONTAL, -1,
|
|
|
|
|
NULL, &sidebar_width, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_paned_set_position (GTK_PANED (impl->browse_widgets_hpaned), sidebar_width);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
settings_save (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GSettings *settings;
|
|
|
|
|
|
|
|
|
|
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
/* All the other state */
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_settings_set_enum (settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
|
|
|
|
|
g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN, impl->show_hidden);
|
|
|
|
|
g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
|
|
|
|
|
g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_TYPE_COLUMN, impl->show_type_column);
|
|
|
|
|
g_settings_set_boolean (settings, SETTINGS_KEY_SORT_DIRECTORIES_FIRST, impl->sort_directories_first);
|
|
|
|
|
g_settings_set_enum (settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
|
|
|
|
|
g_settings_set_enum (settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH,
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
|
|
|
|
|
g_settings_set_enum (settings, SETTINGS_KEY_DATE_FORMAT, impl->show_time ? DATE_FORMAT_WITH_TIME : DATE_FORMAT_REGULAR);
|
|
|
|
|
g_settings_set_enum (settings, SETTINGS_KEY_TYPE_FORMAT, impl->type_format);
|
2015-07-02 17:44:19 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Now apply the settings */
|
|
|
|
|
g_settings_apply (settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Changes the current folder to $CWD */
|
|
|
|
|
static void
|
|
|
|
|
switch_to_cwd (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
|
char *current_working_dir = g_get_current_dir ();
|
|
|
|
|
GFile *cwd = g_file_new_for_path (current_working_dir);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), cwd, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
g_object_unref (cwd);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_free (current_working_dir);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-30 13:21:16 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
recent_files_setting_is_enabled (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
gboolean enabled;
|
|
|
|
|
|
|
|
|
|
settings = gtk_widget_get_settings (GTK_WIDGET (impl));
|
|
|
|
|
g_object_get (settings, "gtk-recent-files-enabled", &enabled, NULL);
|
|
|
|
|
return enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Sets the file chooser to showing Recent Files or $CWD, depending on the
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* user’s settings.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
set_startup_mode (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2015-07-09 00:15:07 +00:00
|
|
|
|
GtkRevealerTransitionType revealer_transition;
|
|
|
|
|
GtkStackTransitionType stack_transition;
|
|
|
|
|
|
|
|
|
|
/* turn off animations for this setup */
|
|
|
|
|
revealer_transition
|
2020-03-28 20:14:43 +00:00
|
|
|
|
= gtk_revealer_get_transition_type (GTK_REVEALER (impl->browse_header_revealer));
|
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2015-07-09 00:15:07 +00:00
|
|
|
|
GTK_REVEALER_TRANSITION_TYPE_NONE);
|
|
|
|
|
stack_transition
|
2020-03-28 20:14:43 +00:00
|
|
|
|
= gtk_stack_get_transition_type (GTK_STACK (impl->browse_header_stack));
|
|
|
|
|
gtk_stack_set_transition_type (GTK_STACK (impl->browse_header_stack),
|
2015-07-09 00:15:07 +00:00
|
|
|
|
GTK_STACK_TRANSITION_TYPE_NONE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
switch (impl->startup_mode)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
case STARTUP_MODE_RECENT:
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_places_sidebar_get_show_recent (GTK_PLACES_SIDEBAR (impl->places_sidebar)))
|
2015-05-30 13:21:16 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_RECENT);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-06 07:32:21 +00:00
|
|
|
|
G_GNUC_FALLTHROUGH;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case STARTUP_MODE_CWD:
|
|
|
|
|
switch_to_cwd (impl);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
2015-07-09 00:15:07 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_transition_type (GTK_STACK (impl->browse_header_stack),
|
2015-07-09 00:15:07 +00:00
|
|
|
|
stack_transition);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_revealer_set_transition_type (GTK_REVEALER (impl->browse_header_revealer),
|
2015-07-09 00:15:07 +00:00
|
|
|
|
revealer_transition);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
shortcut_exists (GtkFileChooserWidget *impl, GFile *needle)
|
|
|
|
|
{
|
2020-07-05 02:08:33 +00:00
|
|
|
|
GListModel *haystack;
|
|
|
|
|
guint n, i;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean exists;
|
|
|
|
|
|
|
|
|
|
exists = FALSE;
|
|
|
|
|
|
2020-07-05 02:08:33 +00:00
|
|
|
|
haystack = gtk_places_sidebar_get_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
|
|
|
|
n = g_list_model_get_n_items (haystack);
|
|
|
|
|
for (i = 0; i < n; i++)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-05 02:08:33 +00:00
|
|
|
|
GFile *hay = g_list_model_get_item (haystack, i);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (g_file_equal (hay, needle))
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-07-05 02:08:33 +00:00
|
|
|
|
g_object_unref (hay);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
exists = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-05 02:08:33 +00:00
|
|
|
|
g_object_unref (hay);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-07-05 02:08:33 +00:00
|
|
|
|
g_object_unref (haystack);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
return exists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_cwd_to_sidebar_if_needed (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
char *cwd;
|
|
|
|
|
GFile *cwd_file;
|
|
|
|
|
GFile *home_file;
|
|
|
|
|
|
2015-08-03 00:58:19 +00:00
|
|
|
|
cwd = g_get_current_dir ();
|
2014-01-28 09:30:33 +00:00
|
|
|
|
cwd_file = g_file_new_for_path (cwd);
|
|
|
|
|
g_free (cwd);
|
|
|
|
|
|
|
|
|
|
if (shortcut_exists (impl, cwd_file))
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
home_file = g_file_new_for_path (g_get_home_dir ());
|
|
|
|
|
|
|
|
|
|
/* We only add an item for $CWD if it is different from $HOME. This way,
|
|
|
|
|
* applications which get launched from a shell in a terminal (by someone who
|
|
|
|
|
* knows what they are doing) will get an item for $CWD in the places sidebar,
|
|
|
|
|
* and "normal" applications launched from the desktop shell (whose $CWD is
|
|
|
|
|
* $HOME) won't get any extra clutter in the sidebar.
|
|
|
|
|
*/
|
|
|
|
|
if (!g_file_equal (home_file, cwd_file))
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), cwd_file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (home_file);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_object_unref (cwd_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GtkWidget::map method */
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_map (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
|
2020-04-14 20:01:12 +00:00
|
|
|
|
impl->browse_files_interaction_frozen = FALSE;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->map (widget);
|
|
|
|
|
|
|
|
|
|
settings_load (impl);
|
|
|
|
|
|
|
|
|
|
add_cwd_to_sidebar_if_needed (impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_BROWSE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
switch (impl->reload_state)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
case RELOAD_EMPTY:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_startup_mode (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
2015-08-03 00:58:19 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
case RELOAD_HAS_FOLDER:
|
|
|
|
|
/* Nothing; we are already loading or loaded, so we
|
|
|
|
|
* don't need to reload
|
|
|
|
|
*/
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* GtkWidget::unmap method */
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_unmap (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
|
|
|
|
|
settings_save (impl);
|
|
|
|
|
|
|
|
|
|
cancel_all_operations (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_EMPTY;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->unmap (widget);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
compare_directory (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
gboolean dir_a, dir_b;
|
|
|
|
|
|
|
|
|
|
dir_a = g_value_get_boolean (_gtk_file_system_model_get_value (model, a, MODEL_COL_IS_FOLDER));
|
|
|
|
|
dir_b = g_value_get_boolean (_gtk_file_system_model_get_value (model, b, MODEL_COL_IS_FOLDER));
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->sort_directories_first && dir_a != dir_b)
|
|
|
|
|
return impl->list_sort_ascending ? (dir_a ? -1 : 1) : (dir_a ? 1 : -1);
|
2015-07-03 05:35:49 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
compare_name (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
const char *key_a, *key_b;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2015-07-03 05:35:49 +00:00
|
|
|
|
|
|
|
|
|
key_a = g_value_get_string (_gtk_file_system_model_get_value (model, a, MODEL_COL_NAME_COLLATED));
|
|
|
|
|
key_b = g_value_get_string (_gtk_file_system_model_get_value (model, b, MODEL_COL_NAME_COLLATED));
|
|
|
|
|
|
|
|
|
|
if (key_a && key_b)
|
|
|
|
|
result = strcmp (key_a, key_b);
|
|
|
|
|
else if (key_a)
|
|
|
|
|
result = 1;
|
|
|
|
|
else if (key_b)
|
|
|
|
|
result = -1;
|
|
|
|
|
else
|
|
|
|
|
result = 0;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
compare_size (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
gint64 size_a, size_b;
|
|
|
|
|
|
|
|
|
|
size_a = g_value_get_int64 (_gtk_file_system_model_get_value (model, a, MODEL_COL_SIZE));
|
|
|
|
|
size_b = g_value_get_int64 (_gtk_file_system_model_get_value (model, b, MODEL_COL_SIZE));
|
|
|
|
|
|
|
|
|
|
return size_a < size_b ? -1 : (size_a == size_b ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2019-06-06 23:02:11 +00:00
|
|
|
|
compare_type (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
const char *key_a, *key_b;
|
|
|
|
|
|
|
|
|
|
key_a = g_value_get_string (_gtk_file_system_model_get_value (model, a, MODEL_COL_TYPE));
|
|
|
|
|
key_b = g_value_get_string (_gtk_file_system_model_get_value (model, b, MODEL_COL_TYPE));
|
|
|
|
|
|
|
|
|
|
return g_strcmp0 (key_a, key_b);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
compare_time (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
glong ta, tb;
|
|
|
|
|
|
|
|
|
|
ta = g_value_get_long (_gtk_file_system_model_get_value (model, a, MODEL_COL_TIME));
|
|
|
|
|
tb = g_value_get_long (_gtk_file_system_model_get_value (model, b, MODEL_COL_TIME));
|
|
|
|
|
|
|
|
|
|
return ta < tb ? -1 : (ta == tb ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
compare_location (GtkFileSystemModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
const char *key_a, *key_b;
|
|
|
|
|
|
|
|
|
|
key_a = g_value_get_string (_gtk_file_system_model_get_value (model, a, MODEL_COL_LOCATION_TEXT));
|
|
|
|
|
key_b = g_value_get_string (_gtk_file_system_model_get_value (model, b, MODEL_COL_LOCATION_TEXT));
|
|
|
|
|
|
|
|
|
|
return g_strcmp0 (key_a, key_b);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Sort callback for the filename column */
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2014-01-28 09:30:33 +00:00
|
|
|
|
name_sort_func (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-03 05:35:49 +00:00
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
result = compare_directory (fs_model, a, b, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_name (fs_model, a, b, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
return result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sort callback for the size column */
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2014-01-28 09:30:33 +00:00
|
|
|
|
size_sort_func (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-03 05:35:49 +00:00
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
result = compare_directory (fs_model, a, b, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_size (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
return result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 23:02:11 +00:00
|
|
|
|
/* Sort callback for the type column */
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2019-06-06 23:02:11 +00:00
|
|
|
|
type_sort_func (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
|
|
|
|
|
result = compare_directory (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_type (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 21:04:17 +00:00
|
|
|
|
/* Sort callback for the time column */
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-01 21:04:17 +00:00
|
|
|
|
time_sort_func (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-03 05:35:49 +00:00
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
result = compare_directory (fs_model, a, b, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_time (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
return result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
recent_sort_func (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
2015-06-27 06:22:23 +00:00
|
|
|
|
{
|
2015-07-03 05:35:49 +00:00
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2015-06-27 06:22:23 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
result = compare_time (fs_model, a, b, impl);
|
2015-06-27 06:22:23 +00:00
|
|
|
|
|
2015-07-03 05:35:49 +00:00
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_name (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_location (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2015-07-03 05:35:49 +00:00
|
|
|
|
search_sort_func (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *a,
|
|
|
|
|
GtkTreeIter *b,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int result;
|
2015-07-03 05:35:49 +00:00
|
|
|
|
|
|
|
|
|
result = compare_location (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_name (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
if (result == 0)
|
|
|
|
|
result = compare_time (fs_model, a, b, impl);
|
|
|
|
|
|
|
|
|
|
return result;
|
2015-06-27 06:22:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Callback used when the sort column changes. We cache the sort order for use
|
|
|
|
|
* in name_sort_func().
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
list_sort_column_changed_cb (GtkTreeSortable *sortable,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkSortType sort_type;
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &sort_type))
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->list_sort_ascending = (sort_type == GTK_SORT_ASCENDING);
|
|
|
|
|
impl->sort_column = sort_column_id;
|
|
|
|
|
impl->sort_order = sort_type;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_busy_cursor (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean busy)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
|
|
|
|
widget = GTK_WIDGET (toplevel);
|
|
|
|
|
if (!toplevel || !gtk_widget_get_realized (widget))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (busy)
|
2017-11-04 00:37:03 +00:00
|
|
|
|
gtk_widget_set_cursor_from_name (widget, "progress");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2017-11-04 00:37:03 +00:00
|
|
|
|
gtk_widget_set_cursor (widget, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 16:22:39 +00:00
|
|
|
|
static void
|
|
|
|
|
update_columns (GtkFileChooserWidget *impl,
|
|
|
|
|
gboolean location_visible,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *time_title)
|
2015-07-03 16:22:39 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean need_resize = FALSE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_tree_view_column_get_visible (impl->list_location_column) != location_visible)
|
2015-07-03 16:22:39 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_visible (impl->list_location_column, location_visible);
|
2015-07-03 16:22:39 +00:00
|
|
|
|
need_resize = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (g_strcmp0 (gtk_tree_view_column_get_title (impl->list_time_column), time_title) != 0)
|
2015-07-03 16:22:39 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_title (impl->list_time_column, time_title);
|
2015-07-03 16:22:39 +00:00
|
|
|
|
need_resize = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_resize)
|
|
|
|
|
{
|
|
|
|
|
/* This undoes user resizing of columns when the columns change. */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_expand (impl->list_name_column, TRUE);
|
|
|
|
|
gtk_tree_view_column_set_expand (impl->list_location_column, TRUE);
|
|
|
|
|
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-03 16:22:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Creates a sort model to wrap the file system model and sets it on the tree view */
|
|
|
|
|
static void
|
|
|
|
|
load_set_model (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->browse_files_model != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
|
|
|
|
GTK_TREE_MODEL (impl->browse_files_model));
|
2015-07-03 16:22:39 +00:00
|
|
|
|
update_columns (impl, FALSE, _("Modified"));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
file_list_set_sort_column_ids (impl);
|
|
|
|
|
set_sort_column (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->list_sort_ascending = TRUE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_set_object (&impl->model_for_search, impl->browse_files_model);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Timeout callback used when the loading timer expires */
|
|
|
|
|
static gboolean
|
|
|
|
|
load_timeout_cb (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_state == LOAD_PRELOAD);
|
|
|
|
|
g_assert (impl->load_timeout_id != 0);
|
|
|
|
|
g_assert (impl->browse_files_model != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->load_timeout_id = 0;
|
|
|
|
|
impl->load_state = LOAD_LOADING;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
load_set_model (impl);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sets up a new load timer for the model and switches to the LOAD_PRELOAD state */
|
|
|
|
|
static void
|
|
|
|
|
load_setup_timer (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_timeout_id == 0);
|
|
|
|
|
g_assert (impl->load_state != LOAD_PRELOAD);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->load_timeout_id = g_timeout_add (MAX_LOADING_TIME, load_timeout_cb, impl);
|
|
|
|
|
g_source_set_name_by_id (impl->load_timeout_id, "[gtk] load_timeout_cb");
|
|
|
|
|
impl->load_state = LOAD_PRELOAD;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Removes the load timeout; changes the impl->load_state to the specified value. */
|
|
|
|
|
static void
|
|
|
|
|
load_remove_timer (GtkFileChooserWidget *impl, LoadState new_load_state)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->load_timeout_id != 0)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_state == LOAD_PRELOAD);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_source_remove (impl->load_timeout_id);
|
|
|
|
|
impl->load_timeout_id = 0;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_state == LOAD_EMPTY ||
|
|
|
|
|
impl->load_state == LOAD_LOADING ||
|
|
|
|
|
impl->load_state == LOAD_FINISHED);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_assert (new_load_state == LOAD_EMPTY ||
|
2015-07-04 00:53:54 +00:00
|
|
|
|
new_load_state == LOAD_LOADING ||
|
|
|
|
|
new_load_state == LOAD_FINISHED);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->load_state = new_load_state;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Selects the first row in the file list */
|
|
|
|
|
static void
|
|
|
|
|
browse_files_select_first_row (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter dummy_iter;
|
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (!tree_model)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (0, -1);
|
|
|
|
|
|
|
|
|
|
/* If the list is empty, do nothing. */
|
|
|
|
|
if (gtk_tree_model_get_iter (tree_model, &dummy_iter, path))
|
|
|
|
|
{
|
|
|
|
|
/* Although the following call to gtk_tree_view_set_cursor() is intended to
|
|
|
|
|
* only change the focus to the first row (not select it), GtkTreeView *will*
|
|
|
|
|
* select the row anyway due to bug #492206. So, we'll use a flag to
|
|
|
|
|
* keep our own callbacks from changing the location_entry when the selection
|
|
|
|
|
* is changed. This entire function, browse_files_select_first_row(), may
|
|
|
|
|
* go away when that bug is fixed in GtkTreeView.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->auto_selecting_first_row = TRUE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->auto_selecting_first_row = FALSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct center_selected_row_closure {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
gboolean already_centered;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Callback used from gtk_tree_selection_selected_foreach(); centers the
|
|
|
|
|
* selected row in the tree view.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
center_selected_row_foreach_cb (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2019-05-28 03:02:33 +00:00
|
|
|
|
struct center_selected_row_closure *closure = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (closure->already_centered)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
closure->already_centered = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Centers the selected row in the tree view */
|
|
|
|
|
static void
|
|
|
|
|
browse_files_center_selected_row (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
struct center_selected_row_closure closure;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
closure.impl = impl;
|
|
|
|
|
closure.already_centered = FALSE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, center_selected_row_foreach_cb, &closure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
show_and_select_files (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GSList *files)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkFileSystemModel *fsmodel;
|
|
|
|
|
gboolean enabled_hidden, removed_filters;
|
|
|
|
|
gboolean selected_a_file;
|
|
|
|
|
GSList *walk;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_state == LOAD_FINISHED);
|
|
|
|
|
g_assert (impl->browse_files_model != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
|
|
|
|
fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (fsmodel == impl->browse_files_model);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
enabled_hidden = impl->show_hidden;
|
|
|
|
|
removed_filters = (impl->current_filter == NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
selected_a_file = FALSE;
|
|
|
|
|
|
|
|
|
|
for (walk = files; walk; walk = walk->next)
|
|
|
|
|
{
|
|
|
|
|
GFile *file = walk->data;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
|
|
/* Is it a hidden file? */
|
|
|
|
|
|
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
|
|
|
|
|
{
|
|
|
|
|
GFileInfo *info = _gtk_file_system_model_get_info (fsmodel, &iter);
|
|
|
|
|
|
|
|
|
|
if (!enabled_hidden &&
|
|
|
|
|
(g_file_info_get_is_hidden (info) ||
|
|
|
|
|
g_file_info_get_is_backup (info)))
|
|
|
|
|
{
|
2020-02-26 10:06:22 +00:00
|
|
|
|
set_show_hidden (impl, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
enabled_hidden = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Is it a filtered file? */
|
|
|
|
|
|
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
|
|
|
|
|
continue; /* re-get the iter as it may change when the model refilters */
|
|
|
|
|
|
|
|
|
|
if (!_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Maybe we should have a way to ask the fsmodel if it had filtered a file */
|
|
|
|
|
if (!removed_filters)
|
|
|
|
|
{
|
|
|
|
|
set_current_filter (impl, NULL);
|
|
|
|
|
removed_filters = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Okay, can we select the file now? */
|
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (fsmodel, &iter, file))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (_gtk_file_system_model_iter_is_visible (fsmodel, &iter))
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (fsmodel), &iter);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2014-01-28 09:30:33 +00:00
|
|
|
|
path, NULL, FALSE);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
selected_a_file = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
browse_files_center_selected_row (impl);
|
|
|
|
|
|
|
|
|
|
return selected_a_file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Processes the pending operation when a folder is finished loading */
|
|
|
|
|
static void
|
|
|
|
|
pending_select_files_process (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_state == LOAD_FINISHED);
|
|
|
|
|
g_assert (impl->browse_files_model != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->pending_select_files)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
show_and_select_files (impl, impl->pending_select_files);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
pending_select_files_free (impl);
|
|
|
|
|
browse_files_center_selected_row (impl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* We only select the first row if the chooser is actually mapped ---
|
|
|
|
|
* selecting the first row is to help the user when he is interacting with
|
|
|
|
|
* the chooser, but sometimes a chooser works not on behalf of the user,
|
|
|
|
|
* but rather on behalf of something else like GtkFileChooserButton. In
|
|
|
|
|
* that case, the chooser's selection should be what the caller expects,
|
|
|
|
|
* as the user can't see that something else got selected. See bug #165264.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN &&
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_widget_get_mapped (GTK_WIDGET (impl)))
|
2015-07-04 00:53:54 +00:00
|
|
|
|
browse_files_select_first_row (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->pending_select_files == NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_error_on_reading_current_folder (GtkFileChooserWidget *impl, GError *error)
|
|
|
|
|
{
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
char *msg;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
info = g_file_query_info (impl->current_folder,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
msg = g_strdup_printf (_("Could not read the contents of %s"), g_file_info_get_display_name (info));
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
msg = g_strdup (_("Could not read the contents of the folder"));
|
|
|
|
|
|
|
|
|
|
error_message (impl, msg, error->message);
|
|
|
|
|
g_free (msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the file system model finishes loading */
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
browse_files_model_finished_loading_cb (GtkFileSystemModel *model,
|
|
|
|
|
GError *error,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (error)
|
2015-10-02 10:57:05 +00:00
|
|
|
|
{
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
show_error_on_reading_current_folder (impl, error);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->load_state == LOAD_PRELOAD)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
load_remove_timer (impl, LOAD_FINISHED);
|
|
|
|
|
load_set_model (impl);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->load_state == LOAD_LOADING)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* Nothing */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* We can't g_assert_not_reached(), as something other than us may have
|
|
|
|
|
* initiated a folder reload. See #165556.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->load_timeout_id == 0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->load_state = LOAD_FINISHED;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
pending_select_files_process (impl);
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 21:32:56 +00:00
|
|
|
|
/* Callback used when file system model adds or updates a file.
|
|
|
|
|
* We detect here when a new renamed file appears and reveal it */
|
|
|
|
|
static void
|
|
|
|
|
browse_files_model_row_changed_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
GSList files;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->renamed_file)
|
2019-08-12 21:32:56 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (g_file_equal (impl->renamed_file, file))
|
2019-08-12 21:32:56 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->renamed_file);
|
2019-08-12 21:32:56 +00:00
|
|
|
|
|
|
|
|
|
files.data = (gpointer) file;
|
|
|
|
|
files.next = NULL;
|
|
|
|
|
|
|
|
|
|
show_and_select_files (impl, &files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
stop_loading_and_clear_list_model (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean remove)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
load_remove_timer (impl, LOAD_EMPTY);
|
2015-07-02 23:12:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_set_object (&impl->browse_files_model, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (remove)
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 05:47:21 +00:00
|
|
|
|
/* Replace 'target' with 'replacement' in the input string. */
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
|
|
|
|
string_replace (const char *input,
|
|
|
|
|
const char *target,
|
|
|
|
|
const char *replacement)
|
2014-08-22 05:47:21 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char **pieces;
|
|
|
|
|
char *output;
|
2014-08-22 05:47:21 +00:00
|
|
|
|
|
|
|
|
|
pieces = g_strsplit (input, target, -1);
|
|
|
|
|
output = g_strjoinv (replacement, pieces);
|
|
|
|
|
g_strfreev (pieces);
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
static void
|
2020-07-24 18:40:36 +00:00
|
|
|
|
replace_ratio (char **str)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (g_get_charset (NULL))
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *ret;
|
2015-07-04 00:53:54 +00:00
|
|
|
|
ret = string_replace (*str, ":", "\xE2\x80\x8E∶");
|
|
|
|
|
g_free (*str);
|
|
|
|
|
*str = ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static char *
|
2015-07-02 09:37:59 +00:00
|
|
|
|
my_g_format_date_for_display (GtkFileChooserWidget *impl,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
glong secs)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GDateTime *now, *time;
|
2016-08-11 16:22:01 +00:00
|
|
|
|
GDateTime *now_date, *date;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *format;
|
|
|
|
|
char *date_str;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int days_ago;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
time = g_date_time_new_from_unix_local (secs);
|
2016-08-11 16:22:01 +00:00
|
|
|
|
date = g_date_time_new_local (g_date_time_get_year (time),
|
|
|
|
|
g_date_time_get_month (time),
|
|
|
|
|
g_date_time_get_day_of_month (time),
|
|
|
|
|
0, 0, 0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-02 09:37:59 +00:00
|
|
|
|
now = g_date_time_new_now_local ();
|
2016-08-11 16:22:01 +00:00
|
|
|
|
now_date = g_date_time_new_local (g_date_time_get_year (now),
|
|
|
|
|
g_date_time_get_month (now),
|
|
|
|
|
g_date_time_get_day_of_month (now),
|
|
|
|
|
0, 0, 0);
|
|
|
|
|
days_ago = g_date_time_difference (now_date, date) / G_TIME_SPAN_DAY;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2016-08-11 16:22:01 +00:00
|
|
|
|
if (days_ago < 1)
|
2015-07-02 09:37:59 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->show_time)
|
2015-07-02 09:37:59 +00:00
|
|
|
|
format = "";
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->clock_format == CLOCK_FORMAT_24)
|
2017-01-28 00:10:12 +00:00
|
|
|
|
/* Translators: see g_date_time_format() for details on the format */
|
2015-07-02 21:47:30 +00:00
|
|
|
|
format = _("%H:%M");
|
2015-07-02 09:37:59 +00:00
|
|
|
|
else
|
2015-07-02 21:47:30 +00:00
|
|
|
|
format = _("%l:%M %p");
|
2015-07-02 09:37:59 +00:00
|
|
|
|
}
|
2016-08-11 16:22:01 +00:00
|
|
|
|
else if (days_ago < 2)
|
2015-07-02 09:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
format = _("Yesterday");
|
|
|
|
|
}
|
2016-08-11 16:22:01 +00:00
|
|
|
|
else if (days_ago < 7)
|
2015-07-02 09:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
format = "%a"; /* Days from last week */
|
|
|
|
|
}
|
|
|
|
|
else if (g_date_time_get_year (now) == g_date_time_get_year (time))
|
|
|
|
|
{
|
|
|
|
|
format = _("%-e %b");
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-02 09:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
format = N_("%-e %b %Y");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
date_str = g_date_time_format (time, format);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
replace_ratio (&date_str);
|
2015-07-02 09:37:59 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_date_time_unref (now);
|
2016-08-11 16:22:01 +00:00
|
|
|
|
g_date_time_unref (now_date);
|
2015-07-02 09:37:59 +00:00
|
|
|
|
g_date_time_unref (time);
|
2016-08-11 16:22:01 +00:00
|
|
|
|
g_date_time_unref (date);
|
2015-07-02 09:37:59 +00:00
|
|
|
|
|
|
|
|
|
return date_str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
my_g_format_time_for_display (GtkFileChooserWidget *impl,
|
|
|
|
|
glong secs)
|
|
|
|
|
{
|
|
|
|
|
GDateTime *time;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *format;
|
|
|
|
|
char *date_str;
|
2015-07-02 09:37:59 +00:00
|
|
|
|
|
|
|
|
|
time = g_date_time_new_from_unix_local (secs);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->clock_format == CLOCK_FORMAT_24)
|
2015-07-02 21:47:30 +00:00
|
|
|
|
format = _("%H:%M");
|
|
|
|
|
else
|
|
|
|
|
format = _("%l:%M %p");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
date_str = g_date_time_format (time, format);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
replace_ratio (&date_str);
|
2014-08-22 05:47:21 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_date_time_unref (time);
|
|
|
|
|
|
|
|
|
|
return date_str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
copy_attribute (GFileInfo *to,
|
|
|
|
|
GFileInfo *from,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *attribute)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GFileAttributeType type;
|
|
|
|
|
gpointer value;
|
|
|
|
|
|
|
|
|
|
if (g_file_info_get_attribute_data (from, attribute, &type, &value, NULL))
|
|
|
|
|
g_file_info_set_attribute (to, attribute, type, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
file_system_model_got_thumbnail (GObject *object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileSystemModel *model = data; /* might be unreffed if operation was cancelled */
|
|
|
|
|
GFile *file = G_FILE (object);
|
|
|
|
|
GFileInfo *queried, *info;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
|
|
queried = g_file_query_info_finish (file, res, NULL);
|
|
|
|
|
if (queried == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* now we know model is valid */
|
|
|
|
|
|
|
|
|
|
/* file was deleted */
|
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (model, &iter, file))
|
|
|
|
|
{
|
2014-02-21 19:02:37 +00:00
|
|
|
|
g_object_unref (queried);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = g_file_info_dup (_gtk_file_system_model_get_info (model, &iter));
|
|
|
|
|
|
|
|
|
|
copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
|
|
|
|
|
copy_attribute (info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
|
|
|
|
|
copy_attribute (info, queried, G_FILE_ATTRIBUTE_STANDARD_ICON);
|
|
|
|
|
|
|
|
|
|
_gtk_file_system_model_update_file (model, file, info);
|
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
2014-02-21 19:02:37 +00:00
|
|
|
|
g_object_unref (queried);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 23:02:11 +00:00
|
|
|
|
/* Copied from src/nautilus_file.c:get_description() */
|
|
|
|
|
struct {
|
|
|
|
|
const char *icon_name;
|
|
|
|
|
const char *display_name;
|
|
|
|
|
} mime_type_map[] = {
|
|
|
|
|
{ "application-x-executable", N_("Program") },
|
|
|
|
|
{ "audio-x-generic", N_("Audio") },
|
|
|
|
|
{ "font-x-generic", N_("Font") },
|
|
|
|
|
{ "image-x-generic", N_("Image") },
|
|
|
|
|
{ "package-x-generic", N_("Archive") },
|
|
|
|
|
{ "text-html", N_("Markup") },
|
|
|
|
|
{ "text-x-generic", N_("Text") },
|
|
|
|
|
{ "text-x-generic-template", N_("Text") },
|
|
|
|
|
{ "text-x-script", N_("Program") },
|
|
|
|
|
{ "video-x-generic", N_("Video") },
|
|
|
|
|
{ "x-office-address-book", N_("Contacts") },
|
|
|
|
|
{ "x-office-calendar", N_("Calendar") },
|
|
|
|
|
{ "x-office-document", N_("Document") },
|
|
|
|
|
{ "x-office-presentation", N_("Presentation") },
|
|
|
|
|
{ "x-office-spreadsheet", N_("Spreadsheet") },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_category_from_content_type (const char *content_type)
|
|
|
|
|
{
|
|
|
|
|
char *icon_name;
|
|
|
|
|
char *basic_type = NULL;
|
|
|
|
|
|
|
|
|
|
icon_name = g_content_type_get_generic_icon_name (content_type);
|
|
|
|
|
if (icon_name != NULL)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (mime_type_map); i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (mime_type_map[i].icon_name, icon_name) == 0)
|
|
|
|
|
{
|
2020-05-02 23:57:38 +00:00
|
|
|
|
basic_type = g_strdup (_(mime_type_map[i].display_name));
|
2019-06-06 23:02:11 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (icon_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (basic_type == NULL)
|
|
|
|
|
{
|
|
|
|
|
basic_type = g_content_type_get_description (content_type);
|
|
|
|
|
if (basic_type == NULL)
|
|
|
|
|
{
|
|
|
|
|
basic_type = g_strdup (_("Unknown"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return basic_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_type_information (GtkFileChooserWidget *impl,
|
|
|
|
|
GFileInfo *info)
|
|
|
|
|
{
|
|
|
|
|
const char *content_type;
|
|
|
|
|
char *mime_type;
|
|
|
|
|
char *description;
|
|
|
|
|
|
|
|
|
|
content_type = g_file_info_get_content_type (info);
|
2020-02-28 15:59:19 +00:00
|
|
|
|
if (!content_type)
|
|
|
|
|
content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
|
2020-02-28 15:56:29 +00:00
|
|
|
|
if (!content_type)
|
|
|
|
|
goto end;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
switch (impl->type_format)
|
2019-06-06 23:02:11 +00:00
|
|
|
|
{
|
|
|
|
|
case TYPE_FORMAT_MIME:
|
|
|
|
|
mime_type = g_content_type_get_mime_type (content_type);
|
|
|
|
|
return mime_type ? mime_type : g_strdup (content_type);
|
|
|
|
|
|
|
|
|
|
case TYPE_FORMAT_DESCRIPTION:
|
|
|
|
|
description = g_content_type_get_description (content_type);
|
|
|
|
|
return description ? description : g_strdup (content_type);
|
|
|
|
|
|
|
|
|
|
case TYPE_FORMAT_CATEGORY:
|
|
|
|
|
return get_category_from_content_type (content_type);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 15:56:29 +00:00
|
|
|
|
end:
|
2019-06-06 23:02:11 +00:00
|
|
|
|
return g_strdup ("");
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
file_system_model_set (GtkFileSystemModel *model,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFileInfo *info,
|
|
|
|
|
int column,
|
|
|
|
|
GValue *value,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2015-08-03 00:58:19 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
switch (column)
|
|
|
|
|
{
|
|
|
|
|
case MODEL_COL_FILE:
|
|
|
|
|
g_value_set_object (value, file);
|
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_NAME:
|
|
|
|
|
if (info == NULL)
|
|
|
|
|
g_value_set_string (value, DEFAULT_NEW_FOLDER_NAME);
|
2015-08-03 00:58:19 +00:00
|
|
|
|
else
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_value_set_string (value, g_file_info_get_display_name (info));
|
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_NAME_COLLATED:
|
|
|
|
|
if (info == NULL)
|
|
|
|
|
g_value_take_string (value, g_utf8_collate_key_for_filename (DEFAULT_NEW_FOLDER_NAME, -1));
|
2015-08-03 00:58:19 +00:00
|
|
|
|
else
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_value_take_string (value, g_utf8_collate_key_for_filename (g_file_info_get_display_name (info), -1));
|
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_IS_FOLDER:
|
|
|
|
|
g_value_set_boolean (value, info == NULL || _gtk_file_info_consider_as_directory (info));
|
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_IS_SENSITIVE:
|
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
gboolean sensitive = TRUE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
sensitive = TRUE; /* for file modes... */
|
|
|
|
|
}
|
|
|
|
|
else if (!_gtk_file_info_consider_as_directory (info))
|
|
|
|
|
{
|
|
|
|
|
sensitive = FALSE; /* for folder modes, files are not sensitive... */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* ... and for folder modes, folders are sensitive only if the filter says so */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (model, &iter, file))
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
sensitive = !_gtk_file_system_model_iter_is_filtered_out (model, &iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_set_boolean (value, sensitive);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_value_set_boolean (value, TRUE);
|
|
|
|
|
break;
|
2017-11-09 02:52:50 +00:00
|
|
|
|
case MODEL_COL_ICON:
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON))
|
|
|
|
|
{
|
2017-11-15 00:48:59 +00:00
|
|
|
|
g_value_take_object (value, _gtk_file_info_get_icon (info, ICON_SIZE, gtk_widget_get_scale_factor (GTK_WIDGET (impl))));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *tree_model;
|
2015-08-03 00:42:42 +00:00
|
|
|
|
GtkTreePath *start, *end;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeIter iter;
|
2015-08-03 00:42:42 +00:00
|
|
|
|
gboolean visible;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_tree_view == NULL ||
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_file_info_has_attribute (info, "filechooser::queried"))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (tree_model != GTK_TREE_MODEL (model))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2015-08-03 00:42:42 +00:00
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (model, &iter, file))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_assert_not_reached ();
|
2015-08-03 00:42:42 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_tree_view_get_visible_range (GTK_TREE_VIEW (impl->browse_files_tree_view), &start, &end))
|
2015-08-03 00:42:42 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_prev (start);
|
|
|
|
|
gtk_tree_path_next (end);
|
|
|
|
|
path = gtk_tree_model_get_path (tree_model, &iter);
|
|
|
|
|
visible = gtk_tree_path_compare (start, path) != 1 &&
|
|
|
|
|
gtk_tree_path_compare (path, end) != 1;
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
gtk_tree_path_free (start);
|
|
|
|
|
gtk_tree_path_free (end);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
visible = TRUE;
|
|
|
|
|
if (visible)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
g_file_info_set_attribute_boolean (info, "filechooser::queried", TRUE);
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
|
|
|
|
|
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_ICON,
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
_gtk_file_system_model_get_cancellable (model),
|
|
|
|
|
file_system_model_got_thumbnail,
|
|
|
|
|
model);
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-03-02 20:53:35 +00:00
|
|
|
|
g_value_set_boxed (value, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_SIZE:
|
|
|
|
|
g_value_set_int64 (value, info ? g_file_info_get_size (info) : 0);
|
|
|
|
|
break;
|
|
|
|
|
case MODEL_COL_SIZE_TEXT:
|
|
|
|
|
if (info == NULL || _gtk_file_info_consider_as_directory (info))
|
|
|
|
|
g_value_set_string (value, NULL);
|
|
|
|
|
else
|
|
|
|
|
g_value_take_string (value, g_format_size (g_file_info_get_size (info)));
|
|
|
|
|
break;
|
2019-06-06 23:02:11 +00:00
|
|
|
|
case MODEL_COL_TYPE:
|
|
|
|
|
if (info == NULL || _gtk_file_info_consider_as_directory (info))
|
|
|
|
|
g_value_set_string (value, NULL);
|
|
|
|
|
else
|
|
|
|
|
g_value_take_string (value, get_type_information (impl, info));
|
|
|
|
|
break;
|
2015-07-01 21:04:17 +00:00
|
|
|
|
case MODEL_COL_TIME:
|
2015-07-02 09:37:59 +00:00
|
|
|
|
case MODEL_COL_DATE_TEXT:
|
2015-07-01 21:04:17 +00:00
|
|
|
|
case MODEL_COL_TIME_TEXT:
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-01 21:04:17 +00:00
|
|
|
|
glong time;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (info == NULL)
|
|
|
|
|
break;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_RECENT)
|
2015-07-01 21:04:17 +00:00
|
|
|
|
time = (glong) g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
|
|
|
|
|
else
|
|
|
|
|
time = (glong) g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
|
|
|
|
if (column == MODEL_COL_TIME)
|
|
|
|
|
g_value_set_long (value, time);
|
|
|
|
|
else if (time == 0)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_value_set_static_string (value, _("Unknown"));
|
2015-07-02 09:37:59 +00:00
|
|
|
|
else if (column == MODEL_COL_DATE_TEXT)
|
|
|
|
|
g_value_take_string (value, my_g_format_date_for_display (impl, time));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-02 09:37:59 +00:00
|
|
|
|
g_value_take_string (value, my_g_format_time_for_display (impl, time));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MODEL_COL_ELLIPSIZE:
|
|
|
|
|
g_value_set_enum (value, info ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE);
|
|
|
|
|
break;
|
2015-02-14 04:50:06 +00:00
|
|
|
|
case MODEL_COL_LOCATION_TEXT:
|
|
|
|
|
{
|
|
|
|
|
GFile *home_location;
|
|
|
|
|
GFile *dir_location;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *location;
|
2015-02-14 04:50:06 +00:00
|
|
|
|
|
|
|
|
|
home_location = g_file_new_for_path (g_get_home_dir ());
|
2015-03-02 20:38:29 +00:00
|
|
|
|
if (file)
|
|
|
|
|
dir_location = g_file_get_parent (file);
|
|
|
|
|
else
|
|
|
|
|
dir_location = NULL;
|
2015-02-14 04:50:06 +00:00
|
|
|
|
|
2015-06-27 05:07:32 +00:00
|
|
|
|
if (dir_location && file_is_recent_uri (dir_location))
|
|
|
|
|
{
|
|
|
|
|
const char *target_uri;
|
|
|
|
|
GFile *target;
|
|
|
|
|
|
|
|
|
|
target_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
|
|
|
|
|
target = g_file_new_for_uri (target_uri);
|
|
|
|
|
g_object_unref (dir_location);
|
|
|
|
|
dir_location = g_file_get_parent (target);
|
|
|
|
|
g_object_unref (target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dir_location)
|
2015-07-03 05:19:05 +00:00
|
|
|
|
location = g_strdup ("/");
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->current_folder && g_file_equal (impl->current_folder, dir_location))
|
2015-06-27 05:07:32 +00:00
|
|
|
|
location = g_strdup ("");
|
|
|
|
|
else if (g_file_equal (home_location, dir_location))
|
2015-02-14 04:50:06 +00:00
|
|
|
|
location = g_strdup (_("Home"));
|
2015-06-27 05:07:32 +00:00
|
|
|
|
else if (g_file_has_prefix (dir_location, home_location))
|
2015-02-14 04:50:06 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *relative_path;
|
2015-02-14 04:50:06 +00:00
|
|
|
|
|
|
|
|
|
relative_path = g_file_get_relative_path (home_location, dir_location);
|
|
|
|
|
location = g_filename_display_name (relative_path);
|
|
|
|
|
|
|
|
|
|
g_free (relative_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
2015-06-27 05:07:32 +00:00
|
|
|
|
location = g_file_get_path (dir_location);
|
2015-02-14 04:50:06 +00:00
|
|
|
|
|
|
|
|
|
g_value_take_string (value, location);
|
|
|
|
|
|
2015-03-02 20:38:29 +00:00
|
|
|
|
if (dir_location)
|
|
|
|
|
g_object_unref (dir_location);
|
2015-02-14 04:50:06 +00:00
|
|
|
|
g_object_unref (home_location);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Gets rid of the old list model and creates a new one for the current folder */
|
|
|
|
|
static gboolean
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_list_model (GtkFileChooserWidget *impl,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->current_folder != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_model &&
|
|
|
|
|
_gtk_file_system_model_get_directory (impl->browse_files_model) == impl->current_folder)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return TRUE;
|
2015-07-02 23:12:55 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
stop_loading_and_clear_list_model (impl, TRUE);
|
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->browse_files_model =
|
|
|
|
|
_gtk_file_system_model_new_for_directory (impl->current_folder,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
MODEL_ATTRIBUTES,
|
|
|
|
|
file_system_model_set,
|
|
|
|
|
impl,
|
|
|
|
|
MODEL_COLUMN_TYPES);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_set_show_hidden (impl->browse_files_model, impl->show_hidden);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_NAME, name_sort_func, impl, NULL);
|
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_SIZE, size_sort_func, impl, NULL);
|
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_TYPE, type_sort_func, impl, NULL);
|
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), MODEL_COL_TIME, time_sort_func, impl, NULL);
|
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->browse_files_model), NULL, NULL, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
set_sort_column (impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->list_sort_ascending = TRUE;
|
|
|
|
|
g_signal_connect (impl->browse_files_model, "sort-column-changed",
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_CALLBACK (list_sort_column_changed_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
load_setup_timer (impl); /* This changes the state to LOAD_PRELOAD */
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->browse_files_model, "finished-loading",
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_CALLBACK (browse_files_model_finished_loading_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->browse_files_model, "row-changed",
|
2019-08-12 21:32:56 +00:00
|
|
|
|
G_CALLBACK (browse_files_model_row_changed_cb), impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_set_filter (impl->browse_files_model, impl->current_filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct update_chooser_entry_selected_foreach_closure {
|
|
|
|
|
int num_selected;
|
|
|
|
|
GtkTreeIter first_selected_iter;
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2020-07-24 18:40:36 +00:00
|
|
|
|
compare_utf8_filenames (const char *a,
|
|
|
|
|
const char *b)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *a_folded, *b_folded;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int retval;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
a_folded = g_utf8_strdown (a, -1);
|
|
|
|
|
b_folded = g_utf8_strdown (b, -1);
|
|
|
|
|
|
|
|
|
|
retval = strcmp (a_folded, b_folded);
|
|
|
|
|
|
|
|
|
|
g_free (a_folded);
|
|
|
|
|
g_free (b_folded);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_chooser_entry_selected_foreach (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct update_chooser_entry_selected_foreach_closure *closure;
|
|
|
|
|
|
|
|
|
|
closure = data;
|
|
|
|
|
closure->num_selected++;
|
|
|
|
|
|
|
|
|
|
if (closure->num_selected == 1)
|
|
|
|
|
closure->first_selected_iter = *iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_chooser_entry (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
struct update_chooser_entry_selected_foreach_closure closure;
|
|
|
|
|
|
|
|
|
|
/* no need to update the file chooser's entry if there's no entry */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH ||
|
|
|
|
|
!impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!(impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
|
|
|
|
|
|| ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
|
|
|
|
|
|| impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
|
|
|
&& impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->location_entry != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
closure.num_selected = 0;
|
|
|
|
|
gtk_tree_selection_selected_foreach (selection, update_chooser_entry_selected_foreach, &closure);
|
|
|
|
|
|
|
|
|
|
if (closure.num_selected == 0)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_RECENT)
|
|
|
|
|
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto maybe_clear_entry;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else if (closure.num_selected == 1)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_BROWSE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFileInfo *info;
|
|
|
|
|
gboolean change_entry;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
info = _gtk_file_system_model_get_info (impl->browse_files_model, &closure.first_selected_iter);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
|
|
|
|
/* If the cursor moved to the row of the newly created folder,
|
|
|
|
|
* retrieving info will return NULL.
|
|
|
|
|
*/
|
|
|
|
|
if (!info)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_free (impl->browse_files_last_selected_name);
|
|
|
|
|
impl->browse_files_last_selected_name =
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_strdup (g_file_info_get_display_name (info));
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
/* Don't change the name when clicking on a folder... */
|
|
|
|
|
change_entry = !_gtk_file_info_consider_as_directory (info);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
change_entry = TRUE; /* ... unless we are in SELECT_FOLDER mode */
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (change_entry && !impl->auto_selecting_first_row)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_handlers_block_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), impl->browse_files_last_selected_name);
|
|
|
|
|
g_signal_handlers_unblock_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
|
|
|
|
_gtk_file_chooser_entry_select_filename (GTK_FILE_CHOOSER_ENTRY (impl->location_entry));
|
2015-07-04 00:53:54 +00:00
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->operation_mode == OPERATION_MODE_RECENT
|
|
|
|
|
&& impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *folder;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Set the base folder on the name entry, so it will do completion relative to the correct recent-folder */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_model), &closure.first_selected_iter,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
MODEL_COL_FILE, &folder,
|
|
|
|
|
-1);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), folder);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_object_unref (folder);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->action != GTK_FILE_CHOOSER_ACTION_SAVE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Multiple selection, so just clear the entry. */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_free (impl->browse_files_last_selected_name);
|
|
|
|
|
impl->browse_files_last_selected_name = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_handlers_block_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), "");
|
|
|
|
|
g_signal_handlers_unblock_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
maybe_clear_entry:
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if ((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
|
|
|
|
&& impl->browse_files_last_selected_name)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
const char *entry_text;
|
|
|
|
|
int len;
|
|
|
|
|
gboolean clear_entry;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
entry_text = gtk_editable_get_text (GTK_EDITABLE (impl->location_entry));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
len = strlen (entry_text);
|
|
|
|
|
if (len != 0)
|
|
|
|
|
{
|
|
|
|
|
/* The file chooser entry may have appended a "/" to its text.
|
|
|
|
|
* So take it out, and compare the result to the old selection.
|
|
|
|
|
*/
|
|
|
|
|
if (entry_text[len - 1] == G_DIR_SEPARATOR)
|
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *tmp;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
tmp = g_strndup (entry_text, len - 1);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, tmp) == 0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-03-28 20:14:43 +00:00
|
|
|
|
clear_entry = (compare_utf8_filenames (impl->browse_files_last_selected_name, entry_text) == 0);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
clear_entry = FALSE;
|
|
|
|
|
|
|
|
|
|
if (clear_entry)
|
2014-02-28 20:19:00 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_handlers_block_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), "");
|
|
|
|
|
g_signal_handlers_unblock_by_func (impl->location_entry, G_CALLBACK (location_entry_changed_cb), impl);
|
2014-02-28 20:19:00 +00:00
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_file_chooser_widget_set_current_folder (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
return gtk_file_chooser_widget_update_current_folder (chooser, file, FALSE, FALSE, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct UpdateCurrentFolderData
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
GFile *file;
|
|
|
|
|
gboolean keep_trail;
|
|
|
|
|
gboolean clear_entry;
|
|
|
|
|
GFile *original_file;
|
|
|
|
|
GError *original_error;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
update_current_folder_mount_enclosing_volume_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
struct UpdateCurrentFolderData *data = user_data;
|
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GError *error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->update_current_folder_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_file_mount_enclosing_volume_finish (file, result, &error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
error_changing_folder_dialog (data->impl, data->file, g_error_copy (error));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_EMPTY;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
change_folder_and_display_error (impl, data->file, data->clear_entry);
|
|
|
|
|
|
|
|
|
|
out:
|
2015-01-20 16:54:03 +00:00
|
|
|
|
g_object_unref (data->impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
update_current_folder_get_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
struct UpdateCurrentFolderData *data = user_data;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFileInfo *info;
|
|
|
|
|
GError *error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->update_current_folder_cancellable);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_EMPTY;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, &error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
GFile *parent_file;
|
|
|
|
|
|
|
|
|
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED))
|
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_operation;
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
2019-05-20 04:47:50 +00:00
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (impl)));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
|
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
impl->update_current_folder_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_mount_enclosing_volume (data->file,
|
|
|
|
|
G_MOUNT_MOUNT_NONE,
|
|
|
|
|
mount_operation,
|
|
|
|
|
impl->update_current_folder_cancellable,
|
|
|
|
|
update_current_folder_mount_enclosing_volume_cb,
|
|
|
|
|
data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data->original_file)
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
data->original_file = g_object_ref (data->file);
|
|
|
|
|
data->original_error = g_error_copy (error);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
parent_file = g_file_get_parent (data->file);
|
|
|
|
|
|
|
|
|
|
/* get parent path and try to change the folder to that */
|
|
|
|
|
if (parent_file)
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
data->file = parent_file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* restart the update current folder operation */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_HAS_FOLDER;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
impl->update_current_folder_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (data->file,
|
|
|
|
|
"standard::type",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->update_current_folder_cancellable,
|
|
|
|
|
update_current_folder_get_info_cb,
|
|
|
|
|
data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Error and bail out, ignoring "not found" errors since they're useless:
|
|
|
|
|
* they only happen when a program defaults to a folder that has been (re)moved.
|
|
|
|
|
*/
|
|
|
|
|
if (!g_error_matches (data->original_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
|
|
|
|
error_changing_folder_dialog (impl, data->original_file, data->original_error);
|
|
|
|
|
else
|
|
|
|
|
g_error_free (data->original_error);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_object_unref (data->original_file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data->original_file)
|
|
|
|
|
{
|
|
|
|
|
/* Error and bail out, ignoring "not found" errors since they're useless:
|
|
|
|
|
* they only happen when a program defaults to a folder that has been (re)moved.
|
|
|
|
|
*/
|
|
|
|
|
if (!g_error_matches (data->original_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
|
|
|
|
error_changing_folder_dialog (impl, data->original_file, data->original_error);
|
|
|
|
|
else
|
|
|
|
|
g_error_free (data->original_error);
|
|
|
|
|
|
|
|
|
|
g_object_unref (data->original_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! _gtk_file_info_consider_as_directory (info))
|
|
|
|
|
goto out;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar), data->file, data->keep_trail);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder != data->file)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
g_object_unref (impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->current_folder = g_object_ref (data->file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_HAS_FOLDER;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Set the folder on the save entry */
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
|
|
|
|
|
impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (data->clear_entry)
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), "");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create a new list model. This is slightly evil; we store the result value
|
|
|
|
|
* but perform more actions rather than returning immediately even if it
|
|
|
|
|
* generates an error.
|
|
|
|
|
*/
|
|
|
|
|
set_list_model (impl, NULL);
|
|
|
|
|
|
|
|
|
|
/* Refresh controls */
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (impl->places_sidebar), impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-08 21:42:34 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "subtitle");
|
|
|
|
|
|
2020-07-09 06:06:31 +00:00
|
|
|
|
update_default (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
out:
|
2015-01-20 16:54:03 +00:00
|
|
|
|
g_object_unref (data->impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&info);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gtk_file_chooser_widget_update_current_folder (GtkFileChooser *chooser,
|
|
|
|
|
GFile *file,
|
|
|
|
|
gboolean keep_trail,
|
|
|
|
|
gboolean clear_entry,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
struct UpdateCurrentFolderData *data;
|
|
|
|
|
|
|
|
|
|
g_object_ref (file);
|
|
|
|
|
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->update_current_folder_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->update_current_folder_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->update_current_folder_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Test validity of path here. */
|
|
|
|
|
data = g_new0 (struct UpdateCurrentFolderData, 1);
|
2015-01-20 16:54:03 +00:00
|
|
|
|
data->impl = g_object_ref (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
data->file = g_object_ref (file);
|
|
|
|
|
data->keep_trail = keep_trail;
|
|
|
|
|
data->clear_entry = clear_entry;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_HAS_FOLDER;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
impl->update_current_folder_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
"standard::type",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->update_current_folder_cancellable,
|
|
|
|
|
update_current_folder_get_info_cb,
|
|
|
|
|
data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GFile *
|
|
|
|
|
gtk_file_chooser_widget_get_current_folder (GtkFileChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_RECENT)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return NULL;
|
2015-06-27 01:14:37 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
return g_object_ref (impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_set_current_name (GtkFileChooser *chooser,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *name)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
2020-08-02 23:18:11 +00:00
|
|
|
|
GtkEntryCompletion *completion;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_return_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
pending_select_files_free (impl);
|
2020-08-02 23:18:11 +00:00
|
|
|
|
|
|
|
|
|
completion = gtk_entry_get_completion (GTK_ENTRY (impl->location_entry));
|
|
|
|
|
gtk_entry_completion_set_popup_completion (completion, FALSE);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), name);
|
2020-08-02 23:18:11 +00:00
|
|
|
|
|
|
|
|
|
gtk_entry_completion_set_popup_completion (completion, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static char *
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_file_chooser_widget_get_current_name (GtkFileChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_return_val_if_fail (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
return g_strdup (gtk_editable_get_text (GTK_EDITABLE (impl->location_entry)));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_file_chooser_widget_select_file (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
GFile *parent_file;
|
|
|
|
|
gboolean same_path;
|
2016-01-31 04:07:56 +00:00
|
|
|
|
GtkFileSystemModel *fsmodel;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
parent_file = g_file_get_parent (file);
|
|
|
|
|
|
|
|
|
|
if (!parent_file)
|
2020-02-21 15:11:15 +00:00
|
|
|
|
return gtk_file_chooser_set_current_folder (chooser, file, error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
fsmodel = GTK_FILE_SYSTEM_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)));
|
2016-01-31 04:07:56 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH ||
|
|
|
|
|
impl->operation_mode == OPERATION_MODE_RECENT ||
|
|
|
|
|
impl->load_state == LOAD_EMPTY ||
|
|
|
|
|
impl->browse_files_model != fsmodel)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
same_path = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->current_folder != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
same_path = g_file_equal (parent_file, impl->current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (same_path && impl->load_state == LOAD_FINISHED)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean result;
|
|
|
|
|
GSList files;
|
|
|
|
|
|
|
|
|
|
files.data = (gpointer) file;
|
|
|
|
|
files.next = NULL;
|
|
|
|
|
|
2016-05-09 12:48:07 +00:00
|
|
|
|
/* Prevent the file chooser from loading a different folder when it is mapped */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->reload_state = RELOAD_HAS_FOLDER;
|
2016-05-09 12:48:07 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
result = show_and_select_files (impl, &files);
|
|
|
|
|
g_object_unref (parent_file);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pending_select_files_add (impl, file);
|
|
|
|
|
|
|
|
|
|
if (!same_path)
|
|
|
|
|
{
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
result = gtk_file_chooser_set_current_folder (chooser, parent_file, error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_unref (parent_file);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (parent_file);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_unselect_file (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
GtkTreeModel *model;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
tree_view = GTK_TREE_VIEW (impl->browse_files_tree_view);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
if (!model)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (!_gtk_file_system_model_get_iter_for_file (GTK_FILE_SYSTEM_MODEL (model), &iter, file))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gtk_tree_selection_unselect_iter (gtk_tree_view_get_selection (tree_view), &iter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-04 00:53:54 +00:00
|
|
|
|
maybe_select (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
gboolean is_sensitive;
|
|
|
|
|
gboolean is_folder;
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
MODEL_COL_IS_FOLDER, &is_folder,
|
|
|
|
|
MODEL_COL_IS_SENSITIVE, &is_sensitive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (is_sensitive &&
|
2020-03-28 20:14:43 +00:00
|
|
|
|
((is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ||
|
|
|
|
|
(!is_folder && impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_select_iter (selection, iter);
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_selection_unselect_iter (selection, iter);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_select_all (GtkFileChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH ||
|
|
|
|
|
impl->operation_mode == OPERATION_MODE_RECENT)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_select_all (selection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->select_multiple)
|
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (impl->browse_files_model),
|
2015-07-04 00:53:54 +00:00
|
|
|
|
maybe_select, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_unselect_all (GtkFileChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
|
pending_select_files_free (impl);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Checks whether the filename entry for Save modes contains a well-formed filename.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*
|
|
|
|
|
* is_well_formed_ret - whether what the user typed passes gkt_file_system_make_path()
|
|
|
|
|
*
|
|
|
|
|
* is_empty_ret - whether the file entry is totally empty
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* is_file_part_empty_ret - whether the file part is empty (will be if user types
|
|
|
|
|
* "foobar/", and the path will be “$cwd/foobar”)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
check_save_entry (GtkFileChooserWidget *impl,
|
|
|
|
|
GFile **file_ret,
|
|
|
|
|
gboolean *is_well_formed_ret,
|
|
|
|
|
gboolean *is_empty_ret,
|
|
|
|
|
gboolean *is_file_part_empty_ret,
|
|
|
|
|
gboolean *is_folder)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserEntry *chooser_entry;
|
|
|
|
|
GFile *current_folder;
|
|
|
|
|
const char *file_part;
|
2015-07-01 23:23:15 +00:00
|
|
|
|
char *file_part_stripped;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *file;
|
|
|
|
|
GError *error;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
|
|
|
|
|
((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) &&
|
|
|
|
|
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
chooser_entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
|
if (strlen (gtk_editable_get_text (GTK_EDITABLE (chooser_entry))) == 0)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
*file_ret = NULL;
|
|
|
|
|
*is_well_formed_ret = TRUE;
|
|
|
|
|
*is_empty_ret = TRUE;
|
|
|
|
|
*is_file_part_empty_ret = TRUE;
|
|
|
|
|
*is_folder = FALSE;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*is_empty_ret = FALSE;
|
|
|
|
|
|
|
|
|
|
current_folder = _gtk_file_chooser_entry_get_current_folder (chooser_entry);
|
|
|
|
|
if (!current_folder)
|
|
|
|
|
{
|
|
|
|
|
*file_ret = NULL;
|
|
|
|
|
*is_well_formed_ret = FALSE;
|
|
|
|
|
*is_file_part_empty_ret = FALSE;
|
|
|
|
|
*is_folder = FALSE;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file_part = _gtk_file_chooser_entry_get_file_part (chooser_entry);
|
|
|
|
|
|
2015-07-01 23:23:15 +00:00
|
|
|
|
/* Copy and strip leading and trailing whitespace */
|
|
|
|
|
file_part_stripped = g_strstrip (g_strdup (file_part));
|
|
|
|
|
|
|
|
|
|
if (!file_part_stripped || file_part_stripped[0] == '\0')
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
*file_ret = current_folder;
|
|
|
|
|
*is_well_formed_ret = TRUE;
|
|
|
|
|
*is_file_part_empty_ret = TRUE;
|
|
|
|
|
*is_folder = TRUE;
|
|
|
|
|
|
2015-07-01 23:23:15 +00:00
|
|
|
|
g_free (file_part_stripped);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*is_file_part_empty_ret = FALSE;
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
2015-07-01 23:23:15 +00:00
|
|
|
|
file = g_file_get_child_for_display_name (current_folder, file_part_stripped, &error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_unref (current_folder);
|
2015-07-01 23:23:15 +00:00
|
|
|
|
g_free (file_part_stripped);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
|
{
|
|
|
|
|
error_building_filename_dialog (impl, error);
|
|
|
|
|
*file_ret = NULL;
|
|
|
|
|
*is_well_formed_ret = FALSE;
|
|
|
|
|
*is_folder = FALSE;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*file_ret = file;
|
|
|
|
|
*is_well_formed_ret = TRUE;
|
|
|
|
|
*is_folder = _gtk_file_chooser_entry_get_is_folder (chooser_entry, file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct get_files_closure {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
2020-07-09 05:29:20 +00:00
|
|
|
|
GListStore *result;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *file_from_entry;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_files_foreach (GtkTreeModel *model,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-03 14:52:39 +00:00
|
|
|
|
GtkFileSystemModel *fs_model = GTK_FILE_SYSTEM_MODEL (model);
|
|
|
|
|
struct get_files_closure *info = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
file = _gtk_file_system_model_get_file (fs_model, iter);
|
|
|
|
|
|
|
|
|
|
if (!info->file_from_entry || !g_file_equal (info->file_from_entry, file))
|
2020-07-09 05:29:20 +00:00
|
|
|
|
g_list_store_append (info->result, file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
|
static GListModel *
|
|
|
|
|
get_selected_files_as_model (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GListStore *store;
|
|
|
|
|
GSList *files, *l;
|
|
|
|
|
|
|
|
|
|
store = g_list_store_new (G_TYPE_FILE);
|
|
|
|
|
files = get_selected_files (impl);
|
|
|
|
|
for (l = files; l; l = l->next)
|
|
|
|
|
g_list_store_append (store, l->data);
|
|
|
|
|
g_slist_free_full (files, g_object_unref);
|
|
|
|
|
|
|
|
|
|
return G_LIST_MODEL (store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GListModel *
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_file_chooser_widget_get_files (GtkFileChooser *chooser)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
struct get_files_closure info;
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
GtkWidget *current_focus;
|
|
|
|
|
gboolean file_list_seen;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2020-07-09 05:29:20 +00:00
|
|
|
|
return get_selected_files_as_model (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_RECENT)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
file_list_seen = TRUE;
|
|
|
|
|
goto file_entry;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2020-07-09 05:29:20 +00:00
|
|
|
|
return get_selected_files_as_model (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
|
info.impl = impl;
|
|
|
|
|
info.result = g_list_store_new (G_TYPE_FILE);
|
|
|
|
|
info.file_from_entry = NULL;
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
|
|
|
|
if (toplevel)
|
2019-03-02 13:49:00 +00:00
|
|
|
|
current_focus = gtk_root_get_focus (GTK_ROOT (toplevel));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
current_focus = NULL;
|
|
|
|
|
|
|
|
|
|
file_list_seen = FALSE;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (current_focus == impl->browse_files_tree_view)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
file_list:
|
|
|
|
|
|
|
|
|
|
file_list_seen = TRUE;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, get_files_foreach, &info);
|
|
|
|
|
|
|
|
|
|
/* If there is no selection in the file list, we probably have this situation:
|
|
|
|
|
*
|
|
|
|
|
* 1. The user typed a filename in the SAVE filename entry ("foo.txt").
|
|
|
|
|
* 2. He then double-clicked on a folder ("bar") in the file list
|
|
|
|
|
*
|
|
|
|
|
* So we want the selection to be "bar/foo.txt". Jump to the case for the
|
|
|
|
|
* filename entry to see if that is the case.
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (info.result == NULL && impl->location_entry)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto file_entry;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->location_entry && current_focus == impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean is_well_formed, is_empty, is_file_part_empty, is_folder;
|
|
|
|
|
|
|
|
|
|
file_entry:
|
|
|
|
|
|
|
|
|
|
check_save_entry (impl, &info.file_from_entry, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
|
|
|
|
|
|
|
|
|
|
if (is_empty)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto out;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (!is_well_formed)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (info.file_from_entry)
|
2020-07-09 05:29:20 +00:00
|
|
|
|
g_list_store_append (info.result, info.file_from_entry);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
else if (!file_list_seen)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto file_list;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto file_list;
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto file_entry;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* The focus is on a dialog's action area button or something else */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto file_entry;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto file_list;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* If there's no folder selected, and we're in SELECT_FOLDER mode,
|
|
|
|
|
* then we fall back to the current directory
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER &&
|
2014-01-28 09:30:33 +00:00
|
|
|
|
info.result == NULL)
|
|
|
|
|
{
|
|
|
|
|
GFile *current_folder;
|
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
current_folder = gtk_file_chooser_get_current_folder (chooser);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (current_folder)
|
2020-07-09 05:29:20 +00:00
|
|
|
|
g_list_store_append (info.result, current_folder);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
|
return G_LIST_MODEL (info.result);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Shows or hides the filter widgets */
|
|
|
|
|
static void
|
|
|
|
|
show_filters (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean show)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_visible (impl->filter_combo_hbox, show);
|
2014-05-24 04:00:00 +00:00
|
|
|
|
update_extra_and_filters (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_add_filter (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileFilter *filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
if (g_list_store_find (impl->filters, filter, NULL))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("gtk_file_chooser_add_filter() called on filter already in list");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_ref_sink (filter);
|
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
g_list_store_append (impl->filters, filter);
|
|
|
|
|
g_object_unref (filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
if (!impl->current_filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
set_current_filter (impl, filter);
|
|
|
|
|
|
|
|
|
|
show_filters (impl, TRUE);
|
2020-07-06 14:34:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (chooser), "filters");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_remove_filter (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileFilter *filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
2019-12-22 01:12:11 +00:00
|
|
|
|
guint filter_index;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
if (!g_list_store_find (impl->filters, filter, &filter_index))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("gtk_file_chooser_remove_filter() called on filter not in list");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
g_list_store_remove (impl->filters, filter_index);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (filter == impl->current_filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->filters)
|
2019-12-22 01:12:11 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileFilter *f = g_list_model_get_item (G_LIST_MODEL (impl->filters), 0);
|
|
|
|
|
set_current_filter (impl, f);
|
|
|
|
|
g_object_unref (f);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_current_filter (impl, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (filter);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->filters)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
show_filters (impl, FALSE);
|
2020-07-06 14:34:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (chooser), "filters");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 16:15:47 +00:00
|
|
|
|
static GListModel *
|
|
|
|
|
gtk_file_chooser_widget_get_filters (GtkFileChooser *chooser)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
2019-12-22 01:12:11 +00:00
|
|
|
|
|
2020-07-04 16:15:47 +00:00
|
|
|
|
return G_LIST_MODEL (g_object_ref (impl->filters));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_file_chooser_widget_add_shortcut_folder (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_add_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file);
|
2020-07-06 15:03:02 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (chooser), "shortcut-folders");
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_file_chooser_widget_remove_shortcut_folder (GtkFileChooser *chooser,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *file,
|
|
|
|
|
GError **error)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_sidebar_remove_shortcut (GTK_PLACES_SIDEBAR (impl->places_sidebar), file);
|
2020-07-06 15:03:02 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (chooser), "shortcut-folders");
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-05 02:08:33 +00:00
|
|
|
|
static GListModel *
|
|
|
|
|
gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
|
2020-07-05 02:08:33 +00:00
|
|
|
|
return gtk_places_sidebar_get_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct switch_folder_closure {
|
|
|
|
|
GtkFileChooserWidget *impl;
|
|
|
|
|
GFile *file;
|
|
|
|
|
int num_selected;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Used from gtk_tree_selection_selected_foreach() in switch_to_selected_folder() */
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
switch_folder_foreach_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
struct switch_folder_closure *closure;
|
|
|
|
|
|
|
|
|
|
closure = data;
|
|
|
|
|
|
2015-02-14 01:43:06 +00:00
|
|
|
|
closure->file = _gtk_file_system_model_get_file (GTK_FILE_SYSTEM_MODEL (model), iter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
closure->num_selected++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Changes to the selected folder in the list view */
|
|
|
|
|
static void
|
|
|
|
|
switch_to_selected_folder (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
struct switch_folder_closure closure;
|
|
|
|
|
|
|
|
|
|
/* We do this with foreach() rather than get_selected() as we may be in
|
|
|
|
|
* multiple selection mode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
closure.impl = impl;
|
|
|
|
|
closure.file = NULL;
|
|
|
|
|
closure.num_selected = 0;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, switch_folder_foreach_cb, &closure);
|
|
|
|
|
|
|
|
|
|
g_assert (closure.file && closure.num_selected == 1);
|
|
|
|
|
|
|
|
|
|
change_folder_and_display_error (impl, closure.file, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Gets the GFileInfo for the selected row in the file list; assumes single
|
|
|
|
|
* selection mode.
|
|
|
|
|
*/
|
|
|
|
|
static GFileInfo *
|
|
|
|
|
get_selected_file_info_from_file_list (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean *had_selection)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GFileInfo *info;
|
2016-02-13 01:35:26 +00:00
|
|
|
|
GtkTreeModel *model;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (!impl->select_multiple);
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2016-02-13 01:35:26 +00:00
|
|
|
|
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
*had_selection = FALSE;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*had_selection = TRUE;
|
|
|
|
|
|
2016-02-13 01:35:26 +00:00
|
|
|
|
info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), &iter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Gets the display name of the selected file in the file list; assumes single
|
|
|
|
|
* selection mode and that something is selected.
|
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
|
static const char *
|
2014-01-28 09:30:33 +00:00
|
|
|
|
get_display_name_from_file_list (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
gboolean had_selection;
|
|
|
|
|
|
|
|
|
|
info = get_selected_file_info_from_file_list (impl, &had_selection);
|
|
|
|
|
g_assert (had_selection);
|
|
|
|
|
g_assert (info != NULL);
|
|
|
|
|
|
|
|
|
|
return g_file_info_get_display_name (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_custom_button_to_dialog (GtkDialog *dialog,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *mnemonic_label,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int response_id)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
|
|
button = gtk_button_new_with_mnemonic (mnemonic_label);
|
|
|
|
|
|
|
|
|
|
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
/* Every time we request a response explicitly, we need to save the selection to
|
|
|
|
|
* the recently-used list, as requesting a response means, “the dialog is confirmed”.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
2020-04-30 13:41:57 +00:00
|
|
|
|
static void
|
|
|
|
|
request_response_and_add_to_recent_list (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-07-12 16:14:32 +00:00
|
|
|
|
gtk_widget_activate_action (GTK_WIDGET (impl), "response.activate", NULL);
|
2020-04-30 13:41:57 +00:00
|
|
|
|
add_selection_to_recent_list (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_confirm_overwrite_response (GtkWidget *dialog,
|
|
|
|
|
int response,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
|
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
|
{
|
|
|
|
|
/* Dialog is now going to be closed, so prevent any button/key presses to
|
|
|
|
|
* file list (will be restablished on next map()). Fixes data loss bug #2288 */
|
|
|
|
|
impl->browse_files_interaction_frozen = TRUE;
|
|
|
|
|
|
|
|
|
|
request_response_and_add_to_recent_list (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Presents an overwrite confirmation dialog */
|
|
|
|
|
static void
|
2014-01-28 09:30:33 +00:00
|
|
|
|
confirm_dialog_should_accept_filename (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *file_part,
|
|
|
|
|
const char *folder_display_name)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWindow *toplevel;
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
|
|
toplevel = get_toplevel (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (toplevel,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
|
_("A file named “%s” already exists. Do you want to replace it?"),
|
|
|
|
|
file_part);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
2015-07-04 00:53:54 +00:00
|
|
|
|
_("The file already exists in “%s”. Replacing it will "
|
|
|
|
|
"overwrite its contents."),
|
|
|
|
|
folder_display_name);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
|
|
|
|
|
add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
|
|
if (gtk_window_has_group (toplevel))
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-04-30 13:41:57 +00:00
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
|
G_CALLBACK (on_confirm_overwrite_response),
|
|
|
|
|
impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct GetDisplayNameData
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl;
|
2020-07-24 18:40:36 +00:00
|
|
|
|
char *file_part;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
confirmation_confirm_get_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
struct GetDisplayNameData *data = user_data;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFileInfo *info;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&data->impl->should_respond_get_info_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
|
|
|
|
if (!info)
|
2020-04-30 13:41:57 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
confirm_dialog_should_accept_filename (data->impl, data->file_part,
|
|
|
|
|
g_file_info_get_display_name (info));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (data->impl, FALSE);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_object_unref (data->impl);
|
|
|
|
|
g_free (data->file_part);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&info);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Does overwrite confirmation if appropriate, and returns whether the dialog
|
|
|
|
|
* should respond. Can get the file part from the file list or the save entry.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
should_respond_after_confirm_overwrite (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *file_part,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GFile *parent_file)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-02-21 15:52:47 +00:00
|
|
|
|
struct GetDisplayNameData *data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-21 15:52:47 +00:00
|
|
|
|
g_assert (file_part != NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-02-21 15:52:47 +00:00
|
|
|
|
data = g_new0 (struct GetDisplayNameData, 1);
|
|
|
|
|
data->impl = g_object_ref (impl);
|
|
|
|
|
data->file_part = g_strdup (file_part);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->should_respond_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->should_respond_get_info_cancellable);
|
|
|
|
|
|
|
|
|
|
impl->should_respond_get_info_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (parent_file,
|
|
|
|
|
"standard::display-name",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->should_respond_get_info_cancellable,
|
|
|
|
|
confirmation_confirm_get_info_cb,
|
|
|
|
|
data);
|
2020-02-21 15:52:47 +00:00
|
|
|
|
set_busy_cursor (data->impl, TRUE);
|
|
|
|
|
return FALSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
name_entry_get_parent_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
|
|
|
|
struct FileExistsData *data = user_data;
|
|
|
|
|
GFileInfo *info;
|
2015-08-22 16:20:17 +00:00
|
|
|
|
gboolean parent_is_folder = FALSE;
|
|
|
|
|
gboolean parent_is_accessible = FALSE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GError *error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->should_respond_get_info_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, &error);
|
2015-08-22 16:20:17 +00:00
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
parent_is_folder = _gtk_file_info_consider_as_directory (info);
|
2016-01-20 10:36:12 +00:00
|
|
|
|
|
|
|
|
|
/* Some gvfs backends do not set executable attribute, let's assume that
|
|
|
|
|
* the folder is accessible even if the attribute is not set.
|
|
|
|
|
*/
|
|
|
|
|
parent_is_accessible = !g_file_info_has_attribute (info, "access::can-execute") ||
|
2015-08-22 16:20:17 +00:00
|
|
|
|
g_file_info_get_attribute_boolean (info, "access::can-execute");
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-08-22 16:20:17 +00:00
|
|
|
|
if (parent_is_folder && parent_is_accessible)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
request_response_and_add_to_recent_list (impl); /* even if the file doesn't exist, apps can make good use of that (e.g. Emacs) */
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (data->file_exists_and_is_not_folder)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean retval;
|
|
|
|
|
char *file_part;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Dup the string because the string may be modified
|
|
|
|
|
* depending on what clients do in the confirm-overwrite
|
|
|
|
|
* signal and this corrupts the pointer
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
file_part = g_strdup (_gtk_file_chooser_entry_get_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry)));
|
2015-07-04 00:53:54 +00:00
|
|
|
|
retval = should_respond_after_confirm_overwrite (impl, file_part, data->parent_file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_free (file_part);
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (retval)
|
|
|
|
|
request_response_and_add_to_recent_list (impl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
request_response_and_add_to_recent_list (impl);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GError *mkdir_error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* In both cases (SELECT_FOLDER and CREATE_FOLDER), if you type
|
|
|
|
|
* "/blah/nonexistent" you *will* want a folder created.
|
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
g_file_make_directory (data->file, NULL, &mkdir_error);
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (!mkdir_error)
|
|
|
|
|
request_response_and_add_to_recent_list (impl);
|
|
|
|
|
else
|
|
|
|
|
error_creating_folder_dialog (impl, data->file, mkdir_error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_assert_not_reached ();
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2015-08-22 16:20:17 +00:00
|
|
|
|
else if (parent_is_folder)
|
|
|
|
|
{
|
2016-10-15 20:30:47 +00:00
|
|
|
|
GError *internal_error;
|
2015-08-22 16:20:17 +00:00
|
|
|
|
|
2016-10-15 20:30:47 +00:00
|
|
|
|
internal_error = NULL;
|
|
|
|
|
g_set_error_literal (&internal_error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
|
2015-08-22 16:20:17 +00:00
|
|
|
|
_("You do not have access to the specified folder."));
|
|
|
|
|
|
2016-10-15 20:30:47 +00:00
|
|
|
|
error_changing_folder_dialog (impl, data->parent_file, internal_error);
|
2015-08-22 16:20:17 +00:00
|
|
|
|
}
|
|
|
|
|
else if (info)
|
|
|
|
|
{
|
|
|
|
|
/* The parent exists, but it's not a folder!
|
|
|
|
|
* Someone probably typed existing_file.txt/subfile.txt
|
|
|
|
|
*/
|
|
|
|
|
error_with_file_under_nonfolder (impl, data->parent_file);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-22 16:20:17 +00:00
|
|
|
|
GError *error_copy;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-08-22 16:20:17 +00:00
|
|
|
|
/* The parent folder is not readable for some reason */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-08-22 16:20:17 +00:00
|
|
|
|
error_copy = g_error_copy (error);
|
|
|
|
|
error_changing_folder_dialog (impl, data->parent_file, error_copy);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (data->impl);
|
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
g_object_unref (data->parent_file);
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
g_clear_object (&info);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-07-12 03:17:40 +00:00
|
|
|
|
file_exists_get_info_cb (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer user_data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GFile *file = G_FILE (source);
|
|
|
|
|
struct FileExistsData *data = user_data;
|
|
|
|
|
GFileInfo *info;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gboolean data_ownership_taken = FALSE;
|
|
|
|
|
gboolean file_exists;
|
|
|
|
|
gboolean is_folder;
|
|
|
|
|
gboolean needs_parent_check = FALSE;
|
|
|
|
|
GtkFileChooserWidget *impl = data->impl;
|
2020-07-12 03:17:40 +00:00
|
|
|
|
GError *error = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_exists_get_info_cancellable);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
info = g_file_query_info_finish (file, result, &error);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
file_exists = (info != NULL);
|
|
|
|
|
is_folder = (file_exists && _gtk_file_info_consider_as_directory (info));
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (is_folder)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
change_folder_and_display_error (impl, data->file, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (file_exists)
|
|
|
|
|
request_response_and_add_to_recent_list (impl); /* user typed an existing filename; we are done */
|
|
|
|
|
else
|
|
|
|
|
needs_parent_check = TRUE; /* file doesn't exist; see if its parent exists */
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (!file_exists)
|
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
needs_parent_check = TRUE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (is_folder)
|
|
|
|
|
{
|
|
|
|
|
/* User typed a folder; we are done */
|
|
|
|
|
request_response_and_add_to_recent_list (impl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
error_selecting_folder_over_existing_file_dialog (impl);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (is_folder)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
change_folder_and_display_error (impl, data->file, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
if (!file_exists && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FILENAME_TOO_LONG))
|
|
|
|
|
error_filename_to_long_dialog (data->impl);
|
|
|
|
|
else
|
|
|
|
|
needs_parent_check = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (needs_parent_check)
|
|
|
|
|
{
|
|
|
|
|
/* check that everything up to the last path component exists (i.e. the parent) */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
data->file_exists_and_is_not_folder = file_exists && !is_folder;
|
|
|
|
|
data_ownership_taken = TRUE;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->should_respond_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->should_respond_get_info_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->should_respond_get_info_cancellable);
|
|
|
|
|
|
|
|
|
|
impl->should_respond_get_info_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (data->parent_file,
|
|
|
|
|
"standard::type,access::can-execute",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->should_respond_get_info_cancellable,
|
|
|
|
|
name_entry_get_parent_info_cb,
|
|
|
|
|
data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data_ownership_taken)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (impl);
|
|
|
|
|
g_object_unref (data->file);
|
|
|
|
|
g_object_unref (data->parent_file);
|
|
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
g_clear_object (&info);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-11-29 08:52:38 +00:00
|
|
|
|
paste_text_received (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2017-11-29 08:52:38 +00:00
|
|
|
|
GtkFileChooserWidget *impl = data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *file;
|
2017-11-29 08:52:38 +00:00
|
|
|
|
char *text;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2017-11-29 08:52:38 +00:00
|
|
|
|
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (source), result, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (!text)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
file = g_file_new_for_uri (text);
|
|
|
|
|
|
|
|
|
|
if (!gtk_file_chooser_widget_select_file (GTK_FILE_CHOOSER (impl), file, NULL))
|
|
|
|
|
location_popup_handler (impl, text);
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
2017-11-29 08:52:38 +00:00
|
|
|
|
g_free (text);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "location-popup-on-paste" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
location_popup_on_paste_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2017-11-29 08:52:38 +00:00
|
|
|
|
GdkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (impl));
|
|
|
|
|
|
|
|
|
|
gdk_clipboard_read_text_async (clipboard,
|
|
|
|
|
NULL,
|
|
|
|
|
paste_text_received,
|
|
|
|
|
impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Implementation for GtkFileChooserEmbed::should_respond() */
|
|
|
|
|
static void
|
|
|
|
|
add_selection_to_recent_list (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-07-09 05:29:20 +00:00
|
|
|
|
GListModel *files;
|
|
|
|
|
guint i, n;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
files = gtk_file_chooser_widget_get_files (GTK_FILE_CHOOSER (impl));
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->recent_manager)
|
|
|
|
|
impl->recent_manager = gtk_recent_manager_get_default ();
|
2019-08-30 05:37:55 +00:00
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
|
n = g_list_model_get_n_items (files);
|
|
|
|
|
for (i = 0; i < n; i++)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-09 05:29:20 +00:00
|
|
|
|
GFile *file = g_list_model_get_item (files, i);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
|
if (uri)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_recent_manager_add_item (impl->recent_manager, uri);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
2020-07-09 05:29:20 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 05:29:20 +00:00
|
|
|
|
g_object_unref (files);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 14:34:27 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_file_chooser_widget_should_respond (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
GtkWidget *current_focus;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (impl)));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_assert (GTK_IS_WINDOW (toplevel));
|
|
|
|
|
|
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
2019-03-02 13:49:00 +00:00
|
|
|
|
current_focus = gtk_root_get_focus (GTK_ROOT (toplevel));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (current_focus == impl->browse_files_tree_view)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
/* The following array encodes what we do based on the impl->action and the
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* number of files selected.
|
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
2015-07-04 00:53:54 +00:00
|
|
|
|
NOOP, /* Do nothing (don't respond) */
|
|
|
|
|
RESPOND, /* Respond immediately */
|
|
|
|
|
RESPOND_OR_SWITCH, /* Respond immediately if the selected item is a file; switch to it if it is a folder */
|
|
|
|
|
ALL_FILES, /* Respond only if everything selected is a file */
|
|
|
|
|
ALL_FOLDERS, /* Respond only if everything selected is a folder */
|
|
|
|
|
SAVE_ENTRY, /* Go to the code for handling the save entry */
|
|
|
|
|
NOT_REACHED /* Sanity check */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
} ActionToTake;
|
2020-02-22 14:54:48 +00:00
|
|
|
|
static const ActionToTake what_to_do[3][3] = {
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* 0 selected 1 selected many selected */
|
|
|
|
|
/* ACTION_OPEN */ { NOOP, RESPOND_OR_SWITCH, ALL_FILES },
|
|
|
|
|
/* ACTION_SAVE */ { SAVE_ENTRY, RESPOND_OR_SWITCH, NOT_REACHED },
|
|
|
|
|
/* ACTION_SELECT_FOLDER */ { RESPOND, ALL_FOLDERS, ALL_FOLDERS },
|
2014-01-28 09:30:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int num_selected;
|
|
|
|
|
gboolean all_files, all_folders;
|
|
|
|
|
int k;
|
|
|
|
|
ActionToTake action;
|
|
|
|
|
|
|
|
|
|
file_list:
|
|
|
|
|
|
2020-04-19 22:00:37 +00:00
|
|
|
|
g_assert (impl->action >= GTK_FILE_CHOOSER_ACTION_OPEN && impl->action <= GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_RECENT)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto save_entry;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
retval = recent_should_respond (impl);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
selection_check (impl, &num_selected, &all_files, &all_folders);
|
|
|
|
|
|
|
|
|
|
if (num_selected > 2)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
k = 2;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
k = num_selected;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
action = what_to_do [impl->action] [k];
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
switch (action)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
case NOOP:
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
case RESPOND:
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
case RESPOND_OR_SWITCH:
|
|
|
|
|
g_assert (num_selected == 1);
|
|
|
|
|
|
|
|
|
|
if (all_folders)
|
|
|
|
|
{
|
|
|
|
|
switch_to_selected_folder (impl);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
retval = should_respond_after_confirm_overwrite (impl,
|
|
|
|
|
get_display_name_from_file_list (impl),
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->current_folder);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ALL_FILES:
|
|
|
|
|
retval = all_files;
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
case ALL_FOLDERS:
|
|
|
|
|
retval = all_folders;
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
case SAVE_ENTRY:
|
|
|
|
|
goto save_entry;
|
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case NOT_REACHED:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if ((impl->location_entry != NULL) && (current_focus == impl->location_entry))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
gboolean is_well_formed, is_empty, is_file_part_empty;
|
|
|
|
|
gboolean is_folder;
|
|
|
|
|
GtkFileChooserEntry *entry;
|
|
|
|
|
|
|
|
|
|
save_entry:
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
|
|
|
|
|
((impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) &&
|
|
|
|
|
impl->location_mode == LOCATION_MODE_FILENAME_ENTRY));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
entry = GTK_FILE_CHOOSER_ENTRY (impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
check_save_entry (impl, &file, &is_well_formed, &is_empty, &is_file_part_empty, &is_folder);
|
|
|
|
|
|
|
|
|
|
if (!is_well_formed)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
if (!is_empty &&
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE &&
|
|
|
|
|
impl->operation_mode == OPERATION_MODE_RECENT)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: ERROR_NO_FOLDER */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#if 0
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* We'll #ifdef this out, as the fucking treeview selects its first row,
|
|
|
|
|
* thus changing our assumption that no selection is present - setting
|
|
|
|
|
* a selection causes the error message from path_bar_set_mode() to go away,
|
|
|
|
|
* but we want the user to see that message!
|
|
|
|
|
*/
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->browse_files_tree_view);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
#endif
|
2015-07-04 00:53:54 +00:00
|
|
|
|
}
|
|
|
|
|
/* FIXME: else show an "invalid filename" error as the pathbar mode? */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (is_empty)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: ERROR_NO_FILENAME */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->location_entry);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
goto file_list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert (file != NULL);
|
|
|
|
|
|
|
|
|
|
if (is_folder)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
change_folder_and_display_error (impl, file, TRUE);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
/* The folder already exists, so we do not need to create it.
|
|
|
|
|
* Just respond to terminate the dialog.
|
|
|
|
|
*/
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
{
|
|
|
|
|
struct FileExistsData *data;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* We need to check whether file exists and whether it is a folder -
|
|
|
|
|
* the GtkFileChooserEntry *does* report is_folder==FALSE as a false
|
|
|
|
|
* negative (it doesn't know yet if your last path component is a
|
|
|
|
|
* folder).
|
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
data = g_new0 (struct FileExistsData, 1);
|
|
|
|
|
data->impl = g_object_ref (impl);
|
|
|
|
|
data->file = g_object_ref (file);
|
|
|
|
|
data->parent_file = _gtk_file_chooser_entry_get_current_folder (entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->file_exists_get_info_cancellable)
|
|
|
|
|
g_cancellable_cancel (impl->file_exists_get_info_cancellable);
|
2020-07-12 03:17:40 +00:00
|
|
|
|
g_clear_object (&impl->file_exists_get_info_cancellable);
|
|
|
|
|
|
|
|
|
|
impl->file_exists_get_info_cancellable = g_cancellable_new ();
|
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
"standard::type",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
|
impl->file_exists_get_info_cancellable,
|
|
|
|
|
file_exists_get_info_cb,
|
|
|
|
|
data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->toplevel_last_focus_widget == impl->browse_files_tree_view)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* The focus is on a dialog's action area button, *and* the widget that
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* was focused immediately before it is the file list.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
goto file_list;
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->operation_mode == OPERATION_MODE_SEARCH && impl->toplevel_last_focus_widget == impl->search_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-01-28 21:02:03 +00:00
|
|
|
|
search_entry_activate_cb (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
/* The focus is on a dialog's action area button, *and* the widget that
|
|
|
|
|
* was focused immediately before it is the location entry.
|
|
|
|
|
*/
|
|
|
|
|
goto save_entry;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* The focus is on a dialog's action area button or something else */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
goto save_entry;
|
|
|
|
|
else
|
2015-07-04 00:53:54 +00:00
|
|
|
|
goto file_list;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
|
|
if (retval)
|
|
|
|
|
add_selection_to_recent_list (impl);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 14:34:27 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_file_chooser_widget_initial_focus (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_mode == LOCATION_MODE_PATH_BAR
|
|
|
|
|
|| impl->operation_mode == OPERATION_MODE_RECENT)
|
|
|
|
|
widget = impl->browse_files_tree_view;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
2020-03-28 20:14:43 +00:00
|
|
|
|
widget = impl->location_entry;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
|
|
|
|
widget = impl->location_entry;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert (widget != NULL);
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-09 01:31:40 +00:00
|
|
|
|
selected_foreach_get_file_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GSList **list;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
list = data;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* The file already has a new ref courtesy of gtk_tree_model_get();
|
|
|
|
|
* this will be unreffed by the caller
|
|
|
|
|
*/
|
|
|
|
|
*list = g_slist_prepend (*list, file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GSList *
|
2015-07-09 01:31:40 +00:00
|
|
|
|
get_selected_files (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GSList *result;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, selected_foreach_get_file_cb, &result);
|
|
|
|
|
result = g_slist_reverse (result);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
selected_foreach_get_info_cb (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GSList **list;
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
|
|
list = data;
|
|
|
|
|
|
|
|
|
|
info = _gtk_file_system_model_get_info (GTK_FILE_SYSTEM_MODEL (model), iter);
|
|
|
|
|
*list = g_slist_prepend (*list, g_object_ref (info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
|
get_selected_infos (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GSList *result;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2015-07-09 01:31:40 +00:00
|
|
|
|
gtk_tree_selection_selected_foreach (selection, selected_foreach_get_info_cb, &result);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
result = g_slist_reverse (result);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 16:20:21 +00:00
|
|
|
|
/* Callback used from GtkSearchEngine when we get new hits */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
2015-06-18 16:20:21 +00:00
|
|
|
|
search_engine_hits_added_cb (GtkSearchEngine *engine,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GList *hits,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-06-18 19:18:30 +00:00
|
|
|
|
GList *l, *files, *files_with_info, *infos;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GFile *file;
|
|
|
|
|
|
2015-06-18 16:20:21 +00:00
|
|
|
|
files = NULL;
|
2015-06-18 19:18:30 +00:00
|
|
|
|
files_with_info = NULL;
|
|
|
|
|
infos = NULL;
|
2015-06-18 16:20:21 +00:00
|
|
|
|
for (l = hits; l; l = l->next)
|
|
|
|
|
{
|
2015-06-18 18:31:02 +00:00
|
|
|
|
GtkSearchHit *hit = (GtkSearchHit *)l->data;
|
2015-07-24 04:40:59 +00:00
|
|
|
|
file = g_object_ref (hit->file);
|
2015-06-18 19:18:30 +00:00
|
|
|
|
if (hit->info)
|
|
|
|
|
{
|
|
|
|
|
files_with_info = g_list_prepend (files_with_info, file);
|
|
|
|
|
infos = g_list_prepend (infos, g_object_ref (hit->info));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
files = g_list_prepend (files, file);
|
2015-06-18 16:20:21 +00:00
|
|
|
|
}
|
2015-05-02 03:04:35 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_update_files (impl->search_model,
|
2015-06-18 19:18:30 +00:00
|
|
|
|
files_with_info, infos);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_add_and_query_files (impl->search_model,
|
2015-06-18 19:18:30 +00:00
|
|
|
|
files, MODEL_ATTRIBUTES);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-06-18 16:20:21 +00:00
|
|
|
|
g_list_free_full (files, g_object_unref);
|
2015-06-18 19:18:30 +00:00
|
|
|
|
g_list_free_full (files_with_info, g_object_unref);
|
|
|
|
|
g_list_free_full (infos, g_object_unref);
|
2015-07-03 06:08:59 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "list");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used from GtkSearchEngine when the query is done running */
|
|
|
|
|
static void
|
|
|
|
|
search_engine_finished_cb (GtkSearchEngine *engine,
|
2020-05-16 22:00:22 +00:00
|
|
|
|
gboolean got_results,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-15 04:03:09 +00:00
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
set_busy_cursor (impl, FALSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_hide (impl->search_spinner);
|
2015-07-03 06:08:59 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->show_progress_timeout)
|
2015-07-03 06:08:59 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_source_remove (impl->show_progress_timeout);
|
|
|
|
|
impl->show_progress_timeout = 0;
|
2015-07-03 06:08:59 +00:00
|
|
|
|
}
|
2015-05-02 03:04:35 +00:00
|
|
|
|
|
2020-05-16 22:00:22 +00:00
|
|
|
|
if (!got_results)
|
2015-10-02 03:32:30 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (impl->browse_files_stack), "empty");
|
|
|
|
|
gtk_widget_grab_focus (impl->search_entry);
|
2015-10-02 03:32:30 +00:00
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
search_engine_error_cb (GtkSearchEngine *engine,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *message,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (data);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
search_stop_searching (impl, TRUE);
|
|
|
|
|
error_message (impl, _("Could not send the search request"), message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Frees the data in the search_model */
|
|
|
|
|
static void
|
2015-07-02 23:12:55 +00:00
|
|
|
|
search_clear_model (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean remove)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->search_model)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (remove &&
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)) == GTK_TREE_MODEL (impl->search_model))
|
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
|
2015-07-02 23:12:55 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_clear_object (&impl->search_model);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stops any ongoing searches; does not touch the search_model */
|
|
|
|
|
static void
|
|
|
|
|
search_stop_searching (GtkFileChooserWidget *impl,
|
2015-07-03 06:08:59 +00:00
|
|
|
|
gboolean remove_query)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (remove_query && impl->search_entry)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->search_entry), "");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_engine)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_search_engine_stop (impl->search_engine);
|
|
|
|
|
g_signal_handlers_disconnect_by_data (impl->search_engine, impl);
|
|
|
|
|
g_clear_object (&impl->search_engine);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2015-06-27 05:23:16 +00:00
|
|
|
|
set_busy_cursor (impl, FALSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_hide (impl->search_spinner);
|
2015-07-03 06:08:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->show_progress_timeout)
|
2015-07-03 06:08:59 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_source_remove (impl->show_progress_timeout);
|
|
|
|
|
impl->show_progress_timeout = 0;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Creates the search_model and puts it in the tree view */
|
|
|
|
|
static void
|
|
|
|
|
search_setup_model (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->search_model == NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->search_model = _gtk_file_system_model_new (file_system_model_set,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
MODEL_COLUMN_TYPES);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->search_model),
|
2015-07-04 00:53:54 +00:00
|
|
|
|
search_sort_func,
|
|
|
|
|
impl, NULL);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->search_model),
|
2015-06-27 06:22:23 +00:00
|
|
|
|
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
|
|
|
|
GTK_SORT_ASCENDING);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
|
|
|
|
GTK_TREE_MODEL (impl->search_model));
|
2015-07-03 05:35:49 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_name_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_time_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_size_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_type_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_location_column, -1);
|
2015-07-03 05:35:49 +00:00
|
|
|
|
|
2015-07-03 16:22:39 +00:00
|
|
|
|
update_columns (impl, TRUE, _("Modified"));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 06:08:59 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
show_spinner (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_show (impl->search_spinner);
|
|
|
|
|
gtk_spinner_start (GTK_SPINNER (impl->search_spinner));
|
|
|
|
|
impl->show_progress_timeout = 0;
|
2015-07-03 06:08:59 +00:00
|
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Creates a new query with the specified text and launches it */
|
|
|
|
|
static void
|
|
|
|
|
search_start_query (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *query_text)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-06-27 04:21:53 +00:00
|
|
|
|
GFile *file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_stack_get_visible_child (GTK_STACK (impl->browse_files_stack)) == impl->places_view)
|
2015-07-14 17:48:49 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-02 23:12:55 +00:00
|
|
|
|
stop_loading_and_clear_list_model (impl, TRUE);
|
|
|
|
|
recent_clear_model (impl, TRUE);
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
search_stop_searching (impl, FALSE);
|
|
|
|
|
search_clear_model (impl, TRUE);
|
|
|
|
|
search_setup_model (impl);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
set_busy_cursor (impl, TRUE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->show_progress_timeout = g_timeout_add (1500, show_spinner, impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_engine == NULL)
|
|
|
|
|
impl->search_engine = _gtk_search_engine_new ();
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->search_query)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->search_query = gtk_query_new ();
|
|
|
|
|
gtk_query_set_text (impl->search_query, query_text);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2015-02-14 05:48:26 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
file = gtk_places_sidebar_get_location (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
2015-06-27 04:21:53 +00:00
|
|
|
|
if (file)
|
2015-02-14 05:48:26 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_query_set_location (impl->search_query, file);
|
2015-06-27 04:21:53 +00:00
|
|
|
|
g_object_unref (file);
|
2015-02-14 05:48:26 +00:00
|
|
|
|
}
|
2015-07-24 19:37:03 +00:00
|
|
|
|
else
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_query_set_location (impl->search_query, impl->current_folder);
|
2015-02-14 05:48:26 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_search_engine_set_model (impl->search_engine, impl->model_for_search);
|
|
|
|
|
_gtk_search_engine_set_query (impl->search_engine, impl->search_query);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->search_engine, "hits-added",
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_CALLBACK (search_engine_hits_added_cb), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->search_engine, "finished",
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_CALLBACK (search_engine_finished_cb), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_signal_connect (impl->search_engine, "error",
|
2015-07-04 00:53:54 +00:00
|
|
|
|
G_CALLBACK (search_engine_error_cb), impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_search_engine_start (impl->search_engine);
|
2015-07-24 20:26:32 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_query_get_location (impl->search_query) &&
|
|
|
|
|
_gtk_file_consider_as_remote (gtk_query_get_location (impl->search_query)))
|
|
|
|
|
gtk_widget_show (impl->remote_warning_bar);
|
2019-04-29 06:33:02 +00:00
|
|
|
|
|
|
|
|
|
/* We're not showing the file list here already and instead rely on the
|
2020-06-18 07:47:16 +00:00
|
|
|
|
* GtkSearchEntry timeout and the ::hits-added signal from above to
|
2019-04-29 06:33:02 +00:00
|
|
|
|
* switch. */
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the user presses Enter while typing on the search
|
|
|
|
|
* entry; starts the query
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2015-01-28 21:02:03 +00:00
|
|
|
|
search_entry_activate_cb (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
const char *text;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode != OPERATION_MODE_SEARCH)
|
2015-03-03 16:43:14 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (impl->search_entry));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* reset any existing query object */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_set_object (&impl->search_query, NULL);
|
2015-01-24 18:32:31 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_places_view_set_search_query (GTK_PLACES_VIEW (impl->places_view), text);
|
2015-07-14 17:48:49 +00:00
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (text[0] != '\0')
|
|
|
|
|
search_start_query (impl, text);
|
2015-07-15 04:12:33 +00:00
|
|
|
|
else
|
|
|
|
|
search_stop_searching (impl, FALSE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 21:06:02 +00:00
|
|
|
|
static void
|
|
|
|
|
search_entry_stop_cb (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_engine)
|
2015-06-27 05:23:16 +00:00
|
|
|
|
search_stop_searching (impl, FALSE);
|
|
|
|
|
else
|
|
|
|
|
g_object_set (impl, "search-mode", FALSE, NULL);
|
2019-04-28 15:17:32 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->starting_search = FALSE;
|
2015-01-28 21:06:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Hides the path bar and creates the search entry */
|
|
|
|
|
static void
|
|
|
|
|
search_setup_widgets (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
/* if there already is a query, restart it */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->search_query)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *query;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
query = gtk_query_get_text (impl->search_query);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (query)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->search_entry), query);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
search_start_query (impl, query);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_object_unref (impl->search_query);
|
|
|
|
|
impl->search_query = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Recent files support
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Frees the data in the recent_model */
|
|
|
|
|
static void
|
|
|
|
|
recent_clear_model (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
gboolean remove)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->recent_model)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
if (remove)
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_set_object (&impl->recent_model, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-08-30 05:17:31 +00:00
|
|
|
|
recent_start_loading (GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2019-08-30 05:17:31 +00:00
|
|
|
|
GList *items;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
recent_clear_model (impl, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
/* Setup recent model */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->recent_model == NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->recent_model = _gtk_file_system_model_new (file_system_model_set,
|
2019-08-30 05:17:31 +00:00
|
|
|
|
impl,
|
|
|
|
|
MODEL_COLUMN_TYPES);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_set_filter (impl->recent_model, impl->current_filter);
|
|
|
|
|
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (impl->recent_model),
|
2019-08-30 05:17:31 +00:00
|
|
|
|
recent_sort_func,
|
|
|
|
|
impl, NULL);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->recent_model),
|
2019-08-30 05:17:31 +00:00
|
|
|
|
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
|
|
|
|
|
GTK_SORT_DESCENDING);
|
2018-08-28 20:14:16 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (!impl->recent_manager)
|
2019-08-30 05:17:31 +00:00
|
|
|
|
return;
|
2015-07-01 19:51:20 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
items = gtk_recent_manager_get_items (impl->recent_manager);
|
2019-08-30 05:17:31 +00:00
|
|
|
|
if (!items)
|
|
|
|
|
return;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
|
2019-08-30 05:17:31 +00:00
|
|
|
|
{
|
|
|
|
|
const int limit = DEFAULT_RECENT_FILES_LIMIT;
|
2019-08-30 05:30:12 +00:00
|
|
|
|
const char *app_name = g_get_application_name ();
|
2019-08-30 05:17:31 +00:00
|
|
|
|
GList *l;
|
|
|
|
|
int n;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
n = 0;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
for (l = items; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GtkRecentInfo *info = l->data;
|
|
|
|
|
GFile *file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:30:12 +00:00
|
|
|
|
if (gtk_recent_info_get_private_hint (info) &&
|
|
|
|
|
!gtk_recent_info_has_application (info, app_name))
|
2019-08-30 05:17:31 +00:00
|
|
|
|
continue;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:30:12 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
file = g_file_new_for_uri (gtk_recent_info_get_uri (info));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_add_and_query_file (impl->recent_model,
|
2019-08-30 05:17:31 +00:00
|
|
|
|
file,
|
|
|
|
|
MODEL_ATTRIBUTES);
|
|
|
|
|
g_object_unref (file);
|
2019-08-30 05:07:48 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
n++;
|
|
|
|
|
if (limit != -1 && n >= limit)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_set_object (&impl->model_for_search, impl->recent_model);
|
2019-08-30 05:17:31 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GList *folders;
|
|
|
|
|
GList *l;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
folders = _gtk_file_chooser_extract_recent_folders (items);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:17:31 +00:00
|
|
|
|
for (l = folders; l; l = l->next)
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_file_system_model_add_and_query_file (impl->recent_model,
|
2019-08-30 05:17:31 +00:00
|
|
|
|
G_FILE (l->data),
|
|
|
|
|
MODEL_ATTRIBUTES);
|
|
|
|
|
|
|
|
|
|
g_list_free_full (folders, g_object_unref);
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:07:48 +00:00
|
|
|
|
g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
|
|
|
|
GTK_TREE_MODEL (impl->recent_model));
|
|
|
|
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->browse_files_tree_view), -1);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_name_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_time_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_size_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_type_column, -1);
|
|
|
|
|
gtk_tree_view_column_set_sort_column_id (impl->list_location_column, -1);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-30 05:07:48 +00:00
|
|
|
|
update_columns (impl, TRUE, _("Accessed"));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Called from ::should_respond(). We return whether there are selected
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* files in the recent files list.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
recent_should_respond (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_assert (impl->operation_mode == OPERATION_MODE_RECENT);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return (gtk_tree_selection_count_selected_rows (selection) != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_current_filter (GtkFileChooserWidget *impl,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileFilter *filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_filter != filter)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2019-12-22 01:12:11 +00:00
|
|
|
|
guint filter_index;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-02 21:31:29 +00:00
|
|
|
|
/* NULL filters are allowed to reset to non-filtered status */
|
2020-06-05 04:26:56 +00:00
|
|
|
|
if (filter)
|
|
|
|
|
{
|
|
|
|
|
if (!g_list_store_find (impl->filters, filter, &filter_index))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
filter_index = -1;
|
|
|
|
|
}
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_filter)
|
|
|
|
|
g_object_unref (impl->current_filter);
|
|
|
|
|
impl->current_filter = filter;
|
|
|
|
|
if (impl->current_filter)
|
|
|
|
|
g_object_ref_sink (impl->current_filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (impl->filter_combo), filter_index);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-07-02 21:31:29 +00:00
|
|
|
|
clear_model_cache (impl, MODEL_COL_IS_SENSITIVE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
set_model_filter (impl, impl->current_filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
g_object_notify (G_OBJECT (impl), "filter");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-12-22 01:12:11 +00:00
|
|
|
|
filter_combo_changed (GtkDropDown *dropdown,
|
|
|
|
|
GParamSpec *pspec,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2015-07-04 00:53:54 +00:00
|
|
|
|
GtkFileFilter *new_filter;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-06-21 05:20:05 +00:00
|
|
|
|
new_filter = gtk_drop_down_get_selected_item (dropdown);
|
2016-11-15 09:51:41 +00:00
|
|
|
|
|
2020-07-04 14:08:28 +00:00
|
|
|
|
set_current_filter (impl, new_filter);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry != NULL)
|
|
|
|
|
_gtk_file_chooser_entry_set_file_filter (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
|
2016-11-15 09:51:41 +00:00
|
|
|
|
new_filter);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-04 00:53:54 +00:00
|
|
|
|
list_select_func (GtkTreeSelection *selection,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean path_currently_selected,
|
|
|
|
|
gpointer data)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean is_sensitive;
|
|
|
|
|
gboolean is_folder;
|
|
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
|
return FALSE;
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
MODEL_COL_IS_SENSITIVE, &is_sensitive,
|
|
|
|
|
MODEL_COL_IS_FOLDER, &is_folder,
|
|
|
|
|
-1);
|
|
|
|
|
if (!is_sensitive || !is_folder)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
list_selection_changed (GtkTreeSelection *selection,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (gtk_tree_view_get_model (GTK_TREE_VIEW (impl->browse_files_tree_view)) == NULL)
|
2015-07-09 01:06:58 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->location_entry &&
|
|
|
|
|
impl->browse_files_model)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
update_chooser_entry (impl);
|
|
|
|
|
|
2014-04-09 16:18:37 +00:00
|
|
|
|
location_bar_update (impl);
|
2020-07-09 06:06:31 +00:00
|
|
|
|
update_default (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 09:27:42 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
browse_files_tree_view_keynav_failed_cb (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
GtkFileChooserWidget *impl = user_data;
|
2019-04-28 09:27:42 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (direction == GTK_DIR_UP && impl->operation_mode == OPERATION_MODE_SEARCH)
|
2019-04-28 09:27:42 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->search_entry);
|
2019-04-28 09:27:42 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
/* Callback used when a row in the file list is activated */
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
list_row_activated (GtkTreeView *tree_view,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
gboolean is_folder;
|
|
|
|
|
gboolean is_sensitive;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (model, &iter, path))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
MODEL_COL_FILE, &file,
|
|
|
|
|
MODEL_COL_IS_FOLDER, &is_folder,
|
|
|
|
|
MODEL_COL_IS_SENSITIVE, &is_sensitive,
|
|
|
|
|
-1);
|
2015-07-04 00:53:54 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (is_sensitive && is_folder && file)
|
|
|
|
|
{
|
|
|
|
|
change_folder_and_display_error (impl, file, FALSE);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2020-07-09 05:40:08 +00:00
|
|
|
|
gtk_widget_activate_default (GTK_WIDGET (impl));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-04 00:53:54 +00:00
|
|
|
|
path_bar_clicked (GtkPathBar *path_bar,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *child_file,
|
|
|
|
|
gboolean child_is_hidden,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (child_file)
|
|
|
|
|
pending_select_files_add (impl, child_file);
|
|
|
|
|
|
|
|
|
|
if (!change_folder_and_display_error (impl, file, FALSE))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Say we have "/foo/bar/[.baz]" and the user clicks on "bar". We should then
|
|
|
|
|
* show hidden files so that ".baz" appears in the file list, as it will still
|
|
|
|
|
* be shown in the path bar: "/foo/[bar]/.baz"
|
|
|
|
|
*/
|
|
|
|
|
if (child_is_hidden)
|
2020-02-26 10:06:22 +00:00
|
|
|
|
set_show_hidden (impl, TRUE);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_cell_renderer_attributes (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_name_column,
|
|
|
|
|
impl->list_pixbuf_renderer,
|
2017-11-09 02:52:50 +00:00
|
|
|
|
"gicon", MODEL_COL_ICON,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
|
|
|
|
NULL);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_name_column,
|
|
|
|
|
impl->list_name_renderer,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
"text", MODEL_COL_NAME,
|
|
|
|
|
"ellipsize", MODEL_COL_ELLIPSIZE,
|
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_size_column,
|
|
|
|
|
impl->list_size_renderer,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
"text", MODEL_COL_SIZE_TEXT,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_type_column,
|
|
|
|
|
impl->list_type_renderer,
|
2019-06-06 23:02:11 +00:00
|
|
|
|
"text", MODEL_COL_TYPE,
|
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_time_column,
|
|
|
|
|
impl->list_date_renderer,
|
2015-07-02 09:37:59 +00:00
|
|
|
|
"text", MODEL_COL_DATE_TEXT,
|
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_time_column,
|
|
|
|
|
impl->list_time_renderer,
|
2015-07-01 21:04:17 +00:00
|
|
|
|
"text", MODEL_COL_TIME_TEXT,
|
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
NULL);
|
2015-07-01 21:04:17 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_column_set_attributes (impl->list_location_column,
|
|
|
|
|
impl->list_location_renderer,
|
2015-02-14 04:50:06 +00:00
|
|
|
|
"text", MODEL_COL_LOCATION_TEXT,
|
|
|
|
|
"sensitive", MODEL_COL_IS_SENSITIVE,
|
|
|
|
|
NULL);
|
2015-07-02 09:37:59 +00:00
|
|
|
|
|
|
|
|
|
update_time_renderer_visible (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
location_set_user_text (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *path)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (impl->location_entry), path);
|
|
|
|
|
gtk_editable_set_position (GTK_EDITABLE (impl->location_entry), -1);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
location_popup_handler (GtkFileChooserWidget *impl,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *path)
|
2015-01-18 21:18:12 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode != OPERATION_MODE_BROWSE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
change_folder_and_display_error (impl, impl->current_folder, FALSE);
|
2015-04-06 02:27:23 +00:00
|
|
|
|
else
|
|
|
|
|
switch_to_home_dir (impl);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
2015-01-18 21:18:12 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
|
|
|
|
|
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (!path)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
return;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2014-04-08 17:13:01 +00:00
|
|
|
|
location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
location_set_user_text (impl, path);
|
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_grab_focus (impl->location_entry);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
if (path != NULL)
|
2015-07-04 00:53:54 +00:00
|
|
|
|
location_set_user_text (impl, path);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "up-folder" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
up_folder_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_path_bar_up (GTK_PATH_BAR (impl->browse_path_bar));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "down-folder" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
down_folder_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_path_bar_down (GTK_PATH_BAR (impl->browse_path_bar));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "home-folder" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
home_folder_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
switch_to_home_dir (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "desktop-folder" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
desktop_folder_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
2020-02-21 15:11:15 +00:00
|
|
|
|
GFile *file;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* "To disable a directory, point it to the homedir."
|
|
|
|
|
* See http://freedesktop.org/wiki/Software/xdg-user-dirs
|
2015-07-04 00:53:54 +00:00
|
|
|
|
*/
|
|
|
|
|
name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
|
|
|
|
if (!g_strcmp0 (name, g_get_home_dir ()))
|
2014-01-28 09:30:33 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
|
file = g_file_new_for_path (name);
|
|
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (impl), file, NULL);
|
|
|
|
|
g_object_unref (file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "search-shortcut" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
search_shortcut_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
2015-06-29 15:39:22 +00:00
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_BROWSE);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->current_folder)
|
|
|
|
|
change_folder_and_display_error (impl, impl->current_folder, FALSE);
|
2015-06-29 15:39:22 +00:00
|
|
|
|
else
|
|
|
|
|
switch_to_home_dir (impl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_SEARCH);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handler for the "recent-shortcut" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
recent_shortcut_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_RECENT);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 04:24:19 +00:00
|
|
|
|
/* Handler for the "places-shortcut" keybinding signal */
|
|
|
|
|
static void
|
|
|
|
|
places_shortcut_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_child_focus (impl->places_sidebar, GTK_DIR_LEFT);
|
2015-07-07 04:24:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
quick_bookmark_handler (GtkFileChooserWidget *impl,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int bookmark_index)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
file = gtk_places_sidebar_get_nth_bookmark (GTK_PLACES_SIDEBAR (impl->places_sidebar), bookmark_index);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
|
{
|
|
|
|
|
change_folder_and_display_error (impl, file, FALSE);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_hidden_handler (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
set_show_hidden (impl, !impl->show_hidden);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-08-12 01:15:00 +00:00
|
|
|
|
add_normal_and_shifted_binding (GtkWidgetClass *widget_class,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
guint keyval,
|
|
|
|
|
GdkModifierType modifiers,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *signal_name)
|
2014-01-28 09:30:33 +00:00
|
|
|
|
{
|
2018-08-12 01:15:00 +00:00
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
keyval, modifiers,
|
|
|
|
|
signal_name,
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
keyval, modifiers | GDK_SHIFT_MASK,
|
|
|
|
|
signal_name,
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-22 00:00:15 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_size_allocate (GtkWidget *widget,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int baseline)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
|
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->size_allocate (widget, width, height, baseline);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->browse_files_popover)
|
|
|
|
|
gtk_native_check_resize (GTK_NATIVE (impl->browse_files_popover));
|
|
|
|
|
if (impl->rename_file_popover)
|
|
|
|
|
gtk_native_check_resize (GTK_NATIVE (impl->rename_file_popover));
|
2020-03-22 00:00:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
|
|
|
|
|
{
|
|
|
|
|
static const guint quick_bookmark_keyvals[10] = {
|
|
|
|
|
GDK_KEY_1, GDK_KEY_2, GDK_KEY_3, GDK_KEY_4, GDK_KEY_5, GDK_KEY_6, GDK_KEY_7, GDK_KEY_8, GDK_KEY_9, GDK_KEY_0
|
|
|
|
|
};
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_file_chooser_widget_finalize;
|
2014-06-26 22:22:42 +00:00
|
|
|
|
gobject_class->constructed = gtk_file_chooser_widget_constructed;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gobject_class->set_property = gtk_file_chooser_widget_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_file_chooser_widget_get_property;
|
|
|
|
|
gobject_class->dispose = gtk_file_chooser_widget_dispose;
|
|
|
|
|
|
|
|
|
|
widget_class->map = gtk_file_chooser_widget_map;
|
|
|
|
|
widget_class->unmap = gtk_file_chooser_widget_unmap;
|
2019-02-23 06:02:25 +00:00
|
|
|
|
widget_class->root = gtk_file_chooser_widget_root;
|
|
|
|
|
widget_class->unroot = gtk_file_chooser_widget_unroot;
|
2020-02-05 01:46:13 +00:00
|
|
|
|
widget_class->css_changed = gtk_file_chooser_widget_css_changed;
|
2020-03-22 00:00:15 +00:00
|
|
|
|
widget_class->size_allocate = gtk_file_chooser_widget_size_allocate;
|
2020-04-08 11:43:28 +00:00
|
|
|
|
widget_class->grab_focus = gtk_widget_grab_focus_child;
|
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/*
|
|
|
|
|
* Signals
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::location-popup:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
|
|
|
|
* @path: a string that gets put in the text entry for the file name
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::location-popup signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to make the file chooser show a "Location" prompt which
|
|
|
|
|
* the user can use to manually type the name of the file he wishes to select.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The default bindings for this signal are `Control + L` with a @path string
|
|
|
|
|
* of "" (the empty string). It is also bound to `/` with a @path string of
|
|
|
|
|
* "`/`" (a slash): this lets you type `/` and immediately type a path name.
|
|
|
|
|
* On Unix systems, this is bound to `~` (tilde) with a @path string of "~"
|
|
|
|
|
* itself for access to home directories.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[LOCATION_POPUP] =
|
|
|
|
|
g_signal_new_class_handler (I_("location-popup"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (location_popup_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::location-popup-on-paste:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::location-popup-on-paste signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to make the file chooser show a "Location" prompt when the user
|
|
|
|
|
* pastes into a #GtkFileChooserWidget.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Control + V`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[LOCATION_POPUP_ON_PASTE] =
|
|
|
|
|
g_signal_new_class_handler (I_("location-popup-on-paste"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (location_popup_on_paste_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::location-toggle-popup:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::location-toggle-popup signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to toggle the visibility of a "Location" prompt which the user
|
|
|
|
|
* can use to manually type the name of the file he wishes to select.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Control + L`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[LOCATION_TOGGLE_POPUP] =
|
|
|
|
|
g_signal_new_class_handler (I_("location-toggle-popup"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (location_toggle_popup_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::up-folder:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::up-folder signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to make the file chooser go to the parent of the current folder
|
|
|
|
|
* in the file hierarchy.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + Up`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[UP_FOLDER] =
|
|
|
|
|
g_signal_new_class_handler (I_("up-folder"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (up_folder_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::down-folder:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::down-folder signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to make the file chooser go to a child of the current folder
|
|
|
|
|
* in the file hierarchy. The subfolder that will be used is displayed in the
|
|
|
|
|
* path bar widget of the file chooser. For example, if the path bar is showing
|
|
|
|
|
* "/foo/bar/baz", with bar currently displayed, then this will cause the file
|
|
|
|
|
* chooser to switch to the "baz" subfolder.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + Down`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[DOWN_FOLDER] =
|
|
|
|
|
g_signal_new_class_handler (I_("down-folder"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (down_folder_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::home-folder:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::home-folder signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to make the file chooser show the user's home
|
|
|
|
|
* folder in the file list.
|
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + Home`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[HOME_FOLDER] =
|
|
|
|
|
g_signal_new_class_handler (I_("home-folder"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (home_folder_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::desktop-folder:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::desktop-folder signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to make the file chooser show the user's Desktop
|
|
|
|
|
* folder in the file list.
|
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + D`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[DESKTOP_FOLDER] =
|
|
|
|
|
g_signal_new_class_handler (I_("desktop-folder"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (desktop_folder_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::quick-bookmark:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* @bookmark_index: the number of the bookmark to switch to
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::quick-bookmark signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* This is used to make the file chooser switch to the bookmark specified
|
|
|
|
|
* in the @bookmark_index parameter. For example, if you have three bookmarks,
|
|
|
|
|
* you can pass 0, 1, 2 to this signal to switch to each of them, respectively.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + 1`, `Alt + 2`,
|
|
|
|
|
* etc. until `Alt + 0`. Note that in the default binding, that
|
|
|
|
|
* `Alt + 1` is actually defined to switch to the bookmark at index
|
|
|
|
|
* 0, and so on successively; `Alt + 0` is defined to switch to the
|
|
|
|
|
* bookmark at index 10.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[QUICK_BOOKMARK] =
|
|
|
|
|
g_signal_new_class_handler (I_("quick-bookmark"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (quick_bookmark_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_INT);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::show-hidden:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::show-hidden signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to make the file chooser display hidden files.
|
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Control + H`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[SHOW_HIDDEN] =
|
|
|
|
|
g_signal_new_class_handler (I_("show-hidden"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (show_hidden_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::search-shortcut:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::search-shortcut signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to make the file chooser show the search entry.
|
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + S`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[SEARCH_SHORTCUT] =
|
|
|
|
|
g_signal_new_class_handler (I_("search-shortcut"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (search_shortcut_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2014-01-28 10:36:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::recent-shortcut:
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* @widget: the object which received the signal
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* The ::recent-shortcut signal is a [keybinding signal][GtkBindingSignal]
|
2014-01-28 10:36:38 +00:00
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to make the file chooser show the Recent location.
|
|
|
|
|
*
|
2014-02-05 00:29:00 +00:00
|
|
|
|
* The default binding for this signal is `Alt + R`.
|
2014-01-28 10:36:38 +00:00
|
|
|
|
*/
|
2014-01-28 09:30:33 +00:00
|
|
|
|
signals[RECENT_SHORTCUT] =
|
|
|
|
|
g_signal_new_class_handler (I_("recent-shortcut"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (recent_shortcut_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-01-28 09:30:33 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2015-07-07 04:24:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkFileChooserWidget::places-shortcut:
|
|
|
|
|
* @widget: the object which received the signal
|
|
|
|
|
*
|
|
|
|
|
* The ::places-shortcut signal is a [keybinding signal][GtkBindingSignal]
|
|
|
|
|
* which gets emitted when the user asks for it.
|
|
|
|
|
*
|
|
|
|
|
* This is used to move the focus to the places sidebar.
|
|
|
|
|
*
|
|
|
|
|
* The default binding for this signal is `Alt + P`.
|
|
|
|
|
*/
|
|
|
|
|
signals[PLACES_SHORTCUT] =
|
|
|
|
|
g_signal_new_class_handler (I_("places-shortcut"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_CALLBACK (places_shortcut_handler),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2015-07-07 04:24:19 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
GDK_KEY_l, GDK_CONTROL_MASK,
|
|
|
|
|
"location-toggle-popup",
|
|
|
|
|
NULL);
|
2020-03-19 22:03:16 +00:00
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
GDK_KEY_v, GDK_CONTROL_MASK,
|
|
|
|
|
"location-popup-on-paste",
|
|
|
|
|
NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
add_normal_and_shifted_binding (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_Up, GDK_ALT_MASK,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"up-folder");
|
2018-08-12 01:15:00 +00:00
|
|
|
|
add_normal_and_shifted_binding (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_KP_Up, GDK_ALT_MASK,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"up-folder");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
add_normal_and_shifted_binding (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_Down, GDK_ALT_MASK,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"down-folder");
|
2018-08-12 01:15:00 +00:00
|
|
|
|
add_normal_and_shifted_binding (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_KP_Down, GDK_ALT_MASK,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"down-folder");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2018-08-12 01:15:00 +00:00
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_Home, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"home-folder",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_KP_Home, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"home-folder",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_d, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"desktop-folder",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
GDK_KEY_h, GDK_CONTROL_MASK,
|
|
|
|
|
"show-hidden",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_s, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"search-shortcut",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
|
|
|
|
GDK_KEY_f, GDK_CONTROL_MASK,
|
|
|
|
|
"search-shortcut",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_r, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"recent-shortcut",
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
GDK_KEY_p, GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"places-shortcut",
|
|
|
|
|
NULL);
|
2018-08-26 16:39:51 +00:00
|
|
|
|
gtk_widget_class_add_binding (widget_class,
|
|
|
|
|
GDK_KEY_slash, 0,
|
|
|
|
|
trigger_location_entry,
|
|
|
|
|
"s", "/");
|
|
|
|
|
gtk_widget_class_add_binding (widget_class,
|
|
|
|
|
GDK_KEY_KP_Divide, 0,
|
|
|
|
|
trigger_location_entry,
|
|
|
|
|
"s", "/");
|
|
|
|
|
gtk_widget_class_add_binding (widget_class,
|
|
|
|
|
GDK_KEY_period, 0,
|
|
|
|
|
trigger_location_entry,
|
|
|
|
|
"s", ".");
|
|
|
|
|
gtk_widget_class_add_binding (widget_class,
|
|
|
|
|
GDK_KEY_asciitilde, 0,
|
|
|
|
|
trigger_location_entry,
|
|
|
|
|
"s", "~");
|
2018-08-12 01:15:00 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (quick_bookmark_keyvals); i++)
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class,
|
2020-04-05 13:39:03 +00:00
|
|
|
|
quick_bookmark_keyvals[i], GDK_ALT_MASK,
|
2018-08-12 01:15:00 +00:00
|
|
|
|
"quick-bookmark",
|
|
|
|
|
"(i)", i);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2015-01-28 20:00:08 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SEARCH_MODE,
|
|
|
|
|
g_param_spec_boolean ("search-mode",
|
|
|
|
|
P_("Search mode"),
|
|
|
|
|
P_("Search mode"),
|
|
|
|
|
FALSE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE));
|
2015-01-28 20:00:08 +00:00
|
|
|
|
|
2015-06-27 01:14:37 +00:00
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SUBTITLE,
|
|
|
|
|
g_param_spec_string ("subtitle",
|
|
|
|
|
P_("Subtitle"),
|
|
|
|
|
P_("Subtitle"),
|
|
|
|
|
"",
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READABLE));
|
2015-06-27 01:14:37 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
_gtk_file_chooser_install_properties (gobject_class);
|
|
|
|
|
|
|
|
|
|
/* Bind class to template */
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"/org/gtk/libgtk/ui/gtkfilechooserwidget.ui");
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* A *lot* of widgets that we need to handle .... */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_widgets_hpaned);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_files_stack);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, places_sidebar);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, places_view);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_files_tree_view);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_files_swin);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_header_revealer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_header_stack);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_new_folder_button);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_path_bar_size_group);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, browse_path_bar);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo_hbox);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, extra_align);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, extra_and_filters);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, location_entry_box);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, search_entry);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, search_spinner);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_name_column);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_pixbuf_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_name_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_time_column);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_date_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_time_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_size_column);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_size_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_type_column);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_type_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_location_column);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, list_location_renderer);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, new_folder_name_entry);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, new_folder_create_button);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, new_folder_error_stack);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, new_folder_popover);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, rename_file_name_entry);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, rename_file_rename_button);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, rename_file_error_stack);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, rename_file_popover);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, remote_warning_bar);
|
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, box);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* And a *lot* of callbacks to bind ... */
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, file_list_query_tooltip_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, list_row_activated);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, list_selection_changed);
|
2019-04-28 09:27:42 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, browse_files_tree_view_keynav_failed_cb);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, path_bar_clicked);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, places_sidebar_open_location_cb);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_error_message_cb);
|
2016-02-29 22:13:51 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, places_sidebar_show_other_locations_with_flags_cb);
|
2014-04-09 15:47:07 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, search_entry_activate_cb);
|
2015-01-28 21:06:02 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, search_entry_stop_cb);
|
2015-04-10 00:56:54 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, new_folder_popover_active);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, new_folder_name_changed);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, new_folder_create_clicked);
|
2015-07-05 01:16:55 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, rename_file_name_changed);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, rename_file_rename_clicked);
|
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, rename_file_end);
|
2019-05-29 17:10:46 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, click_cb);
|
2018-03-09 05:08:31 +00:00
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, long_press_cb);
|
2016-01-14 04:35:22 +00:00
|
|
|
|
|
2017-11-18 03:49:57 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));
|
2019-05-06 11:06:27 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 04:13:46 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
captured_key (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = data;
|
|
|
|
|
gboolean handled;
|
|
|
|
|
|
|
|
|
|
if (impl->operation_mode == OPERATION_MODE_SEARCH)
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
|
|
handled = gtk_event_controller_key_forward (controller, GTK_WIDGET (impl->search_entry));
|
|
|
|
|
if (handled == GDK_EVENT_STOP)
|
|
|
|
|
operation_mode_set (impl, OPERATION_MODE_SEARCH);
|
|
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
post_process_ui (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2020-03-26 16:31:22 +00:00
|
|
|
|
GdkContentFormats *drag_formats;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
GtkTreeSelection *selection;
|
2015-01-18 22:13:12 +00:00
|
|
|
|
GFile *file;
|
2020-02-29 02:47:17 +00:00
|
|
|
|
GtkDropTarget *target;
|
2020-03-19 04:07:45 +00:00
|
|
|
|
GtkGesture *gesture;
|
|
|
|
|
GtkEventController *controller;
|
|
|
|
|
GtkShortcutTrigger *trigger;
|
|
|
|
|
GtkShortcutAction *action;
|
|
|
|
|
GtkShortcut *shortcut;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Setup file list treeview */
|
2020-03-28 20:14:43 +00:00
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_tree_selection_set_select_function (selection,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
list_select_func,
|
|
|
|
|
impl, NULL);
|
2020-03-26 16:31:22 +00:00
|
|
|
|
|
|
|
|
|
drag_formats = gdk_content_formats_new_for_gtype (GDK_TYPE_FILE_LIST);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (impl->browse_files_tree_view),
|
2020-01-07 00:38:17 +00:00
|
|
|
|
GDK_BUTTON1_MASK,
|
2020-03-26 16:31:22 +00:00
|
|
|
|
drag_formats,
|
2020-01-07 00:38:17 +00:00
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
2020-03-26 16:31:22 +00:00
|
|
|
|
gdk_content_formats_unref (drag_formats);
|
|
|
|
|
|
2020-02-29 02:47:17 +00:00
|
|
|
|
target = gtk_drop_target_new (GDK_TYPE_FILE_LIST, GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
|
g_signal_connect (target, "drop", G_CALLBACK (file_list_drag_drop_cb), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_add_controller (impl->browse_files_tree_view, GTK_EVENT_CONTROLLER (target));
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* File browser treemodel columns are shared between GtkFileChooser implementations,
|
|
|
|
|
* so we don't set cell renderer attributes in GtkBuilder, but rather keep that
|
|
|
|
|
* in code.
|
|
|
|
|
*/
|
|
|
|
|
file_list_set_sort_column_ids (impl);
|
|
|
|
|
update_cell_renderer_attributes (impl);
|
|
|
|
|
|
2015-01-18 22:13:12 +00:00
|
|
|
|
file = g_file_new_for_path ("/");
|
2020-03-28 20:14:43 +00:00
|
|
|
|
_gtk_path_bar_set_file (GTK_PATH_BAR (impl->browse_path_bar), file, FALSE);
|
2015-01-18 22:13:12 +00:00
|
|
|
|
g_object_unref (file);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Set the fixed size icon renderer, this requires
|
2020-03-28 20:14:43 +00:00
|
|
|
|
* that impl->icon_size be already setup.
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
set_icon_cell_renderer_fixed_size (impl);
|
2015-04-17 04:14:28 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_popover_set_default_widget (GTK_POPOVER (impl->new_folder_popover), impl->new_folder_create_button);
|
|
|
|
|
gtk_popover_set_default_widget (GTK_POPOVER (impl->rename_file_popover), impl->rename_file_rename_button);
|
2015-07-16 14:45:14 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->item_actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (impl->item_actions),
|
2020-02-19 08:18:25 +00:00
|
|
|
|
entries, G_N_ELEMENTS (entries),
|
|
|
|
|
impl);
|
2020-03-22 00:00:15 +00:00
|
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (impl),
|
|
|
|
|
"item",
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->item_actions);
|
2019-04-01 03:06:42 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (impl->search_entry), impl->search_entry);
|
2020-03-22 00:14:23 +00:00
|
|
|
|
|
2020-04-27 04:13:46 +00:00
|
|
|
|
controller = gtk_event_controller_key_new ();
|
|
|
|
|
g_signal_connect (controller, "key-pressed", G_CALLBACK (captured_key), impl);
|
|
|
|
|
g_signal_connect (controller, "key-released", G_CALLBACK (captured_key), impl);
|
|
|
|
|
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
|
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (impl), controller);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_parent (impl->rename_file_popover, GTK_WIDGET (impl));
|
2020-03-19 04:07:45 +00:00
|
|
|
|
|
|
|
|
|
gesture = gtk_gesture_click_new ();
|
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (files_list_clicked), impl);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (impl->browse_files_tree_view), GTK_EVENT_CONTROLLER (gesture));
|
2020-03-19 04:07:45 +00:00
|
|
|
|
|
|
|
|
|
controller = gtk_shortcut_controller_new ();
|
|
|
|
|
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
|
|
|
|
|
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
|
|
|
|
|
action = gtk_callback_action_new (list_popup_menu_cb, impl, NULL);
|
|
|
|
|
shortcut = gtk_shortcut_new (trigger, action);
|
|
|
|
|
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (impl->browse_files_tree_view), controller);
|
2020-04-14 20:01:12 +00:00
|
|
|
|
|
|
|
|
|
/* Add ability to restrict interaction on file list (click and key_press events),
|
|
|
|
|
* needed to prevent data loss bug #2288 */
|
|
|
|
|
gesture = gtk_gesture_click_new ();
|
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
|
|
|
|
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE);
|
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (files_list_restrict_clicking), impl);
|
|
|
|
|
gtk_widget_add_controller (impl->browse_files_tree_view, GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
|
|
|
|
|
|
controller = gtk_event_controller_key_new ();
|
|
|
|
|
gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
|
|
|
|
|
g_signal_connect (controller, "key-pressed", G_CALLBACK (files_list_restrict_key_presses), impl);
|
|
|
|
|
gtk_widget_add_controller (impl->browse_files_tree_view, controller);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 04:07:59 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_file_chooser_widget_set_save_entry (GtkFileChooserWidget *impl,
|
|
|
|
|
GtkWidget *entry)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_FILE_CHOOSER_WIDGET (impl));
|
2015-07-04 02:45:58 +00:00
|
|
|
|
g_return_if_fail (entry == NULL || GTK_IS_FILE_CHOOSER_ENTRY (entry));
|
2015-06-27 04:07:59 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->external_entry = entry;
|
2015-06-27 04:07:59 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2015-06-27 04:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
save_widgets_destroy (impl);
|
|
|
|
|
save_widgets_create (impl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 09:50:59 +00:00
|
|
|
|
static void
|
|
|
|
|
display_changed_cb (GtkWidget *wiget,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
|
|
|
|
remove_settings_signal (impl, gtk_widget_get_display (GTK_WIDGET (impl)));
|
|
|
|
|
check_icon_theme (impl);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
static char *
|
|
|
|
|
filter_name (GtkFileFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
return g_strdup (gtk_file_filter_get_name (filter));
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
|
|
|
|
|
{
|
2019-12-22 01:12:11 +00:00
|
|
|
|
GtkExpression *expression;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->select_multiple = FALSE;
|
|
|
|
|
impl->show_hidden = FALSE;
|
|
|
|
|
impl->show_size_column = TRUE;
|
|
|
|
|
impl->show_type_column = TRUE;
|
|
|
|
|
impl->type_format = TYPE_FORMAT_MIME;
|
|
|
|
|
impl->load_state = LOAD_EMPTY;
|
|
|
|
|
impl->reload_state = RELOAD_EMPTY;
|
|
|
|
|
impl->pending_select_files = NULL;
|
|
|
|
|
impl->location_mode = LOCATION_MODE_PATH_BAR;
|
|
|
|
|
impl->operation_mode = OPERATION_MODE_BROWSE;
|
|
|
|
|
impl->sort_column = MODEL_COL_NAME;
|
|
|
|
|
impl->sort_order = GTK_SORT_ASCENDING;
|
|
|
|
|
impl->create_folders = TRUE;
|
|
|
|
|
impl->auto_selecting_first_row = FALSE;
|
|
|
|
|
impl->renamed_file = NULL;
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
|
|
|
|
/* Ensure GTK+ private types used by the template
|
|
|
|
|
* definition before calling gtk_widget_init_template()
|
|
|
|
|
*/
|
|
|
|
|
g_type_ensure (GTK_TYPE_PATH_BAR);
|
2015-09-01 05:00:46 +00:00
|
|
|
|
g_type_ensure (GTK_TYPE_PLACES_VIEW);
|
2018-01-09 22:20:23 +00:00
|
|
|
|
g_type_ensure (GTK_TYPE_PLACES_SIDEBAR);
|
2017-05-09 07:52:00 +00:00
|
|
|
|
g_type_ensure (GTK_TYPE_FILE_CHOOSER_ERROR_STACK);
|
2015-09-01 05:00:46 +00:00
|
|
|
|
|
2014-01-28 09:30:33 +00:00
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (impl));
|
2020-03-28 20:14:43 +00:00
|
|
|
|
gtk_widget_set_size_request (impl->browse_files_tree_view, 280, -1);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-08-28 09:50:59 +00:00
|
|
|
|
g_signal_connect (impl, "notify::display,", G_CALLBACK (display_changed_cb), impl);
|
|
|
|
|
check_icon_theme (impl);
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->bookmarks_manager = _gtk_bookmarks_manager_new (NULL, NULL);
|
2014-01-28 09:30:33 +00:00
|
|
|
|
|
2019-12-22 01:12:11 +00:00
|
|
|
|
impl->filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
|
|
|
|
|
gtk_drop_down_set_model (GTK_DROP_DOWN (impl->filter_combo), G_LIST_MODEL (impl->filters));
|
|
|
|
|
|
|
|
|
|
expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
|
|
|
|
|
0, NULL,
|
|
|
|
|
G_CALLBACK (filter_name),
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
gtk_drop_down_set_expression (GTK_DROP_DOWN (impl->filter_combo), expression);
|
|
|
|
|
gtk_expression_unref (expression);
|
|
|
|
|
|
2015-07-04 00:53:54 +00:00
|
|
|
|
/* Setup various attributes and callbacks in the UI
|
2018-01-25 07:27:43 +00:00
|
|
|
|
* which cannot be done with GtkBuilder
|
2014-01-28 09:30:33 +00:00
|
|
|
|
*/
|
|
|
|
|
post_process_ui (impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_file_chooser_widget_new:
|
|
|
|
|
* @action: Open or save mode for the widget
|
|
|
|
|
*
|
2015-07-04 00:53:54 +00:00
|
|
|
|
* Creates a new #GtkFileChooserWidget. This is a file chooser widget that can
|
2014-01-28 09:30:33 +00:00
|
|
|
|
* be embedded in custom windows, and it is the same widget that is used by
|
|
|
|
|
* #GtkFileChooserDialog.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a new #GtkFileChooserWidget
|
2003-10-23 23:02:38 +00:00
|
|
|
|
**/
|
2003-03-21 20:34:02 +00:00
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_file_chooser_widget_new (GtkFileChooserAction action)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
|
2015-07-04 00:53:54 +00:00
|
|
|
|
"action", action,
|
|
|
|
|
NULL);
|
2003-03-21 20:34:02 +00:00
|
|
|
|
}
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id,
|
|
|
|
|
const char *label,
|
|
|
|
|
const char **options,
|
|
|
|
|
const char **option_labels)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->choices == NULL)
|
2016-07-06 02:11:44 +00:00
|
|
|
|
{
|
2020-03-28 20:14:43 +00:00
|
|
|
|
impl->choices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
impl->choice_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
|
|
|
|
set_extra_widget (impl, impl->choice_box);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
}
|
2020-03-28 20:14:43 +00:00
|
|
|
|
else if (g_hash_table_lookup (impl->choices, id))
|
2016-07-06 02:11:44 +00:00
|
|
|
|
{
|
|
|
|
|
g_warning ("Duplicate choice %s", id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
GtkWidget *combo;
|
|
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (box), gtk_label_new (label));
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
2020-07-26 13:34:08 +00:00
|
|
|
|
combo = gtk_drop_down_new_from_strings ((const char * const *)options);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_hash_table_insert (impl->choices, g_strdup (id), combo);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (box), combo);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
|
|
|
|
widget = box;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *check;
|
|
|
|
|
|
|
|
|
|
check = gtk_check_button_new_with_label (label);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_hash_table_insert (impl->choices, g_strdup (id), check);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
|
|
|
|
widget = check;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (impl->choice_box), widget);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_remove_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->choices == NULL)
|
2016-07-06 02:11:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
|
|
|
|
|
g_hash_table_remove (impl->choices, id);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_remove (GTK_BOX (impl->choice_box), widget);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (g_hash_table_size (impl->choices) == 0)
|
2016-07-06 02:11:44 +00:00
|
|
|
|
{
|
|
|
|
|
set_extra_widget (impl, NULL);
|
2020-03-28 20:14:43 +00:00
|
|
|
|
g_hash_table_unref (impl->choices);
|
|
|
|
|
impl->choices = NULL;
|
|
|
|
|
impl->choice_box = NULL;
|
2016-07-06 02:11:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id,
|
|
|
|
|
const char *option)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->choices == NULL)
|
2016-07-06 02:11:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
|
2016-07-06 02:11:44 +00:00
|
|
|
|
|
2019-12-22 02:06:50 +00:00
|
|
|
|
if (GTK_IS_DROP_DOWN (widget))
|
|
|
|
|
{
|
2020-07-12 14:20:52 +00:00
|
|
|
|
guint i, n;
|
|
|
|
|
GListModel *model;
|
|
|
|
|
|
|
|
|
|
model = gtk_drop_down_get_model (GTK_DROP_DOWN (widget));
|
|
|
|
|
n = g_list_model_get_n_items (model);
|
|
|
|
|
for (i = 0; i < n; i++)
|
2019-12-22 02:06:50 +00:00
|
|
|
|
{
|
2020-07-12 14:20:52 +00:00
|
|
|
|
const char *string = gtk_string_list_get_string (GTK_STRING_LIST (model), i);
|
|
|
|
|
if (strcmp (string, option) == 0)
|
2019-12-22 02:06:50 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_drop_down_set_selected (GTK_DROP_DOWN (widget), i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-06 02:11:44 +00:00
|
|
|
|
else if (GTK_IS_TOGGLE_BUTTON (widget))
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), g_str_equal (option, "true"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
|
|
|
|
|
const char *id)
|
|
|
|
|
{
|
|
|
|
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
if (impl->choices == NULL)
|
2016-07-06 02:11:44 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2020-03-28 20:14:43 +00:00
|
|
|
|
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
|
2019-12-22 02:06:50 +00:00
|
|
|
|
if (GTK_IS_DROP_DOWN (widget))
|
|
|
|
|
{
|
2020-07-12 14:20:52 +00:00
|
|
|
|
gpointer selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (widget));
|
|
|
|
|
if (GTK_IS_STRING_OBJECT (selected))
|
|
|
|
|
return gtk_string_object_get_string (GTK_STRING_OBJECT (selected));
|
|
|
|
|
return NULL;
|
2019-12-22 02:06:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 02:11:44 +00:00
|
|
|
|
else if (GTK_IS_TOGGLE_BUTTON (widget))
|
|
|
|
|
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "true" : "false";
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|