filebrowser-plugin: Port to libpeas

Adapted from:
3e00f9094c
This commit is contained in:
JosephMcc 2016-12-26 13:25:50 -08:00
parent fdc2da63a9
commit 4cad8ffa7f
10 changed files with 1304 additions and 1151 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* xed-file-bookmarks-store.h - Xed plugin providing easy file access
* xed-file-bookmarks-store.h - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -25,66 +25,66 @@
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ())
#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore))
#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const))
#define XED_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass))
#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE))
#define XED_IS_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BOOKMARKS_STORE))
#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass))
#define XED_TYPE_FILE_BOOKMARKS_STORE (xed_file_bookmarks_store_get_type ())
#define XED_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore))
#define XED_FILE_BOOKMARKS_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStore const))
#define XED_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass))
#define XED_IS_FILE_BOOKMARKS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BOOKMARKS_STORE))
#define XED_IS_FILE_BOOKMARKS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BOOKMARKS_STORE))
#define XED_FILE_BOOKMARKS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BOOKMARKS_STORE, XedFileBookmarksStoreClass))
typedef struct _XedFileBookmarksStore XedFileBookmarksStore;
typedef struct _XedFileBookmarksStoreClass XedFileBookmarksStoreClass;
typedef struct _XedFileBookmarksStorePrivate XedFileBookmarksStorePrivate;
enum
enum
{
XED_FILE_BOOKMARKS_STORE_COLUMN_ICON = 0,
XED_FILE_BOOKMARKS_STORE_COLUMN_NAME,
XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT,
XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
XED_FILE_BOOKMARKS_STORE_N_COLUMNS
XED_FILE_BOOKMARKS_STORE_COLUMN_ICON = 0,
XED_FILE_BOOKMARKS_STORE_COLUMN_NAME,
XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT,
XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
XED_FILE_BOOKMARKS_STORE_N_COLUMNS
};
enum
enum
{
XED_FILE_BOOKMARKS_STORE_NONE = 0,
XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0, /* Separator item */
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1, /* Special user dir */
XED_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2, /* The special Home user directory */
XED_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3, /* The special Desktop user directory */
XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4, /* The special Documents user directory */
XED_FILE_BOOKMARKS_STORE_IS_FS = 1 << 5, /* A mount object */
XED_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 6, /* A mount object */
XED_FILE_BOOKMARKS_STORE_IS_VOLUME = 1 << 7, /* A volume object */
XED_FILE_BOOKMARKS_STORE_IS_DRIVE = 1 << 8, /* A drive object */
XED_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 9, /* The root file system (file:///) */
XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 10, /* A gtk bookmark */
XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK = 1 << 11, /* A remote gtk bookmark */
XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK = 1 << 12 /* A local gtk bookmark */
XED_FILE_BOOKMARKS_STORE_NONE = 0,
XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR = 1 << 0, /* Separator item */
XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR = 1 << 1, /* Special user dir */
XED_FILE_BOOKMARKS_STORE_IS_HOME = 1 << 2, /* The special Home user directory */
XED_FILE_BOOKMARKS_STORE_IS_DESKTOP = 1 << 3, /* The special Desktop user directory */
XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS = 1 << 4, /* The special Documents user directory */
XED_FILE_BOOKMARKS_STORE_IS_FS = 1 << 5, /* A mount object */
XED_FILE_BOOKMARKS_STORE_IS_MOUNT = 1 << 6, /* A mount object */
XED_FILE_BOOKMARKS_STORE_IS_VOLUME = 1 << 7, /* A volume object */
XED_FILE_BOOKMARKS_STORE_IS_DRIVE = 1 << 8, /* A drive object */
XED_FILE_BOOKMARKS_STORE_IS_ROOT = 1 << 9, /* The root file system (file:///) */
XED_FILE_BOOKMARKS_STORE_IS_BOOKMARK = 1 << 10, /* A gtk bookmark */
XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK = 1 << 11, /* A remote gtk bookmark */
XED_FILE_BOOKMARKS_STORE_IS_LOCAL_BOOKMARK = 1 << 12 /* A local gtk bookmark */
};
struct _XedFileBookmarksStore
struct _XedFileBookmarksStore
{
GtkTreeStore parent;
GtkTreeStore parent;
XedFileBookmarksStorePrivate *priv;
XedFileBookmarksStorePrivate *priv;
};
struct _XedFileBookmarksStoreClass
struct _XedFileBookmarksStoreClass
{
GtkTreeStoreClass parent_class;
GtkTreeStoreClass parent_class;
};
GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST;
GType xed_file_bookmarks_store_register_type (GTypeModule * module);
void _xed_file_bookmarks_store_register_type (GTypeModule * module);
XedFileBookmarksStore *xed_file_bookmarks_store_new (void);
gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model,
GtkTreeIter * iter);
GtkTreeIter * iter);
void xed_file_bookmarks_store_refresh (XedFileBookmarksStore * model);
G_END_DECLS
#endif /* __XED_FILE_BOOKMARKS_STORE_H__ */
#endif /* __XED_FILE_BOOKMARKS_STORE_H__ */
// ex:ts=8:noet:

View File

