1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/** \file panel.h
* \brief Header: defines WPanel structure
*/
#ifndef MC__PANEL_H
#define MC__PANEL_H
#include <inttypes.h> /* uintmax_t */
#include <limits.h> /* MB_LEN_MAX */
#include "lib/global.h" /* gboolean */
#include "lib/fs.h" /* MC_MAXPATHLEN */
#include "lib/strutil.h"
#include "lib/widget.h" /* Widget */
#include "lib/filehighlight.h"
#include "lib/file-entry.h"
#include "dir.h" /* dir_list */
/*** typedefs(not structures) and defined constants **********************************************/
#define PANEL(x) ((WPanel *)(x))
#define DEFAULT_USER_FORMAT "half type name | size | perm"
#define LIST_FORMATS 4
#define UP_KEEPSEL ((char *) -1)
/*** enums ***************************************************************************************/
typedef enum
{
list_full, /* Name, size, perm/date */
list_brief, /* Name */
list_long, /* Like ls -l */
list_user /* User defined */
} list_format_t;
typedef enum
{
frame_full, /* full screen frame */
frame_half /* half screen frame */
} panel_display_t;
typedef enum
{
UP_OPTIMIZE = 0,
UP_RELOAD = 1,
UP_ONLY_CURRENT = 2
} panel_update_flags_t;
/* run mode and params */
enum cd_enum
{
cd_parse_command,
cd_exact
};
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct panel_field_struct
{
const char *id;
int min_size;
gboolean expands;
align_crt_t default_just;
const char *hotkey;
const char *title_hotkey;
gboolean is_user_choice;
gboolean use_in_user_format;
const char *(*string_fn) (file_entry_t *, int);
GCompareFunc sort_routine; /* used by mouse_sort_col() */
} panel_field_t;
typedef struct
{
dir_list list;
vfs_path_t *root_vpath;
} panelized_descr_t;
typedef struct
{
Widget widget;
char *name; /* The panel name */
panel_display_t frame_size; /* half or full frame */
gboolean active; /* If panel is currently selected */
gboolean dirty; /* Should we redisplay the panel? */
gboolean is_panelized; /* Panelization: special mode, can't reload the file list */
panelized_descr_t *panelized_descr; /* Panelization descriptor */
#ifdef HAVE_CHARSET
int codepage; /* Panel codepage */
#endif
dir_list dir; /* Directory contents */
struct stat dir_stat; /* Stat of current dir: used by execute () */
vfs_path_t *cwd_vpath; /* Current Working Directory */
vfs_path_t *lwd_vpath; /* Last Working Directory */
list_format_t list_format; /* Listing type */
GSList *format; /* Display format */
char *user_format; /* User format */
int list_cols; /* Number of file list columns */
int brief_cols; /* Number of columns in case of list_brief format */
/* sort */
dir_sort_options_t sort_info;
const panel_field_t *sort_field;
int marked; /* Count of marked files */
int dirs_marked; /* Count of marked directories */
uintmax_t total; /* Bytes in marked files */
int top; /* The file shown on the top of the panel */
int current; /* Index to the currently selected file */
GSList *status_format; /* Mini status format */
gboolean user_mini_status; /* Is user_status_format used */
char *user_status_format[LIST_FORMATS]; /* User format for status line */
file_filter_t filter; /* File name filter */
struct
{
char *name; /* Directory history name for history file */
GList *list; /* Directory history */
GList *current; /* Pointer to the current history item */
} dir_history;
struct
{
gboolean active;
GString *buffer;
GString *prev_buffer;
char ch[MB_LEN_MAX]; /* Buffer for multi-byte character */
int chpoint; /* Point after last characters in @ch */
} quick_search;
int content_shift; /* Number of characters of filename need to skip from left side. */
int max_shift; /* Max shift for visible part of current panel */
} WPanel;
/*** global variables defined in .c file *********************************************************/
extern hook_t *select_file_hook;
extern mc_fhl_t *mc_filehighlight;
/*** declarations of public functions ************************************************************/
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_reload (WPanel * panel);
void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
void panel_re_sort (WPanel * panel);
#ifdef HAVE_CHARSET
void panel_change_encoding (WPanel * panel);
vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
#endif
void update_panels (panel_update_flags_t flags, const char *current_file);
int set_panel_formats (WPanel * p);
void panel_set_filter (WPanel * panel, const file_filter_t * filter);
void panel_set_current_by_name (WPanel * panel, const char *name);
void unmark_files (WPanel * panel);
void select_item (WPanel * panel);
void recalculate_panel_summary (WPanel * panel);
void file_mark (WPanel * panel, int idx, int val);
void do_file_mark (WPanel * panel, int idx, int val);
gboolean panel_do_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
gboolean panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
gsize panel_get_num_of_sortable_fields (void);
char **panel_get_sortable_fields (gsize * array_size);
const panel_field_t *panel_get_field_by_id (const char *name);
const panel_field_t *panel_get_field_by_title (const char *name);
const panel_field_t *panel_get_field_by_title_hotkey (const char *name);
gsize panel_get_num_of_user_possible_fields (void);
char **panel_get_user_possible_fields (gsize * array_size);
void panel_set_cwd (WPanel * panel, const vfs_path_t * vpath);
void panel_set_lwd (WPanel * panel, const vfs_path_t * vpath);
void panel_panelize_cd (void);
void panel_panelize_change_root (WPanel * panel, const vfs_path_t * new_root);
void panel_panelize_absolutize_if_needed (WPanel * panel);
void panel_panelize_save (WPanel * panel);
void panel_init (void);
void panel_deinit (void);
/* --------------------------------------------------------------------------------------------- */
/*** inline functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Empty panel creation.
*
* @param panel_name name of panel for setup retrieving
*
* @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 retrieving
* @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.
*
* @param panel_name name of panel for setup retrieving
*
* @return new instance of WPanel
*/
static inline WPanel *
panel_new (const char *panel_name)
{
return panel_with_dir_new (panel_name, NULL);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Panel creation with specified size.
*
* @param panel_name name of panel for setup retrieving
* @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);
}
/* --------------------------------------------------------------------------------------------- */
static inline file_entry_t *
panel_current_entry (const WPanel * panel)
{
return &(panel->dir.list[panel->current]);
}
/* --------------------------------------------------------------------------------------------- */
#endif /* MC__PANEL_H */
|