File panel: unification of terminology.
[midnight-commander.git] / src / filemanager / panel.h
blob198d73de5fc66c1c6c3ff44b0438567831c3dbff
1 /** \file panel.h
2 * \brief Header: defines WPanel structure
3 */
5 #ifndef MC__PANEL_H
6 #define MC__PANEL_H
8 #include <inttypes.h> /* uintmax_t */
10 #include "lib/global.h" /* gboolean */
11 #include "lib/fs.h" /* MC_MAXPATHLEN */
12 #include "lib/strutil.h"
13 #include "lib/widget.h" /* Widget */
14 #include "lib/filehighlight.h"
16 #include "dir.h" /* dir_list */
18 /*** typedefs(not structures) and defined constants **********************************************/
20 #define PANEL(x) ((WPanel *)(x))
21 #define selection(p) (&(p->dir.list[p->selected]))
22 #define DEFAULT_USER_FORMAT "half type name | size | perm"
24 #define LIST_FORMATS 4
26 #define UP_KEEPSEL ((char *) -1)
28 /*** enums ***************************************************************************************/
30 typedef enum
32 list_full, /* Name, size, perm/date */
33 list_brief, /* Name */
34 list_long, /* Like ls -l */
35 list_user /* User defined */
36 } list_format_t;
38 typedef enum
40 frame_full, /* full screen frame */
41 frame_half /* half screen frame */
42 } panel_display_t;
44 typedef enum
46 UP_OPTIMIZE = 0,
47 UP_RELOAD = 1,
48 UP_ONLY_CURRENT = 2
49 } panel_update_flags_t;
51 /* selection flags */
52 typedef enum
54 SELECT_FILES_ONLY = 1 << 0,
55 SELECT_MATCH_CASE = 1 << 1,
56 SELECT_SHELL_PATTERNS = 1 << 2
57 } panel_select_flags_t;
59 /* run mode and params */
61 enum cd_enum
63 cd_parse_command,
64 cd_exact
67 /*** structures declarations (and typedefs of structures)*****************************************/
69 struct format_e;
71 typedef struct panel_field_struct
73 const char *id;
74 int min_size;
75 gboolean expands;
76 align_crt_t default_just;
77 const char *hotkey;
78 const char *title_hotkey;
79 gboolean is_user_choice;
80 gboolean use_in_user_format;
81 const char *(*string_fn) (file_entry_t *, int);
82 GCompareFunc sort_routine; /* used by mouse_sort_col() */
83 } panel_field_t;
85 typedef struct
87 dir_list list;
88 vfs_path_t *root_vpath;
89 } panelized_panel_t;
91 typedef struct
93 Widget widget;
94 dir_list dir; /* Directory contents */
96 list_format_t list_format; /* listing type */
97 int active; /* If panel is currently selected */
98 vfs_path_t *cwd_vpath; /* Current Working Directory */
99 vfs_path_t *lwd_vpath; /* Last Working Directory */
100 GList *dir_history; /* directory history */
101 GList *dir_history_current; /* pointer to the current history item */
102 char *hist_name; /* directory history name for history file */
103 int marked; /* Count of marked files */
104 int dirs_marked; /* Count of marked directories */
105 uintmax_t total; /* Bytes in marked files */
106 int top_file; /* The file showed on the top of the panel */
107 int selected; /* Index to the selected file */
108 int list_cols; /* Number of file list columns */
109 int brief_cols; /* Number of columns in case of list_brief format */
110 gboolean is_panelized; /* Flag: special filelisting, can't reload */
111 panel_display_t frame_size; /* half or full frame */
112 char *filter; /* File name filter */
114 /* sort */
115 dir_sort_options_t sort_info;
116 const panel_field_t *sort_field;
118 int dirty; /* Should we redisplay the panel? */
120 gboolean user_mini_status; /* Is user_status_format used */
121 char *user_format; /* User format */
122 char *user_status_format[LIST_FORMATS]; /* User format for status line */
124 struct format_e *format; /* Display format */
125 struct format_e *status_format; /* Mini status format */
127 int format_modified; /* If the format was changed this is set */
129 char *panel_name; /* The panel name */
130 struct stat dir_stat; /* Stat of current dir: used by execute () */
132 #ifdef HAVE_CHARSET
133 int codepage; /* panel codepage */
134 #endif
136 gboolean searching;
137 char search_buffer[MC_MAXFILENAMELEN];
138 char prev_search_buffer[MC_MAXFILENAMELEN];
139 char search_char[MB_LEN_MAX]; /*buffer for multibytes characters */
140 int search_chpoint; /*point after last characters in search_char */
141 int content_shift; /* Number of characters of filename need to skip from left side. */
142 int max_shift; /* Max shift for visible part of current panel */
143 } WPanel;
145 /*** global variables defined in .c file *********************************************************/
147 extern panelized_panel_t panelized_panel;
149 extern hook_t *select_file_hook;
151 extern mc_fhl_t *mc_filehighlight;
153 /*** declarations of public functions ************************************************************/
155 WPanel *panel_new_with_dir (const char *panel_name, const vfs_path_t * vpath);
156 void panel_clean_dir (WPanel * panel);
158 void panel_reload (WPanel * panel);
159 void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
160 void panel_re_sort (WPanel * panel);
162 #ifdef HAVE_CHARSET
163 void panel_change_encoding (WPanel * panel);
164 vfs_path_t *remove_encoding_from_path (const vfs_path_t * vpath);
165 #endif
167 void update_panels (panel_update_flags_t flags, const char *current_file);
168 int set_panel_formats (WPanel * p);
170 void try_to_select (WPanel * panel, const char *name);
172 void unmark_files (WPanel * panel);
173 void select_item (WPanel * panel);
175 void recalculate_panel_summary (WPanel * panel);
176 void file_mark (WPanel * panel, int idx, int val);
177 void do_file_mark (WPanel * panel, int idx, int val);
179 gboolean do_panel_cd (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
181 gsize panel_get_num_of_sortable_fields (void);
182 char **panel_get_sortable_fields (gsize *);
183 const panel_field_t *panel_get_field_by_id (const char *);
184 const panel_field_t *panel_get_field_by_title (const char *);
185 const panel_field_t *panel_get_field_by_title_hotkey (const char *);
186 gsize panel_get_num_of_user_possible_fields (void);
187 char **panel_get_user_possible_fields (gsize *);
188 void panel_set_cwd (WPanel * panel, const vfs_path_t * vpath);
189 void panel_set_lwd (WPanel * panel, const vfs_path_t * vpath);
191 void panel_init (void);
192 void panel_deinit (void);
193 gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
195 /* --------------------------------------------------------------------------------------------- */
196 /*** inline functions ****************************************************************************/
197 /* --------------------------------------------------------------------------------------------- */
199 * Panel creation.
201 * @param panel_name the name of the panel for setup retieving
203 * @return new instance of WPanel
206 static inline WPanel *
207 panel_new (const char *panel_name)
209 return panel_new_with_dir (panel_name, NULL);
212 /* --------------------------------------------------------------------------------------------- */
214 #endif /* MC__PANEL_H */