2011-11-07 13:46:58 -06:00
|
|
|
/*
|
2016-01-25 08:13:49 -06:00
|
|
|
* xedit-file-browser-plugin.c - Xedit plugin providing easy file access
|
2011-11-07 13:46:58 -06:00
|
|
|
* from the sidepanel
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-11-18 19:54:49 -06:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-11-07 13:46:58 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
#include <xedit/xedit-commands.h>
|
|
|
|
#include <xedit/xedit-utils.h>
|
|
|
|
#include <xedit/xedit-app.h>
|
2011-11-07 13:46:58 -06:00
|
|
|
#include <glib/gi18n-lib.h>
|
2016-01-25 08:13:49 -06:00
|
|
|
#include <xedit/xedit-debug.h>
|
2013-01-24 14:05:58 -06:00
|
|
|
#include <gio/gio.h>
|
2011-11-07 13:46:58 -06:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
#include "xedit-file-browser-enum-types.h"
|
|
|
|
#include "xedit-file-browser-plugin.h"
|
|
|
|
#include "xedit-file-browser-utils.h"
|
|
|
|
#include "xedit-file-browser-error.h"
|
|
|
|
#include "xedit-file-browser-widget.h"
|
|
|
|
#include "xedit-file-browser-messages.h"
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
#define WINDOW_DATA_KEY "XeditFileBrowserPluginWindowData"
|
2013-01-24 14:05:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
#define FILE_BROWSER_SCHEMA "org.x.editor.plugins.filebrowser"
|
|
|
|
#define FILE_BROWSER_ONLOAD_SCHEMA "org.x.editor.plugins.filebrowser.on-load"
|
2013-01-24 14:05:58 -06:00
|
|
|
#define TERMINAL_SCHEMA "org.mate.applications-terminal"
|
|
|
|
#define TERMINAL_EXEC_KEY "exec"
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
#define XEDIT_FILE_BROWSER_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), XEDIT_TYPE_FILE_BROWSER_PLUGIN, XeditFileBrowserPluginPrivate))
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
struct _XeditFileBrowserPluginPrivate
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2013-01-24 14:05:58 -06:00
|
|
|
gpointer *dummy;
|
2011-11-07 13:46:58 -06:00
|
|
|
};
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
typedef struct _XeditFileBrowserPluginData
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserWidget * tree_widget;
|
2011-11-07 13:46:58 -06:00
|
|
|
gulong merge_id;
|
|
|
|
GtkActionGroup * action_group;
|
|
|
|
GtkActionGroup * single_selection_action_group;
|
|
|
|
gboolean auto_root;
|
|
|
|
gulong end_loading_handle;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
GSettings *settings;
|
|
|
|
GSettings *onload_settings;
|
|
|
|
GSettings *terminal_settings;
|
2016-01-25 08:13:49 -06:00
|
|
|
} XeditFileBrowserPluginData;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
static void on_uri_activated_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 18:10:16 -06:00
|
|
|
gchar const *uri,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_error_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
guint code,
|
2011-11-07 18:10:16 -06:00
|
|
|
gchar const *message,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_model_set_cb (XeditFileBrowserView * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec *arg1,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_virtual_root_changed_cb (XeditFileBrowserStore * model,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_filter_mode_changed_cb (XeditFileBrowserStore * model,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_rename_cb (XeditFileBrowserStore * model,
|
2011-11-07 13:46:58 -06:00
|
|
|
const gchar * olduri,
|
|
|
|
const gchar * newuri,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_filter_pattern_changed_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static void on_tab_added_cb (XeditWindow * window,
|
|
|
|
XeditTab * tab,
|
|
|
|
XeditFileBrowserPluginData * data);
|
|
|
|
static gboolean on_confirm_delete_cb (XeditFileBrowserWidget * widget,
|
|
|
|
XeditFileBrowserStore * store,
|
2011-11-07 13:46:58 -06:00
|
|
|
GList * rows,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
static gboolean on_confirm_no_trash_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GList * files,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window);
|
|
|
|
|
|
|
|
XEDIT_PLUGIN_REGISTER_TYPE_WITH_CODE (XeditFileBrowserPlugin, filetree_plugin, \
|
|
|
|
xedit_file_browser_enum_and_flag_register_type (type_module); \
|
|
|
|
xedit_file_browser_store_register_type (type_module); \
|
|
|
|
xedit_file_bookmarks_store_register_type (type_module); \
|
|
|
|
xedit_file_browser_view_register_type (type_module); \
|
|
|
|
xedit_file_browser_widget_register_type (type_module); \
|
2011-11-07 13:46:58 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
filetree_plugin_init (XeditFileBrowserPlugin * plugin)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
plugin->priv = XEDIT_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filetree_plugin_finalize (GObject * object)
|
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
//XeditFileBrowserPlugin * plugin = XEDIT_FILE_BROWSER_PLUGIN (object);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
G_OBJECT_CLASS (filetree_plugin_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
static XeditFileBrowserPluginData *
|
|
|
|
get_plugin_data (XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
return (XeditFileBrowserPluginData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_end_loading_cb (XeditFileBrowserStore * store,
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkTreeIter * iter,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
/* Disconnect the signal */
|
|
|
|
g_signal_handler_disconnect (store, data->end_loading_handle);
|
|
|
|
data->end_loading_handle = 0;
|
|
|
|
data->auto_root = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
prepare_auto_root (XeditFileBrowserPluginData *data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserStore *store;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
data->auto_root = TRUE;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
store = xedit_file_browser_widget_get_browser_store (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (data->end_loading_handle != 0) {
|
|
|
|
g_signal_handler_disconnect (store, data->end_loading_handle);
|
|
|
|
data->end_loading_handle = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
data->end_loading_handle = g_signal_connect (store,
|
2011-11-07 13:46:58 -06:00
|
|
|
"end-loading",
|
|
|
|
G_CALLBACK (on_end_loading_cb),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
restore_default_location (XeditFileBrowserPluginData *data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar * root;
|
|
|
|
gchar * virtual_root;
|
|
|
|
gboolean bookmarks;
|
|
|
|
gboolean remote;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
bookmarks = !g_settings_get_boolean (data->onload_settings, "tree-view");
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (bookmarks) {
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_show_bookmarks (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
return;
|
|
|
|
}
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
root = g_settings_get_string (data->onload_settings, "root");
|
|
|
|
virtual_root = g_settings_get_string (data->onload_settings, "virtual-root");
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
remote = g_settings_get_boolean (data->onload_settings, "enable-remote");
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (root != NULL && *root != '\0') {
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
file = g_file_new_for_uri (root);
|
|
|
|
|
|
|
|
if (remote || g_file_is_native (file)) {
|
|
|
|
if (virtual_root != NULL && *virtual_root != '\0') {
|
|
|
|
prepare_auto_root (data);
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_set_root_and_virtual_root (data->tree_widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
root,
|
|
|
|
virtual_root);
|
|
|
|
} else {
|
|
|
|
prepare_auto_root (data);
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_set_root (data->tree_widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
root,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (root);
|
|
|
|
g_free (virtual_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
restore_filter (XeditFileBrowserPluginData * data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar *filter_mode;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserStoreFilterMode mode;
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar *pattern;
|
|
|
|
|
|
|
|
/* Get filter_mode */
|
2013-01-24 14:05:58 -06:00
|
|
|
filter_mode = g_settings_get_string (data->settings, "filter-mode");
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Filter mode */
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = xedit_file_browser_store_filter_mode_get_default ();
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (filter_mode != NULL) {
|
|
|
|
if (strcmp (filter_mode, "hidden") == 0) {
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
|
2011-11-07 13:46:58 -06:00
|
|
|
} else if (strcmp (filter_mode, "binary") == 0) {
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
|
2011-11-07 13:46:58 -06:00
|
|
|
} else if (strcmp (filter_mode, "hidden_and_binary") == 0 ||
|
|
|
|
strcmp (filter_mode, "binary_and_hidden") == 0) {
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN |
|
|
|
|
XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
|
2011-11-07 18:10:16 -06:00
|
|
|
} else if (strcmp (filter_mode, "none") == 0 ||
|
2011-11-07 13:46:58 -06:00
|
|
|
*filter_mode == '\0') {
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = XEDIT_FILE_BROWSER_STORE_FILTER_MODE_NONE;
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
}
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Set the filter mode */
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_store_set_filter_mode (
|
|
|
|
xedit_file_browser_widget_get_browser_store (data->tree_widget),
|
2011-11-07 13:46:58 -06:00
|
|
|
mode);
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
pattern = g_settings_get_string (data->settings, "filter-pattern");
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_set_filter_pattern (data->tree_widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
pattern);
|
|
|
|
|
|
|
|
g_free (filter_mode);
|
|
|
|
g_free (pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
set_root_from_doc (XeditFileBrowserPluginData * data,
|
|
|
|
XeditDocument * doc)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
GFile *parent;
|
|
|
|
|
|
|
|
if (doc == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
file = xedit_document_get_location (doc);
|
2011-11-07 13:46:58 -06:00
|
|
|
if (file == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent = g_file_get_parent (file);
|
|
|
|
|
|
|
|
if (parent != NULL) {
|
|
|
|
gchar * root;
|
|
|
|
|
|
|
|
root = g_file_get_uri (parent);
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_set_root (data->tree_widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
root,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
g_object_unref (parent);
|
|
|
|
g_free (root);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_set_active_root (GtkAction * action,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData *data;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
data = get_plugin_data (window);
|
2011-11-07 18:10:16 -06:00
|
|
|
set_root_from_doc (data,
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_window_get_active_document (window));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2016-01-25 08:13:49 -06:00
|
|
|
get_terminal (XeditFileBrowserPluginData * data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar * terminal;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
terminal = g_settings_get_string (data->terminal_settings,
|
|
|
|
TERMINAL_EXEC_KEY);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (terminal == NULL) {
|
|
|
|
const gchar *term = g_getenv ("TERM");
|
|
|
|
|
|
|
|
if (term != NULL)
|
|
|
|
terminal = g_strdup (term);
|
|
|
|
else
|
|
|
|
terminal = g_strdup ("xterm");
|
|
|
|
}
|
|
|
|
|
|
|
|
return terminal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_open_terminal (GtkAction * action,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar * terminal;
|
|
|
|
gchar * wd = NULL;
|
|
|
|
gchar * local;
|
|
|
|
gchar * argv[2];
|
|
|
|
GFile * file;
|
|
|
|
|
|
|
|
GtkTreeIter iter;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserStore * store;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
data = get_plugin_data (window);
|
|
|
|
|
|
|
|
/* Get the current directory */
|
2016-01-25 08:13:49 -06:00
|
|
|
if (!xedit_file_browser_widget_get_selected_directory (data->tree_widget, &iter))
|
2011-11-07 13:46:58 -06:00
|
|
|
return;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
store = xedit_file_browser_widget_get_browser_store (data->tree_widget);
|
2011-11-07 18:10:16 -06:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (store),
|
2011-11-07 13:46:58 -06:00
|
|
|
&iter,
|
2016-01-25 08:13:49 -06:00
|
|
|
XEDIT_FILE_BROWSER_STORE_COLUMN_URI,
|
2011-11-07 13:46:58 -06:00
|
|
|
&wd,
|
|
|
|
-1);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (wd == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
terminal = get_terminal (data);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
file = g_file_new_for_uri (wd);
|
|
|
|
local = g_file_get_path (file);
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
argv[0] = terminal;
|
|
|
|
argv[1] = NULL;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
|
|
|
g_spawn_async (local,
|
|
|
|
argv,
|
|
|
|
NULL,
|
|
|
|
G_SPAWN_SEARCH_PATH,
|
2011-11-07 13:46:58 -06:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
g_free (terminal);
|
|
|
|
g_free (wd);
|
|
|
|
g_free (local);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_selection_changed_cb (GtkTreeSelection *selection,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow *window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkTreeView * tree_view;
|
|
|
|
GtkTreeModel * model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean sensitive;
|
|
|
|
gchar * uri;
|
|
|
|
|
|
|
|
data = get_plugin_data (window);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
tree_view = GTK_TREE_VIEW (xedit_file_browser_widget_get_browser_view (data->tree_widget));
|
2011-11-07 13:46:58 -06:00
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
if (!XEDIT_IS_FILE_BROWSER_STORE (model))
|
2011-11-07 13:46:58 -06:00
|
|
|
return;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
sensitive = xedit_file_browser_widget_get_selected_directory (data->tree_widget, &iter);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (sensitive) {
|
2011-11-07 18:10:16 -06:00
|
|
|
gtk_tree_model_get (model, &iter,
|
2016-01-25 08:13:49 -06:00
|
|
|
XEDIT_FILE_BROWSER_STORE_COLUMN_URI,
|
2011-11-07 13:46:58 -06:00
|
|
|
&uri, -1);
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
sensitive = xedit_utils_uri_has_file_scheme (uri);
|
2011-11-07 13:46:58 -06:00
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_action_set_sensitive (
|
2011-11-07 18:10:16 -06:00
|
|
|
gtk_action_group_get_action (data->single_selection_action_group,
|
2011-11-07 13:46:58 -06:00
|
|
|
"OpenTerminal"),
|
|
|
|
sensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define POPUP_UI "" \
|
|
|
|
"<ui>" \
|
|
|
|
" <popup name=\"FilePopup\">" \
|
|
|
|
" <placeholder name=\"FilePopup_Opt1\">" \
|
|
|
|
" <menuitem action=\"SetActiveRoot\"/>" \
|
|
|
|
" </placeholder>" \
|
|
|
|
" <placeholder name=\"FilePopup_Opt4\">" \
|
|
|
|
" <menuitem action=\"OpenTerminal\"/>" \
|
|
|
|
" </placeholder>" \
|
|
|
|
" </popup>" \
|
|
|
|
" <popup name=\"BookmarkPopup\">" \
|
|
|
|
" <placeholder name=\"BookmarkPopup_Opt1\">" \
|
|
|
|
" <menuitem action=\"SetActiveRoot\"/>" \
|
|
|
|
" </placeholder>" \
|
|
|
|
" </popup>" \
|
|
|
|
"</ui>"
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static GtkActionEntry extra_actions[] =
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
{"SetActiveRoot", GTK_STOCK_JUMP_TO, N_("_Set root to active document"),
|
|
|
|
NULL,
|
|
|
|
N_("Set the root to the active document location"),
|
|
|
|
G_CALLBACK (on_action_set_active_root)}
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkActionEntry extra_single_selection_actions[] = {
|
|
|
|
{"OpenTerminal", "utilities-terminal", N_("_Open terminal here"),
|
|
|
|
NULL,
|
|
|
|
N_("Open a terminal at the currently opened directory"),
|
|
|
|
G_CALLBACK (on_action_open_terminal)}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
add_popup_ui (XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkUIManager * manager;
|
|
|
|
GtkActionGroup * action_group;
|
|
|
|
GError * error = NULL;
|
|
|
|
|
|
|
|
data = get_plugin_data (window);
|
2016-01-25 08:13:49 -06:00
|
|
|
manager = xedit_file_browser_widget_get_ui_manager (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
action_group = gtk_action_group_new ("FileBrowserPluginExtra");
|
|
|
|
gtk_action_group_set_translation_domain (action_group, NULL);
|
|
|
|
gtk_action_group_add_actions (action_group,
|
|
|
|
extra_actions,
|
|
|
|
G_N_ELEMENTS (extra_actions),
|
|
|
|
window);
|
|
|
|
gtk_ui_manager_insert_action_group (manager, action_group, 0);
|
|
|
|
data->action_group = action_group;
|
|
|
|
|
|
|
|
action_group = gtk_action_group_new ("FileBrowserPluginSingleSelectionExtra");
|
|
|
|
gtk_action_group_set_translation_domain (action_group, NULL);
|
|
|
|
gtk_action_group_add_actions (action_group,
|
|
|
|
extra_single_selection_actions,
|
|
|
|
G_N_ELEMENTS (extra_single_selection_actions),
|
|
|
|
window);
|
|
|
|
gtk_ui_manager_insert_action_group (manager, action_group, 0);
|
|
|
|
data->single_selection_action_group = action_group;
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
data->merge_id = gtk_ui_manager_add_ui_from_string (manager,
|
|
|
|
POPUP_UI,
|
|
|
|
-1,
|
2011-11-07 13:46:58 -06:00
|
|
|
&error);
|
|
|
|
|
|
|
|
if (data->merge_id == 0) {
|
|
|
|
g_warning("Unable to merge UI: %s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
remove_popup_ui (XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkUIManager * manager;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
data = get_plugin_data (window);
|
2016-01-25 08:13:49 -06:00
|
|
|
manager = xedit_file_browser_widget_get_ui_manager (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
gtk_ui_manager_remove_ui (manager, data->merge_id);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
gtk_ui_manager_remove_action_group (manager, data->action_group);
|
|
|
|
g_object_unref (data->action_group);
|
|
|
|
|
|
|
|
gtk_ui_manager_remove_action_group (manager, data->single_selection_action_group);
|
|
|
|
g_object_unref (data->single_selection_action_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
impl_updateui (XeditPlugin * plugin, XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
|
|
|
XeditDocument * doc;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
data = get_plugin_data (window);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
doc = xedit_window_get_active_document (window);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
|
|
|
gtk_action_set_sensitive (gtk_action_group_get_action (data->action_group,
|
2011-11-07 13:46:58 -06:00
|
|
|
"SetActiveRoot"),
|
2011-11-07 18:10:16 -06:00
|
|
|
doc != NULL &&
|
2016-01-25 08:13:49 -06:00
|
|
|
!xedit_document_is_untitled (doc));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
impl_activate (XeditPlugin * plugin, XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditPanel * panel;
|
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkWidget * image;
|
|
|
|
GdkPixbuf * pixbuf;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserStore * store;
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar *data_dir;
|
2013-11-30 06:02:57 -06:00
|
|
|
GSettingsSchemaSource *schema_source;
|
2014-06-06 13:16:24 -05:00
|
|
|
GSettingsSchema *schema;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
data = g_new0 (XeditFileBrowserPluginData, 1);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
data_dir = xedit_plugin_get_data_dir (plugin);
|
|
|
|
data->tree_widget = XEDIT_FILE_BROWSER_WIDGET (xedit_file_browser_widget_new (data_dir));
|
2011-11-07 13:46:58 -06:00
|
|
|
g_free (data_dir);
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
data->settings = g_settings_new (FILE_BROWSER_SCHEMA);
|
|
|
|
data->onload_settings = g_settings_new (FILE_BROWSER_ONLOAD_SCHEMA);
|
|
|
|
data->terminal_settings = g_settings_new (TERMINAL_SCHEMA);
|
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
g_signal_connect (data->tree_widget,
|
|
|
|
"uri-activated",
|
|
|
|
G_CALLBACK (on_uri_activated_cb), window);
|
|
|
|
|
|
|
|
g_signal_connect (data->tree_widget,
|
|
|
|
"error", G_CALLBACK (on_error_cb), window);
|
|
|
|
|
|
|
|
g_signal_connect (data->tree_widget,
|
|
|
|
"notify::filter-pattern",
|
|
|
|
G_CALLBACK (on_filter_pattern_changed_cb),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_signal_connect (data->tree_widget,
|
|
|
|
"confirm-delete",
|
|
|
|
G_CALLBACK (on_confirm_delete_cb),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_signal_connect (data->tree_widget,
|
|
|
|
"confirm-no-trash",
|
|
|
|
G_CALLBACK (on_confirm_no_trash_cb),
|
|
|
|
window);
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW
|
2016-01-25 08:13:49 -06:00
|
|
|
(xedit_file_browser_widget_get_browser_view
|
2011-11-07 13:46:58 -06:00
|
|
|
(data->tree_widget))),
|
|
|
|
"changed",
|
|
|
|
G_CALLBACK (on_selection_changed_cb),
|
2011-11-07 18:10:16 -06:00
|
|
|
window);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
panel = xedit_window_get_side_panel (window);
|
|
|
|
pixbuf = xedit_file_browser_utils_pixbuf_from_theme("system-file-manager",
|
2011-11-07 13:46:58 -06:00
|
|
|
GTK_ICON_SIZE_MENU);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (pixbuf) {
|
|
|
|
image = gtk_image_new_from_pixbuf(pixbuf);
|
|
|
|
g_object_unref(pixbuf);
|
|
|
|
} else {
|
|
|
|
image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_show(image);
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_panel_add_item (panel,
|
2011-11-07 13:46:58 -06:00
|
|
|
GTK_WIDGET (data->tree_widget),
|
|
|
|
_("File Browser"),
|
|
|
|
image);
|
|
|
|
gtk_widget_show (GTK_WIDGET (data->tree_widget));
|
|
|
|
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data);
|
|
|
|
|
|
|
|
add_popup_ui (window);
|
|
|
|
|
|
|
|
/* Restore filter options */
|
|
|
|
restore_filter (data);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Connect signals to store the last visited location */
|
2016-01-25 08:13:49 -06:00
|
|
|
g_signal_connect (xedit_file_browser_widget_get_browser_view (data->tree_widget),
|
2011-11-07 13:46:58 -06:00
|
|
|
"notify::model",
|
|
|
|
G_CALLBACK (on_model_set_cb),
|
|
|
|
window);
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
store = xedit_file_browser_widget_get_browser_store (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
g_signal_connect (store,
|
|
|
|
"notify::virtual-root",
|
|
|
|
G_CALLBACK (on_virtual_root_changed_cb),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_signal_connect (store,
|
|
|
|
"notify::filter-mode",
|
|
|
|
G_CALLBACK (on_filter_mode_changed_cb),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_signal_connect (store,
|
|
|
|
"rename",
|
|
|
|
G_CALLBACK (on_rename_cb),
|
|
|
|
window);
|
|
|
|
|
|
|
|
g_signal_connect (window,
|
|
|
|
"tab-added",
|
|
|
|
G_CALLBACK (on_tab_added_cb),
|
|
|
|
data);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Register messages on the bus */
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_messages_register (window, data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
impl_updateui (plugin, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
impl_deactivate (XeditPlugin * plugin, XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
|
|
|
XeditPanel * panel;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
data = get_plugin_data (window);
|
|
|
|
|
|
|
|
/* Unregister messages from the bus */
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_messages_unregister (window);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
/* Disconnect signals */
|
2011-11-07 18:10:16 -06:00
|
|
|
g_signal_handlers_disconnect_by_func (window,
|
2011-11-07 13:46:58 -06:00
|
|
|
G_CALLBACK (on_tab_added_cb),
|
|
|
|
data);
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
g_object_unref (data->settings);
|
|
|
|
g_object_unref (data->onload_settings);
|
|
|
|
g_object_unref (data->terminal_settings);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
remove_popup_ui (window);
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
panel = xedit_window_get_side_panel (window);
|
|
|
|
xedit_panel_remove_item (panel, GTK_WIDGET (data->tree_widget));
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
filetree_plugin_class_init (XeditFileBrowserPluginClass * klass)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditPluginClass * plugin_class = XEDIT_PLUGIN_CLASS (klass);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
object_class->finalize = filetree_plugin_finalize;
|
|
|
|
|
|
|
|
plugin_class->activate = impl_activate;
|
|
|
|
plugin_class->deactivate = impl_deactivate;
|
|
|
|
plugin_class->update_ui = impl_updateui;
|
|
|
|
|
|
|
|
g_type_class_add_private (object_class,
|
2016-01-25 08:13:49 -06:00
|
|
|
sizeof (XeditFileBrowserPluginPrivate));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_uri_activated_cb (XeditFileBrowserWidget * tree_widget,
|
|
|
|
gchar const *uri, XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_commands_load_uri (window, uri, NULL, 0);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_error_cb (XeditFileBrowserWidget * tree_widget,
|
|
|
|
guint code, gchar const *message, XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar * title;
|
|
|
|
GtkWidget * dlg;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
data = get_plugin_data (window);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Do not show the error when the root has been set automatically */
|
2016-01-25 08:13:49 -06:00
|
|
|
if (data->auto_root && (code == XEDIT_FILE_BROWSER_ERROR_SET_ROOT ||
|
|
|
|
code == XEDIT_FILE_BROWSER_ERROR_LOAD_DIRECTORY))
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
/* Show bookmarks */
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_file_browser_widget_show_bookmarks (data->tree_widget);
|
2011-11-07 13:46:58 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (code) {
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_NEW_DIRECTORY:
|
2011-11-07 13:46:58 -06:00
|
|
|
title =
|
|
|
|
_("An error occurred while creating a new directory");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_NEW_FILE:
|
2011-11-07 13:46:58 -06:00
|
|
|
title = _("An error occurred while creating a new file");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_RENAME:
|
2011-11-07 13:46:58 -06:00
|
|
|
title =
|
|
|
|
_
|
|
|
|
("An error occurred while renaming a file or directory");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_DELETE:
|
2011-11-07 13:46:58 -06:00
|
|
|
title =
|
|
|
|
_
|
|
|
|
("An error occurred while deleting a file or directory");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_OPEN_DIRECTORY:
|
2011-11-07 13:46:58 -06:00
|
|
|
title =
|
|
|
|
_
|
|
|
|
("An error occurred while opening a directory in the file manager");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_SET_ROOT:
|
2011-11-07 13:46:58 -06:00
|
|
|
title =
|
|
|
|
_("An error occurred while setting a root directory");
|
|
|
|
break;
|
2016-01-25 08:13:49 -06:00
|
|
|
case XEDIT_FILE_BROWSER_ERROR_LOAD_DIRECTORY:
|
2011-11-07 18:10:16 -06:00
|
|
|
title =
|
2011-11-07 13:46:58 -06:00
|
|
|
_("An error occurred while loading a directory");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = _("An error occurred");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg = gtk_message_dialog_new (GTK_WINDOW (window),
|
|
|
|
GTK_DIALOG_MODAL |
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
|
|
|
|
"%s", title);
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
|
|
|
|
"%s", message);
|
|
|
|
|
|
|
|
gtk_dialog_run (GTK_DIALOG (dlg));
|
|
|
|
gtk_widget_destroy (dlg);
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_model_set_cb (XeditFileBrowserView * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec *arg1,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data = get_plugin_data (window);
|
2011-11-07 13:46:58 -06:00
|
|
|
GtkTreeModel * model;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (xedit_file_browser_widget_get_browser_view (data->tree_widget)));
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (model == NULL)
|
|
|
|
return;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_boolean (data->onload_settings,
|
|
|
|
"tree-view",
|
2016-01-25 08:13:49 -06:00
|
|
|
XEDIT_IS_FILE_BROWSER_STORE (model));
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_filter_mode_changed_cb (XeditFileBrowserStore * model,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data = get_plugin_data (window);
|
|
|
|
XeditFileBrowserStoreFilterMode mode;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
mode = xedit_file_browser_store_get_filter_mode (model);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
if ((mode & XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) &&
|
|
|
|
(mode & XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY)) {
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-mode", "hidden_and_binary");
|
2016-01-25 08:13:49 -06:00
|
|
|
} else if (mode & XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN) {
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-mode", "hidden");
|
2016-01-25 08:13:49 -06:00
|
|
|
} else if (mode & XEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY) {
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-mode", "binary");
|
2011-11-07 13:46:58 -06:00
|
|
|
} else {
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-mode", "none");
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_rename_cb (XeditFileBrowserStore * store,
|
2011-11-07 13:46:58 -06:00
|
|
|
const gchar * olduri,
|
|
|
|
const gchar * newuri,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditApp * app;
|
2011-11-07 13:46:58 -06:00
|
|
|
GList * documents;
|
|
|
|
GList * item;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditDocument * doc;
|
2011-11-07 13:46:58 -06:00
|
|
|
GFile * docfile;
|
|
|
|
GFile * oldfile;
|
|
|
|
GFile * newfile;
|
|
|
|
gchar * uri;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
/* Find all documents and set its uri to newuri where it matches olduri */
|
2016-01-25 08:13:49 -06:00
|
|
|
app = xedit_app_get_default ();
|
|
|
|
documents = xedit_app_get_documents (app);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
oldfile = g_file_new_for_uri (olduri);
|
|
|
|
newfile = g_file_new_for_uri (newuri);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
for (item = documents; item; item = item->next) {
|
2016-01-25 08:13:49 -06:00
|
|
|
doc = XEDIT_DOCUMENT (item->data);
|
|
|
|
uri = xedit_document_get_uri (doc);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (!uri)
|
|
|
|
continue;
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
docfile = g_file_new_for_uri (uri);
|
|
|
|
|
|
|
|
if (g_file_equal (docfile, oldfile)) {
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_document_set_uri (doc, newuri);
|
2011-11-07 13:46:58 -06:00
|
|
|
} else {
|
|
|
|
gchar *relative;
|
|
|
|
|
|
|
|
relative = g_file_get_relative_path (oldfile, docfile);
|
|
|
|
|
|
|
|
if (relative) {
|
|
|
|
/* relative now contains the part in docfile without
|
|
|
|
the prefix oldfile */
|
|
|
|
|
|
|
|
g_object_unref (docfile);
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
docfile = g_file_get_child (newfile, relative);
|
|
|
|
uri = g_file_get_uri (docfile);
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
xedit_document_set_uri (doc, uri);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (relative);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
g_object_unref (docfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (oldfile);
|
|
|
|
g_object_unref (newfile);
|
|
|
|
|
|
|
|
g_list_free (documents);
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_filter_pattern_changed_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data = get_plugin_data (window);
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar * pattern;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (pattern == NULL)
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-pattern", "");
|
2011-11-07 13:46:58 -06:00
|
|
|
else
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->settings, "filter-pattern", pattern);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
g_free (pattern);
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_virtual_root_changed_cb (XeditFileBrowserStore * store,
|
2011-11-07 13:46:58 -06:00
|
|
|
GParamSpec * param,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData * data = get_plugin_data (window);
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar * root;
|
|
|
|
gchar * virtual_root;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
root = xedit_file_browser_store_get_root (store);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2011-11-07 13:46:58 -06:00
|
|
|
if (!root)
|
|
|
|
return;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->onload_settings, "root", root);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
virtual_root = xedit_file_browser_store_get_virtual_root (store);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (!virtual_root) {
|
|
|
|
/* Set virtual to same as root then */
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->onload_settings, "virtual-root", root);
|
2011-11-07 18:10:16 -06:00
|
|
|
} else {
|
2013-01-24 14:05:58 -06:00
|
|
|
g_settings_set_string (data->onload_settings, "virtual-root", virtual_root);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
g_signal_handlers_disconnect_by_func (window,
|
2011-11-07 13:46:58 -06:00
|
|
|
G_CALLBACK (on_tab_added_cb),
|
|
|
|
data);
|
|
|
|
|
|
|
|
g_free (root);
|
|
|
|
g_free (virtual_root);
|
|
|
|
}
|
|
|
|
|
2011-11-07 18:10:16 -06:00
|
|
|
static void
|
2016-01-25 08:13:49 -06:00
|
|
|
on_tab_added_cb (XeditWindow * window,
|
|
|
|
XeditTab * tab,
|
|
|
|
XeditFileBrowserPluginData * data)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gboolean open;
|
|
|
|
gboolean load_default = TRUE;
|
|
|
|
|
2013-01-24 14:05:58 -06:00
|
|
|
open = g_settings_get_boolean (data->settings, "open-at-first-doc");
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
if (open) {
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditDocument *doc;
|
2011-11-07 13:46:58 -06:00
|
|
|
gchar *uri;
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
doc = xedit_tab_get_document (tab);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
uri = xedit_document_get_uri (doc);
|
2011-11-07 13:46:58 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
if (uri != NULL && xedit_utils_uri_has_file_scheme (uri)) {
|
2011-11-07 13:46:58 -06:00
|
|
|
prepare_auto_root (data);
|
|
|
|
set_root_from_doc (data, doc);
|
|
|
|
load_default = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_default)
|
|
|
|
restore_default_location (data);
|
|
|
|
|
|
|
|
/* Disconnect this signal, it's only called once */
|
2011-11-07 18:10:16 -06:00
|
|
|
g_signal_handlers_disconnect_by_func (window,
|
2011-11-07 13:46:58 -06:00
|
|
|
G_CALLBACK (on_tab_added_cb),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_filename_from_path (GtkTreeModel *model, GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_tree_model_get (model, &iter,
|
2016-01-25 08:13:49 -06:00
|
|
|
XEDIT_FILE_BROWSER_STORE_COLUMN_URI, &uri,
|
2011-11-07 13:46:58 -06:00
|
|
|
-1);
|
2011-11-07 18:10:16 -06:00
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
return xedit_file_browser_utils_uri_basename (uri);
|
2011-11-07 13:46:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-01-25 08:13:49 -06:00
|
|
|
on_confirm_no_trash_cb (XeditFileBrowserWidget * widget,
|
2011-11-07 13:46:58 -06:00
|
|
|
GList * files,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow * window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar *normal;
|
|
|
|
gchar *message;
|
|
|
|
gchar *secondary;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
message = _("Cannot move file to trash, do you\nwant to delete permanently?");
|
|
|
|
|
|
|
|
if (files->next == NULL) {
|
2016-01-25 08:13:49 -06:00
|
|
|
normal = xedit_file_browser_utils_file_basename (G_FILE (files->data));
|
2011-11-07 13:46:58 -06:00
|
|
|
secondary = g_strdup_printf (_("The file \"%s\" cannot be moved to the trash."), normal);
|
|
|
|
g_free (normal);
|
|
|
|
} else {
|
|
|
|
secondary = g_strdup (_("The selected files cannot be moved to the trash."));
|
|
|
|
}
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
result = xedit_file_browser_utils_confirmation_dialog (window,
|
2011-11-07 18:10:16 -06:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
message,
|
|
|
|
secondary,
|
|
|
|
GTK_STOCK_DELETE,
|
2011-11-07 13:46:58 -06:00
|
|
|
NULL);
|
|
|
|
g_free (secondary);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-01-25 08:13:49 -06:00
|
|
|
on_confirm_delete_cb (XeditFileBrowserWidget *widget,
|
|
|
|
XeditFileBrowserStore *store,
|
2011-11-07 13:46:58 -06:00
|
|
|
GList *paths,
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditWindow *window)
|
2011-11-07 13:46:58 -06:00
|
|
|
{
|
|
|
|
gchar *normal;
|
|
|
|
gchar *message;
|
|
|
|
gchar *secondary;
|
|
|
|
gboolean result;
|
2016-01-25 08:13:49 -06:00
|
|
|
XeditFileBrowserPluginData *data;
|
2011-11-07 13:46:58 -06:00
|
|
|
|
|
|
|
data = get_plugin_data (window);
|
|
|
|
|
|
|
|
if (paths->next == NULL) {
|
|
|
|
normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data));
|
|
|
|
message = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\"?"), normal);
|
|
|
|
g_free (normal);
|
|
|
|
} else {
|
|
|
|
message = g_strdup (_("Are you sure you want to permanently delete the selected files?"));
|
|
|
|
}
|
|
|
|
|
|
|
|
secondary = _("If you delete an item, it is permanently lost.");
|
|
|
|
|
2016-01-25 08:13:49 -06:00
|
|
|
result = xedit_file_browser_utils_confirmation_dialog (window,
|
2011-11-07 18:10:16 -06:00
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
message,
|
|
|
|
secondary,
|
|
|
|
GTK_STOCK_DELETE,
|
2011-11-07 13:46:58 -06:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (message);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ex:ts=8:noet:
|