~ubuntu-branches/debian/experimental/geany/experimental

« back to all changes in this revision

Viewing changes to src/document.h

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (3.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      document.h - this file is part of Geany, a fast and lightweight IDE
3
3
 *
4
 
 *      Copyright 2006 Enrico Troeger <enrico.troeger@uvena.de>
 
4
 *      Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
 
5
 *      Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
5
6
 *
6
7
 *      This program is free software; you can redistribute it and/or modify
7
8
 *      it under the terms of the GNU General Public License as published by
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.
19
20
 *
20
 
 *  $Id: document.h 793 2006-09-06 16:09:08Z eht16 $
 
21
 *  $Id: document.h 2453 2008-04-08 14:07:17Z eht16 $
21
22
 */
22
23
 
 
24
/**
 
25
 *  @file document.h
 
26
 *  Document related actions: new, save, open, etc.
 
27
 *  Also Scintilla search actions.
 
28
 **/
 
29
 
23
30
 
24
31
#ifndef GEANY_DOCUMENT_H
25
32
#define GEANY_DOCUMENT_H 1
26
33
 
27
 
#ifndef PLAT_GTK
28
 
#   define PLAT_GTK 1   // needed for ScintillaWidget.h
29
 
#endif
30
 
 
31
34
#include "Scintilla.h"
32
35
#include "ScintillaWidget.h"
33
36
 
34
 
#include "geany.h"
35
 
#include "filetypes.h"
36
 
 
37
 
 
38
 
#define DOC_IDX_VALID(idx) \
39
 
        ((idx) >= 0 && (idx) < GEANY_MAX_OPEN_FILES && doc_list[idx].is_valid)
40
 
 
41
 
 
42
 
/* structure for representing an open tab with all its related stuff. */
 
37
 
 
38
typedef struct FileEncoding
 
39
{
 
40
        gchar                   *encoding;
 
41
        gboolean                 has_bom;
 
42
} FileEncoding;
 
43
 
 
44
 
 
45
/**
 
46
 *  Structure for representing an open tab with all its properties.
 
47
 **/
43
48
typedef struct document
44
49
{
 
50
        /** General flag to represent this document is active and all properties are set correctly. */
45
51
        gboolean                 is_valid;
 
52
        /** Whether this %document support source code symbols(tags) to show in the sidebar. */
46
53
        gboolean                 has_tags;
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. */
48
58
        gchar                   *file_name;
 
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. */
49
61
        gchar                   *encoding;
 
62
        /** Internally used flag to indicate whether the file of this %document has a byte-order-mark. */
50
63
        gboolean                 has_bom;
 
64
        /** The filetype for this %document, it's only a reference to one of the elements of the global
 
65
         *  filetypes array. */
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. */
58
80
        GtkTreeIter              iter;
 
81
        /** Whether this %document is read-only. */
59
82
        gboolean                 readonly;
 
83
        /** Whether this %document has been changed since it was last saved. */
60
84
        gboolean                 changed;
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. */
 
88
        gboolean                 auto_indent;
 
89
        /** Percentage to scroll view by on paint, if positive. */
 
90
        gfloat                   scroll_percent;
 
91
        /** Time of the last disk check. */
 
92
        time_t                   last_check;
 
93
        /** Modification time of this %document on disk. */
65
94
        time_t                   mtime;
 
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. */
 
102
        gboolean                 use_tabs;
68
103
} document;
69
104
 
70
105
 
71
 
/* array of document elements to hold all information of the notebook tabs */
72
 
document doc_list[GEANY_MAX_OPEN_FILES];
73
 
 
74
 
 
75
 
 
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);
78
 
 
79
 
 
80
 
/* returns the index of the notebook page which has sci */
81
 
gint document_find_by_sci(ScintillaObject*);
82
 
 
83
 
 
84
 
/* returns the index of the current notebook page in the document list */
85
 
