Merge branch '3948_network_connect_from_any_panel'

* 3948_network_connect_from_any_panel:
  Stamp path at panel destroy.
  (vfs_stamp_path): get rid of path conversion.
  (nice_cd): allow create network connection from any panel type.
  Ticket 3948: can't create network link from panel...
This commit is contained in:
Andrew Borodin 2019-01-13 12:37:45 +03:00
commit b52ff8c614
8 changed files with 150 additions and 96 deletions

View File

@ -190,18 +190,15 @@ vfs_rmstamp (struct vfs_class *v, vfsid id)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
vfs_stamp_path (const char *path) vfs_stamp_path (const vfs_path_t * vpath)
{ {
vfsid id; vfsid id;
vfs_path_t *vpath;
const vfs_path_element_t *path_element; const vfs_path_element_t *path_element;
vpath = vfs_path_from_str (path);
path_element = vfs_path_get_by_index (vpath, -1); path_element = vfs_path_get_by_index (vpath, -1);
id = vfs_getid (vpath); id = vfs_getid (vpath);
vfs_addstamp (path_element->class, id); vfs_addstamp (path_element->class, id);
vfs_path_free (vpath);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -264,7 +264,7 @@ const char *vfs_translate_path (const char *path);
/* return new string */ /* return new string */
char *vfs_translate_path_n (const char *path); char *vfs_translate_path_n (const char *path);
void vfs_stamp_path (const char *path); void vfs_stamp_path (const vfs_path_t * path);
void vfs_release_path (const vfs_path_t * vpath); void vfs_release_path (const vfs_path_t * vpath);

View File

@ -715,28 +715,12 @@ panel_listing_box (WPanel * panel, int num, char **userp, char **minip, gboolean
int *brief_cols) int *brief_cols)
{ {
int result = -1; int result = -1;
char *section = NULL; const char *p = NULL;
if (panel == NULL) if (panel == NULL)
{ {
const char *p;
size_t i;
p = get_nth_panel_name (num); p = get_nth_panel_name (num);
panel = g_new (WPanel, 1); panel = panel_empty_new (p);
panel->list_format = list_full;
panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
panel->user_mini_status = FALSE;
for (i = 0; i < LIST_FORMATS; i++)
panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
section = g_strconcat ("Temporal:", p, (char *) NULL);
if (!mc_config_has_group (mc_global.main_config, section))
{
g_free (section);
section = g_strdup (p);
}
panel_load_setup (panel, section);
g_free (section);
} }
{ {
@ -817,7 +801,7 @@ panel_listing_box (WPanel * panel, int num, char **userp, char **minip, gboolean
} }
} }
if (section != NULL) if (p != NULL)
{ {
int i; int i;

View File

@ -428,9 +428,6 @@ nice_cd (const char *text, const char *xtext, const char *help,
char *machine; char *machine;
char *cd_path; char *cd_path;
if (!SELECTED_IS_PANEL)
return;
machine = machine =
input_dialog_help (text, xtext, help, history_name, INPUT_LAST_TEXT, strip_password, input_dialog_help (text, xtext, help, history_name, INPUT_LAST_TEXT, strip_password,
INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES |
@ -457,11 +454,22 @@ nice_cd (const char *text, const char *xtext, const char *help,
} }
{ {
panel_view_mode_t save_type;
vfs_path_t *cd_vpath; vfs_path_t *cd_vpath;
save_type = get_display_type (MENU_PANEL_IDX);
if (save_type != view_listing)
set_display_type (MENU_PANEL_IDX, view_listing);
cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON); cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command)) if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command))
{
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path);
if (save_type != view_listing)
set_display_type (MENU_PANEL_IDX, save_type);
}
vfs_path_free (cd_vpath); vfs_path_free (cd_vpath);
} }
g_free (cd_path); g_free (cd_path);

View File

