17
18
* along with this program; if not, write to the Free Software
18
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* $Id: document.h 793 2006-09-06 16:09:08Z eht16 $
21
* $Id: document.h 2453 2008-04-08 14:07:17Z eht16 $
26
* Document related actions: new, save, open, etc.
27
* Also Scintilla search actions.
24
31
#ifndef GEANY_DOCUMENT_H
25
32
#define GEANY_DOCUMENT_H 1
28
# define PLAT_GTK 1 // needed for ScintillaWidget.h
31
34
#include "Scintilla.h"
32
35
#include "ScintillaWidget.h"
35
#include "filetypes.h"
38
#define DOC_IDX_VALID(idx) \
39
((idx) >= 0 && (idx) < GEANY_MAX_OPEN_FILES && doc_list[idx].is_valid)
42
/* structure for representing an open tab with all its related stuff. */
38
typedef struct FileEncoding
46
* Structure for representing an open tab with all its properties.
43
48
typedef struct document
50
/** General flag to represent this document is active and all properties are set correctly. */
52
/** Whether this %document support source code symbols(tags) to show in the sidebar. */
47
// the filename is encoded in UTF-8, but every GLibC function expect the locale representation
54
/** The UTF-8 encoded file name. Be careful glibc and GLib functions expect the locale
55
representation of the file name which can be different from this.
56
For conversion into locale encoding for use with file functions of GLib, you can use
57
@ref utils_get_locale_from_utf8. */
59
/** The encoding of the %document, must be a valid string representation of an encoding, can
60
* be retrieved with @ref encodings_get_charset_from_index. */
62
/** Internally used flag to indicate whether the file of this %document has a byte-order-mark. */
64
/** The filetype for this %document, it's only a reference to one of the elements of the global
51
66
filetype *file_type;
67
/** TMWorkObject object for this %document. */
52
68
TMWorkObject *tm_file;
69
/** The Scintilla object for this %document. */
53
70
ScintillaObject *sci;
71
/** GtkLabel shown in the notebook header. */
54
72
GtkWidget *tab_label;
73
/** GtkLabel shown in the notebook right-click menu. */
55
74
GtkWidget *tabmenu_label;
75
/** GtkTreeView object for this %document within the Open Files treeview of the sidebar. */
56
76
GtkWidget *tag_tree;
77
/** GtkTreeStore object for this %document within the Open Files treeview of the sidebar. */
57
78
GtkTreeStore *tag_store;
79
/** Iter for this %document within the Open Files treeview of the sidebar. */
81
/** Whether this %document is read-only. */
83
/** Whether this %document has been changed since it was last saved. */
61
gboolean do_overwrite;
62
gboolean line_breaking;
63
gboolean use_auto_indention;
64
time_t last_check; // to remember the last disk check
85
/** %Document-specific line wrapping setting. */
86
gboolean line_wrapping;
87
/** %Document-specific indentation setting. */
89
/** Percentage to scroll view by on paint, if positive. */
90
gfloat scroll_percent;
91
/** Time of the last disk check. */
93
/** Modification time of this %document on disk. */
95
/** Internally used by the Undo/Redo management code. */
66
96
GTrashStack *undo_actions;
97
/** Internally used by the Undo/Redo management code. */
67
98
GTrashStack *redo_actions;
99
/** Internally used. */
100
FileEncoding saved_encoding;
101
/** %Document-specific tab setting. */
71
/* array of document elements to hold all information of the notebook tabs */
72
document doc_list[GEANY_MAX_OPEN_FILES];
76
/* returns the index of the notebook page which has the given filename */
77
gint document_find_by_filename(const gchar*, gboolean is_tm_filename);
80
/* returns the index of the notebook page which has sci */
81
gint document_find_by_sci(ScintillaObject*);
84
/* returns the index of the current notebook page in the document list */
85
gint document_get_cur_idx();
87
/* returns NULL if no documents are open */
88
document *document_get_current();
91
/* returns the index of the given notebook page in the document list */
92
gint document_get_n_idx(guint);
95
/* returns the next free place(i.e. index) in the document list
96
* If there is for any reason no free place, -1 is returned */
97
gint document_get_new_idx();
100
void document_set_text_changed(gint);
103
/* sets in all document structs the flag is_valid to FALSE and initializes some members to NULL,
104
* to mark it uninitialized. The flag is_valid is set to TRUE in document_create_new_sci(). */
105
void document_init_doclist();
108
// Apply just the prefs that can change in the Preferences dialog
109
void document_apply_update_prefs(ScintillaObject *sci);
112
/* creates a new tab in the notebook and does all related stuff
113
* finally it returns the index of the created document */
114
gint document_create_new_sci(const gchar*);
117
/* removes the given notebook tab and clears the related entry in the document
119
gboolean document_remove(guint);
122
/* This creates a new document, by clearing the text widget and setting the
123
current filename to NULL. */
124
void document_new_file(filetype *ft);
127
/* If idx is set to -1, it creates a new tab, opens the file from filename and
128
* set the cursor to pos.
129
* If idx is greater than -1, it reloads the file in the tab corresponding to
130
* idx and set the cursor to position 0. In this case, filename should be NULL
131
* It returns the idx of the opened file or -1 if an error occurred.
133
int document_open_file(gint, const gchar*, gint, gboolean, filetype*, const gchar*);
135
int document_reload_file(gint idx, const gchar *forced_enc);
138
/* This saves the file.
139
* When force is set then it is always saved, even if it is unchanged(useful when using Save As)
140
* It returns whether the file could be saved or not. */
106
/* Dynamic array of document elements to hold all information of the notebook tabs. */
107
extern GArray *doc_array;
110
* doc_list wraps doc_array so it can be used with C array syntax.
111
* Example: doc_list[0].sci = NULL;
113
#define doc_list ((document *)doc_array->data)
116
* DOC_IDX_VALID checks whether the passed index points to a valid %document object by checking
117
* important properties. It returns FALSE if the index is not valid and then this index
120
#define DOC_IDX_VALID(doc_idx) \
121
((doc_idx) >= 0 && (guint)(doc_idx) < doc_array->len && doc_list[doc_idx].is_valid)
124
* DOC_FILENAME) returns the filename of the %document corresponding to the passed index or
125
* GEANY_STRING_UNTITLED (e.g. _("untitled")) if the %document's filename was not yet set.
126
* This macro never returns NULL.
128
#define DOC_FILENAME(doc_idx) \
129
((doc_list[doc_idx].file_name != NULL) ? (doc_list[doc_idx].file_name) : GEANY_STRING_UNTITLED)
132
gint document_find_by_filename(const gchar *filename, gboolean is_tm_filename);
134
gint document_find_by_sci(ScintillaObject *sci);
136
gint document_get_notebook_page(gint doc_idx);
138
gint document_get_n_idx(guint page_num);
140
gint document_get_cur_idx(void);
142
document *document_get_current(void);
144
void document_init_doclist(void);
146
void document_finalize(void);
149
void document_set_text_changed(gint idx);
152
void document_apply_update_prefs(gint idx);
154
gboolean document_remove(guint page_num);
156
gint document_new_file_if_non_open();
158
gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
160
gint document_clone(gint old_idx, const gchar *utf8_filename);
163
gint document_open_file(const gchar *locale_filename, gboolean readonly,
164
filetype *ft, const gchar *forced_enc);
166
gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean readonly,
167
filetype *ft, const gchar *forced_enc);
169
void document_open_file_list(const gchar *data, gssize length);
171
void document_open_files(const GSList *filenames, gboolean readonly, filetype *ft,
172
const gchar *forced_enc);
174
gboolean document_reload_file(gint idx, const gchar *forced_enc);
177
gboolean document_save_file_as(gint idx);
141
179
gboolean document_save_file(gint idx, gboolean force);
143
/* special search function, used from the find entry in the toolbar */
144
void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
146
/* General search function, used from the find dialog.
147
* Returns -1 on failure or the start position of the matching text. */
148
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards);
150
void document_replace_text(gint, const gchar*, const gchar*, gint, gboolean);
152
void document_replace_all(gint, const gchar*, const gchar*, gint, gboolean);
154
void document_replace_sel(gint, const gchar*, const gchar*, gint, gboolean);
156
void document_set_font(gint, const gchar*, gint);
158
void document_update_tag_list(gint, gboolean);
160
void document_set_filetype(gint, filetype*);
162
gchar *document_get_eol_mode(gint);
164
gchar *document_prepare_template(filetype *ft);
182
gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
184
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards,
185
gboolean scroll, GtkWidget *parent);
187
gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
188
gint flags, gboolean search_backwards);
190
gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
191
gint flags, gboolean escaped_chars);
193
void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags,
194
gboolean escaped_chars);
196
void document_set_font(gint idx, const gchar *font_name, gint size);
198
void document_update_tag_list(gint idx, gboolean update);
200
void document_set_filetype(gint idx, filetype *type);
202
gchar *document_get_eol_mode(gint idx);
166
204
void document_fold_all(gint idx);