Ticket #2156 (Run editor from viewer)

Added new action 'ViewRunEditor' for run editor from viewer;
    set F6 as default hotkey;
    show action 'Edit' in viewer buttonbar.

Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
Ilia Maslakov 2010-05-08 22:32:57 +00:00
parent 0bad072ae6
commit f3cd6377da
8 changed files with 30 additions and 1 deletions

View File

@ -165,6 +165,7 @@ ViewToggleWrapMode = f2
ViewQuit = f3; f10; q; esc; ctrl-g
ViewToggleHexMode = f4
ViewGoto = f5
ViewRunEditor = f6
ViewSearch = f7; question; slash
ViewToggleMagicMode = f8
ViewToggleNroffMode = f9

View File

@ -169,6 +169,7 @@ ViewToggleWrapMode = f2
ViewQuit = f3; f10; q; esc; ctrl-g
ViewToggleHexMode = f4
ViewGoto = f5
ViewRunEditor = f6
ViewSearch = f7; question; slash
ViewToggleMagicMode = f8
ViewToggleNroffMode = f9

View File

@ -290,6 +290,7 @@
#define CK_ViewPrevFile 5025
#define CK_ViewToggleRuler 5026
#define CK_ViewToggleHexNavMode 5027
#define CK_ViewRunEditor 5028
/* Tree */
#define CK_TreeHelp 6001

View File

@ -281,6 +281,7 @@ static name_keymap_t command_names[] = {
{ "ViewPrevFile", CK_ViewPrevFile },
{ "ViewToggleRuler", CK_ViewToggleRuler },
{ "ViewToggleHexNavMode", CK_ViewToggleHexNavMode },
{ "ViewRunEditor", CK_ViewRunEditor },
/* help */
{ "HelpHelp", CK_HelpHelp },
@ -552,6 +553,7 @@ const global_keymap_t default_viewer_keymap[] = {
{ KEY_F (3), CK_ViewQuit, "F3" },
{ KEY_F (4), CK_ViewToggleHexMode, "F4" },
{ KEY_F (5), CK_ViewGoto, "F5" },
{ KEY_F (6), CK_ViewRunEditor, "F6" },
{ KEY_F (7), CK_ViewSearch, "F7" },
{ KEY_F (8), CK_ViewToggleMagicMode, "F8" },
{ KEY_F (9), CK_ViewToggleNroffMode, "F9" },

View File

@ -79,6 +79,7 @@
/*** file scope functions ************************************************************************/
/* Both views */
static void
mcview_search (mcview_t * view)
@ -340,6 +341,10 @@ mcview_execute_cmd (mcview_t * view, unsigned long command)
/* Toggle between hex view and text view */
mcview_toggle_hex_mode (view);
break;
case CK_ViewRunEditor:
/* Open current file in editor */
mcview_edit (view);
break;
case CK_ViewGoto:
{
off_t addr;

View File

@ -101,7 +101,7 @@ mcview_set_buttonbar (mcview_t * view)
buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap")
: Q_ ("ButtonBar|Wrap"), keymap, (Widget *) view);
buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, (Widget *) view);
buttonbar_set_label (b, 6, "", keymap, (Widget *) view);
buttonbar_set_label (b, 6, Q_ ("ButtonBar|Edit"), keymap, (Widget *) view);
buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, (Widget *) view);
}

View File

@ -285,6 +285,7 @@ void mcview_toggle_magic_mode (mcview_t * view);
void mcview_toggle_wrap_mode (mcview_t * view);
void mcview_toggle_nroff_mode (mcview_t * view);
void mcview_toggle_hex_mode (mcview_t * view);
void mcview_edit (mcview_t * view);
gboolean mcview_ok_to_quit (mcview_t * view);
void mcview_init (mcview_t * view);
void mcview_done (mcview_t * view);

View File

@ -260,6 +260,24 @@ mcview_done (mcview_t * view)
mcview_hexedit_free_change_list (view);
}
void
mcview_edit (mcview_t * view)
{
off_t line, column;
char *canon_fname;
off_t new_offset;
mcview_offset_to_coord (view, &line, &column, view->dpy_start);
do_edit_at_line (view->filename, line + 1);
canon_fname = vfs_canon (view->filename);
load_file_position (canon_fname, &line, &column, &new_offset);
new_offset = min (new_offset, mcview_get_filesize (view));
view->dpy_start = mcview_bol (view, new_offset);
g_free (canon_fname);
view->dpy_bbar_dirty = TRUE;
view->dirty++;
}
/* --------------------------------------------------------------------------------------------- */
void