Add new (App/Window/View)Activatable interfaces for plugins

Currently only the modelines and filebrowser plugins are updated to these new
interfaces
This commit is contained in:
JosephMcc 2017-01-09 11:57:48 -08:00
parent d45e07b7a1
commit b9e5097250
26 changed files with 5361 additions and 4484 deletions

View File

@ -1,7 +1,7 @@
usr/share/appdata usr/share/appdata
usr/share/xed/plugins
usr/share/glib-2.0 usr/share/glib-2.0
usr/share/help usr/share/help
usr/share/locale usr/share/locale
usr/share/xed/icons usr/share/xed/icons
usr/share/xed/plugins
usr/share/xed/ui/ usr/share/xed/ui/

3
debian/xed.install vendored
View File

@ -1,8 +1,7 @@
usr/bin/xed usr/bin/xed
usr/lib/*/xed/plugins/*.plugin
usr/lib/*/xed/girepository-1.0/ usr/lib/*/xed/girepository-1.0/
usr/lib/xed/xed-bugreport.sh
usr/lib/*/xed/plugins/*.plugin usr/lib/*/xed/plugins/*.plugin
usr/lib/*/xed/plugins/*.so usr/lib/*/xed/plugins/*.so
usr/lib/xed/xed-bugreport.sh
usr/share/applications/xed.desktop usr/share/applications/xed.desktop
usr/share/man/ usr/share/man/

View File

@ -1,26 +1,9 @@
DIST_SUBDIRS = \ DIST_SUBDIRS = \
changecase \
docinfo \
filebrowser \ filebrowser \
modelines \ modelines
sort \
spell \
taglist \
time \
trailsave
SUBDIRS = \ SUBDIRS = \
changecase \
docinfo \
filebrowser \ filebrowser \
modelines \ modelines
sort \
taglist \
time \
trailsave
if ENABLE_ENCHANT
SUBDIRS += spell
endif
-include $(top_srcdir)/git.mk -include $(top_srcdir)/git.mk

View File

@ -77,7 +77,7 @@ struct _XedFileBookmarksStoreClass
}; };
GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST; GType xed_file_bookmarks_store_get_type (void) G_GNUC_CONST;
void _xed_file_bookmarks_store_register_type (GTypeModule * module); void _xed_file_bookmarks_store_register_type (GTypeModule *type_module);
XedFileBookmarksStore *xed_file_bookmarks_store_new (void); XedFileBookmarksStore *xed_file_bookmarks_store_new (void);
gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model, gchar *xed_file_bookmarks_store_get_uri (XedFileBookmarksStore * model,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -81,8 +81,7 @@ typedef struct _XedFileBrowserStore XedFileBrowserStore;
typedef struct _XedFileBrowserStoreClass XedFileBrowserStoreClass; typedef struct _XedFileBrowserStoreClass XedFileBrowserStoreClass;
typedef struct _XedFileBrowserStorePrivate XedFileBrowserStorePrivate; typedef struct _XedFileBrowserStorePrivate XedFileBrowserStorePrivate;
typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore typedef gboolean (*XedFileBrowserStoreFilterFunc) (XedFileBrowserStore *model,
* model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer user_data); gpointer user_data);
@ -116,30 +115,23 @@ struct _XedFileBrowserStoreClass {
}; };
GType xed_file_browser_store_get_type (void) G_GNUC_CONST; GType xed_file_browser_store_get_type (void) G_GNUC_CONST;
void _xed_file_browser_store_register_type (GTypeModule * module); void _xed_file_browser_store_register_type (GTypeModule *type_module);
XedFileBrowserStore *xed_file_browser_store_new (gchar const *root); XedFileBrowserStore *xed_file_browser_store_new (gchar const *root);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore *model,
xed_file_browser_store_set_root_and_virtual_root (XedFileBrowserStore * model,
gchar const *root, gchar const *root,
gchar const *virtual_root); gchar const *virtual_root);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_set_root (XedFileBrowserStore *model,
xed_file_browser_store_set_root (XedFileBrowserStore * model,
gchar const *root); gchar const *root);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root (XedFileBrowserStore *model,
xed_file_browser_store_set_virtual_root (XedFileBrowserStore * model,
GtkTreeIter *iter); GtkTreeIter *iter);
XedFileBrowserStoreResult 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); gchar const *root);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore *model);
xed_file_browser_store_set_virtual_root_up (XedFileBrowserStore * model); XedFileBrowserStoreResult xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore *model);
XedFileBrowserStoreResult
xed_file_browser_store_set_virtual_root_top (XedFileBrowserStore * model);
gboolean gboolean xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore *model,
xed_file_browser_store_get_iter_virtual_root (XedFileBrowserStore * model,
GtkTreeIter *iter); GtkTreeIter *iter);
gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore *model, gboolean xed_file_browser_store_get_iter_root (XedFileBrowserStore *model,
GtkTreeIter *iter); GtkTreeIter *iter);
@ -160,28 +152,24 @@ void _xed_file_browser_store_iter_expanded (XedFileBrowserStore * model
void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore *model, void _xed_file_browser_store_iter_collapsed (XedFileBrowserStore *model,
GtkTreeIter *iter); GtkTreeIter *iter);
XedFileBrowserStoreFilterMode XedFileBrowserStoreFilterMode xed_file_browser_store_get_filter_mode (XedFileBrowserStore *model);
xed_file_browser_store_get_filter_mode (XedFileBrowserStore * model);
void xed_file_browser_store_set_filter_mode (XedFileBrowserStore *model, void xed_file_browser_store_set_filter_mode (XedFileBrowserStore *model,
XedFileBrowserStoreFilterMode mode); XedFileBrowserStoreFilterMode mode);
void xed_file_browser_store_set_filter_func (XedFileBrowserStore *model, void xed_file_browser_store_set_filter_func (XedFileBrowserStore *model,
XedFileBrowserStoreFilterFunc func, XedFileBrowserStoreFilterFunc func,
gpointer user_data); gpointer user_data);
void xed_file_browser_store_refilter (XedFileBrowserStore *model); void xed_file_browser_store_refilter (XedFileBrowserStore *model);
XedFileBrowserStoreFilterMode XedFileBrowserStoreFilterMode xed_file_browser_store_filter_mode_get_default (void);
xed_file_browser_store_filter_mode_get_default (void);
void xed_file_browser_store_refresh (XedFileBrowserStore * model); void xed_file_browser_store_refresh (XedFileBrowserStore * model);
gboolean xed_file_browser_store_rename (XedFileBrowserStore *model, gboolean xed_file_browser_store_rename (XedFileBrowserStore *model,
GtkTreeIter *iter, GtkTreeIter *iter,
gchar const *new_name, gchar const *new_name,
GError **error); GError **error);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_delete (XedFileBrowserStore *model,
xed_file_browser_store_delete (XedFileBrowserStore * model,
GtkTreeIter *iter, GtkTreeIter *iter,
gboolean trash); gboolean trash);
XedFileBrowserStoreResult XedFileBrowserStoreResult xed_file_browser_store_delete_all (XedFileBrowserStore *model,
xed_file_browser_store_delete_all (XedFileBrowserStore * model,
GList *rows, GList *rows,
gboolean trash); gboolean trash);

View File

@ -20,6 +20,7 @@
*/ */
#include <string.h> #include <string.h>
#include <glib-object.h>
#include <gio/gio.h> #include <gio/gio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
@ -85,8 +86,7 @@ static const GtkTargetEntry drag_source_targets[] = {
{ "text/uri-list", 0, 0 } { "text/uri-list", 0, 0 }
}; };
G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view, G_DEFINE_DYNAMIC_TYPE (XedFileBrowserView, xed_file_browser_view, GTK_TYPE_TREE_VIEW)
GTK_TYPE_TREE_VIEW)
static void on_cell_edited (GtkCellRendererText *cell, static void on_cell_edited (GtkCellRendererText *cell,
gchar *path, gchar *path,
@ -113,10 +113,14 @@ xed_file_browser_view_finalize (GObject * object)
XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object); XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW(object);
if (obj->priv->hand_cursor) if (obj->priv->hand_cursor)
{
g_object_unref (obj->priv->hand_cursor); g_object_unref (obj->priv->hand_cursor);
}
if (obj->priv->hover_path) if (obj->priv->hover_path)
{
gtk_tree_path_free (obj->priv->hover_path); gtk_tree_path_free (obj->priv->hover_path);
}
if (obj->priv->expand_state) if (obj->priv->expand_state)
{ {
@ -126,8 +130,7 @@ xed_file_browser_view_finalize (GObject * object)
g_object_unref (obj->priv->busy_cursor); g_object_unref (obj->priv->busy_cursor);
G_OBJECT_CLASS (xed_file_browser_view_parent_class)-> G_OBJECT_CLASS (xed_file_browser_view_parent_class)->finalize (object);
finalize (object);
} }
static void static void
@ -137,15 +140,21 @@ add_expand_state (XedFileBrowserView * view,
GFile * file; GFile * file;
if (!uri) if (!uri)
{
return; return;
}
file = g_file_new_for_uri (uri); file = g_file_new_for_uri (uri);
if (view->priv->expand_state) if (view->priv->expand_state)
{
g_hash_table_insert (view->priv->expand_state, file, file); g_hash_table_insert (view->priv->expand_state, file, file);
}
else else
{
g_object_unref (file); g_object_unref (file);
} }
}
static void static void
remove_expand_state (XedFileBrowserView *view, remove_expand_state (XedFileBrowserView *view,
@ -154,12 +163,16 @@ remove_expand_state (XedFileBrowserView * view,
GFile * file; GFile * file;
if (!uri) if (!uri)
{
return; return;
}
file = g_file_new_for_uri (uri); file = g_file_new_for_uri (uri);
if (view->priv->expand_state) if (view->priv->expand_state)
{
g_hash_table_remove (view->priv->expand_state, file); g_hash_table_remove (view->priv->expand_state, file);
}
g_object_unref (file); g_object_unref (file);
} }
@ -173,25 +186,24 @@ row_expanded (GtkTreeView * tree_view,
gchar *uri; gchar *uri;
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)
{
GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded (tree_view, iter, path); GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded (tree_view, iter, path);
}
if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) if (!XED_IS_FILE_BROWSER_STORE (view->priv->model))
{
return; return;
}
if (view->priv->restore_expand_state) if (view->priv->restore_expand_state)
{ {
gtk_tree_model_get (view->priv->model, gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1);
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
add_expand_state (view, uri); add_expand_state (view, uri);
g_free (uri); g_free (uri);
} }
_xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter);
iter);
} }
static void static void
@ -203,25 +215,24 @@ row_collapsed (GtkTreeView * tree_view,
gchar * uri; gchar * uri;
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)
{
GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed (tree_view, iter, path); GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed (tree_view, iter, path);
}
if (!XED_IS_FILE_BROWSER_STORE (view->priv->model)) if (!XED_IS_FILE_BROWSER_STORE (view->priv->model))
{
return; return;
}
if (view->priv->restore_expand_state) if (view->priv->restore_expand_state)
{ {
gtk_tree_model_get (view->priv->model, gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_URI, &uri, -1);
iter,
XED_FILE_BROWSER_STORE_COLUMN_URI,
&uri,
-1);
remove_expand_state (view, uri); remove_expand_state (view, uri);
g_free (uri); g_free (uri);
} }
_xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter);
iter);
} }
static gboolean static gboolean
@ -231,7 +242,8 @@ leave_notify_event (GtkWidget *widget,
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget);
if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE && if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE &&
view->priv->hover_path != NULL) { view->priv->hover_path != NULL)
{
gtk_tree_path_free (view->priv->hover_path); gtk_tree_path_free (view->priv->hover_path);
view->priv->hover_path = NULL; view->priv->hover_path = NULL;
} }
@ -246,9 +258,12 @@ enter_notify_event (GtkWidget *widget,
{ {
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget);
if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE)
{
if (view->priv->hover_path != NULL) if (view->priv->hover_path != NULL)
{
gtk_tree_path_free (view->priv->hover_path); gtk_tree_path_free (view->priv->hover_path);
}
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
event->x, event->y, event->x, event->y,
@ -256,8 +271,9 @@ enter_notify_event (GtkWidget *widget,
NULL, NULL, NULL); NULL, NULL, NULL);
if (view->priv->hover_path != NULL) if (view->priv->hover_path != NULL)
gdk_window_set_cursor (gtk_widget_get_window (widget), {
view->priv->hand_cursor); gdk_window_set_cursor (gtk_widget_get_window (widget), view->priv->hand_cursor);
}
} }
// Chainup // Chainup
@ -271,25 +287,31 @@ motion_notify_event (GtkWidget * widget,
GtkTreePath *old_hover_path; GtkTreePath *old_hover_path;
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget);
if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { if (view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE)
{
old_hover_path = view->priv->hover_path; old_hover_path = view->priv->hover_path;
gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget), gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
event->x, event->y, event->x, event->y,
&view->priv->hover_path, &view->priv->hover_path,
NULL, NULL, NULL); NULL, NULL, NULL);
if ((old_hover_path != NULL) != (view->priv->hover_path != NULL)) { if ((old_hover_path != NULL) != (view->priv->hover_path != NULL))
{
if (view->priv->hover_path != NULL) if (view->priv->hover_path != NULL)
gdk_window_set_cursor (gtk_widget_get_window (widget), {
view->priv->hand_cursor); gdk_window_set_cursor (gtk_widget_get_window (widget), view->priv->hand_cursor);
}
else else
gdk_window_set_cursor (gtk_widget_get_window (widget), {
NULL); gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
}
} }
if (old_hover_path != NULL) if (old_hover_path != NULL)
{
gtk_tree_path_free (old_hover_path); gtk_tree_path_free (old_hover_path);
} }
}
// Chainup // Chainup
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event); return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->motion_notify_event (widget, event);
@ -305,31 +327,41 @@ set_click_policy_property (XedFileBrowserView *obj,
obj->priv->click_policy = click_policy; obj->priv->click_policy = click_policy;
if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE)
{
if (obj->priv->hand_cursor == NULL) if (obj->priv->hand_cursor == NULL)
{
obj->priv->hand_cursor = gdk_cursor_new(GDK_HAND2); obj->priv->hand_cursor = gdk_cursor_new(GDK_HAND2);
} else if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE) { }
if (obj->priv->hover_path != NULL) { }
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (obj->priv->model), else if (click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE)
&iter, obj->priv->hover_path)) {
gtk_tree_model_row_changed (GTK_TREE_MODEL (obj->priv->model), if (obj->priv->hover_path != NULL)
obj->priv->hover_path, &iter); {
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (obj->priv->model), &iter, obj->priv->hover_path))
{
gtk_tree_model_row_changed (GTK_TREE_MODEL (obj->priv->model), obj->priv->hover_path, &iter);
}
gtk_tree_path_free (obj->priv->hover_path); gtk_tree_path_free (obj->priv->hover_path);
obj->priv->hover_path = NULL; obj->priv->hover_path = NULL;
} }
if (gtk_widget_get_realized (GTK_WIDGET (obj))) { if (gtk_widget_get_realized (GTK_WIDGET (obj)))
{
win = gtk_widget_get_window (GTK_WIDGET (obj)); win = gtk_widget_get_window (GTK_WIDGET (obj));
gdk_window_set_cursor (win, NULL); gdk_window_set_cursor (win, NULL);
display = gtk_widget_get_display (GTK_WIDGET (obj)); display = gtk_widget_get_display (GTK_WIDGET (obj));
if (display != NULL) if (display != NULL)
{
gdk_display_flush (display); gdk_display_flush (display);
} }
}
if (obj->priv->hand_cursor) { if (obj->priv->hand_cursor)
{
g_object_unref (obj->priv->hand_cursor); g_object_unref (obj->priv->hand_cursor);
obj->priv->hand_cursor = NULL; obj->priv->hand_cursor = NULL;
} }
@ -344,7 +376,8 @@ directory_activated (XedFileBrowserView *view,
} }
static void static void
activate_selected_files (XedFileBrowserView *view) { activate_selected_files (XedFileBrowserView *view)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (view); GtkTreeView *tree_view = GTK_TREE_VIEW (view);
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
GList *rows, *row; GList *rows, *row;
@ -355,51 +388,69 @@ activate_selected_files (XedFileBrowserView *view) {
rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model); rows = gtk_tree_selection_get_selected_rows (selection, &view->priv->model);
for (row = rows; row; row = row->next) { for (row = rows; row; row = row->next)
{
path = (GtkTreePath *)(row->data); path = (GtkTreePath *)(row->data);
/* Get iter from path */ /* Get iter from path */
if (!gtk_tree_model_get_iter (view->priv->model, &iter, path)) if (!gtk_tree_model_get_iter (view->priv->model, &iter, path))
{
continue; continue;
}
gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); gtk_tree_model_get (view->priv->model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1);
if (FILE_IS_DIR (flags)) { if (FILE_IS_DIR (flags))
{
if (directory == NULL) if (directory == NULL)
{
directory = path; directory = path;
}
} else if (!FILE_IS_DUMMY (flags)) { }
else if (!FILE_IS_DUMMY (flags))
{
g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter); g_signal_emit (view, signals[FILE_ACTIVATED], 0, &iter);
} }
} }
if (directory != NULL) { if (directory != NULL)
{
if (gtk_tree_model_get_iter (view->priv->model, &iter, directory)) if (gtk_tree_model_get_iter (view->priv->model, &iter, directory))
{
g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter); g_signal_emit (view, signals[DIRECTORY_ACTIVATED], 0, &iter);
} }
}
g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL);
g_list_free (rows); g_list_free (rows);
} }
static void static void
activate_selected_bookmark (XedFileBrowserView *view) { activate_selected_bookmark (XedFileBrowserView *view)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (view); GtkTreeView *tree_view = GTK_TREE_VIEW (view);
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
GtkTreeIter iter; GtkTreeIter iter;
if (gtk_tree_selection_get_selected (selection, &view->priv->model, &iter)) if (gtk_tree_selection_get_selected (selection, &view->priv->model, &iter))
{
g_signal_emit (view, signals[BOOKMARK_ACTIVATED], 0, &iter); g_signal_emit (view, signals[BOOKMARK_ACTIVATED], 0, &iter);
} }
}
static void static void
activate_selected_items (XedFileBrowserView *view) activate_selected_items (XedFileBrowserView *view)
{ {
if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) if (XED_IS_FILE_BROWSER_STORE (view->priv->model))
{
activate_selected_files (view); activate_selected_files (view);
}
else if (XED_IS_FILE_BOOKMARKS_STORE (view->priv->model)) else if (XED_IS_FILE_BOOKMARKS_STORE (view->priv->model))
{
activate_selected_bookmark (view); activate_selected_bookmark (view);
} }
}
static void static void
toggle_hidden_filter (XedFileBrowserView *view) toggle_hidden_filter (XedFileBrowserView *view)
@ -408,11 +459,9 @@ toggle_hidden_filter (XedFileBrowserView *view)
if (XED_IS_FILE_BROWSER_STORE (view->priv->model)) if (XED_IS_FILE_BROWSER_STORE (view->priv->model))
{ {
mode = xed_file_browser_store_get_filter_mode mode = xed_file_browser_store_get_filter_mode (XED_FILE_BROWSER_STORE (view->priv->model));
(XED_FILE_BROWSER_STORE (view->priv->model));
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 xed_file_browser_store_set_filter_mode (XED_FILE_BROWSER_STORE (view->priv->model), mode);
(XED_FILE_BROWSER_STORE (view->priv->model), mode);
} }
} }
@ -446,21 +495,27 @@ did_not_drag (XedFileBrowserView *view,
tree_view = GTK_TREE_VIEW (view); tree_view = GTK_TREE_VIEW (view);
selection = gtk_tree_view_get_selection (tree_view); selection = gtk_tree_view_get_selection (tree_view);
if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL))
&path, NULL, NULL, NULL)) { {
if ((view->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) 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)) { && (event->button == 1 || event->button == 2))
{
/* Activate all selected items, and leave them selected */ /* Activate all selected items, and leave them selected */
activate_selected_items (view); activate_selected_items (view);
} else if ((event->button == 1 || event->button == 2) }
else if ((event->button == 1 || event->button == 2)
&& ((event->state & GDK_CONTROL_MASK) != 0 || && ((event->state & GDK_CONTROL_MASK) != 0 ||
(event->state & GDK_SHIFT_MASK) == 0) (event->state & GDK_SHIFT_MASK) == 0)
&& view->priv->selected_on_button_down) { && view->priv->selected_on_button_down)
if (!button_event_modifies_selection (event)) { {
if (!button_event_modifies_selection (event))
{
gtk_tree_selection_unselect_all (selection); gtk_tree_selection_unselect_all (selection);
gtk_tree_selection_select_path (selection, path); gtk_tree_selection_select_path (selection, path);
} else { }
else
{
gtk_tree_selection_unselect_path (selection, path); gtk_tree_selection_unselect_path (selection, path);
} }
} }
@ -475,13 +530,15 @@ button_release_event (GtkWidget *widget,
{ {
XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget); XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (widget);
if (event->button == view->priv->drag_button) { if (event->button == view->priv->drag_button)
{
view->priv->drag_button = 0; view->priv->drag_button = 0;
if (!view->priv->drag_started && if (!view->priv->drag_started && !view->priv->ignore_release)
!view->priv->ignore_release) {
did_not_drag (view, event); did_not_drag (view, event);
} }
}
/* Chain up */ /* 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);
@ -516,42 +573,53 @@ button_press_event (GtkWidget *widget,
/* Determine click count */ /* Determine click count */
if (event->time - last_click_time < double_click_time) if (event->time - last_click_time < double_click_time)
{
click_count++; click_count++;
}
else else
{
click_count = 0; click_count = 0;
}
last_click_time = event->time; last_click_time = event->time;
/* Ignore double click if we are in single click mode */ /* 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)
click_count >= 2) { {
return TRUE; return TRUE;
} }
view->priv->ignore_release = FALSE; view->priv->ignore_release = FALSE;
call_parent = TRUE; call_parent = TRUE;
if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y, &path, NULL, NULL, NULL))
&path, NULL, NULL, NULL)) { {
/* Keep track of path of last click so double clicks only happen /* Keep track of path of last click so double clicks only happen
* on the same item */ * on the same item */
if ((event->button == 1 || event->button == 2) && if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS)
event->type == GDK_BUTTON_PRESS) { {
if (view->priv->double_click_path[1]) if (view->priv->double_click_path[1])
{
gtk_tree_path_free (view->priv->double_click_path[1]); gtk_tree_path_free (view->priv->double_click_path[1]);
}
view->priv->double_click_path[1] = view->priv->double_click_path[0]; view->priv->double_click_path[1] = view->priv->double_click_path[0];
view->priv->double_click_path[0] = gtk_tree_path_copy (path); view->priv->double_click_path[0] = gtk_tree_path_copy (path);
} }
if (event->type == GDK_2BUTTON_PRESS) { if (event->type == GDK_2BUTTON_PRESS)
{
if (view->priv->double_click_path[1] && if (view->priv->double_click_path[1] &&
gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0) gtk_tree_path_compare (view->priv->double_click_path[0], view->priv->double_click_path[1]) == 0)
{
activate_selected_items (view); activate_selected_items (view);
}
/* Chain up */ /* Chain up */
widget_parent->button_press_event (widget, event); widget_parent->button_press_event (widget, event);
} else { }
else
{
/* We're going to filter out some situations where /* We're going to filter out some situations where
* we can't let the default code run because all * we can't let the default code run because all
* but one row would be would be deselected. We don't * but one row would be would be deselected. We don't
@ -560,51 +628,66 @@ button_press_event (GtkWidget *widget,
selected = gtk_tree_selection_path_is_selected (selection, path); selected = gtk_tree_selection_path_is_selected (selection, path);
if (event->button == 3 && selected) if (event->button == 3 && selected)
{
call_parent = FALSE; call_parent = FALSE;
}
if ((event->button == 1 || event->button == 2) && if ((event->button == 1 || event->button == 2) &&
((event->state & GDK_CONTROL_MASK) != 0 || ((event->state & GDK_CONTROL_MASK) != 0 ||
(event->state & GDK_SHIFT_MASK) == 0)) { (event->state & GDK_SHIFT_MASK) == 0))
{
gtk_widget_style_get (widget, gtk_widget_style_get (widget,
"expander-size", &expander_size, "expander-size", &expander_size,
"horizontal-separator", &horizontal_separator, "horizontal-separator", &horizontal_separator,
NULL); NULL);
on_expander = (event->x <= horizontal_separator / 2 + on_expander = (event->x <= horizontal_separator / 2 + gtk_tree_path_get_depth (path) * expander_size);
gtk_tree_path_get_depth (path) * expander_size);
view->priv->selected_on_button_down = selected; view->priv->selected_on_button_down = selected;
if (selected) { if (selected)
{
call_parent = on_expander || gtk_tree_selection_count_selected_rows (selection) == 1; call_parent = on_expander || gtk_tree_selection_count_selected_rows (selection) == 1;
view->priv->ignore_release = call_parent && view->priv->click_policy != XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE; view->priv->ignore_release = call_parent && view->priv->click_policy != XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE;
} else if ((event->state & GDK_CONTROL_MASK) != 0) { }
else if ((event->state & GDK_CONTROL_MASK) != 0)
{
call_parent = FALSE; call_parent = FALSE;
gtk_tree_selection_select_path (selection, path); gtk_tree_selection_select_path (selection, path);
} else { }
else
{
view->priv->ignore_release = on_expander; view->priv->ignore_release = on_expander;
} }
} }
if (call_parent) { if (call_parent)
{
/* Chain up */ /* Chain up */
widget_parent->button_press_event (widget, event); widget_parent->button_press_event (widget, event);
} else if (selected) { }
else if (selected)
{
gtk_widget_grab_focus (widget); gtk_widget_grab_focus (widget);
} }
if ((event->button == 1 || event->button == 2) && if ((event->button == 1 || event->button == 2) &&
event->type == GDK_BUTTON_PRESS) { event->type == GDK_BUTTON_PRESS)
{
view->priv->drag_started = FALSE; view->priv->drag_started = FALSE;
view->priv->drag_button = event->button; view->priv->drag_button = event->button;
} }
} }
gtk_tree_path_free (path); gtk_tree_path_free (path);
} else { }
if ((event->button == 1 || event->button == 2) && else
event->type == GDK_BUTTON_PRESS) { {
if ((event->button == 1 || event->button == 2) && event->type == GDK_BUTTON_PRESS)
{
if (view->priv->double_click_path[1]) if (view->priv->double_click_path[1])
{
gtk_tree_path_free (view->priv->double_click_path[1]); gtk_tree_path_free (view->priv->double_click_path[1]);
}
view->priv->double_click_path[1] = view->priv->double_click_path[0]; view->priv->double_click_path[1] = view->priv->double_click_path[0];
view->priv->double_click_path[0] = NULL; view->priv->double_click_path[0] = NULL;
@ -632,13 +715,16 @@ key_press_event (GtkWidget *widget,
modifiers = gtk_accelerator_get_default_mod_mask (); modifiers = gtk_accelerator_get_default_mod_mask ();
switch (event->keyval) { switch (event->keyval)
{
case GDK_KEY_space: case GDK_KEY_space:
if (event->state & GDK_CONTROL_MASK) { if (event->state & GDK_CONTROL_MASK)
{
handled = FALSE; handled = FALSE;
break; break;
} }
if (!gtk_widget_has_focus (widget)) { if (!gtk_widget_has_focus (widget))
{
handled = FALSE; handled = FALSE;
break; break;
} }
@ -654,7 +740,8 @@ key_press_event (GtkWidget *widget,
break; break;
case GDK_KEY_h: case GDK_KEY_h:
if ((event->state & modifiers) == GDK_CONTROL_MASK) { if ((event->state & modifiers) == GDK_CONTROL_MASK)
{
toggle_hidden_filter (view); toggle_hidden_filter (view);
handled = TRUE; handled = TRUE;
break; break;
@ -666,20 +753,25 @@ key_press_event (GtkWidget *widget,
/* Chain up */ /* Chain up */
if (!handled) if (!handled)
{
return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event); return GTK_WIDGET_CLASS (xed_file_browser_view_parent_class)->key_press_event (widget, event);
}
return TRUE; return TRUE;
} }
static void static void
fill_expand_state (XedFileBrowserView * view, GtkTreeIter * iter) fill_expand_state (XedFileBrowserView *view,
GtkTreeIter *iter)
{ {
GtkTreePath * path; GtkTreePath * path;
GtkTreeIter child; GtkTreeIter child;
gchar * uri; gchar * uri;
if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) if (!gtk_tree_model_iter_has_child (view->priv->model, iter))
{
return; return;
}
path = gtk_tree_model_get_path (view->priv->model, iter); path = gtk_tree_model_get_path (view->priv->model, iter);
@ -697,7 +789,8 @@ fill_expand_state (XedFileBrowserView * view, GtkTreeIter * iter)
if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) if (gtk_tree_model_iter_children (view->priv->model, &child, iter))
{ {
do { do
{
fill_expand_state (view, &child); fill_expand_state (view, &child);
} while (gtk_tree_model_iter_next (view->priv->model, &child)); } while (gtk_tree_model_iter_next (view->priv->model, &child));
} }
@ -709,46 +802,24 @@ static void
uninstall_restore_signals (XedFileBrowserView *tree_view, uninstall_restore_signals (XedFileBrowserView *tree_view,
GtkTreeModel *model) GtkTreeModel *model)
{ {
g_signal_handlers_disconnect_by_func (model, g_signal_handlers_disconnect_by_func (model, on_begin_refresh, tree_view);
on_begin_refresh, g_signal_handlers_disconnect_by_func (model, on_end_refresh, tree_view);
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);
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);
} }
static void static void
install_restore_signals (XedFileBrowserView *tree_view, install_restore_signals (XedFileBrowserView *tree_view,
GtkTreeModel *model) GtkTreeModel *model)
{ {
g_signal_connect (model, g_signal_connect (model, "begin-refresh",
"begin-refresh", G_CALLBACK (on_begin_refresh), tree_view);
G_CALLBACK (on_begin_refresh), g_signal_connect (model, "end-refresh",
tree_view); G_CALLBACK (on_end_refresh), tree_view);
g_signal_connect (model, "unload",
g_signal_connect (model, G_CALLBACK (on_unload), tree_view);
"end-refresh", g_signal_connect_after (model, "row-inserted",
G_CALLBACK (on_end_refresh), G_CALLBACK (on_row_inserted), tree_view);
tree_view);
g_signal_connect (model,
"unload",
G_CALLBACK (on_unload),
tree_view);
g_signal_connect_after (model,
"row-inserted",
G_CALLBACK (on_row_inserted),
tree_view);
} }
static void static void
@ -756,7 +827,9 @@ set_restore_expand_state (XedFileBrowserView * view,
gboolean state) gboolean state)
{ {
if (state == view->priv->restore_expand_state) if (state == view->priv->restore_expand_state)
{
return; return;
}
if (view->priv->expand_state) if (view->priv->expand_state)
{ {
@ -905,8 +978,7 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass * klass)
g_cclosure_marshal_VOID__BOXED, g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER); G_TYPE_NONE, 1, GTK_TYPE_TREE_ITER);
g_type_class_add_private (object_class, g_type_class_add_private (object_class, sizeof (XedFileBrowserViewPrivate));
sizeof (XedFileBrowserViewPrivate));
} }
static void static void
@ -916,8 +988,10 @@ xed_file_browser_view_class_finalize (XedFileBrowserViewClass *klass)
} }
static void static void
cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell, cell_data_cb (GtkTreeViewColumn *tree_column,
GtkTreeModel * tree_model, GtkTreeIter * iter, GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
XedFileBrowserView *obj) XedFileBrowserView *obj)
{ {
GtkTreePath *path; GtkTreePath *path;
@ -926,16 +1000,17 @@ cell_data_cb (GtkTreeViewColumn * tree_column, GtkCellRenderer * cell,
path = gtk_tree_model_get_path (tree_model, iter); path = gtk_tree_model_get_path (tree_model, iter);
if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE) { if (obj->priv->click_policy == XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE)
if (obj->priv->hover_path != NULL && {
gtk_tree_path_compare (path, obj->priv->hover_path) == 0) 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 (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))
gtk_tree_row_reference_valid (obj->priv->editable))
{ {
GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable); GtkTreePath *edpath = gtk_tree_row_reference_get_path (obj->priv->editable);
@ -955,17 +1030,14 @@ xed_file_browser_view_init (XedFileBrowserView * obj)
obj->priv->column = gtk_tree_view_column_new (); obj->priv->column = gtk_tree_view_column_new ();
obj->priv->pixbuf_renderer = gtk_cell_renderer_pixbuf_new (); obj->priv->pixbuf_renderer = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (obj->priv->column, gtk_tree_view_column_pack_start (obj->priv->column, obj->priv->pixbuf_renderer, FALSE);
obj->priv->pixbuf_renderer,
FALSE);
gtk_tree_view_column_add_attribute (obj->priv->column, gtk_tree_view_column_add_attribute (obj->priv->column,
obj->priv->pixbuf_renderer, obj->priv->pixbuf_renderer,
"pixbuf", "pixbuf",
XED_FILE_BROWSER_STORE_COLUMN_ICON); XED_FILE_BROWSER_STORE_COLUMN_ICON);
obj->priv->text_renderer = gtk_cell_renderer_text_new (); obj->priv->text_renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (obj->priv->column, gtk_tree_view_column_pack_start (obj->priv->column, obj->priv->text_renderer, TRUE);
obj->priv->text_renderer, TRUE);
gtk_tree_view_column_add_attribute (obj->priv->column, gtk_tree_view_column_add_attribute (obj->priv->column,
obj->priv->text_renderer, obj->priv->text_renderer,
"text", "text",
@ -974,8 +1046,7 @@ xed_file_browser_view_init (XedFileBrowserView * obj)
g_signal_connect (obj->priv->text_renderer, "edited", g_signal_connect (obj->priv->text_renderer, "edited",
G_CALLBACK (on_cell_edited), obj); G_CALLBACK (on_cell_edited), obj);
gtk_tree_view_append_column (GTK_TREE_VIEW (obj), gtk_tree_view_append_column (GTK_TREE_VIEW (obj), obj->priv->column);
obj->priv->column);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (obj), FALSE); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (obj), FALSE);
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj), gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (obj),
@ -988,14 +1059,13 @@ xed_file_browser_view_init (XedFileBrowserView * obj)
} }
static gboolean static gboolean
bookmarks_separator_func (GtkTreeModel * model, GtkTreeIter * iter, bookmarks_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data) gpointer user_data)
{ {
guint flags; guint flags;
gtk_tree_model_get (model, iter, gtk_tree_model_get (model, iter, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags, -1);
XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS,
&flags, -1);
return (flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR); return (flags & XED_FILE_BOOKMARKS_STORE_IS_SEPARATOR);
} }
@ -1004,9 +1074,7 @@ bookmarks_separator_func (GtkTreeModel * model, GtkTreeIter * iter,
GtkWidget * GtkWidget *
xed_file_browser_view_new (void) xed_file_browser_view_new (void)
{ {
XedFileBrowserView *obj = XedFileBrowserView *obj = XED_FILE_BROWSER_VIEW (g_object_new (XED_TYPE_FILE_BROWSER_VIEW, NULL));
XED_FILE_BROWSER_VIEW (g_object_new
(XED_TYPE_FILE_BROWSER_VIEW, NULL));
return GTK_WIDGET (obj); return GTK_WIDGET (obj);
} }
@ -1018,11 +1086,14 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
GtkTreeSelection *selection; GtkTreeSelection *selection;
if (tree_view->priv->model == model) if (tree_view->priv->model == model)
{
return; return;
}
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
if (XED_IS_FILE_BOOKMARKS_STORE (model)) { 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 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW
(tree_view), (tree_view),
@ -1035,7 +1106,9 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
(GtkTreeCellDataFunc) (GtkTreeCellDataFunc)
cell_data_cb, cell_data_cb,
tree_view, NULL); tree_view, NULL);
} else { }
else
{
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW
(tree_view), NULL, (tree_view), NULL,
@ -1049,19 +1122,24 @@ xed_file_browser_view_set_model (XedFileBrowserView * tree_view,
tree_view, NULL); tree_view, NULL);
if (tree_view->priv->restore_expand_state) if (tree_view->priv->restore_expand_state)
{
install_restore_signals (tree_view, model); install_restore_signals (tree_view, model);
}
} }
if (tree_view->priv->hover_path != NULL) { if (tree_view->priv->hover_path != NULL)
{
gtk_tree_path_free (tree_view->priv->hover_path); gtk_tree_path_free (tree_view->priv->hover_path);
tree_view->priv->hover_path = NULL; tree_view->priv->hover_path = NULL;
} }
if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model)) { if (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model))
{
if (tree_view->priv->restore_expand_state) if (tree_view->priv->restore_expand_state)
uninstall_restore_signals (tree_view, {
tree_view->priv->model); uninstall_restore_signals (tree_view, tree_view->priv->model);
}
} }
tree_view->priv->model = model; tree_view->priv->model = model;
@ -1077,16 +1155,15 @@ xed_file_browser_view_start_rename (XedFileBrowserView * tree_view,
GtkTreePath *path; GtkTreePath *path;
g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view)); g_return_if_fail (XED_IS_FILE_BROWSER_VIEW (tree_view));
g_return_if_fail (XED_IS_FILE_BROWSER_STORE g_return_if_fail (XED_IS_FILE_BROWSER_STORE (tree_view->priv->model));
(tree_view->priv->model));
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
gtk_tree_model_get (tree_view->priv->model, iter, gtk_tree_model_get (tree_view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1);
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1);
if (!(FILE_IS_DIR (flags) || !FILE_IS_DUMMY (flags))) if (!(FILE_IS_DIR (flags) || !FILE_IS_DUMMY (flags)))
{
return; return;
}
path = gtk_tree_model_get_path (tree_view->priv->model, iter); path = gtk_tree_model_get_path (tree_view->priv->model, iter);
rowref = gtk_tree_row_reference_new (tree_view->priv->model, path); rowref = gtk_tree_row_reference_new (tree_view->priv->model, path);
@ -1095,8 +1172,9 @@ xed_file_browser_view_start_rename (XedFileBrowserView * tree_view,
gtk_widget_grab_focus (GTK_WIDGET (tree_view)); gtk_widget_grab_focus (GTK_WIDGET (tree_view));
if (gtk_tree_path_up (path)) if (gtk_tree_path_up (path))
gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), {
path); gtk_tree_view_expand_to_path (GTK_TREE_VIEW (tree_view), path);
}
gtk_tree_path_free (path); gtk_tree_path_free (path);
tree_view->priv->editable = rowref; tree_view->priv->editable = rowref;
@ -1134,7 +1212,9 @@ xed_file_browser_view_set_restore_expand_state (XedFileBrowserView * tree_view,
/* Signal handlers */ /* Signal handlers */
static void static void
on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text, on_cell_edited (GtkCellRendererText *cell,
gchar *path,
gchar *new_text,
XedFileBrowserView *tree_view) XedFileBrowserView *tree_view)
{ {
GtkTreePath * treepath; GtkTreePath * treepath;
@ -1146,25 +1226,27 @@ on_cell_edited (GtkCellRendererText * cell, gchar * path, gchar * new_text,
tree_view->priv->editable = NULL; tree_view->priv->editable = NULL;
if (new_text == NULL || *new_text == '\0') if (new_text == NULL || *new_text == '\0')
{
return; return;
}
treepath = gtk_tree_path_new_from_string (path); treepath = gtk_tree_path_new_from_string (path);
ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath); ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->priv->model), &iter, treepath);
gtk_tree_path_free (treepath); gtk_tree_path_free (treepath);
if (ret) { if (ret)
if (xed_file_browser_store_rename (XED_FILE_BROWSER_STORE (tree_view->priv->model), {
&iter, new_text, &error)) { if (xed_file_browser_store_rename (XED_FILE_BROWSER_STORE (tree_view->priv->model), &iter, new_text, &error))
{
treepath = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_view->priv->model), &iter); treepath = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_view->priv->model), &iter);
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), treepath, NULL, FALSE, 0.0, 0.0);
treepath, NULL,
FALSE, 0.0, 0.0);
gtk_tree_path_free (treepath); gtk_tree_path_free (treepath);
} }
else { else
if (error) { {
g_signal_emit (tree_view, signals[ERROR], 0, if (error)
error->code, error->message); {
g_signal_emit (tree_view, signals[ERROR], 0, error->code, error->message);
g_error_free (error); g_error_free (error);
} }
} }
@ -1196,7 +1278,9 @@ on_unload (XedFileBrowserStore * model,
{ {
/* Don't remove the expand state if we are refreshing */ /* Don't remove the expand state if we are refreshing */
if (!view->priv->restore_expand_state || view->priv->is_refresh) if (!view->priv->restore_expand_state || view->priv->is_refresh)
{
return; return;
}
remove_expand_state (view, uri); remove_expand_state (view, uri);
} }
@ -1217,16 +1301,16 @@ restore_expand_state (XedFileBrowserView * view,
-1); -1);
if (!uri) if (!uri)
{
return; return;
}
file = g_file_new_for_uri (uri); file = g_file_new_for_uri (uri);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
if (g_hash_table_lookup (view->priv->expand_state, file)) if (g_hash_table_lookup (view->priv->expand_state, file))
{ {
gtk_tree_view_expand_row (GTK_TREE_VIEW (view), gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
path,
FALSE);
} }
gtk_tree_path_free (path); gtk_tree_path_free (path);
@ -1245,7 +1329,9 @@ on_row_inserted (XedFileBrowserStore * model,
GtkTreePath * copy; GtkTreePath * copy;
if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (model), iter)) if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL (model), iter))
{
restore_expand_state (view, model, iter); restore_expand_state (view, model, iter);
}
copy = gtk_tree_path_copy (path); copy = gtk_tree_path_copy (path);