gint document_get_cur_idx();
86
 
 
87
 
/* returns NULL if no documents are open */
88
 
document *document_get_current();
89
 
 
90
 
 
91
 
/* returns the index of the given notebook page in the document list */
92
 
gint document_get_n_idx(guint);
93
 
 
94
 
 
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();
98
 
 
99
 
 
100
 
void document_set_text_changed(gint);
101
 
 
102
 
 
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();
106
 
 
107
 
 
108
 
// Apply just the prefs that can change in the Preferences dialog
109
 
void document_apply_update_prefs(ScintillaObject *sci);
110
 
 
111
 
 
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*);
115
 
 
116
 
 
117
 
/* removes the given notebook tab and clears the related entry in the document
118
 
 * list */
119
 
gboolean document_remove(guint);
120
 
 
121
 
 
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);
125
 
 
126
 
 
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.
132
 
 */
133
 
int document_open_file(gint, const gchar*, gint, gboolean, filetype*, const gchar*);
134
 
 
135
 
int document_reload_file(gint idx, const gchar *forced_enc);
136
 
 
137
 
 
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;
 
108
 
 
109
/**
 
110
 *  doc_list wraps doc_array so it can be used with C array syntax.
 
111
 *  Example: doc_list[0].sci = NULL;
 
112
 **/
 
113
#define doc_list ((document *)doc_array->data)
 
114
 
 
115
/**
 
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
 
118
 *  must not be used.
 
119
 **/
 
120
#define DOC_IDX_VALID(doc_idx) \
 
121
        ((doc_idx) >= 0 && (guint)(doc_idx) < doc_array->len && doc_list[doc_idx].is_valid)
 
122
 
 
123
/**
 
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.
 
127
 **/
 
128
#define DOC_FILENAME(doc_idx) \
 
129
        ((doc_list[doc_idx].file_name != NULL) ? (doc_list[doc_idx].file_name) : GEANY_STRING_UNTITLED)
 
130
 
 
131
 
 
132
gint document_find_by_filename(const gchar *filename, gboolean is_tm_filename);
 
133
 
 
134
gint document_find_by_sci(ScintillaObject *sci);
 
135
 
 
136
gint document_get_notebook_page(gint doc_idx);
 
137
 
 
138
gint document_get_n_idx(guint page_num);
 
139
 
 
140
gint document_get_cur_idx(void);
 
141
 
 
142
document *document_get_current(void);
 
143
 
 
144
void document_init_doclist(void);
 
145
 
 
146
void document_finalize(void);
 
147
 
 
148
 
 
149
void document_set_text_changed(gint idx);
 
150
 
 
151
 
 
152
void document_apply_update_prefs(gint idx);
 
153
 
 
154
gboolean document_remove(guint page_num);
 
155
 
 
156
gint document_new_file_if_non_open();
 
157
 
 
158
gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
 
159
 
 
160
gint document_clone(gint old_idx, const gchar *utf8_filename);
 
161
 
 
162
 
 
163
gint document_open_file(const gchar *locale_filename, gboolean readonly,
 
164
                filetype *ft, const gchar *forced_enc);
 
165
 
 
166
gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean readonly,
 
167
                filetype *ft, const gchar *forced_enc);
 
168
 
 
169
void document_open_file_list(const gchar *data, gssize length);
 
170
 
 
171
void document_open_files(const GSList *filenames, gboolean readonly, filetype *ft,
 
172
                const gchar *forced_enc);
 
173
 
 
174
gboolean document_reload_file(gint idx, const gchar *forced_enc);
 
175
 
 
176
 
 
177
gboolean document_save_file_as(gint idx);
 
178
 
141
179
gboolean document_save_file(gint idx, gboolean force);
142
180
 
143
 
/* special search function, used from the find entry in the toolbar */
144
 
void document_find_next(gint, const gchar*, gint, gboolean, gboolean);
145
 
 
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);
149
 
 
150
 
