1 /* 2 * utils.h 3 * 4 * Copyright 2012 Dimitar Toshkov Zhekov <dimitar.zhekov@gmail.com> 5 * 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. 10 * 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. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef UTILS_H 21 22 #define show_error(...) dialogs_show_msgbox(GTK_MESSAGE_ERROR, __VA_ARGS__) 23 void show_errno(const char *prefix); 24 25 gboolean utils_set_nonblock(GPollFD *fd); 26 void utils_handle_button_press(GtkWidget *widget, GdkEventButton *event); 27 void utils_handle_button_release(GtkWidget *widget, GdkEventButton *event); 28 29 gboolean utils_check_path(const char *pathname, gboolean file, int mode); /* "" ok */ 30 const gchar *utils_skip_spaces(const gchar *text); 31 void utils_strchrepl(char *text, char c, char repl); 32 33 #define iff(expr, ...) if (G_UNLIKELY(!(expr))) dc_error(__VA_ARGS__); else 34 #define utils_atoi0(s) ((s) ? atoi(s) : 0) /* note: 2 references to s */ 35 36 gboolean store_find(ScpTreeStore *store, GtkTreeIter *iter, guint column, const char *key); 37 void store_foreach(ScpTreeStore *store, GFunc each_func, gpointer gdata); 38 void store_save(ScpTreeStore *store, GKeyFile *config, const char *prefix, 39 gboolean (*save_func)(GKeyFile *config, const char *section, GtkTreeIter *iter)); 40 gint store_gint_compare(ScpTreeStore *store, GtkTreeIter *a, GtkTreeIter *b, gpointer gdata); 41 gint store_seek_compare(ScpTreeStore *store, GtkTreeIter *a, GtkTreeIter *b, gpointer gdata); 42 #define store_clear(store) scp_tree_store_clear_children((store), NULL, FALSE) 43 44 void utils_load(GKeyFile *config, const char *prefix, 45 gboolean (*load_func)(GKeyFile *config, const char *section)); 46 void utils_stash_group_free(StashGroup *group); 47 48 typedef enum _SeekerType 49 { 50 SK_EXECUTE, /* if opening a file, mark it "scope open" */ 51 SK_EXEC_MARK, /* set marker execute if file already open */ 52 SK_DEFAULT 53 } SeekerType; 54 55 extern const char *const SCOPE_OPEN; 56 extern const char *const SCOPE_LOCK; 57 #define MARKER_BREAKPT (pref_sci_marker_first + 0) /* disabled bp, +1 is enabled */ 58 #define MARKER_EXECUTE (pref_sci_marker_first + 2) 59 60 void utils_seek(const char *file, gint line, gboolean focus, SeekerType seeker); 61 void utils_mark(const char *file, gint line, gboolean mark, gint marker); 62 63 gboolean utils_source_filetype(GeanyFiletype *ft); 64 gboolean utils_source_document(GeanyDocument *doc); 65 66 /* also (un)mark current line */ 67 void utils_lock(GeanyDocument *doc); 68 void utils_unlock(GeanyDocument *doc); 69 void utils_lock_unlock(GeanyDocument *doc, gboolean lock); 70 void utils_lock_all(gboolean lock); 71 72 #define utils_attrib(doc, attrib) (g_object_get_data(G_OBJECT((doc)->editor->sci), (attrib))) 73 #define utils_current_line(doc) (sci_get_current_line((doc)->editor->sci) + 1) 74 void utils_move_mark(ScintillaObject *sci, gint line, gint start, gint delta, gint marker); 75 void utils_remark(GeanyDocument *doc); /* NULL -> nop */ 76 77 guint utils_parse_sci_color(const gchar *string); 78 gboolean utils_key_file_write_to_file(GKeyFile *config, const char *configfile); 79 gchar *utils_key_file_get_string(GKeyFile *config, const char *section, const char *key); 80 gchar *utils_get_utf8_basename(const char *file); 81 82 char *utils_7bit_to_locale(char *text); /* == text */ 83 char *utils_get_locale_from_7bit(const char *text); 84 char *utils_get_locale_from_display(const gchar *display, gint hb_mode); 85 gchar *utils_get_display_from_7bit(const char *text, gint hb_mode); 86 gchar *utils_get_display_from_locale(const char *locale, gint hb_mode); 87 88 gchar *utils_verify_selection(gchar *text); 89 gchar *utils_get_default_selection(void); /* +verify */ 90 gboolean utils_matches_frame(const char *token); 91 92 enum 93 { 94 VALIDATOR_NUMERIC, 95 VALIDATOR_NOSPACE, 96 VALIDATOR_VARFRAME 97 }; 98 99 void validator_attach(GtkEditable *editable, gint validator); 100 gchar *validate_column(gchar *text, gboolean string); 101 GtkWidget *dialog_connect(const char *name); 102 103 gchar *utils_text_buffer_get_text(GtkTextBuffer *text, gint maxlen); 104 void utils_enter_to_clicked(GtkWidget *widget, GtkWidget *button); 105 void utils_tree_set_cursor(GtkTreeSelection *selection, GtkTreeIter *iter, gdouble alignment); 106 107 void utils_init(void); 108 void utils_finalize(void); 109 110 gchar *utils_evaluate_expr_from_string(gchar *chunk, guint peek_index); 111 gchar *utils_read_evaluate_expr(GeanyEditor *editor, gint pos); 112 113 #define UTILS_H 1 114 #endif 115