View File

@ -37,7 +37,8 @@ typedef struct _XedFileBrowserView XedFileBrowserView;
typedef struct _XedFileBrowserViewClass XedFileBrowserViewClass; typedef struct _XedFileBrowserViewClass XedFileBrowserViewClass;
typedef struct _XedFileBrowserViewPrivate XedFileBrowserViewPrivate; typedef struct _XedFileBrowserViewPrivate XedFileBrowserViewPrivate;
typedef enum { typedef enum
{
XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE, XED_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE,
XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE XED_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE
} XedFileBrowserViewClickPolicy; } XedFileBrowserViewClickPolicy;
@ -66,7 +67,7 @@ struct _XedFileBrowserViewClass
}; };
GType xed_file_browser_view_get_type (void) G_GNUC_CONST; GType xed_file_browser_view_get_type (void) G_GNUC_CONST;
void _xed_file_browser_view_register_type (GTypeModule * module); void _xed_file_browser_view_register_type (GTypeModule *type_module);
GtkWidget *xed_file_browser_view_new (void); GtkWidget *xed_file_browser_view_new (void);
void xed_file_browser_view_set_model (XedFileBrowserView *tree_view, void xed_file_browser_view_set_model (XedFileBrowserView *tree_view,

View File

@ -800,18 +800,15 @@ static GtkActionEntry toplevel_actions[] =
static const GtkActionEntry tree_actions_selection[] = static const GtkActionEntry tree_actions_selection[] =
{ {
{"FileMoveToTrash", "user-trash", N_("_Move to Trash"), NULL, {"FileMoveToTrash", "user-trash", N_("_Move to Trash"), NULL,
N_("Move selected file or folder to trash"), N_("Move selected file or folder to trash"), G_CALLBACK (on_action_file_move_to_trash)},
G_CALLBACK (on_action_file_move_to_trash)},
{"FileDelete", "edit-delete-symbolic", N_("_Delete"), NULL, {"FileDelete", "edit-delete-symbolic", N_("_Delete"), NULL,
N_("Delete selected file or folder"), N_("Delete selected file or folder"), G_CALLBACK (on_action_file_delete)}
G_CALLBACK (on_action_file_delete)}
}; };
static const GtkActionEntry tree_actions_file_selection[] = static const GtkActionEntry tree_actions_file_selection[] =
{ {
{"FileOpen", "document-open-symbolic", N_("Open"), NULL, {"FileOpen", "document-open-symbolic", N_("_Open"), NULL,
N_("Open selected file"), N_("Open selected file"), G_CALLBACK (on_action_file_open)}
G_CALLBACK (on_action_file_open)}
}; };
static const GtkActionEntry tree_actions[] = static const GtkActionEntry tree_actions[] =
@ -823,8 +820,7 @@ static const GtkActionEntry tree_actions[] =
static const GtkActionEntry tree_actions_single_most_selection[] = static const GtkActionEntry tree_actions_single_most_selection[] =
{ {
{"DirectoryNew", "folder-new-symbolic", N_("_New Folder"), NULL, {"DirectoryNew", "folder-new-symbolic", N_("_New Folder"), NULL,
N_("Add new empty folder"), N_("Add new empty folder"), G_CALLBACK (on_action_directory_new)},
G_CALLBACK (on_action_directory_new)},
{"FileNew", "document-new-symbolic", N_("New F_ile"), NULL, {"FileNew", "document-new-symbolic", N_("New F_ile"), NULL,
N_("Add new empty file"), G_CALLBACK (on_action_file_new)} N_("Add new empty file"), G_CALLBACK (on_action_file_new)}
}; };
@ -832,33 +828,27 @@ static const GtkActionEntry tree_actions_single_most_selection[] =
static const GtkActionEntry tree_actions_single_selection[] = static const GtkActionEntry tree_actions_single_selection[] =
{ {
{"FileRename", NULL, N_("_Rename"), NULL, {"FileRename", NULL, N_("_Rename"), NULL,
N_("Rename selected file or folder"), N_("Rename selected file or folder"), G_CALLBACK (on_action_file_rename)}
G_CALLBACK (on_action_file_rename)}
}; };
static const GtkActionEntry tree_actions_sensitive[] = static const GtkActionEntry tree_actions_sensitive[] =
{ {
{"DirectoryPrevious", "go-previous-symbolic", N_("_Previous Location"), NULL, {"DirectoryPrevious", "go-previous-symbolic", N_("_Previous Location"), NULL,
N_("Go to the previous visited location"), N_("Go to the previous visited location"), G_CALLBACK (on_action_directory_previous)},
G_CALLBACK (on_action_directory_previous)},
{"DirectoryNext", "go-next-symbolic", N_("_Next Location"), NULL, {"DirectoryNext", "go-next-symbolic", N_("_Next Location"), NULL,
N_("Go to the next visited location"), G_CALLBACK (on_action_directory_next)}, N_("Go to the next visited location"), G_CALLBACK (on_action_directory_next)},
{"DirectoryRefresh", "view-refresh-symbolic", N_("Re_fresh View"), NULL, {"DirectoryRefresh", "view-refresh-symbolic", N_("Re_fresh View"), NULL,
N_("Refresh the view"), G_CALLBACK (on_action_directory_refresh)}, N_("Refresh the view"), G_CALLBACK (on_action_directory_refresh)},
{"DirectoryOpen", "folder-open-symbolic", N_("_View Folder"), NULL, {"DirectoryOpen", "folder-open-symbolic", N_("_View Folder"), NULL,
N_("View folder in file manager"), N_("View folder in file manager"), G_CALLBACK (on_action_directory_open)}
G_CALLBACK (on_action_directory_open)}
}; };
static const GtkToggleActionEntry tree_actions_toggle[] = static const GtkToggleActionEntry tree_actions_toggle[] =
{ {
{"FilterHidden", GTK_STOCK_DIALOG_AUTHENTICATION, {"FilterHidden", GTK_STOCK_DIALOG_AUTHENTICATION, N_("Show _Hidden"), NULL,
N_("Show _Hidden"), NULL, N_("Show hidden files and folders"), G_CALLBACK (on_action_filter_hidden), FALSE},
N_("Show hidden files and folders"),
G_CALLBACK (on_action_filter_hidden), FALSE},
{"FilterBinary", NULL, N_("Show _Binary"), NULL, {"FilterBinary", NULL, N_("Show _Binary"), NULL,
N_("Show binary files"), G_CALLBACK (on_action_filter_binary), N_("Show binary files"), G_CALLBACK (on_action_filter_binary), FALSE}
FALSE}
}; };
static const GtkActionEntry bookmark_actions[] = static const GtkActionEntry bookmark_actions[] =

View File

@ -71,7 +71,7 @@ struct _XedFileBrowserWidgetClass
}; };
GType xed_file_browser_widget_get_type (void) G_GNUC_CONST; GType xed_file_browser_widget_get_type (void) G_GNUC_CONST;
void _xed_file_browser_widget_register_type (GTypeModule * module); void _xed_file_browser_widget_register_type (GTypeModule *type_module);
GtkWidget *xed_file_browser_widget_new (const gchar *data_dir); GtkWidget *xed_file_browser_widget_new (const gchar *data_dir);

