diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h index 55a5707fa..26ffaf6cb 100644 --- a/src/editor/edit-impl.h +++ b/src/editor/edit-impl.h @@ -289,7 +289,7 @@ int edit_save_block_cmd (WEdit * edit); int edit_insert_file_cmd (WEdit * edit); void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width); int edit_insert_column_of_text_from_file (WEdit * edit, int file); -int edit_insert_file (WEdit * edit, const char *filename); +long edit_insert_file (WEdit * edit, const char *filename); int edit_load_back_cmd (WEdit * edit); int edit_load_forward_cmd (WEdit * edit); void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block); diff --git a/src/editor/edit.c b/src/editor/edit.c index 8241e6d8a..607d27171 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -480,7 +480,7 @@ edit_load_file (WEdit * edit) if (*edit->filename) { edit->undo_stack_disable = 1; - if (!edit_insert_file (edit, edit->filename)) + if (edit_insert_file (edit, edit->filename) == 0) { edit_clean (edit); return 1; @@ -1685,22 +1685,23 @@ user_menu (WEdit * edit) edit_save_block (edit, block_file, start_mark, end_mark); /* run shell scripts from menu */ - user_menu_cmd (edit); - - if ((mc_stat (block_file, &status) == 0) && (status.st_size != 0)) + if (user_menu_cmd (edit) && (mc_stat (block_file, &status) == 0) && (status.st_size != 0)) { int rc = 0; FILE *fd; + /* i.e. we have marked block */ if (nomark == 0) - { - /* i.e. we have marked block */ rc = edit_block_delete_cmd (edit); - } if (rc == 0) - edit_insert_file (edit, block_file); + { + long ins_len; + ins_len = edit_insert_file (edit, block_file); + if (nomark == 0 && ins_len > 0) + edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0); + } /* truncate block file */ fd = fopen (block_file, "w"); if (fd != NULL) @@ -2012,11 +2013,12 @@ edit_write_stream (WEdit * edit, FILE * f) } /* --------------------------------------------------------------------------------------------- */ -/** inserts a file at the cursor, returns 1 on success */ -int +/** inserts a file at the cursor, returns count of inserted bytes on success */ +long edit_insert_file (WEdit * edit, const char *filename) { char *p; + long ins_len = 0; p = edit_get_filter (filename); if (p != NULL) @@ -2027,6 +2029,7 @@ edit_insert_file (WEdit * edit, const char *filename) if (f != NULL) { edit_insert_stream (edit, f); + ins_len = edit->curs1 - current; edit_cursor_move (edit, current - edit->curs1); if (pclose (f) > 0) { @@ -2062,25 +2065,32 @@ edit_insert_file (WEdit * edit, const char *filename) blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC)); if (blocklen > 0) { - /* if contain signature VERTICAL_MAGIC tnen it vertical block */ + /* if contain signature VERTICAL_MAGIC then it vertical block */ if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0) vertical_insertion = 1; else mc_lseek (file, 0, SEEK_SET); } if (vertical_insertion) + { blocklen = edit_insert_column_of_text_from_file (edit, file); + } else + { while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) + { for (i = 0; i < blocklen; i++) edit_insert (edit, buf[i]); + } + } + ins_len = edit->curs1 - current; edit_cursor_move (edit, current - edit->curs1); g_free (buf); mc_close (file); if (blocklen != 0) return 0; } - return 1; + return ins_len; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index d91619177..e6079d3df 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -2617,7 +2617,7 @@ edit_insert_file_cmd (WEdit * edit) } else { - if (edit_insert_file (edit, exp)) + if (edit_insert_file (edit, exp) != 0) { g_free (exp); edit->force |= REDRAW_COMPLETELY; diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 3641b4a70..3af5f0674 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -1340,7 +1340,7 @@ help_cmd (void) void user_file_menu_cmd (void) { - user_menu_cmd (NULL); + (void) user_menu_cmd (NULL); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index 2a3b9677e..24358481f 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -850,7 +850,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote) * otherwise we are called from the mcedit menu. */ -void +gboolean user_menu_cmd (struct WEdit *edit_widget) { char *p; @@ -859,11 +859,12 @@ user_menu_cmd (struct WEdit *edit_widget) int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; + gboolean res = FALSE; if (!vfs_current_is_local ()) { message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems")); - return; + return FALSE; } menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); @@ -894,7 +895,7 @@ user_menu_cmd (struct WEdit *edit_widget) message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno)); g_free (menu); menu = NULL; - return; + return FALSE; } max_cols = 0; @@ -990,7 +991,10 @@ user_menu_cmd (struct WEdit *edit_widget) } if (menu_lines == 0) + { message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu); + res = FALSE; + } else { max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); @@ -1010,7 +1014,10 @@ user_menu_cmd (struct WEdit *edit_widget) selected = run_listbox (listbox); if (selected >= 0) + { execute_menu_command (edit_widget, entries[selected]); + res = TRUE; + } do_refresh (); } @@ -1020,6 +1027,7 @@ user_menu_cmd (struct WEdit *edit_widget) menu = NULL; g_free (entries); g_free (data); + return res; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/usermenu.h b/src/filemanager/usermenu.h index 675ed4076..9cbefccb2 100644 --- a/src/filemanager/usermenu.h +++ b/src/filemanager/usermenu.h @@ -19,7 +19,7 @@ struct WEdit; /*** declarations of public functions ************************************************************/ -void user_menu_cmd (struct WEdit *edit_widget); +gboolean user_menu_cmd (struct WEdit *edit_widget); char *expand_format (struct WEdit *edit_widget, char c, gboolean do_quote); int check_format_view (const char *); int check_format_var (const char *, char **);