geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

document.h
Go to the documentation of this file.
1/*
2 * document.h - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2005 The Geany contributors
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 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.
19 */
20
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. */
26
27
28#ifndef GEANY_DOCUMENT_H
29#define GEANY_DOCUMENT_H 1
30
31#include "editor.h"
32#include "filetypes.h"
33#include "geany.h"
34#include "search.h"
35
36#include "gtkcompat.h" /* Needed by ScintillaWidget.h */
37#include "Scintilla.h" /* Needed by ScintillaWidget.h */
38#include "ScintillaWidget.h" /* For ScintillaObject */
39
40#include <glib.h>
41
42
43G_BEGIN_DECLS
44
45/** File Prefs. */
46typedef struct GeanyFilePrefs
47{
52 gboolean replace_tabs;
53 gboolean tab_order_ltr;
59 gboolean cmdline_new_files; /* New file if command-line filename doesn't exist */
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 */
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 */
70}
72
73
74#define GEANY_TYPE_DOCUMENT (document_get_type())
75GType document_get_type (void);
76
77/**
78 * Structure for representing an open tab with all its properties.
79 **/
80typedef struct GeanyDocument
81{
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. */
102 /** TMSourceFile object for this document, or @c NULL. */
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).
111 *
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;
120
121 struct GeanyDocumentPrivate *priv; /* should be last, append fields before this item */
122}
124
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).
127 *
128 * Example: @code GeanyDocument *doc = documents[i]; @endcode
129 * @see documents_array(). */
130#define documents ((GeanyDocument **)GEANY(documents_array)->pdata)
131
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
139
140/** Iterates all valid document indexes.
141 * Use like a @c for statement.
142 * @param i @c guint index for @ref GeanyData::documents_array.
143 *
144 * Example:
145 * @code
146 * guint i;
147 * foreach_document(i)
148 * {
149 * GeanyDocument *doc = documents[i];
150 * g_assert(doc->is_valid);
151 * }
152 * @endcode */
153#define foreach_document(i) \
154 for (i = 0; i < GEANY(documents_array)->len; i++)\
155 if (!documents[i]->is_valid)\
156 {}\
157 else /* prevent outside 'else' matching our macro 'if' */
158
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)
164
165/**
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.
169 **/
170#define DOC_FILENAME(doc) \
171 (G_LIKELY((doc)->file_name != NULL) ? ((doc)->file_name) : GEANY_STRING_UNTITLED)
172
173
174GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
175
177
179
181
182GeanyDocument* document_find_by_filename(const gchar *utf8_filename);
183
184GeanyDocument* document_find_by_real_path(const gchar *realname);
185
186gboolean document_save_file(GeanyDocument *doc, gboolean force);
187
188GeanyDocument* document_open_file(const gchar *locale_filename, gboolean readonly,
189 GeanyFiletype *ft, const gchar *forced_enc);
190
191void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
192 const gchar *forced_enc);
193
194gboolean document_remove_page(guint page_num);
195
196gboolean document_reload_force(GeanyDocument *doc, const gchar *forced_enc);
197
198void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
199
200void document_set_text_changed(GeanyDocument *doc, gboolean changed);
201
203
204gboolean document_close(GeanyDocument *doc);
205
207
208gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname);
209
210void document_rename_file(GeanyDocument *doc, const gchar *new_filename);
211
212const GdkColor *document_get_status_color(GeanyDocument *doc);
213
214gchar *document_get_basename_for_display(GeanyDocument *doc, gint length);
215
217
218gint document_compare_by_display_name(gconstpointer a, gconstpointer b);
219
220gint document_compare_by_tab_order(gconstpointer a, gconstpointer b);
221
222gint document_compare_by_tab_order_reverse(gconstpointer a, gconstpointer b);
223
225
226
227#ifdef GEANY_PRIVATE
228
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
234
236extern GPtrArray *documents_array;
237
238
239/* These functions will replace the older functions. For now they have a documents_ prefix. */
240
242
243gboolean document_reload_prompt(GeanyDocument *doc, const gchar *forced_enc);
244
246
247GeanyDocument *document_find_by_sci(ScintillaObject *sci);
248
250
251void document_init_doclist(void);
252
253void document_finalize(void);
254
255void document_try_focus(GeanyDocument *doc, GtkWidget *source_widget);
256
257gboolean document_account_for_unsaved(void);
258
259gboolean document_close_all(void);
260
262 gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
263
264void document_open_file_list(const gchar *data, gsize length);
265
266gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gboolean inc,
267 gboolean backwards);
268
269gint 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);
272
273gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *original_find_text,
274 const gchar *replace_text, GeanyFindFlags flags, gboolean search_backwards);
275
276gint 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);
278
279void 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);
281
283
285
287
288gboolean document_check_disk_status(GeanyDocument *doc, gboolean force);
289
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. */
293
294gboolean document_can_undo(GeanyDocument *doc);
295
296gboolean document_can_redo(GeanyDocument *doc);
297
299
301
302void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
303
305
307
309
311
312gboolean document_detect_indent_width(GeanyDocument *doc, gint *width_);
313
315
317
319
320gpointer document_get_data(const GeanyDocument *doc, const gchar *key);
321
322void document_set_data(GeanyDocument *doc, const gchar *key, gpointer data);
323
324void document_set_data_full(GeanyDocument *doc, const gchar *key,
325 gpointer data, GDestroyNotify free_func);
326
327#endif /* GEANY_PRIVATE */
328
329G_END_DECLS
330
331#endif /* GEANY_DOCUMENT_H */
Interface to the edit control.
void document_init_doclist(void)
Definition: document.c:382
void document_update_tags(GeanyDocument *doc)
Definition: document.c:2647
GeanyDocument * document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
Definition: document.c:1285
void document_redo(GeanyDocument *doc)
Definition: document.c:3094
gboolean document_close_all(void)
Definition: document.c:3396
GeanyDocument * document_clone(GeanyDocument *old_doc)
Definition: document.c:3323
gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *original_text, GeanyFindFlags flags, gboolean search_backwards, GeanyMatchInfo **match_, gboolean scroll, GtkWidget *parent)
Definition: document.c:2317
gboolean document_can_redo(GeanyDocument *doc)
Definition: document.c:3083
GeanyDocument * document_new_file_if_non_open(void)
Definition: document.c:803
void document_grab_focus(GeanyDocument *doc)
Definition: document.c:3812
void document_undo_add(GeanyDocument *doc, guint type, gpointer data)
Definition: document.c:2955
void document_set_data_full(GeanyDocument *doc, const gchar *key, gpointer data, GDestroyNotify free_func)
Definition: document.c:3844
gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gboolean inc, gboolean backwards)
Definition: document.c:2241
void document_highlight_tags(GeanyDocument *doc)
Definition: document.c:2702
void document_show_tab(GeanyDocument *doc)
Definition: document.c:1273
gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
Definition: document.c:3674
GeanyDocument * document_find_by_sci(ScintillaObject *sci)
Definition: document.c:214
gboolean document_detect_indent_type(GeanyDocument *doc, GeanyIndentType *type_)
Definition: document.c:1107
void document_try_focus(GeanyDocument *doc, GtkWidget *source_widget)
Definition: document.c:595
gpointer document_get_data(const GeanyDocument *doc, const gchar *key)
Definition: document.c:3832
gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *original_find_text, const gchar *replace_text, GeanyFindFlags flags, gboolean search_backwards)
Definition: document.c:2397
void document_update_tag_list_in_idle(GeanyDocument *doc)
Definition: document.c:2772
void document_apply_indent_settings(GeanyDocument *doc)
Definition: document.c:1225
gboolean document_need_save_as(GeanyDocument *doc)
Definition: document.c:1795
const gchar * document_get_status_widget_class(GeanyDocument *doc)
Definition: document.c:3249
gboolean document_account_for_unsaved(void)
Definition: document.c:3360
GeanyFilePrefs file_prefs
Definition: document.c:86
void document_reload_config(GeanyDocument *doc)
Definition: document.c:2864
void document_undo(GeanyDocument *doc)
Definition: document.c:2985
void document_set_data(GeanyDocument *doc, const gchar *key, gpointer data)
Definition: document.c:3838
gboolean document_can_undo(GeanyDocument *doc)
Definition: document.c:2964
GPtrArray * documents_array
Definition: document.c:87
gboolean document_detect_indent_width(GeanyDocument *doc, gint *width_)
Definition: document.c:1219
void document_open_file_list(const gchar *data, gsize length)
Definition: document.c:1521
gboolean document_reload_prompt(GeanyDocument *doc, const gchar *forced_enc)
Definition: document.c:1635
void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, const gchar *original_find_text, const gchar *original_replace_text, GeanyFindFlags flags)
Definition: document.c:2520
void document_update_tab_label(GeanyDocument *doc)
Definition: document.c:430
gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, const gchar *original_find_text, const gchar *original_replace_text, GeanyFindFlags flags)
Definition: document.c:2623
void document_finalize(void)
Definition: document.c:388
GeanyDocument * document_index(gint idx)
Accessor function for GeanyData::documents_array items.
Definition: document.c:3317
GType document_get_type(void)
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding)
Sets the encoding of a document.
Definition: document.c:2879
struct GeanyDocument GeanyDocument
Structure for representing an open tab with all its properties.
const GdkColor * document_get_status_color(GeanyDocument *doc)
Gets the status color of the document, or NULL if default widget coloring should be used.
Definition: document.c:3276
gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname)
Saves the document, detecting the filetype.
Definition: document.c:1815
GeanyDocument * document_get_from_notebook_child(GtkWidget *page)
Definition: document.c:331
struct GeanyFilePrefs GeanyFilePrefs
File Prefs.
GeanyDocument * document_get_from_page(guint page_num)
Finds the document for the given notebook page page_num.
Definition: document.c:352
gint document_get_notebook_page(GeanyDocument *doc)
Gets the notebook page index for a document.
Definition: document.c:289
gboolean document_reload_force(GeanyDocument *doc, const gchar *forced_enc)
Reloads the document with the specified file encoding.
Definition: document.c:1595
gboolean document_save_file(GeanyDocument *doc, gboolean force)
Saves the document.
Definition: document.c:2103
void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
Sets the filetype of the document (which controls syntax highlighting and tags)
Definition: document.c:2826
void document_rename_file(GeanyDocument *doc, const gchar *new_filename)
Renames the file in doc to new_filename.
Definition: document.c:1749
gint document_compare_by_display_name(gconstpointer a, gconstpointer b)
Compares documents by their display names.
Definition: document.c:3746
gint document_compare_by_tab_order(gconstpointer a, gconstpointer b)
Compares documents by their tab order.
Definition: document.c:3776
GeanyDocument * document_find_by_filename(const gchar *utf8_filename)
Finds a document with the given filename.
Definition: document.c:183
void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
Opens each file in the list filenames.
Definition: document.c:1555
gchar * document_get_basename_for_display(GeanyDocument *doc, gint length)
Returns the last part of the filename of the given GeanyDocument.
Definition: document.c:412
GeanyDocument * document_open_file(const gchar *locale_filename, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
Opens a document specified by locale_filename.
Definition: document.c:908
GeanyDocument * document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text)
Creates a new document.
Definition: document.c:824
GeanyDocument * document_find_by_id(guint id)
Lookup an old document by its ID.
Definition: document.c:247
gboolean document_remove_page(guint page_num)
Removes the given notebook tab at page_num and clears all related information in the document list.
Definition: document.c:782
gboolean document_close(GeanyDocument *doc)
Closes the given document.
Definition: document.c:689
GeanyDocument * document_find_by_real_path(const gchar *realname)
Finds a document whose real_path field matches the given filename.
Definition: document.c:137
gint document_compare_by_tab_order_reverse(gconstpointer a, gconstpointer b)
Compares documents by their tab order, in reverse order.
Definition: document.c:3806
void document_set_text_changed(GeanyDocument *doc, gboolean changed)
Updates the tab labels, the status bar, the window title and some save-sensitive buttons according to...
Definition: document.c:460
gchar * text
Definition: editor.c:83
ScintillaObject * sci
Definition: editor.c:88
gint pos
Definition: editor.c:87
Editor-related functions for GeanyEditor.
GeanyIndentType
Whether to use tabs, spaces or both to indent.
Definition: editor.h:45
Filetype detection, file extensions and filetype menu items.
Search (prefs).
GeanyFindFlags
Definition: search.h:36
const gchar filename[]
Definition: stash-example.c:4
Structure for representing an open tab with all its properties.
Definition: document.h:81
gchar * file_name
The UTF-8 encoded file name.
Definition: document.h:92
gboolean changed
Whether this document has been changed since it was last saved.
Definition: document.h:107
GeanyFiletype * file_type
The filetype for this document, it's only a reference to one of the elements of the global filetypes ...
Definition: document.h:101
gboolean has_tags
Whether this document supports source code symbols(tags) to show in the sidebar.
Definition: document.h:86
struct GeanyDocumentPrivate * priv
Definition: document.h:121
gboolean has_bom
Internally used flag to indicate whether the file of this document has a byte-order-mark.
Definition: document.h:97
gchar * real_path
The link-dereferenced, locale-encoded file name.
Definition: document.h:115
gchar * encoding
The encoding of the document, must be a valid string representation of an encoding,...
Definition: document.h:95
gboolean readonly
Whether this document is read-only.
Definition: document.h:105
gboolean is_valid
Flag used to check if this document is valid when iterating GeanyData::documents_array.
Definition: document.h:83
gint index
Index in the documents array.
Definition: document.h:84
GeanyEditor * editor
The editor associated with the document.
Definition: document.h:98
guint id
A pseudo-unique ID for this document.
Definition: document.h:119
TMSourceFile * tm_file
TMSourceFile object for this document, or NULL.
Definition: document.h:103
Editor-owned fields for each document.
Definition: editor.h:150
File Prefs.
Definition: document.h:47
gboolean reload_clean_doc_on_file_change
Definition: document.h:68
gboolean use_safe_file_saving
Definition: document.h:60
gboolean keep_edit_history_on_reload
Definition: document.h:66
gint default_new_encoding
Definition: document.h:48
guint mru_length
Definition: document.h:56
gboolean show_keep_edit_history_on_reload_msg
Definition: document.h:67
gboolean tab_order_beside
Definition: document.h:54
gint disk_check_timeout
Definition: document.h:58
gint default_open_encoding
Definition: document.h:49
gboolean gio_unsafe_save_backup
Definition: document.h:62
gboolean use_gio_unsafe_file_saving
Definition: document.h:63
gboolean strip_trailing_spaces
Definition: document.h:51
gboolean cmdline_new_files
Definition: document.h:59
gchar * extract_filetype_regex
Definition: document.h:64
gboolean final_new_line
Definition: document.h:50
gint default_eol_character
Definition: document.h:57
gboolean show_tab_cross
Definition: document.h:55
gboolean ensure_convert_new_lines
Definition: document.h:61
gboolean save_config_on_file_change
Definition: document.h:69
gboolean tab_close_switch_to_mru
Definition: document.h:65
gboolean replace_tabs
Definition: document.h:52
gboolean tab_order_ltr
Definition: document.h:53
Represents a filetype.
Definition: filetypes.h:144
The TMSourceFile structure represents the source file and its tags in the tag manager.