[gnome-builder] editor: use the new ide_file_find_other_async()/finish() pair
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: use the new ide_file_find_other_async()/finish() pair
- Date: Wed, 1 Apr 2015 07:56:31 +0000 (UTC)
commit 3f365612502a5797715c37c7c53e0635fbfec804
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 1 00:38:15 2015 -0700
editor: use the new ide_file_find_other_async()/finish() pair
src/editor/gb-editor-view-actions.c | 103 ++++-------------------------------
1 files changed, 11 insertions(+), 92 deletions(-)
---
diff --git a/src/editor/gb-editor-view-actions.c b/src/editor/gb-editor-view-actions.c
index 014ae6b..7901936 100644
--- a/src/editor/gb-editor-view-actions.c
+++ b/src/editor/gb-editor-view-actions.c
@@ -492,106 +492,25 @@ gb_editor_view_actions_close (GSimpleAction *action,
}
}
-static gboolean
-has_suffix (const gchar *path,
- const gchar * const *allowed_suffixes)
-{
- const gchar *dot;
- gsize i;
-
- dot = strrchr (path, '.');
- if (!dot)
- return FALSE;
-
- dot++;
-
- for (i = 0; allowed_suffixes [i]; i++)
- {
- if (g_str_equal (dot, allowed_suffixes [i]))
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-gb_editor_view_actions_find_other_file_worker (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GbEditorView *self = source_object;
- const gchar *src_suffixes[] = { "c", "cc", "cpp", "cxx", NULL };
- const gchar *hdr_suffixes[] = { "h", "hh", "hpp", "hxx", NULL };
- const gchar **target = NULL;
- IdeFile *file;
- g_autofree gchar *prefix = NULL;
- const gchar *path;
- gsize i;
-
- g_assert (GB_IS_EDITOR_VIEW (self));
-
- file = ide_buffer_get_file (IDE_BUFFER (self->document));
- path = ide_file_get_path (file);
-
- if (has_suffix (path, src_suffixes))
- {
- target = hdr_suffixes;
- }
- else if (has_suffix (path, hdr_suffixes))
- {
- target = src_suffixes;
- }
- else
- {
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_INVALID_FILENAME,
- "File is missing a suffix.");
- return;
- }
-
- prefix = g_strndup (path, strrchr (path, '.') - path);
-
- for (i = 0; target [i]; i++)
- {
- g_autofree gchar *new_path = NULL;
-
- new_path = g_strdup_printf ("%s.%s", prefix, target [i]);
-
- if (g_file_test (new_path, G_FILE_TEST_IS_REGULAR))
- {
- g_autoptr(GFile) gfile = NULL;
-
- gfile = g_file_new_for_path (new_path);
- g_task_return_pointer (task, g_object_ref (gfile), g_object_unref);
- return;
- }
- }
-
- g_task_return_new_error (task,
- G_IO_ERROR,
- G_IO_ERROR_NOT_FOUND,
- "Failed to locate other file.");
-}
-
static void
find_other_file_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- GbEditorView *self = (GbEditorView *)object;
- GTask *task = (GTask *)result;
- g_autoptr(GFile) ret = NULL;
+ g_autoptr(GbEditorView) self = user_data;
+ g_autoptr(IdeFile) ret = NULL;
+ IdeFile *file = (IdeFile *)object;
- ret = g_task_propagate_pointer (task, NULL);
+ ret = ide_file_find_other_finish (file, result, NULL);
- if (ret)
+ if (ret != NULL)
{
GbWorkbench *workbench;
+ GFile *gfile;
+ gfile = ide_file_get_file (ret);
workbench = gb_widget_get_workbench (GTK_WIDGET (self));
- gb_workbench_open (workbench, ret);
+ gb_workbench_open (workbench, gfile);
}
}
@@ -601,12 +520,12 @@ gb_editor_view_actions_find_other_file (GSimpleAction *action,
gpointer user_data)
{
GbEditorView *self = user_data;
- g_autoptr(GTask) task = NULL;
+ IdeFile *file;
g_assert (GB_IS_EDITOR_VIEW (self));
- task = g_task_new (self, NULL, find_other_file_cb, NULL);
- g_task_run_in_thread (task, gb_editor_view_actions_find_other_file_worker);
+ file = ide_buffer_get_file (IDE_BUFFER (self->document));
+ ide_file_find_other_async (file, NULL, find_other_file_cb, g_object_ref (self));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]