Skip to content

Commit 81f34b4

Browse files
committed
Workbench: added support for project switching
1 parent 53d6515 commit 81f34b4

12 files changed

+396
-4
lines changed

Diff for: workbench/README

+17
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ These are the available items:
7474
to save the workbench settings by selecting "Workbench / Save" in the
7575
menubar.
7676

77+
**Select/Unselect project**
78+
Toggles the selection of a project. If the project gets selected then
79+
the corresponding Geany project will be opened. In the sidebar the
80+
project will be marked with the suffix "[SEL]". If the project already
81+
is selected then it will be un-selected. This feature at least requires
82+
Geany version 1.36.
83+
7784
**Fold/unfold project**
7885
Fold or unfold the items belonging to the project. It is only available
7986
if you right clicked inside of a project.
@@ -167,6 +174,13 @@ The following settings exist for a workbench:
167174
If the option is activated, lines will be drawn between the nodes in
168175
the sidebar tree.
169176

177+
**Enable auto-open project by document**
178+
If the option is activated, then opening or activating a document will
179+
automatically open the project belonging to the document. If a specific
180+
project is selected (see above under **Select/Unselect project**) then
181+
that project will stay opened and no switching to another project will
182+
take place. This feature at least requires Geany version 1.36.
183+
170184
Live update
171185
-----------
172186
From version 1.03 on the workbench plugin supports an automatic live update
@@ -258,6 +272,9 @@ History
258272

259273
This is a short release history showing the major changes:
260274

275+
**1.10:**
276+
Support project switching/opening by the Workbench plugin.
277+
This feature at least requires Geany version 1.36.
261278
**1.09:**
262279
Added option to let git decide which files to display
263280
**1.08:**

Diff for: workbench/src/dialogs.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
570570
{
571571
gint result;
572572
GtkWidget *w_rescan_projects_on_open, *w_enable_live_update, *w_expand_on_hover;
573-
GtkWidget *dialog, *content_area, *w_enable_tree_lines;
573+
GtkWidget *dialog, *content_area, *w_enable_tree_lines, *w_auto_open_by_doc;
574574
GtkWidget *vbox, *hbox;
575575
#if GTK_CHECK_VERSION(3, 4, 0)
576576
GtkWidget *grid;
@@ -582,6 +582,7 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
582582
gboolean enable_live_update, enable_live_update_old;
583583
gboolean expand_on_hover, expand_on_hover_old;
584584
gboolean enable_tree_lines, enable_tree_lines_old;
585+
gboolean enable_auto_open_by_doc, enable_auto_open_by_doc_old;
585586

586587
/* Create the widgets */
587588
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
@@ -670,6 +671,25 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
670671
enable_tree_lines_old = workbench_get_enable_tree_lines(workbench);
671672
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_enable_tree_lines), enable_tree_lines_old);
672673

674+
w_auto_open_by_doc = gtk_check_button_new_with_mnemonic(_("_Enable auto-open project by document"));
675+
#if GTK_CHECK_VERSION(3, 4, 0)
676+
gtk_grid_attach (GTK_GRID(grid), w_auto_open_by_doc, 0, 4, 1, 1);
677+
gtk_widget_set_halign (w_auto_open_by_doc, GTK_ALIGN_CENTER);
678+
gtk_widget_set_hexpand (w_auto_open_by_doc, TRUE);
679+
gtk_widget_set_valign (w_auto_open_by_doc, GTK_ALIGN_CENTER);
680+
gtk_widget_set_vexpand (w_auto_open_by_doc, TRUE);
681+
#else
682+
ui_table_add_row(GTK_TABLE(table), 4, w_auto_open_by_doc, NULL);
683+
#endif
684+
gtk_widget_set_tooltip_text(w_auto_open_by_doc,
685+
_("If the option is activated, a project will be auto-opened "
686+
"if a document belonging to the project becomes active."));
687+
enable_auto_open_by_doc_old = workbench_get_enable_auto_open_by_doc(workbench);
688+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_auto_open_by_doc), enable_auto_open_by_doc_old);
689+
#if GEANY_API_VERSION < 240
690+
gtk_widget_set_sensitive (w_auto_open_by_doc, FALSE);
691+
#endif
692+
673693
#if GTK_CHECK_VERSION(3, 4, 0)
674694
gtk_box_pack_start(GTK_BOX(vbox), grid, FALSE, FALSE, 6);
675695
#else
@@ -711,6 +731,12 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
711731
changed = TRUE;
712732
workbench_set_enable_tree_lines(workbench, enable_tree_lines);
713733
}
734+
enable_auto_open_by_doc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w_auto_open_by_doc));
735+
if (enable_auto_open_by_doc != enable_auto_open_by_doc_old)
736+
{
737+
changed = TRUE;
738+
workbench_set_enable_auto_open_by_doc(workbench, enable_auto_open_by_doc);
739+
}
714740
}
715741

716742
gtk_widget_destroy(dialog);

Diff for: workbench/src/idle_queue.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ static gboolean wb_idle_queue_callback(gpointer foo)
9494
case WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE:
9595
wb_tm_control_source_files_remove(action->param_a);
9696
break;
97+
#if GEANY_API_VERSION >= 240
98+
case WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC:
99+
workbench_open_project_by_filename(wb_globals.opened_wb, action->param_a);
100+
g_free(action->param_a);
101+
break;
102+
#endif
103+
case WB_IDLE_ACTION_ID_OPEN_DOC:
104+
document_open_file(action->param_a, FALSE, NULL, NULL);
105+
g_free(action->param_a);
106+
break;
97107
}
98108
}
99109

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

133-
s_idle_actions = g_slist_prepend(s_idle_actions, action);
143+
s_idle_actions = g_slist_append(s_idle_actions, action);
134144
}

Diff for: workbench/src/idle_queue.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ typedef enum
2626
WB_IDLE_ACTION_ID_TM_SOURCE_FILE_FREE,
2727
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_NEW,
2828
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE,
29+
#if GEANY_API_VERSION >= 240
30+
WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC,
31+
#endif
32+
WB_IDLE_ACTION_ID_OPEN_DOC,
2933
}WB_IDLE_QUEUE_ACTION_ID;
3034

3135
void wb_idle_queue_add_action(WB_IDLE_QUEUE_ACTION_ID id, gpointer param_a);

Diff for: workbench/src/plugin_main.c

+29-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ static void plugin_workbench_on_doc_close(G_GNUC_UNUSED GObject * obj, GeanyDocu
6969
}
7070

7171

