Added type for MC viewer exit codes. Changed MC viewer run interface.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-05-01 16:37:06 +04:00
parent a87165824c
commit 8024889126
6 changed files with 78 additions and 36 deletions

View File

@ -121,7 +121,6 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start
static const char *viewer = NULL; static const char *viewer = NULL;
int move_dir = 0; int move_dir = 0;
if (plain_view) if (plain_view)
{ {
int changed_hex_mode = 0; int changed_hex_mode = 0;
@ -140,17 +139,29 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start
mcview_default_hex_mode = 0; mcview_default_hex_mode = 0;
mcview_default_nroff_flag = 0; mcview_default_nroff_flag = 0;
mcview_default_magic_flag = 0; mcview_default_magic_flag = 0;
mcview_viewer (NULL, filename, &move_dir, start_line);
switch (mcview_viewer (NULL, filename, start_line))
{
case MCVIEW_WANT_NEXT:
move_dir = 1;
break;
case MCVIEW_WANT_PREV:
move_dir = -1;
break;
default:
move_dir = 0;
}
if (changed_hex_mode && !mcview_altered_hex_mode) if (changed_hex_mode && !mcview_altered_hex_mode)
mcview_default_hex_mode = 1; mcview_default_hex_mode = 1;
if (changed_nroff_flag && !mcview_altered_nroff_flag) if (changed_nroff_flag && !mcview_altered_nroff_flag)
mcview_default_nroff_flag = 1; mcview_default_nroff_flag = 1;
if (changed_magic_flag && !mcview_altered_magic_flag) if (changed_magic_flag && !mcview_altered_magic_flag)
mcview_default_magic_flag = 1; mcview_default_magic_flag = 1;
repaint_screen (); repaint_screen ();
return move_dir;
} }
if (internal) else if (internal)
{ {
char view_entry[BUF_TINY]; char view_entry[BUF_TINY];
@ -161,22 +172,35 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start
if (regex_command (filename, view_entry, &move_dir) == 0) if (regex_command (filename, view_entry, &move_dir) == 0)
{ {
mcview_viewer (NULL, filename, &move_dir, start_line); switch (mcview_viewer (NULL, filename, start_line))
{
case MCVIEW_WANT_NEXT:
move_dir = 1;
break;
case MCVIEW_WANT_PREV:
move_dir = -1;
break;
default:
move_dir = 0;
}
repaint_screen (); repaint_screen ();
} }
} }
else else
{ {
if (!viewer) if (viewer == NULL)
{ {
viewer = getenv ("VIEWER"); viewer = getenv ("VIEWER");
if (!viewer) if (viewer == NULL)
viewer = getenv ("PAGER"); viewer = getenv ("PAGER");
if (!viewer) if (viewer == NULL)
viewer = "view"; viewer = "view";
} }
execute_with_vfs_arg (viewer, filename); execute_with_vfs_arg (viewer, filename);
} }
return move_dir; return move_dir;
} }
@ -300,12 +324,12 @@ filtered_view_cmd (void)
input_dialog (_("Filtered view"), input_dialog (_("Filtered view"),
_("Filter command and arguments:"), _("Filter command and arguments:"),
MC_HISTORY_FM_FILTERED_VIEW, selection (current_panel)->fname); MC_HISTORY_FM_FILTERED_VIEW, selection (current_panel)->fname);
if (!command)
return;
mcview_viewer (command, "", NULL, 0); if (command != NULL)
{
g_free (command); mcview_viewer (command, "", 0);
g_free (command);
}
} }
void void
@ -345,7 +369,7 @@ do_edit (const char *what)
void void
edit_cmd (void) edit_cmd (void)
{ {
if (regex_command (selection (current_panel)->fname, "Edit", 0) == 0) if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
do_edit (selection (current_panel)->fname); do_edit (selection (current_panel)->fname);
} }

View File

