Cleanup code, comments and refactor a bit.
This commit is contained in:
parent
a42161181a
commit
7c9430884f
130
src/interface.c
130
src/interface.c
@ -1,7 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
* Compatibility wrapper for old Glade2 code generation file.
|
* interface.c - this file is part of Geany, a fast and lightweight IDE
|
||||||
*
|
*
|
||||||
* DO NOT ADD NEW CODE HERE!
|
* Copyright 2006-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
* Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -14,31 +31,37 @@
|
|||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
|
|
||||||
#define GLADE_HOOKUP_OBJECT(component, widget, name) \
|
|
||||||
g_object_set_data_full(G_OBJECT(component), name, \
|
|
||||||
g_object_ref(G_OBJECT(widget)), (GDestroyNotify) g_object_unref)
|
|
||||||
|
|
||||||
#define GLADE_HOOKUP_OBJECT_NO_REF(component, widget, name) \
|
static gchar* interface_file = NULL;
|
||||||
g_object_set_data(G_OBJECT(component), name, G_OBJECT(widget))
|
static GtkBuilder* builder = NULL;
|
||||||
|
static GSList* local_objects = NULL;
|
||||||
|
|
||||||
static gchar *ui_file = NULL;
|
|
||||||
static GtkBuilder *builder = NULL;
|
|
||||||
static GSList *objects = NULL;
|
|
||||||
|
|
||||||
static void init_builder(void);
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Returns a widget from a name.
|
||||||
|
*
|
||||||
|
* Call it with the name of the GObject you want returned. This is
|
||||||
|
* similar to @a ui_lookup_widget except that it supports arbitrary
|
||||||
|
* GObjects.
|
||||||
|
*
|
||||||
|
* @note The GObject must either be in the GtkBuilder/Glade file or
|
||||||
|
* have been added with the function @a interface_add_object.
|
||||||
|
*
|
||||||
|
* @param widget Widget with the @a widget_name property set.
|
||||||
|
* @param widget_name Name to lookup.
|
||||||
|
* @return The widget found.
|
||||||
|
*
|
||||||
|
* @see ui_hookup_widget().
|
||||||
|
* @see interface_add_object().
|
||||||
|
* @since 0.21
|
||||||
|
*/
|
||||||
GObject *interface_get_object(const gchar *name)
|
GObject *interface_get_object(const gchar *name)
|
||||||
{
|
{
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
|
|
||||||
init_builder();
|
|
||||||
|
|
||||||
g_return_val_if_fail(name != NULL, NULL);
|
g_return_val_if_fail(name != NULL, NULL);
|
||||||
g_return_val_if_fail(objects != NULL, NULL);
|
g_return_val_if_fail(local_objects != NULL, NULL);
|
||||||
|
|
||||||
for (iter = objects; iter != NULL; iter = g_slist_next(iter))
|
for (iter = local_objects; iter != NULL; iter = g_slist_next(iter))
|
||||||
{
|
{
|
||||||
if (G_IS_OBJECT(iter->data))
|
if (G_IS_OBJECT(iter->data))
|
||||||
{
|
{
|
||||||
@ -59,15 +82,23 @@ GObject *interface_get_object(const gchar *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_debug("Can't locate: %s", name);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void interface_set_object(GObject *obj, const gchar *name)
|
/* Sets a name to lookup GObject @a obj.
|
||||||
|
*
|
||||||
|
* This is similar to @a ui_hookup_widget() except that it supports
|
||||||
|
* arbitrary GObjects.
|
||||||
|
*
|
||||||
|
* @param obj GObject.
|
||||||
|
* @param name Name.
|
||||||
|
*
|
||||||
|
* @see ui_hookup_widget().
|
||||||
|
* @since 0.21
|
||||||
|
**/
|
||||||
|
void interface_add_object(GObject *obj, const gchar *name)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
g_return_if_fail(G_IS_OBJECT(obj));
|
g_return_if_fail(G_IS_OBJECT(obj));
|
||||||
|
|
||||||
if (! name)
|
if (! name)
|
||||||
@ -76,107 +107,102 @@ void interface_set_object(GObject *obj, const gchar *name)
|
|||||||
name = g_object_get_data(obj, "gtk-builder-name");
|
name = g_object_get_data(obj, "gtk-builder-name");
|
||||||
if (! name && GTK_IS_BUILDABLE(obj))
|
if (! name && GTK_IS_BUILDABLE(obj))
|
||||||
name = gtk_buildable_get_name(GTK_BUILDABLE(obj));
|
name = gtk_buildable_get_name(GTK_BUILDABLE(obj));
|
||||||
else if (! name && GTK_IS_WIDGET(obj))
|
if (! name && GTK_IS_WIDGET(obj))
|
||||||
name = gtk_widget_get_name(GTK_WIDGET(obj));
|
name = gtk_widget_get_name(GTK_WIDGET(obj));
|
||||||
|
|
||||||
g_return_if_fail(name);
|
g_return_if_fail(name);
|
||||||
|
|
||||||
g_object_set_data_full(obj, "name", g_strdup(name), g_free);
|
g_object_set_data_full(obj, "name", g_strdup(name), g_free);
|
||||||
|
|
||||||
objects = g_slist_append(objects, g_object_ref(obj));
|
local_objects = g_slist_append(local_objects, g_object_ref(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void init_builder(void)
|
void interface_init(void)
|
||||||
{
|
{
|
||||||
GError *error;
|
GError *error;
|
||||||
GSList *iter, *all_objects;
|
GSList *iter, *all_objects;
|
||||||
|
GtkCellRenderer *renderer;
|
||||||
|
|
||||||
if (builder) /* only run once */
|
g_return_if_fail(builder == NULL);
|
||||||
return;
|
|
||||||
|
|
||||||
ui_file = g_build_filename(GEANY_DATADIR, "geany", "geany.glade", NULL);
|
interface_file = g_build_filename(GEANY_DATADIR, "geany", "geany.glade", NULL);
|
||||||
|
|
||||||
if (! (builder = gtk_builder_new()))
|
if (! (builder = gtk_builder_new()))
|
||||||
{
|
{
|
||||||
g_error("failed to initialize the user-interface");
|
g_error("Failed to initialize the user-interface");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
if (! gtk_builder_add_from_file(builder, ui_file, &error))
|
if (! gtk_builder_add_from_file(builder, interface_file, &error))
|
||||||
{
|
{
|
||||||
g_error("failed to load the user-interface file: %s",
|
g_error("Failed to load the user-interface file: %s", error->message);
|
||||||
error->message);
|
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: make sure all callbacks have G_MODULE_EXPORT */
|
|
||||||
gtk_builder_connect_signals(builder, NULL);
|
gtk_builder_connect_signals(builder, NULL);
|
||||||
|
|
||||||
/* TODO: set translation domain? */;
|
/* TODO: set translation domain on GtkBuilder? */;
|
||||||
|
|
||||||
all_objects = gtk_builder_get_objects(builder);
|
all_objects = gtk_builder_get_objects(builder);
|
||||||
for (iter = all_objects; iter != NULL; iter = g_slist_next(iter))
|
for (iter = all_objects; iter != NULL; iter = g_slist_next(iter))
|
||||||
{
|
{
|
||||||
interface_set_object(iter->data, NULL);
|
interface_add_object(iter->data, NULL);
|
||||||
//g_debug("ADDED OBJECT: %s", g_object_get_data(iter->data, "name"));
|
|
||||||
|
/* FIXME: Hack to get Glade 3/GtkBuilder combo boxes working */
|
||||||
if (GTK_IS_COMBO_BOX(iter->data))
|
if (GTK_IS_COMBO_BOX(iter->data))
|
||||||
{
|
{
|
||||||
GtkCellRenderer *r = gtk_cell_renderer_text_new();
|
renderer = gtk_cell_renderer_text_new();
|
||||||
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(iter->data), r, TRUE);
|
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(iter->data), renderer, TRUE);
|
||||||
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(iter->data),
|
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(iter->data),
|
||||||
r, "text", 0, NULL);
|
renderer, "text", 0, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g_slist_free(all_objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Hookup to atexit() or make public and call at program exit? */
|
void interface_finalize(void)
|
||||||
/* Ensure everything is freed. */
|
|
||||||
static void finalize_builder(void)
|
|
||||||
{
|
{
|
||||||
GSList *iter;
|
|
||||||
g_return_if_fail(GTK_IS_BUILDER(builder));
|
g_return_if_fail(GTK_IS_BUILDER(builder));
|
||||||
for (iter = objects; iter != NULL; iter = g_slist_next(iter))
|
|
||||||
g_object_unref(iter->data);
|
g_slist_free(local_objects);
|
||||||
g_slist_free(objects);
|
g_free(interface_file);
|
||||||
g_free(ui_file);
|
|
||||||
g_object_unref(builder);
|
g_object_unref(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Compatibility functions with Glade 2 generated code.
|
||||||
|
*
|
||||||
|
* TODO: remove these
|
||||||
|
*/
|
||||||
GtkWidget *create_window1(void)
|
GtkWidget *create_window1(void)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
return GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
|
return GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *create_toolbar_popup_menu1(void)
|
GtkWidget *create_toolbar_popup_menu1(void)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
return GTK_WIDGET(gtk_builder_get_object(builder, "toolbar_popup_menu1"));
|
return GTK_WIDGET(gtk_builder_get_object(builder, "toolbar_popup_menu1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *create_edit_menu1(void)
|
GtkWidget *create_edit_menu1(void)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
return GTK_WIDGET(gtk_builder_get_object(builder, "edit_menu1"));
|
return GTK_WIDGET(gtk_builder_get_object(builder, "edit_menu1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *create_prefs_dialog(void)
|
GtkWidget *create_prefs_dialog(void)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
return GTK_WIDGET(gtk_builder_get_object(builder, "prefs_dialog"));
|
return GTK_WIDGET(gtk_builder_get_object(builder, "prefs_dialog"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *create_project_dialog(void)
|
GtkWidget *create_project_dialog(void)
|
||||||
{
|
{
|
||||||
init_builder();
|
|
||||||
return GTK_WIDGET(gtk_builder_get_object(builder, "project_dialog"));
|
return GTK_WIDGET(gtk_builder_get_object(builder, "project_dialog"));
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* Compatibility wrapper for old Glade2 code generation file.
|
* interface.h - this file is part of Geany, a fast and lightweight IDE
|
||||||
*
|
*
|
||||||
* DO NOT ADD NEW CODE HERE!
|
* Copyright 2006-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
* Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GtkWidget* create_window1 (void);
|
|
||||||
GtkWidget* create_toolbar_popup_menu1 (void);
|
|
||||||
GtkWidget* create_edit_menu1 (void);
|
|
||||||
GtkWidget* create_prefs_dialog (void);
|
|
||||||
GtkWidget* create_project_dialog (void);
|
|
||||||
|
|
||||||
GObject *interface_get_object(const gchar *name);
|
void interface_init (void);
|
||||||
void interface_set_object(GObject *obj, const gchar *name);
|
void interface_finalize (void);
|
||||||
|
GObject* interface_get_object (const gchar *name);
|
||||||
|
void interface_add_object (GObject *obj, const gchar *name);
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: remove these and just use ui_lookup_widget() */
|
||||||
|
GtkWidget* create_window1 (void);
|
||||||
|
GtkWidget* create_toolbar_popup_menu1 (void);
|
||||||
|
GtkWidget* create_edit_menu1 (void);
|
||||||
|
GtkWidget* create_prefs_dialog (void);
|
||||||
|
GtkWidget* create_project_dialog (void);
|
||||||
|
@ -223,6 +223,8 @@ static void apply_settings(void)
|
|||||||
static void main_init(void)
|
static void main_init(void)
|
||||||
{
|
{
|
||||||
/* inits */
|
/* inits */
|
||||||
|
interface_init();
|
||||||
|
|
||||||
main_widgets.window = NULL;
|
main_widgets.window = NULL;
|
||||||
app->project = NULL;
|
app->project = NULL;
|
||||||
ui_widgets.open_fontsel = NULL;
|
ui_widgets.open_fontsel = NULL;
|
||||||
@ -1179,6 +1181,7 @@ void main_quit()
|
|||||||
filetypes_free_types();
|
filetypes_free_types();
|
||||||
ui_finalize();
|
ui_finalize();
|
||||||
log_finalize();
|
log_finalize();
|
||||||
|
interface_finalize();
|
||||||
|
|
||||||
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
|
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
|
||||||
g_free(app->configdir);
|
g_free(app->configdir);
|
||||||
|
@ -2214,22 +2214,6 @@ void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Sets a name to lookup @a widget from @a owner.
|
|
||||||
* @param owner Usually a window, dialog or popup menu.
|
|
||||||
* @param widget Widget.
|
|
||||||
* @param widget_name Name.
|
|
||||||
* @see ui_lookup_widget().
|
|
||||||
*
|
|
||||||
* @since 0.16
|
|
||||||
**/
|
|
||||||
void ui_hookup_widget_real(GtkWidget *owner, GObject *widget, const gchar *widget_name)
|
|
||||||
{
|
|
||||||
g_return_if_fail(GTK_IS_WIDGET(widget));
|
|
||||||
g_return_if_fail(widget_name != NULL);
|
|
||||||
interface_set_object(G_OBJECT(widget), widget_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns a widget from a name in a component, usually created by Glade.
|
/** Returns a widget from a name in a component, usually created by Glade.
|
||||||
* Call it with the toplevel widget in the component (i.e. a window/dialog),
|
* Call it with the toplevel widget in the component (i.e. a window/dialog),
|
||||||
* or alternatively any widget in the component, and the name of the widget
|
* or alternatively any widget in the component, and the name of the widget
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
* @since 0.16
|
* @since 0.16
|
||||||
**/
|
**/
|
||||||
#define ui_hookup_widget(owner, widget, widget_name) \
|
#define ui_hookup_widget(owner, widget, widget_name) \
|
||||||
ui_hookup_widget_real(owner, G_OBJECT(widget), widget_name)
|
interface_add_object(G_OBJECT(widget), widget_name)
|
||||||
|
|
||||||
|
|
||||||
/** Interface preferences */
|
/** Interface preferences */
|
||||||
@ -205,8 +205,6 @@ void ui_auto_separator_add_ref(GeanyAutoSeparator *autosep, GtkWidget *item);
|
|||||||
|
|
||||||
void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text);
|
void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text);
|
||||||
|
|
||||||
void ui_hookup_widget_real(GtkWidget *owner, GObject *widget, const gchar *widget_name);
|
|
||||||
|
|
||||||
GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name);
|
GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name);
|
||||||
|
|
||||||
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
|
void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user