[ghex/gtk4-port: 66/91] Commence 'New document' WIP.




commit 23008a2618b613359e0b9420eb27d51748e8ca8c
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Jan 29 14:55:12 2021 -0500

    Commence 'New document' WIP.

 src/ghex-application-window.c  | 21 +++++++++++++++++++++
 src/ghex-application-window.ui |  4 ++++
 src/gtkhex.c                   | 26 +++++++++-----------------
 3 files changed, 34 insertions(+), 17 deletions(-)
---
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 8834a680..a2f87654 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -1121,6 +1121,23 @@ do_print (GtkWidget *widget,
        common_print (GTK_WINDOW(self), self->gh, /* preview: */ FALSE);
 }
 
+static void
+new_file (GtkWidget *widget,
+               const char *action_name,
+               GVariant *parameter)
+{
+       GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(widget);
+       HexDocument *doc;
+       GtkHex *gh;
+
+       doc = hex_document_new ();
+       gh = GTK_HEX(gtk_hex_new (doc));
+
+       ghex_application_window_add_hex (self, gh);
+       ghex_application_window_set_hex (self, gh);
+       ghex_application_window_activate_tab (self, gh);
+}
+
 /* convenience helper function to build a GtkHex widget pre-loaded with
  * a hex document, from a GFile *.
  */
@@ -1880,6 +1897,10 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
 
        /* ACTIONS */
 
+       gtk_widget_class_install_action (widget_class, "ghex.new",
+                       NULL,   /* GVariant string param_type */
+                       new_file);
+
        gtk_widget_class_install_action (widget_class, "ghex.open",
                        NULL,   /* GVariant string param_type */
                        open_file);
diff --git a/src/ghex-application-window.ui b/src/ghex-application-window.ui
index b206b597..b5fa3168 100644
--- a/src/ghex-application-window.ui
+++ b/src/ghex-application-window.ui
@@ -27,6 +27,10 @@
        <menu id="hamburger_menu">
                <!-- "FILE" -->
                <section>
+                       <item>
+                               <attribute name="label" translatable="yes">_New</attribute>
+                               <attribute name="action">ghex.new</attribute>
+                       </item>
                        <item>
                                <attribute name="label" translatable="yes">Save _As</attribute>
                                <attribute name="action">ghex.save-as</attribute>
diff --git a/src/gtkhex.c b/src/gtkhex.c
index bc0d8eb1..2713b8ba 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -2422,38 +2422,30 @@ static void
 gtk_hex_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
 {
        GtkHex *gh = GTK_HEX(widget);
-       graphene_rect_t rect;
-       float width, height;
-       cairo_t *cr;
        GtkWidget *child;
+       float height;
 
        /* Update character width & height */
        gh->char_width = get_char_width(gh);
        gh->char_height = get_char_height(gh);
 
        /* Get cpl from layout manager */
-       gh->cpl = gtk_hex_layout_get_cpl (GTK_HEX_LAYOUT(gh->layout_manager));
-
-       /* get width and height, implicitly converted to floats so we can pass
-        * to graphene_rect_init below. */
-       width = gtk_widget_get_allocated_width (widget);
        height = gtk_widget_get_allocated_height (widget);
+       gh->cpl = gtk_hex_layout_get_cpl (GTK_HEX_LAYOUT(gh->layout_manager));
 
        /* set visible lines - do this here and now as we can use the height
         * of the widget as a whole.  */
        gh->vis_lines = height / gh->char_height;
 
-       /* get a graphene rect so we can pass it to the next function and draw
-        * with cairo, which is all we want to do anyway. */
-       graphene_rect_init (&rect,
-               /* float x: */  0.0f,
-               /* float y: */  0.0f,
-                       width, height);
-
-       cr = gtk_snapshot_append_cairo (snapshot, &rect);
-
        /* queue child draw functions
         */
+
+       /* manually specify these as sometimes _snapshot_child doesn't `think'
+        * they need to be redrawn. */
+       gtk_widget_queue_draw (gh->offsets);
+       gtk_widget_queue_draw (gh->xdisp);
+       gtk_widget_queue_draw (gh->adisp);
+
        for (child = gtk_widget_get_first_child (widget);
                        child != NULL;
                        child = gtk_widget_get_next_sibling (child))


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