mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Added engine for handle own events.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
f5c77bcd36
commit
d9c20c3065
@ -564,6 +564,7 @@ src/mcconfig/Makefile
|
|||||||
src/search/Makefile
|
src/search/Makefile
|
||||||
src/tty/Makefile
|
src/tty/Makefile
|
||||||
src/viewer/Makefile
|
src/viewer/Makefile
|
||||||
|
src/event/Makefile
|
||||||
|
|
||||||
edit/Makefile
|
edit/Makefile
|
||||||
syntax/Makefile
|
syntax/Makefile
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = mcconfig search tty viewer filehighlight
|
SUBDIRS = mcconfig search tty viewer filehighlight event
|
||||||
|
|
||||||
AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS)
|
AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS)
|
||||||
|
|
||||||
@ -43,10 +43,11 @@ MCCONFIGLIB = mcconfig/libmcconfig.la
|
|||||||
SEARCHLIB = search/libsearch.la
|
SEARCHLIB = search/libsearch.la
|
||||||
TTYLIB = tty/libmctty.la
|
TTYLIB = tty/libmctty.la
|
||||||
VIEWERLIB = viewer/libmcviewer.la
|
VIEWERLIB = viewer/libmcviewer.la
|
||||||
|
EVENTLIB = event/libmcevent.la
|
||||||
FILEHIGHLIGHTLIB=filehighlight/libmcfilehighlight.la
|
FILEHIGHLIGHTLIB=filehighlight/libmcfilehighlight.la
|
||||||
|
|
||||||
mc_LDADD = $(EDITLIB) $(VFSLIB) $(FILEHIGHLIGHTLIB) \
|
mc_LDADD = $(EDITLIB) $(VFSLIB) $(FILEHIGHLIGHTLIB) \
|
||||||
$(MCCONFIGLIB) $(SEARCHLIB) $(TTYLIB) $(VIEWERLIB) \
|
$(MCCONFIGLIB) $(SEARCHLIB) $(TTYLIB) $(VIEWERLIB) $(EVENTLIB)\
|
||||||
$(INTLLIBS) $(MCLIBS) $(SLANGLIB) $(LIBICONV) $(GLIB_LIBS)
|
$(INTLLIBS) $(MCLIBS) $(SLANGLIB) $(LIBICONV) $(GLIB_LIBS)
|
||||||
|
|
||||||
CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h
|
CHARSET_SRC = charsets.c charsets.h selcodepage.c selcodepage.h
|
||||||
|
13
src/event/Makefile.am
Normal file
13
src/event/Makefile.am
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
noinst_LTLIBRARIES = libmcevent.la
|
||||||
|
|
||||||
|
libmcevent_la_SOURCES = \
|
||||||
|
callback.c \
|
||||||
|
event.h \
|
||||||
|
event.c \
|
||||||
|
internal.h
|
||||||
|
|
||||||
|
libmcevent_la_CFLAGS=-I../ -I$(top_srcdir)/src \
|
||||||
|
$(GLIB_CFLAGS) \
|
||||||
|
-DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\"
|
||||||
|
|
79
src/event/callback.c
Normal file
79
src/event/callback.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Handle any events in application.
|
||||||
|
Interface functions: callbacks handle
|
||||||
|
|
||||||
|
Copyright (C) 2009 The Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by:
|
||||||
|
Slava Zanko <slavazanko@gmail.com>, 2009.
|
||||||
|
|
||||||
|
This file is part of the Midnight Commander.
|
||||||
|
|
||||||
|
The Midnight Commander 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.
|
||||||
|
|
||||||
|
The Midnight Commander 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "event.h"
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mcevent_add_cb(const gchar *event_name , mcevent_callback_func event_callback, gpointer some_callback_data)
|
||||||
|
{
|
||||||
|
mcevent_t *event;
|
||||||
|
|
||||||
|
if (mcevent_hashlist == NULL || event_name == NULL || event_callback == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
event = g_new0(mcevent_t, 1);
|
||||||
|
if (event == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
event->name = g_strdup(event_name);
|
||||||
|
event->cb = event_callback;
|
||||||
|
event->data = some_callback_data;
|
||||||
|
|
||||||
|
if (mcevent_get_handler(event_name) != NULL)
|
||||||
|
mcevent_del_cb(event_name);
|
||||||
|
|
||||||
|
g_hash_table_insert (mcevent_hashlist, (gpointer) event_name, (gpointer) event);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mcevent_del_cb(const gchar *event_name)
|
||||||
|
{
|
||||||
|
if (mcevent_hashlist == NULL || event_name == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return g_hash_table_remove (mcevent_hashlist, (gpointer) event_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
140
src/event/event.c
Normal file
140
src/event/event.c
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
Handle any events in application.
|
||||||
|
Interface functions: init/deinit; start/stop
|
||||||
|
|
||||||
|
Copyright (C) 2009 The Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Written by:
|
||||||
|
Slava Zanko <slavazanko@gmail.com>, 2009.
|
||||||
|
|
||||||
|
This file is part of the Midnight Commander.
|
||||||
|
|
||||||
|
The Midnight Commander 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.
|
||||||
|
|
||||||
|
The Midnight Commander 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "event.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
GHashTable *mcevent_hashlist = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
mcevent_hash_destroy_key (gpointer data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
mcevent_hash_destroy_value (gpointer data)
|
||||||
|
{
|
||||||
|
mcevent_t *event = (mcevent_t *) data;
|
||||||
|
g_free(event->name);
|
||||||
|
g_free (event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
gboolean mcevent_init(void)
|
||||||
|
{
|
||||||
|
mcevent_hashlist =
|
||||||
|
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
mcevent_hash_destroy_key,
|
||||||
|
mcevent_hash_destroy_value);
|
||||||
|
if (mcevent_hashlist == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void mcevent_deinit(void)
|
||||||
|
{
|
||||||
|
if (mcevent_hashlist == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_hash_table_destroy (mcevent_hashlist);
|
||||||
|
mcevent_hashlist = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void mcevent_run(void)
|
||||||
|
{
|
||||||
|
/* start GMainLoop */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void mcevent_stop(void)
|
||||||
|
{
|
||||||
|
/* stop GMainLoop */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
GList *
|
||||||
|
mcevent_get_list (void)
|
||||||
|
{
|
||||||
|
if (mcevent_hashlist == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return g_hash_table_get_keys (mcevent_hashlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
mcevent_t *
|
||||||
|
mcevent_get_handler(const gchar *event_name)
|
||||||
|
{
|
||||||
|
if (event_name == NULL || mcevent_hashlist == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return (mcevent_t *) g_hash_table_lookup (mcevent_hashlist, (gpointer) event_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
gboolean mcevent_raise(const gchar *event_name, gpointer event_data)
|
||||||
|
{
|
||||||
|
mcevent_t *event = mcevent_get_handler(event_name);
|
||||||
|
|
||||||
|
if (event == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return (*event->cb) (event, event_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
48
src/event/event.h
Normal file
48
src/event/event.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef MC__EVENT_H
|
||||||
|
#define MC__EVENT_H
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "../src/global.h" /* <glib.h> */
|
||||||
|
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
struct mcevent_struct;
|
||||||
|
|
||||||
|
|
||||||
|
typedef gboolean (*mcevent_callback_func) (struct mcevent_struct *, gpointer);
|
||||||
|
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
typedef struct mcevent_struct
|
||||||
|
{
|
||||||
|
gchar *name;
|
||||||
|
mcevent_callback_func cb;
|
||||||
|
gpointer data;
|
||||||
|
} mcevent_t;
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/* event.c: */
|
||||||
|
gboolean mcevent_init(void);
|
||||||
|
void mcevent_deinit(void);
|
||||||
|
void mcevent_run(void);
|
||||||
|
void mcevent_stop(void);
|
||||||
|
|
||||||
|
GList *mcevent_get_list (void);
|
||||||
|
mcevent_t *mcevent_get_handler(const gchar *);
|
||||||
|
gboolean mcevent_raise(const gchar *, gpointer);
|
||||||
|
|
||||||
|
|
||||||
|
/* callback.c: */
|
||||||
|
gboolean mcevent_add_cb(const gchar *, mcevent_callback_func, gpointer);
|
||||||
|
gboolean mcevent_del_cb(const gchar *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
16
src/event/internal.h
Normal file
16
src/event/internal.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef MC_EVENT_INTERNAL_H
|
||||||
|
#define MC_EVENT_INTERNAL_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants ********************/
|
||||||
|
|
||||||
|
/*** enums *************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)***************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *******************************/
|
||||||
|
|
||||||
|
extern GHashTable *mcevent_hashlist;
|
||||||
|
|
||||||
|
/*** declarations of public functions **********************************/
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user