Refactoring.

(restore_into_right_dir_panel): made static.
(panel_update_cols): moved from panel.[ch] to layout.[ch].
(set_display_type): minor cleanup and type accuracy.
(panel_display_t): type accuracy

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2011-01-14 14:27:25 +03:00
parent c7fdc8f95b
commit 57cdd0a08a
4 changed files with 67 additions and 73 deletions

View File

@ -587,6 +587,25 @@ panel_do_cols (int idx)
panel_update_cols (panels[idx].widget, frame_half);
}
/* --------------------------------------------------------------------------------------------- */
/** Save current list_view widget directory into panel */
static Widget *
restore_into_right_dir_panel (int idx, Widget * from_widget)
{
Widget *new_widget = NULL;
const char *saved_dir = panels[idx].last_saved_dir;
gboolean last_was_panel = (from_widget && get_display_type (idx) != view_listing);
const char *p_name = get_nth_panel_name (idx);
if (last_was_panel)
new_widget = (Widget *) panel_new_with_dir (p_name, saved_dir);
else
new_widget = (Widget *) panel_new (p_name);
return new_widget;
}
/* --------------------------------------------------------------------------------------------- */
static inline void
@ -966,7 +985,7 @@ void
set_display_type (int num, panel_view_mode_t type)
{
int x = 0, y = 0, cols = 0, lines = 0;
int the_other = 0; /* Index to the other panel */
unsigned int the_other = 0; /* Index to the other panel */
const char *file_name = NULL; /* For Quick view */
Widget *new_widget = NULL, *old_widget = NULL;
WPanel *the_other_panel = NULL;
@ -986,16 +1005,16 @@ set_display_type (int num, panel_view_mode_t type)
}
/* Get rid of it */
if (panels[num].widget)
if (panels[num].widget != NULL)
{
Widget *w = panels[num].widget;
WPanel *panel = (WPanel *) panels[num].widget;
WPanel *panel = (WPanel *) w;
x = w->x;
y = w->y;
cols = w->cols;
lines = w->lines;
old_widget = panels[num].widget;
old_widget = w;
if (panels[num].type == view_listing)
{
@ -1056,7 +1075,7 @@ set_display_type (int num, panel_view_mode_t type)
/* We use replace to keep the circular list of the dialog in the */
/* same state. Maybe we could just kill it and then replace it */
if ((midnight_dlg != NULL) && (old_widget != NULL))
dlg_replace_widget (old_widget, panels[num].widget);
dlg_replace_widget (old_widget, new_widget);
if (type == view_listing)
{
@ -1082,12 +1101,49 @@ set_display_type (int num, panel_view_mode_t type)
* - as long as you stay in the left panel almost everything that uses
* current_panel causes segfault, e.g. C-Enter, C-x c, ...
*/
if ((type != view_listing) && (current_panel == (WPanel *) old_widget))
current_panel = num == 0 ? right_panel : left_panel;
g_free (old_widget);
}
/* --------------------------------------------------------------------------------------------- */
void
panel_update_cols (Widget * widget, panel_display_t frame_size)
{
int cols, origin;
/* don't touch panel if it is not in dialog yet */
/* if panel is not in dialog it is not in widgets list
and cannot be compared with get_panel_widget() result */
if (widget->owner == NULL)
return;
if (horizontal_split)
{
widget->cols = COLS;
return;
}
if (frame_size == frame_full)
{
cols = COLS;
origin = 0;
}
else if (widget == get_panel_widget (0))
{
cols = first_panel_size;
origin = 0;
}
else
{
cols = COLS - first_panel_size;
origin = first_panel_size;
}
widget->cols = cols;
widget->x = origin;
}
/* --------------------------------------------------------------------------------------------- */
/** This routine is deeply sticked to the two panels idea.
@ -1293,25 +1349,6 @@ save_panel_dir (int idx)
}
}
/* --------------------------------------------------------------------------------------------- */
/** Save current list_view widget directory into panel */
Widget *
restore_into_right_dir_panel (int idx, Widget * from_widget)
{
Widget *new_widget = NULL;
const char *saved_dir = panels[idx].last_saved_dir;
gboolean last_was_panel = (from_widget && get_display_type (idx) != view_listing);
const char *p_name = get_nth_panel_name (idx);
if (last_was_panel)
new_widget = (Widget *) panel_new_with_dir (p_name, saved_dir);
else
new_widget = (Widget *) panel_new (p_name);
return new_widget;
}
/* --------------------------------------------------------------------------------------------- */
/** Return working dir, if it's view_listing - cwd,
but for other types - last_saved_dir */

View File

@ -42,6 +42,7 @@ void destroy_panels (void);
void sigwinch_handler (int dummy);
void change_screen_size (void);
void set_display_type (int num, panel_view_mode_t type);
void panel_update_cols (Widget * widget, panel_display_t frame_size);
void swap_panels (void);
panel_view_mode_t get_display_type (int idx);
panel_view_mode_t get_current_type (void);
@ -55,7 +56,6 @@ struct Widget *get_panel_widget (int idx);
struct WPanel *get_other_panel (void);
void save_panel_dir (int idx);
Widget *restore_into_right_dir_panel (int idx, Widget * from_widget);
const char *get_panel_dir_for (const WPanel * widget);
void set_hintbar (const char *str);

View File

@ -1373,7 +1373,7 @@ paint_frame (WPanel * panel)
static const char *
parse_panel_size (WPanel * panel, const char *format, int isstatus)
{
int frame = frame_half;
panel_display_t frame = frame_half;
format = skip_separators (format);
if (!strncmp (format, "full", 4))
@ -3446,48 +3446,6 @@ try_to_select (WPanel * panel, const char *name)
/* --------------------------------------------------------------------------------------------- */
void
panel_update_cols (Widget * widget, int frame_size)
{
int cols, origin;
/* don't touch panel if it is not in dialog yet */
/* if panel is not in dialog it is not in widgets list
and cannot be compared with get_panel_widget() result */
if (widget->owner == NULL)
return;
if (horizontal_split)
{
widget->cols = COLS;
return;
}
if (frame_size == frame_full)
{
cols = COLS;
origin = 0;
}
else
{
if (widget == get_panel_widget (0))
{
cols = first_panel_size;
origin = 0;
}
else
{
cols = COLS - first_panel_size;
origin = first_panel_size;
}
}
widget->cols = cols;
widget->x = origin;
}
/* --------------------------------------------------------------------------------------------- */
void
panel_clean_dir (WPanel * panel)
{

View File

@ -44,11 +44,11 @@ typedef enum
view_nothing = 4, /* Undefined */
} panel_view_mode_t;
enum panel_display_enum
typedef enum
{
frame_full, /* full screen frame */
frame_half /* half screen frame */
};
} panel_display_t;
typedef enum
{
@ -102,7 +102,7 @@ typedef struct WPanel
int selected; /* Index to the selected file */
int split; /* Split panel to allow two columns */
int is_panelized; /* Flag: special filelisting, can't reload */
int frame_size; /* half or full frame */
panel_display_t frame_size; /* half or full frame */
char *filter; /* File name filter */
panel_sort_info_t sort_info; /* Sort descriptor */
@ -151,7 +151,6 @@ void panel_change_encoding (WPanel * panel);
void update_dirty_panels (void);
void update_panels (panel_update_flags_t flags, const char *current_file);
void panel_update_cols (Widget * widget, int frame_size);
int set_panel_formats (WPanel * p);
void try_to_select (WPanel * panel, const char *name);