Handle CK_Help, CK_Quit and CK_About actions in dialog level instead of widget one.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2011-07-22 13:59:28 +04:00
parent b50f4f07e5
commit 98e0de0c3a
6 changed files with 85 additions and 74 deletions

View File

@ -300,7 +300,7 @@ Replace = f4
ReplaceContinue = f14 ReplaceContinue = f14
Complete = alt-tab Complete = alt-tab
InsertFile = f15 InsertFile = f15
Quit = f10 Quit = f10, esc
InsertOverwrite = insert InsertOverwrite = insert
Help = f1 Help = f1
Date = Date =

View File

@ -300,7 +300,7 @@ Replace = f4
ReplaceContinue = f14 ReplaceContinue = f14
Complete = alt-tab Complete = alt-tab
InsertFile = f15 InsertFile = f15
Quit = f10 Quit = f10, esc
InsertOverwrite = insert InsertOverwrite = insert
Help = f1 Help = f1
Date = Date =

View File

@ -269,7 +269,6 @@ void edit_move_display (WEdit * e, long line);
void edit_word_wrap (WEdit * edit); void edit_word_wrap (WEdit * edit);
int edit_sort_cmd (WEdit * edit); int edit_sort_cmd (WEdit * edit);
int edit_ext_cmd (WEdit * edit); int edit_ext_cmd (WEdit * edit);
void edit_help_cmd (WEdit * edit);
int edit_store_macro_cmd (WEdit * edit); int edit_store_macro_cmd (WEdit * edit);
gboolean edit_load_macro_cmd (WEdit * edit); gboolean edit_load_macro_cmd (WEdit * edit);

View File

@ -171,56 +171,6 @@ static long last_bracket = -1;
static int left_of_four_spaces (WEdit * edit); static int left_of_four_spaces (WEdit * edit);
/* --------------------------------------------------------------------------------------------- */
static void
edit_about (void)
{
const char *header = N_("About");
const char *button_name = N_("&OK");
const char *const version = "MCEdit " VERSION;
char text[BUF_LARGE];
int win_len, version_len, button_len;
int cols, lines;
Dlg_head *about_dlg;
#ifdef ENABLE_NLS
header = _(header);
button_name = _(button_name);
#endif
button_len = str_term_width1 (button_name) + 5;
version_len = str_term_width1 (version);
g_snprintf (text, sizeof (text),
_("Copyright (C) 1996-2010 the Free Software Foundation\n\n"
" A user friendly text editor\n"
" written for the Midnight Commander"));
win_len = str_term_width1 (header);
win_len = max (win_len, version_len);
win_len = max (win_len, button_len);
/* count width and height of text */
str_msg_term_size (text, &lines, &cols);
lines += 9;
cols = max (win_len, cols) + 6;
/* dialog */
about_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
"[Internal File Editor]", header, DLG_CENTER | DLG_TRYUP);
add_widget (about_dlg, label_new (3, (cols - version_len) / 2, version));
add_widget (about_dlg, label_new (5, 3, text));
add_widget (about_dlg, button_new (lines - 3, (cols - button_len) / 2,
B_ENTER, NORMAL_BUTTON, button_name, NULL));
run_dlg (about_dlg);
destroy_dlg (about_dlg);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Initialize the buffers for an empty files. * Initialize the buffers for an empty files.
@ -3514,7 +3464,14 @@ edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_inse
void void
edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
{ {
/* at first, handle window state */ /* at first, handle CK_Quit command */
if (command == CK_Quit)
{
dlg_stop (((Widget *) edit)->owner);
return;
}
/* handle window state */
if (edit_handle_move_resize (edit, command)) if (edit_handle_move_resize (edit, command))
return; return;
@ -4168,18 +4125,12 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
case CK_EditNew: case CK_EditNew:
edit_new_cmd (edit); edit_new_cmd (edit);
break; break;
case CK_Help:
edit_help_cmd (edit);
break;
case CK_Refresh: case CK_Refresh:
edit_refresh_cmd (edit); edit_refresh_cmd (edit);
break; break;
case CK_SaveSetup: case CK_SaveSetup:
save_setup_cmd (); save_setup_cmd ();
break; break;
case CK_About:
edit_about ();
break;
case CK_LearnKeys: case CK_LearnKeys:
learn_keys (); learn_keys ();
break; break;

View File

@ -1541,17 +1541,6 @@ edit_delete_macro (WEdit * edit, int hotkey)
/*** public functions ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void
edit_help_cmd (WEdit * edit)
{
ev_help_t event_data = { NULL, "[Internal File Editor]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
edit->force |= REDRAW_COMPLETELY;
}
/* --------------------------------------------------------------------------------------------- */
void void
edit_refresh_cmd (WEdit * edit) edit_refresh_cmd (WEdit * edit)
{ {

View File

@ -52,6 +52,7 @@
#include "lib/util.h" /* mc_build_filename() */ #include "lib/util.h" /* mc_build_filename() */
#include "lib/widget.h" #include "lib/widget.h"
#include "lib/mcconfig.h" #include "lib/mcconfig.h"
#include "lib/event.h" /* mc_event_raise() */
#include "src/keybind-defaults.h" #include "src/keybind-defaults.h"
#include "src/main.h" /* home_dir */ #include "src/main.h" /* home_dir */
@ -74,6 +75,71 @@
static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm); static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm);
/* --------------------------------------------------------------------------------------------- */
/**
* Show info about editor
*/
static void
edit_about (void)
{
const char *header = N_("About");
const char *button_name = N_("&OK");
const char *const version = "MCEdit " VERSION;
char text[BUF_LARGE];
int win_len, version_len, button_len;
int cols, lines;
Dlg_head *about_dlg;
#ifdef ENABLE_NLS
header = _(header);
button_name = _(button_name);
#endif
button_len = str_term_width1 (button_name) + 5;
version_len = str_term_width1 (version);
g_snprintf (text, sizeof (text),
_("Copyright (C) 1996-2012 the Free Software Foundation\n\n"
" A user friendly text editor\n"
" written for the Midnight Commander"));
win_len = str_term_width1 (header);
win_len = max (win_len, version_len);
win_len = max (win_len, button_len);
/* count width and height of text */
str_msg_term_size (text, &lines, &cols);
lines += 9;
cols = max (win_len, cols) + 6;
/* dialog */
about_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
"[Internal File Editor]", header, DLG_CENTER | DLG_TRYUP);
add_widget (about_dlg, label_new (3, (cols - version_len) / 2, version));
add_widget (about_dlg, label_new (5, 3, text));
add_widget (about_dlg, button_new (lines - 3, (cols - button_len) / 2,
B_ENTER, NORMAL_BUTTON, button_name, NULL));
run_dlg (about_dlg);
destroy_dlg (about_dlg);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Show a help window
*/
static void
edit_help (void)
{
ev_help_t event_data = { NULL, "[Internal File Editor]" };
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Restore saved window size. * Restore saved window size.
@ -414,6 +480,10 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
switch (command) switch (command)
{ {
case CK_Help:
edit_help ();
/* edit->force |= REDRAW_COMPLETELY; */
break;
case CK_Menu: case CK_Menu:
edit_menu_cmd (h); edit_menu_cmd (h);
break; break;
@ -428,12 +498,14 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
edit_restore_size ((WEdit *) w); edit_restore_size ((WEdit *) w);
} }
break; break;
case CK_About:
edit_about ();
break;
case CK_WindowMove: case CK_WindowMove:
case CK_WindowResize: case CK_WindowResize:
if (edit_widget_is_editor ((Widget *) h->current->data)) if (edit_widget_is_editor ((Widget *) h->current->data))
edit_handle_move_resize ((WEdit *) h->current->data, command); edit_handle_move_resize ((WEdit *) h->current->data, command);
break; break;
default: default:
ret = MSG_NOT_HANDLED; ret = MSG_NOT_HANDLED;
break; break;
@ -447,7 +519,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
static inline void static inline void
edit_set_buttonbar (WEdit * edit, WButtonBar * bb) edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
{ {
buttonbar_set_label (bb, 1, Q_ ("ButtonBar|Help"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 1, Q_ ("ButtonBar|Help"), editor_map, NULL);
buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, (Widget *) edit);
buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, (Widget *) edit);
buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, (Widget *) edit);
@ -456,7 +528,7 @@ edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, (Widget *) edit);
buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, (Widget *) edit);
buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, NULL); buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, NULL);
buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, (Widget *) edit); buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, NULL);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */