Use events for calling help window

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-02-17 14:02:31 +02:00
parent 62207c8d4d
commit 5f8a5e4290
11 changed files with 82 additions and 35 deletions

View File

@ -41,6 +41,13 @@ typedef struct
gboolean ret;
} ev_clipboard_text_from_file_t;
/* MCEVENT_GROUP_CORE:help */
typedef struct
{
const char *filename;
const char *node;
} ev_help_t;
/*** global variables defined in .c file *********************************************************/

View File

@ -37,6 +37,7 @@
#include "lib/tty/key.h"
#include "lib/strutil.h"
#include "lib/widget.h"
#include "lib/event.h" /* mc_event_raise() */
/* TODO: these includes should be removed! */
#include "src/help.h" /* interactive_display() */
@ -266,8 +267,11 @@ dlg_execute_cmd (Dlg_head * h, unsigned long command)
break;
case CK_Help:
interactive_display (NULL, h->help_ctx);
do_refresh ();
{
ev_help_t event_data = { NULL, h->help_ctx };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
do_refresh ();
}
break;
case CK_Suspend:

View File

@ -34,6 +34,7 @@
#include "lib/tty/key.h" /* key macros */
#include "lib/strutil.h"
#include "lib/widget.h"
#include "lib/event.h" /* mc_event_raise() */
/* TODO: these includes should be removed! */
#include "src/keybind-defaults.h" /* CK_IgnoreKey */
@ -422,15 +423,19 @@ menubar_handle_key (WMenuBar * menubar, int key)
switch (key)
{
case KEY_F (1):
if (menubar->is_dropped)
interactive_display (NULL,
((Menu *) g_list_nth_data (menubar->menu,
menubar->selected))->help_node);
else
interactive_display (NULL, "[Menu Bar]");
menubar_draw (menubar);
return 1;
{
ev_help_t event_data = { NULL, NULL };
if (menubar->is_dropped)
event_data.node =
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->help_node;
else
event_data.node = "[Menu Bar]";
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
menubar_draw (menubar);
return 1;
}
case KEY_LEFT:
case XCTRL ('b'):
menubar_left (menubar);

View File

@ -42,13 +42,13 @@
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/charsets.h"
#include "lib/event.h" /* mc_event_raise() */
#include "src/filemanager/cmd.h"
#include "src/filemanager/midnight.h" /* Needed for current_panel and other_panel */
#include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */
#include "src/keybind-defaults.h"
#include "src/help.h"
#include "src/history.h"
#include "src/selcodepage.h"
@ -118,7 +118,9 @@ dview_set_codeset (WDiff * dview)
const char *encoding_id = NULL;
dview->utf8 = TRUE;
encoding_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage);
encoding_id =
get_codepage_id (mc_global.source_codepage >=
0 ? mc_global.source_codepage : mc_global.display_codepage);
if (encoding_id != NULL)
{
GIConv conv;
@ -2980,7 +2982,10 @@ dview_execute_cmd (WDiff * dview, unsigned long command)
switch (command)
{
case CK_Help:
interactive_display (NULL, "[Diff Viewer]");
{
ev_help_t event_data = { NULL, "[Diff Viewer]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
break;
case CK_ShowSymbols:
dview->display_symbols ^= 1;

View File

@ -60,7 +60,6 @@
#include "src/history.h"
#include "src/setup.h" /* option_tab_spacing */
#include "src/help.h" /* interactive_display() */
#include "src/selcodepage.h"
#include "src/keybind-defaults.h"
#include "src/util.h" /* check_for_default() */
@ -1146,7 +1145,9 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len,
void
edit_help_cmd (WEdit * edit)
{
interactive_display (NULL, "[Internal File Editor]");
ev_help_t event_data = { NULL, "[Internal File Editor]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
edit->force |= REDRAW_COMPLETELY;
}

View File

@ -28,6 +28,7 @@
#include "lib/event.h"
#include "clipboard.h" /* clipboard events */
#include "help.h" /* help_interactive_display() */
#include "events_init.h"
@ -58,6 +59,8 @@ events_init (GError ** error)
{MCEVENT_GROUP_CORE, "clipboard_text_to_file", clipboard_text_to_file, NULL},
{MCEVENT_GROUP_CORE, "clipboard_text_from_file", clipboard_text_from_file, NULL},
{MCEVENT_GROUP_CORE, "help", help_interactive_display, NULL},
{NULL, NULL, NULL, NULL}
};
/* *INDENT-ON* */

View File

@ -59,9 +59,9 @@
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/keybind.h" /* CK_Down, CK_History */
#include "lib/event.h" /* mc_event_raise() */
#include "src/viewer/mcviewer.h"
#include "src/help.h" /* interactive_display() */
#include "src/setup.h"
#include "src/execute.h" /* toggle_panels() */
#include "src/history.h"
@ -1322,10 +1322,14 @@ edit_symlink_cmd (void)
void
help_cmd (void)
{
ev_help_t event_data = { NULL, NULL };
if (current_panel->searching)
interactive_display (NULL, "[Quick search]");
event_data.node = "[Quick search]";
else
interactive_display (NULL, "[main]");
event_data.node = "[main]";
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -50,11 +50,12 @@
#include "lib/strutil.h"
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/event.h" /* mc_event_raise() */
#include "src/setup.h" /* confirm_delete, panels_options */
#include "src/keybind-defaults.h"
#include "src/history.h"
#include "src/help.h"
#include "dir.h"
#include "midnight.h" /* the_menubar */
@ -1022,7 +1023,10 @@ tree_execute_cmd (WTree * tree, unsigned long command)
switch (command)
{
case CK_Help:
interactive_display (NULL, "[Directory Tree]");
{
ev_help_t event_data = { NULL, "[Directory Tree]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
break;
case CK_Forget:
tree_forget (tree);

View File

@ -60,6 +60,7 @@
#include "lib/fileloc.h"
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/event-types.h"
#include "keybind-defaults.h"
#include "keybind-defaults.h"
@ -1028,8 +1029,10 @@ mousedispatch_new (int y, int x, int yl, int xl)
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
interactive_display (const char *filename, const char *node)
/* event callback */
gboolean
help_interactive_display (const gchar * event_group_name, const gchar * event_name,
gpointer init_data, gpointer data)
{
const dlg_colors_t help_colors = {
HELP_NORMAL_COLOR, /* common text color */
@ -1043,43 +1046,48 @@ interactive_display (const char *filename, const char *node)
Widget *md;
char *hlpfile = NULL;
char *filedata;
ev_help_t *event_data = (ev_help_t *) data;
if (filename != NULL)
g_file_get_contents (filename, &filedata, NULL, NULL);
(void) event_group_name;
(void) event_name;
(void) init_data;
if (event_data->filename != NULL)
g_file_get_contents (event_data->filename, &filedata, NULL, NULL);
else
filedata = load_mc_home_file (mc_global.share_data_dir, MC_HELP, &hlpfile);
if (filedata == NULL)
message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"),
filename ? filename : hlpfile, unix_error_string (errno));
event_data->filename ? event_data->filename : hlpfile, unix_error_string (errno));
g_free (hlpfile);
if (filedata == NULL)
return;
return TRUE;
translate_file (filedata);
g_free (filedata);
if (fdata == NULL)
return;
return TRUE;
if ((node == NULL) || (*node == '\0'))
node = "[main]";
if ((event_data->node == NULL) || (*event_data->node == '\0'))
event_data->node = "[main]";
main_node = search_string (fdata, node);
main_node = search_string (fdata, event_data->node);
if (main_node == NULL)
{
message (D_ERROR, MSG_ERROR, _("Cannot find node %s in help file"), node);
message (D_ERROR, MSG_ERROR, _("Cannot find node %s in help file"), event_data->node);
/* Fallback to [main], return if it also cannot be found */
main_node = search_string (fdata, "[main]");
if (main_node == NULL)
{
interactive_display_finish ();
return;
return TRUE;
}
}
@ -1123,6 +1131,7 @@ interactive_display (const char *filename, const char *node)
run_dlg (whelp);
interactive_display_finish ();
destroy_dlg (whelp);
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -50,7 +50,8 @@
/*** declarations of public functions ************************************************************/
void interactive_display (const char *filename, const char *node);
gboolean help_interactive_display (const gchar * event_group_name, const gchar * event_name,
gpointer init_data, gpointer data);
/*** inline functions ****************************************************************************/
#endif /* MC__HELP_H */

View File

@ -57,6 +57,7 @@
#include "lib/util.h"
#include "lib/widget.h"
#include "lib/charsets.h"
#include "lib/event.h" /* mc_event_raise() */
#include "src/filemanager/layout.h"
#include "src/filemanager/cmd.h"
@ -64,7 +65,6 @@
#include "src/history.h"
#include "src/execute.h"
#include "src/help.h"
#include "src/keybind-defaults.h"
#include "internal.h"
@ -249,7 +249,11 @@ mcview_execute_cmd (mcview_t * view, unsigned long command)
switch (command)
{
case CK_Help:
interactive_display (NULL, "[Internal File Viewer]");
{
ev_help_t event_data = { NULL, "[Internal File Viewer]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
do_refresh ();
}
break;
case CK_WrapMode:
/* Toggle between wrapped and unwrapped view */