[anjuta] file-manager: Add option for showing the currently edited file in the file manager.
- From: Carl-Anton Ingmarsson <carlantoni src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] file-manager: Add option for showing the currently edited file in the file manager.
- Date: Mon, 21 Jan 2013 20:28:45 +0000 (UTC)
commit aa3dea443c73c5bb0b1b96693c6aaaeedbc3fdbc
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date: Sat Jan 19 10:05:44 2013 +0100
file-manager: Add option for showing the currently edited file in the file manager.
https://bugzilla.gnome.org/show_bug.cgi?id=692175
plugins/file-manager/file-manager.ui | 80 +++++++++---
plugins/file-manager/file-model.c | 18 +++
plugins/file-manager/file-view.c | 135 +++++++++++++++++++-
plugins/file-manager/file-view.h | 3 +
.../org.gnome.anjuta.file-manager.gschema.xml.in | 3 +
plugins/file-manager/plugin.c | 41 ++++++-
plugins/file-manager/plugin.h | 2 +
7 files changed, 263 insertions(+), 19 deletions(-)
---
diff --git a/plugins/file-manager/file-manager.ui b/plugins/file-manager/file-manager.ui
index 9ed6e83..a8c735a 100644
--- a/plugins/file-manager/file-manager.ui
+++ b/plugins/file-manager/file-manager.ui
@@ -1,53 +1,89 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 2.16 -->
- <!-- interface-naming-policy toplevel-contextual -->
+ <!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="filemanager_pref_window">
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<object class="GtkVBox" id="filemanager_prefs">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="left_padding">12</property>
<child>
- <object class="GtkHBox" id="hbox1">
+ <object class="GtkBox" id="box1">
<property name="visible">True</property>
- <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkLabel" id="label2">
+ <object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="label" translatable="yes">Root directory if no project is open:</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">Root directory if no project is open:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkFileChooserButton" id="preferences_folder:text:/:0:filemanager-root">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="action">select-folder</property>
+ <property name="preview_widget_active">False</property>
+ <property name="use_preview_label">False</property>
+ <property name="title" translatable="yes">Choose Directory to show if no project is open</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">5</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">5</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkFileChooserButton" id="preferences_folder:text:/:0:filemanager-root">
+ <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:filemanager-select-current-document">
+ <property name="label" translatable="yes">Automatically select the current document</property>
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
- <property name="use_preview_label">False</property>
- <property name="action">select-folder</property>
- <property name="preview_widget_active">False</property>
- <property name="title" translatable="yes">Choose Directory to show if no project is open</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
- <property name="padding">5</property>
- <property name="pack_type">end</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -58,6 +94,7 @@
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Global</property>
<attributes>
@@ -68,6 +105,7 @@
</object>
<packing>
<property name="expand">False</property>
+ <property name="fill">True</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
@@ -75,17 +113,20 @@
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<object class="GtkCheckButton" id="preferences_toggle:bool:1:0:filemanager-filter-binary">
@@ -94,6 +135,7 @@
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -109,6 +151,7 @@
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -124,6 +167,7 @@
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -139,6 +183,7 @@
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0.5</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -154,6 +199,7 @@
<child type="label">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Filter</property>
<attributes>
@@ -163,6 +209,8 @@
</child>
</object>
<packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
<property name="padding">5</property>
<property name="position">1</property>
</packing>
diff --git a/plugins/file-manager/file-model.c b/plugins/file-manager/file-model.c
index 1e383a1..cbcfcd6 100644
--- a/plugins/file-manager/file-model.c
+++ b/plugins/file-manager/file-model.c
@@ -54,6 +54,14 @@ enum
PROP_FILTER_UNVERSIONED
};
+enum
+{
+ SIGNAL_DIRECTORY_EXPANDED,
+ SIGNAL_LAST
+};
+
+guint signals [SIGNAL_LAST];
+
typedef struct _FileModelPrivate FileModelPrivate;
typedef struct _FileModelAsyncData FileModelAsyncData;
@@ -521,6 +529,9 @@ on_row_expanded_async (GObject* source_object,
file_model_add_watch (model, path);
file_model_get_vcs_status (model, &real_iter, dir);
+
+ g_signal_emit (model, signals[SIGNAL_DIRECTORY_EXPANDED], 0, &real_iter, path);
+
gtk_tree_path_free (path);
gtk_tree_row_reference_free (ref);
g_object_unref(files);
@@ -727,6 +738,13 @@ file_model_class_init (FileModelClass *klass)
"file_unversioned",
TRUE,
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
+
+ signals[SIGNAL_DIRECTORY_EXPANDED] =
+ g_signal_new ("directory-expanded",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 2, GTK_TYPE_TREE_ITER, GTK_TYPE_TREE_PATH);
}
diff --git a/plugins/file-manager/file-view.c b/plugins/file-manager/file-view.c
index b57fc06..1a1ed1a 100644
--- a/plugins/file-manager/file-view.c
+++ b/plugins/file-manager/file-view.c
@@ -47,6 +47,8 @@ struct _AnjutaFileViewPrivate
GList* saved_paths;
GtkTreeRowReference* current_selection;
+
+ GFile* pending_selected_file;
};
GtkTargetEntry uri_targets[] =
@@ -150,6 +152,129 @@ file_view_get_selected (AnjutaFileView* view)
}
static void
+file_view_select_iter (AnjutaFileView* view, GtkTreeIter iter)
+{
+ GtkTreeModelSort* model_sort;
+ GtkTreeIter sort_iter;
+ GtkTreeSelection* selection;
+ GtkTreePath* path;
+
+ model_sort = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ gtk_tree_model_sort_convert_child_iter_to_iter (model_sort, &sort_iter, &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model_sort), &sort_iter);
+
+ gtk_tree_selection_select_iter (selection, &sort_iter);
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL, TRUE, 0.5, 0.0);
+}
+
+static void
+file_view_select_from_iter (AnjutaFileView* view, GtkTreeIter iter)
+{
+ AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view);
+
+ GtkTreeModelSort* model_sort;
+ gboolean valid;
+ GtkTreeIter sort_iter;
+ GFile* file;
+
+ model_sort = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
+
+ do
+ {
+ gboolean is_dummy, is_dir;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->model), &iter,
+ COLUMN_FILE, &file, COLUMN_DUMMY, &is_dummy,
+ COLUMN_IS_DIR, &is_dir, -1);
+
+ if (is_dummy)
+ break;
+
+ if (g_file_equal (priv->pending_selected_file, file))
+ {
+ file_view_select_iter (view, iter);
+ break;
+ }
+
+ else if (g_file_has_prefix (priv->pending_selected_file, file))
+ {
+ if (is_dir)
+ {
+ GtkTreePath *path = NULL;
+
+ gtk_tree_model_sort_convert_child_iter_to_iter (model_sort, &sort_iter, &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model_sort), &sort_iter);
+
+ if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path))
+ {
+ GtkTreeIter parent = iter;
+ valid = gtk_tree_model_iter_children (GTK_TREE_MODEL (priv->model), &iter, &parent);
+ gtk_tree_path_free (path);
+ }
+ else
+ {
+ gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE);
+ gtk_tree_path_free (path);
+ break;
+ }
+ }
+ else
+ {
+ file_view_select_iter (view, iter);
+ break;
+ }
+ }
+ else
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->model), &iter);
+
+ g_clear_object (&file);
+
+ } while (valid);
+
+ if (file)
+ g_object_unref (file);
+}
+
+static void
+file_view_directory_expanded (FileModel* model, GtkTreeIter* iter, GtkTreePath* path,
+ gpointer user_data)
+{
+ AnjutaFileView* view = user_data;
+ AnjutaFileViewPrivate *priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view);
+
+ if (priv->pending_selected_file)
+ {
+ GFile *dir;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->model), iter,
+ COLUMN_FILE, &dir, -1);
+
+ if (g_file_has_prefix (priv->pending_selected_file, dir))
+ file_view_select_from_iter (view, *iter);
+
+ g_object_unref (dir);
+ }
+}
+
+void
+file_view_set_selected (AnjutaFileView* view, GFile *selected)
+{
+ AnjutaFileViewPrivate *priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view);
+
+ GtkTreeIter iter;
+ gboolean valid;
+
+ g_clear_object (&priv->pending_selected_file);
+ priv->pending_selected_file = g_object_ref (selected);
+
+ valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->model), &iter);
+ if (valid)
+ file_view_select_from_iter (view, iter);
+}
+
+static void
file_view_drag_data_get (GtkWidget* widget,
GdkDragContext *drag_context,
GtkSelectionData *data,
@@ -438,6 +563,11 @@ file_view_selection_changed (GtkTreeSelection* selection, AnjutaFileView* view)
g_signal_emit_by_name (G_OBJECT (view), "current-file-changed",
NULL, NULL);
}
+
+ /* The pending selection is now either done or if the user changed the
+ * selection before it was finished we cancel it. */
+ g_clear_object (&priv->pending_selected_file);
+
DEBUG_PRINT ("%s", "selection_changed");
}
@@ -648,7 +778,10 @@ file_view_init (AnjutaFileView *object)
priv->current_selection = NULL;
priv->model = file_model_new (GTK_TREE_VIEW(object), NULL);
- sort_model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(priv->model));
+ g_signal_connect_object (priv->model, "directory-expanded",
+ G_CALLBACK (file_view_directory_expanded), object, 0);
+
+ sort_model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(priv->model));
gtk_tree_view_set_model (GTK_TREE_VIEW(object), sort_model);
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE(sort_model),
diff --git a/plugins/file-manager/file-view.h b/plugins/file-manager/file-view.h
index 1940bc7..5c4e6f5 100644
--- a/plugins/file-manager/file-view.h
+++ b/plugins/file-manager/file-view.h
@@ -74,6 +74,9 @@ GFile*
file_view_get_selected (AnjutaFileView* view);
void
+file_view_set_selected (AnjutaFileView* view, GFile *selected);
+
+void
file_view_refresh (AnjutaFileView* view);
void
diff --git a/plugins/file-manager/org.gnome.anjuta.file-manager.gschema.xml.in b/plugins/file-manager/org.gnome.anjuta.file-manager.gschema.xml.in
index 54cb68d..96f3d78 100644
--- a/plugins/file-manager/org.gnome.anjuta.file-manager.gschema.xml.in
+++ b/plugins/file-manager/org.gnome.anjuta.file-manager.gschema.xml.in
@@ -15,5 +15,8 @@
<key name="filemanager-filter-unversioned" type="b">
<default>false</default>
</key>
+ <key name="filemanager-select-current-document" type="b">
+ <default>false</default>
+ </key>
</schema>
</schemalist>
\ No newline at end of file
diff --git a/plugins/file-manager/plugin.c b/plugins/file-manager/plugin.c
index ab5e758..5d73ce9 100644
--- a/plugins/file-manager/plugin.c
+++ b/plugins/file-manager/plugin.c
@@ -32,6 +32,9 @@
#include <libanjuta/interfaces/ianjuta-vcs.h>
#include <libanjuta/interfaces/ianjuta-project-manager.h>
#include <libanjuta/interfaces/ianjuta-preferences.h>
+#include <libanjuta/interfaces/ianjuta-document.h>
+#include <libanjuta/interfaces/ianjuta-document-manager.h>
+#include <libanjuta/interfaces/ianjuta-file.h>
#include "plugin.h"
#define UI_FILE PACKAGE_DATA_DIR"/ui/file-manager.xml"
@@ -45,6 +48,7 @@
#define PREF_FILTER_HIDDEN "filemanager-filter-hidden"
#define PREF_FILTER_BACKUP "filemanager-filter-backup"
#define PREF_FILTER_UNVERSIONED "filemanager-filter-unversioned"
+#define PREF_SELECT_CURRENT_DOCUMENT "filemanager-select-current-document"
#define REGISTER_NOTIFY(key, func) \
notify_id = anjuta_preferences_notify_add (prefs, \
@@ -163,6 +167,32 @@ get_vcs_plugin(AnjutaFileManager* file_manager, const gchar* root_uri)
}
static void
+current_document_added (AnjutaPlugin *plugin, const gchar *name,
+ const GValue *value, gpointer user_data)
+{
+ AnjutaFileManager* file_manager = (AnjutaFileManager*) plugin;
+ IAnjutaDocument *current_document;
+
+ if (!g_settings_get_boolean (file_manager->settings, PREF_SELECT_CURRENT_DOCUMENT))
+ return;
+
+ current_document = g_value_get_object (value);
+
+ if (IANJUTA_IS_FILE (current_document))
+ {
+ GFile *file = ianjuta_file_get_file (IANJUTA_FILE (current_document), NULL);
+ ianjuta_file_manager_set_selected (IANJUTA_FILE_MANAGER (plugin), file, NULL);
+ g_object_unref (file);
+ }
+}
+
+static void
+current_document_removed (AnjutaPlugin *plugin, const gchar *name,
+ gpointer user_data)
+{
+}
+
+static void
project_root_added (AnjutaPlugin *plugin, const gchar *name,
const GValue *value, gpointer user_data)
{
@@ -347,6 +377,10 @@ file_manager_activate (AnjutaPlugin *plugin)
anjuta_plugin_add_watch (plugin, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI,
project_root_added,
project_root_removed, NULL);
+
+ file_manager->current_document_watch_id =
+ anjuta_plugin_add_watch (plugin, IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT,
+ current_document_added, current_document_removed, NULL);
g_signal_connect (file_manager->settings, "changed::" PREF_ROOT,
@@ -376,6 +410,7 @@ file_manager_deactivate (AnjutaPlugin *plugin)
ui = anjuta_shell_get_ui (plugin->shell, NULL);
anjuta_plugin_remove_watch (plugin, file_manager->root_watch_id, TRUE);
+ anjuta_plugin_remove_watch (plugin, file_manager->current_document_watch_id, FALSE);
anjuta_ui_remove_action_group (ui, ((AnjutaFileManager*)plugin)->action_group);
anjuta_ui_unmerge (ui, ((AnjutaFileManager*)plugin)->uiid);
@@ -436,10 +471,12 @@ ifile_manager_set_root (IAnjutaFileManager *ifile_manager, const gchar *root,
}
static void
-ifile_manager_set_selected (IAnjutaFileManager *file_manager,
+ifile_manager_set_selected (IAnjutaFileManager *ifile_manager,
GFile* selected, GError **err)
{
- /* TODO */
+ AnjutaFileManager* file_manager = (AnjutaFileManager*) ifile_manager;
+
+ file_view_set_selected (file_manager->fv, selected);
}
static GFile*
diff --git a/plugins/file-manager/plugin.h b/plugins/file-manager/plugin.h
index 7f9e4fa..17709fc 100644
--- a/plugins/file-manager/plugin.h
+++ b/plugins/file-manager/plugin.h
@@ -51,6 +51,8 @@ struct _AnjutaFileManager {
gint uiid;
GtkActionGroup *action_group;
GSettings* settings;
+
+ guint current_document_watch_id;
};
struct _AnjutaFileManagerClass {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]