2 * ui_utils.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2006 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef GEANY_UI_UTILS_H
22 #define GEANY_UI_UTILS_H 1
24 #include "geany.h" /* for GEANY_DEPRECATED */
27 #include "gtkcompat.h"
31 /** Sets a name to lookup @a widget from @a owner.
32 * @param owner Usually a window, dialog or popup menu.
33 * @param widget Widget.
34 * @param widget_name Name.
35 * @see ui_lookup_widget().
39 #define ui_hookup_widget(owner, widget, widget_name) \
40 g_object_set_data_full(G_OBJECT(owner), widget_name, \
41 g_object_ref(widget), (GDestroyNotify)g_object_unref);
44 /** Interface preferences */
45 typedef struct GeanyInterfacePrefs
47 gboolean sidebar_symbol_visible
; /**< whether the symbol sidebar is visible */
48 gboolean sidebar_openfiles_visible
; /**< whether the open file list is visible */
49 gchar
*editor_font
; /**< editor font */
50 gchar
*tagbar_font
; /**< symbol sidebar font */
51 gchar
*msgwin_font
; /**< message window font */
52 gboolean show_notebook_tabs
; /**< whether editor tabs are visible */
53 gint tab_pos_editor
; /**< positions of editor's tabs */
54 gint tab_pos_msgwin
; /**< positions of message window's tabs */
55 gint tab_pos_sidebar
; /**< positions of sidebar's tabs */
56 gboolean statusbar_visible
; /**< whether the status bar is visible */
57 gboolean show_symbol_list_expanders
; /**< whether to show expanders in the symbol list */
58 /** whether a double click on notebook tabs hides all other windows */
59 gboolean notebook_double_click_hides_widgets
;
60 gboolean highlighting_invert_all
; /**< whether highlighting colors are inverted */
61 gint sidebar_pos
; /**< position of the sidebar (left or right) */
62 gboolean msgwin_status_visible
; /**< whether message window's status tab is visible */
63 gboolean msgwin_compiler_visible
; /**< whether message window's compiler tab is visible */
64 gboolean msgwin_messages_visible
; /**< whether message window's messages tab is visible */
65 gboolean msgwin_scribble_visible
; /**< whether message window's scribble tab is visible */
66 /** whether to use native Windows' dialogs (only used on Windows) */
67 gboolean use_native_windows_dialogs
;
68 /** whether compiler messages window is automatically scrolled to show new messages */
69 gboolean compiler_tab_autoscroll
;
70 gint msgwin_orientation
; /**< orientation of the message window */
71 gint symbols_sort_mode
; /**< symbol list sorting mode */
72 /** whether to show a warning when closing a project to open a new one */
73 gboolean warn_on_project_close
;
78 /** Important widgets in the main window.
79 * Accessed by @c geany->main_widgets. */
80 typedef struct GeanyMainWidgets
82 GtkWidget
*window
; /**< Main window. */
83 GtkWidget
*toolbar
; /**< Main toolbar. */
84 GtkWidget
*sidebar_notebook
; /**< Sidebar notebook. */
85 GtkWidget
*notebook
; /**< Document notebook. */
86 GtkWidget
*editor_menu
; /**< Popup editor menu. */
87 GtkWidget
*tools_menu
; /**< Most plugins add menu items to the Tools menu. */
88 /** Progress bar widget in the status bar to show progress of various actions.
89 * See ui_progress_bar_start() for details. */
90 GtkWidget
*progressbar
;
91 GtkWidget
*message_window_notebook
; /**< Message Window notebook. */
92 /** Plugins modifying the project can add their items to the Project menu. */
93 GtkWidget
*project_menu
;
98 #define GEANY_STOCK_SAVE_ALL "geany-save-all"
99 #define GEANY_STOCK_CLOSE_ALL "geany-close-all"
100 #define GEANY_STOCK_BUILD "geany-build"
103 GtkWidget
*ui_dialog_vbox_new(GtkDialog
*dialog
);
105 void ui_set_statusbar(gboolean log
, const gchar
*format
, ...) G_GNUC_PRINTF (2, 3);
107 void ui_table_add_row(GtkTable
*table
, gint row
, ...) G_GNUC_NULL_TERMINATED
;
109 GtkWidget
*ui_path_box_new(const gchar
*title
, GtkFileChooserAction action
, GtkEntry
*entry
);
111 GtkWidget
*ui_button_new_with_image(const gchar
*stock_id
, const gchar
*text
);
113 void ui_add_document_sensitive(GtkWidget
*widget
);
115 GtkWidget
*ui_image_menu_item_new(const gchar
*stock_id
, const gchar
*label
);
117 GtkWidget
*ui_lookup_widget(GtkWidget
*widget
, const gchar
*widget_name
);
119 void ui_progress_bar_start(const gchar
*text
);
121 void ui_progress_bar_stop(void);
123 void ui_entry_add_clear_icon(GtkEntry
*entry
);
125 void ui_menu_add_document_items(GtkMenu
*menu
, GeanyDocument
*active
, GCallback callback
);
127 void ui_menu_add_document_items_sorted(GtkMenu
*menu
, GeanyDocument
*active
,
128 GCallback callback
, GCompareFunc sort_func
);
130 void ui_widget_modify_font_from_string(GtkWidget
*wid
, const gchar
*str
);
132 gboolean
ui_is_keyval_enter_or_return(guint keyval
);
134 gint
ui_get_gtk_settings_integer(const gchar
*property_name
, gint default_value
);
136 void ui_combo_box_add_to_history(GtkComboBoxText
*combo_entry
,
137 const gchar
*text
, gint history_len
);
139 const gchar
*ui_lookup_stock_label(const gchar
*stock_id
);
141 void ui_tree_view_set_tooltip_text_column(GtkTreeView
*tree_view
, gint column
);
144 #ifndef GEANY_DISABLE_DEPRECATED
145 GtkWidget
*ui_frame_new_with_alignment(const gchar
*label_text
, GtkWidget
**alignment
) GEANY_DEPRECATED
;
147 void ui_widget_set_tooltip_text(GtkWidget
*widget
, const gchar
*text
) GEANY_DEPRECATED_FOR(gtk_widget_set_tooltip_text
);
148 #endif /* GEANY_DISABLE_DEPRECATED */
153 extern GeanyInterfacePrefs interface_prefs
;
155 extern GeanyMainWidgets main_widgets
;
158 /* User Interface settings not shown in the Prefs dialog. */
159 typedef struct UIPrefs
161 /* State of the main window when Geany was closed */
162 gint geometry
[5]; /* 0:x, 1:y, 2:width, 3:height, flag for maximized state */
164 gboolean sidebar_visible
;
166 gboolean msgwindow_visible
;
167 gboolean allow_always_save
; /* if set, files can always be saved, even if unchanged */
168 gchar
*statusbar_template
;
169 gboolean new_document_after_close
;
171 /* Menu-item related data */
172 GQueue
*recent_queue
;
173 GQueue
*recent_projects_queue
;
174 gchar
*custom_date_format
;
175 gchar
**custom_commands
;
176 gchar
**custom_commands_labels
;
178 /* Color picker settings */
179 gchar
*color_picker_palette
;
183 extern UIPrefs ui_prefs
;
186 /* Less commonly used widgets */
187 typedef struct UIWidgets
190 GtkWidget
*toolbar_menu
;
191 GtkWidget
*recent_files_menuitem
;
192 GtkWidget
*recent_files_menu_menubar
;
193 GtkWidget
*print_page_setup
;
194 GtkWidget
*recent_projects_menuitem
;
195 GtkWidget
*recent_projects_menu_menubar
;
196 GtkWidget
*config_files_filetype_menu
;
199 GtkWidget
*open_colorsel
;
200 GtkWidget
*open_fontsel
;
201 GtkWidget
*prefs_dialog
;
203 /* other widgets not needed in GeanyMainWidgets */
204 GtkWidget
*statusbar
; /* use ui_set_statusbar() to set */
208 extern UIWidgets ui_widgets
;
211 /* The following block of types & functions are more generic and closely related to
212 * certain GTK+ widgets. */
214 typedef struct GeanyAutoSeparator
216 GtkWidget
*widget
; /* e.g. GtkSeparatorToolItem, GtkSeparatorMenuItem */
217 gint show_count
; /* visible items, set to zero initially */
218 gint item_count
; /* total items, set to zero initially */
225 GEANY_EDITOR_SHOW_MARKERS_MARGIN
,
226 GEANY_EDITOR_SHOW_LINE_NUMBERS
,
227 GEANY_EDITOR_SHOW_WHITE_SPACE
,
228 GEANY_EDITOR_SHOW_INDENTATION_GUIDES
,
229 GEANY_EDITOR_SHOW_LINE_ENDINGS
231 GeanyUIEditorFeatures
;
234 void ui_widget_show_hide(GtkWidget
*widget
, gboolean show
);
236 gchar
*ui_menu_item_get_text(GtkMenuItem
*menu_item
);
238 void ui_dialog_set_primary_button_order(GtkDialog
*dialog
, gint response
, ...);
240 void ui_hbutton_box_copy_layout(GtkButtonBox
*master
, GtkButtonBox
*copy
);
242 void ui_combo_box_prepend_text_once(GtkComboBoxText
*combo
, const gchar
*text
);
244 void ui_setup_open_button_callback(GtkWidget
*open_btn
, const gchar
*title
,
245 GtkFileChooserAction action
, GtkEntry
*entry
);
247 void ui_auto_separator_add_ref(GeanyAutoSeparator
*autosep
, GtkWidget
*item
);
249 gpointer
ui_builder_get_object (const gchar
*name
);
251 /* Compatibility functions */
252 GtkWidget
*create_edit_menu1(void);
253 GtkWidget
*create_prefs_dialog(void);
254 GtkWidget
*create_project_dialog(void);
255 GtkWidget
*create_toolbar_popup_menu1(void);
256 GtkWidget
*create_window1(void);
258 void ui_widget_set_sensitive(GtkWidget
*widget
, gboolean set
);
260 void ui_entry_add_activate_backward_signal(GtkEntry
*entry
);
262 void ui_editable_insert_text_callback(GtkEditable
*editable
, gchar
*new_text
,
263 gint new_text_len
, gint
*position
, gpointer data
);
265 GtkWidget
*ui_label_new_bold(const gchar
*text
);
267 void ui_label_set_markup(GtkLabel
*label
, const gchar
*format
, ...) G_GNUC_PRINTF(2, 3);
269 /* End of general widget functions */
271 void ui_init_builder(void);
275 void ui_init_prefs(void);
277 void ui_finalize_builder(void);
279 void ui_init_toolbar_widgets(void);
281 void ui_init_stock_items(void);
283 void ui_add_config_file_menu_item(const gchar
*real_path
, const gchar
*label
,
284 GtkContainer
*parent
);
286 void ui_update_statusbar(GeanyDocument
*doc
, gint pos
);
289 /* This sets the window title according to the current filename. */
290 void ui_set_window_title(GeanyDocument
*doc
);
292 void ui_set_editor_font(const gchar
*font_name
);
294 void ui_set_fullscreen(void);
297 void ui_update_popup_reundo_items(GeanyDocument
*doc
);
299 void ui_update_popup_copy_items(GeanyDocument
*doc
);
301 void ui_update_popup_goto_items(gboolean enable
);
304 void ui_menu_copy_items_set_sensitive(gboolean sensitive
);
306 void ui_update_menu_copy_items(GeanyDocument
*doc
);
308 void ui_update_insert_include_item(GeanyDocument
*doc
, gint item
);
310 void ui_update_fold_items(void);
313 void ui_create_insert_menu_items(void);
315 void ui_create_insert_date_menu_items(void);
318 void ui_save_buttons_toggle(gboolean enable
);
320 void ui_document_buttons_update(void);
323 void ui_sidebar_show_hide(void);
325 void ui_document_show_hide(GeanyDocument
*doc
);
327 void ui_set_search_entry_background(GtkWidget
*widget
, gboolean success
);
330 void ui_create_recent_menus(void);
332 void ui_add_recent_document(GeanyDocument
*doc
);
334 void ui_add_recent_project_file(const gchar
*utf8_filename
);
336 void ui_update_recent_project_menu(void);
339 void ui_update_tab_status(GeanyDocument
*doc
);
342 typedef gboolean
TVMatchCallback(gboolean
);
344 gboolean
ui_tree_view_find_next(GtkTreeView
*treeview
, TVMatchCallback cb
);
346 gboolean
ui_tree_view_find_previous(GtkTreeView
*treeview
, TVMatchCallback cb
);
348 gboolean
ui_tree_model_iter_any_next(GtkTreeModel
*model
, GtkTreeIter
*iter
, gboolean down
);
350 void ui_statusbar_showhide(gboolean state
);
352 void ui_toggle_editor_features(GeanyUIEditorFeatures feature
);
354 void ui_update_view_editor_menu_items(void);
356 void ui_swap_sidebar_pos(void);
358 GIcon
*ui_get_mime_icon(const gchar
*mime_type
);
360 void ui_focus_current_document(void);
362 GtkWidget
*ui_create_encodings_combo_box(gboolean has_detect
, gint default_enc
);
364 gint
ui_encodings_combo_box_get_active_encoding(GtkComboBox
*combo
);
366 gboolean
ui_encodings_combo_box_set_active_encoding(GtkComboBox
*combo
, gint enc
);
368 gchar
*ui_get_project_directory(const gchar
*path
);
370 #endif /* GEANY_PRIVATE */
374 #endif /* GEANY_UI_UTILS_H */