Skip to content

Workbench: added support for project switching #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions workbench/README
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ These are the available items:
to save the workbench settings by selecting "Workbench / Save" in the
menubar.

**Select/Unselect project**
Toggles the selection of a project. If the project gets selected then
the corresponding Geany project will be opened. In the sidebar the
project will be marked with the suffix "[SEL]". If the project already
is selected then it will be un-selected. This feature at least requires
Geany version 1.36.

**Fold/unfold project**
Fold or unfold the items belonging to the project. It is only available
if you right clicked inside of a project.
Expand Down Expand Up @@ -167,6 +174,13 @@ The following settings exist for a workbench:
If the option is activated, lines will be drawn between the nodes in
the sidebar tree.

**Enable auto-open project by document**
If the option is activated, then opening or activating a document will
automatically open the project belonging to the document. If a specific
project is selected (see above under **Select/Unselect project**) then
that project will stay opened and no switching to another project will
take place. This feature at least requires Geany version 1.36.

Live update
-----------
From version 1.03 on the workbench plugin supports an automatic live update
Expand Down Expand Up @@ -258,6 +272,9 @@ History

This is a short release history showing the major changes:

**1.10:**
Support project switching/opening by the Workbench plugin.
This feature at least requires Geany version 1.36.
**1.09:**
Added option to let git decide which files to display
**1.08:**
Expand Down
28 changes: 27 additions & 1 deletion workbench/src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
{
gint result;
GtkWidget *w_rescan_projects_on_open, *w_enable_live_update, *w_expand_on_hover;
GtkWidget *dialog, *content_area, *w_enable_tree_lines;
GtkWidget *dialog, *content_area, *w_enable_tree_lines, *w_auto_open_by_doc;
GtkWidget *vbox, *hbox;
#if GTK_CHECK_VERSION(3, 4, 0)
GtkWidget *grid;
Expand All @@ -582,6 +582,7 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
gboolean enable_live_update, enable_live_update_old;
gboolean expand_on_hover, expand_on_hover_old;
gboolean enable_tree_lines, enable_tree_lines_old;
gboolean enable_auto_open_by_doc, enable_auto_open_by_doc_old;

/* Create the widgets */
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
Expand Down Expand Up @@ -670,6 +671,25 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
enable_tree_lines_old = workbench_get_enable_tree_lines(workbench);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_enable_tree_lines), enable_tree_lines_old);

w_auto_open_by_doc = gtk_check_button_new_with_mnemonic(_("_Enable auto-open project by document"));
#if GTK_CHECK_VERSION(3, 4, 0)
gtk_grid_attach (GTK_GRID(grid), w_auto_open_by_doc, 0, 4, 1, 1);
gtk_widget_set_halign (w_auto_open_by_doc, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (w_auto_open_by_doc, TRUE);
gtk_widget_set_valign (w_auto_open_by_doc, GTK_ALIGN_CENTER);
gtk_widget_set_vexpand (w_auto_open_by_doc, TRUE);
#else
ui_table_add_row(GTK_TABLE(table), 4, w_auto_open_by_doc, NULL);
#endif
gtk_widget_set_tooltip_text(w_auto_open_by_doc,
_("If the option is activated, a project will be auto-opened "
"if a document belonging to the project becomes active."));
enable_auto_open_by_doc_old = workbench_get_enable_auto_open_by_doc(workbench);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_auto_open_by_doc), enable_auto_open_by_doc_old);
#if GEANY_API_VERSION < 240
gtk_widget_set_sensitive (w_auto_open_by_doc, FALSE);
#endif

#if GTK_CHECK_VERSION(3, 4, 0)
gtk_box_pack_start(GTK_BOX(vbox), grid, FALSE, FALSE, 6);
#else
Expand Down Expand Up @@ -711,6 +731,12 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
changed = TRUE;
workbench_set_enable_tree_lines(workbench, enable_tree_lines);
}
enable_auto_open_by_doc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w_auto_open_by_doc));
if (enable_auto_open_by_doc != enable_auto_open_by_doc_old)
{
changed = TRUE;
workbench_set_enable_auto_open_by_doc(workbench, enable_auto_open_by_doc);
}
}

gtk_widget_destroy(dialog);
Expand Down
12 changes: 11 additions & 1 deletion workbench/src/idle_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ static gboolean wb_idle_queue_callback(gpointer foo)
case WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE:
wb_tm_control_source_files_remove(action->param_a);
break;
#if GEANY_API_VERSION >= 240
case WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC:
workbench_open_project_by_filename(wb_globals.opened_wb, action->param_a);
g_free(action->param_a);
break;
#endif
case WB_IDLE_ACTION_ID_OPEN_DOC:
document_open_file(action->param_a, FALSE, NULL, NULL);
g_free(action->param_a);
break;
}
}

Expand Down Expand Up @@ -130,5 +140,5 @@ void wb_idle_queue_add_action(WB_IDLE_QUEUE_ACTION_ID id, gpointer param_a)
plugin_idle_add(wb_globals.geany_plugin, (GSourceFunc)wb_idle_queue_callback, NULL);
}

s_idle_actions = g_slist_prepend(s_idle_actions, action);
s_idle_actions = g_slist_append(s_idle_actions, action);
}
4 changes: 4 additions & 0 deletions workbench/src/idle_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ typedef enum
WB_IDLE_ACTION_ID_TM_SOURCE_FILE_FREE,
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_NEW,
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE,
#if GEANY_API_VERSION >= 240
WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC,
#endif
WB_IDLE_ACTION_ID_OPEN_DOC,
}WB_IDLE_QUEUE_ACTION_ID;

void wb_idle_queue_add_action(WB_IDLE_QUEUE_ACTION_ID id, gpointer param_a);
Expand Down
30 changes: 29 additions & 1 deletion workbench/src/plugin_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ static void plugin_workbench_on_doc_close(G_GNUC_UNUSED GObject * obj, GeanyDocu
}


#if GEANY_API_VERSION >= 240

/* Callback function for document activate */
static void plugin_workbench_on_doc_activate(G_GNUC_UNUSED GObject * obj, GeanyDocument * doc,
G_GNUC_UNUSED gpointer user_data)
{
g_return_if_fail(doc != NULL && doc->file_name != NULL);
if (wb_globals.opened_wb != NULL &&
workbench_get_enable_auto_open_by_doc(wb_globals.opened_wb) == TRUE &&
workbench_get_selected_project(wb_globals.opened_wb) == NULL)
{
wb_idle_queue_add_action(WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC,
g_strdup(doc->file_name));
}
}

#endif


/* Initialize plugin */
static gboolean plugin_workbench_init(GeanyPlugin *plugin, G_GNUC_UNUSED gpointer pdata)
{
Expand All @@ -91,6 +110,12 @@ static gboolean plugin_workbench_init(GeanyPlugin *plugin, G_GNUC_UNUSED gpointe
/* Init libgit2. */
git_libgit2_init();

#if GEANY_API_VERSION < 240
ui_set_statusbar(TRUE,
_("Workbench: project switching is not available. Your version of Geany is too old. "
"At least version 1.36 is required to enable project switching."));
#endif

return TRUE;
}

Expand All @@ -117,6 +142,9 @@ static void plugin_workbench_help (G_GNUC_UNUSED GeanyPlugin *plugin, G_GNUC_UNU
static PluginCallback plugin_workbench_callbacks[] = {
{"document-open", (GCallback) &plugin_workbench_on_doc_open, TRUE, NULL},
{"document-close", (GCallback) &plugin_workbench_on_doc_close, TRUE, NULL},
#if GEANY_API_VERSION >= 240
{"document_activate", (GCallback) &plugin_workbench_on_doc_activate, TRUE, NULL},
#endif
{NULL, NULL, FALSE, NULL}
};

Expand All @@ -131,7 +159,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.09";
plugin->info->version = "1.10";
plugin->info->author = "LarsGit223";

/* Set functions */
Expand Down
59 changes: 59 additions & 0 deletions workbench/src/popup_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <project.h>

#include "wb_globals.h"
#include "dialogs.h"
Expand All @@ -42,6 +43,7 @@ static struct

GtkWidget *add_project;
GtkWidget *remove_project;
GtkWidget *project_toggle_select;
GtkWidget *fold_unfold_project;
GtkWidget *project_open_all;
GtkWidget *project_close_all;
Expand Down Expand Up @@ -81,6 +83,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_PROJECT:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
#if GEANY_API_VERSION >= 240
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
#else
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
#endif
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
Expand All @@ -103,6 +110,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_DIRECTORY:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
#if GEANY_API_VERSION >= 240
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
#else
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
#endif
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
Expand All @@ -125,6 +137,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_SUB_DIRECTORY:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
#if GEANY_API_VERSION >= 240
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
#else
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
#endif
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
Expand All @@ -147,6 +164,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_FILE:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
#if GEANY_API_VERSION >= 240
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
#else
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
#endif
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
Expand All @@ -169,6 +191,7 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_BACKGROUND:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, FALSE);
Expand All @@ -191,6 +214,7 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_WB_BOOKMARK:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, FALSE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, FALSE);
Expand All @@ -213,6 +237,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
case POPUP_CONTEXT_PRJ_BOOKMARK:
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
#if GEANY_API_VERSION >= 240
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
#else
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
#endif
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
Expand Down Expand Up @@ -317,6 +346,28 @@ static void popup_menu_on_remove_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_
}


/* Handle popup menu item "Select/Unselect project" */
#if GEANY_API_VERSION >= 240
static void popup_menu_on_toggle_selected_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
{
WB_PROJECT *project;

project = sidebar_file_view_get_selected_project(NULL);
if (project != NULL && wb_globals.opened_wb != NULL)
{
if (workbench_get_selected_project(wb_globals.opened_wb) != project)
{
workbench_open_project(wb_globals.opened_wb, project, TRUE);
}
else
{
workbench_open_project(wb_globals.opened_wb, NULL, TRUE);
}
}
}
#endif


/* Handle popup menu item "Expand all" */
static void popup_menu_on_expand_all(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
{
Expand Down Expand Up @@ -819,6 +870,14 @@ void popup_menu_init(void)
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_remove_project), NULL);
s_popup_menu.remove_project = item;

item = gtk_menu_item_new_with_mnemonic(_("_Select/Unselect project"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);
#if GEANY_API_VERSION >= 240
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_toggle_selected_project), NULL);
#endif
s_popup_menu.project_toggle_select = item;

item = gtk_menu_item_new_with_mnemonic(_("_Fold/unfold project"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);
Expand Down
Loading