Add ui_table_add_row() for easily adding widgets to a GtkTable, and

use it in project_new().
Group 'generic' functions related to GTK+ together at the top of
ui_utils.h.
Make sure G_GNUC_NULL_TERMINATED is defined in geany.h.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1702 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-07-13 15:54:16 +00:00
parent 5ec03cdc0a
commit 3ecd31d9fd
6 changed files with 68 additions and 42 deletions

View File

@ -13,6 +13,13 @@
remove some unnecessary border width.
Add ui->dialog_vbox_new() and ui->frame_new_with_alignment()
functions to the plugin API.
* src/ui_utils.h, src/utils.h, src/project.c, src/geany.h,
src/ui_utils.c:
Add ui_table_add_row() for easily adding widgets to a GtkTable, and
use it in project_new().
Group 'generic' functions related to GTK+ together at the top of
ui_utils.h.
Make sure G_GNUC_NULL_TERMINATED is defined in geany.h.
2007-07-12 Enrico Tröger <enrico.troeger@uvena.de>

View File

@ -210,6 +210,11 @@ enum
};
/* Useful for some variable argument list functions, e.g. in utils.h */
#if ! GLIB_CHECK_VERSION(2, 8, 0)
#define G_GNUC_NULL_TERMINATED
#endif
// implementation in main.c; prototype is here so that all files can use it.
void geany_debug(gchar const *format, ...) G_GNUC_PRINTF (1, 2);

View File

@ -124,21 +124,14 @@ void project_new()
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
label = gtk_label_new(_("Name:"));
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
e->name = gtk_entry_new();
gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN);
gtk_table_attach(GTK_TABLE(table), e->name, 1, 2, 0, 1,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
ui_table_add_row(GTK_TABLE(table), 0, label, e->name, NULL);
label = gtk_label_new(_("Filename:"));
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
e->file_name = gtk_entry_new();
@ -151,14 +144,10 @@ void project_new()
bbox = gtk_hbox_new(FALSE, 6);
gtk_box_pack_start_defaults(GTK_BOX(bbox), e->file_name);
gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 1, 2,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL);
label = gtk_label_new(_("Base path:"));
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
e->base_path = gtk_entry_new();
@ -167,9 +156,8 @@ void project_new()
"This can be a new path, or an existing directory tree."), NULL);
bbox = ui_path_box_new(_("Choose Project Base Path"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path));
gtk_table_attach(GTK_TABLE(table), bbox, 1, 2, 2, 3,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL);
gtk_container_add(GTK_CONTAINER(vbox), table);

View File

@ -1266,3 +1266,26 @@ void ui_statusbar_showhide(gboolean state)
else
gtk_widget_hide(app->statusbar);
}
/* Pack all GtkWidgets passed after the row argument into a table, using
* one widget per cell. The first widget is not expanded, as this is usually
* a label. */
void ui_table_add_row(GtkTable *table, gint row, ...)
{
va_list args;
gint i;
GtkWidget *widget;
va_start(args, row);
for (i = 0; (widget = va_arg(args, GtkWidget*), widget != NULL); i++)
{
gint options = (i == 0) ? GTK_FILL : GTK_EXPAND | GTK_FILL;
gtk_table_attach(GTK_TABLE(table), widget, i, i + 1, row, row + 1,
options, 0, 0, 0);
}
va_end(args);
}

View File

@ -24,6 +24,33 @@
#ifndef GEANY_UI_UTILS_H
#define GEANY_UI_UTILS_H 1
/* The following block of functions are more generic functions and closely related to
* certain GTK+ widgets. */
void ui_widget_show_hide(GtkWidget *widget, gboolean show);
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment);
GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog);
GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text);
void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy);
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text);
GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry);
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
GtkFileChooserAction action, GtkEntry *entry);
void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED;
/* End of 'generic' functions */
// Display text on the statusbar without logging it to the Status window.
void ui_set_statusbar(const gchar *format, ...) G_GNUC_PRINTF (1, 2);
@ -62,8 +89,6 @@ void ui_save_buttons_toggle(gboolean enable);
void ui_close_buttons_toggle();
void ui_widget_show_hide(GtkWidget *widget, gboolean show);
void ui_treeviews_show_hide(gboolean force);
void ui_document_show_hide(gint idx);
@ -89,22 +114,6 @@ void ui_show_markers_margin();
void ui_show_linenumber_margin();
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment);
GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog);
GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text);
void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy);
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text);
GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry);
void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
GtkFileChooserAction action, GtkEntry *entry);
void ui_update_tab_status(gint idx);
@ -113,8 +122,6 @@ typedef gboolean TVMatchCallback();
gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb);
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
void ui_statusbar_showhide(gboolean state);
#endif

View File

@ -25,10 +25,6 @@
#ifndef GEANY_UTILS_H
#define GEANY_UTILS_H 1
#if ! GLIB_CHECK_VERSION(2, 8, 0)
#define G_GNUC_NULL_TERMINATED
#endif
// Returns: TRUE if ptr points to a non-zero value.
#define NZV(ptr) \
((ptr) && (ptr)[0])