mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
mceditor: massive use of edit_arg_t as function argument.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
e79e76b72b
commit
258b52b2d1
@ -130,7 +130,7 @@ extern char *edit_window_close_char;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
gboolean edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline);
|
||||
gboolean edit_add_window (WDialog * h, const WRect * r, const edit_arg_t * arg);
|
||||
WEdit *edit_find_editor (const WDialog * h);
|
||||
gboolean edit_widget_is_editor (const Widget * w);
|
||||
gboolean edit_drop_hotkey_menu (WDialog * h, int key);
|
||||
@ -152,7 +152,7 @@ long edit_get_col (const WEdit * edit);
|
||||
void edit_update_curs_row (WEdit * edit);
|
||||
void edit_update_curs_col (WEdit * edit);
|
||||
void edit_find_bracket (WEdit * edit);
|
||||
gboolean edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line);
|
||||
gboolean edit_reload_line (WEdit * edit, const edit_arg_t * arg);
|
||||
void edit_set_codeset (WEdit * edit);
|
||||
|
||||
void edit_block_copy_cmd (WEdit * edit);
|
||||
@ -174,11 +174,11 @@ char *edit_get_write_filter (const vfs_path_t * write_name_vpath,
|
||||
const vfs_path_t * filename_vpath);
|
||||
gboolean edit_save_confirm_cmd (WEdit * edit);
|
||||
gboolean edit_save_as_cmd (WEdit * edit);
|
||||
WEdit *edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line);
|
||||
WEdit *edit_init (WEdit * edit, const WRect * r, const edit_arg_t * arg);
|
||||
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_filename (WDialog * h, const edit_arg_t * arg);
|
||||
gboolean edit_load_file_from_history (WDialog * h);
|
||||
gboolean edit_load_syntax_file (WDialog * h);
|
||||
gboolean edit_load_menu_file (WDialog * h);
|
||||
@ -266,7 +266,11 @@ int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboole
|
||||
static inline gboolean
|
||||
edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
{
|
||||
return edit_reload_line (edit, filename_vpath, 0);
|
||||
edit_arg_t arg;
|
||||
|
||||
edit_arg_init (&arg, (vfs_path_t *) filename_vpath, 0);
|
||||
|
||||
return edit_reload_line (edit, &arg);
|
||||
}
|
||||
|
||||
#endif /* MC__EDIT_IMPL_H */
|
||||
|
@ -2114,14 +2114,15 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
|
||||
* Fill in the edit structure. Return NULL on failure. Pass edit as
|
||||
* NULL to allocate a new structure.
|
||||
*
|
||||
* If line is 0, try to restore saved position. Otherwise put the
|
||||
* If arg is NULL or arg->line_number is 0, try to restore saved position. Otherwise put the
|
||||
* cursor on that line and show it in the middle of the screen.
|
||||
*/
|
||||
|
||||
WEdit *
|
||||
edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line)
|
||||
edit_init (WEdit * edit, const WRect * r, const edit_arg_t * arg)
|
||||
{
|
||||
gboolean to_free = FALSE;
|
||||
long line;
|
||||
|
||||
auto_syntax = TRUE; /* Resetting to auto on every invocation */
|
||||
edit_options.line_state_width = edit_options.line_state ? LINE_STATE_WIDTH : 0;
|
||||
@ -2164,7 +2165,7 @@ edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon
|
||||
edit->stat1.st_gid = getgid ();
|
||||
edit->stat1.st_mtime = 0;
|
||||
|
||||
edit->attrs_ok = (mc_fgetflags (filename_vpath, &edit->attrs) == 0);
|
||||
edit->attrs_ok = (mc_fgetflags (arg->file_vpath, &edit->attrs) == 0);
|
||||
|
||||
edit->over_col = 0;
|
||||
edit->bracket = -1;
|
||||
@ -2172,7 +2173,16 @@ edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon
|
||||
edit->force |= REDRAW_PAGE;
|
||||
|
||||
/* set file name before load file */
|
||||
edit_set_filename (edit, filename_vpath);
|
||||
if (arg != NULL)
|
||||
{
|
||||
edit_set_filename (edit, arg->file_vpath);
|
||||
line = arg->line_number;
|
||||
}
|
||||
else
|
||||
{
|
||||
edit_set_filename (edit, NULL);
|
||||
line = 0;
|
||||
}
|
||||
|
||||
edit->undo_stack_size = START_STACK_SIZE;
|
||||
edit->undo_stack_size_mask = START_STACK_SIZE - 1;
|
||||
@ -2273,7 +2283,7 @@ edit_clean (WEdit * edit)
|
||||
* @return TRUE on success, FALSE on failure.
|
||||
*/
|
||||
gboolean
|
||||
edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
||||
edit_reload_line (WEdit * edit, const edit_arg_t * arg)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
WEdit *e;
|
||||
@ -2284,7 +2294,7 @@ edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
||||
e->fullscreen = edit->fullscreen;
|
||||
e->loc_prev = edit->loc_prev;
|
||||
|
||||
if (edit_init (e, &w->rect, filename_vpath, line) == NULL)
|
||||
if (edit_init (e, &w->rect, arg) == NULL)
|
||||
{
|
||||
g_free (e);
|
||||
return FALSE;
|
||||
|
@ -78,7 +78,7 @@ extern edit_options_t edit_options;
|
||||
void edit_stack_init (void);
|
||||
void edit_stack_free (void);
|
||||
|
||||
gboolean edit_file (const vfs_path_t * file_vpath, long line);
|
||||
gboolean edit_file (const edit_arg_t * arg);
|
||||
gboolean edit_files (const GList * files);
|
||||
|
||||
edit_arg_t *edit_arg_vpath_new (vfs_path_t * file_vpath, long line_number);
|
||||
|
@ -1058,9 +1058,11 @@ edit_load_cmd (WDialog * h)
|
||||
if (exp != NULL && *exp != '\0')
|
||||
{
|
||||
vfs_path_t *exp_vpath;
|
||||
edit_arg_t arg;
|
||||
|
||||
exp_vpath = vfs_path_from_str (exp);
|
||||
ret = edit_load_file_from_filename (h, exp_vpath, 0);
|
||||
edit_arg_init (&arg, exp_vpath, 0);
|
||||
ret = edit_load_file_from_filename (h, &arg);
|
||||
vfs_path_free (exp_vpath, TRUE);
|
||||
}
|
||||
|
||||
@ -1081,13 +1083,13 @@ edit_load_cmd (WDialog * h)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath, long line)
|
||||
edit_load_file_from_filename (WDialog * h, const edit_arg_t * arg)
|
||||
{
|
||||
WRect r = WIDGET (h)->rect;
|
||||
|
||||
rect_grow (&r, -1, 0);
|
||||
|
||||
return edit_add_window (h, &r, vpath, line);
|
||||
return edit_add_window (h, &r, arg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1108,9 +1110,11 @@ edit_load_file_from_history (WDialog * h)
|
||||
if (exp != NULL && (action == CK_Edit || action == CK_Enter))
|
||||
{
|
||||
vfs_path_t *exp_vpath;
|
||||
edit_arg_t arg;
|
||||
|
||||
exp_vpath = vfs_path_from_str (exp);
|
||||
ret = edit_load_file_from_filename (h, exp_vpath, 0);
|
||||
edit_arg_init (&arg, exp_vpath, 0);
|
||||
ret = edit_load_file_from_filename (h, &arg);
|
||||
vfs_path_free (exp_vpath, TRUE);
|
||||
}
|
||||
|
||||
@ -1131,6 +1135,7 @@ edit_load_syntax_file (WDialog * h)
|
||||
{
|
||||
vfs_path_t *extdir_vpath;
|
||||
int dir = 0;
|
||||
edit_arg_t arg;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (geteuid () == 0)
|
||||
@ -1153,11 +1158,15 @@ edit_load_syntax_file (WDialog * h)
|
||||
|
||||
user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE);
|
||||
check_for_default (extdir_vpath, user_syntax_file_vpath);
|
||||
ret = edit_load_file_from_filename (h, user_syntax_file_vpath, 0);
|
||||
edit_arg_init (&arg, user_syntax_file_vpath, 0);
|
||||
ret = edit_load_file_from_filename (h, &arg);
|
||||
vfs_path_free (user_syntax_file_vpath, TRUE);
|
||||
}
|
||||
else if (dir == 1)
|
||||
ret = edit_load_file_from_filename (h, extdir_vpath, 0);
|
||||
{
|
||||
edit_arg_init (&arg, extdir_vpath, 0);
|
||||
ret = edit_load_file_from_filename (h, &arg);
|
||||
}
|
||||
|
||||
vfs_path_free (extdir_vpath, TRUE);
|
||||
|
||||
@ -1177,6 +1186,7 @@ edit_load_menu_file (WDialog * h)
|
||||
vfs_path_t *buffer_vpath;
|
||||
vfs_path_t *menufile_vpath;
|
||||
int dir;
|
||||
edit_arg_t arg;
|
||||
gboolean ret;
|
||||
|
||||
query_set_sel (1);
|
||||
@ -1222,7 +1232,8 @@ edit_load_menu_file (WDialog * h)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ret = edit_load_file_from_filename (h, buffer_vpath, 0);
|
||||
edit_arg_init (&arg, buffer_vpath, 0);
|
||||
ret = edit_load_file_from_filename (h, &arg);
|
||||
|
||||
vfs_path_free (buffer_vpath, TRUE);
|
||||
vfs_path_free (menufile_vpath, TRUE);
|
||||
@ -1982,8 +1993,7 @@ edit_load_forward_cmd (WEdit * edit)
|
||||
|
||||
edit_stack_iterator++;
|
||||
if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL)
|
||||
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath,
|
||||
edit_history_moveto[edit_stack_iterator].line_number);
|
||||
return edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@ -2009,8 +2019,7 @@ edit_load_back_cmd (WEdit * edit)
|
||||
|
||||
edit_stack_iterator--;
|
||||
if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL)
|
||||
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath,
|
||||
edit_history_moveto[edit_stack_iterator].line_number);
|
||||
return edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ edit_dialog_command_execute (WDialog * h, long command)
|
||||
switch (command)
|
||||
{
|
||||
case CK_EditNew:
|
||||
edit_load_file_from_filename (h, NULL, 0);
|
||||
edit_load_file_from_filename (h, NULL);
|
||||
break;
|
||||
case CK_EditFile:
|
||||
edit_load_cmd (h);
|
||||
@ -1196,13 +1196,12 @@ edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_file (const vfs_path_t * file_vpath, long line)
|
||||
edit_file (const edit_arg_t * arg)
|
||||
{
|
||||
edit_arg_t arg = { (vfs_path_t *) file_vpath, line };
|
||||
GList *files;
|
||||
gboolean ok;
|
||||
|
||||
files = g_list_prepend (NULL, &arg);
|
||||
files = g_list_prepend (NULL, (edit_arg_t *) arg);
|
||||
ok = edit_files (files);
|
||||
g_list_free (files);
|
||||
|
||||
@ -1269,10 +1268,9 @@ edit_files (const GList * files)
|
||||
|
||||
for (file = files; file != NULL; file = g_list_next (file))
|
||||
{
|
||||
edit_arg_t *f = (edit_arg_t *) file->data;
|
||||
gboolean f_ok;
|
||||
|
||||
f_ok = edit_load_file_from_filename (edit_dlg, f->file_vpath, f->line_number);
|
||||
f_ok = edit_load_file_from_filename (edit_dlg, (const edit_arg_t *) file->data);
|
||||
/* at least one file has been opened succefully */
|
||||
ok = ok || f_ok;
|
||||
}
|
||||
@ -1363,12 +1361,12 @@ edit_save_size (WEdit * edit)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline)
|
||||
edit_add_window (WDialog * h, const WRect * r, const edit_arg_t * arg)
|
||||
{
|
||||
WEdit *edit;
|
||||
Widget *w;
|
||||
|
||||
edit = edit_init (NULL, r, f, fline);
|
||||
edit = edit_init (NULL, r, arg);
|
||||
if (edit == NULL)
|
||||
return FALSE;
|
||||
|
||||
|
@ -394,8 +394,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray
|
||||
edit_stack_iterator++;
|
||||
edit_arg_assign (&edit_history_moveto[edit_stack_iterator],
|
||||
vfs_path_from_str ((char *) curr_def->fullpath), curr_def->line);
|
||||
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath,
|
||||
edit_history_moveto[edit_stack_iterator].line_number);
|
||||
edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,7 +664,11 @@ edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_
|
||||
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
if (internal)
|
||||
edit_file (what_vpath, start_line);
|
||||
{
|
||||
const edit_arg_t arg = { (vfs_path_t *) what_vpath, start_line };
|
||||
|
||||
edit_file (&arg);
|
||||
}
|
||||
else
|
||||
#endif /* USE_INTERNAL_EDIT */
|
||||
{
|
||||
|
@ -152,6 +152,7 @@ static void
|
||||
my_setup (void)
|
||||
{
|
||||
WRect r;
|
||||
edit_arg_t arg;
|
||||
|
||||
str_init_strings (NULL);
|
||||
|
||||
@ -171,7 +172,9 @@ my_setup (void)
|
||||
edit_options.filesize_threshold = (char *) "64M";
|
||||
|
||||
rect_init (&r, 0, 0, 24, 80);
|
||||
test_edit = edit_init (NULL, &r, vfs_path_from_str ("test-data.txt"), 1);
|
||||
arg.file_vpath = vfs_path_from_str ("test-data.txt");
|
||||
arg.line_number = 1;
|
||||
test_edit = edit_init (NULL, &r, &arg);
|
||||
memset (&owner, 0, sizeof (owner));
|
||||
group_add_widget (&owner, WIDGET (test_edit));
|
||||
edit_completion_dialog_show__init ();
|
||||
|
Loading…
Reference in New Issue
Block a user