Skip to content
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

workbench: support live update. Closes #659. #695

Merged
merged 1 commit into from
Mar 4, 2018
Merged
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
31 changes: 29 additions & 2 deletions workbench/README
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ related settings is done using the context menu on the sidebar. Some
items in the context menu will only be active if you right click inside
a project, directory or bookmark.

The Workbench context menu:
---------------------------
The Workbench context menu
--------------------------

These are the available items:

Expand Down Expand Up @@ -141,6 +141,33 @@ These are the available items:
Select this item to create a new directory at the current selected position
in the file tree. Available since version 1.02 of the workbench plugin.

The Workbench settings
----------------------
The following settings exist for a workbench:

**Rescan all projects on open**
If the option is activated (default), then all projects will be re-scanned
on opening of a workbench.

**Enable live update**
If the option is activated (default), then the list of files and the sidebar
will be updated automatically if a file or directory is created, removed or renamed.
A manual re-scan is not required if the option is enabled. This feature is available
since version 1.03 of the workbench plugin. If you open a workbench file
which has been created with an older version of the workbench plugin
then the option will be added with value "activated".

Live update
-----------
From version 1.03 on the workbench plugin supports an automatic live update
of the file list and the sidebar.

This feature will only work if your system supports directory file monitoring.
If the workbench plugin cannot setup file monitoring for a directory then it
will output a message in the message window. The message has the following form::

Could not setup file monitoring for directory: "exampledir". Error: <some error message>

Known issues
============

Expand Down
2 changes: 2 additions & 0 deletions workbench/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ workbench_la_SOURCES = \
workbench.c \
wb_project.h \
wb_project.c \
wb_monitor.h \
wb_monitor.c \
dialogs.h \
dialogs.c \
menu.h \
Expand Down
18 changes: 17 additions & 1 deletion workbench/src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,12 @@ gboolean dialogs_directory_settings(WB_PROJECT_DIR *directory)
gboolean dialogs_workbench_settings(WORKBENCH *workbench)
{
gint result;
GtkWidget *w_rescan_projects_on_open;
GtkWidget *w_rescan_projects_on_open, *w_enable_live_update;
GtkWidget *dialog, *content_area;
GtkWidget *vbox, *hbox, *table;
GtkDialogFlags flags;
gboolean changed, rescan_projects_on_open, rescan_projects_on_open_old;
gboolean enable_live_update, enable_live_update_old;

/* Create the widgets */
flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
Expand All @@ -437,6 +438,15 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
rescan_projects_on_open_old = workbench_get_rescan_projects_on_open(workbench);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_rescan_projects_on_open), rescan_projects_on_open_old);

w_enable_live_update = gtk_check_button_new_with_mnemonic(_("_Enable live update"));
ui_table_add_row(GTK_TABLE(table), 1, w_enable_live_update, NULL);
gtk_widget_set_tooltip_text(w_enable_live_update,
_("If the option is activated (default), then the list of files and the sidebar"
" will be updated automatically if a file or directory is created, removed or renamed."
"A manual re-scan is not required if the option is enabled."));
enable_live_update_old = workbench_get_enable_live_update(workbench);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w_enable_live_update), enable_live_update_old);

gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 6);

hbox = gtk_hbox_new(FALSE, 0);
Expand All @@ -456,6 +466,12 @@ gboolean dialogs_workbench_settings(WORKBENCH *workbench)
changed = TRUE;
workbench_set_rescan_projects_on_open(workbench, rescan_projects_on_open);
}
enable_live_update = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w_enable_live_update));
if (enable_live_update != enable_live_update_old)
{
changed = TRUE;
workbench_set_enable_live_update(workbench, enable_live_update);
}
}

gtk_widget_destroy(dialog);
Expand Down
18 changes: 18 additions & 0 deletions workbench/src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,27 @@ static void item_workbench_settings_activate_cb(G_GNUC_UNUSED GtkMenuItem *menui
{
if (wb_globals.opened_wb != NULL)
{
gboolean enable_live_update_old, enable_live_update;

enable_live_update_old = workbench_get_enable_live_update(wb_globals.opened_wb);
if (dialogs_workbench_settings(wb_globals.opened_wb))
{
sidebar_update(SIDEBAR_CONTEXT_WB_SETTINGS_CHANGED, NULL);

enable_live_update = workbench_get_enable_live_update(wb_globals.opened_wb);
if (enable_live_update != enable_live_update_old)
{
if (enable_live_update == TRUE)
{
/* Start/create all file monitors. */
workbench_enable_live_update(wb_globals.opened_wb);
}
else
{
/* Stop/free all file monitors. */
workbench_disable_live_update(wb_globals.opened_wb);
}
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions workbench/src/plugin_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static void plugin_workbench_on_doc_open(G_GNUC_UNUSED GObject * obj, G_GNUC_UNU
project = workbench_file_is_included(wb_globals.opened_wb, doc->file_name);
if (project != NULL)
{
wb_project_remove_single_tm_file(project, doc->file_name);
wb_project_add_idle_action(WB_PROJECT_IDLE_ACTION_ID_REMOVE_SINGLE_TM_FILE,
project, g_strdup(doc->file_name));
}
}

Expand All @@ -69,7 +70,8 @@ static void plugin_workbench_on_doc_close(G_GNUC_UNUSED GObject * obj, GeanyDocu
project = workbench_file_is_included(wb_globals.opened_wb, doc->file_name);
if (project != NULL)
{
wb_project_add_single_tm_file(project, doc->file_name);
wb_project_add_idle_action(WB_PROJECT_IDLE_ACTION_ID_ADD_SINGLE_TM_FILE,
project, g_strdup(doc->file_name));
}
}

Expand Down Expand Up @@ -128,7 +130,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.02";
plugin->info->version = "1.03";
plugin->info->author = "LarsGit223";

/* Set functions */
Expand Down
20 changes: 16 additions & 4 deletions workbench/src/popup_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,15 @@ static void popup_menu_on_new_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_U
else
{
fclose(new_file);
wb_project_dir_rescan(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_RESCANNED, &context);

if (workbench_get_enable_live_update(wb_globals.opened_wb) == FALSE)
{
/* Live update is disabled. We need to update the file list and
the sidebar manually. */
wb_project_dir_rescan(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_RESCANNED, &context);
}

document_open_file(filename, FALSE, NULL, NULL);
}
}
Expand Down Expand Up @@ -595,8 +602,13 @@ static void popup_menu_on_new_directory(G_GNUC_UNUSED GtkMenuItem *menuitem, G_G
filename = dialogs_create_new_directory(abs_path);
if (filename != NULL)
{
wb_project_dir_rescan(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_RESCANNED, &context);
if (workbench_get_enable_live_update(wb_globals.opened_wb) == FALSE)
{
/* Live update is disabled. We need to update the file list and
the sidebar manually. */
wb_project_dir_rescan(context.project, context.directory);
sidebar_update(SIDEBAR_CONTEXT_DIRECTORY_RESCANNED, &context);
}
}

g_free(abs_path);
Expand Down
Loading