135
/** Display text on the statusbar.
139
/** Displays text on the statusbar.
136
140
* @param log Whether the message should be recorded in the Status window.
137
141
* @param format A @c printf -style string. */
138
142
void ui_set_statusbar(gboolean log, const gchar *format, ...)
143
147
va_start(args, format);
144
g_vsnprintf(string, 512, format, args);
148
string = g_strdup_vprintf(format, args);
147
151
if (! prefs.suppress_status_messages)
1238
1253
GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment)
1240
1255
GtkWidget *label, *align;
1241
GtkWidget *frame = gtk_frame_new (NULL);
1242
gchar *label_markup;
1244
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
1246
align = gtk_alignment_new (0.5, 0.5, 1, 1);
1247
gtk_container_add (GTK_CONTAINER (frame), align);
1248
gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
1250
label_markup = g_strconcat("<b>", label_text, "</b>", NULL);
1251
label = gtk_label_new (label_markup);
1252
gtk_frame_set_label_widget (GTK_FRAME (frame), label);
1253
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1254
g_free(label_markup);
1256
GtkWidget *frame = gtk_frame_new(NULL);
1258
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
1260
align = gtk_alignment_new(0.5, 0.5, 1, 1);
1261
gtk_container_add(GTK_CONTAINER(frame), align);
1262
gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 0, 12, 0);
1264
label = ui_label_new_bold(label_text);
1265
gtk_frame_set_label_widget(GTK_FRAME(frame), label);
1256
1267
*alignment = align;
1261
const gint BUTTON_BOX_BORDER = 5;
1263
/** Convenience function for getting a fixed border for dialogs that doesn't
1264
* increase the button box border.
1272
/** Makes a fixed border for dialogs without increasing the button box border.
1265
1273
* @param dialog The parent container for the @c GtkVBox.
1266
1274
* @return The packed @c GtkVBox. */
1267
1275
GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog)
1269
1277
GtkWidget *vbox = gtk_vbox_new(FALSE, 12); /* need child vbox to set a separate border. */
1271
gtk_container_set_border_width(GTK_CONTAINER(vbox), BUTTON_BOX_BORDER);
1279
gtk_container_set_border_width(GTK_CONTAINER(vbox), 6);
1272
1280
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
1277
/** Create a @c GtkButton with custom text and a stock image, aligned like
1285
/** Creates a @c GtkButton with custom text and a stock image similar to
1278
1286
* @c gtk_button_new_from_stock().
1279
1287
* @param stock_id A @c GTK_STOCK_NAME string.
1280
1288
* @param text Button label text, can include mnemonics.
1283
1291
GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text)
1285
GtkWidget *image, *label, *align, *hbox, *button;
1293
GtkWidget *image, *button;
1287
hbox = gtk_hbox_new(FALSE, 2);
1295
button = gtk_button_new_with_mnemonic(text);
1296
gtk_widget_show(button);
1288
1297
image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON);
1289
label = gtk_label_new_with_mnemonic(text);
1290
gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
1291
gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1293
button = gtk_button_new();
1294
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
1295
gtk_container_add(GTK_CONTAINER(align), hbox);
1296
gtk_container_add(GTK_CONTAINER(button), align);
1297
gtk_widget_show_all(align);
1298
gtk_button_set_image(GTK_BUTTON(button), image);
1299
/* note: image is shown by gtk */
1302
/** Create a @c GtkImageMenuItem with a stock image and a custom label.
1304
/** Creates a @c GtkImageMenuItem with a stock image and a custom label.
1303
1305
* @param stock_id Stock image ID, e.g. @c GTK_STOCK_OPEN.
1304
1306
* @param label Menu item label, can include mnemonics.
1305
1307
* @return The new @c GtkImageMenuItem.
1524
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str)
1528
* Modifies the font of a widget using gtk_widget_modify_font().
1530
* @param widget The widget.
1531
* @param str The font name as expected by pango_font_description_from_string().
1533
void ui_widget_modify_font_from_string(GtkWidget *widget, const gchar *str)
1526
1535
PangoFontDescription *pfd;
1528
1537
pfd = pango_font_description_from_string(str);
1529
gtk_widget_modify_font(wid, pfd);
1538
gtk_widget_modify_font(widget, pfd);
1530
1539
pango_font_description_free(pfd);
1634
1648
GtkEntry *entry =
1635
1649
(GtkEntry *) g_object_get_data(G_OBJECT(path_box), "entry");
1636
1650
const gchar *title = g_object_get_data(G_OBJECT(path_box), "title");
1651
gchar *utf8_path = NULL;
1639
1653
/* TODO: extend for other actions */
1640
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
1654
g_return_if_fail(action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
1655
action == GTK_FILE_CHOOSER_ACTION_OPEN);
1642
1657
if (title == NULL)
1643
1658
title = (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER) ?
1644
1659
_("Select Folder") : _("Select File");
1647
utf8_path = win32_show_project_folder_dialog(ui_widgets.prefs_dialog, title,
1648
gtk_entry_get_text(GTK_ENTRY(entry)));
1650
utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry)));
1661
if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
1664
utf8_path = win32_show_file_dialog(GTK_WINDOW(ui_widgets.prefs_dialog), title,
1665
gtk_entry_get_text(GTK_ENTRY(entry)));
1667
utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry)));
1670
else if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
1672
gchar *path = g_path_get_dirname(gtk_entry_get_text(GTK_ENTRY(entry)));
1674
utf8_path = win32_show_folder_dialog(ui_widgets.prefs_dialog, title,
1675
gtk_entry_get_text(GTK_ENTRY(entry)));
1677
utf8_path = run_file_chooser(title, action, path);
1653
1682
if (utf8_path != NULL)
1717
1746
if (g_file_test(global_file, G_FILE_TEST_EXISTS))
1718
1747
g_file_get_contents(global_file, &global_content, NULL, NULL);
1720
document_new_file(utf8, ft, global_content);
1721
utils_free_pointers(4, utf8, base_name, global_file, global_content, NULL);
1749
document_new_file(utf8_filename, ft, global_content);
1751
utils_free_pointers(4, utf8_filename, base_name, global_file, global_content, NULL);
1844
void ui_swap_sidebar_pos(void)
1846
GtkWidget *pane = ui_lookup_widget(main_widgets.window, "hpaned1");
1847
GtkWidget *left = gtk_paned_get_child1(GTK_PANED(pane));
1848
GtkWidget *right = gtk_paned_get_child2(GTK_PANED(pane));
1849
GtkWidget *box = ui_lookup_widget(main_widgets.window, "vbox1");
1851
/* reparenting avoids scintilla problem with middle click paste */
1852
gtk_widget_reparent(left, box);
1853
gtk_widget_reparent(right, box);
1854
gtk_widget_reparent(right, pane);
1855
gtk_widget_reparent(left, pane);
1857
gtk_paned_set_position(GTK_PANED(pane), pane->allocation.width
1858
- gtk_paned_get_position(GTK_PANED(pane)));
1816
1862
static void init_recent_files(void)
1818
1864
GtkWidget *toolbar_recent_files_menu;
1880
static void ui_menu_move(GtkWidget *menu, GtkWidget *old, GtkWidget *new)
1883
gtk_menu_item_set_submenu(GTK_MENU_ITEM(old), NULL);
1884
gtk_menu_item_set_submenu(GTK_MENU_ITEM(new), menu);
1885
g_object_unref(menu);
1889
static void on_editor_menu_show(GtkWidget *item)
1891
GtkWidget *popup = ui_lookup_widget(main_widgets.editor_menu, "commands1");
1892
GtkWidget *bar = ui_lookup_widget(main_widgets.window, "commands2");
1894
ui_menu_move(widgets.commands_menu, bar, popup);
1896
popup = ui_lookup_widget(main_widgets.editor_menu, "menu_format2");
1897
bar = ui_lookup_widget(main_widgets.window, "menu_format1");
1898
ui_menu_move(widgets.format_menu, bar, popup);
1902
static void on_editor_menu_hide(GtkWidget *item)
1904
GtkWidget *popup = ui_lookup_widget(main_widgets.editor_menu, "commands1");
1905
GtkWidget *bar = ui_lookup_widget(main_widgets.window, "commands2");
1907
ui_menu_move(widgets.commands_menu, popup, bar);
1909
popup = ui_lookup_widget(main_widgets.editor_menu, "menu_format2");
1910
bar = ui_lookup_widget(main_widgets.window, "menu_format1");
1911
ui_menu_move(widgets.format_menu, popup, bar);
1834
1915
void ui_init(void)
1836
1919
init_recent_files();
1838
1921
ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar");
1859
1942
widgets.undo_items[0] = ui_lookup_widget(main_widgets.editor_menu, "undo1");
1860
1943
widgets.undo_items[1] = ui_lookup_widget(main_widgets.window, "menu_undo2");
1945
item = ui_lookup_widget(main_widgets.window, "menu_format1");
1946
widgets.format_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(item));
1947
item = ui_lookup_widget(main_widgets.window, "commands2");
1948
widgets.commands_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(item));
1950
/* reparent edit submenus as needed */
1951
item = main_widgets.editor_menu;
1952
g_signal_connect(item, "show", G_CALLBACK(on_editor_menu_show), NULL);
1953
g_signal_connect(item, "hide", G_CALLBACK(on_editor_menu_hide), NULL);
1862
1955
ui_init_toolbar_widgets();
1863
1956
init_document_widgets();
1864
1957
create_config_files_menu();
2088
2180
g_list_free(list);
2184
/* return value is for macros */
2185
GtkWidget *ui_label_set_markup(GtkLabel *label, const gchar *format, ...)
2190
va_start(a, format);
2191
text = g_strdup_vprintf(format, a);
2194
gtk_label_set_text(label, text);
2195
gtk_label_set_use_markup(label, TRUE);
2197
return GTK_WIDGET(label);
2201
/** Adds a list of document items to @a menu.
2203
* @param active Which document to highlight, or @c NULL.
2204
* @param callback is used for each menu item's @c "activate" signal and will be passed
2205
* the corresponding document pointer as @c user_data.
2206
* @warning You should check @c doc->is_valid in the callback.
2208
void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback)
2210
GtkWidget *menu_item, *menu_item_label;
2211
const GdkColor *color;
2216
len = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
2217
for (i = 0; i < len; i++)
2219
doc = document_get_from_page(i);
2220
if (! DOC_VALID(doc))
2223
base_name = g_path_get_basename(DOC_FILENAME(doc));
2224
menu_item = gtk_menu_item_new_with_label(base_name);
2225
gtk_widget_show(menu_item);
2226
gtk_container_add(GTK_CONTAINER(menu), menu_item);
2227
g_signal_connect(menu_item, "activate", callback, doc);
2229
color = document_get_status_color(doc);
2230
menu_item_label = gtk_bin_get_child(GTK_BIN(menu_item));
2231
gtk_widget_modify_fg(menu_item_label, GTK_STATE_NORMAL, color);
2232
gtk_widget_modify_fg(menu_item_label, GTK_STATE_ACTIVE, color);
2235
ui_label_set_markup(GTK_LABEL(menu_item_label), "<b>%s</b>", base_name);
2242
/** Checks whether the passed @a keyval is the Enter or Return key.
2243
* There are three different Enter/Return key values
2244
* (@c GDK_Return, @c GDK_ISO_Enter, @c GDK_KP_Enter).
2245
* This is just a convenience function.
2246
* @param keyval A keyval.
2247
* @return @c TRUE if @a keyval is the one of the Enter/Return key values, otherwise @c FALSE.
2249
gboolean ui_is_keyval_enter_or_return(guint keyval)
2251
return (keyval == GDK_Return || keyval == GDK_ISO_Enter|| keyval == GDK_KP_Enter);
2255
/** Reads an integer from the GTK default settings registry
2256
* (see http://library.gnome.org/devel/gtk/stable/GtkSettings.html).
2257
* @param property_name The property to read.
2258
* @param default_value The default value in case the value could not be read.
2259
* @return The value for the property if it exists, otherwise the @a default_value.
2261
gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value)
2263
if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(
2264
gtk_settings_get_default())), property_name))
2267
g_object_get(G_OBJECT(gtk_settings_get_default()), property_name, &value, NULL);
2271
return default_value;
2275
void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text,
2276
gint new_text_len, gint *position, gpointer data)
2278
gboolean stop_signal = FALSE;
2279
const gchar c = *new_text;
2281
/* allow inserting '+' and '-' as the first character */
2282
if (position != NULL && *position == 0)
2284
if (c != '+' && c != '-' && ! isdigit(c))
2287
/* don't insert any text when it is not a digit */
2288
else if (! isdigit(c))
2292
g_signal_stop_emission_by_name(editable, "insert-text");