@ -283,6 +283,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
if (run_view) if (run_view)
{ {
mcview_ret_t ret;
mcview_altered_hex_mode = 0; mcview_altered_hex_mode = 0;
mcview_altered_nroff_flag = 0; mcview_altered_nroff_flag = 0;
if (def_hex_mode != mcview_default_hex_mode) if (def_hex_mode != mcview_default_hex_mode)
@ -295,17 +297,30 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
*/ */
if (written_nonspace) if (written_nonspace)
{ {
mcview_viewer (cmd, filename, move_dir, start_line); ret = mcview_viewer (cmd, filename, start_line);
unlink (file_name); unlink (file_name);
} }
else else
{ ret = mcview_viewer (NULL, filename, start_line);
mcview_viewer (NULL, filename, move_dir, start_line);
} if (move_dir != NULL)
switch (ret)
{
case MCVIEW_WANT_NEXT:
*move_dir = 1;
break;
case MCVIEW_WANT_PREV:
*move_dir = -1;
break;
default:
*move_dir = 0;
}
if (changed_hex_mode && !mcview_altered_hex_mode) if (changed_hex_mode && !mcview_altered_hex_mode)
mcview_default_hex_mode = def_hex_mode; mcview_default_hex_mode = def_hex_mode;
if (changed_nroff_flag && !mcview_altered_nroff_flag) if (changed_nroff_flag && !mcview_altered_nroff_flag)
mcview_default_nroff_flag = def_nroff_flag; mcview_default_nroff_flag = def_nroff_flag;
repaint_screen (); repaint_screen ();
} }
else if (is_cd) else if (is_cd)
@ -331,11 +346,9 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
{ {
handle_console (CONSOLE_SAVE); handle_console (CONSOLE_SAVE);
if (output_lines && keybar_visible) if (output_lines && keybar_visible)
{
show_console_contents (output_start_y, show_console_contents (output_start_y,
LINES - keybar_visible - LINES - keybar_visible -
output_lines - 1, LINES - keybar_visible - 1); output_lines - 1, LINES - keybar_visible - 1);
}
} }
} }

View File

@ -2509,7 +2509,7 @@ do_enter_on_file_entry (file_entry * fe)
} }
/* Try associated command */ /* Try associated command */
if (regex_command (fe->fname, "Open", 0) != 0) if (regex_command (fe->fname, "Open", NULL) != 0)
return 1; return 1;
/* Check if the file is executable */ /* Check if the file is executable */

View File

@ -775,10 +775,7 @@ execute_menu_command (WEdit * edit_widget, const char *commands)
fclose (cmd_file); fclose (cmd_file);
chmod (file_name, S_IRWXU); chmod (file_name, S_IRWXU);
if (run_view) if (run_view)
{ mcview_viewer (file_name, NULL, 0);
run_view = 0;
mcview_viewer (file_name, NULL, &run_view, 0);
}
else else
{ {
/* execute the command indirectly to allow execution even /* execute the command indirectly to allow execution even

View File

@ -237,12 +237,13 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/* Real view only */ /* Real view only */
int mcview_ret_t
mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line) mcview_viewer (const char *command, const char *file, int start_line)
{ {
gboolean succeeded; gboolean succeeded;
mcview_t *lc_mcview; mcview_t *lc_mcview;
Dlg_head *view_dlg; Dlg_head *view_dlg;
mcview_ret_t ret;
/* Create dialog and widgets, put them on the dialog */ /* Create dialog and widgets, put them on the dialog */
view_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, mcview_dialog_callback, view_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, mcview_dialog_callback,
@ -259,17 +260,18 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start
if (succeeded) if (succeeded)
{ {
run_dlg (view_dlg); run_dlg (view_dlg);
if (move_dir_p)
*move_dir_p = lc_mcview->move_dir; ret = lc_mcview->move_dir == 0 ? MCVIEW_EXIT_OK :
lc_mcview->move_dir > 0 ? MCVIEW_WANT_NEXT : MCVIEW_WANT_PREV;
} }
else else
{ {
if (move_dir_p) view_dlg->state = DLG_CLOSED;
*move_dir_p = 0; ret = MCVIEW_EXIT_FAILURE;
} }
destroy_dlg (view_dlg); destroy_dlg (view_dlg);
return succeeded; return ret;
} }
/* {{{ Miscellaneous functions }}} */ /* {{{ Miscellaneous functions }}} */

View File

@ -11,6 +11,14 @@
struct mcview_struct; struct mcview_struct;
typedef enum
{
MCVIEW_EXIT_FAILURE = -1,
MCVIEW_EXIT_OK = 0,
MCVIEW_WANT_NEXT,
MCVIEW_WANT_PREV
} mcview_ret_t;
/*** enums *************************************************************/ /*** enums *************************************************************/
/*** structures declarations (and typedefs of structures)***************/ /*** structures declarations (and typedefs of structures)***************/
@ -41,11 +49,9 @@ extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, gboo
/* Shows {file} or the output of {command} in the internal viewer, /* Shows {file} or the output of {command} in the internal viewer,
* starting in line {start_line}. {move_dir_p} may be NULL or * starting in line {start_line}.
* point to a variable that will receive the direction in which the user
* wants to move (-1 = previous file, 1 = next file, 0 = do nothing).
*/ */
extern int mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line); extern mcview_ret_t mcview_viewer (const char *command, const char *file, int start_line);
extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int); extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int);