72+
#if GEANY_API_VERSION >= 240
73+
74+
/* Callback function for document activate */
75+
static void plugin_workbench_on_doc_activate(G_GNUC_UNUSED GObject * obj, GeanyDocument * doc,
76+
G_GNUC_UNUSED gpointer user_data)
77+
{
78+
g_return_if_fail(doc != NULL && doc->file_name != NULL);
79+
if (wb_globals.opened_wb != NULL &&
80+
workbench_get_enable_auto_open_by_doc(wb_globals.opened_wb) == TRUE &&
81+
workbench_get_selected_project(wb_globals.opened_wb) == NULL)
82+
{
83+
wb_idle_queue_add_action(WB_IDLE_ACTION_ID_OPEN_PROJECT_BY_DOC,
84+
g_strdup(doc->file_name));
85+
}
86+
}
87+
88+
#endif
89+
90+
7291
/* Initialize plugin */
7392
static gboolean plugin_workbench_init(GeanyPlugin *plugin, G_GNUC_UNUSED gpointer pdata)
7493
{
@@ -91,6 +110,12 @@ static gboolean plugin_workbench_init(GeanyPlugin *plugin, G_GNUC_UNUSED gpointe
91110
/* Init libgit2. */
92111
git_libgit2_init();
93112

113+
#if GEANY_API_VERSION < 240
114+
ui_set_statusbar(TRUE,
115+
_("Workbench: project switching is not available. Your version of Geany is too old. "
116+
"At least version 1.36 is required to enable project switching."));
117+
#endif
118+
94119
return TRUE;
95120
}
96121

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

@@ -131,7 +159,7 @@ void geany_load_module(GeanyPlugin *plugin)
131159
/* Set metadata */
132160
plugin->info->name = _("Workbench");
133161
plugin->info->description = _("Manage and customize multiple projects.");
134-
plugin->info->version = "1.09";
162+
plugin->info->version = "1.10";
135163
plugin->info->author = "LarsGit223";
136164

137165
/* Set functions */

Diff for: workbench/src/popup_menu.c

+59
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#ifdef HAVE_CONFIG_H
3030
#include "config.h"
3131
#endif
32+
#include <project.h>
3233

3334
#include "wb_globals.h"
3435
#include "dialogs.h"
@@ -42,6 +43,7 @@ static struct
4243

4344
GtkWidget *add_project;
4445
GtkWidget *remove_project;
46+
GtkWidget *project_toggle_select;
4547
GtkWidget *fold_unfold_project;
4648
GtkWidget *project_open_all;
4749
GtkWidget *project_close_all;
@@ -81,6 +83,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
8183
case POPUP_CONTEXT_PROJECT:
8284
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
8385
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
86+
#if GEANY_API_VERSION >= 240
87+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
88+
#else
89+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
90+
#endif
8491
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
8592
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
8693
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
@@ -103,6 +110,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
103110
case POPUP_CONTEXT_DIRECTORY:
104111
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
105112
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
113+
#if GEANY_API_VERSION >= 240
114+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
115+
#else
116+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
117+
#endif
106118
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
107119
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
108120
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
@@ -125,6 +137,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
125137
case POPUP_CONTEXT_SUB_DIRECTORY:
126138
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
127139
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
140+
#if GEANY_API_VERSION >= 240
141+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
142+
#else
143+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
144+
#endif
128145
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
129146
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
130147
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
@@ -147,6 +164,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
147164
case POPUP_CONTEXT_FILE:
148165
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
149166
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
167+
#if GEANY_API_VERSION >= 240
168+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
169+
#else
170+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
171+
#endif
150172
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
151173
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
152174
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
@@ -169,6 +191,7 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
169191
case POPUP_CONTEXT_BACKGROUND:
170192
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
171193
gtk_widget_set_sensitive (s_popup_menu.remove_project, FALSE);
194+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
172195
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, FALSE);
173196
gtk_widget_set_sensitive (s_popup_menu.project_open_all, FALSE);
174197
gtk_widget_set_sensitive (s_popup_menu.project_close_all, FALSE);
@@ -191,6 +214,7 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
191214
case POPUP_CONTEXT_WB_BOOKMARK:
192215
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
193216
gtk_widget_set_sensitive (s_popup_menu.remove_project, FALSE);
217+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
194218
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, FALSE);
195219
gtk_widget_set_sensitive (s_popup_menu.project_open_all, FALSE);
196220
gtk_widget_set_sensitive (s_popup_menu.project_close_all, FALSE);
@@ -213,6 +237,11 @@ void popup_menu_show(POPUP_CONTEXT context, GdkEventButton *event)
213237
case POPUP_CONTEXT_PRJ_BOOKMARK:
214238
gtk_widget_set_sensitive (s_popup_menu.add_project, TRUE);
215239
gtk_widget_set_sensitive (s_popup_menu.remove_project, TRUE);
240+
#if GEANY_API_VERSION >= 240
241+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, TRUE);
242+
#else
243+
gtk_widget_set_sensitive (s_popup_menu.project_toggle_select, FALSE);
244+
#endif
216245
gtk_widget_set_sensitive (s_popup_menu.fold_unfold_project, TRUE);
217246
gtk_widget_set_sensitive (s_popup_menu.project_open_all, TRUE);
218247
gtk_widget_set_sensitive (s_popup_menu.project_close_all, TRUE);
@@ -317,6 +346,28 @@ static void popup_menu_on_remove_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_
317346
}
318347

319348

349+
/* Handle popup menu item "Select/Unselect project" */
350+
#if GEANY_API_VERSION >= 240
351+
static void popup_menu_on_toggle_selected_project(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
352+
{
353+
WB_PROJECT *project;
354+
355+
project = sidebar_file_view_get_selected_project(NULL);
356+
if (project != NULL && wb_globals.opened_wb != NULL)
357+
{
358+
if (workbench_get_selected_project(wb_globals.opened_wb) != project)
359+
{
360+
workbench_open_project(wb_globals.opened_wb, project, TRUE);
361+
}
362+
else
363+
{
364+
workbench_open_project(wb_globals.opened_wb, NULL, TRUE);
365+
}
366+
}
367+
}
368+
#endif
369+
370+
320371
/* Handle popup menu item "Expand all" */
321372
static void popup_menu_on_expand_all(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data)
322373
{
@@ -819,6 +870,14 @@ void popup_menu_init(void)
819870
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_remove_project), NULL);
820871
s_popup_menu.remove_project = item;
821872

873+
item = gtk_menu_item_new_with_mnemonic(_("_Select/Unselect project"));
874+
gtk_widget_show(item);
875+
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);
876+
#if GEANY_API_VERSION >= 240
877+
g_signal_connect(item, "activate", G_CALLBACK(popup_menu_on_toggle_selected_project), NULL);
878+
#endif
879+
s_popup_menu.project_toggle_select = item;
880+
822881
item = gtk_menu_item_new_with_mnemonic(_("_Fold/unfold project"));
823882
gtk_widget_show(item);
824883
gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item);

0 commit comments

Comments
 (0)