Small NEWS update
[geany-mirror.git] / src / document.h
blob4533d2603374989b92bba016276b4ff58518e8bc
1 /*
2 * document.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005 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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /**
22 * @file document.h
23 * Document related actions: new, save, open, etc.
24 **/
25 /* Also Scintilla search actions - but these should probably be moved to search.c. */
28 #ifndef GEANY_DOCUMENT_H
29 #define GEANY_DOCUMENT_H 1
31 #include "editor.h"
32 #include "filetypes.h"
33 #include "geany.h"
34 #include "search.h"
36 #include "gtkcompat.h" /* Needed by ScintillaWidget.h */
37 #include "Scintilla.h" /* Needed by ScintillaWidget.h */
38 #include "ScintillaWidget.h" /* For ScintillaObject */
40 #include <glib.h>
43 G_BEGIN_DECLS
45 /** File Prefs. */
46 typedef struct GeanyFilePrefs
48 gint default_new_encoding;
49 gint default_open_encoding;
50 gboolean final_new_line;
51 gboolean strip_trailing_spaces;
52 gboolean replace_tabs;
53 gboolean tab_order_ltr;
54 gboolean tab_order_beside;
55 gboolean show_tab_cross;
56 guint mru_length;
57 gint default_eol_character;
58 gint disk_check_timeout;
59 gboolean cmdline_new_files; /* New file if command-line filename doesn't exist */
60 gboolean use_safe_file_saving;
61 gboolean ensure_convert_new_lines;
62 gboolean gio_unsafe_save_backup;
63 gboolean use_gio_unsafe_file_saving; /* whether to use GIO as the unsafe backend */
64 gchar *extract_filetype_regex; /* regex to extract filetype on opening */
65 gboolean tab_close_switch_to_mru;
66 gboolean keep_edit_history_on_reload; /* Keep undo stack upon, and allow undoing of, document reloading. */
67 gboolean show_keep_edit_history_on_reload_msg; /* whether to show the message introducing the above feature */
68 gboolean reload_clean_doc_on_file_change;
69 gboolean save_config_on_file_change;
71 GeanyFilePrefs;
74 #define GEANY_TYPE_DOCUMENT (document_get_type())
75 GType document_get_type (void);
77 /**
78 * Structure for representing an open tab with all its properties.
79 **/
80 typedef struct GeanyDocument
82 /** Flag used to check if this document is valid when iterating @ref GeanyData::documents_array. */
83 gboolean is_valid;
84 gint index; /**< Index in the documents array. */
85 /** Whether this document supports source code symbols(tags) to show in the sidebar. */
86 gboolean has_tags;
87 /** The UTF-8 encoded file name.
88 * Be careful; glibc and GLib file functions expect the locale representation of the
89 * file name which can be different from this.
90 * For conversion into locale encoding, you can use @ref utils_get_locale_from_utf8().
91 * @see real_path. */
92 gchar *file_name;
93 /** The encoding of the document, must be a valid string representation of an encoding, can
94 * be retrieved with @ref encodings_get_charset_from_index. */
95 gchar *encoding;
96 /** Internally used flag to indicate whether the file of this document has a byte-order-mark. */
97 gboolean has_bom;
98 GeanyEditor *editor; /**< The editor associated with the document. */
99 /** The filetype for this document, it's only a reference to one of the elements of the global
100 * filetypes array. */
101 GeanyFiletype *file_type;
102 /** TMSourceFile object for this document, or @c NULL. */
103 TMSourceFile *tm_file;
104 /** Whether this document is read-only. */
105 gboolean readonly;
106 /** Whether this document has been changed since it was last saved. */
107 gboolean changed;
108 /** The link-dereferenced, locale-encoded file name.
109 * If non-NULL, this indicates the file once existed on disk (not just as an
110 * unsaved document with a filename set).
112 * @note This is only assigned after a successful save or open - it should
113 * not be set elsewhere.
114 * @see file_name. */
115 gchar *real_path;
116 /** A pseudo-unique ID for this document.
117 * @c 0 is reserved as an unused value.
118 * @see document_find_by_id(). */
119 guint id;
121 struct GeanyDocumentPrivate *priv; /* should be last, append fields before this item */
123 GeanyDocument;
125 /** Wraps @ref GeanyData::documents_array so it can be used with C array syntax.
126 * @warning Always check the returned document is valid (@c doc->is_valid).
128 * Example: @code GeanyDocument *doc = documents[i]; @endcode
129 * @see documents_array(). */
130 #define documents ((GeanyDocument **)GEANY(documents_array)->pdata)
132 /** @deprecated Use @ref foreach_document() instead.
133 * Iterates all valid documents.
134 * Use like a @c for statement.
135 * @param i @c guint index for document_index(). */
136 #ifndef GEANY_DISABLE_DEPRECATED
137 #define documents_foreach(i) foreach_document(i)
138 #endif
140 /** Iterates all valid document indexes.
141 * Use like a @c for statement.
142 * @param i @c guint index for @ref GeanyData::documents_array.
144 * Example:
145 * @code
146 * guint i;
147 * foreach_document(i)
149 * GeanyDocument *doc = documents[i];
150 * g_assert(doc->is_valid);
152 * @endcode */
153 #define foreach_document(i) \
154 for (i = 0; i < GEANY(documents_array)->len; i++)\
155 if (!documents[i]->is_valid)\
157 else /* prevent outside 'else' matching our macro 'if' */
159 /** Null-safe way to check @ref GeanyDocument::is_valid.
160 * @note This should not be used to check the result of the main API functions,
161 * these only need a NULL-pointer check - @c document_get_current() != @c NULL. */
162 #define DOC_VALID(doc_ptr) \
163 ((doc_ptr) != NULL && (doc_ptr)->is_valid)
166 * Returns the filename of the document passed or @c GEANY_STRING_UNTITLED
167 * (e.g. _("untitled")) if the document's filename was not yet set.
168 * This macro never returns @c NULL.
170 #define DOC_FILENAME(doc) \
171 (G_LIKELY((doc)->file_name != NULL) ? ((doc)->file_name) : GEANY_STRING_UNTITLED)
174 GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
176 GeanyDocument *document_get_current(void);
178 GeanyDocument *document_get_from_notebook_child(GtkWidget *page);
180 GeanyDocument* document_get_from_page(guint page_num);
182 GeanyDocument* document_find_by_filename(const gchar *utf8_filename);
184 GeanyDocument* document_find_by_real_path(const gchar *realname);
186 gboolean document_save_file(GeanyDocument *doc, gboolean force);
188 GeanyDocument* document_open_file(const gchar *locale_filename, gboolean readonly,
189 GeanyFiletype *ft, const gchar *forced_enc);
191 void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
192 const gchar *forced_enc);
194 gboolean document_remove_page(guint page_num);
196 gboolean document_reload_force(GeanyDocument *doc, const gchar *forced_enc);
198 void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
200 void document_set_text_changed(GeanyDocument *doc, gboolean changed);
202 void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
204 gboolean document_close(GeanyDocument *doc);
206 GeanyDocument *document_index(gint idx);
208 gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname);
210 void document_rename_file(GeanyDocument *doc, const gchar *new_filename);
212 const GdkColor *document_get_status_color(GeanyDocument *doc);
214 gchar *document_get_basename_for_display(GeanyDocument *doc, gint length);
216 gint document_get_notebook_page(GeanyDocument *doc);
218 gint document_compare_by_display_name(gconstpointer a, gconstpointer b);
220 gint document_compare_by_tab_order(gconstpointer a, gconstpointer b);
222 gint document_compare_by_tab_order_reverse(gconstpointer a, gconstpointer b);
224 GeanyDocument *document_find_by_id(guint id);
227 #ifdef GEANY_PRIVATE
229 #if defined(G_OS_WIN32)
230 # define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CRLF
231 #else
232 # define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_LF
233 #endif
235 extern GeanyFilePrefs file_prefs;
236 extern GPtrArray *documents_array;
239 /* These functions will replace the older functions. For now they have a documents_ prefix. */
241 GeanyDocument* document_new_file_if_non_open(void);
243 gboolean document_reload_prompt(GeanyDocument *doc, const gchar *forced_enc);
245 void document_reload_config(GeanyDocument *doc);
247 GeanyDocument *document_find_by_sci(ScintillaObject *sci);
249 void document_show_tab(GeanyDocument *doc);
251 void document_init_doclist(void);
253 void document_finalize(void);
255 void document_try_focus(GeanyDocument *doc, GtkWidget *source_widget);
257 gboolean document_account_for_unsaved(void);
259 gboolean document_close_all(void);
261 GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos,
262 gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
264 void document_open_file_list(const gchar *data, gsize length);
266 gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gboolean inc,
267 gboolean backwards);
269 gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *original_text,
270 GeanyFindFlags flags, gboolean search_backwards, GeanyMatchInfo **match_,
271 gboolean scroll, GtkWidget *parent);
273 gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *original_find_text,
274 const gchar *replace_text, GeanyFindFlags flags, gboolean search_backwards);
276 gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
277 const gchar *original_find_text, const gchar *original_replace_text, GeanyFindFlags flags);
279 void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
280 const gchar *original_find_text, const gchar *original_replace_text, GeanyFindFlags flags);
282 void document_update_tags(GeanyDocument *doc);
284 void document_update_tag_list_in_idle(GeanyDocument *doc);
286 void document_highlight_tags(GeanyDocument *doc);
288 gboolean document_check_disk_status(GeanyDocument *doc, gboolean force);
290 /* own Undo / Redo implementation to be able to undo / redo changes
291 * to the encoding or the Unicode BOM (which are Scintilla independent).
292 * All Scintilla events are stored in the undo / redo buffer and are passed through. */
294 gboolean document_can_undo(GeanyDocument *doc);
296 gboolean document_can_redo(GeanyDocument *doc);
298 void document_undo(GeanyDocument *doc);
300 void document_redo(GeanyDocument *doc);
302 void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
304 void document_update_tab_label(GeanyDocument *doc);
306 const gchar *document_get_status_widget_class(GeanyDocument *doc);
308 gboolean document_need_save_as(GeanyDocument *doc);
310 gboolean document_detect_indent_type(GeanyDocument *doc, GeanyIndentType *type_);
312 gboolean document_detect_indent_width(GeanyDocument *doc, gint *width_);
314 void document_apply_indent_settings(GeanyDocument *doc);
316 void document_grab_focus(GeanyDocument *doc);
318 GeanyDocument *document_clone(GeanyDocument *old_doc);
320 gpointer document_get_data(const GeanyDocument *doc, const gchar *key);
322 void document_set_data(GeanyDocument *doc, const gchar *key, gpointer data);
324 void document_set_data_full(GeanyDocument *doc, const gchar *key,
325 gpointer data, GDestroyNotify free_func);
327 #endif /* GEANY_PRIVATE */
329 G_END_DECLS
331 #endif /* GEANY_DOCUMENT_H */