View File

@ -79,9 +79,12 @@ has_option (ModelineOptions *options,
void void
modeline_parser_init (const gchar *data_dir) modeline_parser_init (const gchar *data_dir)
{
if (modelines_data_dir == NULL)
{ {
modelines_data_dir = g_strdup (data_dir); modelines_data_dir = g_strdup (data_dir);
} }
}
void void
modeline_parser_shutdown () modeline_parser_shutdown ()
@ -100,6 +103,7 @@ modeline_parser_shutdown ()
kate_languages = NULL; kate_languages = NULL;
g_free (modelines_data_dir); g_free (modelines_data_dir);
modelines_data_dir = NULL;
} }
static GHashTable * static GHashTable *
@ -326,7 +330,7 @@ parse_vim_modeline (gchar *s,
options->set |= MODELINE_SET_WRAP_MODE; options->set |= MODELINE_SET_WRAP_MODE;
} }
else if (strcmp (key->str, "textwidth") == 0) else if (strcmp (key->str, "textwidth") == 0 || strcmp (key->str, "tw") == 0)
{ {
intval = atoi (value->str); intval = atoi (value->str);
@ -825,6 +829,7 @@ modeline_parser_apply_modeline (GtkSourceView *view)
if (previous) if (previous)
{ {
g_free (previous->language_id);
*previous = options; *previous = options;
previous->language_id = g_strdup (options.language_id); previous->language_id = g_strdup (options.language_id);
} }

View File

@ -23,7 +23,7 @@
#define __MODELINE_PARSER_H__ #define __MODELINE_PARSER_H__
#include <glib.h> #include <glib.h>
#include <gtksourceview/gtksourceview.h> #include <gtksourceview/gtksource.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View File

@ -25,50 +25,35 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <gmodule.h> #include <gmodule.h>
#include <libpeas/peas-activatable.h>
#include "xed-modeline-plugin.h" #include "xed-modeline-plugin.h"
#include "modeline-parser.h" #include "modeline-parser.h"
#include <xed/xed-window.h>
#include <xed/xed-debug.h> #include <xed/xed-debug.h>
#include <xed/xed-utils.h> #include <xed/xed-view-activatable.h>
#include <xed/xed-view.h>
#define DOCUMENT_DATA_KEY "XedModelinePluginDocumentData"
struct _XedModelinePluginPrivate struct _XedModelinePluginPrivate
{ {
GtkWidget *window; XedView *view;
gulong tab_added_handler_id;
gulong tab_removed_handler_id;
};
typedef struct
{
gulong document_loaded_handler_id; gulong document_loaded_handler_id;
gulong document_saved_handler_id; gulong document_saved_handler_id;
} DocumentData; };
enum enum
{ {
PROP_0, PROP_0,
PROP_OBJECT PROP_VIEW
}; };
static void peas_activatable_iface_init (PeasActivatableInterface *iface); static void xed_view_activatable_iface_init (XedViewActivatableInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedModelinePlugin, G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedModelinePlugin,
xed_modeline_plugin, xed_modeline_plugin,
PEAS_TYPE_EXTENSION_BASE, PEAS_TYPE_EXTENSION_BASE,
0, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_VIEW_ACTIVATABLE,
peas_activatable_iface_init)) xed_view_activatable_iface_init))
static void
document_data_free (DocumentData *ddata)
{
g_slice_free (DocumentData, ddata);
}
static void static void
xed_modeline_plugin_constructed (GObject *object) xed_modeline_plugin_constructed (GObject *object)
@ -94,6 +79,18 @@ xed_modeline_plugin_init (XedModelinePlugin *plugin)
XedModelinePluginPrivate); XedModelinePluginPrivate);
} }
static void
xed_modeline_plugin_dispose (GObject *object)
{
XedModelinePlugin *plugin = XED_MODELINE_PLUGIN (object);
xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin disposing");
g_clear_object (&plugin->priv->view);
G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->dispose (object);
}
static void static void
xed_modeline_plugin_finalize (GObject *object) xed_modeline_plugin_finalize (GObject *object)
{ {
@ -104,22 +101,6 @@ xed_modeline_plugin_finalize (GObject *object)
G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->finalize (object); G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->finalize (object);
} }
static void
xed_modeline_plugin_dispose (GObject *object)
{
XedModelinePlugin *plugin = XED_MODELINE_PLUGIN (object);
xed_debug_message (DEBUG_PLUGINS, "XedModelinePlugin disposing");
if (plugin->priv->window != NULL)
{
g_object_unref (plugin->priv->window);
plugin->priv->window = NULL;
}
G_OBJECT_CLASS (xed_modeline_plugin_parent_class)->dispose (object);
}
static void static void
xed_modeline_plugin_set_property (GObject *object, xed_modeline_plugin_set_property (GObject *object,
guint prop_id, guint prop_id,
@ -130,8 +111,8 @@ xed_modeline_plugin_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_OBJECT: case PROP_VIEW:
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); plugin->priv->view = XED_VIEW (g_value_dup_object (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -149,8 +130,8 @@ xed_modeline_plugin_get_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_OBJECT: case PROP_VIEW:
g_value_set_object (value, plugin->priv->window); g_value_set_object (value, plugin->priv->view);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -167,123 +148,41 @@ on_document_loaded_or_saved (XedDocument *document,
} }
static void static void
connect_handlers (XedView *view) xed_modeline_plugin_activate (XedViewActivatable *activatable)
{ {
DocumentData *data; XedModelinePlugin *plugin;
GtkTextBuffer *doc; GtkTextBuffer *doc;
doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); xed_debug (DEBUG_PLUGINS);
data = g_slice_new (DocumentData); plugin = XED_MODELINE_PLUGIN (activatable);
data->document_loaded_handler_id = modeline_parser_apply_modeline (GTK_SOURCE_VIEW (plugin->priv->view));
doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (plugin->priv->view));
plugin->priv->document_loaded_handler_id =
g_signal_connect (doc, "loaded", g_signal_connect (doc, "loaded",
G_CALLBACK (on_document_loaded_or_saved), G_CALLBACK (on_document_loaded_or_saved), plugin->priv->view);
view); plugin->priv->document_saved_handler_id =
data->document_saved_handler_id =
g_signal_connect (doc, "saved", g_signal_connect (doc, "saved",
G_CALLBACK (on_document_loaded_or_saved), G_CALLBACK (on_document_loaded_or_saved), plugin->priv->view);
view);
g_object_set_data_full (G_OBJECT (doc), DOCUMENT_DATA_KEY,
data, (GDestroyNotify) document_data_free);
} }
static void static void
disconnect_handlers (XedView *view) xed_modeline_plugin_deactivate (XedViewActivatable *activatable)
{ {
DocumentData *data; XedModelinePlugin *plugin;
GtkTextBuffer *doc; GtkTextBuffer *doc;
doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
data = g_object_steal_data (G_OBJECT (doc), DOCUMENT_DATA_KEY);
if (data)
{
g_signal_handler_disconnect (doc, data->document_loaded_handler_id);
g_signal_handler_disconnect (doc, data->document_saved_handler_id);
document_data_free (data);
}
else
{
g_warning ("Modeline handlers not found");
}
}
static void
on_window_tab_added (XedWindow *window,
XedTab *tab,
gpointer user_data)
{
connect_handlers (xed_tab_get_view (tab));
}
static void
on_window_tab_removed (XedWindow *window,
XedTab *tab,
gpointer user_data)
{
disconnect_handlers (xed_tab_get_view (tab));
}
static void
xed_modeline_plugin_activate (PeasActivatable *activatable)
{
XedModelinePluginPrivate *data;
XedWindow *window;
GList *views;
GList *l;
xed_debug (DEBUG_PLUGINS); xed_debug (DEBUG_PLUGINS);
data = XED_MODELINE_PLUGIN (activatable)->priv; plugin = XED_MODELINE_PLUGIN (activatable);
window = XED_WINDOW (data->window);
views = xed_window_get_views (window); doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (plugin->priv->view));
for (l = views; l != NULL; l = l->next)
{
connect_handlers (XED_VIEW (l->data));
modeline_parser_apply_modeline (GTK_SOURCE_VIEW (l->data));
}
g_list_free (views);
data->tab_added_handler_id = g_signal_handler_disconnect (doc, plugin->priv->document_loaded_handler_id);
g_signal_connect (window, "tab-added", g_signal_handler_disconnect (doc, plugin->priv->document_saved_handler_id);
G_CALLBACK (on_window_tab_added), NULL);
data->tab_removed_handler_id =
g_signal_connect (window, "tab-removed",
G_CALLBACK (on_window_tab_removed), NULL);
}
static void
xed_modeline_plugin_deactivate (PeasActivatable *activatable)
{
XedModelinePluginPrivate *data;
XedWindow *window;
GList *views;
GList *l;
xed_debug (DEBUG_PLUGINS);
data = XED_MODELINE_PLUGIN (activatable)->priv;
window = XED_WINDOW (data->window);
g_signal_handler_disconnect (window, data->tab_added_handler_id);
g_signal_handler_disconnect (window, data->tab_removed_handler_id);
views = xed_window_get_views (window);
for (l = views; l != NULL; l = l->next)
{
disconnect_handlers (XED_VIEW (l->data));
modeline_parser_deactivate (GTK_SOURCE_VIEW (l->data));
}
g_list_free (views);
} }
static void static void
@ -292,35 +191,35 @@ xed_modeline_plugin_class_init (XedModelinePluginClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = xed_modeline_plugin_constructed; object_class->constructed = xed_modeline_plugin_constructed;
object_class->finalize = xed_modeline_plugin_finalize;
object_class->dispose = xed_modeline_plugin_dispose; object_class->dispose = xed_modeline_plugin_dispose;
object_class->finalize = xed_modeline_plugin_finalize;
object_class->set_property = xed_modeline_plugin_set_property; object_class->set_property = xed_modeline_plugin_set_property;
object_class->get_property = xed_modeline_plugin_get_property; object_class->get_property = xed_modeline_plugin_get_property;
g_object_class_override_property (object_class, PROP_OBJECT, "object"); g_object_class_override_property (object_class, PROP_VIEW, "view");
g_type_class_add_private (klass, sizeof (XedModelinePluginPrivate)); g_type_class_add_private (klass, sizeof (XedModelinePluginPrivate));
} }
static void
xed_view_activatable_iface_init (XedViewActivatableInterface *iface)
{
iface->activate = xed_modeline_plugin_activate;
iface->deactivate = xed_modeline_plugin_deactivate;
}
static void static void
xed_modeline_plugin_class_finalize (XedModelinePluginClass *klass) xed_modeline_plugin_class_finalize (XedModelinePluginClass *klass)
{ {
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
} }
static void
peas_activatable_iface_init (PeasActivatableInterface *iface)
{
iface->activate = xed_modeline_plugin_activate;
iface->deactivate = xed_modeline_plugin_deactivate;
}
G_MODULE_EXPORT void G_MODULE_EXPORT void
peas_register_types (PeasObjectModule *module) peas_register_types (PeasObjectModule *module)
{ {
xed_modeline_plugin_register_type (G_TYPE_MODULE (module)); xed_modeline_plugin_register_type (G_TYPE_MODULE (module));
peas_object_module_register_extension_type (module, peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE, XED_TYPE_VIEW_ACTIVATABLE,
XED_TYPE_MODELINE_PLUGIN); XED_TYPE_MODELINE_PLUGIN);
} }

