Update gtk35

This commit is contained in:
daleclack 2021-01-19 13:32:31 +08:00
parent e27736ce23
commit 6ca3df73c3
2 changed files with 37 additions and 5 deletions

View File

@ -1,9 +1,27 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
void file_dialog(GtkWidget *widget,gpointer data){
GtkFileChooserAction action=GTK_FILE_CHOOSER_ACTION_OPEN;
GtkWidget *dialog=gtk_file_chooser_dialog_new("Open File",GTK_WINDOW(data),action,
"Cencel",GTK_RESPONSE_CANCEL,"OK",GTK_RESPONSE_OK,NULL);
gint res;
res=gtk_dialog_run(GTK_DIALOG(dialog));
if(res==GTK_RESPONSE_OK){
char *filename;
filename=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
g_print("%s\n",filename);
}
gtk_widget_destroy(dialog);
}
static void gtkmain(GtkApplication *app,gpointer user_data){ static void gtkmain(GtkApplication *app,gpointer user_data){
//Main window
GtkBuilder *builder=gtk_builder_new_from_file("window.ui"); GtkBuilder *builder=gtk_builder_new_from_file("window.ui");
GObject *window=gtk_builder_get_object(builder,"window"); GObject *window=gtk_builder_get_object(builder,"window");
gtk_application_add_window(app,GTK_WINDOW(window)); gtk_application_add_window(app,GTK_WINDOW(window));
//dialog button
GObject *btn_dialog=gtk_builder_get_object(builder,"btnchoose");
g_signal_connect(btn_dialog,"clicked",G_CALLBACK(file_dialog),window);
gtk_widget_show_all(GTK_WIDGET(window)); gtk_widget_show_all(GTK_WIDGET(window));
} }

View File

@ -13,7 +13,12 @@
<property name="default_width">440</property> <property name="default_width">440</property>
<property name="default_height">250</property> <property name="default_height">250</property>
<child type="titlebar"> <child type="titlebar">
<placeholder/> <object class="GtkButton" id="btnchoose">
<property name="label" translatable="yes">File Chooser dialog</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child> </child>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
@ -21,10 +26,19 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<placeholder/> <object class="GtkScrolledWindow">
</child> <property name="visible">True</property>
<child> <property name="can_focus">True</property>
<placeholder/> <property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child> </child>
<child> <child>
<object class="GtkScrollbar"> <object class="GtkScrollbar">