mirror of https://github.com/MidnightCommander/mc
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:
parent
a87165824c
commit
8024889126
50
src/cmd.c
50
src/cmd.c
|
@ -121,7 +121,6 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start
|
|||
static const char *viewer = NULL;
|
||||
int move_dir = 0;
|
||||
|
||||
|
||||
if (plain_view)
|
||||
{
|
||||
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_nroff_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)
|
||||
mcview_default_hex_mode = 1;
|
||||
if (changed_nroff_flag && !mcview_altered_nroff_flag)
|
||||
mcview_default_nroff_flag = 1;
|
||||
if (changed_magic_flag && !mcview_altered_magic_flag)
|
||||
mcview_default_magic_flag = 1;
|
||||
|
||||
repaint_screen ();
|
||||
return move_dir;
|
||||
}
|
||||
if (internal)
|
||||
else if (internal)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!viewer)
|
||||
if (viewer == NULL)
|
||||
{
|
||||
viewer = getenv ("VIEWER");
|
||||
if (!viewer)
|
||||
if (viewer == NULL)
|
||||
viewer = getenv ("PAGER");
|
||||
if (!viewer)
|
||||
if (viewer == NULL)
|
||||
viewer = "view";
|
||||
}
|
||||
|
||||
execute_with_vfs_arg (viewer, filename);
|
||||
}
|
||||
|
||||
return move_dir;
|
||||
}
|
||||
|
||||
|
@ -300,13 +324,13 @@ filtered_view_cmd (void)
|
|||
input_dialog (_("Filtered view"),
|
||||
_("Filter command and arguments:"),
|
||||
MC_HISTORY_FM_FILTERED_VIEW, selection (current_panel)->fname);
|
||||
if (!command)
|
||||
return;
|
||||
|
||||
mcview_viewer (command, "", NULL, 0);
|
||||
|
||||
if (command != NULL)
|
||||
{
|
||||
mcview_viewer (command, "", 0);
|
||||
g_free (command);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
do_edit_at_line (const char *what, int start_line)
|
||||
|
@ -345,7 +369,7 @@ do_edit (const char *what)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
21
src/ext.c
21
src/ext.c
|
@ -283,6 +283,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
|||
|
||||
if (run_view)
|
||||
{
|
||||
mcview_ret_t ret;
|
||||
|
||||
mcview_altered_hex_mode = 0;
|
||||
mcview_altered_nroff_flag = 0;
|
||||
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)
|
||||
{
|
||||
mcview_viewer (cmd, filename, move_dir, start_line);
|
||||
ret = mcview_viewer (cmd, filename, start_line);
|
||||
unlink (file_name);
|
||||
}
|
||||
else
|
||||
ret = mcview_viewer (NULL, filename, start_line);
|
||||
|
||||
if (move_dir != NULL)
|
||||
switch (ret)
|
||||
{
|
||||
mcview_viewer (NULL, filename, move_dir, 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)
|
||||
mcview_default_hex_mode = def_hex_mode;
|
||||
if (changed_nroff_flag && !mcview_altered_nroff_flag)
|
||||
mcview_default_nroff_flag = def_nroff_flag;
|
||||
|
||||
repaint_screen ();
|
||||
}
|
||||
else if (is_cd)
|
||||
|
@ -331,13 +346,11 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
|||
{
|
||||
handle_console (CONSOLE_SAVE);
|
||||
if (output_lines && keybar_visible)
|
||||
{
|
||||
show_console_contents (output_start_y,
|
||||
LINES - keybar_visible -
|
||||
output_lines - 1, LINES - keybar_visible - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free (file_name);
|
||||
g_free (cmd);
|
||||
|
|
|
@ -2509,7 +2509,7 @@ do_enter_on_file_entry (file_entry * fe)
|
|||
}
|
||||
|
||||
/* Try associated command */
|
||||
if (regex_command (fe->fname, "Open", 0) != 0)
|
||||
if (regex_command (fe->fname, "Open", NULL) != 0)
|
||||
return 1;
|
||||
|
||||
/* Check if the file is executable */
|
||||
|
|
|
@ -775,10 +775,7 @@ execute_menu_command (WEdit * edit_widget, const char *commands)
|
|||
fclose (cmd_file);
|
||||
chmod (file_name, S_IRWXU);
|
||||
if (run_view)
|
||||
{
|
||||
run_view = 0;
|
||||
mcview_viewer (file_name, NULL, &run_view, 0);
|
||||
}
|
||||
mcview_viewer (file_name, NULL, 0);
|
||||
else
|
||||
{
|
||||
/* execute the command indirectly to allow execution even
|
||||
|
|
|
@ -237,12 +237,13 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
|
|||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Real view only */
|
||||
int
|
||||
mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line)
|
||||
mcview_ret_t
|
||||
mcview_viewer (const char *command, const char *file, int start_line)
|
||||
{
|
||||
gboolean succeeded;
|
||||
mcview_t *lc_mcview;
|
||||
Dlg_head *view_dlg;
|
||||
mcview_ret_t ret;
|
||||
|
||||
/* Create dialog and widgets, put them on the dialog */
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
if (move_dir_p)
|
||||
*move_dir_p = 0;
|
||||
view_dlg->state = DLG_CLOSED;
|
||||
ret = MCVIEW_EXIT_FAILURE;
|
||||
}
|
||||
destroy_dlg (view_dlg);
|
||||
|
||||
return succeeded;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* {{{ Miscellaneous functions }}} */
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
|
||||
struct mcview_struct;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MCVIEW_EXIT_FAILURE = -1,
|
||||
MCVIEW_EXIT_OK = 0,
|
||||
MCVIEW_WANT_NEXT,
|
||||
MCVIEW_WANT_PREV
|
||||
} mcview_ret_t;
|
||||
|
||||
/*** enums *************************************************************/
|
||||
|
||||
/*** 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,
|
||||
* starting in line {start_line}. {move_dir_p} may be NULL or
|
||||
* 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).
|
||||
* starting in line {start_line}.
|
||||
*/
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue