geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

document.h File Reference

Document related actions: new, save, open, etc. More...

#include "editor.h"
#include "filetypes.h"
#include "geany.h"
#include "search.h"
#include "gtkcompat.h"
#include "Scintilla.h"
#include "ScintillaWidget.h"
#include <glib.h>
Include dependency graph for document.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GeanyFilePrefs
 File Prefs. More...
 
struct  GeanyDocument
 Structure for representing an open tab with all its properties. More...
 

Macros

#define GEANY_TYPE_DOCUMENT   (document_get_type())
 
#define documents   ((GeanyDocument **)GEANY(documents_array)->pdata)
 Wraps GeanyData::documents_array so it can be used with C array syntax. More...
 
#define documents_foreach(i)   foreach_document(i)
 
#define foreach_document(i)
 Iterates all valid document indexes. More...
 
#define DOC_VALID(doc_ptr)    ((doc_ptr) != NULL && (doc_ptr)->is_valid)
 Null-safe way to check GeanyDocument::is_valid. More...
 
#define DOC_FILENAME(doc)    (G_LIKELY((doc)->file_name != NULL) ? ((doc)->file_name) : GEANY_STRING_UNTITLED)
 Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g. More...
 

Typedefs

typedef struct GeanyFilePrefs GeanyFilePrefs
 File Prefs. More...
 
typedef struct GeanyDocument GeanyDocument
 Structure for representing an open tab with all its properties. More...
 

Functions

GType document_get_type (void)
 
GeanyDocumentdocument_new_file (const gchar *filename, GeanyFiletype *ft, const gchar *text)
 Creates a new document. More...
 
GeanyDocumentdocument_get_current (void)
 Finds the current document. More...
 
GeanyDocumentdocument_get_from_notebook_child (GtkWidget *page)
 
GeanyDocumentdocument_get_from_page (guint page_num)
 Finds the document for the given notebook page page_num. More...
 
GeanyDocumentdocument_find_by_filename (const gchar *utf8_filename)
 Finds a document with the given filename. More...
 
GeanyDocumentdocument_find_by_real_path (const gchar *realname)
 Finds a document whose real_path field matches the given filename. More...
 
gboolean document_save_file (GeanyDocument *doc, gboolean force)
 Saves the document. More...
 
GeanyDocumentdocument_open_file (const gchar *locale_filename, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
 Opens a document specified by locale_filename. More...
 
void document_open_files (const GSList *filenames, gboolean readonly, GeanyFiletype *ft, const gchar *forced_enc)
 Opens each file in the list filenames. More...
 
gboolean document_remove_page (guint page_num)
 Removes the given notebook tab at page_num and clears all related information in the document list. More...
 
gboolean document_reload_force (GeanyDocument *doc, const gchar *forced_enc)
 Reloads the document with the specified file encoding. More...
 
void document_set_encoding (GeanyDocument *doc, const gchar *new_encoding)
 Sets the encoding of a document. More...
 
void document_set_text_changed (GeanyDocument *doc, gboolean changed)
 Updates the tab labels, the status bar, the window title and some save-sensitive buttons according to the document's save state. More...
 
void document_set_filetype (GeanyDocument *doc, GeanyFiletype *type)
 Sets the filetype of the document (which controls syntax highlighting and tags) More...
 
gboolean document_close (GeanyDocument *doc)
 Closes the given document. More...
 
GeanyDocumentdocument_index (gint idx)
 Accessor function for GeanyData::documents_array items. More...
 
gboolean document_save_file_as (GeanyDocument *doc, const gchar *utf8_fname)
 Saves the document, detecting the filetype. More...
 
void document_rename_file (GeanyDocument *doc, const gchar *new_filename)
 Renames the file in doc to new_filename. More...
 
const GdkColor * document_get_status_color (GeanyDocument *doc)
 Gets the status color of the document, or NULL if default widget coloring should be used. More...
 
gchar * document_get_basename_for_display (GeanyDocument *doc, gint length)
 Returns the last part of the filename of the given GeanyDocument. More...
 
gint document_get_notebook_page (GeanyDocument *doc)
 Gets the notebook page index for a document. More...
 
gint document_compare_by_display_name (gconstpointer a, gconstpointer b)
 Compares documents by their display names. More...
 
gint document_compare_by_tab_order (gconstpointer a, gconstpointer b)
 Compares documents by their tab order. More...
 
gint document_compare_by_tab_order_reverse (gconstpointer a, gconstpointer b)
 Compares documents by their tab order, in reverse order. More...
 
GeanyDocumentdocument_find_by_id (guint id)
 Lookup an old document by its ID. More...
 

Detailed Description

Document related actions: new, save, open, etc.

Definition in file document.h.

Macro Definition Documentation

◆ DOC_FILENAME

#define DOC_FILENAME (   doc)     (G_LIKELY((doc)->file_name != NULL) ? ((doc)->file_name) : GEANY_STRING_UNTITLED)

Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g.

_("untitled")) if the document's filename was not yet set. This macro never returns NULL.

Definition at line 170 of file document.h.

◆ DOC_VALID

#define DOC_VALID (   doc_ptr)     ((doc_ptr) != NULL && (doc_ptr)->is_valid)

Null-safe way to check GeanyDocument::is_valid.

Note
This should not be used to check the result of the main API functions, these only need a NULL-pointer check - document_get_current() != NULL.

Definition at line 162 of file document.h.

◆ documents

#define documents   ((GeanyDocument **)GEANY(documents_array)->pdata)

Wraps GeanyData::documents_array so it can be used with C array syntax.

Warning
Always check the returned document is valid (doc->is_valid).

Example:

#define documents
Wraps GeanyData::documents_array so it can be used with C array syntax.
Definition: document.h:130
Structure for representing an open tab with all its properties.
Definition: document.h:81
See also
documents_array().

Definition at line 130 of file document.h.

◆ documents_foreach

#define documents_foreach (   i)    foreach_document(i)
Deprecated:
Use foreach_document() instead. Iterates all valid documents. Use like a for statement.
Parameters
iguint index for document_index().

Definition at line 137 of file document.h.

◆ foreach_document

#define foreach_document (   i)
Value:
for (i = 0; i < GEANY(documents_array)->len; i++)\
if (!documents[i]->is_valid)\
{}\
else /* prevent outside 'else' matching our macro 'if' */
GPtrArray * documents_array
Definition: document.c:87
#define GEANY(symbol_name)
Definition: geany.h:68

Iterates all valid document indexes.

Use like a for statement.

Parameters
iguint index for GeanyData::documents_array.

Example:

guint i;
{
g_assert(doc->is_valid);
}
#define foreach_document(i)
Iterates all valid document indexes.
Definition: document.h:153
gboolean is_valid
Flag used to check if this document is valid when iterating GeanyData::documents_array.
Definition: document.h:83

Definition at line 153 of file document.h.

◆ GEANY_TYPE_DOCUMENT

#define GEANY_TYPE_DOCUMENT   (document_get_type())

Definition at line 74 of file document.h.

Typedef Documentation

◆ GeanyDocument

typedef struct GeanyDocument GeanyDocument

Structure for representing an open tab with all its properties.

◆ GeanyFilePrefs

File Prefs.

Function Documentation

◆ document_close()

gboolean document_close ( GeanyDocument doc)

Closes the given document.

Parameters
docThe document to remove.
Returns
TRUE if the document was actually removed or FALSE otherwise.
Since
0.15

Definition at line 689 of file document.c.

References document_get_notebook_page(), and document_remove_page().

Referenced by force_close_all().

◆ document_compare_by_display_name()

gint document_compare_by_display_name ( gconstpointer  a,
gconstpointer  b 
)

Compares documents by their display names.

This matches GCompareFunc for use with e.g. g_ptr_array_sort().

Note
'Display name' means the base name of the document's filename.
Parameters
aGeanyDocument**.
bGeanyDocument**.
Warning
The arguments take the address of each document pointer.
Returns
Negative value if a < b; zero if a = b; positive value if a > b.
Since
0.21

Definition at line 3746 of file document.c.

References DOC_FILENAME.

◆ document_compare_by_tab_order()

gint document_compare_by_tab_order ( gconstpointer  a,
gconstpointer  b 
)

Compares documents by their tab order.

This matches GCompareFunc for use with e.g. g_ptr_array_sort().

