Add 'Refresh' popup menu item (part of geany-plugins #2999858).
[geany-mirror.git] / src / document.h
blob9eb8975343e0a4af170063f3bf6b783385b0c8c8
1 /*
2 * document.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2010 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.
21 * $Id$
24 /**
25 * @file document.h
26 * Document related actions: new, save, open, etc.
27 **/
28 /* Also Scintilla search actions - but these should probably be moved to search.c. */
31 #ifndef GEANY_DOCUMENT_H
32 #define GEANY_DOCUMENT_H 1
34 #include "Scintilla.h"
35 #include "ScintillaWidget.h"
37 #if defined(G_OS_WIN32)
38 # define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CRLF
39 #elif defined(G_OS_UNIX)
40 # define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_LF
41 #else
42 # define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CR
43 #endif
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 show_tab_cross;
55 guint mru_length;
56 gint default_eol_character;
57 gint disk_check_timeout;
58 gboolean cmdline_new_files; /* New file if command-line filename doesn't exist */
59 gboolean use_safe_file_saving;
61 GeanyFilePrefs;
63 extern GeanyFilePrefs file_prefs;
66 /**
67 * Structure for representing an open tab with all its properties.
68 **/
69 struct GeanyDocument
71 /** General flag to represent this document is active and all properties are set correctly. */
72 gboolean is_valid;
73 gint index; /**< Index in the documents array. */
74 /** Whether this document supports source code symbols(tags) to show in the sidebar. */
75 gboolean has_tags;
76 /** The UTF-8 encoded file name.
77 * Be careful; glibc and GLib file functions expect the locale representation of the
78 * file name which can be different from this.
79 * For conversion into locale encoding, you can use @ref utils_get_locale_from_utf8().
80 * @see real_path. */
81 gchar *file_name;
82 /** The encoding of the document, must be a valid string representation of an encoding, can
83 * be retrieved with @ref encodings_get_charset_from_index. */
84 gchar *encoding;
85 /** Internally used flag to indicate whether the file of this document has a byte-order-mark. */
86 gboolean has_bom;
87 struct GeanyEditor *editor; /**< The editor associated with the document. */
88 /** The filetype for this document, it's only a reference to one of the elements of the global
89 * filetypes array. */
90 GeanyFiletype *file_type;
91 /** TMWorkObject object for this document, or @c NULL. */
92 TMWorkObject *tm_file;
93 /** Whether this document is read-only. */
94 gboolean readonly;
95 /** Whether this document has been changed since it was last saved. */
96 gboolean changed;
97 /** The link-dereferenced, locale-encoded file name.
98 * If non-NULL, this indicates the file once existed on disk (not just as an
99 * unsaved document with a filename set).
101 * @note This is only assigned after a successful save or open - it should
102 * not be set elsewhere.
103 * @see file_name. */
104 gchar *real_path;
106 struct GeanyDocumentPrivate *priv; /* should be last, append fields before this item */
109 extern GPtrArray *documents_array;
112 /** Wraps documents_array so it can be used with C array syntax.
113 * Example: documents[0]->sci = NULL;
114 * @see document_index(). */
115 #define documents ((GeanyDocument **)GEANY(documents_array)->pdata)
117 /** @deprecated Use @ref foreach_document() instead.
118 * Iterates all valid documents.
119 * Use like a @c for statement.
120 * @param i @c guint index for document_index(). */
121 #ifndef GEANY_DISABLE_DEPRECATED
122 #define documents_foreach(i) foreach_document(i)
123 #endif
125 /** Iterates all valid documents.
126 * Use like a @c for statement.
127 * @param i @c guint index for document_index(). */
128 #define foreach_document(i) \
129 for (i = 0; i < GEANY(documents_array)->len; i++)\
130 if (!documents[i]->is_valid)\
132 else /* prevent outside 'else' matching our macro 'if' */
134 /** @c NULL-safe way to check @c doc_ptr->is_valid.
135 * This is useful when @a doc_ptr was stored some time earlier and documents may have been
136 * closed since then.
137 * @note This should not be used to check the result of the main API functions,
138 * these only need a NULL-pointer check - @c document_get_current() != @c NULL. */
139 #define DOC_VALID(doc_ptr) \
140 (G_LIKELY((doc_ptr) != NULL) && G_LIKELY((doc_ptr)->is_valid))
143 * Returns the filename of the document passed or @c GEANY_STRING_UNTITLED
144 * (e.g. _("untitled")) if the document's filename was not yet set.
145 * This macro never returns @c NULL.
147 #define DOC_FILENAME(doc) \
148 (G_LIKELY(doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED)
152 /* These functions will replace the older functions. For now they have a documents_ prefix. */
154 GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
156 GeanyDocument* document_new_file_if_non_open(void);
158 GeanyDocument* document_find_by_filename(const gchar *utf8_filename);
160 GeanyDocument* document_find_by_real_path(const gchar *realname);
162 gboolean document_save_file(GeanyDocument *doc, gboolean force);
164 gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname);
166 GeanyDocument* document_open_file(const gchar *locale_filename, gboolean readonly,
167 GeanyFiletype *ft, const gchar *forced_enc);
169 gboolean document_reload_file(GeanyDocument *doc, const gchar *forced_enc);
171 void document_set_text_changed(GeanyDocument *doc, gboolean changed);
173 void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
175 void document_reload_config(GeanyDocument *doc);
177 void document_rename_file(GeanyDocument *doc, const gchar *new_filename);
179 GeanyDocument *document_index(gint idx);
181 GeanyDocument *document_find_by_sci(ScintillaObject *sci);
183 gint document_get_notebook_page(GeanyDocument *doc);
185 GeanyDocument* document_get_from_page(guint page_num);
187 GeanyDocument *document_get_current(void);
189 void document_init_doclist(void);
191 void document_finalize(void);
193 gboolean document_remove_page(guint page_num);
195 void document_try_focus(GeanyDocument *doc, GtkWidget *source_widget);
197 gboolean document_close(GeanyDocument *doc);
199 gboolean document_account_for_unsaved(void);
201 gboolean document_close_all(void);
203 GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename);
205 GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos,
206 gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
208 void document_open_file_list(const gchar *data, gssize length);
210 void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
211 const gchar *forced_enc);
213 gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint flags, gboolean inc);
215 gint document_find_text(GeanyDocument *doc, const gchar *text, gint flags, gboolean search_backwards,
216 gboolean scroll, GtkWidget *parent);
218 gint document_replace_text(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
219 gint flags, gboolean search_backwards);
221 gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
222 gint flags, gboolean escaped_chars);
224 void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, gint flags,
225 gboolean escaped_chars);
227 void document_update_tag_list(GeanyDocument *doc, gboolean update);
229 void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
231 gboolean document_check_disk_status(GeanyDocument *doc, gboolean force);
233 /* own Undo / Redo implementation to be able to undo / redo changes
234 * to the encoding or the Unicode BOM (which are Scintilla independent).
235 * All Scintilla events are stored in the undo / redo buffer and are passed through. */
237 gboolean document_can_undo(GeanyDocument *doc);
239 gboolean document_can_redo(GeanyDocument *doc);
241 void document_undo(GeanyDocument *doc);
243 void document_redo(GeanyDocument *doc);
245 void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
247 void document_update_tab_label(GeanyDocument *doc);
249 const GdkColor *document_get_status_color(GeanyDocument *doc);
251 gchar *document_get_basename_for_display(GeanyDocument *doc, gint length);
253 gboolean document_need_save_as(GeanyDocument *doc);
255 void document_apply_indent_settings(GeanyDocument *doc);
257 #endif