mceditor: minor refactoring of file load.

(edit_load_file_from_filename): make public, use it as main function to
load file and create editor window.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2022-05-21 20:26:15 +03:00
parent 12543835f9
commit 5f746eea0c
3 changed files with 29 additions and 35 deletions

View File

@ -184,6 +184,7 @@ WEdit *edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpa
gboolean edit_clean (WEdit * edit);
gboolean edit_ok_to_exit (WEdit * edit);
gboolean edit_load_cmd (WDialog * h);
gboolean edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath, long line);
gboolean edit_load_file_from_history (WDialog * h);
gboolean edit_load_syntax_file (WDialog * h);
gboolean edit_load_menu_file (WDialog * h);

View File

@ -462,25 +462,6 @@ edit_save_cmd (WEdit * edit)
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load file content
*
* @param h screen the owner of editor window
* @param vpath vfs file path
* @return TRUE if file content was successfully loaded, FALSE otherwise
*/
static inline gboolean
edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath)
{
WRect r = WIDGET (h)->rect;
rect_grow (&r, -1, 0);
return edit_add_window (h, &r, vpath, 0);
}
/* --------------------------------------------------------------------------------------------- */
static void
@ -1068,7 +1049,7 @@ edit_load_cmd (WDialog * h)
vfs_path_t *exp_vpath;
exp_vpath = vfs_path_from_str (exp);
ret = edit_load_file_from_filename (h, exp_vpath);
ret = edit_load_file_from_filename (h, exp_vpath, 0);
vfs_path_free (exp_vpath, TRUE);
}
@ -1077,6 +1058,27 @@ edit_load_cmd (WDialog * h)
return ret;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Load file content
*
* @param h screen the owner of editor window
* @param vpath vfs file path
* @param line line number
*
* @return TRUE if file content was successfully loaded, FALSE otherwise
*/
gboolean
edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath, long line)
{
WRect r = WIDGET (h)->rect;
rect_grow (&r, -1, 0);
return edit_add_window (h, &r, vpath, line);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Show history od edited or viewed files and open selected file.
@ -1097,7 +1099,7 @@ edit_load_file_from_history (WDialog * h)
vfs_path_t *exp_vpath;
exp_vpath = vfs_path_from_str (exp);
ret = edit_load_file_from_filename (h, exp_vpath);
ret = edit_load_file_from_filename (h, exp_vpath, 0);
vfs_path_free (exp_vpath, TRUE);
}
@ -1140,11 +1142,11 @@ edit_load_syntax_file (WDialog * h)
user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_HOME_SYNTAX_FILE);
check_for_default (extdir_vpath, user_syntax_file_vpath);
ret = edit_load_file_from_filename (h, user_syntax_file_vpath);
ret = edit_load_file_from_filename (h, user_syntax_file_vpath, 0);
vfs_path_free (user_syntax_file_vpath, TRUE);
}
else if (dir == 1)
ret = edit_load_file_from_filename (h, extdir_vpath);
ret = edit_load_file_from_filename (h, extdir_vpath, 0);
vfs_path_free (extdir_vpath, TRUE);
@ -1209,7 +1211,7 @@ edit_load_menu_file (WDialog * h)
return FALSE;
}
ret = edit_load_file_from_filename (h, buffer_vpath);
ret = edit_load_file_from_filename (h, buffer_vpath, 0);
vfs_path_free (buffer_vpath, TRUE);
vfs_path_free (menufile_vpath, TRUE);

View File

@ -397,18 +397,12 @@ static cb_ret_t
edit_dialog_command_execute (WDialog * h, long command)
{
WGroup *g = GROUP (h);
Widget *wh = WIDGET (h);
cb_ret_t ret = MSG_HANDLED;
switch (command)
{
case CK_EditNew:
{
WRect r = wh->rect;
rect_resize_centered (&r, -1, 0);
edit_add_window (h, &r, NULL, 0);
}
edit_load_file_from_filename (h, NULL, 0);
break;
case CK_EditFile:
edit_load_cmd (h);
@ -1276,11 +1270,8 @@ edit_files (const GList * files)
{
mcedit_arg_t *f = (mcedit_arg_t *) file->data;
gboolean f_ok;
WRect r = wd->rect;
rect_grow (&r, -1, 0);
f_ok = edit_add_window (edit_dlg, &r, f->file_vpath, f->line_number);
f_ok = edit_load_file_from_filename (edit_dlg, f->file_vpath, f->line_number);
/* at least one file has been opened succefully */
ok = ok || f_ok;
}