mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
1999-09-20 Federico Mena Quintero <federico@redhat.com>
The following is a patch from Volker Braun <volker.braun@physik.hu-berlin.de> to fix column resizing in the file panels. * gcustom-layout.c (custom_layout_apply): Set the default_user_format to the new format. * gscreen.c (panel_fill_panel_list): Set the column widths according to the previously stored values. Nuked the old and hideous panel_file_list_configure_contents(). (panel_file_list_configure): Connect to resize_column in the clist. (panel_create_file_list): Do not connect to size_allocate. (x_create_panel): Set the column width array for this panel. Set the user format from the default one if it exists. * gsession.c (PanelInfo): Added information about column widths and the user format. (save_panel_info): Save the complete information. (load_panel_info): Load the complete information. (free_panel_info): Free the user format. (idle_create_panels): Set the user format and column widths. 1999-09-20 Federico Mena Quintero <federico@redhat.com> The following is a patch from Volker Braun <volker.braun@physik.hu-berlin.de> to fix column resizing in the file panels. * setup.c (options): Declare the column width option values. (save_configure): Save the default user format. (load_setup): Load the default user format. * panel.h (WPanel): Added a field for the column widths.
This commit is contained in:
parent
0045150f92
commit
248d2ef5cc
@ -1,3 +1,27 @@
|
||||
1999-09-20 Federico Mena Quintero <federico@redhat.com>
|
||||
|
||||
The following is a patch from Volker Braun
|
||||
<volker.braun@physik.hu-berlin.de> to fix column resizing in the
|
||||
file panels.
|
||||
|
||||
* gcustom-layout.c (custom_layout_apply): Set the
|
||||
default_user_format to the new format.
|
||||
|
||||
* gscreen.c (panel_fill_panel_list): Set the column widths
|
||||
according to the previously stored values.
|
||||
Nuked the old and hideous panel_file_list_configure_contents().
|
||||
(panel_file_list_configure): Connect to resize_column in the clist.
|
||||
(panel_create_file_list): Do not connect to size_allocate.
|
||||
(x_create_panel): Set the column width array for this panel. Set
|
||||
the user format from the default one if it exists.
|
||||
|
||||
* gsession.c (PanelInfo): Added information about column widths
|
||||
and the user format.
|
||||
(save_panel_info): Save the complete information.
|
||||
(load_panel_info): Load the complete information.
|
||||
(free_panel_info): Free the user format.
|
||||
(idle_create_panels): Set the user format and column widths.
|
||||
|
||||
1999-09-20 Federico Mena Quintero <federico@redhat.com>
|
||||
|
||||
* gdesktop.c (desktop_rescan_devices): Call gmount_setup_devices().
|
||||
|
@ -324,6 +324,9 @@ custom_layout_apply (GCustomLayout *layout)
|
||||
g_free (container->panel->user_format);
|
||||
container->panel->user_format = g_strdup (format);
|
||||
|
||||
g_free (default_user_format);
|
||||
default_user_format = g_strdup (format);
|
||||
|
||||
set_panel_formats (container->panel);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
|
164
gnome/gscreen.c
164
gnome/gscreen.c
@ -45,6 +45,21 @@
|
||||
# define MAX(a,b) ((a) > (b) ? a : b)
|
||||
#endif
|
||||
|
||||
/* Offsets within the default_column_width array for the different listing types */
|
||||
static const int column_width_pos[LIST_TYPES] = {
|
||||
GMC_COLUMNS_BRIEF,
|
||||
0,
|
||||
-1,
|
||||
GMC_COLUMNS_BRIEF + GMC_COLUMNS_DETAILED,
|
||||
-1
|
||||
};
|
||||
|
||||
/* Default column widths for file listings */
|
||||
int default_column_width[GMC_COLUMNS];
|
||||
|
||||
/* default format for custom view */
|
||||
char* default_user_format = NULL;
|
||||
|
||||
/* Whether to display the tree view on the left */
|
||||
int tree_panel_visible = -1;
|
||||
|
||||
@ -184,6 +199,7 @@ panel_fill_panel_list (WPanel *panel)
|
||||
const int selected = panel->selected;
|
||||
GtkCList *cl = CLIST_FROM_SW (panel->list);
|
||||
int i, col, type_col, color;
|
||||
int width, p;
|
||||
char **texts;
|
||||
|
||||
texts = g_new (char *, items + 1);
|
||||
@ -241,6 +257,16 @@ panel_fill_panel_list (WPanel *panel)
|
||||
/* This is needed as the gtk_clist_append changes selected under us :-( */
|
||||
panel->selected = selected;
|
||||
|
||||
p = column_width_pos[panel->list_type]; /* offset in column_width */
|
||||
g_assert (p >= 0);
|
||||
for (i = 0; i < items; i++) {
|
||||
width = panel->column_width[p + i];
|
||||
if (width == 0)
|
||||
width = gtk_clist_optimal_column_width (cl, i);
|
||||
|
||||
gtk_clist_set_column_width (cl, i, width);
|
||||
}
|
||||
|
||||
gtk_clist_thaw (GTK_CLIST (cl));
|
||||
}
|
||||
|
||||
@ -391,104 +417,6 @@ x_adjust_top_file (WPanel *panel)
|
||||
/* gtk_clist_moveto (GTK_CLIST (panel->list), panel->top_file, 0, 0.0, 0.0); */
|
||||
}
|
||||
|
||||
/*
|
||||
* These two constants taken from Gtk sources, hack to figure out how much
|
||||
* of the clist is visible
|
||||
*/
|
||||
#define COLUMN_INSET 3
|
||||
#define CELL_SPACING 1
|
||||
|
||||
/*
|
||||
* Configures the columns title sizes for the panel->list CList widget
|
||||
*/
|
||||
static void
|
||||
panel_file_list_configure_contents (GtkWidget *sw, WPanel *panel, int main_width, int height)
|
||||
{
|
||||
GtkCList *clist;
|
||||
format_e *format = panel->format;
|
||||
int i, used_columns, expandables, items;
|
||||
int char_width, usable_pixels, extra_pixels, width;
|
||||
int total_columns, extra_columns;
|
||||
int expand_space, extra_space, shrink_space;
|
||||
int lost_pixels, display_the_mini_info;
|
||||
|
||||
/* Pass 1: Count minimum columns,
|
||||
* set field_len to default to the requested_field_len
|
||||
* and compute how much space we lost to the column decorations
|
||||
*/
|
||||
lost_pixels = used_columns = expandables = items = 0;
|
||||
char_width = gdk_string_width (sw->style->font, "xW") / 2;
|
||||
for (format = panel->format; format; format = format->next) {
|
||||
format->field_len = format->requested_field_len;
|
||||
if (!format->use_in_gui)
|
||||
continue;
|
||||
|
||||
if (format->use_in_gui == 2)
|
||||
used_columns += 2;
|
||||
else
|
||||
used_columns += format->field_len;
|
||||
|
||||
items++;
|
||||
if (format->expand)
|
||||
expandables++;
|
||||
lost_pixels += CELL_SPACING + (2 * COLUMN_INSET);
|
||||
}
|
||||
|
||||
/* The left scrollbar might take some space from us, use this information */
|
||||
if (GTK_WIDGET_VISIBLE (GTK_SCROLLED_WINDOW (sw)->vscrollbar)) {
|
||||
int scrollbar_width = GTK_WIDGET (GTK_SCROLLED_WINDOW (sw)->vscrollbar)->requisition.width;
|
||||
int scrollbar_space = GTK_SCROLLED_WINDOW_CLASS (GTK_OBJECT (sw)->klass)->scrollbar_spacing;
|
||||
|
||||
lost_pixels += scrollbar_space + scrollbar_width;
|
||||
}
|
||||
|
||||
width = main_width - lost_pixels;
|
||||
|
||||
extra_pixels = width % char_width;
|
||||
usable_pixels = width - extra_pixels;
|
||||
total_columns = usable_pixels / char_width;
|
||||
extra_columns = total_columns - used_columns;
|
||||
if (extra_columns > 0 && expandables > 0) {
|
||||
expand_space = extra_columns / expandables;
|
||||
extra_space = extra_columns % expandables;
|
||||
} else
|
||||
extra_space = expand_space = 0;
|
||||
|
||||
/*
|
||||
* Hack: the default mini-info display only gets displayed
|
||||
* if panel->estimated_total is not zero, ie, if this has been
|
||||
* initialized for the first time.
|
||||
*/
|
||||
|
||||
display_the_mini_info = (panel->estimated_total == 0);
|
||||
panel->estimated_total = total_columns;
|
||||
|
||||
if (display_the_mini_info)
|
||||
display_mini_info (panel);
|
||||
|
||||
/* If we dont have enough space, shorten the fields */
|
||||
if (used_columns > total_columns) {
|
||||
expand_space = 0;
|
||||
shrink_space = (used_columns - total_columns) / items;
|
||||
} else
|
||||
shrink_space = 0;
|
||||
|
||||
clist = CLIST_FROM_SW (sw);
|
||||
|
||||
gtk_clist_freeze (clist);
|
||||
|
||||
for (i = 0, format = panel->format; format; format = format->next) {
|
||||
if (!format->use_in_gui)
|
||||
continue;
|
||||
|
||||
format->field_len += (format->expand ? expand_space : 0) - shrink_space;
|
||||
gtk_clist_set_column_width (clist, i, format->field_len * char_width);
|
||||
i++;
|
||||
}
|
||||
|
||||
gtk_clist_thaw (clist);
|
||||
}
|
||||
|
||||
static void
|
||||
panel_file_list_select_row (GtkWidget *file_list, gint row, gint column,
|
||||
GdkEvent *event, gpointer data)
|
||||
@ -516,28 +444,19 @@ panel_file_list_unselect_row (GtkWidget *widget, int row, int columns, GdkEvent
|
||||
panel->selected = 0;
|
||||
}
|
||||
|
||||
/* Figure out the number of visible lines in the panel */
|
||||
static void
|
||||
panel_file_list_compute_lines (GtkScrolledWindow *sw, WPanel *panel, int height)
|
||||
panel_file_list_resize_callback (GtkCList *clist, gint column, gint width, WPanel *panel)
|
||||
{
|
||||
int lost_pixels = 0;
|
||||
if (GTK_WIDGET_VISIBLE (sw->hscrollbar)) {
|
||||
int scrollbar_width = GTK_WIDGET (sw->hscrollbar)->requisition.width;
|
||||
int scrollbar_space = GTK_SCROLLED_WINDOW_CLASS (GTK_OBJECT (sw)->klass)->scrollbar_spacing;
|
||||
format_e *format = panel->format;
|
||||
int i, p;
|
||||
|
||||
lost_pixels = scrollbar_space + scrollbar_width;
|
||||
}
|
||||
panel->widget.lines = (height-lost_pixels) / (CLIST_FROM_SW (sw)->row_height + CELL_SPACING);
|
||||
}
|
||||
p = column_width_pos[panel->list_type]; /* offset in column_width */
|
||||
g_assert (p >= 0);
|
||||
|
||||
static void
|
||||
panel_file_list_size_allocate_hook (GtkWidget *sw, GtkAllocation *allocation, WPanel *panel)
|
||||
{
|
||||
gtk_signal_handler_block_by_data (GTK_OBJECT (sw), panel);
|
||||
panel_file_list_configure_contents (sw, panel, allocation->width, allocation->height);
|
||||
gtk_signal_handler_unblock_by_data (GTK_OBJECT (sw), panel);
|
||||
panel->column_width[p + column] = width;
|
||||
|
||||
panel_file_list_compute_lines (GTK_SCROLLED_WINDOW (sw), panel, allocation->height);
|
||||
/* make this default */
|
||||
memcpy (default_column_width, panel->column_width, sizeof (default_column_width));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -620,6 +539,10 @@ panel_file_list_configure (WPanel *panel, GtkWidget *sw, GtkWidget *file_list)
|
||||
gtk_signal_connect (GTK_OBJECT (file_list), "click_column",
|
||||
GTK_SIGNAL_FUNC (panel_file_list_column_callback), panel);
|
||||
|
||||
/* Set column resize callback */
|
||||
gtk_signal_connect (GTK_OBJECT (file_list), "resize_column",
|
||||
GTK_SIGNAL_FUNC (panel_file_list_resize_callback), panel);
|
||||
|
||||
/* Avoid clist's broken focusing behavior */
|
||||
GTK_WIDGET_UNSET_FLAGS (file_list, GTK_CAN_FOCUS);
|
||||
|
||||
@ -1309,10 +1232,6 @@ panel_create_file_list (WPanel *panel)
|
||||
panel_file_list_configure (panel, sw, file_list);
|
||||
g_free (titles);
|
||||
|
||||
gtk_signal_connect_after (GTK_OBJECT (sw), "size_allocate",
|
||||
GTK_SIGNAL_FUNC (panel_file_list_size_allocate_hook),
|
||||
panel);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (file_list), "select_row",
|
||||
GTK_SIGNAL_FUNC (panel_file_list_select_row),
|
||||
panel);
|
||||
@ -2384,6 +2303,7 @@ x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
|
||||
panel->icons = panel_create_icon_display (panel);
|
||||
gtk_widget_show (panel->icons);
|
||||
|
||||
memcpy (panel->column_width, default_column_width, sizeof (default_column_width));
|
||||
panel->list = panel_create_file_list (panel);
|
||||
gtk_widget_ref (panel->icons);
|
||||
gtk_widget_ref (panel->list);
|
||||
@ -2562,6 +2482,12 @@ x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
|
||||
panel->estimated_total = 0;
|
||||
|
||||
panel->timer_id = -1;
|
||||
|
||||
/* re-set the user_format explicitly */
|
||||
if (default_user_format != NULL) {
|
||||
g_free (panel->user_format);
|
||||
panel->user_format = g_strdup (default_user_format);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -24,6 +24,8 @@ static GnomeClient *master_client;
|
||||
/* Structure to hold information for a panel to be created */
|
||||
typedef struct {
|
||||
char *cwd;
|
||||
int column_width[GMC_COLUMNS];
|
||||
char *user_format;
|
||||
} PanelInfo;
|
||||
|
||||
|
||||
@ -32,15 +34,26 @@ static void
|
||||
save_panel_info (WPanel *panel)
|
||||
{
|
||||
char section[50];
|
||||
char *key;
|
||||
char key[50];
|
||||
char *path;
|
||||
int i;
|
||||
|
||||
sprintf (section, "panel %d", panel->id);
|
||||
g_snprintf (section, sizeof (section), "panel %d", panel->id);
|
||||
|
||||
key = g_strconcat (section, "/cwd", NULL);
|
||||
gnome_config_set_string (key, panel->cwd);
|
||||
g_free (key);
|
||||
path = g_strconcat (section, "/cwd", NULL);
|
||||
gnome_config_set_string (path, panel->cwd);
|
||||
g_free (path);
|
||||
|
||||
/* FIXME: save information about list column sizes, etc. */
|
||||
path = g_strconcat (section, "/user_format", NULL);
|
||||
gnome_config_set_string (path, panel->user_format);
|
||||
g_free (path);
|
||||
|
||||
for (i = 0; i < GMC_COLUMNS; i++) {
|
||||
g_snprintf (key, sizeof (key), "/column_width_%i", i);
|
||||
path = g_strconcat (section, key, NULL);
|
||||
gnome_config_set_int (path, panel->column_width[i]);
|
||||
g_free (path);
|
||||
}
|
||||
}
|
||||
|
||||
/* Loads a panel from the information in the specified gnome-config file/section */
|
||||
@ -49,7 +62,9 @@ load_panel_info (char *file, char *section)
|
||||
{
|
||||
PanelInfo *pi;
|
||||
char *prefix;
|
||||
char *cwd;
|
||||
char *cwd, *user_format;
|
||||
char key[50];
|
||||
int i;
|
||||
|
||||
pi = NULL;
|
||||
|
||||
@ -59,10 +74,25 @@ load_panel_info (char *file, char *section)
|
||||
|
||||
cwd = gnome_config_get_string ("cwd");
|
||||
if (cwd) {
|
||||
g_warning ("Could not read panel data for \"%s\"", prefix);
|
||||
gnome_config_pop_prefix ();
|
||||
g_free (prefix);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pi = g_new (PanelInfo, 1);
|
||||
pi->cwd = cwd;
|
||||
} else
|
||||
g_warning ("Could not read panel data for \"%s\"", prefix);
|
||||
|
||||
user_format = gnome_config_get_string ("user_format");
|
||||
if (!user_format)
|
||||
user_format = g_strdup (DEFAULT_USER_FORMAT);
|
||||
|
||||
pi->user_format = user_format;
|
||||
|
||||
for (i = 0; i < GMC_COLUMNS; i++) {
|
||||
g_snprintf (key, sizeof (key), "column_width_%i=0", i);
|
||||
pi->column_width[i] = gnome_config_get_int_with_default (key, NULL);
|
||||
}
|
||||
|
||||
gnome_config_pop_prefix ();
|
||||
g_free (prefix);
|
||||
@ -75,6 +105,7 @@ static void
|
||||
free_panel_info (PanelInfo *pi)
|
||||
{
|
||||
g_free (pi->cwd);
|
||||
g_free (pi->user_format);
|
||||
g_free (pi);
|
||||
}
|
||||
|
||||
@ -84,12 +115,18 @@ idle_create_panels (gpointer data)
|
||||
{
|
||||
GSList *panels, *p;
|
||||
PanelInfo *pi;
|
||||
WPanel *panel;
|
||||
|
||||
panels = data;
|
||||
|
||||
for (p = panels; p; p = p->next) {
|
||||
pi = p->data;
|
||||
new_panel_at (pi->cwd);
|
||||
panel = new_panel_at (pi->cwd);
|
||||
|
||||
g_free (panel->user_format);
|
||||
panel->user_format = g_strdup (pi->user_format);
|
||||
memcpy (panel->column_width, pi->column_width, sizeof (pi->column_width));
|
||||
|
||||
free_panel_info (pi);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,15 @@
|
||||
1999-09-20 Federico Mena Quintero <federico@redhat.com>
|
||||
|
||||
The following is a patch from Volker Braun
|
||||
<volker.braun@physik.hu-berlin.de> to fix column resizing in the
|
||||
file panels.
|
||||
|
||||
* setup.c (options): Declare the column width option values.
|
||||
(save_configure): Save the default user format.
|
||||
(load_setup): Load the default user format.
|
||||
|
||||
* panel.h (WPanel): Added a field for the column widths.
|
||||
|
||||
1999-09-19 Andrew V. Samoilov <sav@bcs.zp.ua>
|
||||
|
||||
* user.c (check_patterns): char* is used instead of char [] in sizeof
|
||||
|
19
src/panel.h
19
src/panel.h
@ -9,6 +9,22 @@
|
||||
|
||||
#define LIST_TYPES 5
|
||||
|
||||
#ifdef HAVE_GNOME
|
||||
/* Keep the following in sync with setup.c */
|
||||
|
||||
/* Number of columns that each mode requires */
|
||||
#define GMC_COLUMNS_BRIEF 2 /* brief view */
|
||||
#define GMC_COLUMNS_DETAILED 4 /* detailed view */
|
||||
#define GMC_COLUMNS_CUSTOM 15 /* custom view */
|
||||
#define GMC_COLUMNS (GMC_COLUMNS_BRIEF + GMC_COLUMNS_DETAILED + GMC_COLUMNS_CUSTOM)
|
||||
|
||||
/* Default column widths */
|
||||
extern int default_column_width[GMC_COLUMNS];
|
||||
|
||||
/* custom listing format */
|
||||
extern char *default_user_format;
|
||||
#endif
|
||||
|
||||
enum list_types {
|
||||
list_full, /* Name, size, perm/date */
|
||||
list_brief, /* Name */
|
||||
@ -144,6 +160,9 @@ typedef struct {
|
||||
void *current_dir; /* A WInput* */
|
||||
int estimated_total;
|
||||
|
||||
/* default column layout */
|
||||
int column_width[GMC_COLUMNS];
|
||||
|
||||
/* navigation buttons */
|
||||
void *back_b;
|
||||
void *fwd_b;
|
||||
|
32
src/setup.c
32
src/setup.c
@ -264,6 +264,29 @@ static struct {
|
||||
{ "desktop_arr_rows", &desktop_arr_rows },
|
||||
{ "tree_panel_visible", &tree_panel_visible },
|
||||
{ "we_can_afford_the_speed", &we_can_afford_the_speed },
|
||||
|
||||
/* Keep the following in sync with panel.h */
|
||||
{ "column_width_brief_icon", &default_column_width[0] },
|
||||
{ "column_width_brief_filename", &default_column_width[1] },
|
||||
{ "column_width_detailed_icon", &default_column_width[2] },
|
||||
{ "column_width_detailed_filename", &default_column_width[3] },
|
||||
{ "column_width_detailed_size", &default_column_width[4] },
|
||||
{ "column_width_detailed_mtime", &default_column_width[5] },
|
||||
{ "column_width_custom_0", &default_column_width[6] },
|
||||
{ "column_width_custom_1", &default_column_width[7] },
|
||||
{ "column_width_custom_2", &default_column_width[8] },
|
||||
{ "column_width_custom_3", &default_column_width[9] },
|
||||
{ "column_width_custom_4", &default_column_width[10] },
|
||||
{ "column_width_custom_5", &default_column_width[11] },
|
||||
{ "column_width_custom_6", &default_column_width[12] },
|
||||
{ "column_width_custom_7", &default_column_width[13] },
|
||||
{ "column_width_custom_8", &default_column_width[14] },
|
||||
{ "column_width_custom_9", &default_column_width[15] },
|
||||
{ "column_width_custom_10", &default_column_width[16] },
|
||||
{ "column_width_custom_11", &default_column_width[17] },
|
||||
{ "column_width_custom_12", &default_column_width[18] },
|
||||
{ "column_width_custom_13", &default_column_width[19] },
|
||||
{ "column_width_custom_14", &default_column_width[20] },
|
||||
#else
|
||||
{ "nice_rotating_dash", &nice_rotating_dash },
|
||||
{ "horizontal_split", &horizontal_split },
|
||||
@ -338,6 +361,10 @@ save_configure (void)
|
||||
for (i = 0; options [i].opt_name; i++)
|
||||
set_int (profile, options [i].opt_name, *options [i].opt_addr);
|
||||
|
||||
#ifdef HAVE_GNOME
|
||||
save_string (app_text, "default_user_format", default_user_format, profile_name);
|
||||
#endif
|
||||
|
||||
g_free (profile);
|
||||
}
|
||||
|
||||
@ -549,6 +576,11 @@ load_setup (void)
|
||||
*options [i].opt_addr =
|
||||
get_int (profile, options [i].opt_name, *options [i].opt_addr);
|
||||
|
||||
#ifdef HAVE_GNOME
|
||||
g_free (default_user_format);
|
||||
default_user_format = do_load_string (app_text, "default_user_format", DEFAULT_USER_FORMAT);
|
||||
#endif
|
||||
|
||||
load_layout (profile);
|
||||
|
||||
load_panelize ();
|
||||
|
Loading…
Reference in New Issue
Block a user