View File

@ -39,10 +39,11 @@ G_BEGIN_DECLS
/* Private structure type */ /* Private structure type */
typedef struct _XedModelinePlugin XedModelinePlugin; typedef struct _XedModelinePlugin XedModelinePlugin;
typedef struct _XedModelinePluginPrivate XedModelinePluginPrivate; typedef struct _XedModelinePluginPrivate XedModelinePluginPrivate;
typedef struct _XedModelinePluginClass XedModelinePluginClass;
struct _XedModelinePlugin struct _XedModelinePlugin
{ {
PeasExtensionBase parent_instance; PeasExtensionBase parent;
/*< private >*/ /*< private >*/
XedModelinePluginPrivate *priv; XedModelinePluginPrivate *priv;

View File

@ -70,6 +70,7 @@ NOINST_H_FILES = \
INST_H_FILES = \ INST_H_FILES = \
xed-app.h \ xed-app.h \
xed-app-activatable.h \
xed-commands.h \ xed-commands.h \
xed-debug.h \ xed-debug.h \
xed-document.h \ xed-document.h \
@ -91,7 +92,9 @@ INST_H_FILES = \
xed-tab.h \ xed-tab.h \
xed-utils.h \ xed-utils.h \
xed-view.h \ xed-view.h \
xed-window.h xed-view-activatable.h \
xed-window.h \
xed-window-activatable.h
if !ENABLE_GVFS_METADATA if !ENABLE_GVFS_METADATA
INST_H_FILES += xed-metadata-manager.h INST_H_FILES += xed-metadata-manager.h
@ -105,6 +108,7 @@ header_DATA = \
libxed_c_files = \ libxed_c_files = \
xed-app.c \ xed-app.c \
xed-app-activatable.c \
xed-close-button.c \ xed-close-button.c \
xed-commands-documents.c \ xed-commands-documents.c \
xed-commands-edit.c \ xed-commands-edit.c \
@ -152,7 +156,9 @@ libxed_c_files = \
xed-tab-label.c \ xed-tab-label.c \
xed-utils.c \ xed-utils.c \
xed-view.c \ xed-view.c \
xed-view-activatable.c \
xed-window.c \ xed-window.c \
xed-window-activatable.c \
xedtextregion.c xedtextregion.c
libxed_la_SOURCES = \ libxed_la_SOURCES = \

108
xed/xed-app-activatable.c Normal file
View File

@ -0,0 +1,108 @@
/*
* xed-app-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 Steve Frécinaux
* Copyright (C) 2010 Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xed-app-activatable.h"
#include "xed-app.h"
/**
* SECTION:xed-app-activatable
* @short_description: Interface for activatable extensions on apps
* @see_also: #PeasExtensionSet
*
* #XedAppActivatable is an interface which should be implemented by
* extensions that should be activated on a xed application.
**/
G_DEFINE_INTERFACE(XedAppActivatable, xed_app_activatable, G_TYPE_OBJECT)
void
xed_app_activatable_default_init (XedAppActivatableInterface *iface)
{
static gboolean initialized = FALSE;
if (!initialized)
{
/**
* XedAppActivatable:app:
*
* The app property contains the xed app for this
* #XedAppActivatable instance.
*/
g_object_interface_install_property (iface,
g_param_spec_object ("app",
"App",
"The xed app",
XED_TYPE_APP,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
initialized = TRUE;
}
}
/**
* xed_app_activatable_activate:
* @activatable: A #XedAppActivatable.
*
* Activates the extension on the application.
*/
void
xed_app_activatable_activate (XedAppActivatable *activatable)
{
XedAppActivatableInterface *iface;
g_return_if_fail (XED_IS_APP_ACTIVATABLE (activatable));
iface = XED_APP_ACTIVATABLE_GET_IFACE (activatable);
if (iface->activate != NULL)
{
iface->activate (activatable);
}
}
/**
* xed_app_activatable_deactivate:
* @activatable: A #XedAppActivatable.
*
* Deactivates the extension from the application.
*
*/
void
xed_app_activatable_deactivate (XedAppActivatable *activatable)
{
XedAppActivatableInterface *iface;
g_return_if_fail (XED_IS_APP_ACTIVATABLE (activatable));
iface = XED_APP_ACTIVATABLE_GET_IFACE (activatable);
if (iface->deactivate != NULL)
{
iface->deactivate (activatable);
}
}

61
xed/xed-app-activatable.h Normal file
View File

@ -0,0 +1,61 @@
/*
* xed-app-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 - Steve Frécinaux
* Copyright (C) 2010 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __XED_APP_ACTIVATABLE_H__
#define __XED_APP_ACTIVATABLE_H__
#include <glib-object.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_APP_ACTIVATABLE (xed_app_activatable_get_type ())
#define XED_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatable))
#define XED_APP_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatableInterface))
#define XED_IS_APP_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_APP_ACTIVATABLE))
#define XED_APP_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_APP_ACTIVATABLE, XedAppActivatableInterface))
typedef struct _XedAppActivatable XedAppActivatable; /* dummy typedef */
typedef struct _XedAppActivatableInterface XedAppActivatableInterface;
struct _XedAppActivatableInterface
{
GTypeInterface g_iface;
/* Virtual public methods */
void (*activate) (XedAppActivatable *activatable);
void (*deactivate) (XedAppActivatable *activatable);
};
/*
* Public methods
*/
GType xed_app_activatable_get_type (void) G_GNUC_CONST;
void xed_app_activatable_activate (XedAppActivatable *activatable);
void xed_app_activatable_deactivate (XedAppActivatable *activatable);
G_END_DECLS
#endif /* __XED_APP_ACTIVATABLE_H__ */

View File

@ -36,6 +36,7 @@
#include <unistd.h> #include <unistd.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <libpeas/peas-extension-set.h>
#include "xed-app.h" #include "xed-app.h"
#include "xed-prefs-manager-app.h" #include "xed-prefs-manager-app.h"
@ -45,6 +46,8 @@
#include "xed-utils.h" #include "xed-utils.h"
#include "xed-enum-types.h" #include "xed-enum-types.h"
#include "xed-dirs.h" #include "xed-dirs.h"
#include "xed-app-activatable.h"
#include "xed-plugins-engine.h"
#define XED_PAGE_SETUP_FILE "xed-page-setup" #define XED_PAGE_SETUP_FILE "xed-page-setup"
#define XED_PRINT_SETTINGS_FILE "xed-print-settings" #define XED_PRINT_SETTINGS_FILE "xed-print-settings"
@ -61,8 +64,11 @@ struct _XedAppPrivate
{ {
GList *windows; GList *windows;
XedWindow *active_window; XedWindow *active_window;
GtkPageSetup *page_setup; GtkPageSetup *page_setup;
GtkPrintSettings *print_settings; GtkPrintSettings *print_settings;
PeasExtensionSet *extensions;
}; };
G_DEFINE_TYPE(XedApp, xed_app, G_TYPE_OBJECT) G_DEFINE_TYPE(XedApp, xed_app, G_TYPE_OBJECT)
@ -87,6 +93,16 @@ xed_app_finalize (GObject *object)
G_OBJECT_CLASS (xed_app_parent_class)->finalize (object); G_OBJECT_CLASS (xed_app_parent_class)->finalize (object);
} }
static void
xed_app_dispose (GObject *object)
{
XedApp *app = XED_APP (object);
g_clear_object (&app->priv->extensions);
G_OBJECT_CLASS (xed_app_parent_class)->dispose (object);
}
static void static void
xed_app_get_property (GObject *object, xed_app_get_property (GObject *object,
guint prop_id, guint prop_id,
@ -107,6 +123,7 @@ xed_app_class_init (XedAppClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = xed_app_finalize; object_class->finalize = xed_app_finalize;
object_class->dispose = xed_app_dispose;
object_class->get_property = xed_app_get_property; object_class->get_property = xed_app_get_property;
g_type_class_add_private (object_class, sizeof (XedAppPrivate)); g_type_class_add_private (object_class, sizeof (XedAppPrivate));
@ -308,19 +325,40 @@ save_print_settings (XedApp *app)
g_free (filename); g_free (filename);
} }
static void
extension_added (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedApp *app)
{
peas_extension_call (exten, "activate");
}
static void
extension_removed (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedApp *app)
{
peas_extension_call (exten, "deactivate");
}
static void static void
xed_app_init (XedApp *app) xed_app_init (XedApp *app)
{ {
app->priv = XED_APP_GET_PRIVATE (app); app->priv = XED_APP_GET_PRIVATE (app);
load_accels (); load_accels ();
}
static void app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()),
app_weak_notify (gpointer data, XED_TYPE_APP_ACTIVATABLE, "app", app, NULL);
GObject *where_the_app_was)
{ g_signal_connect (app->priv->extensions, "extension-added",
gtk_main_quit (); G_CALLBACK (extension_added), app);
g_signal_connect (app->priv->extensions, "extension-removed",
G_CALLBACK (extension_removed), app);
peas_extension_set_call (app->priv->extensions, "activate");
} }
/** /**
@ -342,7 +380,6 @@ xed_app_get_default (void)
app = XED_APP (g_object_new (XED_TYPE_APP, NULL)); app = XED_APP (g_object_new (XED_TYPE_APP, NULL));
g_object_add_weak_pointer (G_OBJECT (app), (gpointer) &app); g_object_add_weak_pointer (G_OBJECT (app), (gpointer) &app);
g_object_weak_ref (G_OBJECT (app), app_weak_notify, NULL);
return app; return app;
} }
@ -421,7 +458,7 @@ window_destroy (XedWindow *window,
save_page_setup (app); save_page_setup (app);
save_print_settings (app); save_print_settings (app);
g_object_unref (app); gtk_main_quit ();
} }
} }

View File

@ -0,0 +1,96 @@
/*
* xed-view-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 Steve Frécinaux
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xed-view-activatable.h"
#include "xed-view.h"
/**
* SECTION:xed-view-activatable
* @short_description: Interface for activatable extensions on views
* @see_also: #PeasExtensionSet
*
* #XedViewActivatable is an interface which should be implemented by
* extensions that should be activated on a xed view.
**/
G_DEFINE_INTERFACE(XedViewActivatable, xed_view_activatable, G_TYPE_OBJECT)
void
xed_view_activatable_default_init (XedViewActivatableInterface *iface)
{
/**
* XedViewActivatable:view:
*
* The window property contains the xed window for this
* #XedViewActivatable instance.
*/
g_object_interface_install_property (iface,
g_param_spec_object ("view",
"view",
"A xed view",
XED_TYPE_VIEW,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
/**
* xed_view_activatable_activate:
* @activatable: A #XedViewActivatable.
*
* Activates the extension on the window property.
*/
void
xed_view_activatable_activate (XedViewActivatable *activatable)
{
XedViewActivatableInterface *iface;
g_return_if_fail (XED_IS_VIEW_ACTIVATABLE (activatable));
iface = XED_VIEW_ACTIVATABLE_GET_IFACE (activatable);
if (iface->activate != NULL)
{
iface->activate (activatable);
}
}
/**
* xed_view_activatable_deactivate:
* @activatable: A #XedViewActivatable.
*
* Deactivates the extension on the window property.
*/
void
xed_view_activatable_deactivate (XedViewActivatable *activatable)
{
XedViewActivatableInterface *iface;
g_return_if_fail (XED_IS_VIEW_ACTIVATABLE (activatable));
iface = XED_VIEW_ACTIVATABLE_GET_IFACE (activatable);
if (iface->deactivate != NULL)
{
iface->deactivate (activatable);
}
}

View File

@ -0,0 +1,60 @@
/*
* xed-view-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 - Steve Frécinaux
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __XED_VIEW_ACTIVATABLE_H__
#define __XED_VIEW_ACTIVATABLE_H__
#include <glib-object.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_VIEW_ACTIVATABLE (xed_view_activatable_get_type ())
#define XED_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatable))
#define XED_VIEW_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatableInterface))
#define XED_IS_VIEW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_VIEW_ACTIVATABLE))
#define XED_VIEW_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_VIEW_ACTIVATABLE, XedViewActivatableInterface))
typedef struct _XedViewActivatable XedViewActivatable; /* dummy typedef */
typedef struct _XedViewActivatableInterface XedViewActivatableInterface;
struct _XedViewActivatableInterface
{
GTypeInterface g_iface;
/* Virtual public methods */
void (*activate) (XedViewActivatable *activatable);
void (*deactivate) (XedViewActivatable *activatable);
};
/*
* Public methods
*/
GType xed_view_activatable_get_type (void) G_GNUC_CONST;
void xed_view_activatable_activate (XedViewActivatable *activatable);
void xed_view_activatable_deactivate (XedViewActivatable *activatable);
G_END_DECLS
#endif /* __XED_VIEW_ACTIVATABLE_H__ */

View File

@ -6,9 +6,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <libpeas/peas-extension-set.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include "xed-view.h" #include "xed-view.h"
#include "xed-view-activatable.h"
#include "xed-plugins-engine.h"
#include "xed-debug.h" #include "xed-debug.h"
#include "xed-prefs-manager.h" #include "xed-prefs-manager.h"
#include "xed-prefs-manager-app.h" #include "xed-prefs-manager-app.h"
@ -34,10 +37,13 @@ struct _XedViewPrivate
guint search_entry_changed_id; guint search_entry_changed_id;
gboolean disable_popdown; gboolean disable_popdown;
GtkTextBuffer *current_buffer; GtkTextBuffer *current_buffer;
PeasExtensionSet *extensions;
guint view_realized : 1;
}; };
static void xed_view_dispose (GObject *object); static void xed_view_dispose (GObject *object);
static void xed_view_finalize (GObject *object); static void xed_view_finalize (GObject *object);
static void xed_view_realize (GtkWidget *widget);
static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event); static gint xed_view_focus_out (GtkWidget *widget, GdkEventFocus *event);
static gboolean xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp); static gboolean xed_view_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint timestamp);
static void xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, static void xed_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
@ -107,6 +113,7 @@ xed_view_class_init (XedViewClass *klass)
widget_class->drag_data_received = xed_view_drag_data_received; widget_class->drag_data_received = xed_view_drag_data_received;
widget_class->drag_drop = xed_view_drag_drop; widget_class->drag_drop = xed_view_drag_drop;
widget_class->button_press_event = xed_view_button_press_event; widget_class->button_press_event = xed_view_button_press_event;
widget_class->realize = xed_view_realize;
klass->start_interactive_goto_line = start_interactive_goto_line; klass->start_interactive_goto_line = start_interactive_goto_line;
text_view_class->delete_from_cursor = xed_view_delete_from_cursor; text_view_class->delete_from_cursor = xed_view_delete_from_cursor;
@ -152,6 +159,24 @@ current_buffer_removed (XedView *view)
} }
} }
static void
extension_added (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedView *view)
{
peas_extension_call (exten, "activate");
}
static void
extension_removed (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedView *view)
{
peas_extension_call (exten, "deactivate");
}
static void static void
on_notify_buffer_cb (XedView *view, on_notify_buffer_cb (XedView *view,
GParamSpec *arg1, GParamSpec *arg1,
@ -223,6 +248,14 @@ xed_view_init (XedView *view)
gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST); gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST);
} }
view->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()),
XED_TYPE_VIEW_ACTIVATABLE, "view", view, NULL);
g_signal_connect (view->priv->extensions, "extension-added",
G_CALLBACK (extension_added), view);
g_signal_connect (view->priv->extensions, "extension-removed",
G_CALLBACK (extension_removed), view);
/* Act on buffer change */ /* Act on buffer change */
g_signal_connect(view, "notify::buffer", G_CALLBACK (on_notify_buffer_cb), NULL); g_signal_connect(view, "notify::buffer", G_CALLBACK (on_notify_buffer_cb), NULL);
} }
@ -234,6 +267,12 @@ xed_view_dispose (GObject *object)
view = XED_VIEW(object); view = XED_VIEW(object);
if (view->priv->extensions != NULL)
{
g_object_unref (view->priv->extensions);
view->priv->extensions = NULL;
}
if (view->priv->search_window != NULL) if (view->priv->search_window != NULL)
{ {
gtk_widget_destroy (view->priv->search_window); gtk_widget_destroy (view->priv->search_window);
@ -261,7 +300,8 @@ xed_view_finalize (GObject *object)
XedView *view; XedView *view;
view = XED_VIEW(object); view = XED_VIEW(object);
current_buffer_removed (view); current_buffer_removed (view);
(* G_OBJECT_CLASS (xed_view_parent_class)->finalize) (object);
G_OBJECT_CLASS (xed_view_parent_class)->finalize (object);
} }
static gint static gint
@ -1141,6 +1181,20 @@ xed_view_button_press_event (GtkWidget *widget,
return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event); return GTK_WIDGET_CLASS (xed_view_parent_class)->button_press_event (widget, event);
} }
static void
xed_view_realize (GtkWidget *widget)
{
XedView *view = XED_VIEW (widget);
if (!view->priv->view_realized)
{
peas_extension_set_call (view->priv->extensions, "activate");
view->priv->view_realized = TRUE;
}
GTK_WIDGET_CLASS (xed_view_parent_class)->realize (widget);
}
static void static void
search_highlight_updated_cb (XedDocument *doc, search_highlight_updated_cb (XedDocument *doc,
GtkTextIter *start, GtkTextIter *start,

View File

@ -0,0 +1,117 @@
/*
* xed-window-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 Steve Frécinaux
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "xed-window-activatable.h"
#include "xed-window.h"
/**
* SECTION:xed-window-activatable
* @short_description: Interface for activatable extensions on windows
* @see_also: #PeasExtensionSet
*
* #XedWindowActivatable is an interface which should be implemented by
* extensions that should be activated on a xed main window.
**/
G_DEFINE_INTERFACE(XedWindowActivatable, xed_window_activatable, G_TYPE_OBJECT)
void
xed_window_activatable_default_init (XedWindowActivatableInterface *iface)
{
/**
* XedWindowActivatable:window:
*
* The window property contains the xed window for this
* #XedWindowActivatable instance.
*/
g_object_interface_install_property (iface,
g_param_spec_object ("window",
"Window",
"The xed window",
XED_TYPE_WINDOW,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
/**
* xed_window_activatable_activate:
* @activatable: A #XedWindowActivatable.
*
* Activates the extension on the window property.
*/
void
xed_window_activatable_activate (XedWindowActivatable *activatable)
{
XedWindowActivatableInterface *iface;
g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable));
iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
if (iface->activate != NULL)
{
iface->activate (activatable);
}
}
/**
* xed_window_activatable_deactivate:
* @activatable: A #XedWindowActivatable.
*
* Deactivates the extension on the window property.
*/
void
xed_window_activatable_deactivate (XedWindowActivatable *activatable)
{
XedWindowActivatableInterface *iface;
g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable));
iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
if (iface->deactivate != NULL)
{
iface->deactivate (activatable);
}
}
/**
* xed_window_activatable_update_state:
* @activatable: A #XedWindowActivatable.
*
* Triggers an update of the extension insternal state to take into account
* state changes in the window state, due to some event or user action.
*/
void
xed_window_activatable_update_state (XedWindowActivatable *activatable)
{
XedWindowActivatableInterface *iface;
g_return_if_fail (XED_IS_WINDOW_ACTIVATABLE (activatable));
iface = XED_WINDOW_ACTIVATABLE_GET_IFACE (activatable);
if (iface->update_state != NULL)
{
iface->update_state (activatable);
}
}

View File

@ -0,0 +1,62 @@
/*
* xed-window-activatable.h
* This file is part of xed
*
* Copyright (C) 2010 - Steve Frécinaux
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __XED_WINDOW_ACTIVATABLE_H__
#define __XED_WINDOW_ACTIVATABLE_H__
#include <glib-object.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define XED_TYPE_WINDOW_ACTIVATABLE (xed_window_activatable_get_type ())
#define XED_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatable))
#define XED_WINDOW_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatableInterface))
#define XED_IS_WINDOW_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XED_TYPE_WINDOW_ACTIVATABLE))
#define XED_WINDOW_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), XED_TYPE_WINDOW_ACTIVATABLE, XedWindowActivatableInterface))
typedef struct _XedWindowActivatable XedWindowActivatable; /* dummy typedef */
typedef struct _XedWindowActivatableInterface XedWindowActivatableInterface;
struct _XedWindowActivatableInterface
{
GTypeInterface g_iface;
/* Virtual public methods */
void (*activate) (XedWindowActivatable *activatable);
void (*deactivate) (XedWindowActivatable *activatable);
void (*update_state) (XedWindowActivatable *activatable);
};
/*
* Public methods
*/
GType xed_window_activatable_get_type (void) G_GNUC_CONST;
void xed_window_activatable_activate (XedWindowActivatable *activatable);
void xed_window_activatable_deactivate (XedWindowActivatable *activatable);
void xed_window_activatable_update_state (XedWindowActivatable *activatable);
G_END_DECLS
#endif /* __XED_WINDOW_ACTIVATABLE_H__ */

View File

@ -9,7 +9,6 @@
#include <gio/gio.h> #include <gio/gio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <libpeas/peas-activatable.h>
#include <libpeas/peas-extension-set.h> #include <libpeas/peas-extension-set.h>
#include "xed-ui.h" #include "xed-ui.h"
@ -27,6 +26,7 @@
#include "xed-panel.h" #include "xed-panel.h"
#include "xed-documents-panel.h" #include "xed-documents-panel.h"
#include "xed-plugins-engine.h" #include "xed-plugins-engine.h"
#include "xed-window-activatable.h"
#include "xed-enum-types.h" #include "xed-enum-types.h"
#include "xed-dirs.h" #include "xed-dirs.h"
#include "xed-status-combo-box.h" #include "xed-status-combo-box.h"
@ -163,11 +163,13 @@ xed_window_dispose (GObject *object)
if (!window->priv->dispose_has_run) if (!window->priv->dispose_has_run)
{ {
save_panes_state (window); save_panes_state (window);
/* Note that unreffing the extension will automatically remove /* Note that unreffing the extension will automatically remove
all extensions which in turn will deactivate the extension */ all extensions which in turn will deactivate the extension */
g_object_unref (window->priv->extensions); g_object_unref (window->priv->extensions);
peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ()));
window->priv->dispose_has_run = TRUE; window->priv->dispose_has_run = TRUE;
} }
@ -191,23 +193,10 @@ xed_window_dispose (GObject *object)
window->priv->recents_handler_id = 0; window->priv->recents_handler_id = 0;
} }
if (window->priv->manager != NULL) g_clear_object (&window->priv->manager);
{ g_clear_object (&window->priv->message_bus);
g_object_unref (window->priv->manager); g_clear_object (&window->priv->window_group);
window->priv->manager = NULL; g_clear_object (&window->priv->default_location);
}
if (window->priv->message_bus != NULL)
{
g_object_unref (window->priv->message_bus);
window->priv->message_bus = NULL;
}
if (window->priv->window_group != NULL)
{
g_object_unref (window->priv->window_group);
window->priv->window_group = NULL;
}
/* Now that there have broken some reference loops, force collection again. */ /* Now that there have broken some reference loops, force collection again. */
peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ())); peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ()));
@ -218,13 +207,8 @@ xed_window_dispose (GObject *object)
static void static void
xed_window_finalize (GObject *object) xed_window_finalize (GObject *object)
{ {
XedWindow *window;
xed_debug (DEBUG_WINDOW); xed_debug (DEBUG_WINDOW);
window = XED_WINDOW(object);
if (window->priv->default_location != NULL)
{
g_object_unref (window->priv->default_location);
}
G_OBJECT_CLASS (xed_window_parent_class)->finalize (object); G_OBJECT_CLASS (xed_window_parent_class)->finalize (object);
} }
@ -646,7 +630,7 @@ set_sensitivity_according_to_tab (XedWindow *window,
update_next_prev_doc_sensitivity (window, tab); update_next_prev_doc_sensitivity (window, tab);
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static void static void
@ -2376,7 +2360,7 @@ sync_name (XedTab *tab,
g_free (escaped_name); g_free (escaped_name);
g_free (tip); g_free (tip);
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static XedWindow * static XedWindow *
@ -2789,7 +2773,7 @@ selection_changed (XedDocument *doc,
gtk_action_set_sensitive (action, gtk_action_set_sensitive (action,
state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc))); state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc)));
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static void static void
@ -2798,7 +2782,7 @@ sync_languages_menu (XedDocument *doc,
XedWindow *window) XedWindow *window)
{ {
update_languages_menu (window); update_languages_menu (window);
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static void static void
@ -2808,7 +2792,7 @@ readonly_changed (XedDocument *doc,
{ {
set_sensitivity_according_to_tab (window, window->priv->active_tab); set_sensitivity_according_to_tab (window, window->priv->active_tab);
sync_name (window->priv->active_tab, NULL, window); sync_name (window->priv->active_tab, NULL, window);
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static void static void
@ -2816,7 +2800,7 @@ editable_changed (XedView *view,
GParamSpec *arg1, GParamSpec *arg1,
XedWindow *window) XedWindow *window)
{ {
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
static void static void
@ -2964,7 +2948,7 @@ notebook_tab_removed (XedNotebook *notebook,
if (window->priv->num_tabs == 0) if (window->priv->num_tabs == 0)
{ {
peas_extension_set_call (window->priv->extensions, "update_state", window); peas_extension_set_call (window->priv->extensions, "update_state");
} }
update_window_state (window); update_window_state (window);
@ -3374,21 +3358,21 @@ add_notebook (XedWindow *window,
} }
static void static void
on_extension_added (PeasExtensionSet *extensions, extension_added (PeasExtensionSet *extensions,
PeasPluginInfo *info, PeasPluginInfo *info,
PeasExtension *exten, PeasExtension *exten,
XedWindow *window) XedWindow *window)
{ {
peas_extension_call (exten, "activate", window); peas_extension_call (exten, "activate");
} }
static void static void
on_extension_removed (PeasExtensionSet *extensions, extension_removed (PeasExtensionSet *extensions,
PeasPluginInfo *info, PeasPluginInfo *info,
PeasExtension *exten, PeasExtension *exten,
XedWindow *window) XedWindow *window)
{ {
peas_extension_call (exten, "deactivate", window); peas_extension_call (exten, "deactivate");
/* Ensure update of the ui manager, because we suspect it does something with expected static strings in the /* Ensure update of the ui manager, because we suspect it does something with expected static strings in the
* type module (when unloaded the strings don't exist anymore, and the ui manager update in a idle func) */ * type module (when unloaded the strings don't exist anymore, and the ui manager update in a idle func) */
@ -3501,13 +3485,13 @@ xed_window_init (XedWindow *window)
xed_debug_message (DEBUG_WINDOW, "Update plugins ui"); xed_debug_message (DEBUG_WINDOW, "Update plugins ui");
window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()), window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()),
PEAS_TYPE_ACTIVATABLE, "object", window, NULL); XED_TYPE_WINDOW_ACTIVATABLE, "window", window, NULL);
g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (extension_added), window);
g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (extension_removed), window);
peas_extension_set_call (window->priv->extensions, "activate"); peas_extension_set_call (window->priv->extensions, "activate");
g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (on_extension_added), window);
g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), window);
/* set visibility of panes. /* set visibility of panes.
* This needs to be done after plugins activatation */ * This needs to be done after plugins activatation */
init_panels_visibility (window); init_panels_visibility (window);