void document_replace_text(gint, const gchar*, const gchar*, gint, gboolean);
151
 
 
152
 
void document_replace_all(gint, const gchar*, const gchar*, gint, gboolean);
153
 
 
154
 
void document_replace_sel(gint, const gchar*, const gchar*, gint, gboolean);
155
 
 
156
 
void document_set_font(gint, const gchar*, gint);
157
 
 
158
 
void document_update_tag_list(gint, gboolean);
159
 
 
160
 
void document_set_filetype(gint, filetype*);
161
 
 
162
 
gchar *document_get_eol_mode(gint);
163
 
 
164
 
gchar *document_prepare_template(filetype *ft);
 
181
 
 
182
gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
 
183
 
 
184
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards,
 
185
                gboolean scroll, GtkWidget *parent);
 
186
 
 
187
gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
 
188
                gint flags, gboolean search_backwards);
 
189
 
 
190
gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
 
191
                gint flags, gboolean escaped_chars);
 
192
 
 
193
void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags,
 
194
                                                  gboolean escaped_chars);
 
195
 
 
196
void document_set_font(gint idx, const gchar *font_name, gint size);
 
197
 
 
198
void document_update_tag_list(gint idx, gboolean update);
 
199
 
 
200
void document_set_filetype(gint idx, filetype *type);
 
201
 
 
202
gchar *document_get_eol_mode(gint idx);
165
203
 
166
204
void document_fold_all(gint idx);
167
205
 
171
209
 
172
210
void document_clear_indicators(gint idx);
173
211
 
174
 
/* simple file print */
175
 
void document_print(gint idx);
176
 
 
177
212
void document_replace_tabs(gint idx);
178
213
 
 
214
void document_strip_line_trailing_spaces(gint idx, gint line);
 
215
 
179
216
void document_strip_trailing_spaces(gint idx);
180
217
 
181
218
void document_ensure_final_newline(gint idx);
182
219
 
 
220
void document_set_encoding(gint idx, const gchar *new_encoding);
183
221
 
184
222
 
185
223
/* own Undo / Redo implementation to be able to undo / redo changes
186
224
 * to the encoding or the Unicode BOM (which are Scintilla independet).
187
225
 * All Scintilla events are stored in the undo / redo buffer and are passed through. */
 
226
 
 
227
/* available UNDO actions, UNDO_SCINTILLA is a pseudo action to trigger Scintilla's
 
228
 * undo management */
188
229
enum
189
230
{
190
231
        UNDO_SCINTILLA = 0,
193
234
        UNDO_ACTIONS_MAX
194
235
};
195
236
 
 
237
/* an undo action, also used for redo actions */
196
238
typedef struct
197
239
{
198
 
        GTrashStack *next;
199
 
        guint type;     // to identify the action
200
 
        gpointer *data; // the old value (before the change)
 
240
        GTrashStack *next;      /* pointer to the next stack element(required for the GTrashStack) */
 
241
        guint type;                     /* to identify the action */
 
242
        gpointer *data;         /* the old value (before the change), in case of a redo action
 
243
                                                 * it contains the new value */
201
244
} undo_action;
202
245
 
203
246
gboolean document_can_undo(gint idx);
210
253
 
211
254
void document_undo_add(gint idx, guint type, gpointer data);
212
255
 
213
 
void document_undo_clear(gint idx);
214
 
 
215
 
void document_redo_clear(gint idx);
 
256
GdkColor *document_get_status(gint idx);
 
257
 
 
258
void document_delay_colourise(void);
 
259
 
 
260
void document_colourise_new(void);
 
261
 
 
262
void document_insert_colour(gint idx, const gchar *colour);
 
263
 
 
264
void document_set_use_tabs(gint idx, gboolean use_tabs);
 
265
 
 
266
void document_set_line_wrapping(gint idx, gboolean wrap);
216
267
 
217
268
#endif