Skip to content

Commit

Permalink
workbench: auto-save project on change
Browse files Browse the repository at this point in the history
This removes the item "Save project" from the popup menu and automatically
saves a project if something is changed (e.g. directory added/removed).

This also fixes some situations in which saving of the workbench file
was missing (e.g. a change in the workbench bookmarks). See geany#841.
  • Loading branch information
lpaulsen93 committed Jun 23, 2019
1 parent 612cb70 commit f1ae577
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
6 changes: 0 additions & 6 deletions workbench/README
Expand Up @@ -62,12 +62,6 @@ These are the available items:
adding a project you need to save the workbench settings by selecting
"Workbench / Save" in the menubar.

**Save project**
Selecting this item will save the Workbench related project settings in
the Geany project file. It is only available if you right clicked inside
of a project. It will only save the settings of the project that you
clicked on.

**Remove project**
Remove the project from the Workbench. It is only available if you
right clicked inside of a project. After removing a project you need
Expand Down
2 changes: 1 addition & 1 deletion workbench/src/plugin_main.c
Expand Up @@ -117,7 +117,7 @@ void geany_load_module(GeanyPlugin *plugin)
/* Set metadata */
plugin->info->name = _("Workbench");
plugin->info->description = _("Manage and customize multiple projects.");
plugin->info->version = "1.07";
plugin->info->version = "1.08";
plugin->info->author = "LarsGit223";

/* Set functions */
Expand Down
81 changes: 53 additions & 28 deletions workbench/src/popup_menu.c
Expand Up @@ -41,7 +41,6 @@ static struct
GtkWidget *widget;

GtkWidget *add_project;
GtkWidget *save_project;
GtkWidget *remove_project;
GtkWidget *fold_unfold_project;
GtkWidget *project_open_all;
Expand Down Expand Up @@ -243,6 +242,32 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
}


/* Helper function for saving the project and updating of the sidebar. */
static void save_project(SIDEBAR_CONTEXT *context)
{
GError *error = NULL;

if (context->project != NULL && wb_project_save(context->project, &error))
{
sidebar_update(SIDEBAR_CONTEXT_PROJECT_SAVED, context);
}
}


/* Helper function for saving the workbench and updating of the sidebar. */
static void save_workbench(WORKBENCH *wb)
{
GError *error = NULL;

/* Save the new settings to the workbench file (.geanywb). */
if (!workbench_save(wb, &error))
{
dialogs_show_msgbox(GTK_MESSAGE_INFO, _("Could not save workbench file: %s"), error->message);
}
sidebar_update(SIDEBAR_CONTEXT_WB_SAVED, NULL);
}


/* Handle popup menu item "Add project" */
static void popup_menu_on_add_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
{
Expand All @@ -257,6 +282,9 @@ static void popup_menu_on_add_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNU
if (workbench_add_project(wb_globals.opened_wb, filename))
{
sidebar_update(SIDEBAR_CONTEXT_PROJECT_ADDED, NULL);

/* Save the changes to the workbench file (.geanywb). */
save_workbench(wb_globals.opened_wb);
}
else
{
Expand All @@ -266,27 +294,6 @@ static void popup_menu_on_add_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNU
}


/* Handle popup menu item "Save project" */
static void popup_menu_on_save_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
{
GError *error = NULL;
WB_PROJECT *project;

project = sidebar_file_view_get_selected_project(NULL);
if (project != NULL && wb_globals.opened_wb != NULL)
{
if (wb_project_save(project, &error))
{
SIDEBAR_CONTEXT context;

memset(&context, 0, sizeof(context));
context.project = project;
sidebar_update(SIDEBAR_CONTEXT_PROJECT_SAVED, &context);
}
}
}


/* Handle popup menu item "Remove project" */
static void popup_menu_on_remove_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
{
Expand All @@ -302,6 +309,9 @@ static void popup_menu_on_remove_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_
memset(&context, 0, sizeof(context));
context.project = project;
sidebar_update(SIDEBAR_CONTEXT_PROJECT_REMOVED, &context);

/* Save the changes to the workbench file (.geanywb). */
save_workbench(wb_globals.opened_wb);
}
}
}
Expand Down Expand Up @@ -375,6 +385,9 @@ static void popup_menu_on_add_directory(G_GNUC_UNUSED GtkMenuItem * menuitem, G_
wb_project_add_directory(project, dirname);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_ADDED, &context);
g_free(dirname);

/* Save the now changed project. */
save_project(&context);
}
}
}
Expand All @@ -390,6 +403,9 @@ static void popup_menu_on_remove_directory(G_GNUC_UNUSED GtkMenuItem * menuitem,
{
wb_project_remove_directory(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_REMOVED, &context);

/* Save the now changed project. */
save_project(&context);
}
}

Expand Down Expand Up @@ -421,6 +437,9 @@ static void popup_menu_on_directory_settings(G_GNUC_UNUSED GtkMenuItem * menuite
wb_project_set_modified(context.project, TRUE);
wb_project_dir_rescan(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_SETTINGS_CHANGED, &context);

/* Save the now changed project. */
save_project(&context);
}
}
}
Expand Down Expand Up @@ -471,6 +490,9 @@ static void popup_menu_on_add_to_workbench_bookmarks(G_GNUC_UNUSED GtkMenuItem *
{
workbench_add_bookmark(wb_globals.opened_wb, context.file);
sidebar_update(SIDEBAR_CONTEXT_WB_BOOKMARK_ADDED, &context);

/* Save the changes to the workbench file (.geanywb). */
save_workbench(wb_globals.opened_wb);
}
}

Expand All @@ -485,6 +507,9 @@ static void popup_menu_on_add_to_project_bookmarks(G_GNUC_UNUSED GtkMenuItem *me
{
wb_project_add_bookmark(context.project, context.file);
sidebar_update(SIDEBAR_CONTEXT_PRJ_BOOKMARK_ADDED, &context);

/* Save the now changed project. */
save_project(&context);
}
}

Expand All @@ -499,12 +524,18 @@ static void popup_menu_on_remove_from_bookmarks(G_GNUC_UNUSED GtkMenuItem *menui
{
workbench_remove_bookmark(wb_globals.opened_wb, context.wb_bookmark);
sidebar_update(SIDEBAR_CONTEXT_WB_BOOKMARK_REMOVED, &context);

/* Save the changes to the workbench file (.geanywb). */
save_workbench(wb_globals.opened_wb);
}
if (sidebar_file_view_get_selected_context(&context)
&& context.project != NULL && context.prj_bookmark != NULL)
{
wb_project_remove_bookmark(context.project, context.prj_bookmark);
sidebar_update(SIDEBAR_CONTEXT_PRJ_BOOKMARK_REMOVED, &context);

/* Save the now changed project. */
save_project(&context);
}
}

Expand Down Expand Up @@ -782,12 +813,6 @@ void popup_menu_init(void)
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_add_project), NULL);
s_popup_menu.add_project = item;

item = gtk_menu_item_new_with_mnemonic(_("_Save project"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_save_project), NULL);
s_popup_menu.save_project = item;

item = gtk_menu_item_new_with_mnemonic(_("_Remove project"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);
Expand Down

0 comments on commit f1ae577

Please sign in to comment.