[gtksourceview/wip/chergert/vim] open a test file



commit 95052e84b0f4ed8666eb57637aea3b5765583ea4
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 25 19:08:24 2021 -0700

    open a test file

 tests/test-vim.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/tests/test-vim.c b/tests/test-vim.c
index 88269c1c..3077fad6 100644
--- a/tests/test-vim.c
+++ b/tests/test-vim.c
@@ -23,6 +23,37 @@
 
 #include <gtksourceview/gtksource.h>
 
+static void
+load_cb (GObject      *object,
+         GAsyncResult *result,
+         gpointer      user_data)
+{
+       GtkTextBuffer *buffer = user_data;
+       GtkTextIter iter;
+
+       gtk_text_buffer_get_start_iter (buffer, &iter);
+       gtk_text_buffer_select_range (buffer, &iter, &iter);
+}
+
+static void
+open_file (GtkSourceBuffer *buffer,
+           GFile           *file)
+{
+       GtkSourceFileLoader *loader;
+       GtkSourceFile *sfile;
+
+       sfile = gtk_source_file_new ();
+       gtk_source_file_set_location (sfile, file);
+       loader = gtk_source_file_loader_new (buffer, sfile);
+
+       gtk_source_file_loader_load_async (loader,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL, NULL, NULL, NULL, load_cb, buffer);
+
+       g_object_unref (sfile);
+       g_object_unref (loader);
+}
+
 static gboolean
 on_close_request (GtkWindow *window,
                   GMainLoop *main_loop)
@@ -45,6 +76,7 @@ main (int argc,
        GtkEventController *key;
        GtkSourceBuffer *buffer;
        GtkText *command_bar;
+       GFile *file;
 
        gtk_init ();
        gtk_source_init ();
@@ -90,6 +122,9 @@ main (int argc,
        g_signal_connect (window, "close-request", G_CALLBACK (on_close_request), main_loop);
        gtk_window_present (window);
 
+       file = g_file_new_for_path (TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
+       open_file (buffer, file);
+
        g_main_loop_run (main_loop);
 
        gtk_source_finalize ();


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