@ -28,9 +28,11 @@
#include <xed/xed-utils.h>
#include <xed/xed-app.h>
#include <glib/gi18n-lib.h>
#include <xed/xed-window.h>
#include <xed/xed-debug.h>
#include <gio/gio.h>
#include <string.h>
#include <libpeas/peas-activatable.h>
#include "xed-file-browser-enum-types.h"
#include "xed-file-browser-plugin.h"
@ -39,8 +41,6 @@
#include "xed-file-browser-widget.h"
#include "xed-file-browser-messages.h"
#define WINDOW_DATA_KEY "XedFileBrowserPluginWindowData"
#define FILE_BROWSER_SCHEMA "org.x.editor.plugins.filebrowser"
#define FILE_BROWSER_ONLOAD_SCHEMA "org.x.editor.plugins.filebrowser.on-load"
@ -48,11 +48,8 @@
struct _XedFileBrowserPluginPrivate
{
gpointer *dummy;
};
GtkWidget *window;
typedef struct _XedFileBrowserPluginData
{
XedFileBrowserWidget * tree_widget;
gulong merge_id;
GtkActionGroup * action_group;
@ -62,7 +59,13 @@ typedef struct _XedFileBrowserPluginData
GSettings *settings;
GSettings *onload_settings;
} XedFileBrowserPluginData;
};
enum
{
PROP_0,
PROP_OBJECT
};
static void on_uri_activated_cb (XedFileBrowserWidget * widget,
gchar const *uri,
@ -70,67 +73,113 @@ static void on_uri_activated_cb (XedFileBrowserWidget * widget,
static void on_error_cb (XedFileBrowserWidget * widget,
guint code,
gchar const *message,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static void on_model_set_cb (XedFileBrowserView * widget,
GParamSpec *arg1,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static void on_virtual_root_changed_cb (XedFileBrowserStore * model,
GParamSpec * param,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static void on_filter_mode_changed_cb (XedFileBrowserStore * model,
GParamSpec * param,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static void on_rename_cb (XedFileBrowserStore * model,
const gchar * olduri,
const gchar * newuri,
XedWindow * window);
static void on_filter_pattern_changed_cb (XedFileBrowserWidget * widget,
GParamSpec * param,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static void on_tab_added_cb (XedWindow * window,
XedTab * tab,
XedFileBrowserPluginData * data);
XedFileBrowserPluginPrivate * data);
static gboolean on_confirm_delete_cb (XedFileBrowserWidget * widget,
XedFileBrowserStore * store,
GList * rows,
XedWindow * window);
XedFileBrowserPluginPrivate * data);
static gboolean on_confirm_no_trash_cb (XedFileBrowserWidget * widget,
GList * files,
XedWindow * window);
XED_PLUGIN_REGISTER_TYPE_WITH_CODE (XedFileBrowserPlugin, filetree_plugin, \
xed_file_browser_enum_and_flag_register_type (type_module); \
xed_file_browser_store_register_type (type_module); \
xed_file_bookmarks_store_register_type (type_module); \
xed_file_browser_view_register_type (type_module); \
xed_file_browser_widget_register_type (type_module); \
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserPlugin,
xed_file_browser_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
peas_activatable_iface_init) \
\
xed_file_browser_enum_and_flag_register_type (type_module); \
_xed_file_browser_store_register_type (type_module); \
_xed_file_bookmarks_store_register_type (type_module); \
_xed_file_browser_view_register_type (type_module); \
_xed_file_browser_widget_register_type (type_module);
)
static void
filetree_plugin_init (XedFileBrowserPlugin * plugin)
xed_file_browser_plugin_init (XedFileBrowserPlugin * plugin)
{
plugin->priv = XED_FILE_BROWSER_PLUGIN_GET_PRIVATE (plugin);
}
static void
filetree_plugin_finalize (GObject * object)
xed_file_browser_plugin_dispose (GObject * object)
{
//XedFileBrowserPlugin * plugin = XED_FILE_BROWSER_PLUGIN (object);
XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object);
G_OBJECT_CLASS (filetree_plugin_parent_class)->finalize (object);
if (plugin->priv->window != NULL)
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
G_OBJECT_CLASS (xed_file_browser_plugin_parent_class)->dispose (object);
}
static XedFileBrowserPluginData *
get_plugin_data (XedWindow * window)
static void
xed_file_browser_plugin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
return (XedFileBrowserPluginData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY));
XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object);
switch (prop_id)
{
case PROP_OBJECT:
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xed_file_browser_plugin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XedFileBrowserPlugin *plugin = XED_FILE_BROWSER_PLUGIN (object);
switch (prop_id)
{
case PROP_OBJECT:
g_value_set_object (value, plugin->priv->window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
on_end_loading_cb (XedFileBrowserStore * store,
GtkTreeIter * iter,
XedFileBrowserPluginData * data)
XedFileBrowserPluginPrivate * data)
{
/* Disconnect the signal */
g_signal_handler_disconnect (store, data->end_loading_handle);
@ -139,7 +188,7 @@ on_end_loading_cb (XedFileBrowserStore * store,
}
static void
prepare_auto_root (XedFileBrowserPluginData *data)
prepare_auto_root (XedFileBrowserPluginPrivate *data)
{
XedFileBrowserStore *store;
@ -159,7 +208,7 @@ prepare_auto_root (XedFileBrowserPluginData *data)
}
static void
restore_default_location (XedFileBrowserPluginData *data)
restore_default_location (XedFileBrowserPluginPrivate *data)
{
gchar * root;
gchar * virtual_root;
@ -205,7 +254,7 @@ restore_default_location (XedFileBrowserPluginData *data)
}
static void
restore_filter (XedFileBrowserPluginData * data)
restore_filter (XedFileBrowserPluginPrivate *data)
{
gchar *filter_mode;
XedFileBrowserStoreFilterMode mode;
@ -247,7 +296,7 @@ restore_filter (XedFileBrowserPluginData * data)
}
static void
set_root_from_doc (XedFileBrowserPluginData * data,
set_root_from_doc (XedFileBrowserPluginPrivate * data,
XedDocument * doc)
{
GFile *file;
@ -280,17 +329,13 @@ set_root_from_doc (XedFileBrowserPluginData * data,
static void
on_action_set_active_root (GtkAction * action,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData *data;
data = get_plugin_data (window);
set_root_from_doc (data,
xed_window_get_active_document (window));
set_root_from_doc (data, xed_window_get_active_document (XED_WINDOW (data->window)));
}
static gchar *
get_terminal (XedFileBrowserPluginData * data)
get_terminal (XedFileBrowserPluginPrivate * data)
{
// 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");
@ -298,9 +343,8 @@ get_terminal (XedFileBrowserPluginData * data)
static void
on_action_open_terminal (GtkAction * action,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData * data;
gchar * terminal;
gchar * wd = NULL;
gchar * local;
@ -310,8 +354,6 @@ on_action_open_terminal (GtkAction * action,
GtkTreeIter iter;
XedFileBrowserStore * store;
data = get_plugin_data (window);
/* Get the current directory */
if (!xed_file_browser_widget_get_selected_directory (data->tree_widget, &iter))
return;
@ -351,17 +393,14 @@ on_action_open_terminal (GtkAction * action,
static void
on_selection_changed_cb (GtkTreeSelection *selection,
XedWindow *window)
XedFileBrowserPluginPrivate *data)
{
XedFileBrowserPluginData * data;
GtkTreeView * tree_view;
GtkTreeModel * model;
GtkTreeIter iter;
gboolean sensitive;
gchar * uri;
data = get_plugin_data (window);
tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget));
model = gtk_tree_view_get_model (tree_view);
@ -418,14 +457,12 @@ static GtkActionEntry extra_single_selection_actions[] = {
};
static void
add_popup_ui (XedWindow * window)
add_popup_ui (XedFileBrowserPluginPrivate *data)
{
XedFileBrowserPluginData * data;
GtkUIManager * manager;
GtkActionGroup * action_group;
GError * error = NULL;
data = get_plugin_data (window);
manager = xed_file_browser_widget_get_ui_manager (data->tree_widget);
action_group = gtk_action_group_new ("FileBrowserPluginExtra");
@ -433,7 +470,7 @@ add_popup_ui (XedWindow * window)
gtk_action_group_add_actions (action_group,
extra_actions,
G_N_ELEMENTS (extra_actions),
window);
data);
gtk_ui_manager_insert_action_group (manager, action_group, 0);
data->action_group = action_group;
@ -442,7 +479,7 @@ add_popup_ui (XedWindow * window)
gtk_action_group_add_actions (action_group,
extra_single_selection_actions,
G_N_ELEMENTS (extra_single_selection_actions),
window);
data);
gtk_ui_manager_insert_action_group (manager, action_group, 0);
data->single_selection_action_group = action_group;
@ -458,12 +495,10 @@ add_popup_ui (XedWindow * window)
}
static void
remove_popup_ui (XedWindow * window)
remove_popup_ui (XedFileBrowserPluginPrivate *data)
{
XedFileBrowserPluginData * data;
GtkUIManager * manager;
data = get_plugin_data (window);
manager = xed_file_browser_widget_get_ui_manager (data->tree_widget);
gtk_ui_manager_remove_ui (manager, data->merge_id);
@ -475,14 +510,14 @@ remove_popup_ui (XedWindow * window)
}
static void
impl_updateui (XedPlugin * plugin, XedWindow * window)
xed_file_browser_plugin_update_state (PeasActivatable *activatable)
{
XedFileBrowserPluginData * data;
XedFileBrowserPluginPrivate *data;
XedDocument * doc;
data = get_plugin_data (window);
data = XED_FILE_BROWSER_PLUGIN (activatable)->priv;
doc = xed_window_get_active_document (window);
doc = xed_window_get_active_document (XED_WINDOW (data->window));
gtk_action_set_sensitive (gtk_action_group_get_action (data->action_group,
"SetActiveRoot"),
@ -491,10 +526,11 @@ impl_updateui (XedPlugin * plugin, XedWindow * window)
}
static void
impl_activate (XedPlugin * plugin, XedWindow * window)
xed_file_browser_plugin_activate (PeasActivatable *activatable)
{
XedFileBrowserPluginPrivate *data;
XedWindow *window;
XedPanel * panel;
XedFileBrowserPluginData * data;
GtkWidget * image;
GdkPixbuf * pixbuf;
XedFileBrowserStore * store;
@ -502,9 +538,10 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
GSettingsSchemaSource *schema_source;
GSettingsSchema *schema;
data = g_new0 (XedFileBrowserPluginData, 1);
data = XED_FILE_BROWSER_PLUGIN (activatable)->priv;
window = XED_WINDOW (data->window);
data_dir = xed_plugin_get_data_dir (plugin);
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (activatable));
data->tree_widget = XED_FILE_BROWSER_WIDGET (xed_file_browser_widget_new (data_dir));
g_free (data_dir);
@ -516,17 +553,17 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
G_CALLBACK (on_uri_activated_cb), window);
g_signal_connect (data->tree_widget,
"error", G_CALLBACK (on_error_cb), window);
"error", G_CALLBACK (on_error_cb), data);
g_signal_connect (data->tree_widget,
"notify::filter-pattern",
G_CALLBACK (on_filter_pattern_changed_cb),
window);
data);
g_signal_connect (data->tree_widget,
"confirm-delete",
G_CALLBACK (on_confirm_delete_cb),
window);
data);
g_signal_connect (data->tree_widget,
"confirm-no-trash",
@ -538,7 +575,7 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
(data->tree_widget))),
"changed",
G_CALLBACK (on_selection_changed_cb),
window);
data);
panel = xed_window_get_side_panel (window);
pixbuf = xed_file_browser_utils_pixbuf_from_theme("system-file-manager",
@ -557,9 +594,8 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
_("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);
add_popup_ui (data);
/* Restore filter options */
restore_filter (data);
@ -568,18 +604,18 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
g_signal_connect (xed_file_browser_widget_get_browser_view (data->tree_widget),
"notify::model",
G_CALLBACK (on_model_set_cb),
window);
data);
store = xed_file_browser_widget_get_browser_store (data->tree_widget);
g_signal_connect (store,
"notify::virtual-root",
G_CALLBACK (on_virtual_root_changed_cb),
window);
data);
g_signal_connect (store,
"notify::filter-mode",
G_CALLBACK (on_filter_mode_changed_cb),
window);
data);
g_signal_connect (store,
"rename",
@ -594,16 +630,18 @@ impl_activate (XedPlugin * plugin, XedWindow * window)
/* Register messages on the bus */
xed_file_browser_messages_register (window, data->tree_widget);
impl_updateui (plugin, window);
xed_file_browser_plugin_update_state (activatable);
}
static void
impl_deactivate (XedPlugin * plugin, XedWindow * window)
xed_file_browser_plugin_deactivate (PeasActivatable *activatable)
{
XedFileBrowserPluginData * data;
XedFileBrowserPluginPrivate *data;
XedWindow *window;
XedPanel * panel;
data = get_plugin_data (window);
data = XED_FILE_BROWSER_PLUGIN (activatable)->priv;
window = XED_WINDOW (data->window);
/* Unregister messages from the bus */
xed_file_browser_messages_unregister (window);
@ -616,31 +654,51 @@ impl_deactivate (XedPlugin * plugin, XedWindow * window)
g_object_unref (data->settings);
g_object_unref (data->onload_settings);
remove_popup_ui (window);
remove_popup_ui (data);
panel = xed_window_get_side_panel (window);
xed_panel_remove_item (panel, GTK_WIDGET (data->tree_widget));
g_free (data);
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
}
static void
filetree_plugin_class_init (XedFileBrowserPluginClass * klass)
xed_file_browser_plugin_class_init (XedFileBrowserPluginClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
XedPluginClass * plugin_class = XED_PLUGIN_CLASS (klass);
object_class->finalize = filetree_plugin_finalize;
object_class->dispose = xed_file_browser_plugin_dispose;
object_class->set_property = xed_file_browser_plugin_set_property;
object_class->get_property = xed_file_browser_plugin_get_property;
plugin_class->activate = impl_activate;
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_updateui;
g_object_class_override_property (object_class, PROP_OBJECT, "object");
g_type_class_add_private (object_class,
sizeof (XedFileBrowserPluginPrivate));
}
static void
xed_file_browser_plugin_class_finalize (XedFileBrowserPluginClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
}
static void
peas_activatable_iface_init (PeasActivatableInterface *iface)
{
iface->activate = xed_file_browser_plugin_activate;
iface->deactivate = xed_file_browser_plugin_deactivate;
iface->update_state = xed_file_browser_plugin_update_state;
}
G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module)
{
xed_file_browser_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
XED_TYPE_FILE_BROWSER_PLUGIN);
}
/* Callbacks */
static void
on_uri_activated_cb (XedFileBrowserWidget * tree_widget,
@ -651,13 +709,10 @@ on_uri_activated_cb (XedFileBrowserWidget * tree_widget,
static void
on_error_cb (XedFileBrowserWidget * tree_widget,
guint code, gchar const *message, XedWindow * window)
guint code, gchar const *message, XedFileBrowserPluginPrivate * data)
{
gchar * title;
GtkWidget * dlg;
XedFileBrowserPluginData * data;
data = get_plugin_data (window);
/* Do not show the error when the root has been set automatically */
if (data->auto_root && (code == XED_FILE_BROWSER_ERROR_SET_ROOT ||
@ -704,7 +759,7 @@ on_error_cb (XedFileBrowserWidget * tree_widget,
break;
}
dlg = gtk_message_dialog_new (GTK_WINDOW (window),
dlg = gtk_message_dialog_new (GTK_WINDOW (data->window),
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
@ -719,9 +774,8 @@ on_error_cb (XedFileBrowserWidget * tree_widget,
static void
on_model_set_cb (XedFileBrowserView * widget,
GParamSpec *arg1,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData * data = get_plugin_data (window);
GtkTreeModel * model;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (data->tree_widget)));
@ -737,9 +791,8 @@ on_model_set_cb (XedFileBrowserView * widget,
static void
on_filter_mode_changed_cb (XedFileBrowserStore * model,
GParamSpec * param,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData * data = get_plugin_data (window);
XedFileBrowserStoreFilterMode mode;
mode = xed_file_browser_store_get_filter_mode (model);
@ -823,9 +876,8 @@ on_rename_cb (XedFileBrowserStore * store,
static void
on_filter_pattern_changed_cb (XedFileBrowserWidget * widget,
GParamSpec * param,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData * data = get_plugin_data (window);
gchar * pattern;
g_object_get (G_OBJECT (widget), "filter-pattern", &pattern, NULL);
@ -841,9 +893,8 @@ on_filter_pattern_changed_cb (XedFileBrowserWidget * widget,
static void
on_virtual_root_changed_cb (XedFileBrowserStore * store,
GParamSpec * param,
XedWindow * window)
XedFileBrowserPluginPrivate * data)
{
XedFileBrowserPluginData * data = get_plugin_data (window);
gchar * root;
gchar * virtual_root;
@ -863,7 +914,7 @@ on_virtual_root_changed_cb (XedFileBrowserStore * store,
g_settings_set_string (data->onload_settings, "virtual-root", virtual_root);
}
g_signal_handlers_disconnect_by_func (window,
g_signal_handlers_disconnect_by_func (XED_WINDOW (data->window),
G_CALLBACK (on_tab_added_cb),
data);
@ -874,7 +925,7 @@ on_virtual_root_changed_cb (XedFileBrowserStore * store,
static void
on_tab_added_cb (XedWindow * window,
XedTab * tab,
XedFileBrowserPluginData * data)
XedFileBrowserPluginPrivate *data)
{
gboolean open;
gboolean load_default = TRUE;
@ -956,15 +1007,12 @@ static gboolean
on_confirm_delete_cb (XedFileBrowserWidget *widget,
XedFileBrowserStore *store,
GList *paths,
XedWindow *window)
XedFileBrowserPluginPrivate *data)
{
gchar *normal;
gchar *message;
gchar *secondary;
gboolean result;
XedFileBrowserPluginData *data;
data = get_plugin_data (window);
if (paths->next == NULL) {
normal = get_filename_from_path (GTK_TREE_MODEL (store), (GtkTreePath *)(paths->data));
@ -976,7 +1024,7 @@ on_confirm_delete_cb (XedFileBrowserWidget *widget,
secondary = _("If you delete an item, it is permanently lost.");
result = xed_file_browser_utils_confirmation_dialog (window,
result = xed_file_browser_utils_confirmation_dialog (XED_WINDOW (data->window),
GTK_MESSAGE_QUESTION,
message,
secondary,

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-plugin.h - Xed plugin providing easy file access
* xed-file-browser-plugin.h - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -24,46 +24,48 @@
#include <glib.h>
#include <glib-object.h>
#include <xed/xed-plugin.h>
#include <libpeas/peas-extension-base.h>
#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_FILE_BROWSER_PLUGIN (filetree_plugin_get_type ())
#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin))
#define XED_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass))
#define XED_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_FILE_BROWSER_PLUGIN))
#define XED_IS_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_FILE_BROWSER_PLUGIN))
#define XED_FILE_BROWSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass))
#define XED_TYPE_FILE_BROWSER_PLUGIN (xed_file_browser_plugin_get_type ())
#define XED_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPlugin))
#define XED_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass))
#define XED_IS_FILE_BROWSER_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_FILE_BROWSER_PLUGIN))
#define XED_IS_FILE_BROWSER_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_FILE_BROWSER_PLUGIN))
#define XED_FILE_BROWSER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_FILE_BROWSER_PLUGIN, XedFileBrowserPluginClass))
/* Private structure type */
typedef struct _XedFileBrowserPluginPrivate XedFileBrowserPluginPrivate;
typedef struct _XedFileBrowserPlugin XedFileBrowserPlugin;
typedef struct _XedFileBrowserPluginClass XedFileBrowserPluginClass;
struct _XedFileBrowserPlugin
struct _XedFileBrowserPlugin
{
XedPlugin parent_instance;
PeasExtensionBase parent_instance;
/*< private > */
XedFileBrowserPluginPrivate *priv;
/*< private > */
XedFileBrowserPluginPrivate *priv;
};
struct _XedFileBrowserPluginClass
struct _XedFileBrowserPluginClass
{
XedPluginClass parent_class;
PeasExtensionBaseClass parent_class;
};
/*
* Public methods
*/
GType filetree_plugin_get_type (void) G_GNUC_CONST;
GType xed_file_browser_plugin_get_type (void) G_GNUC_CONST;
/* All the plugins must implement this function */
G_MODULE_EXPORT GType register_xed_plugin (GTypeModule * module);
G_MODULE_EXPORT void peas_register_types (PeasObjectModule * module);
G_END_DECLS
#endif /* __XED_FILE_BROWSER_PLUGIN_H__ */

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-store.c - Xed plugin providing easy file access
* xed-file-browser-store.c - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -26,7 +26,6 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <xed/xed-plugin.h>
#include <xed/xed-utils.h>
#include "xed-file-browser-store.h"
@ -88,7 +87,7 @@ typedef struct {
GCancellable * cancellable;
} MountInfo;
struct _FileBrowserNode
struct _FileBrowserNode
{
GFile *file;
guint flags;
@ -102,7 +101,7 @@ struct _FileBrowserNode
gboolean inserted;
};
struct _FileBrowserNodeDir
struct _FileBrowserNodeDir
{
FileBrowserNode node;
GSList *children;
@ -113,7 +112,7 @@ struct _FileBrowserNodeDir
XedFileBrowserStore *model;
};
struct _XedFileBrowserStorePrivate
struct _XedFileBrowserStorePrivate
{
FileBrowserNode *root;
FileBrowserNode *virtual_root;
@ -133,7 +132,7 @@ static FileBrowserNode *model_find_node (XedFileBrowserStore *model,
FileBrowserNode *node,
GFile *uri);
static void model_remove_node (XedFileBrowserStore * model,
FileBrowserNode * node,
FileBrowserNode * node,
GtkTreePath * path,
gboolean free_nodes);
@ -165,7 +164,7 @@ static gint xed_file_browser_store_iter_n_children (GtkTreeModel * tree_m
GtkTreeIter * iter);
static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model,
GtkTreeIter * iter,
GtkTreeIter * parent,
GtkTreeIter * parent,
gint n);
static gboolean xed_file_browser_store_iter_parent (GtkTreeModel * tree_model,
GtkTreeIter * iter,
@ -197,13 +196,12 @@ static void model_check_dummy (XedFileBrowserStore
static void next_files_async (GFileEnumerator * enumerator,
AsyncNode * async);
XED_PLUGIN_DEFINE_TYPE_WITH_CODE (XedFileBrowserStore, xed_file_browser_store,
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store,
G_TYPE_OBJECT,
XED_PLUGIN_IMPLEMENT_INTERFACE (xed_file_browser_store_tree_model,
GTK_TYPE_TREE_MODEL,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_MODEL,
xed_file_browser_store_iface_init)
XED_PLUGIN_IMPLEMENT_INTERFACE (xed_file_browser_store_drag_source,
GTK_TYPE_TREE_DRAG_SOURCE,
G_IMPLEMENT_INTERFACE_DYNAMIC (GTK_TYPE_TREE_DRAG_SOURCE,
xed_file_browser_store_drag_source_init))
/* Properties */
@ -216,7 +214,7 @@ enum {
};
/* Signals */
enum
enum
{
BEGIN_LOADING,
END_LOADING,
@ -256,10 +254,10 @@ xed_file_browser_store_finalize (GObject * object)
{
AsyncData *data = (AsyncData *) (item->data);
g_cancellable_cancel (data->cancellable);
data->removed = TRUE;
}
cancel_mount_operation (obj);
g_slist_free (obj->priv->async_handles);
@ -295,7 +293,7 @@ xed_file_browser_store_get_property (GObject *object,
break;
case PROP_VIRTUAL_ROOT:
set_gvalue_from_node (value, obj->priv->virtual_root);
break;
break;
case PROP_FILTER_MODE:
g_value_set_flags (value, obj->priv->filter_mode);
break;
@ -393,7 +391,7 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XedFileBrowserStoreClass,
rename), NULL, NULL,
xed_file_browser_marshal_VOID__STRING_STRING,
xed_file_browser_marshal_VOID__STRING_STRING,
G_TYPE_NONE, 2,
G_TYPE_STRING,
G_TYPE_STRING);
@ -427,6 +425,12 @@ xed_file_browser_store_class_init (XedFileBrowserStoreClass * klass)
sizeof (XedFileBrowserStorePrivate));
}
static void
xed_file_browser_store_class_finalize (XedFileBrowserStoreClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
}
static void
xed_file_browser_store_iface_init (GtkTreeModelIface * iface)
{
@ -659,13 +663,13 @@ xed_file_browser_store_get_path (GtkTreeModel * tree_model,
g_return_val_if_fail (iter != NULL, NULL);
g_return_val_if_fail (iter->user_data != NULL, NULL);
return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model),
return xed_file_browser_store_get_path_real (XED_FILE_BROWSER_STORE (tree_model),
(FileBrowserNode *) (iter->user_data));
}
static void
xed_file_browser_store_get_value (GtkTreeModel * tree_model,
GtkTreeIter * iter,
GtkTreeIter * iter,
gint column,
GValue * value)
{
@ -774,7 +778,7 @@ filter_tree_model_iter_has_child_real (XedFileBrowserStore * model,
FileBrowserNode * node)
{
GSList *item;
if (!NODE_IS_DIR (node))
return FALSE;
@ -910,7 +914,7 @@ xed_file_browser_store_row_inserted (GtkTreeModel * tree_model,
GtkTreeIter * iter)
{
FileBrowserNode * node = (FileBrowserNode *)(iter->user_data);
node->inserted = TRUE;
}
@ -1143,7 +1147,7 @@ row_changed (XedFileBrowserStore * model,
signal may alter the path */
gtk_tree_model_row_changed (GTK_TREE_MODEL(model), *path, iter);
gtk_tree_path_free (*path);
*path = gtk_tree_row_reference_get_path (ref);
gtk_tree_row_reference_free (ref);
}
@ -1155,7 +1159,7 @@ row_inserted (XedFileBrowserStore * model,
{
/* This function creates a row reference for the path because it's
uncertain what might change the actual model/view when we insert
a node, maybe another directory load is triggered for example.
a node, maybe another directory load is triggered for example.
Because functions that use this function rely on the notion that
the path remains pointed towards the inserted node, we use the
reference to keep track. */
@ -1164,7 +1168,7 @@ row_inserted (XedFileBrowserStore * model,
gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), copy, iter);
gtk_tree_path_free (copy);
if (ref)
{
gtk_tree_path_free (*path);
@ -1184,7 +1188,7 @@ row_deleted (XedFileBrowserStore * model,
const GtkTreePath * path)
{
GtkTreePath *copy = gtk_tree_path_copy (path);
/* Delete a copy of the actual path here because the row-deleted
signal may alter the path */
gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), copy);
@ -1255,7 +1259,7 @@ model_refilter_node (XedFileBrowserStore * model,
gtk_tree_path_next (*path);
}
}
model_check_dummy (model, node);
if (tmppath)
@ -1373,7 +1377,7 @@ file_browser_node_free (XedFileBrowserStore * model,
if (dir->hidden_file_hash)
g_hash_table_destroy (dir->hidden_file_hash);
}
if (node->file)
{
uri = g_file_get_uri (node->file);
@ -1390,7 +1394,7 @@ file_browser_node_free (XedFileBrowserStore * model,
g_object_unref (node->emblem);
g_free (node->name);
if (NODE_IS_DIR (node))
g_slice_free (FileBrowserNodeDir, (FileBrowserNodeDir *)node);
else
@ -1432,10 +1436,10 @@ model_remove_node_children (XedFileBrowserStore * model,
// be freed
if (free_nodes)
file_browser_node_free_children (model, node);
return;
}
if (path == NULL)
path_child =
xed_file_browser_store_get_path_real (model, node);
@ -1459,10 +1463,10 @@ model_remove_node_children (XedFileBrowserStore * model,
* model_remove_node:
* @model: the #XedFileBrowserStore
* @node: the FileBrowserNode to remove
* @path: the path to use to remove this node, or NULL to use the path
* @path: the path to use to remove this node, or NULL to use the path
* calculated from the node itself
* @free_nodes: whether to also remove the nodes from memory
*
*
* Removes this node and all its children from the model. This function is used
* to remove the node from the _model_. Don't use it to just free
* a node.
@ -1505,7 +1509,7 @@ model_remove_node (XedFileBrowserStore * model,
(node->parent)->children,
node);
}
/* If this is the virtual root, than set the parent as the virtual root */
if (node == model->priv->virtual_root)
set_virtual_root_from_node (model, parent);
@ -1548,7 +1552,7 @@ model_clear (XedFileBrowserStore * model, gboolean free_nodes)
if (NODE_IS_DUMMY (dummy)
&& model_node_visibility (model, dummy)) {
path = gtk_tree_path_new_first ();
dummy->inserted = FALSE;
row_deleted (model, path);
gtk_tree_path_free (path);
@ -1562,7 +1566,7 @@ file_browser_node_unload (XedFileBrowserStore * model,
FileBrowserNode * node, gboolean remove_children)
{
FileBrowserNodeDir *dir;
if (node == NULL)
return;
@ -1585,7 +1589,7 @@ file_browser_node_unload (XedFileBrowserStore * model,
if (dir->monitor) {
g_file_monitor_cancel (dir->monitor);
g_object_unref (dir->monitor);
dir->monitor = NULL;
}
@ -1734,7 +1738,7 @@ model_check_dummy (XedFileBrowserStore * model, FileBrowserNode * node)
path =
xed_file_browser_store_get_path_real
(model, dummy);
row_inserted (model, &path, &iter);
gtk_tree_path_free (path);
}
@ -1750,7 +1754,7 @@ model_check_dummy (XedFileBrowserStore * model, FileBrowserNode * node)
(model, dummy);
dummy->flags |=
XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN;
dummy->inserted = FALSE;
row_deleted (model, path);
gtk_tree_path_free (path);
@ -1892,15 +1896,15 @@ static gchar const *
backup_content_type (GFileInfo * info)
{
gchar const * content;
if (!g_file_info_get_is_backup (info))
return NULL;
content = g_file_info_get_content_type (info);
if (!content || g_content_type_equals (content, "application/x-trash"))
return "text/plain";
return content;
}
@ -1919,12 +1923,12 @@ file_browser_node_set_from_info (XedFileBrowserStore * model,
GError * error = NULL;
if (info == NULL) {
info = g_file_query_info (node->file,
info = g_file_query_info (node->file,
STANDARD_ATTRIBUTE_TYPES,
G_FILE_QUERY_INFO_NONE,
NULL,
&error);
if (!info) {
if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)) {
uri = g_file_get_uri (node->file);
@ -1935,7 +1939,7 @@ file_browser_node_set_from_info (XedFileBrowserStore * model,
return;
}
free_info = TRUE;
}
@ -1953,13 +1957,13 @@ file_browser_node_set_from_info (XedFileBrowserStore * model,
else {
if (!(content = backup_content_type (info)))
content = g_file_info_get_content_type (info);
if (!content ||
if (!content ||
g_content_type_is_unknown (content) ||
g_content_type_is_a (content, "text/plain"))
node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT;
node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_TEXT;
}
model_recomposite_icon_real (model, node, info);
if (free_info)
@ -1969,7 +1973,7 @@ file_browser_node_set_from_info (XedFileBrowserStore * model,
path = xed_file_browser_store_get_path_real (model, node);
model_refilter_node (model, node, &path);
gtk_tree_path_free (path);
model_check_dummy (model, node->parent);
} else {
model_node_update_visibility (model, node);
@ -2013,11 +2017,11 @@ model_add_node_from_file (XedFileBrowserStore * model,
&error);
free_info = TRUE;
}
if (!info) {
g_warning ("Error querying file info: %s", error->message);
g_error_free (error);
/* FIXME: What to do now then... */
node = file_browser_node_new (file, parent);
} else if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
@ -2028,7 +2032,7 @@ model_add_node_from_file (XedFileBrowserStore * model,
file_browser_node_set_from_info (model, node, info, FALSE);
model_add_node (model, node, parent);
if (info && free_info)
g_object_unref (info);
}
@ -2063,7 +2067,7 @@ model_add_nodes_from_files (XedFileBrowserStore * model,
type != G_FILE_TYPE_SYMBOLIC_LINK) {
g_object_unref (info);
continue;
}
}
name = g_file_info_get_name (info);
@ -2105,7 +2109,7 @@ model_add_node_from_dir (XedFileBrowserStore * model,
FileBrowserNode *node;
/* Check if it already exists */
if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) {
if ((node = node_list_contains_file (FILE_BROWSER_NODE_DIR (parent)->children, file)) == NULL) {
node = file_browser_node_dir_new (model, file, parent);
file_browser_node_set_from_info (model, node, NULL, FALSE);
@ -2142,15 +2146,15 @@ parse_dot_hidden_file (FileBrowserNode *directory)
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);
@ -2168,7 +2172,7 @@ parse_dot_hidden_file (FileBrowserNode *directory)
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) {
@ -2181,14 +2185,14 @@ parse_dot_hidden_file (FileBrowserNode *directory)
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);
@ -2216,7 +2220,7 @@ on_directory_monitor_event (GFileMonitor * monitor,
if (g_file_query_exists (file, NULL)) {
model_add_node_from_file (dir->model, parent, file, NULL);
}
break;
default:
break;
@ -2232,33 +2236,33 @@ async_node_free (AsyncNode *async)
}
static void
model_iterate_next_files_cb (GFileEnumerator * enumerator,
GAsyncResult * result,
model_iterate_next_files_cb (GFileEnumerator * enumerator,
GAsyncResult * result,
AsyncNode * async)
{
GList * files;
GError * error = NULL;
FileBrowserNodeDir * dir = async->dir;
FileBrowserNode * parent = (FileBrowserNode *)dir;
files = g_file_enumerator_next_files_finish (enumerator, result, &error);
if (files == NULL) {
g_file_enumerator_close (enumerator, NULL, NULL);
async_node_free (async);
if (!error)
{
/* We're done loading */
g_object_unref (dir->cancellable);
dir->cancellable = NULL;
/*
* FIXME: This is temporarly, it is a bug in gio:
* http://bugzilla.gnome.org/show_bug.cgi?id=565924
*/
if (g_file_is_native (parent->file) && dir->monitor == NULL) {
dir->monitor = g_file_monitor_directory (parent->file,
dir->monitor = g_file_monitor_directory (parent->file,
G_FILE_MONITOR_NONE,
NULL,
NULL);
@ -2277,7 +2281,7 @@ model_iterate_next_files_cb (GFileEnumerator * enumerator,
/* Simply return if we were cancelled */
if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
return;
/* Otherwise handle the error appropriately */
g_signal_emit (dir->model,
model_signals[ERROR],
@ -2294,7 +2298,7 @@ model_iterate_next_files_cb (GFileEnumerator * enumerator,
async_node_free (async);
} else {
model_add_nodes_from_files (dir->model, parent, async->original_children, files);
g_list_free (files);
next_files_async (enumerator, async);
}
@ -2313,7 +2317,7 @@ next_files_async (GFileEnumerator * enumerator,
}
static void
model_iterate_children_cb (GFile * file,
model_iterate_children_cb (GFile * file,
GAsyncResult * result,
AsyncNode * async)
{
@ -2325,13 +2329,13 @@ model_iterate_children_cb (GFile * file,
async_node_free (async);
return;
}
enumerator = g_file_enumerate_children_finish (file, result, &error);
if (enumerator == NULL) {
/* Simply return if we were cancelled or if the dir is not there */
FileBrowserNodeDir *dir = async->dir;
/* Otherwise handle the error appropriately */
g_signal_emit (dir->model,
model_signals[ERROR],
@ -2368,9 +2372,9 @@ model_load_directory (XedFileBrowserStore * model,
/* Read the '.hidden' file first (if any) */
parse_dot_hidden_file (node);
dir->cancellable = g_cancellable_new ();
async = g_new (AsyncNode, 1);
async->dir = dir;
async->cancellable = g_object_ref (dir->cancellable);
@ -2390,7 +2394,7 @@ static GList *
get_parent_files (XedFileBrowserStore * model, GFile * file)
{
GList * result = NULL;
result = g_list_prepend (result, g_object_ref (file));
while ((file = g_file_get_parent (file))) {
@ -2436,7 +2440,7 @@ model_fill (XedFileBrowserStore * model, FileBrowserNode * node,
if (node != model->priv->virtual_root) {
/* Insert node */
iter.user_data = node;
row_inserted(model, path, &iter);
}
@ -2459,7 +2463,7 @@ model_fill (XedFileBrowserStore * model, FileBrowserNode * node,
/* Move back up to node path */
gtk_tree_path_up (*path);
}
model_check_dummy (model, node);
if (free_path)
@ -2520,8 +2524,8 @@ set_virtual_root_from_node (XedFileBrowserStore * model,
for (item = FILE_BROWSER_NODE_DIR (node)->children; item;
item = item->next) {
check = (FileBrowserNode *) (item->data);
if (NODE_IS_DIR (check)) {
if (NODE_IS_DIR (check)) {
for (copy =
FILE_BROWSER_NODE_DIR (check)->children; copy;
copy = copy->next) {
@ -2572,7 +2576,7 @@ set_virtual_root_from_file (XedFileBrowserStore * model,
for (item = files; item; item = item->next) {
check = G_FILE (item->data);
parent = model_add_node_from_dir (model, parent, check);
g_object_unref (check);
}
@ -2590,21 +2594,21 @@ model_find_node_children (XedFileBrowserStore * model,
FileBrowserNode *child;
FileBrowserNode *result;
GSList *children;
if (!NODE_IS_DIR (parent))
return NULL;
dir = FILE_BROWSER_NODE_DIR (parent);
for (children = dir->children; children; children = children->next) {
child = (FileBrowserNode *)(children->data);
result = model_find_node (model, child, file);
if (result)
return result;
}
return NULL;
}
@ -2621,7 +2625,7 @@ model_find_node (XedFileBrowserStore * model,
if (NODE_IS_DIR (node) && g_file_has_prefix (file, node->file))
return model_find_node_children (model, node, file);
return NULL;
}
@ -2684,40 +2688,40 @@ handle_root_error (XedFileBrowserStore * model, GError *error)
{
FileBrowserNode * root;
g_signal_emit (model,
model_signals[ERROR],
0,
g_signal_emit (model,
model_signals[ERROR],
0,
XED_FILE_BROWSER_ERROR_SET_ROOT,
error->message);
/* Set the virtual root to the root */
root = model->priv->root;
model->priv->virtual_root = root;
/* Set the root to be loaded */
root->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED;
/* Check the dummy */
model_check_dummy (model, root);
g_object_notify (G_OBJECT (model), "root");
g_object_notify (G_OBJECT (model), "virtual-root");
}
static void
mount_cb (GFile * file,
GAsyncResult * res,
mount_cb (GFile * file,
GAsyncResult * res,
MountInfo * mount_info)
{
gboolean mounted;
GError * error = NULL;
XedFileBrowserStore * model = mount_info->model;
mounted = g_file_mount_enclosing_volume_finish (file, res, &error);
if (mount_info->model)
{
model->priv->mount_info = NULL;
model->priv->mount_info = NULL;
model_end_loading (model, model->priv->root);
}
@ -2734,7 +2738,7 @@ mount_cb (GFile * file,
{
handle_root_error (model, error);
}
if (error)
g_error_free (error);
@ -2751,9 +2755,9 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root)
GFileInfo * info;
GError * error = NULL;
MountInfo * mount_info;
info = g_file_query_info (model->priv->root->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
info = g_file_query_info (model->priv->root->file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
NULL,
&error);
@ -2762,23 +2766,23 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root)
if (error->code == G_IO_ERROR_NOT_MOUNTED) {
/* Try to mount it */
FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new ();
mount_info = g_new(MountInfo, 1);
mount_info->model = model;
mount_info->virtual_root = g_strdup (virtual_root);
/* FIXME: we should be setting the correct window */
mount_info->operation = gtk_mount_operation_new (NULL);
mount_info->cancellable = g_object_ref (FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable);
model_begin_loading (model, model->priv->root);
g_file_mount_enclosing_volume (model->priv->root->file,
g_file_mount_enclosing_volume (model->priv->root->file,
G_MOUNT_MOUNT_NONE,
mount_info->operation,
mount_info->cancellable,
(GAsyncReadyCallback)mount_cb,
mount_info);
model->priv->mount_info = mount_info;
return XED_FILE_BROWSER_STORE_RESULT_MOUNTING;
}
@ -2786,14 +2790,14 @@ model_mount_root (XedFileBrowserStore * model, gchar const * virtual_root)
{
handle_root_error (model, error);
}
g_error_free (error);
} else {
g_object_unref (info);
return model_root_mounted (model, virtual_root);
}
return XED_FILE_BROWSER_STORE_RESULT_OK;
}
@ -2844,7 +2848,7 @@ xed_file_browser_store_set_value (XedFileBrowserStore * tree_model,
model_recomposite_icon (tree_model, iter);
if (model_node_visibility (tree_model, node)) {
path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model),
path = xed_file_browser_store_get_path (GTK_TREE_MODEL (tree_model),
iter);
row_changed (tree_model, &path, iter);
gtk_tree_path_free (path);
@ -3002,7 +3006,7 @@ void
xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store)
{
g_return_if_fail (XED_IS_FILE_BROWSER_STORE (store));
cancel_mount_operation (store);
}
@ -3049,7 +3053,7 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *
g_object_unref (vfile);
}
/* make sure to cancel any previous mount operations */
cancel_mount_operation (model);
@ -3063,7 +3067,7 @@ xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *
if (file != NULL) {
/* Create the root node */
node = file_browser_node_dir_new (model, file, NULL);
g_object_unref (file);
model->priv->root = node;
@ -3091,18 +3095,18 @@ gchar *
xed_file_browser_store_get_root (XedFileBrowserStore * model)
{
g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL);
if (model->priv->root == NULL || model->priv->root->file == NULL)
return NULL;
else
return g_file_get_uri (model->priv->root->file);
}
gchar *
gchar *
xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model)
{
g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), NULL);
if (model->priv->virtual_root == NULL || model->priv->virtual_root->file == NULL)
return NULL;
else
@ -3228,7 +3232,7 @@ reparent_node (FileBrowserNode * node, gboolean reparent)
if (!node->file) {
return;
}
if (reparent) {
parent = node->parent->file;
base = g_file_get_basename (node->file);
@ -3237,10 +3241,10 @@ reparent_node (FileBrowserNode * node, gboolean reparent)
node->file = g_file_get_child (parent, base);
g_free (base);
}
if (NODE_IS_DIR (node)) {
dir = FILE_BROWSER_NODE_DIR (node);
for (child = dir->children; child; child = child->next) {
reparent_node ((FileBrowserNode *)child->data, TRUE);
}
@ -3286,7 +3290,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model,
/* This makes sure the actual info for the node is requeried */
file_browser_node_set_name (node);
file_browser_node_set_from_info (model, node, NULL, TRUE);
reparent_node (node, FALSE);
if (model_node_visibility (model, node)) {
@ -3298,7 +3302,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model,
model_resort_node (model, node);
} else {
g_object_unref (previous);
if (error != NULL)
*error = g_error_new_literal (xed_file_browser_store_error_quark (),
XED_FILE_BROWSER_ERROR_RENAME,
@ -3327,7 +3331,7 @@ xed_file_browser_store_rename (XedFileBrowserStore * model,
XED_FILE_BROWSER_ERROR_RENAME,
err->message);
}
g_error_free (err);
}
@ -3339,13 +3343,13 @@ static void
async_data_free (AsyncData * data)
{
g_object_unref (data->cancellable);
g_list_foreach (data->files, (GFunc)g_object_unref, NULL);
g_list_free (data->files);
if (!data->removed)
data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data);
g_free (data);
}
@ -3372,7 +3376,7 @@ file_deleted (IdleDelete * data)
if (node != NULL)
model_remove_node (data->model, node, NULL, TRUE);
return FALSE;
}
@ -3386,14 +3390,14 @@ delete_files (GIOSchedulerJob * job,
gboolean ret;
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)
ret = g_file_trash (file, cancellable, &error);
else
@ -3419,7 +3423,7 @@ delete_files (GIOSchedulerJob * job,
return TRUE;
}
/* End the job */
return FALSE;
} else if (code == G_IO_ERROR_CANCELLED) {
@ -3427,7 +3431,7 @@ delete_files (GIOSchedulerJob * job,
return FALSE;
}
}
/* Process the next item */
data->iter = data->iter->next;
return TRUE;
@ -3446,7 +3450,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
GtkTreePath * path;
g_return_val_if_fail (XED_IS_FILE_BROWSER_STORE (model), XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE);
if (rows == NULL)
return XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE;
@ -3460,17 +3464,17 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
continue;
/* Skip if the current path is actually a descendant of the
previous path */
if (prev != NULL && gtk_tree_path_is_descendant (path, prev))
continue;
prev = path;
node = (FileBrowserNode *)(iter.user_data);
files = g_list_prepend (files, g_object_ref (node->file));
}
data = g_new (AsyncData, 1);
data->model = model;
@ -3479,17 +3483,17 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model,
data->trash = trash;
data->iter = files;
data->removed = FALSE;
model->priv->async_handles =
g_slist_prepend (model->priv->async_handles, data);
g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files,
g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files,
data,
(GDestroyNotify)async_data_free,
G_PRIORITY_DEFAULT,
(GDestroyNotify)async_data_free,
G_PRIORITY_DEFAULT,
data->cancellable);
g_list_free (rows);
return XED_FILE_BROWSER_STORE_RESULT_OK;
}
@ -3512,10 +3516,10 @@ xed_file_browser_store_delete (XedFileBrowserStore * model,
rows = g_list_append(NULL, xed_file_browser_store_get_path_real (model, node));
result = xed_file_browser_store_delete_all (model, rows, trash);
g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
g_list_free (rows);
return result;
}
@ -3544,7 +3548,7 @@ xed_file_browser_store_new_file (XedFileBrowserStore * model,
file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file"));
stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
if (!stream)
{
g_signal_emit (model, model_signals[ERROR], 0,
@ -3553,9 +3557,9 @@ xed_file_browser_store_new_file (XedFileBrowserStore * model,
g_error_free (error);
} else {
g_object_unref (stream);
node = model_add_node_from_file (model,
(FileBrowserNode *)parent_node,
file,
node = model_add_node_from_file (model,
(FileBrowserNode *)parent_node,
file,
NULL);
if (model_node_visibility (model, node)) {
@ -3602,9 +3606,9 @@ xed_file_browser_store_new_directory (XedFileBrowserStore * model,
error->message);
g_error_free (error);
} else {
node = model_add_node_from_file (model,
(FileBrowserNode *)parent_node,
file,
node = model_add_node_from_file (model,
(FileBrowserNode *)parent_node,
file,
NULL);
if (model_node_visibility (model, node)) {
@ -3622,4 +3626,10 @@ xed_file_browser_store_new_directory (XedFileBrowserStore * model,
return result;
}
void
_xed_file_browser_store_register_type (GTypeModule *type_module)
{
xed_file_browser_store_register_type (type_module);
}
// ex:ts=8:noet:

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-store.h - Xed plugin providing easy file access
* xed-file-browser-store.h - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -25,113 +25,113 @@
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define XED_TYPE_FILE_BROWSER_STORE (xed_file_browser_store_get_type ())
#define XED_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore))
#define XED_FILE_BROWSER_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore const))
#define XED_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass))
#define XED_IS_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_STORE))
#define XED_IS_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_STORE))
#define XED_FILE_BROWSER_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass))
#define XED_TYPE_FILE_BROWSER_STORE (xed_file_browser_store_get_type ())
#define XED_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore))
#define XED_FILE_BROWSER_STORE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStore const))
#define XED_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass))
#define XED_IS_FILE_BROWSER_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_STORE))
#define XED_IS_FILE_BROWSER_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_STORE))
#define XED_FILE_BROWSER_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_STORE, XedFileBrowserStoreClass))
typedef enum
typedef enum
{
XED_FILE_BROWSER_STORE_COLUMN_ICON = 0,
XED_FILE_BROWSER_STORE_COLUMN_NAME,
XED_FILE_BROWSER_STORE_COLUMN_URI,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS,
XED_FILE_BROWSER_STORE_COLUMN_EMBLEM,
XED_FILE_BROWSER_STORE_COLUMN_NUM
XED_FILE_BROWSER_STORE_COLUMN_ICON = 0,
XED_FILE_BROWSER_STORE_COLUMN_NAME,
XED_FILE_BROWSER_STORE_COLUMN_URI,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS,
XED_FILE_BROWSER_STORE_COLUMN_EMBLEM,
XED_FILE_BROWSER_STORE_COLUMN_NUM
} XedFileBrowserStoreColumn;
typedef enum
typedef enum
{
XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY = 1 << 0,
XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN = 1 << 1,
XED_FILE_BROWSER_STORE_FLAG_IS_TEXT = 1 << 2,
XED_FILE_BROWSER_STORE_FLAG_LOADED = 1 << 3,
XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED = 1 << 4,
XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY = 1 << 5
XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY = 1 << 0,
XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN = 1 << 1,
XED_FILE_BROWSER_STORE_FLAG_IS_TEXT = 1 << 2,
XED_FILE_BROWSER_STORE_FLAG_LOADED = 1 << 3,
XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED = 1 << 4,
XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY = 1 << 5
} XedFileBrowserStoreFlag;
typedef enum
typedef enum
{
XED_FILE_BROWSER_STORE_RESULT_OK,
XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE,
XED_FILE_BROWSER_STORE_RESULT_ERROR,
XED_FILE_BROWSER_STORE_RESULT_NO_TRASH,
XED_FILE_BROWSER_STORE_RESULT_MOUNTING,
XED_FILE_BROWSER_STORE_RESULT_NUM
XED_FILE_BROWSER_STORE_RESULT_OK,
XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE,
XED_FILE_BROWSER_STORE_RESULT_ERROR,
XED_FILE_BROWSER_STORE_RESULT_NO_TRASH,
XED_FILE_BROWSER_STORE_RESULT_MOUNTING,
XED_FILE_BROWSER_STORE_RESULT_NUM
} XedFileBrowserStoreResult;
typedef enum
typedef enum
{
XED_FILE_BROWSER_STORE_FILTER_MODE_NONE = 0,
XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN = 1 << 0,
XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY = 1 << 1
XED_FILE_BROWSER_STORE_FILTER_MODE_NONE = 0,
XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN = 1 << 0,
XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY = 1 << 1
} XedFileBrowserStoreFilterMode;
#define FILE_IS_DIR(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)
#define FILE_IS_HIDDEN(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN)
#define FILE_IS_TEXT(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_TEXT)
#define FILE_LOADED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_LOADED)
#define FILE_IS_FILTERED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED)
#define FILE_IS_DUMMY(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY)
#define FILE_IS_DIR(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DIRECTORY)
#define FILE_IS_HIDDEN(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN)
#define FILE_IS_TEXT(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_TEXT)
#define FILE_LOADED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_LOADED)
#define FILE_IS_FILTERED(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_FILTERED)
#define FILE_IS_DUMMY(flags) (flags & XED_FILE_BROWSER_STORE_FLAG_IS_DUMMY)
typedef struct _XedFileBrowserStore XedFileBrowserStore;
typedef struct _XedFileBrowserStoreClass XedFileBrowserStoreClass;
typedef struct _XedFileBrowserStorePrivate XedFileBrowserStorePrivate;
typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore
* model,
GtkTreeIter * iter,
gpointer user_data);
* model,
GtkTreeIter * iter,
gpointer user_data);
struct _XedFileBrowserStore
struct _XedFileBrowserStore
{
GObject parent;
GObject parent;
XedFileBrowserStorePrivate *priv;
XedFileBrowserStorePrivate *priv;
};
struct _XedFileBrowserStoreClass {
GObjectClass parent_class;
GObjectClass parent_class;
/* Signals */
void (*begin_loading) (XedFileBrowserStore * model,
GtkTreeIter * iter);
void (*end_loading) (XedFileBrowserStore * model,
GtkTreeIter * iter);
void (*error) (XedFileBrowserStore * model,
guint code,
gchar * message);
gboolean (*no_trash) (XedFileBrowserStore * model,
GList * files);
void (*rename) (XedFileBrowserStore * model,
const gchar * olduri,
const gchar * newuri);
void (*begin_refresh) (XedFileBrowserStore * model);
void (*end_refresh) (XedFileBrowserStore * model);
void (*unload) (XedFileBrowserStore * model,
const gchar * uri);
/* Signals */
void (*begin_loading) (XedFileBrowserStore * model,
GtkTreeIter * iter);
void (*end_loading) (XedFileBrowserStore * model,
GtkTreeIter * iter);
void (*error) (XedFileBrowserStore * model,
guint code,
gchar * message);
gboolean (*no_trash) (XedFileBrowserStore * model,
GList * files);
void (*rename) (XedFileBrowserStore * model,
const gchar * olduri,
const gchar * newuri);
void (*begin_refresh) (XedFileBrowserStore * model);
void (*end_refresh) (XedFileBrowserStore * model);
void (*unload) (XedFileBrowserStore * model,
const gchar * uri);
};
GType xed_file_browser_store_get_type (void) G_GNUC_CONST;
GType xed_file_browser_store_register_type (GTypeModule * module);
void _xed_file_browser_store_register_type (GTypeModule * module);
XedFileBrowserStore *xed_file_browser_store_new (gchar const *root);
XedFileBrowserStoreResult
xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * model,
gchar const *root,
gchar const *virtual_root);
gchar const *root,
gchar const *virtual_root);
XedFileBrowserStoreResult
xed_file_browser_store_set_root (XedFileBrowserStore * model,
gchar const *root);
gchar const *root);
XedFileBrowserStoreResult
xed_file_browser_store_set_virtual_root (XedFileBrowserStore * model,
GtkTreeIter * iter);
GtkTreeIter * iter);
XedFileBrowserStoreResult
xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore * model,
xed_file_browser_store_set_virtual_root_from_string (XedFileBrowserStore * model,
gchar const *root);
XedFileBrowserStoreResult
xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore * model);
@ -139,25 +139,25 @@ XedFileBrowserStoreResult
xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore * model);
gboolean
xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model,
xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model,
GtkTreeIter * iter);
gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore * model,
GtkTreeIter * iter);
GtkTreeIter * iter);
gchar * xed_file_browser_store_get_root (XedFileBrowserStore * model);
gchar * xed_file_browser_store_get_virtual_root (XedFileBrowserStore * model);
gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore * model,
gboolean xed_file_browser_store_iter_equal (XedFileBrowserStore * model,
GtkTreeIter * iter1,
GtkTreeIter * iter2);
GtkTreeIter * iter2);
void xed_file_browser_store_set_value (XedFileBrowserStore * tree_model,
void xed_file_browser_store_set_value (XedFileBrowserStore * tree_model,
GtkTreeIter * iter,
gint column,
gint column,
GValue * value);
void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model,
void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model,
GtkTreeIter * iter);
void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model,
void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore * model,
GtkTreeIter * iter);
XedFileBrowserStoreFilterMode
@ -165,7 +165,7 @@ xed_file_browser_store_get_filter_mode (XedFileBrowserStore * model
void xed_file_browser_store_set_filter_mode (XedFileBrowserStore * model,
XedFileBrowserStoreFilterMode mode);
void xed_file_browser_store_set_filter_func (XedFileBrowserStore * model,
XedFileBrowserStoreFilterFunc func,
XedFileBrowserStoreFilterFunc func,
gpointer user_data);
void xed_file_browser_store_refilter (XedFileBrowserStore * model);
XedFileBrowserStoreFilterMode
@ -178,11 +178,11 @@ gboolean xed_file_browser_store_rename (XedFileBrowserStore * model
GError ** error);
XedFileBrowserStoreResult
xed_file_browser_store_delete (XedFileBrowserStore * model,
GtkTreeIter * iter,
GtkTreeIter * iter,
gboolean trash);
XedFileBrowserStoreResult
xed_file_browser_store_delete_all (XedFileBrowserStore * model,
GList *rows,
GList *rows,
gboolean trash);
gboolean xed_file_browser_store_new_file (XedFileBrowserStore * model,
@ -195,6 +195,6 @@ gboolean xed_file_browser_store_new_directory (XedFileBrowserStore * model
void xed_file_browser_store_cancel_mount_operation (XedFileBrowserStore *store);
G_END_DECLS
#endif /* __XED_FILE_BROWSER_STORE_H__ */
#endif /* __XED_FILE_BROWSER_STORE_H__ */
// ex:ts=8:noet:

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-view.c - Xed plugin providing easy file access
* xed-file-browser-view.c - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -21,7 +21,6 @@
#include <string.h>
#include <gio/gio.h>
#include <xed/xed-plugin.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@ -35,7 +34,7 @@
G_TYPE_INSTANCE_GET_PRIVATE((object), \
XED_TYPE_FILE_BROWSER_VIEW, XedFileBrowserViewPrivate))
struct _XedFileBrowserViewPrivate
struct _XedFileBrowserViewPrivate
{
GtkTreeViewColumn *column;
GtkCellRenderer *pixbuf_renderer;
@ -55,7 +54,7 @@ struct _XedFileBrowserViewPrivate
gboolean selected_on_button_down;
gint drag_button;
gboolean drag_started;
gboolean restore_expand_state;
gboolean is_refresh;
GHashTable * expand_state;
@ -65,7 +64,7 @@ struct _XedFileBrowserViewPrivate
enum
{
PROP_0,
PROP_CLICK_POLICY,
PROP_RESTORE_EXPAND_STATE
};
@ -86,33 +85,33 @@ static const GtkTargetEntry drag_source_targets[] = {
{ "text/uri-list", 0, 0 }
};
XED_PLUGIN_DEFINE_TYPE (XedFileBrowserView, xed_file_browser_view,
G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view,
GTK_TYPE_TREE_VIEW)
static void on_cell_edited (GtkCellRendererText * cell,
static void on_cell_edited (GtkCellRendererText * cell,
gchar * path,
gchar * new_text,
XedFileBrowserView * tree_view);
static void on_begin_refresh (XedFileBrowserStore * model,
static void on_begin_refresh (XedFileBrowserStore * model,
XedFileBrowserView * view);
static void on_end_refresh (XedFileBrowserStore * model,
static void on_end_refresh (XedFileBrowserStore * model,
XedFileBrowserView * view);
static void on_unload (XedFileBrowserStore * model,
static void on_unload (XedFileBrowserStore * model,
gchar const * uri,
XedFileBrowserView * view);
static void on_row_inserted (XedFileBrowserStore * model,
static void on_row_inserted (XedFileBrowserStore * model,
GtkTreePath * path,
GtkTreeIter * iter,
XedFileBrowserView * view);
static void
xed_file_browser_view_finalize (GObject * object)
{
XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object);
if (obj->priv->hand_cursor)
g_object_unref (obj->priv->hand_cursor);
@ -136,12 +135,12 @@ add_expand_state (XedFileBrowserView * view,
gchar const * uri)
{
GFile * file;
if (!uri)
return;
file = g_file_new_for_uri (uri);
if (view->priv->expand_state)
g_hash_table_insert (view->priv->expand_state, file, file);
else
@ -153,12 +152,12 @@ remove_expand_state (XedFileBrowserView * view,
gchar const * uri)
{
GFile * file;
if (!uri)
return;
file = g_file_new_for_uri (uri);
if (view->priv->expand_state)
g_hash_table_remove (view->priv->expand_state, file);
@ -182,7 +181,7 @@ row_expanded (GtkTreeView * tree_view,
if (view->priv->restore_expand_state)
{
gtk_tree_model_get (view->priv->model,
iter,
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
@ -208,11 +207,11 @@ row_collapsed (GtkTreeView * tree_view,
if (!XED_IS_FILE_BROWSER_STORE (view->priv->model))
return;
if (view->priv->restore_expand_state)
{
gtk_tree_model_get (view->priv->model,
iter,
gtk_tree_model_get (view->priv->model,
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
@ -291,7 +290,7 @@ motion_notify_event (GtkWidget * widget,
if (old_hover_path != NULL)
gtk_tree_path_free (old_hover_path);
}
// Chainup
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event);
}
@ -323,7 +322,7 @@ set_click_policy_property (XedFileBrowserView *obj,
if (gtk_widget_get_realized (GTK_WIDGET (obj))) {
win = gtk_widget_get_window (GTK_WIDGET (obj));
gdk_window_set_cursor (win, NULL);
display = gtk_widget_get_display (GTK_WIDGET (obj));
if (display != NULL)
@ -338,7 +337,7 @@ set_click_policy_property (XedFileBrowserView *obj,
}
static void
directory_activated (XedFileBrowserView *view,
directory_activated (XedFileBrowserView *view,
GtkTreeIter *iter)
{
xed_file_browser_store_set_virtual_root (XED_FILE_BROWSER_STORE (view->priv->model), iter);
@ -355,30 +354,30 @@ activate_selected_files (XedFileBrowserView *view) {
XedFileBrowserStoreFlag flags;
rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model);
for (row = rows; row; row = row->next) {
path = (GtkTreePath *)(row->data);
/* Get iter from path */
if (!gtk_tree_model_get_iter (view->priv->model, &iter, path))
continue;
gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1);
if (FILE_IS_DIR (flags)) {
if (directory == NULL)
directory = path;
} else if (!FILE_IS_DUMMY (flags)) {
g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter);
}
}
if (directory != NULL) {
if (gtk_tree_model_get_iter (view->priv->model, &iter, directory))
g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter);
}
g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
g_list_free (rows);
}
@ -428,10 +427,10 @@ drag_begin (GtkWidget *widget,
GdkDragContext *context)
{
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget);
view->priv->drag_button = 0;
view->priv->drag_started = TRUE;
/* Chain up */
GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->drag_begin (widget, context);
}
@ -443,14 +442,14 @@ did_not_drag (XedFileBrowserView *view,
GtkTreeView *tree_view;
GtkTreeSelection *selection;
GtkTreePath *path;
tree_view = GTK_TREE_VIEW (view);
selection = gtk_tree_view_get_selection (tree_view);
if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
&path, NULL, NULL, NULL)) {
if ((view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE)
&& !button_event_modifies_selection(event)
&& !button_event_modifies_selection(event)
&& (event->button == 1 || event->button == 2)) {
/* Activate all selected items, and leave them selected */
activate_selected_items (view);
@ -483,9 +482,9 @@ button_release_event (GtkWidget *widget,
!view->priv->ignore_release)
did_not_drag (view, event);
}
/* Chain up */
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event);
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->button_release_event (widget, event);
}
static gboolean
@ -511,7 +510,7 @@ button_press_event (GtkWidget *widget,
selection = gtk_tree_view_get_selection (tree_view);
/* Get double click time */
g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
"gtk-double-click-time", &double_click_time,
NULL);
@ -520,11 +519,11 @@ button_press_event (GtkWidget *widget,
click_count++;
else
click_count = 0;
last_click_time = event->time;
/* Ignore double click if we are in single click mode */
if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE &&
if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE &&
click_count >= 2) {
return TRUE;
}
@ -536,7 +535,7 @@ button_press_event (GtkWidget *widget,
&path, NULL, NULL, NULL)) {
/* Keep track of path of last click so double clicks only happen
* on the same item */
if ((event->button == 1 || event->button == 2) &&
if ((event->button == 1 || event->button == 2) &&
event->type == GDK_BUTTON_PRESS) {
if (view->priv->double_click_path[1])
gtk_tree_path_free (view->priv->double_click_path[1]);
@ -549,7 +548,7 @@ button_press_event (GtkWidget *widget,
if (view->priv->double_click_path[1] &&
gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0)
activate_selected_items (view);
/* Chain up */
widget_parent->button_press_event (widget, event);
} else {
@ -585,14 +584,14 @@ button_press_event (GtkWidget *widget,
view->priv->ignore_release = on_expander;
}
}
if (call_parent) {
/* Chain up */
widget_parent->button_press_event (widget, event);
} else if (selected) {
gtk_widget_grab_focus (widget);
}
if ((event->button == 1 || event->button == 2) &&
event->type == GDK_BUTTON_PRESS) {
view->priv->drag_started = FALSE;
@ -602,7 +601,7 @@ button_press_event (GtkWidget *widget,
gtk_tree_path_free (path);
} else {
if ((event->button == 1 || event->button == 2) &&
if ((event->button == 1 || event->button == 2) &&
event->type == GDK_BUTTON_PRESS) {
if (view->priv->double_click_path[1])
gtk_tree_path_free (view->priv->double_click_path[1]);
@ -668,7 +667,7 @@ key_press_event (GtkWidget *widget,
/* Chain up */
if (!handled)
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event);
return TRUE;
}
@ -678,31 +677,31 @@ fill_expand_state (XedFileBrowserView * view, GtkTreeIter * iter)
GtkTreePath * path;
GtkTreeIter child;
gchar * uri;
if (!gtk_tree_model_iter_has_child (view->priv->model, iter))
return;
path = gtk_tree_model_get_path (view->priv->model, iter);
if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path))
{
gtk_tree_model_get (view->priv->model,
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
gtk_tree_model_get (view->priv->model,
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
add_expand_state (view, uri);
g_free (uri);
}
if (gtk_tree_model_iter_children (view->priv->model, &child, iter))
{
do {
fill_expand_state (view, &child);
} while (gtk_tree_model_iter_next (view->priv->model, &child));
}
gtk_tree_path_free (path);
}
@ -710,20 +709,20 @@ static void
uninstall_restore_signals (XedFileBrowserView * tree_view,
GtkTreeModel * model)
{
g_signal_handlers_disconnect_by_func (model,
on_begin_refresh,
tree_view);
g_signal_handlers_disconnect_by_func (model,
on_end_refresh,
tree_view);
g_signal_handlers_disconnect_by_func (model,
on_unload,
g_signal_handlers_disconnect_by_func (model,
on_begin_refresh,
tree_view);
g_signal_handlers_disconnect_by_func (model,
on_row_inserted,
g_signal_handlers_disconnect_by_func (model,
on_end_refresh,
tree_view);
g_signal_handlers_disconnect_by_func (model,
on_unload,
tree_view);
g_signal_handlers_disconnect_by_func (model,
on_row_inserted,
tree_view);
}
@ -731,24 +730,24 @@ static void
install_restore_signals (XedFileBrowserView * tree_view,
GtkTreeModel * model)
{
g_signal_connect (model,
g_signal_connect (model,
"begin-refresh",
G_CALLBACK (on_begin_refresh),
G_CALLBACK (on_begin_refresh),
tree_view);
g_signal_connect (model,
g_signal_connect (model,
"end-refresh",
G_CALLBACK (on_end_refresh),
G_CALLBACK (on_end_refresh),
tree_view);
g_signal_connect (model,
g_signal_connect (model,
"unload",
G_CALLBACK (on_unload),
G_CALLBACK (on_unload),
tree_view);
g_signal_connect_after (model,
g_signal_connect_after (model,
"row-inserted",
G_CALLBACK (on_row_inserted),
G_CALLBACK (on_row_inserted),
tree_view);
}
@ -771,7 +770,7 @@ set_restore_expand_state (XedFileBrowserView * view,
(GEqualFunc)g_file_equal,
g_object_unref,
NULL);
if (view->priv->model && XED_IS_FILE_BROWSER_STORE (view->priv->model))
{
fill_expand_state (view, NULL);
@ -837,11 +836,11 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkTreeViewClass *tree_view_class = GTK_TREE_VIEW_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = xed_file_browser_view_finalize;
object_class->get_property = get_property;
object_class->set_property = set_property;
/* Event handlers */
widget_class->motion_notify_event = motion_notify_event;
widget_class->enter_notify_event = enter_notify_event;
@ -854,7 +853,7 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass)
/* Tree view handlers */
tree_view_class->row_expanded = row_expanded;
tree_view_class->row_collapsed = row_collapsed;
/* Default handlers */
klass->directory_activated = directory_activated;
@ -910,6 +909,12 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass)
sizeof (XedFileBrowserViewPrivate));
}
static void
xed_file_browser_view_class_finalize (XedFileBrowserViewClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE */
}
static void
cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell,
GtkTreeModel * tree_model, GtkTreeIter * iter,
@ -922,18 +927,18 @@ cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell,
path = gtk_tree_model_get_path (tree_model, iter);
if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) {
if (obj->priv->hover_path != NULL &&
if (obj->priv->hover_path != NULL &&
gtk_tree_path_compare (path, obj->priv->hover_path) == 0)
underline = PANGO_UNDERLINE_SINGLE;
underline = PANGO_UNDERLINE_SINGLE;
}
if (XED_IS_FILE_BROWSER_STORE (tree_model))
{
if (obj->priv->editable != NULL &&
if (obj->priv->editable != NULL &&
gtk_tree_row_reference_valid (obj->priv->editable))
{
GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable);
editable = edpath && gtk_tree_path_compare (path, edpath) == 0;
}
}
@ -1018,7 +1023,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
if (XED_IS_FILE_BOOKMARKS_STORE (model)) {
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW
(tree_view),
bookmarks_separator_func,
@ -1045,7 +1050,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
if (tree_view->priv->restore_expand_state)
install_restore_signals (tree_view, model);
}
if (tree_view->priv->hover_path != NULL) {
@ -1055,7 +1060,7 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)) {
if (tree_view->priv->restore_expand_state)
uninstall_restore_signals (tree_view,
uninstall_restore_signals (tree_view,
tree_view->priv->model);
}
@ -1088,18 +1093,18 @@ xed_file_browser_view_start_rename (XedFileBrowserView * tree_view,
/* Start editing */
gtk_widget_grab_focus (GTK_WIDGET (tree_view));
if (gtk_tree_path_up (path))
gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view),
path);
gtk_tree_path_free (path);
tree_view->priv->editable = rowref;
gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view),
gtk_tree_row_reference_get_path (tree_view->priv->editable),
tree_view->priv->column, TRUE);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view),
gtk_tree_row_reference_get_path (tree_view->priv->editable),
tree_view->priv->column,
@ -1111,9 +1116,9 @@ xed_file_browser_view_set_click_policy (XedFileBrowserView *tree_view,
XedFileBrowserViewClickPolicy policy)
{
g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view));
set_click_policy_property (tree_view, policy);
g_object_notify (G_OBJECT (tree_view), "click-policy");
}
@ -1136,13 +1141,13 @@ on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text,
GtkTreeIter iter;
gboolean ret;
GError * error = NULL;
gtk_tree_row_reference_free (tree_view->priv->editable);
tree_view->priv->editable = NULL;
if (new_text == NULL || *new_text == '\0')
return;
treepath = gtk_tree_path_new_from_string (path);
ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath);
gtk_tree_path_free (treepath);
@ -1166,8 +1171,8 @@ on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text,
}
}
static void
on_begin_refresh (XedFileBrowserStore * model,
static void
on_begin_refresh (XedFileBrowserStore * model,
XedFileBrowserView * view)
{
/* Store the refresh state, so we can handle unloading of nodes while
@ -1175,8 +1180,8 @@ on_begin_refresh (XedFileBrowserStore * model,
view->priv->is_refresh = TRUE;
}
static void
on_end_refresh (XedFileBrowserStore * model,
static void
on_end_refresh (XedFileBrowserStore * model,
XedFileBrowserView * view)
{
/* Store the refresh state, so we can handle unloading of nodes while
@ -1185,14 +1190,14 @@ on_end_refresh (XedFileBrowserStore * model,
}
static void
on_unload (XedFileBrowserStore * model,
on_unload (XedFileBrowserStore * model,
gchar const * uri,
XedFileBrowserView * view)
{
/* Don't remove the expand state if we are refreshing */
if (!view->priv->restore_expand_state || view->priv->is_refresh)
return;
remove_expand_state (view, uri);
}
@ -1205,10 +1210,10 @@ restore_expand_state (XedFileBrowserView * view,
GFile * file;
GtkTreePath * path;
gtk_tree_model_get (GTK_TREE_MODEL (model),
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
gtk_tree_model_get (GTK_TREE_MODEL (model),
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
if (!uri)
@ -1223,15 +1228,15 @@ restore_expand_state (XedFileBrowserView * view,
path,
FALSE);
}
gtk_tree_path_free (path);
g_object_unref (file);
g_object_unref (file);
g_free (uri);
}
static void
on_row_inserted (XedFileBrowserStore * model,
static void
on_row_inserted (XedFileBrowserStore * model,
GtkTreePath * path,
GtkTreeIter * iter,
XedFileBrowserView * view)
@ -1253,5 +1258,11 @@ on_row_inserted (XedFileBrowserStore * model,
gtk_tree_path_free (copy);
}
void
_xed_file_browser_view_register_type (GTypeModule *type_module)
{
xed_file_browser_view_register_type (type_module);
}
// ex:ts=8:noet:

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-view.h - Xed plugin providing easy file access
* xed-file-browser-view.h - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -39,22 +39,22 @@ typedef struct _XedFileBrowserViewPrivate XedFileBrowserViewPrivate;
typedef enum {
XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE,
XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE
XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE
} XedFileBrowserViewClickPolicy;
struct _XedFileBrowserView
struct _XedFileBrowserView
{
GtkTreeView parent;
XedFileBrowserViewPrivate *priv;
};
struct _XedFileBrowserViewClass
struct _XedFileBrowserViewClass
{
GtkTreeViewClass parent_class;
/* Signals */
void (*error) (XedFileBrowserView * filetree,
void (*error) (XedFileBrowserView * filetree,
guint code,
gchar const *message);
void (*file_activated) (XedFileBrowserView * filetree,
@ -66,12 +66,12 @@ struct _XedFileBrowserViewClass
};
GType xed_file_browser_view_get_type (void) G_GNUC_CONST;
GType xed_file_browser_view_register_type (GTypeModule * module);
void _xed_file_browser_view_register_type (GTypeModule * module);
GtkWidget *xed_file_browser_view_new (void);
void xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
GtkTreeModel * model);
void xed_file_browser_view_start_rename (XedFileBrowserView * tree_view,
void xed_file_browser_view_start_rename (XedFileBrowserView * tree_view,
GtkTreeIter * iter);
void xed_file_browser_view_set_click_policy (XedFileBrowserView * tree_view,
XedFileBrowserViewClickPolicy policy);

View File

@ -32,7 +32,6 @@
#include <gdk/gdkkeysyms.h>
#include <xed/xed-utils.h>
#include <xed/xed-plugin.h>
#include "xed-file-browser-utils.h"
#include "xed-file-browser-error.h"
@ -236,7 +235,7 @@ static void on_action_filter_binary (GtkAction * action,
static void on_action_bookmark_open (GtkAction * action,
XedFileBrowserWidget * obj);
XED_PLUGIN_DEFINE_TYPE (XedFileBrowserWidget, xed_file_browser_widget,
G_DEFINE_DYNAMIC_TYPE (XedFileBrowserWidget, xed_file_browser_widget,
GTK_TYPE_BOX)
static void
@ -479,6 +478,12 @@ xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass)
sizeof (XedFileBrowserWidgetPrivate));
}
static void
xed_file_browser_widget_class_finalize (XedFileBrowserWidgetClass *klass)
{
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE */
}
static void
add_signal (XedFileBrowserWidget * obj, gpointer object, gulong id)
{
@ -3146,4 +3151,10 @@ on_action_bookmark_open (GtkAction * action, XedFileBrowserWidget * obj)
bookmark_open (obj, model, &iter);
}
void
_xed_file_browser_widget_register_type (GTypeModule *type_module)
{
xed_file_browser_widget_register_type (type_module);
}
// ex:ts=8:noet:

View File

@ -1,5 +1,5 @@
/*
* xed-file-browser-widget.h - Xed plugin providing easy file access
* xed-file-browser-widget.h - Xed plugin providing easy file access
* from the sidepanel
*
* Copyright (C) 2006 - Jesse van den Kieboom <jesse@icecrew.nl>
@ -28,13 +28,13 @@
#include "xed-file-browser-view.h"
G_BEGIN_DECLS
#define XED_TYPE_FILE_BROWSER_WIDGET (xed_file_browser_widget_get_type ())
#define XED_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget))
#define XED_FILE_BROWSER_WIDGET_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget const))
#define XED_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass))
#define XED_IS_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_WIDGET))
#define XED_IS_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_WIDGET))
#define XED_FILE_BROWSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass))
#define XED_TYPE_FILE_BROWSER_WIDGET (xed_file_browser_widget_get_type ())
#define XED_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget))
#define XED_FILE_BROWSER_WIDGET_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidget const))
#define XED_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass))
#define XED_IS_FILE_BROWSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_FILE_BROWSER_WIDGET))
#define XED_IS_FILE_BROWSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_BROWSER_WIDGET))
#define XED_FILE_BROWSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_BROWSER_WIDGET, XedFileBrowserWidgetClass))
typedef struct _XedFileBrowserWidget XedFileBrowserWidget;
typedef struct _XedFileBrowserWidgetClass XedFileBrowserWidgetClass;
@ -42,36 +42,36 @@ typedef struct _XedFileBrowserWidgetPrivate XedFileBrowserWidgetPrivate;
typedef
gboolean (*XedFileBrowserWidgetFilterFunc) (XedFileBrowserWidget * obj,
XedFileBrowserStore *
model, GtkTreeIter * iter,
gpointer user_data);
XedFileBrowserStore *
model, GtkTreeIter * iter,
gpointer user_data);
struct _XedFileBrowserWidget
struct _XedFileBrowserWidget
{
GtkBox parent;
GtkBox parent;
XedFileBrowserWidgetPrivate *priv;
XedFileBrowserWidgetPrivate *priv;
};
struct _XedFileBrowserWidgetClass
struct _XedFileBrowserWidgetClass
{
GtkBoxClass parent_class;
GtkBoxClass parent_class;
/* Signals */
void (*uri_activated) (XedFileBrowserWidget * widget,
gchar const *uri);
void (*error) (XedFileBrowserWidget * widget,
guint code,
gchar const *message);
gboolean (*confirm_delete) (XedFileBrowserWidget * widget,
XedFileBrowserStore * model,
GList *list);
gboolean (*confirm_no_trash) (XedFileBrowserWidget * widget,
GList *list);
/* Signals */
void (*uri_activated) (XedFileBrowserWidget * widget,
gchar const *uri);
void (*error) (XedFileBrowserWidget * widget,
guint code,
gchar const *message);
gboolean (*confirm_delete) (XedFileBrowserWidget * widget,
XedFileBrowserStore * model,
GList *list);
gboolean (*confirm_no_trash) (XedFileBrowserWidget * widget,
GList *list);
};
GType xed_file_browser_widget_get_type (void) G_GNUC_CONST;
GType xed_file_browser_widget_register_type (GTypeModule * module);
void _xed_file_browser_widget_register_type (GTypeModule * module);
GtkWidget *xed_file_browser_widget_new (const gchar *data_dir);
@ -83,27 +83,27 @@ void xed_file_browser_widget_set_root (XedFileBrowserWidget * obj,
gboolean virtual_root);
void
xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget * obj,
gchar const *root,
gchar const *virtual_root);
gchar const *root,
gchar const *virtual_root);
gboolean
xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj,
xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj,
GtkTreeIter * iter);
XedFileBrowserStore *
XedFileBrowserStore *
xed_file_browser_widget_get_browser_store (XedFileBrowserWidget * obj);
XedFileBookmarksStore *
XedFileBookmarksStore *
xed_file_browser_widget_get_bookmarks_store (XedFileBrowserWidget * obj);
XedFileBrowserView *
xed_file_browser_widget_get_browser_view (XedFileBrowserWidget * obj);
GtkWidget *
xed_file_browser_widget_get_filter_entry (XedFileBrowserWidget * obj);
GtkUIManager *
GtkUIManager *
xed_file_browser_widget_get_ui_manager (XedFileBrowserWidget * obj);
gulong xed_file_browser_widget_add_filter (XedFileBrowserWidget * obj,
XedFileBrowserWidgetFilterFunc func,
XedFileBrowserWidgetFilterFunc func,
gpointer user_data,
GDestroyNotify notify);
void xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj,
@ -111,9 +111,9 @@ void xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj,
void xed_file_browser_widget_set_filter_pattern (XedFileBrowserWidget * obj,
gchar const *pattern);
void xed_file_browser_widget_refresh (XedFileBrowserWidget * obj);
void xed_file_browser_widget_history_back (XedFileBrowserWidget * obj);
void xed_file_browser_widget_history_forward (XedFileBrowserWidget * obj);
void xed_file_browser_widget_refresh (XedFileBrowserWidget * obj);
void xed_file_browser_widget_history_back (XedFileBrowserWidget * obj);
void xed_file_browser_widget_history_forward (XedFileBrowserWidget * obj);
G_END_DECLS
#endif /* __XED_FILE_BROWSER_WIDGET_H__ */