[gnome-builder] project-tree: track various changes to libide and workbench



commit a6914afdf190d56a2895fe9bc51151ccb433de39
Author: Christian Hergert <christian hergert me>
Date:   Wed Jun 17 16:01:10 2015 -0700

    project-tree: track various changes to libide and workbench

 libide/ide-buffer-manager.c                |   10 +-
 libide/ide-buffer-manager.h                |    4 +-
 libide/ide-project.c                       |   78 +++--------------
 src/project-tree/gb-project-tree-actions.c |  131 +++++++++-------------------
 src/workbench/gb-workbench.c               |   22 +++++-
 tests/test-ide-source-view.c               |    4 +-
 6 files changed, 83 insertions(+), 166 deletions(-)
---
diff --git a/libide/ide-buffer-manager.c b/libide/ide-buffer-manager.c
index 4d5cff4..a66385e 100644
--- a/libide/ide-buffer-manager.c
+++ b/libide/ide-buffer-manager.c
@@ -1465,7 +1465,7 @@ ide_buffer_manager_get_word_completion (IdeBufferManager *self)
 /**
  * ide_buffer_manager_find_buffer:
  * @self: (in): An #IdeBufferManager.
- * @file: (in): An #IdeFile.
+ * @file: (in): A #GFile.
  *
  * Gets the buffer for a given file. If it has not yet been loaded, %NULL is
  * returned.
@@ -1474,12 +1474,12 @@ ide_buffer_manager_get_word_completion (IdeBufferManager *self)
  */
 IdeBuffer *
 ide_buffer_manager_find_buffer (IdeBufferManager *self,
-                                IdeFile          *file)
+                                GFile            *file)
 {
   gsize i;
 
   g_return_val_if_fail (IDE_IS_BUFFER_MANAGER (self), NULL);
-  g_return_val_if_fail (IDE_IS_FILE (file), NULL);
+  g_return_val_if_fail (G_IS_FILE (file), NULL);
 
   for (i = 0; i < self->buffers->len; i++)
     {
@@ -1489,7 +1489,7 @@ ide_buffer_manager_find_buffer (IdeBufferManager *self,
       buffer = g_ptr_array_index (self->buffers, i);
       buffer_file = ide_buffer_get_file (buffer);
 
-      if (ide_file_equal (buffer_file, file))
+      if (g_file_equal (file, ide_file_get_file (buffer_file)))
         return buffer;
     }
 
@@ -1507,7 +1507,7 @@ ide_buffer_manager_find_buffer (IdeBufferManager *self,
  */
 gboolean
 ide_buffer_manager_has_file (IdeBufferManager *self,
-                             IdeFile          *file)
+                             GFile            *file)
 {
   return !!ide_buffer_manager_find_buffer (self, file);
 }
diff --git a/libide/ide-buffer-manager.h b/libide/ide-buffer-manager.h
index 5705a3d..1c37516 100644
--- a/libide/ide-buffer-manager.h
+++ b/libide/ide-buffer-manager.h
@@ -65,9 +65,9 @@ GPtrArray                *ide_buffer_manager_get_buffers         (IdeBufferManag
 GtkSourceCompletionWords *ide_buffer_manager_get_word_completion (IdeBufferManager     *self);
 guint                     ide_buffer_manager_get_n_buffers       (IdeBufferManager     *self);
 gboolean                  ide_buffer_manager_has_file            (IdeBufferManager     *self,
-                                                                  IdeFile              *file);
+                                                                  GFile                *file);
 IdeBuffer                *ide_buffer_manager_find_buffer         (IdeBufferManager     *self,
-                                                                  IdeFile              *file);
+                                                                  GFile                *file);
 gsize                     ide_buffer_manager_get_max_file_size   (IdeBufferManager     *self);
 void                      ide_buffer_manager_set_max_file_size   (IdeBufferManager     *self,
                                                                   gsize                 max_file_size);
diff --git a/libide/ide-project.c b/libide/ide-project.c
index d6feefe..5da4160 100644
--- a/libide/ide-project.c
+++ b/libide/ide-project.c
@@ -427,12 +427,9 @@ ide_project_rename_file_worker (GTask        *task,
                                 GCancellable *cancellable)
 {
   IdeProject *self = source_object;
-  IdeProjectFiles *files;
-  IdeProjectItem *item;
   IdeContext *context;
   IdeVcs *vcs;
   RenameFile *op = task_data;
-  g_autoptr(GFileInfo) file_info = NULL;
   g_autofree gchar *path = NULL;
   GError *error = NULL;
   GFile *workdir;
@@ -443,9 +440,6 @@ ide_project_rename_file_worker (GTask        *task,
   g_assert (G_IS_FILE (op->new_file));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  ide_project_writer_lock (self);
-
-  files = ide_project_get_files (self);
   context = ide_object_get_context (IDE_OBJECT (self));
   vcs = ide_context_get_vcs (context);
   workdir = ide_vcs_get_working_directory (vcs);
@@ -467,54 +461,22 @@ ide_project_rename_file_worker (GTask        *task,
                                G_IO_ERROR,
                                G_IO_ERROR_INVALID_FILENAME,
                                _("Destination file must be within the project tree."));
-      goto cleanup;
-    }
-
-  item = ide_project_files_find_file (files, op->orig_file);
-
-  if (item == NULL)
-    {
-      g_task_return_new_error (task,
-                               G_IO_ERROR,
-                               G_IO_ERROR_INVALID_FILENAME,
-                               _("Source file must be within the project tree."));
-      goto cleanup;
-    }
-
-  if (!g_file_move (op->orig_file, op->new_file, G_FILE_COPY_NONE, cancellable, NULL, NULL, &error))
-    {
-      g_task_return_error (task, error);
-      goto cleanup;
+      return;
     }
 
-  file_info = g_file_query_info (op->new_file,
-                                 G_FILE_ATTRIBUTE_STANDARD_NAME","
-                                 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME","
-                                 G_FILE_ATTRIBUTE_STANDARD_TYPE,
-                                 G_FILE_QUERY_INFO_NONE,
-                                 cancellable,
-                                 &error);
-
-  if (file_info == NULL)
+  if (!g_file_move (op->orig_file,
+                    op->new_file,
+                    G_FILE_COPY_NONE,
+                    cancellable,
+                    NULL,
+                    NULL,
+                    &error))
     {
       g_task_return_error (task, error);
-      goto cleanup;
+      return;
     }
 
-  g_object_ref (item);
-  ide_project_item_remove (ide_project_item_get_parent (item), item);
-  g_object_set (item,
-                "file", op->new_file,
-                "path", path,
-                "file-info", file_info,
-                NULL);
-  ide_project_files_add_file (files, IDE_PROJECT_FILE (item));
-  g_object_unref (item);
-
   g_task_return_boolean (task, TRUE);
-
-cleanup:
-  ide_project_writer_unlock (self);
 }
 
 static void
@@ -575,31 +537,15 @@ ide_project_trash_file__file_trash_cb (GObject      *object,
 {
   GFile *file = (GFile *)object;
   g_autoptr(GTask) task = user_data;
-  IdeProject *self;
-  IdeProjectFiles *files;
-  IdeProjectItem *item;
   GError *error = NULL;
 
   g_assert (G_IS_FILE (file));
   g_assert (G_IS_TASK (task));
 
-  self = g_task_get_source_object (task);
-  g_assert (IDE_IS_PROJECT (self));
-
   if (!g_file_trash_finish (file, result, &error))
-    {
-      g_task_return_error (task, error);
-      return;
-    }
-
-  ide_project_writer_lock (self);
-  files = ide_project_get_files (self);
-  item = ide_project_files_find_file (files, file);
-  if (item != NULL)
-    ide_project_item_remove (ide_project_item_get_parent (item), item);
-  ide_project_writer_unlock (self);
-
-  g_task_return_boolean (task, TRUE);
+    g_task_return_error (task, error);
+  else
+    g_task_return_boolean (task, TRUE);
 }
 
 static gboolean
diff --git a/src/project-tree/gb-project-tree-actions.c b/src/project-tree/gb-project-tree-actions.c
index 411b1a5..77095ce 100644
--- a/src/project-tree/gb-project-tree-actions.c
+++ b/src/project-tree/gb-project-tree-actions.c
@@ -361,16 +361,9 @@ gb_project_tree_actions__make_directory_cb (GObject      *object,
                                             GAsyncResult *result,
                                             gpointer      user_data)
 {
-#if 0
   GFile *file = (GFile *)object;
   g_autoptr(GbTreeNode) node = user_data;
   g_autoptr(GError) error = NULL;
-  g_autoptr(IdeProjectFile) project_file = NULL;
-  GbProjectTree *self;
-  GbWorkbench *workbench;
-  IdeContext *context;
-  IdeProject *project;
-  GbTreeNode *created;
 
   g_assert (G_IS_FILE (file));
   g_assert (GB_IS_TREE_NODE (node));
@@ -381,31 +374,9 @@ gb_project_tree_actions__make_directory_cb (GObject      *object,
       return;
     }
 
-  self = GB_PROJECT_TREE (gb_tree_node_get_tree (node));
-  if (self == NULL)
-    return;
-
-  workbench = gb_widget_get_workbench (GTK_WIDGET (self));
-  if (workbench == NULL)
-    return;
-
-  context = gb_workbench_get_context (workbench);
-  if (context == NULL)
-    return;
-
-  project = ide_context_get_project (context);
-
-  project_file = create_file (context, file, G_FILE_TYPE_DIRECTORY);
-  ide_project_add_file (project, project_file);
-
   gb_tree_node_invalidate (node);
   gb_tree_node_expand (node, FALSE);
-
-  created = gb_tree_find_item (GB_TREE (self), G_OBJECT (project_file));
-
-  if (created != NULL)
-    gb_tree_node_select (created);
-#endif
+  gb_tree_node_select (node);
 }
 
 static void
@@ -413,16 +384,11 @@ gb_project_tree_actions__create_cb (GObject      *object,
                                     GAsyncResult *result,
                                     gpointer      user_data)
 {
-#if 0
   GFile *file = (GFile *)object;
-  g_autoptr(IdeProjectFile) project_file = NULL;
   g_autoptr(GbTreeNode) node = user_data;
   g_autoptr(GError) error = NULL;
   GbProjectTree *self;
   GbWorkbench *workbench;
-  IdeContext *context;
-  IdeProject *project;
-  GbTreeNode *created;
 
   g_assert (G_IS_FILE (file));
   g_assert (GB_IS_TREE_NODE (node));
@@ -441,29 +407,11 @@ gb_project_tree_actions__create_cb (GObject      *object,
   if (workbench == NULL)
     return;
 
-  context = gb_workbench_get_context (workbench);
-  if (context == NULL)
-    return;
-
-  project = ide_context_get_project (context);
-
-  project_file = create_file (context, file, G_FILE_TYPE_REGULAR);
-  ide_project_add_file (project, project_file);
-
   gb_workbench_open (workbench, file);
 
   gb_tree_node_invalidate (node);
   gb_tree_node_expand (node, FALSE);
-
-  created = gb_tree_find_item (GB_TREE (self), G_OBJECT (project_file));
-
-  if (created != NULL)
-    gb_tree_node_select (created);
-#endif
-
-  /*
-   * TODO: Invalidate parent.
-   */
+  gb_tree_node_select (node);
 }
 
 static void
@@ -620,6 +568,24 @@ gb_project_tree_actions_new_file (GSimpleAction *action,
   gb_project_tree_actions_new (self, G_FILE_TYPE_REGULAR);
 }
 
+static gboolean
+find_child_node (GbTree     *tree,
+                 GbTreeNode *parent,
+                 GbTreeNode *child,
+                 gpointer    user_data)
+{
+  GObject *item = gb_tree_node_get_item (child);
+  GFile *target = user_data;
+  GFile *child_file;
+
+  if (GB_IS_PROJECT_FILE (item) &&
+      (child_file = gb_project_file_get_file (GB_PROJECT_FILE (item))) &&
+      g_file_equal (child_file, target))
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 gb_project_tree_actions__project_rename_file_cb (GObject      *object,
                                                  GAsyncResult *result,
@@ -653,11 +619,14 @@ gb_project_tree_actions__project_rename_file_cb (GObject      *object,
   parent = gb_tree_node_get_parent (node);
 
   gb_tree_node_invalidate (parent);
-  gb_tree_node_expand (parent, TRUE);
+  gb_tree_node_expand (parent, FALSE);
 
-  /*
-   * TODO: Reselect child node.
-   */
+  node = gb_tree_find_child_node (tree, parent, find_child_node, file);
+
+  if (node != NULL)
+    gb_tree_node_select (node);
+  else
+    gb_tree_node_select (parent);
 
   gtk_widget_hide (GTK_WIDGET (popover));
   gtk_widget_destroy (GTK_WIDGET (popover));
@@ -737,13 +706,12 @@ gb_project_tree_actions__trash_file_cb (GObject      *object,
                                         gpointer      user_data)
 {
   IdeProject *project = (IdeProject *)object;
-  g_autoptr(GbProjectTree) self = user_data;
+  g_autoptr(GbTreeNode) node = user_data;
   g_autoptr(GError) error = NULL;
-  GbTreeNode *node;
-  GObject *item = NULL;
+  GbTreeNode *parent;
 
   g_assert (IDE_IS_PROJECT (project));
-  g_assert (GB_IS_PROJECT_TREE (self));
+  g_assert (GB_IS_TREE_NODE (node));
 
   if (!ide_project_trash_file_finish (project, result, &error))
     {
@@ -752,28 +720,12 @@ gb_project_tree_actions__trash_file_cb (GObject      *object,
       return;
     }
 
-  /* todo: this should be done with tree observer */
-  if ((node = gb_tree_get_selected (GB_TREE (self))))
+  if ((parent = gb_tree_node_get_parent (node)))
     {
-      if ((node = gb_tree_node_get_parent (node)))
-        item = gb_tree_node_get_item (node);
+      gb_tree_node_invalidate (parent);
+      gb_tree_node_expand (parent, FALSE);
+      gb_tree_node_select (parent);
     }
-
-  gb_tree_rebuild (GB_TREE (self));
-
-  if ((node = gb_tree_find_item (GB_TREE (self), item)))
-    gb_tree_node_expand (node, TRUE);
-}
-
-static GbViewStack *
-get_view_stack (GbView *view)
-{
-  GtkWidget *widget = (GtkWidget *)view;
-
-  while ((widget != NULL) && !GB_IS_VIEW_STACK (widget))
-    widget = gtk_widget_get_parent (widget);
-
-  return (GbViewStack *)widget;
 }
 
 typedef struct
@@ -814,7 +766,6 @@ gb_project_tree_actions_move_to_trash (GSimpleAction *action,
   IdeProject *project;
   GbTreeNode *node;
   GFile *file;
-  IdeFile *ifile;
   GObject *item;
   GList *iter;
 
@@ -828,7 +779,7 @@ gb_project_tree_actions_move_to_trash (GSimpleAction *action,
 
   if (!(node = gb_tree_get_selected (GB_TREE (self))) ||
       !(item = gb_tree_node_get_item (node)) ||
-      !IDE_IS_PROJECT_FILE (item) ||
+      !GB_IS_PROJECT_FILE (item) ||
       !(file = gb_project_file_get_file (GB_PROJECT_FILE (item))))
     return;
 
@@ -836,9 +787,7 @@ gb_project_tree_actions_move_to_trash (GSimpleAction *action,
    * Find all of the views that contain this file.
    * We do not close them until we leave the foreach callback.
    */
-  ifile = ide_project_get_project_file (project, file);
-  buffer = ide_buffer_manager_find_buffer (buffer_manager, ifile);
-  if (buffer != NULL)
+  if ((buffer = ide_buffer_manager_find_buffer (buffer_manager, file)))
     {
       removal.document = g_object_ref (buffer);
       gb_workbench_views_foreach (workbench,
@@ -852,11 +801,11 @@ gb_project_tree_actions_move_to_trash (GSimpleAction *action,
    */
   for (iter = removal.views; iter; iter = iter->next)
     {
-      GbViewStack *stack;
+      GtkWidget *stack;
 
-      stack = get_view_stack (iter->data);
+      stack = gtk_widget_get_ancestor (iter->data, GB_TYPE_VIEW_STACK);
       if (stack != NULL)
-        gb_view_stack_remove (stack, iter->data);
+        gb_view_stack_remove (GB_VIEW_STACK (stack), iter->data);
     }
 
   g_list_free_full (removal.views, g_object_unref);
@@ -868,7 +817,7 @@ gb_project_tree_actions_move_to_trash (GSimpleAction *action,
                                 file,
                                 NULL,
                                 gb_project_tree_actions__trash_file_cb,
-                                g_object_ref (self));
+                                g_object_ref (node));
 }
 
 static gboolean
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index d59ab2d..d6fdb65 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -1046,10 +1046,30 @@ gb_workbench_views_foreach (GbWorkbench *self,
                             GtkCallback  callback,
                             gpointer     callback_data)
 {
+  GList *stacks;
+  GList *iter;
+
   g_return_if_fail (GB_IS_WORKBENCH (self));
   g_return_if_fail (callback != NULL);
 
-  //gb_workspace_views_foreach (GB_WORKSPACE (self->editor_workspace), callback, callback_data);
+  stacks = gb_view_grid_get_stacks (self->view_grid);
+
+  for (iter = stacks; iter; iter = iter->next)
+    {
+      GList *views;
+      GList *views_iter;
+
+      views = gb_view_stack_get_views (iter->data);
+
+      for (views_iter = views; views_iter; views_iter = views_iter->next)
+        {
+          callback (views_iter->data, callback_data);
+        }
+
+      g_list_free (views);
+    }
+
+  g_list_free (stacks);
 }
 
 GtkWidget *
diff --git a/tests/test-ide-source-view.c b/tests/test-ide-source-view.c
index 3c1c6ae..1997a02 100644
--- a/tests/test-ide-source-view.c
+++ b/tests/test-ide-source-view.c
@@ -404,6 +404,7 @@ navigate_to_cb (IdeBackForwardList *list,
   IdeSourceLocation *srcloc;
   IdeBuffer *buffer;
   IdeFile *file;
+  GFile *gfile;
   guint line;
   guint line_offset;
 
@@ -411,9 +412,10 @@ navigate_to_cb (IdeBackForwardList *list,
   file = ide_source_location_get_file (srcloc);
   line = ide_source_location_get_line (srcloc);
   line_offset = ide_source_location_get_line_offset (srcloc);
+  gfile = ide_file_get_file (file);
 
   bufmgr = ide_context_get_buffer_manager (gContext);
-  buffer = ide_buffer_manager_find_buffer (bufmgr, file);
+  buffer = ide_buffer_manager_find_buffer (bufmgr, gfile);
 
   if (buffer)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]