2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* document.h - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2010-01-01 22:55:18 +00:00
|
|
|
* Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2010 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.
|
|
|
|
**/
|
2008-06-12 16:50:01 +00:00
|
|
|
/* Also Scintilla search actions - but these should probably be moved to search.c. */
|
2008-02-17 18:00:42 +00:00
|
|
|
|
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
|
|
|
|
2010-10-25 16:24:55 +00:00
|
|
|
/** File Prefs. */
|
2008-05-16 12:08:39 +00:00
|
|
|
typedef struct GeanyFilePrefs
|
|
|
|
{
|
|
|
|
gint default_new_encoding;
|
|
|
|
gint default_open_encoding;
|
|
|
|
gboolean final_new_line;
|
|
|
|
gboolean strip_trailing_spaces;
|
|
|
|
gboolean replace_tabs;
|
|
|
|
gboolean tab_order_ltr;
|
2010-05-16 17:45:39 +00:00
|
|
|
gboolean tab_order_beside;
|
2008-05-16 12:08:39 +00:00
|
|
|
gboolean show_tab_cross;
|
|
|
|
guint mru_length;
|
|
|
|
gint default_eol_character;
|
|
|
|
gint disk_check_timeout;
|
2008-07-21 14:28:46 +00:00
|
|
|
gboolean cmdline_new_files; /* New file if command-line filename doesn't exist */
|
2009-04-21 20:54:04 +00:00
|
|
|
gboolean use_safe_file_saving;
|
2010-10-25 16:24:55 +00:00
|
|
|
gboolean ensure_convert_new_lines;
|
2008-05-16 12:08:39 +00:00
|
|
|
}
|
|
|
|
GeanyFilePrefs;
|
|
|
|
|
|
|
|
extern GeanyFilePrefs file_prefs;
|
|
|
|
|
|
|
|
|
2008-02-17 18:00:42 +00:00
|
|
|
/**
|
|
|
|
* Structure for representing an open tab with all its properties.
|
|
|
|
**/
|
2008-06-15 13:35:48 +00:00
|
|
|
struct GeanyDocument
|
2006-08-20 15:47:18 +00:00
|
|
|
{
|
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-06-12 16:50:01 +00:00
|
|
|
gint index; /**< Index in the documents array. */
|
2009-08-09 20:31:03 +00:00
|
|
|
/** Whether this document supports source code symbols(tags) to show in the sidebar. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean has_tags;
|
2008-06-05 16:07:39 +00:00
|
|
|
/** The UTF-8 encoded file name.
|
|
|
|
* Be careful; glibc and GLib file functions expect the locale representation of the
|
|
|
|
* file name which can be different from this.
|
|
|
|
* For conversion into locale encoding, you can use @ref utils_get_locale_from_utf8().
|
2008-06-03 17:22:04 +00:00
|
|
|
* @see real_path. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gchar *file_name;
|
2009-08-09 20:31:03 +00:00
|
|
|
/** The encoding of the document, must be a valid string representation of an encoding, can
|
2008-02-17 18:00:42 +00:00
|
|
|
* be retrieved with @ref encodings_get_charset_from_index. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gchar *encoding;
|
2009-08-09 20:31:03 +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-07-15 14:29:41 +00:00
|
|
|
struct GeanyEditor *editor; /**< The editor associated with the document. */
|
2009-08-09 20:31:03 +00:00
|
|
|
/** The filetype for this document, it's only a reference to one of the elements of the global
|
2008-02-17 18:00:42 +00:00
|
|
|
* filetypes array. */
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *file_type;
|
2009-08-09 20:31:03 +00:00
|
|
|
/** TMWorkObject object for this document, or @c NULL. */
|
2006-08-20 15:47:18 +00:00
|
|
|
TMWorkObject *tm_file;
|
2009-08-09 20:31:03 +00:00
|
|
|
/** Whether this document is read-only. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean readonly;
|
2009-08-09 20:31:03 +00:00
|
|
|
/** Whether this document has been changed since it was last saved. */
|
2006-08-20 15:47:18 +00:00
|
|
|
gboolean changed;
|
2008-06-03 17:22:04 +00:00
|
|
|
/** The link-dereferenced, locale-encoded file name.
|
|
|
|
* If non-NULL, this indicates the file once existed on disk (not just as an
|
|
|
|
* unsaved document with a filename set).
|
|
|
|
*
|
2008-06-05 16:07:39 +00:00
|
|
|
* @note This is only assigned after a successful save or open - it should
|
|
|
|
* not be set elsewhere.
|
|
|
|
* @see file_name. */
|
2008-06-03 17:22:04 +00:00
|
|
|
gchar *real_path;
|
2008-09-26 17:28:50 +00:00
|
|
|
|
|
|
|
struct GeanyDocumentPrivate *priv; /* should be last, append fields before this item */
|
2008-06-15 13:35:48 +00:00
|
|
|
};
|
2006-08-20 15:47:18 +00:00
|
|
|
|
2008-05-29 17:00:54 +00:00
|
|
|
extern GPtrArray *documents_array;
|
2006-08-20 15:47:18 +00:00
|
|
|
|
2008-07-24 15:17:55 +00:00
|
|
|
|
2010-03-12 18:15:48 +00:00
|
|
|
/** Wraps documents_array so it can be used with C array syntax.
|
2009-07-14 13:05:51 +00:00
|
|
|
* Example: documents[0]->sci = NULL;
|
|
|
|
* @see document_index(). */
|
|
|
|
#define documents ((GeanyDocument **)GEANY(documents_array)->pdata)
|
|
|
|
|
2009-11-04 15:28:38 +00:00
|
|
|
/** @deprecated Use @ref foreach_document() instead.
|
|
|
|
* Iterates all valid documents.
|
|
|
|
* Use like a @c for statement.
|
|
|
|
* @param i @c guint index for document_index(). */
|
|
|
|
#ifndef GEANY_DISABLE_DEPRECATED
|
|
|
|
#define documents_foreach(i) foreach_document(i)
|
|
|
|
#endif
|
|
|
|
|
2009-07-14 13:05:51 +00:00
|
|
|
/** Iterates all valid documents.
|
|
|
|
* Use like a @c for statement.
|
|
|
|
* @param i @c guint index for document_index(). */
|
2009-11-04 15:28:38 +00:00
|
|
|
#define foreach_document(i) \
|
2009-07-14 13:05:51 +00:00
|
|
|
for (i = 0; i < GEANY(documents_array)->len; i++)\
|
|
|
|
if (!documents[i]->is_valid)\
|
|
|
|
{}\
|
|
|
|
else /* prevent outside 'else' matching our macro 'if' */
|
2006-10-09 16:08:53 +00:00
|
|
|
|
2008-12-04 13:26:48 +00:00
|
|
|
/** @c NULL-safe way to check @c doc_ptr->is_valid.
|
2008-06-13 15:02:29 +00:00
|
|
|
* This is useful when @a doc_ptr was stored some time earlier and documents may have been
|
|
|
|
* closed since then.
|
|
|
|
* @note This should not be used to check the result of the main API functions,
|
2008-12-04 13:26:48 +00:00
|
|
|
* these only need a NULL-pointer check - @c document_get_current() != @c NULL. */
|
2008-06-13 15:02:29 +00:00
|
|
|
#define DOC_VALID(doc_ptr) \
|
2009-04-05 21:07:40 +00:00
|
|
|
(G_LIKELY((doc_ptr) != NULL) && G_LIKELY((doc_ptr)->is_valid))
|
2008-02-17 18:00:42 +00:00
|
|
|
|
|
|
|
/**
|
2010-03-12 18:15:48 +00:00
|
|
|
* Returns the filename of the document passed or @c GEANY_STRING_UNTITLED
|
|
|
|
* (e.g. _("untitled")) if the document's filename was not yet set.
|
2009-08-09 20:31:03 +00:00
|
|
|
* This macro never returns @c NULL.
|
2008-02-17 18:00:42 +00:00
|
|
|
**/
|
2008-06-15 13:35:48 +00:00
|
|
|
#define DOC_FILENAME(doc) \
|
2009-04-05 21:07:40 +00:00
|
|
|
(G_LIKELY(doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED)
|
2006-11-25 12:32:22 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-03 17:22:04 +00:00
|
|
|
|
2008-06-12 16:50:01 +00:00
|
|
|
/* These functions will replace the older functions. For now they have a documents_ prefix. */
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument* document_new_file(const gchar *filename, GeanyFiletype *ft, const gchar *text);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2009-01-11 18:29:39 +00:00
|
|
|
GeanyDocument* document_new_file_if_non_open(void);
|
2007-02-23 15:36:21 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument* document_find_by_filename(const gchar *utf8_filename);
|
2006-10-09 16:08:53 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument* document_find_by_real_path(const gchar *realname);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_save_file(GeanyDocument *doc, gboolean force);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument* document_open_file(const gchar *locale_filename, gboolean readonly,
|
|
|
|
GeanyFiletype *ft, const gchar *forced_enc);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_reload_file(GeanyDocument *doc, const gchar *forced_enc);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_set_text_changed(GeanyDocument *doc, gboolean changed);
|
2006-08-01 13:24:58 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2009-07-13 11:58:21 +00:00
|
|
|
void document_reload_config(GeanyDocument *doc);
|
|
|
|
|
2009-01-18 18:19:58 +00:00
|
|
|
void document_rename_file(GeanyDocument *doc, const gchar *new_filename);
|
2008-04-24 14:33:12 +00:00
|
|
|
|
2008-12-03 18:03:54 +00:00
|
|
|
GeanyDocument *document_index(gint idx);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *document_find_by_sci(ScintillaObject *sci);
|
2008-04-24 14:33:12 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gint document_get_notebook_page(GeanyDocument *doc);
|
2008-04-08 14:07:17 +00:00
|
|
|
|
2008-06-12 16:50:01 +00:00
|
|
|
GeanyDocument* document_get_from_page(guint page_num);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyDocument *document_get_current(void);
|
2007-07-17 14:52:57 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_init_doclist(void);
|
2007-09-11 15:21:11 +00:00
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
void document_finalize(void);
|
2006-11-15 23:12:13 +00:00
|
|
|
|
2008-06-12 16:50:01 +00:00
|
|
|
gboolean document_remove_page(guint page_num);
|
|
|
|
|
2010-02-28 14:32:38 +00:00
|
|
|
void document_try_focus(GeanyDocument *doc, GtkWidget *source_widget);
|
2009-09-03 12:04:27 +00:00
|
|
|
|
2008-07-01 14:20:16 +00:00
|
|
|
gboolean document_close(GeanyDocument *doc);
|
|
|
|
|
2008-04-24 14:33:12 +00:00
|
|
|
gboolean document_account_for_unsaved(void);
|
2007-03-06 16:57:09 +00:00
|
|
|
|
2008-04-24 14:33:12 +00:00
|
|
|
gboolean document_close_all(void);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename);
|
2006-06-20 11:55:34 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename, gint pos,
|
|
|
|
gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc);
|
2008-03-21 14:02:59 +00:00
|
|
|
|
2006-11-17 12:19:31 +00:00
|
|
|
void document_open_file_list(const gchar *data, gssize length);
|
2008-03-21 14:02:59 +00:00
|
|
|
|
2008-05-16 14:17:54 +00:00
|
|
|
void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
|
2007-03-06 16:57:09 +00:00
|
|
|
const gchar *forced_enc);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint flags, gboolean inc);
|
2006-07-20 21:19:18 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gint document_find_text(GeanyDocument *doc, 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
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gint document_replace_text(GeanyDocument *doc, 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
|
|
|
|
2010-01-18 17:05:13 +00:00
|
|
|
gint document_replace_all(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text,
|
2006-11-25 12:32:22 +00:00
|
|
|
gint flags, gboolean escaped_chars);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gchar *replace_text, gint flags,
|
2007-03-06 16:57:09 +00:00
|
|
|
gboolean escaped_chars);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_update_tag_list(GeanyDocument *doc, gboolean update);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_check_disk_status(GeanyDocument *doc, gboolean force);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
|
|
|
/* own Undo / Redo implementation to be able to undo / redo changes
|
2008-06-02 15:31:59 +00:00
|
|
|
* to the encoding or the Unicode BOM (which are Scintilla independent).
|
2006-09-06 16:09:08 +00:00
|
|
|
* All Scintilla events are stored in the undo / redo buffer and are passed through. */
|
2006-10-10 16:02:41 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_can_undo(GeanyDocument *doc);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
gboolean document_can_redo(GeanyDocument *doc);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_undo(GeanyDocument *doc);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_redo(GeanyDocument *doc);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
|
2006-09-06 16:09:08 +00:00
|
|
|
|
2008-11-18 20:13:29 +00:00
|
|
|
void document_update_tab_label(GeanyDocument *doc);
|
2008-06-02 15:31:59 +00:00
|
|
|
|
2009-02-08 19:52:21 +00:00
|
|
|
const GdkColor *document_get_status_color(GeanyDocument *doc);
|
2006-12-05 10:37:36 +00:00
|
|
|
|
2009-04-21 20:52:51 +00:00
|
|
|
gchar *document_get_basename_for_display(GeanyDocument *doc, gint length);
|
|
|
|
|
2009-12-20 15:36:52 +00:00
|
|
|
gboolean document_need_save_as(GeanyDocument *doc);
|
|
|
|
|
2010-05-05 12:07:45 +00:00
|
|
|
void document_apply_indent_settings(GeanyDocument *doc);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|