Add edit_add_window() function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2011-07-28 13:57:50 +04:00
parent 1c33972ee5
commit 8fd3338060
3 changed files with 60 additions and 24 deletions

View File

@ -178,6 +178,8 @@ extern gboolean search_create_bookmark;
/*** declarations of public functions ************************************************************/
gboolean edit_add_window (Dlg_head * h, int y, int x, int lines, int cols,
const vfs_path_t * f, int fline);
WEdit *find_editor (const Dlg_head * h);
gboolean edit_widget_is_editor (const Widget * w);
gboolean edit_drop_hotkey_menu (Dlg_head * h, int key);

View File

@ -448,7 +448,10 @@ edit_load_file (WEdit * edit)
/* If we are dealing with a real file, check that it exists */
if (!check_file_access (edit, edit->filename_vpath, &edit->stat1))
{
edit_clean (edit);
return FALSE;
}
}
else
{
@ -2178,7 +2181,9 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
else
option_line_state_width = 0;
if (edit == NULL)
if (edit != NULL)
edit_purge_widget (edit);
else
{
#ifdef ENABLE_NLS
/*
@ -2208,11 +2213,9 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
}
#endif /* ENABLE_NLS */
edit = g_malloc0 (sizeof (WEdit));
edit->search = NULL;
to_free = TRUE;
}
edit_purge_widget (edit);
edit->drag_state = MCEDIT_DRAG_NORMAL;
edit->widget.y = y;
edit->widget.x = x;
@ -2228,6 +2231,8 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
edit->over_col = 0;
edit->bracket = -1;
edit->force |= REDRAW_PAGE;
/* set file name before load file */
edit_set_filename (edit, filename_vpath);
edit->undo_stack_size = START_STACK_SIZE;

View File

@ -720,8 +720,8 @@ edit_file (const vfs_path_t * _file_vpath, int line)
{
static gboolean made_directory = FALSE;
Dlg_head *edit_dlg;
WEdit *wedit;
WMenuBar *menubar;
gboolean ok;
if (!made_directory)
{
@ -740,11 +740,6 @@ edit_file (const vfs_path_t * _file_vpath, int line)
g_free (dir);
}
wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file_vpath, line);
if (wedit == NULL)
return FALSE;
/* Create a new dialog and add it widgets to it */
edit_dlg =
create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback, NULL,
@ -757,20 +752,18 @@ edit_file (const vfs_path_t * _file_vpath, int line)
add_widget (edit_dlg, menubar);
edit_init_menu (menubar);
init_widget (&wedit->widget, wedit->widget.y, wedit->widget.x,
wedit->widget.lines, wedit->widget.cols, edit_callback, edit_event);
widget_want_cursor (wedit->widget, TRUE);
add_widget (edit_dlg, wedit);
add_widget (edit_dlg, buttonbar_new (TRUE));
run_dlg (edit_dlg);
ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x,
edit_dlg->lines - 2, edit_dlg->cols, _file_vpath, line);
if (edit_dlg->state == DLG_CLOSED)
if (ok)
run_dlg (edit_dlg);
if (!ok || edit_dlg->state == DLG_CLOSED)
destroy_dlg (edit_dlg);
return TRUE;
return ok;
}
/* --------------------------------------------------------------------------------------------- */
@ -782,12 +775,6 @@ edit_get_file_name (const WEdit * edit)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Check if widget is an WEdit class.
*
* @param w probably editor object
* @return TRUE if widget is an WEdit class, FALSE otherwise
*/
WEdit *
find_editor (const Dlg_head * h)
@ -796,6 +783,12 @@ find_editor (const Dlg_head * h)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Check if widget is an WEdit class.
*
* @param w probably editor object
* @return TRUE if widget is an WEdit class, FALSE otherwise
*/
gboolean
edit_widget_is_editor (const Widget * w)
@ -852,6 +845,42 @@ edit_save_size (WEdit * edit)
edit->cols_prev = edit->widget.cols;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Create new editor window and insert it into editor screen.
*
* @param h editor dialog (screen)
* @param y y coordinate
* @param x x coordinate
* @param lines window height
* @param cols window width
* @param f file object
* @param fline line number in file
* @return TRUE if new window was successfully created and inserted into editor screen,
* FALSE otherwise
*/
gboolean
edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path_t *f, int fline)
{
WEdit *edit;
Widget *w;
edit = edit_init (NULL, y, x, lines, cols, f, fline);
if (edit == NULL)
return FALSE;
w = (Widget *) edit;
w->callback = edit_callback;
w->mouse = edit_event;
widget_want_cursor (*w, TRUE);
add_widget (h, w);
dlg_redraw (h);
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Handle move/resize events.