Parameters
aGeanyDocument**.
bGeanyDocument**.
Warning
The arguments take the address of each document pointer.
Returns
Negative value if a < b; zero if a = b; positive value if a > b.
Since
0.21 (GEANY_API_VERSION 209)

Definition at line 3776 of file document.c.

References document_get_notebook_page().

Referenced by document_compare_by_tab_order_reverse(), and ui_menu_add_document_items_sorted().

◆ document_compare_by_tab_order_reverse()

gint document_compare_by_tab_order_reverse ( gconstpointer  a,
gconstpointer  b 
)

Compares documents by their tab order, in reverse order.

This matches GCompareFunc for use with e.g. g_ptr_array_sort().

Parameters
aGeanyDocument**.
bGeanyDocument**.
Warning
The arguments take the address of each document pointer.
Returns
Negative value if a < b; zero if a = b; positive value if a > b.
Since
0.21 (GEANY_API_VERSION 209)

Definition at line 3806 of file document.c.

References document_compare_by_tab_order().

◆ document_find_by_filename()

GeanyDocument * document_find_by_filename ( const gchar *  utf8_filename)

Finds a document with the given filename.

This matches either an exact GeanyDocument::file_name string, or variant filenames with relative elements in the path (e.g. "/dir/..//name" will match "/name").

Parameters
utf8_filenameThe filename to search (in UTF-8 encoding).
Returns
(transfer: none) The matching document, or NULL.
See also
document_find_by_real_path().

Definition at line 183 of file document.c.

References document_find_by_real_path(), documents, documents_array, GeanyDocument::file_name, get_real_path_from_utf8(), GeanyDocument::is_valid, NULL, and utils_filenamecmp.

Referenced by document_open_file_full(), goto_compiler_file_line(), goto_file_pos(), main_handle_filename(), and process_build_output_line().

◆ document_find_by_id()

GeanyDocument * document_find_by_id ( guint  id)

Lookup an old document by its ID.

Useful when the corresponding document may have been closed since the ID was retrieved.

Parameters
idThe ID of the document to find
Returns
(transfer: none) NULL if the document is no longer open.

Example:

static guint id;
GeanyDocument *doc = ...;
id = doc->id; // store ID
...
// time passes - the document may have been closed by now
GeanyDocument *doc = document_find_by_id(id);
gboolean still_open = (doc != NULL);
GeanyDocument * document_find_by_id(guint id)
Lookup an old document by its ID.
Definition: document.c:247
#define NULL
Definition: rbtree.h:150
guint id
A pseudo-unique ID for this document.
Definition: document.h:119
Since
1.25.

Definition at line 247 of file document.c.

References documents, foreach_document, and NULL.

Referenced by msgwin_goto_messages_file_line().

◆ document_find_by_real_path()

GeanyDocument * document_find_by_real_path ( const gchar *  realname)

Finds a document whose real_path field matches the given filename.

Parameters
realnameThe filename to search, which should be identical to the string returned by utils_get_real_path().
Returns
(transfer: none) The matching document, or NULL.
Note
This is only really useful when passing a TMSourceFile::file_name.
See also
GeanyDocument::real_path.
document_find_by_filename().
Since
0.15

Definition at line 137 of file document.c.

References documents, documents_array, GeanyDocument::is_valid, NULL, GeanyDocument::real_path, and utils_filenamecmp.

Referenced by document_find_by_filename(), and goto_tag().

◆ document_get_basename_for_display()

gchar * document_get_basename_for_display ( GeanyDocument doc,
gint  length 
)

Returns the last part of the filename of the given GeanyDocument.

The result is also truncated to a maximum of length characters in case the filename is very long.

Parameters
docThe document to use.
lengthThe length of the resulting string or -1 to use a default value.
Returns
The ellipsized last part of the filename of doc, should be freed when no longer needed.
Since
0.17

Definition at line 412 of file document.c.

References DOC_FILENAME, NULL, and utils_str_middle_truncate().

Referenced by dialogs_show_unsaved_file(), document_update_tab_label(), and ui_set_window_title().

◆ document_get_current()

GeanyDocument * document_get_current ( void  )

Finds the current document.

Returns
(transfer: none) A pointer to the current document or NULL if there are no opened documents.

Definition at line 371 of file document.c.

References document_get_from_page(), main_widgets, GeanyMainWidgets::notebook, and NULL.

Referenced by auto_save(), build_get_regex(), build_keybinding(), build_menu_update(), cb_func_document_action(), cb_func_editor_action(), cb_func_format_action(), cb_func_goto_action(), cb_func_insert_action(), cb_func_search_action(), cb_func_select_action(), cb_func_switch_action(), cc_on_custom_command_activate(), convert_eol(), convert_eol_characters(), create_file_save_as_dialog(), delay_match_brace(), dialogs_show_save_as(), do_select_current(), do_toolbar_search(), document_create(), document_save_file_as(), encodings_radio_item_change_cb(), encodings_reload_radio_item_change_cb(), filetypes_parse_error_message(), filetypes_reload(), find_usage(), focus_sci(), get_build_group_pointer(), get_next_build_cmd(), goto_compiler_file_line(), goto_tag(), handle_save_as(), have_session_docs(), highlighting_show_color_scheme_dialog(), insert_build_page(), main_lib(), msgwin_goto_messages_file_line(), navqueue_go_back(), on_build_menu_item(), on_clone1_activate(), on_close1_activate(), on_close_other_documents1_activate(), on_color_dialog_response(), on_comments_bsd_activate(), on_comments_changelog_activate(), on_comments_fileheader_activate(), on_comments_function_activate(), on_comments_gpl_activate(), on_comments_multiline_activate(), on_context_action1_activate(), on_current_path(), on_detect_type_from_file_activate(), on_detect_width_from_file_activate(), on_edit1_select(), on_expand_collapse(), on_file_properties_activate(), on_filetype_change(), on_find_dialog_response(), on_find_nextsel1_activate(), on_find_prevsel1_activate(), on_find_usage(), on_go_to_line_activate(), on_goto_popup_item_activate(), on_indent_width_activate(), on_key_press_event(), on_key_release_event(), on_line_breaking1_activate(), on_line_wrapping1_toggled(), on_make_custom_input_response(), on_menu_comment_line1_activate(), on_menu_comments_bsd_activate(), on_menu_comments_gpl_activate(), on_menu_comments_multiline_activate(), on_menu_decrease_indent1_activate(), on_menu_fold_all1_activate(), on_menu_increase_indent1_activate(), on_menu_insert_date_activate(), on_menu_insert_include_activate(), on_menu_open_selected_file1_activate(), on_menu_remove_indicators1_activate(), on_menu_toggle_line_commentation1_activate(), on_menu_uncomment_line1_activate(), on_menu_unfold_all1_activate(), on_menu_write_unicode_bom1_toggled(), on_normal_size1_activate(), on_notebook_switch_page(), on_popup_insert_date_activate(), on_popup_insert_include_activate(), on_prefs_dialog_response(), on_print1_activate(), on_redo1_activate(), on_refresh(), on_remove_markers1_activate(), on_replace_dialog_response(), on_replace_spaces_activate(), on_replace_tabs_activate(), on_save1_activate(), on_save_all1_activate(), on_set_file_readonly1_toggled(), on_show_color_chooser1_activate(), on_sidebar_switch_page(), on_snippet_keybinding_activate(), on_strip_trailing_spaces1_activate(), on_symbol_tree_menu_show(), on_symbol_tree_sort_clicked(), on_toggle_case1_activate(), on_toolbutton_goto_entry_activate(), on_toolbutton_reload_clicked(), on_toolbutton_search_clicked(), on_undo1_activate(), on_use_auto_indentation1_toggled(), on_window_active_changed(), on_zoom_in1_activate(), on_zoom_out1_activate(), open_selected_files(), parse_file_line(), printfcmds(), replace_special_character(), reshow_calltip(), sc_insert(), search_find_again(), search_find_usage(), search_show_find_dialog(), search_show_find_in_files_dialog_full(), search_show_replace_dialog(), set_indent_type(), show_build_commands_dialog(), show_tab_bar_popup_menu(), split_view(), taglist_go_to_selection(), toolbar_reload(), tools_word_count(), ui_document_show_hide(), ui_focus_current_document(), ui_set_window_title(), ui_update_statusbar(), update_config(), and utils_get_current_file_dir_utf8().

◆ document_get_from_notebook_child()

GeanyDocument * document_get_from_notebook_child ( GtkWidget *  page)

◆ document_get_from_page()

GeanyDocument * document_get_from_page ( guint  page_num)

Finds the document for the given notebook page page_num.

Parameters
page_numThe notebook page number to search.
Returns
(transfer: none) The corresponding document for the given notebook page, or NULL.

Definition at line 352 of file document.c.

References document_get_from_notebook_child(), documents_array, main_widgets, GeanyMainWidgets::notebook, and NULL.

Referenced by auto_save(), configuration_save_session_files(), document_account_for_unsaved(), document_get_current(), on_close_documents_right_activate(), on_notebook_switch_page(), on_save_all1_activate(), remove_page(), and replace_in_session().

◆ document_get_notebook_page()

gint document_get_notebook_page ( GeanyDocument doc)

Gets the notebook page index for a document.

Parameters
docThe document.
Returns
The index.
Since
0.19

Definition at line 289 of file document.c.

References document_get_notebook_child(), main_widgets, and GeanyMainWidgets::notebook.

Referenced by document_close(), document_compare_by_tab_order(), document_show_tab(), has_tabs_on_right(), notebook_remove_page(), and on_close_documents_right_activate().

◆ document_get_status_color()

const GdkColor * document_get_status_color ( GeanyDocument doc)

Gets the status color of the document, or NULL if default widget coloring should be used.

Returned colors are red if the document has changes, green if the document is read-only or simply NULL if the document is unmodified but writable.

Parameters
docThe document to use.
Returns
The color for the document or NULL if the default color should be used. The color object is owned by Geany and should not be modified or freed.
Since
0.16

Definition at line 3276 of file document.c.

References color, document_get_status_id(), document_status_styles, GeanyDocument::editor, loaded, name, NULL, and GeanyEditor::sci.

Referenced by sidebar_openfiles_add(), and sidebar_openfiles_update().

◆ document_get_type()

GType document_get_type ( void  )

◆ document_index()

GeanyDocument * document_index ( gint  idx)

Accessor function for GeanyData::documents_array items.

Warning
Always check the returned document is valid (doc->is_valid).
Parameters
idxGeanyData::documents_array index.
Returns
(transfer: none) The document, or NULL if idx is out of range.
Since
0.16

Definition at line 3317 of file document.c.

References documents, documents_array, and NULL.

◆ document_new_file()

GeanyDocument * document_new_file ( const gchar *  utf8_filename,
GeanyFiletype ft,
const gchar *  text 
)

Creates a new document.

Line endings in text will be converted to the default setting. Afterwards, the "document-new" signal is emitted for plugins.

Parameters
utf8_filename The file name in UTF-8 encoding, or NULL to open a file as "untitled".
ft The filetype to set or NULL to detect it from filename if not NULL.
text The initial content of the file (in UTF-8 encoding), or NULL.
Returns
(transfer: none) The new document.

Definition at line 824 of file document.c.

References _, build_menu_update(), GeanyEncoding::charset, GeanyFilePrefs::default_eol_character, GeanyFilePrefs::default_new_encoding, DOC_FILENAME, document_create(), document_get_notebook_child(), document_set_filetype(), document_set_text_changed(), document_try_focus(), GeanyDocument::editor, editor_goto_pos(), editor_prefs, editor_sci_notify_cb(), GeanyDocument::encoding, encodings, file_prefs, filetypes_detect_from_document(), geany_object, monitor_file_setup(), msgwin_status_add(), GeanyDocumentPrivate::mtime, NULL, GeanyDocument::priv, GeanyEditor::sci, sci_clear_all(), sci_empty_undo_buffer(), sci_set_eol_mode(), sci_set_line_numbers(), sci_set_text(), sci_set_undo_collection(), GeanyEditorPrefs::show_linenumber_margin, store_saved_encoding(), text, ui_document_show_hide(), ui_set_window_title(), utils_ensure_same_eol_characters(), utils_strdupa, and utils_tidy_path().

Referenced by cb_func_file_action(), document_clone(), document_new_file_if_non_open(), main_handle_filename(), notebook_tab_bar_click_cb(), on_config_file_clicked(), on_new1_activate(), and on_new_with_file_template().

◆ document_open_file()

GeanyDocument * document_open_file ( const gchar *  locale_filename,
gboolean  readonly,
GeanyFiletype ft,
const gchar *  forced_enc 
)

Opens a document specified by locale_filename.

Afterwards, the "document-open" signal is emitted for plugins.

Parameters
locale_filenameThe filename of the document to load, in locale encoding.
readonlyWhether to open the document in read-only mode.
ft The filetype for the document or NULL to auto-detect the filetype.
forced_enc The file encoding to use or NULL to auto-detect the file encoding.
Returns
(transfer: none) The document opened or NULL.

Definition at line 908 of file document.c.

References document_open_file_full(), and NULL.

Referenced by cb_func_file_action(), document_open_file_list(), document_open_files(), goto_compiler_file_line(), goto_tag(), main_handle_filename(), msgwin_goto_messages_file_line(), on_config_file_clicked(), on_goto_popup_item_activate(), on_menu_open_selected_file1_activate(), and recent_file_activate_cb().

◆ document_open_files()

void document_open_files ( const GSList *  filenames,
gboolean  readonly,
GeanyFiletype ft,
const gchar *  forced_enc 
)

Opens each file in the list filenames.

Internally, document_open_file() is called for every list item.

Parameters
filenames (element-type: filename) A list of filenames to load, in locale encoding.
readonlyWhether to open the document in read-only mode.
ft The filetype for the document or NULL to auto-detect the filetype.
forced_enc The file encoding to use or NULL to auto-detect the file encoding.

Definition at line 1555 of file document.c.

References document_open_file(), and NULL.

Referenced by open_file_dialog_handle_response(), and open_selected_files().

◆ document_reload_force()

gboolean document_reload_force ( GeanyDocument doc,
const gchar *  forced_enc 
)

Reloads the document with the specified file encoding.

forced_enc or NULL to auto-detect the file encoding.

Parameters
docThe document to reload.
forced_enc The file encoding to use or NULL to auto-detect the file encoding.
Returns
TRUE if the document was actually reloaded or FALSE otherwise.

Definition at line 1595 of file document.c.

References _, document_open_file_full(), document_show_message(), GeanyDocument::editor, file_prefs, GeanyDocument::file_type, GeanyDocumentPrivate::info_bars, GeanyFilePrefs::keep_edit_history_on_reload, MSG_TYPE_POST_RELOAD, MSG_TYPE_RELOAD, MSG_TYPE_RESAVE, NULL, on_keep_edit_history_on_reload_response(), pos, GeanyDocument::priv, GeanyDocument::readonly, GeanyEditor::sci, sci_get_current_position(), and GeanyFilePrefs::show_keep_edit_history_on_reload_msg.

Referenced by document_reload_prompt(), monitor_reload_file(), on_keep_edit_history_on_reload_response(), on_monitor_reload_file_response(), and on_reload_all().

◆ document_remove_page()

gboolean document_remove_page ( guint  page_num)

Removes the given notebook tab at page_num and clears all related information in the document list.

Parameters
page_numThe notebook page number to remove.
Returns
TRUE if the document was actually removed or FALSE otherwise.

Definition at line 782 of file document.c.

References document_new_file_if_non_open(), remove_page(), and ui_prefs.

Referenced by document_close().

◆ document_rename_file()

void document_rename_file ( GeanyDocument doc,
const gchar *  new_filename 
)

Renames the file in doc to new_filename.

Only the file on disk is actually renamed, you still have to call document_save_file_as() to change the doc object. It also stops monitoring for file changes to prevent receiving too many file change events while renaming. File monitoring is setup again in document_save_file_as().

Parameters
docThe current document which should be renamed.
new_filenameThe new filename in UTF-8 encoding.
Since
0.16

Definition at line 1749 of file document.c.

References _, dialogs_show_msgbox_with_secondary(), document_stop_file_monitoring(), errno, GeanyDocument::file_name, and utils_get_locale_from_utf8().

Referenced by handle_save_as().

◆ document_save_file()

gboolean document_save_file ( GeanyDocument doc,
gboolean  force 
)

Saves the document.

Also shows the Save As dialog if necessary. If the file is not modified, this function may do nothing unless force is set to TRUE.

Saving may include replacing tabs with spaces, stripping trailing spaces and adding a final new line at the end of the file, depending on user preferences. Then the "document-before-save" signal is emitted, allowing plugins to modify the document before it is saved, and data is actually written to disk.

