Save encoding in session as text
[geany-mirror.git] / src / ui_utils.h
blobd856c6e6ccfc8235f2bfbe214ad5bdc2629f9216
1 /*
2 * ui_utils.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2006-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef GEANY_UI_UTILS_H
23 #define GEANY_UI_UTILS_H 1
25 G_BEGIN_DECLS
28 /** Sets a name to lookup @a widget from @a owner.
29 * @param owner Usually a window, dialog or popup menu.
30 * @param widget Widget.
31 * @param widget_name Name.
32 * @see ui_lookup_widget().
34 * @since 0.16
35 **/
36 #define ui_hookup_widget(owner, widget, widget_name) \
37 g_object_set_data_full(G_OBJECT(owner), widget_name, \
38 g_object_ref(widget), (GDestroyNotify)g_object_unref);
41 /** Interface preferences */
42 typedef struct GeanyInterfacePrefs
44 gboolean sidebar_symbol_visible; /**< whether the symbol sidebar is visible */
45 gboolean sidebar_openfiles_visible; /**< whether the open file list is visible */
46 gchar *editor_font; /**< editor font */
47 gchar *tagbar_font; /**< symbol sidebar font */
48 gchar *msgwin_font; /**< message window font */
49 gboolean show_notebook_tabs; /**< whether editor tabs are visible */
50 gint tab_pos_editor; /**< positions of editor's tabs */
51 gint tab_pos_msgwin; /**< positions of message window's tabs */
52 gint tab_pos_sidebar; /**< positions of sidebar's tabs */
53 gboolean statusbar_visible; /**< whether the status bar is visible */
54 gboolean show_symbol_list_expanders; /**< whether to show expanders in the symbol list */
55 /** whether a double click on notebook tabs hides all other windows */
56 gboolean notebook_double_click_hides_widgets;
57 gboolean highlighting_invert_all; /**< whether highlighting colors are inverted */
58 gint sidebar_pos; /**< position of the sidebar (left or right) */
59 gboolean msgwin_status_visible; /**< whether message window's status tab is visible */
60 gboolean msgwin_compiler_visible; /**< whether message window's compiler tab is visible */
61 gboolean msgwin_messages_visible; /**< whether message window's messages tab is visible */
62 gboolean msgwin_scribble_visible; /**< whether message window's scribble tab is visible */
63 /** whether to use native Windows' dialogs (only used on Windows) */
64 gboolean use_native_windows_dialogs;
65 /** whether compiler messages window is automatically scrolled to show new messages */
66 gboolean compiler_tab_autoscroll;
68 GeanyInterfacePrefs;
71 extern GeanyInterfacePrefs interface_prefs;
74 /** Important widgets in the main window.
75 * Accessed by @c geany->main_widgets. */
76 typedef struct GeanyMainWidgets
78 GtkWidget *window; /**< Main window. */
79 GtkWidget *toolbar; /**< Main toolbar. */
80 GtkWidget *sidebar_notebook; /**< Sidebar notebook. */
81 GtkWidget *notebook; /**< Document notebook. */
82 GtkWidget *editor_menu; /**< Popup editor menu. */
83 GtkWidget *tools_menu; /**< Most plugins add menu items to the Tools menu. */
84 /** Progress bar widget in the status bar to show progress of various actions.
85 * See ui_progress_bar_start() for details. */
86 GtkWidget *progressbar;
87 GtkWidget *message_window_notebook; /**< Message Window notebook. */
88 /** Plugins modifying the project can add their items to the Project menu. */
89 GtkWidget *project_menu;
91 GeanyMainWidgets;
93 extern GeanyMainWidgets main_widgets;
96 /* User Interface settings not shown in the Prefs dialog. */
97 typedef struct UIPrefs
99 /* State of the main window when Geany was closed */
100 gint geometry[5]; /* 0:x, 1:y, 2:width, 3:height, flag for maximized state */
101 gboolean fullscreen;
102 gboolean sidebar_visible;
103 gint sidebar_page;
104 gboolean msgwindow_visible;
105 gboolean allow_always_save; /* if set, files can always be saved, even if unchanged */
106 gboolean new_document_after_close;
108 /* Menu-item related data */
109 GQueue *recent_queue;
110 GQueue *recent_projects_queue;
111 gchar *custom_date_format;
112 gchar **custom_commands;
113 gchar **custom_commands_labels;
115 UIPrefs;
117 extern UIPrefs ui_prefs;
120 /* Less commonly used widgets */
121 typedef struct UIWidgets
123 /* menu widgets */
124 GtkWidget *toolbar_menu;
125 GtkWidget *recent_files_menuitem;
126 GtkWidget *recent_files_menu_menubar;
127 GtkWidget *print_page_setup;
128 GtkWidget *recent_projects_menuitem;
129 GtkWidget *recent_projects_menu_menubar;
131 /* dialogs */
132 GtkWidget *open_colorsel;
133 GtkWidget *open_fontsel;
134 GtkWidget *prefs_dialog;
136 /* other widgets not needed in GeanyMainWidgets */
137 GtkWidget *statusbar; /* use ui_set_statusbar() to set */
139 UIWidgets;
141 extern UIWidgets ui_widgets;
144 /* The following block of types & functions are more generic and closely related to
145 * certain GTK+ widgets. */
147 typedef struct GeanyAutoSeparator
149 GtkWidget *widget; /* e.g. GtkSeparatorToolItem, GtkSeparatorMenuItem */
150 gint ref_count; /* set to zero initially */
152 GeanyAutoSeparator;
155 typedef enum
157 GEANY_EDITOR_SHOW_MARKERS_MARGIN,
158 GEANY_EDITOR_SHOW_LINE_NUMBERS,
159 GEANY_EDITOR_SHOW_WHITE_SPACE,
160 GEANY_EDITOR_SHOW_INDENTATION_GUIDES,
161 GEANY_EDITOR_SHOW_LINE_ENDINGS
163 GeanyUIEditorFeatures;
166 #define GEANY_STOCK_SAVE_ALL "geany-save-all"
167 #define GEANY_STOCK_CLOSE_ALL "geany-close-all"
168 #define GEANY_STOCK_BUILD "geany-build"
170 enum
172 GEANY_IMAGE_LOGO,
173 GEANY_IMAGE_SAVE_ALL,
174 GEANY_IMAGE_CLOSE_ALL,
175 GEANY_IMAGE_BUILD
179 void ui_widget_show_hide(GtkWidget *widget, gboolean show);
181 void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
183 void ui_menu_sort_by_label(GtkMenu *menu);
185 gchar *ui_menu_item_get_text(GtkMenuItem *menu_item);
187 GtkWidget *ui_frame_new_with_alignment(const gchar *label_text, GtkWidget **alignment);
189 GtkWidget *ui_dialog_vbox_new(GtkDialog *dialog);
191 GtkWidget *ui_button_new_with_image(const gchar *stock_id, const gchar *text);
193 GtkWidget *ui_image_menu_item_new(const gchar *stock_id, const gchar *label);
195 void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy);
197 void ui_combo_box_add_to_history(GtkComboBoxEntry *combo_entry,
198 const gchar *text, gint history_len);
200 void ui_combo_box_prepend_text_once(GtkComboBox *combo, const gchar *text);
202 GtkWidget *ui_path_box_new(const gchar *title, GtkFileChooserAction action, GtkEntry *entry);
204 void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title,
205 GtkFileChooserAction action, GtkEntry *entry);
207 void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED;
209 void ui_auto_separator_add_ref(GeanyAutoSeparator *autosep, GtkWidget *item);
211 void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text);
213 GtkWidget *ui_lookup_widget(GtkWidget *widget, const gchar *widget_name);
215 gpointer ui_builder_get_object (const gchar *name);
217 /* Compatibility functions */
218 GtkWidget *create_edit_menu1(void);
219 GtkWidget *create_prefs_dialog(void);
220 GtkWidget *create_project_dialog(void);
221 GtkWidget *create_toolbar_popup_menu1(void);
222 GtkWidget *create_window1(void);
224 void ui_widget_set_sensitive(GtkWidget *widget, gboolean set);
226 void ui_entry_add_clear_icon(GtkEntry *entry);
228 void ui_entry_add_activate_backward_signal(GtkEntry *entry);
230 void ui_editable_insert_text_callback(GtkEditable *editable, gchar *new_text,
231 gint new_text_len, gint *position, gpointer data);
233 GtkWidget *ui_label_new_bold(const gchar *text);
235 void ui_label_set_markup(GtkLabel *label, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
237 const gchar *ui_lookup_stock_label(const gchar *stock_id);
239 /* End of general widget functions */
241 void ui_init_builder(void);
243 void ui_init(void);
245 void ui_init_prefs(void);
247 void ui_finalize_builder(void);
249 void ui_finalize(void);
251 void ui_init_toolbar_widgets(void);
253 void ui_init_stock_items(void);
255 void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label,
256 GtkContainer *parent);
258 void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback);
260 void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active,
261 GCallback callback, GCompareFunc sort_func);
263 void ui_set_statusbar(gboolean log, const gchar *format, ...) G_GNUC_PRINTF (2, 3);
265 void ui_update_statusbar(GeanyDocument *doc, gint pos);
268 /* This sets the window title according to the current filename. */
269 void ui_set_window_title(GeanyDocument *doc);
271 void ui_set_editor_font(const gchar *font_name);
273 void ui_set_fullscreen(void);
276 void ui_update_popup_reundo_items(GeanyDocument *doc);
278 void ui_update_popup_copy_items(GeanyDocument *doc);
280 void ui_update_popup_goto_items(gboolean enable);
283 void ui_update_menu_copy_items(GeanyDocument *doc);
285 void ui_update_insert_include_item(GeanyDocument *doc, gint item);
287 void ui_update_fold_items(void);
290 void ui_create_insert_menu_items(void);
292 void ui_create_insert_date_menu_items(void);
295 void ui_save_buttons_toggle(gboolean enable);
297 void ui_document_buttons_update(void);
300 void ui_sidebar_show_hide(void);
302 void ui_document_show_hide(GeanyDocument *doc);
304 void ui_set_search_entry_background(GtkWidget *widget, gboolean success);
307 GdkPixbuf *ui_new_pixbuf_from_inline(gint img);
309 GtkWidget *ui_new_image_from_inline(gint img);
312 void ui_create_recent_menus(void);
314 void ui_add_recent_document(GeanyDocument *doc);
316 void ui_add_recent_project_file(const gchar *utf8_filename);
319 void ui_update_tab_status(GeanyDocument *doc);
322 typedef gboolean TVMatchCallback(gboolean);
324 gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb);
326 gboolean ui_tree_view_find_previous(GtkTreeView *treeview, TVMatchCallback cb);
329 void ui_statusbar_showhide(gboolean state);
331 void ui_add_document_sensitive(GtkWidget *widget);
333 void ui_toggle_editor_features(GeanyUIEditorFeatures feature);
335 void ui_update_view_editor_menu_items(void);
337 void ui_progress_bar_start(const gchar *text);
339 void ui_progress_bar_stop(void);
341 void ui_swap_sidebar_pos(void);
343 gboolean ui_is_keyval_enter_or_return(guint keyval);
345 gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value);
347 GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size);
349 void ui_focus_current_document(void);
351 G_END_DECLS
353 #endif