2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* document.h - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-05-10 23:06:47 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
2005-12-29 19:50:50 +00:00
|
|
|
* $Id$
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* @file document.h
|
|
|
|
* Document related actions: new, save, open, etc.
|
|
|
|
* Also Scintilla search actions.
|
|
|
|
**/
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#ifndef GEANY_DOCUMENT_H
|
|
|
|
#define GEANY_DOCUMENT_H 1
|
|
|
|
|
2006-08-20 20:39:59 +00:00
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "ScintillaWidget.h"
|
|
|
|
|
2008-05-14 15:36:27 +00:00
|
|
|
#if defined(G_OS_WIN32)
|
|
|
|
# define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CRLF
|
|
|
|
#elif defined(G_OS_UNIX)
|
|
|
|
# define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_LF
|
|
|
|
#else
|
|
|
|
# define GEANY_DEFAULT_EOL_CHARACTER SC_EOL_CR
|
|
|
|
#endif
|
|
|
|
|
2006-09-02 20:49:11 +00:00
|
|
|
|
2006-10-24 13:41:34 +00:00
|
|
|
typedef struct FileEncoding
|
|
|
|
{
|
|
|
|
gchar *encoding;
|
|
|
|
gboolean has_bom;
|
|
|
|
} FileEncoding;
|
|
|
|
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* Structure for representing an open tab with all its properties.
|
|
|
|
**/
|
2006-08-20 15:47:18 +00:00
|
|
|
typedef struct document
|
|
|
|
{
|
2008-02-17 18:00:42 +00:00
|
|
|
/** General flag to represent this document is active and all properties are set correctly. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean is_valid;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Whether this %document support source code symbols(tags) to show in the sidebar. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean has_tags;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** The UTF-8 encoded file name. Be careful glibc and GLib functions expect the locale
|
|
|
|
representation of the file name which can be different from this.
|
|
|
|
For conversion into locale encoding for use with file functions of GLib, you can use
|
|
|
|
@ref utils_get_locale_from_utf8. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gchar *file_name;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** The encoding of the %document, must be a valid string representation of an encoding, can
|
|
|
|
* be retrieved with @ref encodings_get_charset_from_index. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gchar *encoding;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Internally used flag to indicate whether the file of this %document has a byte-order-mark. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean has_bom;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** The filetype for this %document, it's only a reference to one of the elements of the global
|
|
|
|
* filetypes array. */
|
2006-08-20 15:47:18 +00:00
|
|
|
filetype *file_type;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** TMWorkObject object for this %document. */
|
2006-08-20 15:47:18 +00:00
|
|
|
TMWorkObject *tm_file;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** The Scintilla object for this %document. */
|
2006-08-20 15:47:18 +00:00
|
|
|
ScintillaObject *sci;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** GtkLabel shown in the notebook header. */
|
2006-08-20 15:47:18 +00:00
|
|
|
GtkWidget *tab_label;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** GtkLabel shown in the notebook right-click menu. */
|
2006-08-20 15:47:18 +00:00
|
|
|
GtkWidget *tabmenu_label;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** GtkTreeView object for this %document within the Open Files treeview of the sidebar. */
|
2006-08-20 15:47:18 +00:00
|
|
|
GtkWidget *tag_tree;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** GtkTreeStore object for this %document within the Open Files treeview of the sidebar. */
|
2006-08-20 15:47:18 +00:00
|
|
|
GtkTreeStore *tag_store;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Iter for this %document within the Open Files treeview of the sidebar. */
|
|
|
|
GtkTreeIter iter;
|
|
|
|
/** Whether this %document is read-only. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean readonly;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Whether this %document has been changed since it was last saved. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean changed;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** %Document-specific line wrapping setting. */
|
2007-08-24 16:20:33 +00:00
|
|
|
gboolean line_wrapping;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** %Document-specific indentation setting. */
|
2007-06-12 15:16:17 +00:00
|
|
|
gboolean auto_indent;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Percentage to scroll view by on paint, if positive. */
|
|
|
|
gfloat scroll_percent;
|
|
|
|
/** Time of the last disk check. */
|
|
|
|
time_t last_check;
|
|
|
|
/** Modification time of this %document on disk. */
|
2006-08-20 15:47:18 +00:00
|
|
|
time_t mtime;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Internally used by the Undo/Redo management code. */
|
2006-09-06 16:09:08 +00:00
|
|
|
GTrashStack *undo_actions;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Internally used by the Undo/Redo management code. */
|
2006-09-06 16:09:08 +00:00
|
|
|
GTrashStack *redo_actions;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** Internally used. */
|
2006-10-24 13:41:34 +00:00
|
|
|
FileEncoding saved_encoding;
|
2008-02-17 18:00:42 +00:00
|
|
|
/** %Document-specific tab setting. */
|
2007-10-17 12:27:07 +00:00
|
|
|
gboolean use_tabs;
|
2008-05-09 12:13:29 +00:00
|
|
|
gboolean line_breaking; /**< Whether to split long lines as you type. */
|
2006-08-20 15:47:18 +00:00
|
|
|
} document;
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Dynamic array of document elements to hold all information of the notebook tabs. */
|
2006-10-09 16:08:53 +00:00
|
|
|
extern GArray *doc_array;
|
2006-08-20 15:47:18 +00:00
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* doc_list wraps doc_array so it can be used with C array syntax.
|
|
|
|
* Example: doc_list[0].sci = NULL;
|
|
|
|
**/
|
2006-10-09 16:08:53 +00:00
|
|
|
#define doc_list ((document *)doc_array->data)
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* DOC_IDX_VALID checks whether the passed index points to a valid %document object by checking
|
|
|
|
* important properties. It returns FALSE if the index is not valid and then this index
|
|
|
|
* must not be used.
|
|
|
|
**/
|
|
|
|
#define DOC_IDX_VALID(doc_idx) \
|
|
|
|
((doc_idx) >= 0 && (guint)(doc_idx) < doc_array->len && doc_list[doc_idx].is_valid)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC_FILENAME) returns the filename of the %document corresponding to the passed index or
|
|
|
|
* GEANY_STRING_UNTITLED (e.g. _("untitled")) if the %document's filename was not yet set.
|
|
|
|
* This macro never returns NULL.
|
|
|
|
**/
|
2006-11-25 12:32:22 +00:00
|
|
|
#define DOC_FILENAME(doc_idx) \
|
2008-02-17 18:00:42 +00:00
|
|
|
((doc_list[doc_idx].file_name != NULL) ? (doc_list[doc_idx].file_name) : GEANY_STRING_UNTITLED)
|
2006-11-25 12:32:22 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-02-23 15:36:21 +00:00
|
|
|
gint document_find_by_filename(const gchar *filename, gboolean is_tm_filename);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-02-23 15:36:21 +00:00
|
|
|
gint document_find_by_sci(ScintillaObject *sci);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-02-23 15:36:21 +00:00
|
|
|
gint document_get_notebook_page(gint doc_idx);
|
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
gint document_get_n_idx(guint page_num);
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
gint document_get_cur_idx(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
document *document_get_current(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_init_doclist(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_finalize(void);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_set_text_changed(gint idx);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-08 18:02:08 +00:00
|
|
|
void document_apply_update_prefs(gint idx);
|
2006-08-01 13:24:58 +00:00
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
gboolean document_remove(guint page_num);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-04-24 14:33:12 +00:00
|
|
|
gboolean document_account_for_unsaved(void);
|
|
|
|
|
|
|
|
gboolean document_close_all(void);
|
|
|
|
|
2008-04-08 14:07:17 +00:00
|
|
|
gint document_new_file_if_non_open();
|
|
|
|
|
2007-09-03 16:09:53 +00:00
|
|
|
gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-07-17 14:52:57 +00:00
|
|
|
gint document_clone(gint old_idx, const gchar *utf8_filename);
|
|
|
|
|
2007-09-11 15:21:11 +00:00
|
|
|
gint document_open_file(const gchar *locale_filename, gboolean readonly,
|
|
|
|
filetype *ft, const gchar *forced_enc);
|
|
|
|
|
|
|
|
gint document_open_file_full(gint idx, const gchar *filename, gint pos, gboolean readonly,
|
2007-03-06 16:57:09 +00:00
|
|
|
filetype *ft, const gchar *forced_enc);
|
2006-11-15 23:12:13 +00:00
|
|
|
|
2006-11-17 12:19:31 +00:00
|
|
|
void document_open_file_list(const gchar *data, gssize length);
|
2006-11-15 23:12:13 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_open_files(const GSList *filenames, gboolean readonly, filetype *ft,
|
|
|
|
const gchar *forced_enc);
|
|
|
|
|
2007-09-11 16:05:03 +00:00
|
|
|
gboolean document_reload_file(gint idx, const gchar *forced_enc);
|
2006-06-20 11:55:34 +00:00
|
|
|
|
2008-03-21 14:02:59 +00:00
|
|
|
|
|
|
|
gboolean document_save_file_as(gint idx);
|
|
|
|
|
2006-09-05 18:33:48 +00:00
|
|
|
gboolean document_save_file(gint idx, gboolean force);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-07-09 17:33:31 +00:00
|
|
|
gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
|
2006-07-20 21:19:18 +00:00
|
|
|
|
2006-11-03 15:09:13 +00:00
|
|
|
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards,
|
2008-03-21 14:02:59 +00:00
|
|
|
gboolean scroll, GtkWidget *parent);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-10-22 14:56:05 +00:00
|
|
|
gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text,
|
2008-03-21 14:02:59 +00:00
|
|
|
gint flags, gboolean search_backwards);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-25 12:32:22 +00:00
|
|
|
gboolean document_replace_all(gint idx, const gchar *find_text, const gchar *replace_text,
|
|
|
|
gint flags, gboolean escaped_chars);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags,
|
|
|
|
gboolean escaped_chars);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_update_tag_list(gint idx, gboolean update);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_set_filetype(gint idx, filetype *type);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-10-10 16:02:41 +00:00
|
|
|
void document_set_encoding(gint idx, const gchar *new_encoding);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* own Undo / Redo implementation to be able to undo / redo changes
|
|
|
|
* to the encoding or the Unicode BOM (which are Scintilla independet).
|
|
|
|
* All Scintilla events are stored in the undo / redo buffer and are passed through. */
|
2006-10-10 16:02:41 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* available UNDO actions, UNDO_SCINTILLA is a pseudo action to trigger Scintilla's
|
|
|
|
* undo management */
|
2006-09-06 16:09:08 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
UNDO_SCINTILLA = 0,
|
|
|
|
UNDO_ENCODING,
|
|
|
|
UNDO_BOM,
|
|
|
|
UNDO_ACTIONS_MAX
|
|
|
|
};
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* an undo action, also used for redo actions */
|
2006-09-06 16:09:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
GTrashStack *next; /* pointer to the next stack element(required for the GTrashStack) */
|
|
|
|
guint type; /* to identify the action */
|
|
|
|
gpointer *data; /* the old value (before the change), in case of a redo action
|
|
|
|
* it contains the new value */
|
2006-09-06 16:09:08 +00:00
|
|
|
} undo_action;
|
|
|
|
|
|
|
|
gboolean document_can_undo(gint idx);
|
|
|
|
|
|
|
|
gboolean document_can_redo(gint idx);
|
|
|
|
|
|
|
|
void document_undo(gint idx);
|
|
|
|
|
|
|
|
void document_redo(gint idx);
|
|
|
|
|
|
|
|
void document_undo_add(gint idx, guint type, gpointer data);
|
|
|
|
|
2008-05-15 13:43:29 +00:00
|
|
|
GdkColor *document_get_status_color(gint idx);
|
2006-12-05 10:37:36 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_delay_colourise(void);
|
2007-02-23 13:26:06 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_colourise_new(void);
|
2007-02-23 13:26:06 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|