mirror of https://github.com/MidnightCommander/mc
Moved panel update functions from main.c to screen.c.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
c43bb6f576
commit
5cd4a8ad83
|
@ -37,6 +37,7 @@
|
|||
#include "layout.h"
|
||||
#include "dialog.h"
|
||||
#include "wtools.h"
|
||||
#include "panel.h" /* update_panels() */
|
||||
#include "execute.h"
|
||||
#include "../vfs/vfs.h"
|
||||
|
||||
|
|
127
src/main.c
127
src/main.c
|
@ -304,133 +304,6 @@ char *mc_home_alt = NULL;
|
|||
|
||||
char cmd_buf[512];
|
||||
|
||||
static void
|
||||
reload_panelized (WPanel *panel)
|
||||
{
|
||||
int i, j;
|
||||
dir_list *list = &panel->dir;
|
||||
|
||||
if (panel != current_panel)
|
||||
mc_chdir (panel->cwd);
|
||||
|
||||
for (i = 0, j = 0; i < panel->count; i++) {
|
||||
if (list->list[i].f.marked) {
|
||||
/* Unmark the file in advance. In case the following mc_lstat
|
||||
* fails we are done, else we have to mark the file again
|
||||
* (Note: do_file_mark depends on a valid "list->list [i].buf").
|
||||
* IMO that's the best way to update the panel's summary status
|
||||
* -- Norbert
|
||||
*/
|
||||
do_file_mark (panel, i, 0);
|
||||
}
|
||||
if (mc_lstat (list->list[i].fname, &list->list[i].st)) {
|
||||
g_free (list->list[i].fname);
|
||||
continue;
|
||||
}
|
||||
if (list->list[i].f.marked)
|
||||
do_file_mark (panel, i, 1);
|
||||
if (j != i)
|
||||
list->list[j] = list->list[i];
|
||||
j++;
|
||||
}
|
||||
if (j == 0)
|
||||
panel->count = set_zero_dir (list);
|
||||
else
|
||||
panel->count = j;
|
||||
|
||||
if (panel != current_panel)
|
||||
mc_chdir (current_panel->cwd);
|
||||
}
|
||||
|
||||
static void
|
||||
update_one_panel_widget (WPanel *panel, int force_update,
|
||||
const char *current_file)
|
||||
{
|
||||
int free_pointer;
|
||||
char *my_current_file = NULL;
|
||||
|
||||
if (force_update & UP_RELOAD) {
|
||||
panel->is_panelized = 0;
|
||||
mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
|
||||
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
|
||||
}
|
||||
|
||||
/* If current_file == -1 (an invalid pointer) then preserve selection */
|
||||
if (current_file == UP_KEEPSEL) {
|
||||
free_pointer = 1;
|
||||
my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
|
||||
current_file = my_current_file;
|
||||
} else
|
||||
free_pointer = 0;
|
||||
|
||||
if (panel->is_panelized)
|
||||
reload_panelized (panel);
|
||||
else
|
||||
panel_reload (panel);
|
||||
|
||||
try_to_select (panel, current_file);
|
||||
panel->dirty = 1;
|
||||
|
||||
if (free_pointer)
|
||||
g_free (my_current_file);
|
||||
}
|
||||
|
||||
void
|
||||
panel_clean_dir (WPanel *panel)
|
||||
{
|
||||
int count = panel->count;
|
||||
|
||||
panel->count = 0;
|
||||
panel->top_file = 0;
|
||||
panel->selected = 0;
|
||||
panel->marked = 0;
|
||||
panel->dirs_marked = 0;
|
||||
panel->total = 0;
|
||||
panel->searching = 0;
|
||||
panel->is_panelized = 0;
|
||||
panel->dirty = 1;
|
||||
|
||||
clean_dir (&panel->dir, count);
|
||||
}
|
||||
|
||||
static void
|
||||
update_one_panel (int which, int force_update, const char *current_file)
|
||||
{
|
||||
WPanel *panel;
|
||||
|
||||
if (get_display_type (which) != view_listing)
|
||||
return;
|
||||
|
||||
panel = (WPanel *) get_panel_widget (which);
|
||||
update_one_panel_widget (panel, force_update, current_file);
|
||||
}
|
||||
|
||||
/* This routine reloads the directory in both panels. It tries to
|
||||
* select current_file in current_panel and other_file in other_panel.
|
||||
* If current_file == -1 then it automatically sets current_file and
|
||||
* other_file to the currently selected files in the panels.
|
||||
*
|
||||
* if force_update has the UP_ONLY_CURRENT bit toggled on, then it
|
||||
* will not reload the other panel.
|
||||
*/
|
||||
void
|
||||
update_panels (int force_update, const char *current_file)
|
||||
{
|
||||
int reload_other = !(force_update & UP_ONLY_CURRENT);
|
||||
WPanel *panel;
|
||||
|
||||
update_one_panel (get_current_index (), force_update, current_file);
|
||||
if (reload_other)
|
||||
update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
|
||||
|
||||
if (get_current_type () == view_listing)
|
||||
panel = (WPanel *) get_panel_widget (get_current_index ());
|
||||
else
|
||||
panel = (WPanel *) get_panel_widget (get_other_index ());
|
||||
|
||||
mc_chdir (panel->cwd);
|
||||
}
|
||||
|
||||
/* Save current stat of directories to avoid reloading the panels */
|
||||
/* when no modifications have taken place */
|
||||
void
|
||||
|
|
|
@ -12,12 +12,6 @@ void toggle_mix_all_files (void);
|
|||
void toggle_show_backup (void);
|
||||
void toggle_show_hidden (void);
|
||||
|
||||
#define UP_OPTIMIZE 0
|
||||
#define UP_RELOAD 1
|
||||
#define UP_ONLY_CURRENT 2
|
||||
|
||||
#define UP_KEEPSEL ((char *) -1)
|
||||
|
||||
extern int quote;
|
||||
extern volatile int quit;
|
||||
|
||||
|
@ -85,7 +79,6 @@ typedef struct {
|
|||
key_callback fn;
|
||||
} key_map;
|
||||
|
||||
void update_panels (int force_update, const char *current_file);
|
||||
void do_update_prompt (void);
|
||||
|
||||
enum cd_enum {
|
||||
|
|
|
@ -97,7 +97,14 @@ void panel_set_sort_order (WPanel *panel, sortfn *sort_order);
|
|||
void panel_re_sort (WPanel *panel);
|
||||
void set_panel_encoding (WPanel *);
|
||||
|
||||
#define UP_OPTIMIZE 0
|
||||
#define UP_RELOAD 1
|
||||
#define UP_ONLY_CURRENT 2
|
||||
|
||||
#define UP_KEEPSEL ((char *) -1)
|
||||
|
||||
void update_dirty_panels (void);
|
||||
void update_panels (int force_update, const char *current_file);
|
||||
void panel_update_cols (Widget *widget, int frame_size);
|
||||
int set_panel_formats (WPanel *p);
|
||||
|
||||
|
|
127
src/screen.c
127
src/screen.c
|
@ -1043,6 +1043,24 @@ panel_save_name (WPanel *panel)
|
|||
return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
|
||||
}
|
||||
|
||||
void
|
||||
panel_clean_dir (WPanel *panel)
|
||||
{
|
||||
int count = panel->count;
|
||||
|
||||
panel->count = 0;
|
||||
panel->top_file = 0;
|
||||
panel->selected = 0;
|
||||
panel->marked = 0;
|
||||
panel->dirs_marked = 0;
|
||||
panel->total = 0;
|
||||
panel->searching = 0;
|
||||
panel->is_panelized = 0;
|
||||
panel->dirty = 1;
|
||||
|
||||
clean_dir (&panel->dir, count);
|
||||
}
|
||||
|
||||
static void
|
||||
panel_destroy (WPanel *p)
|
||||
{
|
||||
|
@ -2672,3 +2690,112 @@ set_panel_encoding (WPanel *panel)
|
|||
g_free (cd_path);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
reload_panelized (WPanel *panel)
|
||||
{
|
||||
int i, j;
|
||||
dir_list *list = &panel->dir;
|
||||
|
||||
if (panel != current_panel)
|
||||
mc_chdir (panel->cwd);
|
||||
|
||||
for (i = 0, j = 0; i < panel->count; i++) {
|
||||
if (list->list[i].f.marked) {
|
||||
/* Unmark the file in advance. In case the following mc_lstat
|
||||
* fails we are done, else we have to mark the file again
|
||||
* (Note: do_file_mark depends on a valid "list->list [i].buf").
|
||||
* IMO that's the best way to update the panel's summary status
|
||||
* -- Norbert
|
||||
*/
|
||||
do_file_mark (panel, i, 0);
|
||||
}
|
||||
if (mc_lstat (list->list[i].fname, &list->list[i].st)) {
|
||||
g_free (list->list[i].fname);
|
||||
continue;
|
||||
}
|
||||
if (list->list[i].f.marked)
|
||||
do_file_mark (panel, i, 1);
|
||||
if (j != i)
|
||||
list->list[j] = list->list[i];
|
||||
j++;
|
||||
}
|
||||
if (j == 0)
|
||||
panel->count = set_zero_dir (list);
|
||||
else
|
||||
panel->count = j;
|
||||
|
||||
if (panel != current_panel)
|
||||
mc_chdir (current_panel->cwd);
|
||||
}
|
||||
|
||||
static void
|
||||
update_one_panel_widget (WPanel *panel, int force_update,
|
||||
const char *current_file)
|
||||
{
|
||||
int free_pointer;
|
||||
char *my_current_file = NULL;
|
||||
|
||||
if (force_update & UP_RELOAD) {
|
||||
panel->is_panelized = 0;
|
||||
mc_setctl (panel->cwd, VFS_SETCTL_FLUSH, 0);
|
||||
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
|
||||
}
|
||||
|
||||
/* If current_file == -1 (an invalid pointer) then preserve selection */
|
||||
if (current_file == UP_KEEPSEL) {
|
||||
free_pointer = 1;
|
||||
my_current_file = g_strdup (panel->dir.list[panel->selected].fname);
|
||||
current_file = my_current_file;
|
||||
} else
|
||||
free_pointer = 0;
|
||||
|
||||
if (panel->is_panelized)
|
||||
reload_panelized (panel);
|
||||
else
|
||||
panel_reload (panel);
|
||||
|
||||
try_to_select (panel, current_file);
|
||||
panel->dirty = 1;
|
||||
|
||||
if (free_pointer)
|
||||
g_free (my_current_file);
|
||||
}
|
||||
|
||||
static void
|
||||
update_one_panel (int which, int force_update, const char *current_file)
|
||||
{
|
||||
WPanel *panel;
|
||||
|
||||
if (get_display_type (which) != view_listing)
|
||||
return;
|
||||
|
||||
panel = (WPanel *) get_panel_widget (which);
|
||||
update_one_panel_widget (panel, force_update, current_file);
|
||||
}
|
||||
|
||||
/* This routine reloads the directory in both panels. It tries to
|
||||
* select current_file in current_panel and other_file in other_panel.
|
||||
* If current_file == -1 then it automatically sets current_file and
|
||||
* other_file to the currently selected files in the panels.
|
||||
*
|
||||
* if force_update has the UP_ONLY_CURRENT bit toggled on, then it
|
||||
* will not reload the other panel.
|
||||
*/
|
||||
void
|
||||
update_panels (int force_update, const char *current_file)
|
||||
{
|
||||
int reload_other = !(force_update & UP_ONLY_CURRENT);
|
||||
WPanel *panel;
|
||||
|
||||
update_one_panel (get_current_index (), force_update, current_file);
|
||||
if (reload_other)
|
||||
update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
|
||||
|
||||
if (get_current_type () == view_listing)
|
||||
panel = (WPanel *) get_panel_widget (get_current_index ());
|
||||
else
|
||||
panel = (WPanel *) get_panel_widget (get_other_index ());
|
||||
|
||||
mc_chdir (panel->cwd);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue