New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GResource to load GtkBuilder XML UI file #1703
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
AC_DEFUN([GEANY_CHECK_GRESOURCE], | ||
[ | ||
AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources], [no]) | ||
AS_IF([test "x$GLIB_COMPILE_RESOURCES" = "xno"], [ | ||
AC_MSG_ERROR([Unable to find glib-compile-resources, is it installed?]) | ||
]) | ||
]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<gresources> | ||
<gresource prefix="/org/geany/Geany"> | ||
<file alias="geany.glade" compressed="true">../data/geany.glade</file> | ||
</gresource> | ||
</gresources> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,26 @@ G_BEGIN_DECLS | |
#endif | ||
|
||
|
||
#if !GTK_CHECK_VERSION(3, 4, 0) | ||
static inline guint gtkcompat_builder_add_from_resource(GtkBuilder *builder, | ||
const gchar *resource_path, GError **error) | ||
{ | ||
GBytes *bytes = g_resources_lookup_data(resource_path, | ||
G_RESOURCE_LOOKUP_FLAGS_NONE, error); | ||
if (bytes == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is worth a a g_error(), as it means Geany wasn't compiled correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be done in the calling code; this function is just a compat wrapper around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, makes sense. |
||
return 0; | ||
gsize data_len = 0; | ||
gconstpointer data = g_bytes_get_data(bytes, &data_len); | ||
g_assert(data_len > 0); | ||
g_assert(data != NULL); | ||
guint id = gtk_builder_add_from_string(builder, data, data_len, error); | ||
g_bytes_unref(bytes); | ||
return id; | ||
} | ||
#define gtk_builder_add_from_resource gtkcompat_builder_add_from_resource | ||
#endif | ||
|
||
|
||
G_END_DECLS | ||
|
||
#endif /* GTK_COMPAT_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
#include "msgwindow.h" | ||
#include "prefs.h" | ||
#include "project.h" | ||
#include "resources.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not needed :) Could you remove this extra include please? |
||
#include "sciwrappers.h" | ||
#include "sidebar.h" | ||
#include "stash.h" | ||
|
@@ -2425,7 +2426,6 @@ static GtkWidget *ui_get_top_parent(GtkWidget *widget) | |
|
||
void ui_init_builder(void) | ||
{ | ||
gchar *interface_file; | ||
const gchar *name; | ||
GError *error; | ||
GSList *iter, *all_objects; | ||
|
@@ -2440,20 +2440,17 @@ void ui_init_builder(void) | |
gtk_builder_set_translation_domain(builder, GETTEXT_PACKAGE); | ||
|
||
error = NULL; | ||
interface_file = g_build_filename(app->datadir, "geany.glade", NULL); | ||
if (! gtk_builder_add_from_file(builder, interface_file, &error)) | ||
if (gtk_builder_add_from_resource(builder, "/org/geany/Geany/geany.glade", &error) == 0) | ||
{ | ||
/* Show the user this message so they know WTF happened */ | ||
dialogs_show_msgbox_with_secondary(GTK_MESSAGE_ERROR, | ||
_("Geany cannot start!"), error->message); | ||
/* Aborts */ | ||
g_error("Cannot create user-interface: %s", error->message); | ||
g_error_free(error); | ||
g_free(interface_file); | ||
g_object_unref(builder); | ||
return; | ||
} | ||
g_free(interface_file); | ||
|
||
callbacks_connect(builder); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, maybe you need to add something like
|| rm -f $@
(but you need to still return in error) so that if the generation fails for some reason it will be tried again next time. Another common solution is to generate a temporary file and move it over on success, so it's mostly atomic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this tool is too stupid to not properly update the file (or not) depending on the outcome?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but many tools aren't smart enough so I'd at least check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs glib-compile-resources twice. It's usually better to a construct pattern rule, where (GNU) make recognizes that one rule produces multiple output files. That's assuming it's even possible with, I haven't checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kugel- It's supposed to run it twice, once for the source file (
--generate-source
) and once for the header file (--generate-header
).