From 8d134534d29568eebb8099b7cea3865709256279 Mon Sep 17 00:00:00 2001 From: LarsGit223 Date: Sun, 28 Jul 2019 21:34:39 +0200 Subject: [PATCH] Plugin-API: extended project API Added 'project_close()' and 'project_load_file()' to the plugin API. Also added a setter and getter function for 'project_prefs.project_session'. --- src/plugindata.h | 2 +- src/project.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++- src/project.h | 12 +++++++----- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/plugindata.h b/src/plugindata.h index 8fb0e35140..ad5ab77bbb 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -58,7 +58,7 @@ G_BEGIN_DECLS * @warning You should not test for values below 200 as previously * @c GEANY_API_VERSION was defined as an enum value, not a macro. */ -#define GEANY_API_VERSION 239 +#define GEANY_API_VERSION 240 /* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins * with GTK3-linked Geany leads to crash */ diff --git a/src/project.c b/src/project.c index 19eef0f26b..a5e628ea5d 100644 --- a/src/project.c +++ b/src/project.c @@ -264,6 +264,40 @@ void project_new(void) } +/** Controls whether currently opened files are stored in the project file. + * + * If @a save is @c TRUE, this causes the opened files to be persisted when + * the project is closed and re-opened, or when @c FALSE none of the + * opened files will be re-opened when a project is re-opened. + * + * @param save Whether or not to persist the list of open files in the project file. + * + * @see project_get_save_open_files_list + * @see project_close + * @since 1.36 (240) + */ +GEANY_API_SYMBOL +void project_set_save_open_files_list(gboolean save) +{ + project_prefs.project_session = save; +} + + +/** Returns if opened project files shall be restored or not. + * + * See @ref project_set_save_open_files_list for documentation. + * + * @returns @c TRUE if open files are restored or @c FALSE if not. + * @see project_close + * @since 1.36 (240) + */ +GEANY_API_SYMBOL +gboolean project_get_save_open_files_list(void) +{ + return project_prefs.project_session; +} + + gboolean project_load_file_with_session(const gchar *locale_file_name) { if (project_load_file(locale_file_name)) @@ -397,7 +431,13 @@ static void remove_foreach_project_filetype(gpointer data, gpointer user_data) } -/* open_default will make function reload default session files on close */ +/** Closes the project and eventually reloads default session files on close. + * + * @param open_default Load default session files? + * @returns @c TRUE on success and @c FALSE on error (error on closing docs) + * @since 1.36 (240) + */ +GEANY_API_SYMBOL gboolean project_close(gboolean open_default) { g_return_val_if_fail(app->project != NULL, FALSE); @@ -1001,6 +1041,13 @@ static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget } +/** Open a project file + * + * @param locale_file_name File path of the project to open + * @returns @c TRUE on success and @c FALSE otherwise (config file could not be loaded) + * @since 1.36 (240) + */ +GEANY_API_SYMBOL gboolean project_load_file(const gchar *locale_file_name) { g_return_val_if_fail(locale_file_name != NULL, FALSE); diff --git a/src/project.h b/src/project.h index 4fdacb65bb..2d7ce09d83 100644 --- a/src/project.h +++ b/src/project.h @@ -49,6 +49,13 @@ GeanyProject; void project_write_config(void); +gboolean project_close(gboolean open_default); + +gboolean project_load_file(const gchar *locale_file_name); + +void project_set_save_open_files_list(gboolean save); + +gboolean project_get_save_open_files_list(void); #ifdef GEANY_PRIVATE @@ -71,17 +78,12 @@ void project_new(void); void project_open(void); -gboolean project_close(gboolean open_default); - void project_properties(void); void project_build_properties(void); gboolean project_ask_close(void); - -gboolean project_load_file(const gchar *locale_file_name); - gboolean project_load_file_with_session(const gchar *locale_file_name); gchar *project_get_base_path(void);