Procházet zdrojové kódy

Ajout d'un champ de recherche et d'un callback

Thomas Arnoux před 3 měsíci
rodič
revize
6b7b9f489e
2 změnil soubory, kde provedl 32 přidání a 8 odebrání
  1. 26 8
      src/oupis-window.c
  2. 6 0
      src/oupis-window.ui

+ 26 - 8
src/oupis-window.c

@@ -24,25 +24,43 @@
 
 struct _OupisWindow
 {
-	AdwApplicationWindow  parent_instance;
+  AdwApplicationWindow  parent_instance;
 
-	/* Template widgets */
-	GtkLabel            *label;
+  /* Template widgets */
+  GtkSearchEntry      *searchentry;
+  GtkLabel            *label;
 };
 
 G_DEFINE_FINAL_TYPE (OupisWindow, oupis_window, ADW_TYPE_APPLICATION_WINDOW)
 
 static void
-oupis_window_class_init (OupisWindowClass *klass)
+oupis_window__search_request (GtkSearchEntry *self,
+                              gpointer        userdata)
 {
-	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  char* request;
+  request = gtk_editable_get_text (GTK_EDITABLE (self));
+  g_print ("%s\n", request);
+}
 
-	gtk_widget_class_set_template_from_resource (widget_class, "/lu/arnoux/Oupis/oupis-window.ui");
-	gtk_widget_class_bind_template_child (widget_class, OupisWindow, label);
+static void
+oupis_window_class_init (OupisWindowClass *klass)
+  {
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/lu/arnoux/Oupis/oupis-window.ui");
+  gtk_widget_class_bind_template_child (widget_class, OupisWindow, searchentry);
+  gtk_widget_class_bind_template_child (widget_class, OupisWindow, label);
 }
 
 static void
 oupis_window_init (OupisWindow *self)
 {
-	gtk_widget_init_template (GTK_WIDGET (self));
+  gtk_widget_init_template (GTK_WIDGET (self) );
+
+  GtkSearchEntry *searchentry = GTK_SEARCH_ENTRY (self->searchentry);
+  g_signal_connect (searchentry,
+                    "activate",
+                    G_CALLBACK (oupis_window__search_request),
+                    self);
+
 }

+ 6 - 0
src/oupis-window.ui

@@ -10,6 +10,12 @@
       <object class="AdwToolbarView">
         <child type="top">
           <object class="AdwHeaderBar">
+            <child type="start">
+              <object class="GtkSearchEntry" id="searchentry">
+                <property name="placeholder-text">Rechercher…</property>
+                <property name="margin-start">10</property>
+              </object>
+            </child>
             <child type="end">
               <object class="GtkMenuButton">
                 <property name="primary">True</property>