@ -597,23 +597,23 @@ panel_do_cols (int idx)
/** Save current list_view widget directory into panel */ /** Save current list_view widget directory into panel */
static Widget * static Widget *
restore_into_right_dir_panel (int idx, Widget * from_widget) restore_into_right_dir_panel (int idx, gboolean last_was_panel, int y, int x, int lines, int cols)
{ {
WPanel *new_widget; WPanel *new_widget;
const char *saved_dir = panels[idx].last_saved_dir; const char *p_name;
gboolean last_was_panel = (from_widget && get_display_type (idx) != view_listing);
const char *p_name = get_nth_panel_name (idx); p_name = get_nth_panel_name (idx);
if (last_was_panel) if (last_was_panel)
{ {
vfs_path_t *saved_dir_vpath; vfs_path_t *saved_dir_vpath;
saved_dir_vpath = vfs_path_from_str (saved_dir); saved_dir_vpath = vfs_path_from_str (panels[idx].last_saved_dir);
new_widget = panel_new_with_dir (p_name, saved_dir_vpath); new_widget = panel_sized_with_dir_new (p_name, y, x, lines, cols, saved_dir_vpath);
vfs_path_free (saved_dir_vpath); vfs_path_free (saved_dir_vpath);
} }
else else
new_widget = panel_new (p_name); new_widget = panel_sized_new (p_name, y, x, lines, cols);
return WIDGET (new_widget); return WIDGET (new_widget);
} }
@ -1032,9 +1032,13 @@ set_display_type (int num, panel_view_mode_t type)
{ {
case view_nothing: case view_nothing:
case view_listing: case view_listing:
new_widget = restore_into_right_dir_panel (num, old_widget); {
widget_set_size (new_widget, y, x, lines, cols); gboolean last_was_panel;
last_was_panel = old_widget != NULL && get_display_type (num) != view_listing;
new_widget = restore_into_right_dir_panel (num, last_was_panel, y, x, lines, cols);
break; break;
}
case view_info: case view_info:
new_widget = WIDGET (info_new (y, x, lines, cols)); new_widget = WIDGET (info_new (y, x, lines, cols));

View File

@ -899,18 +899,10 @@ done_mc (void)
* We sync the profiles since the hotlist may have changed, while * We sync the profiles since the hotlist may have changed, while
* we only change the setup data if we have the auto save feature set * we only change the setup data if we have the auto save feature set
*/ */
const char *curr_dir;
save_setup (auto_save_setup, panels_options.auto_save_setup); save_setup (auto_save_setup, panels_options.auto_save_setup);
curr_dir = vfs_get_current_dir (); vfs_stamp_path (vfs_get_raw_current_dir ());
vfs_stamp_path (curr_dir);
if ((current_panel != NULL) && (get_current_type () == view_listing))
vfs_stamp_path (vfs_path_as_str (current_panel->cwd_vpath));
if ((other_panel != NULL) && (get_other_type () == view_listing))
vfs_stamp_path (vfs_path_as_str (other_panel->cwd_vpath));
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -3721,6 +3721,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
return panel_execute_cmd (panel, parm); return panel_execute_cmd (panel, parm);
case MSG_DESTROY: case MSG_DESTROY:
vfs_stamp_path (panel->cwd_vpath);
/* unsubscribe from "history_load" event */ /* unsubscribe from "history_load" event */
mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w); mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w);
/* unsubscribe from "history_save" event */ /* unsubscribe from "history_save" event */
@ -4274,81 +4275,53 @@ panel_set_lwd (WPanel * panel, const vfs_path_t * vpath)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Panel creation for specified directory. * Creatie an empty panel with specified size.
* *
* @param panel_name specifies the name of the panel for setup retieving * @param panel_name name of panel for setup retieving
* @param wpath the path of working panel directory. If path is NULL then panel will be created
* for current directory
* *
* @return new instance of WPanel * @return new instance of WPanel
*/ */
WPanel * WPanel *
panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath) panel_sized_empty_new (const char *panel_name, int y, int x, int lines, int cols)
{ {
WPanel *panel; WPanel *panel;
Widget *w; Widget *w;
char *section; char *section;
int i, err; int i, err;
char *curdir = NULL;
panel = g_new0 (WPanel, 1); panel = g_new0 (WPanel, 1);
w = WIDGET (panel); w = WIDGET (panel);
/* No know sizes of the panel at startup */ widget_init (w, y, x, lines, cols, panel_callback, panel_mouse_callback);
widget_init (w, 0, 0, 0, 0, panel_callback, panel_mouse_callback);
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT; w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
if (vpath != NULL)
{
curdir = _vfs_get_cwd ();
panel_set_cwd (panel, vpath);
}
else
{
vfs_setup_cwd ();
panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
}
panel_set_lwd (panel, vfs_get_raw_current_dir ());
panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
/* directories history will be get later */
panel->dir.size = DIR_LIST_MIN_SIZE; panel->dir.size = DIR_LIST_MIN_SIZE;
panel->dir.list = g_new (file_entry_t, panel->dir.size); panel->dir.list = g_new (file_entry_t, panel->dir.size);
panel->dir.len = 0; panel->dir.len = 0;
panel->active = 0;
panel->filter = NULL;
panel->list_cols = 1; panel->list_cols = 1;
panel->brief_cols = 2; panel->brief_cols = 2;
panel->top_file = 0;
panel->selected = 0;
panel->marked = 0;
panel->total = 0;
panel->dirty = 1; panel->dirty = 1;
panel->searching = FALSE;
panel->dirs_marked = 0;
panel->is_panelized = FALSE;
panel->format = NULL;
panel->status_format = NULL;
panel->format_modified = 1; panel->format_modified = 1;
panel->content_shift = -1; panel->content_shift = -1;
panel->max_shift = -1; panel->max_shift = -1;
panel->panel_name = g_strdup (panel_name); panel->list_format = list_full;
panel->user_format = g_strdup (DEFAULT_USER_FORMAT); panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
for (i = 0; i < LIST_FORMATS; i++)
panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
panel->codepage = SELECT_CHARSET_NO_TRANSLATE; panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
#endif #endif
for (i = 0; i < LIST_FORMATS; i++)
panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
panel->search_buffer[0] = '\0';
panel->prev_search_buffer[0] = '\0';
panel->frame_size = frame_half; panel->frame_size = frame_half;
panel->panel_name = g_strdup (panel_name);
panel->hist_name = g_strconcat ("Dir Hist ", panel->panel_name, (char *) NULL);
/* directories history will be get later */
section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); section = g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
if (!mc_config_has_group (mc_global.main_config, section)) if (!mc_config_has_group (mc_global.main_config, section))
{ {
@ -4363,14 +4336,52 @@ panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath)
if (err != 0) if (err != 0)
set_panel_formats (panel); set_panel_formats (panel);
#ifdef HAVE_CHARSET return panel;
{ }
const vfs_path_element_t *path_element;
/* --------------------------------------------------------------------------------------------- */
/**
* Panel creation for specified size and directory.
*
* @param panel_name name of panel for setup retieving
* @param y y coordinate of top-left corner
* @param x x coordinate of top-left corner
* @param lines vertical size
* @param cols horizontal size
* @param vpath working panel directory. If NULL then current directory is used
*
* @return new instance of WPanel
*/
WPanel *
panel_sized_with_dir_new (const char *panel_name, int y, int x, int lines, int cols,
const vfs_path_t * vpath)
{
WPanel *panel;
char *curdir = NULL;
#ifdef HAVE_CHARSET
const vfs_path_element_t *path_element;
#endif
panel = panel_sized_empty_new (panel_name, y, x, lines, cols);
if (vpath != NULL)
{
curdir = _vfs_get_cwd ();
panel_set_cwd (panel, vpath);
}
else
{
vfs_setup_cwd ();
panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
}
panel_set_lwd (panel, vfs_get_raw_current_dir ());
#ifdef HAVE_CHARSET
path_element = vfs_path_get_by_index (panel->cwd_vpath, -1); path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
if (path_element->encoding != NULL) if (path_element->encoding != NULL)
panel->codepage = get_codepage_index (path_element->encoding); panel->codepage = get_codepage_index (path_element->encoding);
}
#endif #endif
if (mc_chdir (panel->cwd_vpath) != 0) if (mc_chdir (panel->cwd_vpath) != 0)
@ -4391,10 +4402,12 @@ panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath)
if (curdir != NULL) if (curdir != NULL)
{ {
vfs_path_t *tmp_vpath; vfs_path_t *tmp_vpath;
int err;
tmp_vpath = vfs_path_from_str (curdir); tmp_vpath = vfs_path_from_str (curdir);
err = mc_chdir (tmp_vpath); err = mc_chdir (tmp_vpath);
vfs_path_free (tmp_vpath); vfs_path_free (tmp_vpath);
(void) err;
} }
g_free (curdir); g_free (curdir);

View File

@ -153,7 +153,10 @@ extern mc_fhl_t *mc_filehighlight;
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
WPanel *panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath); WPanel *panel_sized_empty_new (const char *panel_name, int y, int x, int lines, int cols);
WPanel *panel_sized_with_dir_new (const char *panel_name, int y, int x, int lines, int cols,
const vfs_path_t * vpath);
void panel_clean_dir (WPanel * panel); void panel_clean_dir (WPanel * panel);
void panel_reload (WPanel * panel); void panel_reload (WPanel * panel);
@ -195,11 +198,45 @@ gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Empty panel creation.
*
* @param panel_name name of panel for setup retieving
*
* @return new instance of WPanel
*/
static inline WPanel *
panel_empty_new (const char *panel_name)
{
/* Unknown sizes of the panel at startup */
return panel_sized_empty_new (panel_name, 0, 0, 1, 1);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Panel creation for specified directory.
*
* @param panel_name name of panel for setup retieving
* @param vpath working panel directory. If NULL then current directory is used
*
* @return new instance of WPanel
*/
static inline WPanel *
panel_with_dir_new (const char *panel_name, const vfs_path_t * vpath)
{
/* Unknown sizes of the panel at startup */
return panel_sized_with_dir_new (panel_name, 0, 0, 1, 1, vpath);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Panel creation. * Panel creation.
* *
* @param panel_name the name of the panel for setup retieving * @param panel_name name of panel for setup retieving
* *
* @return new instance of WPanel * @return new instance of WPanel
*/ */
@ -207,7 +244,26 @@ gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
static inline WPanel * static inline WPanel *
panel_new (const char *panel_name) panel_new (const char *panel_name)
{ {
return panel_new_with_dir (panel_name, NULL); return panel_with_dir_new (panel_name, NULL);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Panel creation with specified size.
*
* @param panel_name name of panel for setup retieving
* @param y y coordinate of top-left corner
* @param x x coordinate of top-left corner
* @param lines vertical size
* @param cols horizontal size
*
* @return new instance of WPanel
*/
static inline WPanel *
panel_sized_new (const char *panel_name, int y, int x, int lines, int cols)
{
return panel_sized_with_dir_new (panel_name, y, x, lines, cols, NULL);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */