Skip to content

Commit

Permalink
Merge pull request #867 from LarsGit223/wb-tm-control
Browse files Browse the repository at this point in the history
workbench: revised tag-manager control/usage
  • Loading branch information
frlan committed Jun 2, 2019
2 parents 51d8292 + a4e68e6 commit cf96581
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 331 deletions.
6 changes: 5 additions & 1 deletion workbench/src/Makefile.am
Expand Up @@ -22,7 +22,11 @@ workbench_la_SOURCES = \
sidebar.h \
sidebar.c \
utils.h \
utils.c
utils.c \
idle_queue.h \
idle_queue.c \
tm_control.h \
tm_control.c

workbench_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DG_LOG_DOMAIN=\"Workbench\"
Expand Down
134 changes: 134 additions & 0 deletions workbench/src/idle_queue.c
@@ -0,0 +1,134 @@
/*
* Copyright 2019 LarsGit223
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*
* Code for the Workbench idle queue.
*/
#include <glib/gstdio.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <geanyplugin.h>
#include "wb_globals.h"
#include "idle_queue.h"
#include "tm_control.h"

extern GeanyData *geany_data;

typedef struct
{
WB_IDLE_QUEUE_ACTION_ID id;
gpointer param_a;
}WB_IDLE_QUEUE_ACTION;

static GSList *s_idle_actions = NULL;


/* Clear idle queue */
static void wb_idle_queue_clear(void)
{
if (s_idle_actions == NULL)
{
return;
}

g_slist_free_full(s_idle_actions, g_free);
s_idle_actions = NULL;
}


/* On-idle callback function. */
static gboolean wb_idle_queue_callback(gpointer foo)
{
static gboolean first = TRUE;
GSList *elem = NULL;
WB_IDLE_QUEUE_ACTION *action;
static GMutex mutex;

if (first == TRUE)
{
first = FALSE;
g_mutex_init (&mutex);
}

g_mutex_lock(&mutex);

foreach_slist (elem, s_idle_actions)
{
action = elem->data;
switch (action->id)
{
case WB_IDLE_ACTION_ID_TM_SOURCE_FILES_NEW:
wb_tm_control_source_files_new(action->param_a);
break;

case WB_IDLE_ACTION_ID_TM_SOURCE_FILE_ADD:
wb_tm_control_source_file_add(action->param_a);
break;

case WB_IDLE_ACTION_ID_TM_SOURCE_FILE_REMOVE:
wb_tm_control_source_file_remove(action->param_a);
break;

case WB_IDLE_ACTION_ID_TM_SOURCE_FILE_FREE:
wb_tm_control_source_file_free(action->param_a);
break;

case WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE:
wb_tm_control_source_files_remove(action->param_a);
break;
}
}

wb_idle_queue_clear();

g_mutex_unlock(&mutex);

return FALSE;
}


/** Add a new idle action to the list.
*
* The function allocates a new WB_IDLE_QUEUE_ACTION structure and fills
* in the values passed. On-idle Geany will then call wb_idle_queue_callback
* and that function will call the function related to the action ID
* and pass the relevant parameters to it.
*
* @param id The action to execute on-idle
* @param param_a Parameter A
* @param param_a Parameter B
*
**/
void wb_idle_queue_add_action(WB_IDLE_QUEUE_ACTION_ID id, gpointer param_a)
{
WB_IDLE_QUEUE_ACTION *action;

action = g_new0(WB_IDLE_QUEUE_ACTION, 1);
action->id = id;
action->param_a = param_a;

if (s_idle_actions == NULL)
{
plugin_idle_add(wb_globals.geany_plugin, (GSourceFunc)wb_idle_queue_callback, NULL);
}

s_idle_actions = g_slist_prepend(s_idle_actions, action);
}
33 changes: 33 additions & 0 deletions workbench/src/idle_queue.h
@@ -0,0 +1,33 @@
/*
* Copyright 2019 LarsGit223
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef __WB_IDLE_QUEUE_H__
#define __WB_IDLE_QUEUE_H__

typedef enum
{
WB_IDLE_ACTION_ID_TM_SOURCE_FILE_ADD,
WB_IDLE_ACTION_ID_TM_SOURCE_FILE_REMOVE,
WB_IDLE_ACTION_ID_TM_SOURCE_FILE_FREE,
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_NEW,
WB_IDLE_ACTION_ID_TM_SOURCE_FILES_REMOVE,
}WB_IDLE_QUEUE_ACTION_ID;

void wb_idle_queue_add_action(WB_IDLE_QUEUE_ACTION_ID id, gpointer param_a);

#endif
31 changes: 9 additions & 22 deletions workbench/src/plugin_main.c
Expand Up @@ -31,6 +31,8 @@
#include "sidebar.h"
#include "menu.h"
#include "popup_menu.h"
#include "idle_queue.h"
#include "tm_control.h"

GeanyPlugin *geany_plugin;
GeanyData *geany_data;
Expand All @@ -39,40 +41,23 @@ GeanyData *geany_data;
static void plugin_workbench_on_doc_open(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED GeanyDocument * doc,
G_GNUC_UNUSED gpointer user_data)
{
WB_PROJECT *project;

g_return_if_fail(doc != NULL && doc->file_name != NULL);

project = workbench_file_is_included(wb_globals.opened_wb, doc->file_name);
if (project != NULL)
{
wb_project_add_idle_action(WB_PROJECT_IDLE_ACTION_ID_REMOVE_SINGLE_TM_FILE,
project, g_strdup(doc->file_name));
}
wb_idle_queue_add_action(WB_IDLE_ACTION_ID_TM_SOURCE_FILE_REMOVE,
g_strdup(doc->file_name));
}


/* Callback function for document close */
static void plugin_workbench_on_doc_close(G_GNUC_UNUSED GObject * obj, GeanyDocument * doc,
G_GNUC_UNUSED gpointer user_data)
{
WB_PROJECT *project;

g_return_if_fail(doc != NULL);

if (doc->file_name == NULL)
{
return;
}
g_return_if_fail(doc != NULL && doc->file_name != NULL);

/* tags of open files managed by geany - when the file gets closed,
* we should take care of it */
project = workbench_file_is_included(wb_globals.opened_wb, doc->file_name);
if (project != NULL)
{
wb_project_add_idle_action(WB_PROJECT_IDLE_ACTION_ID_ADD_SINGLE_TM_FILE,
project, g_strdup(doc->file_name));
}
wb_idle_queue_add_action(WB_IDLE_ACTION_ID_TM_SOURCE_FILE_ADD,
g_strdup(doc->file_name));
}


Expand All @@ -88,6 +73,7 @@ static gboolean plugin_workbench_init(GeanyPlugin *plugin, G_GNUC_UNUSED gpointe
menu_init();
sidebar_init();
popup_menu_init();
wb_tm_control_init();

/* At start there is no workbench open:
deactive save and close menu item and sidebar */
Expand All @@ -103,6 +89,7 @@ static void plugin_workbench_cleanup(G_GNUC_UNUSED GeanyPlugin *plugin, G_GNUC_U
{
menu_cleanup();
sidebar_cleanup();
wb_tm_control_cleanup();
}


Expand Down

0 comments on commit cf96581

Please sign in to comment.