Merge pull request #89 from JosephMcc/filebrowser-3

Filebrowser 3
This commit is contained in:
Clement Lefebvre 2017-02-22 10:40:17 +00:00 committed by GitHub
commit 99a730fa9c
10 changed files with 1684 additions and 1818 deletions

View File

@ -16,6 +16,11 @@
<summary>File Browser Filter Pattern</summary> <summary>File Browser Filter Pattern</summary>
<description>The filter pattern to filter the file browser with. This filter works on top of the filter_mode.</description> <description>The filter pattern to filter the file browser with. This filter works on top of the filter_mode.</description>
</key> </key>
<key name="terminal-command" type="s">
<default>'x-terminal-emulator'</default>
<summary>Terminal Command</summary>
<description>The terminal command when using the "Open terminal here" command.</description>
</key>
<child name="on-load" schema="org.x.editor.plugins.filebrowser.on-load"/> <child name="on-load" schema="org.x.editor.plugins.filebrowser.on-load"/>
</schema> </schema>
<schema id="org.x.editor.plugins.filebrowser.on-load" path="/org/x/editor/plugins/filebrowser/on-load/"> <schema id="org.x.editor.plugins.filebrowser.on-load" path="/org/x/editor/plugins/filebrowser/on-load/">

View File

@ -234,23 +234,23 @@ init_special_directories (XedFileBookmarksStore * model)
g_object_unref (file); g_object_unref (file);
} }
path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); // path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
if (path != NULL) // if (path != NULL)
{ // {
file = g_file_new_for_path (path); // file = g_file_new_for_path (path);
add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP | // add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP |
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); // XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
g_object_unref (file); // g_object_unref (file);
} // }
path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); // path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
if (path != NULL) // if (path != NULL)
{ // {
file = g_file_new_for_path (path); // file = g_file_new_for_path (path);
add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS | // add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS |
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); // XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL);
g_object_unref (file); // g_object_unref (file);
} // }
file = g_file_new_for_uri ("file:///"); file = g_file_new_for_uri ("file:///");
add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL); add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL);
@ -514,75 +514,106 @@ add_bookmark (XedFileBookmarksStore * model,
return ret; return ret;
} }
static void static gchar *
init_bookmarks (XedFileBookmarksStore * model) get_bookmarks_file (void)
{
return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL);
}
static gchar *
get_legacy_bookmarks_file (void)
{
return g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
}
static gboolean
parse_bookmarks_file (XedFileBookmarksStore *model,
const gchar *bookmarks,
gboolean *added)
{ {
gchar *bookmarks;
GError *error = NULL; GError *error = NULL;
gchar *contents; gchar *contents;
gchar **lines; gchar **lines;
gchar **line; gchar **line;
gboolean added = FALSE;
/* Read the bookmarks file */ if (!g_file_get_contents (bookmarks, &contents, NULL, &error))
bookmarks = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
if (g_file_get_contents (bookmarks, &contents, NULL, &error))
{
lines = g_strsplit (contents, "\n", 0);
for (line = lines; *line; ++line)
{
if (**line)
{
GFile *location;
gchar *pos;
gchar *name;
/* CHECK: is this really utf8? */
pos = g_utf8_strchr (*line, -1, ' ');
if (pos != NULL)
{
*pos = '\0';
name = pos + 1;
}
else
{
name = NULL;
}
/* the bookmarks file should contain valid
* URIs, but paranoia is good */
location = g_file_new_for_uri (*line);
if (xed_utils_is_valid_location (location))
{
added |= add_bookmark (model, name, *line);
}
g_object_unref (location);
}
}
g_strfreev (lines);
g_free (contents);
/* Add a watch */
if (model->priv->bookmarks_monitor == NULL)
{
GFile * file;
file = g_file_new_for_path (bookmarks);
model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
g_signal_connect (model->priv->bookmarks_monitor, "changed",
(GCallback)on_bookmarks_file_changed, model);
}
}
else
{ {
/* The bookmarks file doesn't exist (which is perfectly fine) */ /* The bookmarks file doesn't exist (which is perfectly fine) */
g_error_free (error); g_error_free (error);
return FALSE;
}
lines = g_strsplit (contents, "\n", 0);
for (line = lines; *line; ++line)
{
if (**line)
{
GFile *location;
gchar *pos;
gchar *name;
/* CHECK: is this really utf8? */
pos = g_utf8_strchr (*line, -1, ' ');
if (pos != NULL)
{
*pos = '\0';
name = pos + 1;
}
else
{
name = NULL;
}
/* the bookmarks file should contain valid
* URIs, but paranoia is good */
location = g_file_new_for_uri (*line);
if (xed_utils_is_valid_location (location))
{
*added |= add_bookmark (model, name, *line);
}
g_object_unref (location);
}
}
g_strfreev (lines);
g_free (contents);
/* Add a watch */
if (model->priv->bookmarks_monitor == NULL)
{
GFile * file;
file = g_file_new_for_path (bookmarks);
model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
g_signal_connect (model->priv->bookmarks_monitor, "changed",
G_CALLBACK (on_bookmarks_file_changed), model);
}
return TRUE;
}
static void
init_bookmarks (XedFileBookmarksStore *model)
{
gchar *bookmarks;
gboolean added = FALSE;
bookmarks = get_bookmarks_file ();
if (!parse_bookmarks_file (model, bookmarks, &added))
{
g_free (bookmarks);
/* try the old location (gtk <= 3.4) */
bookmarks = get_legacy_bookmarks_file ();
parse_bookmarks_file (model, bookmarks, &added);
} }
if (added) if (added)

View File

@ -2,8 +2,8 @@
#include "xed-file-browser-store.h" #include "xed-file-browser-store.h"
#include <xed/xed-message.h> #include <xed/xed-message.h>
#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" #define MESSAGE_OBJECT_PATH "/plugins/filebrowser"
#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" #define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData"
#define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL) #define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL)
@ -41,7 +41,7 @@ typedef struct
static WindowData * static WindowData *
window_data_new (XedWindow *window, window_data_new (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
WindowData *data = g_slice_new (WindowData); WindowData *data = g_slice_new (WindowData);
GtkUIManager *manager; GtkUIManager *manager;
@ -50,14 +50,14 @@ window_data_new (XedWindow *window,
data->bus = xed_window_get_message_bus (window); data->bus = xed_window_get_message_bus (window);
data->widget = widget; data->widget = widget;
data->row_tracking = g_hash_table_new_full (g_str_hash, data->row_tracking = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
(GDestroyNotify)gtk_tree_row_reference_free); (GDestroyNotify)gtk_tree_row_reference_free);
data->filters = g_hash_table_new_full (g_str_hash, data->filters = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
NULL); NULL);
manager = xed_file_browser_widget_get_ui_manager (widget); manager = xed_file_browser_widget_get_ui_manager (widget);
@ -92,7 +92,9 @@ window_data_free (XedWindow *window)
gtk_ui_manager_remove_action_group (manager, data->merged_actions); gtk_ui_manager_remove_action_group (manager, data->merged_actions);
for (item = data->merge_ids; item; item = item->next) for (item = data->merge_ids; item; item = item->next)
{
gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data)); gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data));
}
g_list_free (data->merge_ids); g_list_free (data->merge_ids);
g_object_unref (data->merged_actions); g_object_unref (data->merged_actions);
@ -104,7 +106,7 @@ window_data_free (XedWindow *window)
static FilterData * static FilterData *
filter_data_new (XedWindow *window, filter_data_new (XedWindow *window,
XedMessage *message) XedMessage *message)
{ {
FilterData *data = g_slice_new (FilterData); FilterData *data = g_slice_new (FilterData);
WindowData *wdata; WindowData *wdata;
@ -115,10 +117,8 @@ filter_data_new (XedWindow *window,
wdata = get_window_data (window); wdata = get_window_data (window);
g_hash_table_insert (wdata->filters, g_hash_table_insert (wdata->filters, xed_message_type_identifier (xed_message_get_object_path (message),
xed_message_type_identifier (xed_message_get_object_path (message), xed_message_get_method (message)), data);
xed_message_get_method (message)),
data);
return data; return data;
} }
@ -130,7 +130,7 @@ filter_data_free (FilterData *data)
gchar *identifier; gchar *identifier;
identifier = xed_message_type_identifier (xed_message_get_object_path (data->message), identifier = xed_message_type_identifier (xed_message_get_object_path (data->message),
xed_message_get_method (data->message)); xed_message_get_method (data->message));
g_hash_table_remove (wdata->filters, identifier); g_hash_table_remove (wdata->filters, identifier);
g_free (identifier); g_free (identifier);
@ -141,14 +141,16 @@ filter_data_free (FilterData *data)
static GtkTreePath * static GtkTreePath *
track_row_lookup (WindowData *data, track_row_lookup (WindowData *data,
const gchar *id) const gchar *id)
{ {
GtkTreeRowReference *ref; GtkTreeRowReference *ref;
ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id); ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id);
if (!ref) if (!ref)
{
return NULL; return NULL;
}
return gtk_tree_row_reference_get_path (ref); return gtk_tree_row_reference_get_path (ref);
} }
@ -161,8 +163,8 @@ message_cache_data_free (MessageCacheData *data)
} }
static MessageCacheData * static MessageCacheData *
message_cache_data_new (XedWindow *window, message_cache_data_new (XedWindow *window,
XedMessage *message) XedMessage *message)
{ {
MessageCacheData *data = g_slice_new (MessageCacheData); MessageCacheData *data = g_slice_new (MessageCacheData);
@ -174,8 +176,8 @@ message_cache_data_new (XedWindow *window,
static void static void
message_get_root_cb (XedMessageBus *bus, message_get_root_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserStore *store; XedFileBrowserStore *store;
GFile *location; GFile *location;
@ -192,8 +194,8 @@ message_get_root_cb (XedMessageBus *bus,
static void static void
message_set_root_cb (XedMessageBus *bus, message_set_root_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
GFile *root; GFile *root;
GFile *virtual = NULL; GFile *virtual = NULL;
@ -201,21 +203,29 @@ message_set_root_cb (XedMessageBus *bus,
xed_message_get (message, "location", &root, NULL); xed_message_get (message, "location", &root, NULL);
if (!root) if (!root)
{
return; return;
}
if (xed_message_has_key (message, "virtual")) if (xed_message_has_key (message, "virtual"))
{
xed_message_get (message, "virtual", &virtual, NULL); xed_message_get (message, "virtual", &virtual, NULL);
}
if (virtual) if (virtual)
{
xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual); xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual);
}
else else
{
xed_file_browser_widget_set_root (data->widget, root, TRUE); xed_file_browser_widget_set_root (data->widget, root, TRUE);
}
} }
static void static void
message_set_emblem_cb (XedMessageBus *bus, message_set_emblem_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gchar *id = NULL; gchar *id = NULL;
gchar *emblem = NULL; gchar *emblem = NULL;
@ -239,11 +249,7 @@ message_set_emblem_cb (XedMessageBus *bus,
GError *error = NULL; GError *error = NULL;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), emblem, 10, 0, &error);
emblem,
10,
0,
&error);
if (pixbuf) if (pixbuf)
{ {
@ -257,10 +263,7 @@ message_set_emblem_cb (XedMessageBus *bus,
g_value_init (&value, GDK_TYPE_PIXBUF); g_value_init (&value, GDK_TYPE_PIXBUF);
g_value_set_object (&value, pixbuf); g_value_set_object (&value, pixbuf);
xed_file_browser_store_set_value (store, xed_file_browser_store_set_value (store, &iter, XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, &value);
&iter,
XED_FILE_BROWSER_STORE_COLUMN_EMBLEM,
&value);
g_value_unset (&value); g_value_unset (&value);
} }
@ -278,7 +281,7 @@ message_set_emblem_cb (XedMessageBus *bus,
static gchar * static gchar *
item_id (const gchar *path, item_id (const gchar *path,
GFile *location) GFile *location)
{ {
gchar *uri; gchar *uri;
gchar *id; gchar *id;
@ -291,10 +294,10 @@ item_id (const gchar *path,
} }
static gchar * static gchar *
track_row (WindowData *data, track_row (WindowData *data,
XedFileBrowserStore *store, XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
GFile *location) GFile *location)
{ {
GtkTreeRowReference *ref; GtkTreeRowReference *ref;
gchar *id; gchar *id;
@ -312,51 +315,51 @@ track_row (WindowData *data,
} }
static void static void
set_item_message (WindowData *data, set_item_message (WindowData *data,
GtkTreeIter *iter, GtkTreeIter *iter,
GtkTreePath *path, GtkTreePath *path,
XedMessage *message) XedMessage *message)
{ {
XedFileBrowserStore *store; XedFileBrowserStore *store;
GFile *location; GFile *location;
guint flags = 0; guint flags = 0;
gchar *track_id;
store = xed_file_browser_widget_get_browser_store (data->widget); store = xed_file_browser_widget_get_browser_store (data->widget);
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!location) if (location)
return;
if (path && gtk_tree_path_get_depth (path) != 0)
track_id = track_row (data, store, path, location);
else
track_id = NULL;
xed_message_set (message,
"id", track_id,
"location", location,
NULL);
if (xed_message_has_key (message, "is_directory"))
{ {
xed_message_set (message, gchar *track_id;
"is_directory", FILE_IS_DIR (flags),
NULL);
}
g_free (track_id); if (path && gtk_tree_path_get_depth (path) != 0)
{
track_id = track_row (data, store, path, location);
}
else
{
track_id = NULL;
}
xed_message_set (message, "id", track_id, "location", location, NULL);
if (xed_message_has_key (message, "is_directory"))
{
xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL);
}
g_free (track_id);
g_object_unref (location);
}
} }
static gboolean static gboolean
custom_message_filter_func (XedFileBrowserWidget *widget, custom_message_filter_func (XedFileBrowserWidget *widget,
XedFileBrowserStore *store, XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
FilterData *data) FilterData *data)
{ {
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
GFile *location; GFile *location;
@ -365,9 +368,9 @@ custom_message_filter_func (XedFileBrowserWidget *widget,
GtkTreePath *path; GtkTreePath *path;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!location || FILE_IS_DUMMY (flags)) if (!location || FILE_IS_DUMMY (flags))
{ {
@ -383,13 +386,15 @@ custom_message_filter_func (XedFileBrowserWidget *widget,
xed_message_bus_send_message_sync (wdata->bus, data->message); xed_message_bus_send_message_sync (wdata->bus, data->message);
xed_message_get (data->message, "filter", &filter, NULL); xed_message_get (data->message, "filter", &filter, NULL);
g_object_unref (location);
return !filter; return !filter;
} }
static void static void
message_add_filter_cb (XedMessageBus *bus, message_add_filter_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
XedWindow *window) XedWindow *window)
{ {
gchar *object_path = NULL; gchar *object_path = NULL;
gchar *method = NULL; gchar *method = NULL;
@ -399,10 +404,7 @@ message_add_filter_cb (XedMessageBus *bus,
FilterData *filter_data; FilterData *filter_data;
WindowData *data = get_window_data (window); WindowData *data = get_window_data (window);
xed_message_get (message, xed_message_get (message, "object_path", &object_path, "method", &method, NULL);
"object_path", &object_path,
"method", &method,
NULL);
// Check if there exists such a 'callback' message // Check if there exists such a 'callback' message
if (!object_path || !method) if (!object_path || !method)
@ -433,41 +435,43 @@ message_add_filter_cb (XedMessageBus *bus,
} }
cbmessage = xed_message_type_instantiate (message_type, cbmessage = xed_message_type_instantiate (message_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
"filter", FALSE, "filter", FALSE,
NULL); NULL);
// Register the custom filter on the widget // Register the custom filter on the widget
filter_data = filter_data_new (window, cbmessage); filter_data = filter_data_new (window, cbmessage);
id = xed_file_browser_widget_add_filter (data->widget, id = xed_file_browser_widget_add_filter (data->widget,
(XedFileBrowserWidgetFilterFunc)custom_message_filter_func, (XedFileBrowserWidgetFilterFunc)custom_message_filter_func,
filter_data, filter_data,
(GDestroyNotify)filter_data_free); (GDestroyNotify)filter_data_free);
filter_data->id = id; filter_data->id = id;
} }
static void static void
message_remove_filter_cb (XedMessageBus *bus, message_remove_filter_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gulong id = 0; gulong id = 0;
xed_message_get (message, "id", &id, NULL); xed_message_get (message, "id", &id, NULL);
if (!id) if (!id)
{
return; return;
}
xed_file_browser_widget_remove_filter (data->widget, id); xed_file_browser_widget_remove_filter (data->widget, id);
} }
static void static void
message_up_cb (XedMessageBus *bus, message_up_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget); XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget);
@ -476,32 +480,32 @@ message_up_cb (XedMessageBus *bus,
static void static void
message_history_back_cb (XedMessageBus *bus, message_history_back_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_history_back (data->widget); xed_file_browser_widget_history_back (data->widget);
} }
static void static void
message_history_forward_cb (XedMessageBus *bus, message_history_forward_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_history_forward (data->widget); xed_file_browser_widget_history_forward (data->widget);
} }
static void static void
message_refresh_cb (XedMessageBus *bus, message_refresh_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_refresh (data->widget); xed_file_browser_widget_refresh (data->widget);
} }
static void static void
message_set_show_hidden_cb (XedMessageBus *bus, message_set_show_hidden_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gboolean active = FALSE; gboolean active = FALSE;
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -513,17 +517,21 @@ message_set_show_hidden_cb (XedMessageBus *bus,
mode = xed_file_browser_store_get_filter_mode (store); mode = xed_file_browser_store_get_filter_mode (store);
if (active) if (active)
{
mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
}
else else
{
mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
}
xed_file_browser_store_set_filter_mode (store, mode); xed_file_browser_store_set_filter_mode (store, mode);
} }
static void static void
message_set_show_binary_cb (XedMessageBus *bus, message_set_show_binary_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gboolean active = FALSE; gboolean active = FALSE;
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -535,33 +543,37 @@ message_set_show_binary_cb (XedMessageBus *bus,
mode = xed_file_browser_store_get_filter_mode (store); mode = xed_file_browser_store_get_filter_mode (store);
if (active) if (active)
{
mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
}
else else
{
mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
}
xed_file_browser_store_set_filter_mode (store, mode); xed_file_browser_store_set_filter_mode (store, mode);
} }
static void static void
message_show_bookmarks_cb (XedMessageBus *bus, message_show_bookmarks_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_show_bookmarks (data->widget); xed_file_browser_widget_show_bookmarks (data->widget);
} }
static void static void
message_show_files_cb (XedMessageBus *bus, message_show_files_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_show_files (data->widget); xed_file_browser_widget_show_files (data->widget);
} }
static void static void
message_add_context_item_cb (XedMessageBus *bus, message_add_context_item_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
GtkAction *action = NULL; GtkAction *action = NULL;
gchar *path = NULL; gchar *path = NULL;
@ -569,15 +581,14 @@ message_add_context_item_cb (XedMessageBus *bus,
GtkUIManager *manager; GtkUIManager *manager;
guint merge_id; guint merge_id;
xed_message_get (message, xed_message_get (message, "action", &action, "path", &path, NULL);
"action", &action,
"path", &path,
NULL);
if (!action || !path) if (!action || !path)
{ {
if (action) if (action)
{
g_object_unref (action); g_object_unref (action);
}
g_free (path); g_free (path);
return; return;
@ -589,12 +600,12 @@ message_add_context_item_cb (XedMessageBus *bus,
merge_id = gtk_ui_manager_new_merge_id (manager); merge_id = gtk_ui_manager_new_merge_id (manager);
gtk_ui_manager_add_ui (manager, gtk_ui_manager_add_ui (manager,
merge_id, merge_id,
path, path,
name, name,
gtk_action_get_name (action), gtk_action_get_name (action),
GTK_UI_MANAGER_AUTO, GTK_UI_MANAGER_AUTO,
FALSE); FALSE);
if (gtk_ui_manager_get_widget (manager, path)) if (gtk_ui_manager_get_widget (manager, path))
{ {
@ -613,8 +624,8 @@ message_add_context_item_cb (XedMessageBus *bus,
static void static void
message_remove_context_item_cb (XedMessageBus *bus, message_remove_context_item_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
guint merge_id = 0; guint merge_id = 0;
GtkUIManager *manager; GtkUIManager *manager;
@ -622,7 +633,9 @@ message_remove_context_item_cb (XedMessageBus *bus,
xed_message_get (message, "id", &merge_id, NULL); xed_message_get (message, "id", &merge_id, NULL);
if (merge_id == 0) if (merge_id == 0)
{
return; return;
}
manager = xed_file_browser_widget_get_ui_manager (data->widget); manager = xed_file_browser_widget_get_ui_manager (data->widget);
@ -632,8 +645,8 @@ message_remove_context_item_cb (XedMessageBus *bus,
static void static void
message_get_view_cb (XedMessageBus *bus, message_get_view_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserView *view; XedFileBrowserView *view;
view = xed_file_browser_widget_get_browser_view (data->widget); view = xed_file_browser_widget_get_browser_view (data->widget);
@ -643,59 +656,59 @@ message_get_view_cb (XedMessageBus *bus,
static void static void
register_methods (XedWindow *window, register_methods (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
XedMessageBus *bus = xed_window_get_message_bus (window); XedMessageBus *bus = xed_window_get_message_bus (window);
WindowData *data = get_window_data (window); WindowData *data = get_window_data (window);
/* Register method calls */ /* Register method calls */
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "get_root", MESSAGE_OBJECT_PATH, "get_root",
1, 1,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_root", MESSAGE_OBJECT_PATH, "set_root",
1, 1,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"virtual", G_TYPE_STRING, "virtual", G_TYPE_STRING,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_emblem", MESSAGE_OBJECT_PATH, "set_emblem",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"emblem", G_TYPE_STRING, "emblem", G_TYPE_STRING,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "add_filter", MESSAGE_OBJECT_PATH, "add_filter",
1, 1,
"object_path", G_TYPE_STRING, "object_path", G_TYPE_STRING,
"method", G_TYPE_STRING, "method", G_TYPE_STRING,
"id", G_TYPE_ULONG, "id", G_TYPE_ULONG,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "remove_filter", MESSAGE_OBJECT_PATH, "remove_filter",
0, 0,
"id", G_TYPE_ULONG, "id", G_TYPE_ULONG,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "add_context_item", MESSAGE_OBJECT_PATH, "add_context_item",
1, 1,
"action", GTK_TYPE_ACTION, "action", GTK_TYPE_ACTION,
"path", G_TYPE_STRING, "path", G_TYPE_STRING,
"id", G_TYPE_UINT, "id", G_TYPE_UINT,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "remove_context_item", MESSAGE_OBJECT_PATH, "remove_context_item",
0, 0,
"id", G_TYPE_UINT, "id", G_TYPE_UINT,
NULL); NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL);
@ -705,24 +718,24 @@ register_methods (XedWindow *window,
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_show_hidden", MESSAGE_OBJECT_PATH, "set_show_hidden",
0, 0,
"active", G_TYPE_BOOLEAN, "active", G_TYPE_BOOLEAN,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_show_binary", MESSAGE_OBJECT_PATH, "set_show_binary",
0, 0,
"active", G_TYPE_BOOLEAN, "active", G_TYPE_BOOLEAN,
NULL); NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "get_view", MESSAGE_OBJECT_PATH, "get_view",
1, 1,
"view", XED_TYPE_FILE_BROWSER_VIEW, "view", XED_TYPE_FILE_BROWSER_VIEW,
NULL); NULL);
BUS_CONNECT (bus, get_root, data); BUS_CONNECT (bus, get_root, data);
BUS_CONNECT (bus, set_root, data); BUS_CONNECT (bus, set_root, data);
@ -750,15 +763,15 @@ register_methods (XedWindow *window,
static void static void
store_row_inserted (XedFileBrowserStore *store, store_row_inserted (XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
guint flags = 0; guint flags = 0;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{ {
@ -771,18 +784,20 @@ store_row_inserted (XedFileBrowserStore *store,
static void static void
store_row_deleted (XedFileBrowserStore *store, store_row_deleted (XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreeIter iter; GtkTreeIter iter;
guint flags = 0; guint flags = 0;
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
{
return; return;
}
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{ {
@ -795,8 +810,8 @@ store_row_deleted (XedFileBrowserStore *store,
static void static void
store_virtual_root_changed (XedFileBrowserStore *store, store_virtual_root_changed (XedFileBrowserStore *store,
GParamSpec *spec, GParamSpec *spec,
MessageCacheData *data) MessageCacheData *data)
{ {
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
GFile *vroot; GFile *vroot;
@ -804,11 +819,11 @@ store_virtual_root_changed (XedFileBrowserStore *store,
vroot = xed_file_browser_store_get_virtual_root (store); vroot = xed_file_browser_store_get_virtual_root (store);
if (!vroot) if (!vroot)
{
return; return;
}
xed_message_set (data->message, xed_message_set (data->message, "location", vroot, NULL);
"location", vroot,
NULL);
xed_message_bus_send_message_sync (wdata->bus, data->message); xed_message_bus_send_message_sync (wdata->bus, data->message);
@ -817,8 +832,8 @@ store_virtual_root_changed (XedFileBrowserStore *store,
static void static void
store_begin_loading (XedFileBrowserStore *store, store_begin_loading (XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreePath *path; GtkTreePath *path;
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
@ -833,8 +848,8 @@ store_begin_loading (XedFileBrowserStore *store,
static void static void
store_end_loading (XedFileBrowserStore *store, store_end_loading (XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreePath *path; GtkTreePath *path;
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
@ -849,7 +864,7 @@ store_end_loading (XedFileBrowserStore *store,
static void static void
register_signals (XedWindow *window, register_signals (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
XedMessageBus *bus = xed_window_get_message_bus (window); XedMessageBus *bus = xed_window_get_message_bus (window);
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -864,141 +879,141 @@ register_signals (XedWindow *window,
/* Register signals */ /* Register signals */
root_changed_type = xed_message_bus_register (bus, root_changed_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "root_changed", MESSAGE_OBJECT_PATH, "root_changed",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
begin_loading_type = xed_message_bus_register (bus, begin_loading_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "begin_loading", MESSAGE_OBJECT_PATH, "begin_loading",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
end_loading_type = xed_message_bus_register (bus, end_loading_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "end_loading", MESSAGE_OBJECT_PATH, "end_loading",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
inserted_type = xed_message_bus_register (bus, inserted_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "inserted", MESSAGE_OBJECT_PATH, "inserted",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"is_directory", G_TYPE_BOOLEAN, "is_directory", G_TYPE_BOOLEAN,
NULL); NULL);
deleted_type = xed_message_bus_register (bus, deleted_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "deleted", MESSAGE_OBJECT_PATH, "deleted",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"is_directory", G_TYPE_BOOLEAN, "is_directory", G_TYPE_BOOLEAN,
NULL); NULL);
store = xed_file_browser_widget_get_browser_store (widget); store = xed_file_browser_widget_get_browser_store (widget);
message = xed_message_type_instantiate (inserted_type, message = xed_message_type_instantiate (inserted_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
NULL); NULL);
data = get_window_data (window); data = get_window_data (window);
data->row_inserted_id = data->row_inserted_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"row-inserted", "row-inserted",
G_CALLBACK (store_row_inserted), G_CALLBACK (store_row_inserted),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (deleted_type, message = xed_message_type_instantiate (deleted_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
NULL); NULL);
data->row_deleted_id = data->row_deleted_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"row-deleted", "row-deleted",
G_CALLBACK (store_row_deleted), G_CALLBACK (store_row_deleted),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (root_changed_type, message = xed_message_type_instantiate (root_changed_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->root_changed_id = data->root_changed_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"notify::virtual-root", "notify::virtual-root",
G_CALLBACK (store_virtual_root_changed), G_CALLBACK (store_virtual_root_changed),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (begin_loading_type, message = xed_message_type_instantiate (begin_loading_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->begin_loading_id = data->begin_loading_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"begin_loading", "begin_loading",
G_CALLBACK (store_begin_loading), G_CALLBACK (store_begin_loading),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (end_loading_type, message = xed_message_type_instantiate (end_loading_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->end_loading_id = data->end_loading_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"end_loading", "end_loading",
G_CALLBACK (store_end_loading), G_CALLBACK (store_end_loading),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
} }
static void static void
message_unregistered (XedMessageBus *bus, message_unregistered (XedMessageBus *bus,
XedMessageType *message_type, XedMessageType *message_type,
XedWindow *window) XedWindow *window)
{ {
gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type),
xed_message_type_get_method (message_type)); xed_message_type_get_method (message_type));
FilterData *data; FilterData *data;
WindowData *wdata = get_window_data (window); WindowData *wdata = get_window_data (window);
data = g_hash_table_lookup (wdata->filters, identifier); data = g_hash_table_lookup (wdata->filters, identifier);
if (data) if (data)
{
xed_file_browser_widget_remove_filter (wdata->widget, data->id); xed_file_browser_widget_remove_filter (wdata->widget, data->id);
}
g_free (identifier); g_free (identifier);
} }
void void
xed_file_browser_messages_register (XedWindow *window, xed_file_browser_messages_register (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
window_data_new (window, widget); window_data_new (window, widget);
register_methods (window, widget); register_methods (window, widget);
register_signals (window, widget); register_signals (window, widget);
g_signal_connect (xed_window_get_message_bus (window), g_signal_connect (xed_window_get_message_bus (window), "unregistered",
"unregistered", G_CALLBACK (message_unregistered), window);
G_CALLBACK (message_unregistered),
window);
} }
static void static void

View File

@ -337,21 +337,11 @@ on_action_set_active_root (GtkAction *action,
set_root_from_doc (plugin, xed_window_get_active_document (XED_WINDOW (plugin->priv->window))); set_root_from_doc (plugin, xed_window_get_active_document (XED_WINDOW (plugin->priv->window)));
} }
static gchar *
get_terminal (XedFileBrowserPlugin *plugin)
{
// TODO : Identify the DE, find the preferred terminal application (xterminal shouldn't be hardcoded here, it should be set as default in the DE prefs)
return g_strdup ("xterminal");
}
static void static void
on_action_open_terminal (GtkAction *action, on_action_open_terminal (GtkAction *action,
XedFileBrowserPlugin *plugin) XedFileBrowserPlugin *plugin)
{ {
XedFileBrowserPluginPrivate *priv = plugin->priv; XedFileBrowserPluginPrivate *priv = plugin->priv;
gchar *terminal;
gchar *local;
gchar *argv[2];
GFile *file; GFile *file;
GtkTreeIter iter; GtkTreeIter iter;
@ -366,29 +356,31 @@ on_action_open_terminal (GtkAction *action,
store = xed_file_browser_widget_get_browser_store (priv->tree_widget); store = xed_file_browser_widget_get_browser_store (priv->tree_widget);
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &file, -1); gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &file, -1);
if (file == NULL) if (file)
{ {
return; gchar *terminal;
gchar *local;
gchar *argv[2];
terminal = g_settings_get_string (priv->settings, "terminal-command");
local = g_file_get_path (file);
argv[0] = terminal;
argv[1] = NULL;
g_spawn_async (local,
argv,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL);
g_free (terminal);
g_free (local);
g_object_unref (file);
} }
terminal = get_terminal (plugin);
local = g_file_get_path (file);
argv[0] = terminal;
argv[1] = NULL;
g_spawn_async (local,
argv,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL);
g_free (terminal);
g_free (local);
} }
static void static void
@ -400,7 +392,6 @@ on_selection_changed_cb (GtkTreeSelection *selection,
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; GtkTreeIter iter;
gboolean sensitive; gboolean sensitive;
GFile *location;
tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget)); tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget));
model = gtk_tree_view_get_model (tree_view); model = gtk_tree_view_get_model (tree_view);
@ -414,9 +405,19 @@ on_selection_changed_cb (GtkTreeSelection *selection,
if (sensitive) if (sensitive)
{ {
GFile *location;
gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
sensitive = g_file_has_uri_scheme (location, "file"); if (location)
{
sensitive = g_file_has_uri_scheme (location, "file");
g_object_unref (location);
}
else
{
sensitive = FALSE;
}
} }
gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive); gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive);
@ -478,7 +479,7 @@ add_popup_ui (XedFileBrowserPlugin *plugin)
gtk_action_group_add_actions (action_group, gtk_action_group_add_actions (action_group,
extra_single_selection_actions, extra_single_selection_actions,
G_N_ELEMENTS (extra_single_selection_actions), G_N_ELEMENTS (extra_single_selection_actions),
priv->window); plugin);
gtk_ui_manager_insert_action_group (manager, action_group, 0); gtk_ui_manager_insert_action_group (manager, action_group, 0);
priv->single_selection_action_group = action_group; priv->single_selection_action_group = action_group;
@ -927,11 +928,18 @@ get_filename_from_path (GtkTreeModel *model,
{ {
GtkTreeIter iter; GtkTreeIter iter;
GFile *location; GFile *location;
gchar *ret = NULL;
gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
return xed_file_browser_utils_file_basename (location); if (location)
{
ret = xed_file_browser_utils_file_basename (location);
g_object_unref (location);
}
return ret;
} }
static gboolean static gboolean
@ -961,8 +969,7 @@ on_confirm_no_trash_cb (XedFileBrowserWidget *widget,
GTK_MESSAGE_QUESTION, GTK_MESSAGE_QUESTION,
message, message,
secondary, secondary,
GTK_STOCK_DELETE, _("_Delete"));
NULL);
g_free (secondary); g_free (secondary);
return result; return result;
@ -997,8 +1004,7 @@ on_confirm_delete_cb (XedFileBrowserWidget *widget,
GTK_MESSAGE_QUESTION, GTK_MESSAGE_QUESTION,
message, message,
secondary, secondary,
GTK_STOCK_DELETE, _("_Delete"));
NULL);
g_free (message); g_free (message);

View File

@ -104,7 +104,6 @@ struct _FileBrowserNodeDir
{ {
FileBrowserNode node; FileBrowserNode node;
GSList *children; GSList *children;
GHashTable *hidden_file_hash;
GCancellable *cancellable; GCancellable *cancellable;
GFileMonitor *monitor; GFileMonitor *monitor;
@ -131,12 +130,12 @@ static FileBrowserNode *model_find_node (XedFileBrowserStore *model,
FileBrowserNode *node, FileBrowserNode *node,
GFile *uri); GFile *uri);
static void model_remove_node (XedFileBrowserStore *model, static void model_remove_node (XedFileBrowserStore *model,
FileBrowserNode *node, FileBrowserNode *node,
GtkTreePath *path, GtkTreePath *path,
gboolean free_nodes); gboolean free_nodes);
static void set_virtual_root_from_node (XedFileBrowserStore *model, static void set_virtual_root_from_node (XedFileBrowserStore *model,
FileBrowserNode *node); FileBrowserNode *node);
static void xed_file_browser_store_iface_init (GtkTreeModelIface *iface); static void xed_file_browser_store_iface_init (GtkTreeModelIface *iface);
static GtkTreeModelFlags xed_file_browser_store_get_flags (GtkTreeModel *tree_model); static GtkTreeModelFlags xed_file_browser_store_get_flags (GtkTreeModel *tree_model);
@ -158,42 +157,44 @@ static gboolean xed_file_browser_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter, GtkTreeIter *iter,
GtkTreeIter *parent); GtkTreeIter *parent);
static gboolean xed_file_browser_store_iter_has_child (GtkTreeModel *tree_model, static gboolean xed_file_browser_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter); GtkTreeIter *iter);
static gint xed_file_browser_store_iter_n_children (GtkTreeModel *tree_model, static gint xed_file_browser_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter * iter); GtkTreeIter *iter);
static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model, static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter * iter, GtkTreeIter *iter,
GtkTreeIter * parent, GtkTreeIter *parent,
gint n); gint n);
static gboolean xed_file_browser_store_iter_parent (GtkTreeModel * tree_model, static gboolean xed_file_browser_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter * iter, GtkTreeIter *iter,
GtkTreeIter * child); GtkTreeIter *child);
static void xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, static void xed_file_browser_store_row_inserted (GtkTreeModel *tree_model,
GtkTreePath * path, GtkTreePath *path,
GtkTreeIter * iter); GtkTreeIter *iter);
static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface * iface); static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface *iface);
static gboolean xed_file_browser_store_row_draggable (GtkTreeDragSource * drag_source, static gboolean xed_file_browser_store_row_draggable (GtkTreeDragSource *drag_source,
GtkTreePath * path); GtkTreePath *path);
static gboolean xed_file_browser_store_drag_data_delete (GtkTreeDragSource * drag_source, static gboolean xed_file_browser_store_drag_data_delete (GtkTreeDragSource *drag_source,
GtkTreePath * path); GtkTreePath *path);
static gboolean xed_file_browser_store_drag_data_get (GtkTreeDragSource * drag_source, static gboolean xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source,
GtkTreePath * path, GtkTreePath *path,
GtkSelectionData * selection_data); GtkSelectionData *selection_data);
static void file_browser_node_free (XedFileBrowserStore * model, static void file_browser_node_free (XedFileBrowserStore *model,
FileBrowserNode * node); FileBrowserNode *node);
static void model_add_node (XedFileBrowserStore * model, static void model_add_node (XedFileBrowserStore *model,
FileBrowserNode * child, FileBrowserNode *child,
FileBrowserNode * parent); FileBrowserNode *parent);
static void model_clear (XedFileBrowserStore * model, static void model_clear (XedFileBrowserStore *model,
gboolean free_nodes); gboolean free_nodes);
static gint model_sort_default (FileBrowserNode * node1, static gint model_sort_default (FileBrowserNode *node1,
FileBrowserNode * node2); FileBrowserNode *node2);
static void model_check_dummy (XedFileBrowserStore * model, static void model_check_dummy (XedFileBrowserStore *model,
FileBrowserNode * node); FileBrowserNode *node);
static void next_files_async (GFileEnumerator * enumerator, static void next_files_async (GFileEnumerator *enumerator,
AsyncNode * async); AsyncNode *async);
static void delete_files (AsyncData *data);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store, G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store,
G_TYPE_OBJECT, G_TYPE_OBJECT,
@ -1027,6 +1028,7 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source,
ret = gtk_selection_data_set_uris (selection_data, uris); ret = gtk_selection_data_set_uris (selection_data, uris);
g_free (uris[0]); g_free (uris[0]);
g_object_unref (location);
return ret; return ret;
} }
@ -1471,11 +1473,6 @@ file_browser_node_free (XedFileBrowserStore *model,
g_file_monitor_cancel (dir->monitor); g_file_monitor_cancel (dir->monitor);
g_object_unref (dir->monitor); g_object_unref (dir->monitor);
} }
if (dir->hidden_file_hash)
{
g_hash_table_destroy (dir->hidden_file_hash);
}
} }
if (node->file) if (node->file)
@ -2082,9 +2079,7 @@ file_browser_node_set_from_info (XedFileBrowserStore *model,
GFileInfo *info, GFileInfo *info,
gboolean isadded) gboolean isadded)
{ {
FileBrowserNodeDir *dir;
gchar const *content; gchar const *content;
gchar const *name;
gboolean free_info = FALSE; gboolean free_info = FALSE;
GtkTreePath *path; GtkTreePath *path;
gchar *uri; gchar *uri;
@ -2114,17 +2109,10 @@ file_browser_node_set_from_info (XedFileBrowserStore *model,
free_info = TRUE; free_info = TRUE;
} }
dir = FILE_BROWSER_NODE_DIR (node->parent);
name = g_file_info_get_name (info);
if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info)) if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info))
{ {
node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
} }
else if (dir != NULL && dir->hidden_file_hash != NULL && g_hash_table_lookup (dir->hidden_file_hash, name) != NULL)
{
node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
}
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{ {
@ -2276,15 +2264,17 @@ model_add_nodes_from_files (XedFileBrowserStore *model,
(strcmp (name, ".") == 0 || (strcmp (name, ".") == 0 ||
strcmp (name, "..") == 0)) strcmp (name, "..") == 0))
{ {
g_object_unref (info);
continue; continue;
} }
file = g_file_get_child (parent->file, name); file = g_file_get_child (parent->file, name);
if ((node = node_list_contains_file (original_children, file)) == NULL) node = node_list_contains_file (original_children, file);
if (node == NULL)
{ {
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) if (type == G_FILE_TYPE_DIRECTORY)
{ {
node = file_browser_node_dir_new (model, file, parent); node = file_browser_node_dir_new (model, file, parent);
} }
@ -2337,83 +2327,6 @@ model_add_node_from_dir (XedFileBrowserStore *model,
return node; return node;
} }
/* Read is sync, but we only do it for local files */
static void
parse_dot_hidden_file (FileBrowserNode *directory)
{
gsize file_size;
char *file_contents;
GFile *child;
GFileInfo *info;
GFileType type;
int i;
FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (directory);
/* FIXME: We only support .hidden on file: uri's for the moment.
* Need to figure out if we should do this async or sync to extend
* it to all types of uris.
*/
if (directory->file == NULL || !g_file_is_native (directory->file))
{
return;
}
child = g_file_get_child (directory->file, ".hidden");
info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN;
if (info)
{
g_object_unref (info);
}
if (type != G_FILE_TYPE_REGULAR)
{
g_object_unref (child);
return;
}
if (!g_file_load_contents (child, NULL, &file_contents, &file_size, NULL, NULL))
{
g_object_unref (child);
return;
}
g_object_unref (child);
if (dir->hidden_file_hash == NULL)
{
dir->hidden_file_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
/* Now parse the data */
i = 0;
while (i < file_size)
{
int start;
start = i;
while (i < file_size && file_contents[i] != '\n')
{
i++;
}
if (i > start)
{
char *hidden_filename;
hidden_filename = g_strndup (file_contents + start, i - start);
g_hash_table_insert (dir->hidden_file_hash, hidden_filename, hidden_filename);
}
i++;
}
g_free (file_contents);
}
static void static void
on_directory_monitor_event (GFileMonitor *monitor, on_directory_monitor_event (GFileMonitor *monitor,
GFile *file, GFile *file,
@ -2451,7 +2364,7 @@ async_node_free (AsyncNode *async)
{ {
g_object_unref (async->cancellable); g_object_unref (async->cancellable);
g_slist_free (async->original_children); g_slist_free (async->original_children);
g_free (async); g_slice_free (AsyncNode, async);
} }
static void static void
@ -2469,6 +2382,7 @@ model_iterate_next_files_cb (GFileEnumerator *enumerator,
if (files == NULL) if (files == NULL)
{ {
g_file_enumerator_close (enumerator, NULL, NULL); g_file_enumerator_close (enumerator, NULL, NULL);
g_object_unref (enumerator);
async_node_free (async); async_node_free (async);
if (!error) if (!error)
@ -2520,6 +2434,7 @@ model_iterate_next_files_cb (GFileEnumerator *enumerator,
{ {
/* Check cancel state manually */ /* Check cancel state manually */
g_file_enumerator_close (enumerator, NULL, NULL); g_file_enumerator_close (enumerator, NULL, NULL);
g_object_unref (enumerator);
async_node_free (async); async_node_free (async);
} }
else else
@ -2601,12 +2516,9 @@ model_load_directory (XedFileBrowserStore *model,
node->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; node->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED;
model_begin_loading (model, node); model_begin_loading (model, node);
/* Read the '.hidden' file first (if any) */
parse_dot_hidden_file (node);
dir->cancellable = g_cancellable_new (); dir->cancellable = g_cancellable_new ();
async = g_new (AsyncNode, 1); async = g_slice_new (AsyncNode);
async->dir = dir; async->dir = dir;
async->cancellable = g_object_ref (dir->cancellable); async->cancellable = g_object_ref (dir->cancellable);
async->original_children = g_slist_copy (dir->children); async->original_children = g_slist_copy (dir->children);
@ -3013,9 +2925,13 @@ mount_cb (GFile *file,
g_object_unref (mount_info->operation); g_object_unref (mount_info->operation);
g_object_unref (mount_info->cancellable); g_object_unref (mount_info->cancellable);
g_free (mount_info->virtual_root);
g_free (mount_info); if (mount_info->virtual_root)
{
g_object_unref (mount_info->virtual_root);
}
g_slice_free (MountInfo, mount_info);
} }
static XedFileBrowserStoreResult static XedFileBrowserStoreResult
@ -3039,7 +2955,7 @@ model_mount_root (XedFileBrowserStore *model,
/* Try to mount it */ /* Try to mount it */
FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new (); FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new ();
mount_info = g_new(MountInfo, 1); mount_info = g_slice_new (MountInfo);
mount_info->model = model; mount_info->model = model;
mount_info->virtual_root = g_file_dup (virtual_root); mount_info->virtual_root = g_file_dup (virtual_root);
@ -3633,7 +3549,7 @@ async_data_free (AsyncData *data)
data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data); data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data);
} }
g_free (data); g_slice_free (AsyncData, data);
} }
static gboolean static gboolean
@ -3646,93 +3562,101 @@ emit_no_trash (AsyncData *data)
return ret; return ret;
} }
typedef struct static void
delete_file_finished (GFile *file,
GAsyncResult *res,
AsyncData *data)
{ {
XedFileBrowserStore *model;
GFile *file;
} IdleDelete;
static gboolean
file_deleted (IdleDelete *data)
{
FileBrowserNode *node;
node = model_find_node (data->model, NULL, data->file);
if (node != NULL)
{
model_remove_node (data->model, node, NULL, TRUE);
}
return FALSE;
}
static gboolean
delete_files (GIOSchedulerJob *job,
GCancellable *cancellable,
AsyncData *data)
{
GFile *file;
GError *error = NULL; GError *error = NULL;
gboolean ret; gboolean ok;
gint code;
IdleDelete delete;
/* Check if our job is done */
if (!data->iter)
{
return FALSE;
}
/* Move a file to the trash */
file = G_FILE (data->iter->data);
if (data->trash) if (data->trash)
{ {
ret = g_file_trash (file, cancellable, &error); ok = g_file_trash_finish (file, res, &error);
} }
else else
{ {
ret = g_file_delete (file, cancellable, &error); ok = g_file_delete_finish (file, res, &error);
} }
if (ret) if (ok)
{ {
delete.model = data->model; /* Remove the file from the model */
delete.file = file; FileBrowserNode *node = model_find_node (data->model, NULL, file);
/* Remove the file from the model in the main loop */ if (node != NULL)
g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL); {
model_remove_node (data->model, node, NULL, TRUE);
}
/* Process the next file */
data->iter = data->iter->next;
} }
else if (!ret && error) else if (!ok && error != NULL)
{ {
code = error->code; gint code = error->code;
g_error_free (error); g_error_free (error);
if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED)
{ {
/* Trash is not supported on this system ... */ /* Trash is not supported on this system. Ask the user
if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL)) * if he wants to delete completely the files instead.
*/
if (emit_no_trash (data))
{ {
/* Changes this into a delete job */ /* Changes this into a delete job */
data->trash = FALSE; data->trash = FALSE;
data->iter = data->files; data->iter = data->files;
return TRUE;
} }
else
/* End the job */ {
return FALSE; /* End the job */
async_data_free (data);
return;
}
} }
else if (code == G_IO_ERROR_CANCELLED) else if (code == G_IO_ERROR_CANCELLED)
{ {
/* Job has been cancelled, just let the job end */ /* Job has been cancelled, end the job */
return FALSE; async_data_free (data);
return;
} }
} }
/* Process the next item */ /* Continue the job */
data->iter = data->iter->next; delete_files (data);
return TRUE; }
static void
delete_files (AsyncData *data)
{
GFile *file;
/* Check if our job is done */
if (data->iter == NULL)
{
async_data_free (data);
return;
}
file = G_FILE (data->iter->data);
if (data->trash)
{
g_file_trash_async (file,
G_PRIORITY_DEFAULT,
data->cancellable,
(GAsyncReadyCallback)delete_file_finished,
data);
}
else
{
g_file_delete_async (file,
G_PRIORITY_DEFAULT,
data->cancellable,
(GAsyncReadyCallback)delete_file_finished,
data);
}
} }
XedFileBrowserStoreResult XedFileBrowserStoreResult
@ -3781,7 +3705,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
files = g_list_prepend (files, g_object_ref (node->file)); files = g_list_prepend (files, g_object_ref (node->file));
} }
data = g_new (AsyncData, 1); data = g_slice_new (AsyncData);
data->model = model; data->model = model;
data->cancellable = g_cancellable_new (); data->cancellable = g_cancellable_new ();
@ -3792,11 +3716,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data); model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data);
g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, delete_files (data);
data,
(GDestroyNotify)async_data_free,
G_PRIORITY_DEFAULT,
data->cancellable);
g_list_free (rows); g_list_free (rows);
return XED_FILE_BROWSER_STORE_RESULT_OK; return XED_FILE_BROWSER_STORE_RESULT_OK;
@ -3851,7 +3771,7 @@ xed_file_browser_store_new_file (XedFileBrowserStore *model,
parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); parent_node = FILE_BROWSER_NODE_DIR (parent->user_data);
/* Translators: This is the default name of new files created by the file browser pane. */ /* Translators: This is the default name of new files created by the file browser pane. */
file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")); file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("Untitled File"));
stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error); stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
@ -3906,7 +3826,7 @@ xed_file_browser_store_new_directory (XedFileBrowserStore *model,
parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); parent_node = FILE_BROWSER_NODE_DIR (parent->user_data);
/* Translators: This is the default name of new directories created by the file browser pane. */ /* Translators: This is the default name of new directories created by the file browser pane. */
file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory")); file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("Untitled Folder"));
if (!g_file_make_directory (file, NULL, &error)) if (!g_file_make_directory (file, NULL, &error))
{ {

View File

@ -1,5 +1,5 @@
/* /*
* xed-file-bookmarks-store.c - Xed plugin providing easy file access * xed-file-browser-utils.c - Xed plugin providing easy file access
* from the sidepanel * from the sidepanel
* *
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl> * Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -19,167 +19,148 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "xed-file-browser-utils.h" #ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib/gi18n-lib.h>
#include <xed/xed-utils.h> #include <xed/xed-utils.h>
#include "xed-file-browser-utils.h"
static GdkPixbuf * static GdkPixbuf *
process_icon_pixbuf (GdkPixbuf * pixbuf, process_icon_pixbuf (GdkPixbuf *pixbuf,
gchar const * name, gchar const *name,
gint size, gint size,
GError * error) GError *error)
{ {
GdkPixbuf * scale; GdkPixbuf *scale;
if (error != NULL) { if (error != NULL)
g_warning ("Could not load theme icon %s: %s", {
name, g_warning ("Could not load theme icon %s: %s", name, error->message);
error->message); g_error_free (error);
g_error_free (error); }
}
if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size) { if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size)
scale = gdk_pixbuf_scale_simple (pixbuf, {
size, scale = gdk_pixbuf_scale_simple (pixbuf, size, size, GDK_INTERP_BILINEAR);
size, g_object_unref (pixbuf);
GDK_INTERP_BILINEAR); pixbuf = scale;
g_object_unref (pixbuf); }
pixbuf = scale;
}
return pixbuf; return pixbuf;
} }
GdkPixbuf * GdkPixbuf *
xed_file_browser_utils_pixbuf_from_theme (gchar const * name, xed_file_browser_utils_pixbuf_from_theme (gchar const *name,
GtkIconSize size) GtkIconSize size)
{ {
gint width; gint width;
GError *error = NULL; GError *error = NULL;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gtk_icon_size_lookup (size, &width, NULL); gtk_icon_size_lookup (size, &width, NULL);
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), name, width, 0, &error);
name,
width,
0,
&error);
pixbuf = process_icon_pixbuf (pixbuf, name, width, error); pixbuf = process_icon_pixbuf (pixbuf, name, width, error);
return pixbuf; return pixbuf;
} }
GdkPixbuf * GdkPixbuf *
xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, xed_file_browser_utils_pixbuf_from_icon (GIcon *icon,
GtkIconSize size) GtkIconSize size)
{ {
GdkPixbuf * ret = NULL; GdkPixbuf *ret = NULL;
GtkIconTheme *theme; GtkIconTheme *theme;
GtkIconInfo *info; GtkIconInfo *info;
gint width; gint width;
if (!icon) if (!icon)
return NULL; {
return NULL;
}
theme = gtk_icon_theme_get_default (); theme = gtk_icon_theme_get_default ();
gtk_icon_size_lookup (size, &width, NULL); gtk_icon_size_lookup (size, &width, NULL);
info = gtk_icon_theme_lookup_by_gicon (theme, info = gtk_icon_theme_lookup_by_gicon (theme, icon, width, GTK_ICON_LOOKUP_USE_BUILTIN);
icon,
width,
GTK_ICON_LOOKUP_USE_BUILTIN);
if (!info) if (!info)
return NULL; {
return NULL;
}
ret = gtk_icon_info_load_icon (info, NULL); ret = gtk_icon_info_load_icon (info, NULL);
gtk_icon_info_free (info); gtk_icon_info_free (info);
return ret; return ret;
} }
GdkPixbuf * GdkPixbuf *
xed_file_browser_utils_pixbuf_from_file (GFile * file, xed_file_browser_utils_pixbuf_from_file (GFile *file,
GtkIconSize size) GtkIconSize size)
{ {
GIcon * icon; GIcon *icon;
GFileInfo * info; GFileInfo *info;
GdkPixbuf * ret = NULL; GdkPixbuf *ret = NULL;
info = g_file_query_info (file, info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, NULL, NULL);
G_FILE_ATTRIBUTE_STANDARD_ICON,
G_FILE_QUERY_INFO_NONE,
NULL,
NULL);
if (!info) if (!info)
return NULL; {
return NULL;
}
icon = g_file_info_get_icon (info); icon = g_file_info_get_icon (info);
if (icon != NULL) if (icon != NULL)
ret = xed_file_browser_utils_pixbuf_from_icon (icon, size); {
ret = xed_file_browser_utils_pixbuf_from_icon (icon, size);
}
g_object_unref (info); g_object_unref (info);
return ret; return ret;
} }
gchar * gchar *
xed_file_browser_utils_file_basename (GFile * file) xed_file_browser_utils_file_basename (GFile *file)
{ {
return xed_utils_basename_for_display (file); return xed_utils_basename_for_display (file);
} }
gboolean gboolean
xed_file_browser_utils_confirmation_dialog (XedWindow * window, xed_file_browser_utils_confirmation_dialog (XedWindow *window,
GtkMessageType type, GtkMessageType type,
gchar const *message, gchar const *message,
gchar const *secondary, gchar const *secondary,
gchar const * button_stock, gchar const *button_label)
gchar const * button_label)
{ {
GtkWidget *dlg; GtkWidget *dlg;
gint ret; gint ret;
GtkWidget *button;
dlg = gtk_message_dialog_new (GTK_WINDOW (window), dlg = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL | GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
type, type,
GTK_BUTTONS_NONE, "%s", message); GTK_BUTTONS_NONE, "%s", message);
if (secondary) if (secondary)
gtk_message_dialog_format_secondary_text {
(GTK_MESSAGE_DIALOG (dlg), "%s", secondary); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), "%s", secondary);
}
/* Add a cancel button */ gtk_dialog_add_buttons (GTK_DIALOG (dlg),
button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); _("_Cancel"), GTK_RESPONSE_CANCEL,
gtk_widget_show (button); button_label, GTK_RESPONSE_OK,
NULL);
gtk_widget_set_can_default (button, TRUE); gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_CANCEL);
gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
button,
GTK_RESPONSE_CANCEL);
/* Add custom button */ ret = gtk_dialog_run (GTK_DIALOG (dlg));
button = gtk_button_new_from_stock (button_stock); gtk_widget_destroy (dlg);
if (button_label) { return (ret == GTK_RESPONSE_OK);
gtk_button_set_use_stock (GTK_BUTTON (button), FALSE);
gtk_button_set_label (GTK_BUTTON (button), button_label);
}
gtk_widget_show (button);
gtk_widget_set_can_default (button, TRUE);
gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
button,
GTK_RESPONSE_OK);
ret = gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
return (ret == GTK_RESPONSE_OK);
} }
// ex:ts=8:noet:

View File

@ -4,22 +4,21 @@
#include <xed/xed-window.h> #include <xed/xed-window.h>
#include <gio/gio.h> #include <gio/gio.h>
GdkPixbuf *xed_file_browser_utils_pixbuf_from_theme (gchar const *name, GdkPixbuf *xed_file_browser_utils_pixbuf_from_theme (gchar const *name,
GtkIconSize size); GtkIconSize size);
GdkPixbuf *xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, GdkPixbuf *xed_file_browser_utils_pixbuf_from_icon (GIcon *icon,
GtkIconSize size); GtkIconSize size);
GdkPixbuf *xed_file_browser_utils_pixbuf_from_file (GFile * file, GdkPixbuf *xed_file_browser_utils_pixbuf_from_file (GFile *file,
GtkIconSize size); GtkIconSize size);
gchar * xed_file_browser_utils_file_basename (GFile * file); gchar * xed_file_browser_utils_file_basename (GFile *file);
gboolean xed_file_browser_utils_confirmation_dialog (XedWindow * window, gboolean xed_file_browser_utils_confirmation_dialog (XedWindow *window,
GtkMessageType type, GtkMessageType type,
gchar const *message, gchar const *message,
gchar const *secondary, gchar const *secondary,
gchar const * button_stock, gchar const *button_label);
gchar const * button_label);
#endif /* __XED_FILE_BROWSER_UTILS_H__ */ #endif /* __XED_FILE_BROWSER_UTILS_H__ */

View File

@ -44,8 +44,6 @@ struct _XedFileBrowserViewPrivate
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeRowReference *editable; GtkTreeRowReference *editable;
GdkCursor *busy_cursor;
/* CLick policy */ /* CLick policy */
XedFileBrowserViewClickPolicy click_policy; XedFileBrowserViewClickPolicy click_policy;
GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */ GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */
@ -128,8 +126,6 @@ xed_file_browser_view_finalize (GObject *object)
obj->priv->expand_state = NULL; obj->priv->expand_state = NULL;
} }
g_object_unref (obj->priv->busy_cursor);
G_OBJECT_CLASS (xed_file_browser_view_parent_class)->finalize (object); G_OBJECT_CLASS (xed_file_browser_view_parent_class)->finalize (object);
} }
@ -169,7 +165,6 @@ row_expanded (GtkTreeView *tree_view,
GtkTreePath *path) GtkTreePath *path)
{ {
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view);
GFile *location;
if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded) if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded)
{ {
@ -183,9 +178,16 @@ row_expanded (GtkTreeView *tree_view,
if (view->priv->restore_expand_state) if (view->priv->restore_expand_state)
{ {
GFile *location;
gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
add_expand_state (view, location); add_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
} }
_xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter); _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter);
@ -197,7 +199,6 @@ row_collapsed (GtkTreeView *tree_view,
GtkTreePath *path) GtkTreePath *path)
{ {
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view);
GFile *location;
if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed) if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed)
{ {
@ -211,9 +212,16 @@ row_collapsed (GtkTreeView *tree_view,
if (view->priv->restore_expand_state) if (view->priv->restore_expand_state)
{ {
GFile *location;
gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1);
remove_expand_state (view, location); remove_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
} }
_xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter); _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter);
@ -436,6 +444,20 @@ activate_selected_items (XedFileBrowserView *view)
} }
} }
static void
row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
/* Make sure the activated row is the only one selected */
gtk_tree_selection_unselect_all (selection);
gtk_tree_selection_select_path (selection, path);
activate_selected_items (XED_FILE_BROWSER_VIEW (tree_view));
}
static void static void
toggle_hidden_filter (XedFileBrowserView *view) toggle_hidden_filter (XedFileBrowserView *view)
{ {
@ -751,7 +773,6 @@ fill_expand_state (XedFileBrowserView *view,
{ {
GtkTreePath * path; GtkTreePath * path;
GtkTreeIter child; GtkTreeIter child;
GFile *location;
if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) if (!gtk_tree_model_iter_has_child (view->priv->model, iter))
{ {
@ -762,6 +783,8 @@ fill_expand_state (XedFileBrowserView *view,
if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path))
{ {
GFile *location;
gtk_tree_model_get (view->priv->model, gtk_tree_model_get (view->priv->model,
iter, iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, XED_FILE_BROWSER_STORE_COLUMN_LOCATION,
@ -769,6 +792,11 @@ fill_expand_state (XedFileBrowserView *view,
-1); -1);
add_expand_state (view, location); add_expand_state (view, location);
if (location)
{
g_object_unref (location);
}
} }
if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) if (gtk_tree_model_iter_children (view->priv->model, &child, iter))
@ -908,6 +936,7 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass *klass)
widget_class->key_press_event = key_press_event; widget_class->key_press_event = key_press_event;
/* Tree view handlers */ /* Tree view handlers */
tree_view_class->row_activated = row_activated;
tree_view_class->row_expanded = row_expanded; tree_view_class->row_expanded = row_expanded;
tree_view_class->row_collapsed = row_collapsed; tree_view_class->row_collapsed = row_collapsed;
@ -1038,8 +1067,6 @@ xed_file_browser_view_init (XedFileBrowserView *obj)
drag_source_targets, drag_source_targets,
G_N_ELEMENTS (drag_source_targets), G_N_ELEMENTS (drag_source_targets),
GDK_ACTION_COPY); GDK_ACTION_COPY);
obj->priv->busy_cursor = gdk_cursor_new (GDK_WATCH);
} }
static gboolean static gboolean
@ -1275,7 +1302,6 @@ restore_expand_state (XedFileBrowserView *view,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
GFile *location; GFile *location;
GtkTreePath *path;
gtk_tree_model_get (GTK_TREE_MODEL (model), gtk_tree_model_get (GTK_TREE_MODEL (model),
iter, iter,
@ -1283,19 +1309,20 @@ restore_expand_state (XedFileBrowserView *view,
&location, &location,
-1); -1);
if (!location) if (location)
{ {
return; GtkTreePath *path;
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
if (g_hash_table_lookup (view->priv->expand_state, location))
{
gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
}
gtk_tree_path_free (path);
g_object_unref (location);
} }
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
if (g_hash_table_lookup (view->priv->expand_state, location))
{
gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
}
gtk_tree_path_free (path);
} }
static void static void

View File

@ -1,14 +1,9 @@
<ui> <ui>
<toolbar name="ToolBar"> <toolbar name="ToolBar">
<placeholder name="Tool_Opt1"/> <toolitem action="DirectoryPrevious"/>
<toolitem action="DirectoryNext"/>
<toolitem action="DirectoryUp"/> <toolitem action="DirectoryUp"/>
<separator/>
<toolitem action="DirectoryRefresh"/>
<separator/>
<placeholder name="Tool_Opt2"/> <placeholder name="Tool_Opt2"/>
<separator/>
<toolitem action="FilterHidden"/>
<separator/>
<placeholder name="Tool_Opt3"/> <placeholder name="Tool_Opt3"/>
</toolbar> </toolbar>

File diff suppressed because it is too large Load Diff