On successful saving:

  • GeanyDocument::real_path is set.
  • The filetype is set again or auto-detected if it wasn't set yet.
  • The "document-save" signal is emitted for plugins.
Warning
You should ensure doc->file_name has an absolute path unless you want the Save As dialog to be shown. A NULL value also shows the dialog. This behaviour was added in Geany 1.22.
Parameters
docThe document to save.
forceWhether to save the file even if it is not modified.
Returns
TRUE if the file was saved or FALSE if the file could not or should not be saved.

Definition at line 2103 of file document.c.

References _, GeanyDocument::changed, GeanyEncoding::charset, dialogs_show_msgbox_with_secondary(), dialogs_show_save_as(), GeanyFilePrefs::disk_check_timeout, DOC_FILENAME, document_check_disk_status(), document_need_save_as(), document_set_filetype(), document_show_tab(), document_update_tab_label(), document_update_timestamp(), GeanyDocument::editor, editor_ensure_final_newline(), editor_replace_tabs(), editor_strip_trailing_spaces(), GeanyDocument::encoding, encodings, encodings_is_unicode_charset(), GeanyFilePrefs::ensure_convert_new_lines, GeanyDocumentPrivate::file_disk_status, FILE_IGNORE, GeanyDocument::file_name, FILE_OK, file_prefs, GeanyDocument::file_type, GeanyFilePrefs::final_new_line, GEANY_ENCODING_NONE, GEANY_FILETYPES_MAKE, geany_object, GeanyDocument::has_bom, GeanyFiletype::id, main_status, msgwin_status_add(), NULL, GeanyDocument::priv, project_get_file_prefs(), GeanyDocumentPrivate::protected, GeanyDocument::readonly, GeanyDocument::real_path, GeanyFilePrefs::replace_tabs, save_convert_to_encoding(), save_doc(), save_file_handle_infobars(), GeanyEditor::sci, sci_convert_eols(), sci_get_eol_mode(), sci_get_length(), sci_get_text(), sci_set_savepoint(), SETPTR, store_saved_encoding(), GeanyFilePrefs::strip_trailing_spaces, ui_set_statusbar(), ui_update_statusbar(), GeanyFilePrefs::use_safe_file_saving, utils_beep(), utils_get_locale_from_utf8(), and utils_str_equal().

Referenced by auto_save(), dialogs_show_unsaved_file(), document_action(), document_save_file_as(), instantsave_document_new_cb(), on_build_menu_item(), on_monitor_reload_file_response(), on_save1_activate(), on_save_all1_activate(), and save_on_focus_out_idle().

◆ document_save_file_as()

gboolean document_save_file_as ( GeanyDocument doc,
const gchar *  utf8_fname 
)

◆ document_set_encoding()

void document_set_encoding ( GeanyDocument doc,
const gchar *  new_encoding 
)

Sets the encoding of a document.

This function only set the encoding of the document, it does not any conversions. The new encoding is used when e.g. saving the file.

Parameters
docThe document to use.
new_encodingThe encoding to be set for the document.

Definition at line 2879 of file document.c.

References GeanyDocument::encoding, encodings_is_unicode_charset(), main_widgets, NULL, ui_lookup_widget(), ui_update_statusbar(), utils_str_equal(), and GeanyMainWidgets::window.

Referenced by document_clone(), document_redo(), document_undo(), and encodings_radio_item_change_cb().

◆ document_set_filetype()

◆ document_set_text_changed()

void document_set_text_changed ( GeanyDocument doc,
gboolean  changed 
)

Updates the tab labels, the status bar, the window title and some save-sensitive buttons according to the document's save state.

This is called by Geany mostly when opening or saving files.

Parameters
docThe document to use.
changedWhether the document state should indicate changes have been made.

Definition at line 460 of file document.c.

References GeanyDocument::changed, main_status, NULL, ui_save_buttons_toggle(), ui_set_window_title(), ui_update_statusbar(), and ui_update_tab_status().

Referenced by document_clone(), document_new_file(), document_open_file_full(), document_redo_add(), document_undo_add_internal(), document_undo_clear(), monitor_resave_missing_file(), on_config_file_clicked(), on_editor_notify(), on_monitor_reload_file_response(), and update_changed_state().