2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* document.h - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2007-01-14 17:36:42 +00:00
|
|
|
* Copyright 2005-2007 Enrico Tröger <enrico.troeger@uvena.de>
|
|
|
|
* Copyright 2006-2007 Nick Treleaven <nick.treleaven@btinternet.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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GEANY_DOCUMENT_H
|
|
|
|
#define GEANY_DOCUMENT_H 1
|
|
|
|
|
2006-08-20 20:39:59 +00:00
|
|
|
#ifndef PLAT_GTK
|
|
|
|
# define PLAT_GTK 1 // needed for ScintillaWidget.h
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "ScintillaWidget.h"
|
|
|
|
|
2006-08-20 15:47:18 +00:00
|
|
|
#include "geany.h"
|
2006-08-20 20:39:59 +00:00
|
|
|
#include "filetypes.h"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2006-08-20 15:47:18 +00:00
|
|
|
/* structure for representing an open tab with all its related stuff. */
|
|
|
|
typedef struct document
|
|
|
|
{
|
|
|
|
gboolean is_valid;
|
|
|
|
gboolean has_tags;
|
|
|
|
// the filename is encoded in UTF-8, but every GLibC function expect the locale representation
|
|
|
|
gchar *file_name;
|
|
|
|
gchar *encoding;
|
|
|
|
gboolean has_bom;
|
|
|
|
filetype *file_type;
|
|
|
|
TMWorkObject *tm_file;
|
|
|
|
ScintillaObject *sci;
|
|
|
|
GtkWidget *tab_label;
|
|
|
|
GtkWidget *tabmenu_label;
|
|
|
|
GtkWidget *tag_tree;
|
|
|
|
GtkTreeStore *tag_store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean readonly;
|
|
|
|
gboolean changed;
|
|
|
|
gboolean line_breaking;
|
|
|
|
gboolean use_auto_indention;
|
2007-01-31 15:53:11 +00:00
|
|
|
gfloat scroll_percent; // % to scroll view by on paint, if positive.
|
2006-08-20 15:47:18 +00:00
|
|
|
time_t last_check; // to remember the last disk check
|
|
|
|
time_t mtime;
|
2006-09-06 16:09:08 +00:00
|
|
|
GTrashStack *undo_actions;
|
|
|
|
GTrashStack *redo_actions;
|
2006-10-24 13:41:34 +00:00
|
|
|
FileEncoding saved_encoding;
|
2006-08-20 15:47:18 +00:00
|
|
|
} document;
|
|
|
|
|
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
/* dynamic array of document elements to hold all information of the notebook tabs */
|
|
|
|
extern GArray *doc_array;
|
2006-08-20 15:47:18 +00:00
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
/* doc_list wraps doc_array so it can be used with C array syntax.
|
|
|
|
* Example: doc_list[0].sci = NULL; */
|
|
|
|
#define doc_list ((document *)doc_array->data)
|
|
|
|
|
|
|
|
#define DOC_IDX_VALID(idx) \
|
|
|
|
((idx) >= 0 && (guint)(idx) < doc_array->len && doc_list[idx].is_valid)
|
2006-08-20 15:47:18 +00:00
|
|
|
|
2006-11-25 12:32:22 +00:00
|
|
|
#define DOC_FILENAME(doc_idx) \
|
|
|
|
((doc_list[doc_idx].file_name != NULL) ? \
|
|
|
|
(doc_list[doc_idx].file_name) : GEANY_STRING_UNTITLED)
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-02-23 15:36:21 +00:00
|
|
|
/* returns the document index which has the given filename.
|
|
|
|
* is_tm_filename is needed when passing TagManager filenames because they are
|
|
|
|
* dereferenced, and would not match the link filename. */
|
|
|
|
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
|
|
|
/* returns the document index which has sci */
|
|
|
|
gint document_find_by_sci(ScintillaObject *sci);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2007-02-23 15:36:21 +00:00
|
|
|
/* returns the index of the notebook page from the document index */
|
|
|
|
gint document_get_notebook_page(gint doc_idx);
|
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
/* returns the index of the given notebook page in the document list */
|
|
|
|
gint document_get_n_idx(guint page_num);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/* returns the index of the current notebook page in the document list */
|
2006-09-02 20:49:11 +00:00
|
|
|
gint document_get_cur_idx();
|
|
|
|
|
|
|
|
/* returns NULL if no documents are open */
|
|
|
|
document *document_get_current();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
void document_init_doclist();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-10-09 16:08:53 +00:00
|
|
|
void document_finalize();
|
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
|
|
|
|
|
|
|
|
2006-08-01 13:24:58 +00:00
|
|
|
// Apply just the prefs that can change in the Preferences dialog
|
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
|
|
|
/* removes the given notebook tab and clears the related entry in the document list */
|
|
|
|
gboolean document_remove(guint page_num);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* This creates a new document, by clearing the text widget and setting the
|
2007-02-15 23:56:15 +00:00
|
|
|
current filename to filename or NULL. If ft is NULL and filename is not NULL, then the filetype
|
|
|
|
will be guessed from the given filename.
|
|
|
|
filename is expected in UTF-8 encoding. */
|
|
|
|
gint document_new_file(const gchar *filename, filetype *ft);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
/* To open a new file, set idx to -1; filename should be locale encoded.
|
|
|
|
* To reload a file, set the idx for the document to be reloaded; filename should be NULL.
|
|
|
|
* Returns: idx of the opened file or -1 if an error occurred.
|
|
|
|
* Note: If opening more than one file, document_delay_colourise() should be used before
|
|
|
|
* and document_colourise_new() after opening to avoid unnecessary recolourising. */
|
|
|
|
gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean readonly,
|
|
|
|
filetype *ft, const gchar *forced_enc);
|
2006-11-15 23:12:13 +00:00
|
|
|
|
|
|
|
/* Takes a new line separated list of filename URIs and opens each file.
|
|
|
|
* length is the length of the string or -1 if it should be detected */
|
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
|
|
|
/* Takes a linked list of filename URIs and opens each file, ensuring the newly opened
|
|
|
|
* documents and existing documents (if necessary) are only colourised once. */
|
|
|
|
void document_open_files(const GSList *filenames, gboolean readonly, filetype *ft,
|
|
|
|
const gchar *forced_enc);
|
|
|
|
|
2006-11-15 23:12:13 +00:00
|
|
|
|
2007-02-15 23:56:15 +00:00
|
|
|
gint document_reload_file(gint idx, const gchar *forced_enc);
|
2006-06-20 11:55:34 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-08-02 10:50:53 +00:00
|
|
|
/* This saves the file.
|
2006-09-05 18:33:48 +00:00
|
|
|
* When force is set then it is always saved, even if it is unchanged(useful when using Save As)
|
|
|
|
* It returns whether the file could be saved or not. */
|
|
|
|
gboolean document_save_file(gint idx, gboolean force);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-07-20 21:19:18 +00:00
|
|
|
/* special search function, used from the find entry in the toolbar */
|
2006-11-03 15:09:13 +00:00
|
|
|
void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
|
2006-07-20 21:19:18 +00:00
|
|
|
|
|
|
|
/* General search function, used from the find dialog.
|
|
|
|
* Returns -1 on failure or the start position of the matching text. */
|
2006-11-03 15:09:13 +00:00
|
|
|
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards,
|
|
|
|
gboolean scroll);
|
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,
|
|
|
|
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_set_font(gint idx, const gchar *font_name, gint size);
|
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
|
|
|
/* sets the filetype of the document (sets syntax highlighting and tagging) */
|
|
|
|
void document_set_filetype(gint idx, filetype *type);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
gchar *document_get_eol_mode(gint idx);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-02-26 18:19:28 +00:00
|
|
|
void document_fold_all(gint idx);
|
|
|
|
|
|
|
|
void document_unfold_all(gint idx);
|
|
|
|
|
2006-06-13 19:37:21 +00:00
|
|
|
void document_set_indicator(gint idx, gint line);
|
|
|
|
|
|
|
|
void document_clear_indicators(gint idx);
|
|
|
|
|
2006-06-29 17:14:52 +00:00
|
|
|
/* simple file print */
|
|
|
|
void document_print(gint idx);
|
|
|
|
|
2006-07-17 10:42:26 +00:00
|
|
|
void document_replace_tabs(gint idx);
|
|
|
|
|
|
|
|
void document_strip_trailing_spaces(gint idx);
|
|
|
|
|
|
|
|
void document_ensure_final_newline(gint idx);
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2006-10-10 16:02:41 +00:00
|
|
|
// an undo action, also used for redo actions
|
2006-09-06 16:09:08 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2006-10-10 16:02:41 +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);
|
|
|
|
|
2006-12-05 10:37:36 +00:00
|
|
|
|
|
|
|
GdkColor *document_get_status(gint idx);
|
|
|
|
|
2007-02-23 13:26:06 +00:00
|
|
|
|
|
|
|
void document_delay_colourise();
|
|
|
|
|
2007-03-06 16:57:09 +00:00
|
|
|
void document_colourise_new();
|
2007-02-23 13:26:06 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|