This source file includes following definitions.
- panelized_descr_new
- panelized_descr_free
- set_colors
- format_item_free
- panel_lines
- add_permission_string
- string_file_name
- ilog10
- format_device_number
- string_file_size
- string_file_size_brief
- string_file_type
- string_file_mtime
- string_file_atime
- string_file_ctime
- string_file_permission
- string_file_perm_octal
- string_file_nlinks
- string_inode
- string_file_nuid
- string_file_ngid
- string_file_owner
- string_file_group
- string_marked
- string_space
- string_dot
- file_compute_color
- panel_items
- format_file
- repaint_file
- repaint_status
- display_mini_info
- paint_dir
- display_total_marked_size
- mini_info_separator
- show_free_space
- panel_correct_path_to_show
- panel_get_encoding_info_str
- show_vertical_separator_tee
- show_dir
- adjust_top_file
- panel_save_name
- directory_history_add
- panel_load_history
- panel_save_history
- panel_destroy
- panel_paint_sort_info
- panel_get_title_without_hotkey
- panel_print_header
- parse_panel_size
- parse_display_format
- use_display_format
- panel_format
- mini_status_format
- cd_up_dir
- maybe_cd
- force_maybe_cd
- unselect_item
- panel_select_ext_cmd
- panel_set_current
- panel_current_at_half
- move_down
- move_up
- panel_move_current
- move_left
- move_right
- prev_page
- goto_parent_dir
- next_page
- goto_child_dir
- goto_top_file
- goto_middle_file
- goto_bottom_file
- move_home
- move_end
- do_mark_file
- mark_file
- mark_file_up
- mark_file_down
- mark_file_right
- mark_file_left
- panel_select_unselect_files_dialog
- panel_select_unselect_files
- panel_select_files
- panel_unselect_files
- panel_select_invert_files
- panel_do_set_filter
- do_search
- start_search
- stop_search
- do_enter_on_file_entry
- do_enter
- panel_cycle_listing_format
- chdir_other_panel
- panel_sync_other
- chdir_to_readlink
- panel_get_format_field_index_by_name
- panel_get_sortable_field_by_format
- panel_toggle_sort_order_prev
- panel_toggle_sort_order_next
- panel_select_sort_order
- panel_content_scroll_left
- panel_content_scroll_right
- panel_content_scroll_home
- panel_content_scroll_end
- panel_set_sort_type_by_id
- get_parent_dir_name
- panel_do_cd_int
- directory_history_next
- directory_history_prev
- directory_history_list
- panel_execute_cmd
- panel_key
- panel_callback
- mouse_toggle_mark
- mouse_set_mark
- mark_if_marking
- mouse_sort_col
- panel_mouse_is_on_item
- panel_mouse_callback
- reload_panelized
- update_one_panel_widget
- update_one_panel
- event_update_panels
- panel_save_current_file_to_clip_file
- panel_recursive_cd_to_parent
- panel_dir_list_callback
- panel_current_entry
- panel_set_current_by_name
- panel_clean_dir
- panel_set_cwd
- panel_set_lwd
- panel_sized_empty_new
- panel_sized_with_dir_new
- panel_reload
- set_panel_formats
- panel_set_filter
- select_item
- unmark_files
- recalculate_panel_summary
- do_file_mark
- panel_do_cd
- file_mark
- panel_find_marked_file
- panel_get_marked_file
- panel_re_sort
- panel_set_sort_order
- panel_change_encoding
- remove_encoding_from_path
- update_panels
- panel_get_num_of_sortable_fields
- panel_get_sortable_fields
- panel_get_field_by_id
- panel_get_field_by_title_hotkey
- panel_get_field_by_title
- panel_get_num_of_user_possible_fields
- panel_get_user_possible_fields
- panel_panelize_restore
- panel_panelize_change_root
- panel_panelize_absolutize_if_needed
- panel_panelize_save
- panel_init
- panel_deinit
- panel_cd
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 #include <config.h>
34
35 #include <limits.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "lib/global.h"
41
42 #include "lib/tty/tty.h"
43 #include "lib/tty/key.h"
44 #include "lib/skin.h"
45 #include "lib/strutil.h"
46 #include "lib/mcconfig.h"
47 #include "lib/vfs/vfs.h"
48 #include "lib/unixcompat.h"
49 #include "lib/search.h"
50 #include "lib/timefmt.h"
51 #include "lib/util.h"
52 #include "lib/widget.h"
53 #include "lib/charsets.h"
54 #include "lib/event.h"
55
56 #include "src/setup.h"
57 #include "src/execute.h"
58 #include "src/selcodepage.h"
59 #include "src/keymap.h"
60 #include "src/history.h"
61 #ifdef ENABLE_SUBSHELL
62 #include "src/subshell/subshell.h"
63 #endif
64
65 #include "src/usermenu.h"
66
67 #include "dir.h"
68 #include "boxes.h"
69 #include "tree.h"
70 #include "ext.h"
71 #include "layout.h"
72 #include "cmd.h"
73 #include "command.h"
74 #include "filemanager.h"
75 #include "mountlist.h"
76 #include "cd.h"
77
78 #include "panel.h"
79
80
81
82
83 hook_t *select_file_hook = NULL;
84
85 mc_fhl_t *mc_filehighlight = NULL;
86
87
88
89 typedef enum
90 {
91 FATTR_NORMAL = 0,
92 FATTR_CURRENT,
93 FATTR_MARKED,
94 FATTR_MARKED_CURRENT,
95 FATTR_STATUS
96 } file_attr_t;
97
98 #define DEFAULT_USER_FORMAT "half type name | size | perm"
99
100
101 #define SELECT_RESET ((mc_search_t *) (-1))
102 #define SELECT_ERROR ((mc_search_t *) (-2))
103
104
105 #define MOUSE_UPPER_FILE_LIST (-1)
106 #define MOUSE_BELOW_FILE_LIST (-2)
107 #define MOUSE_AFTER_LAST_FILE (-3)
108
109
110
111 typedef enum
112 {
113 MARK_DONT_MOVE = 0,
114 MARK_DOWN = 1,
115 MARK_FORCE_DOWN = 2,
116 MARK_FORCE_UP = 3
117 } mark_act_t;
118
119
120
121
122
123 typedef struct format_item_t
124 {
125 int requested_field_len;
126 int field_len;
127 align_crt_t just_mode;
128 gboolean expand;
129 const char *(*string_fn) (const file_entry_t *fe, int len);
130 char *title;
131 const char *id;
132 } format_item_t;
133
134
135 typedef enum
136 {
137 FILENAME_NOSCROLL = 1,
138 FILENAME_SCROLL_LEFT = 2,
139 FILENAME_SCROLL_RIGHT = 4
140 } filename_scroll_flag_t;
141
142
143
144 static const char *string_file_name (const file_entry_t *fe, int len);
145 static const char *string_file_size (const file_entry_t *fe, int len);
146 static const char *string_file_size_brief (const file_entry_t *fe, int len);
147 static const char *string_file_type (const file_entry_t *fe, int len);
148 static const char *string_file_mtime (const file_entry_t *fe, int len);
149 static const char *string_file_atime (const file_entry_t *fe, int len);
150 static const char *string_file_ctime (const file_entry_t *fe, int len);
151 static const char *string_file_permission (const file_entry_t *fe, int len);
152 static const char *string_file_perm_octal (const file_entry_t *fe, int len);
153 static const char *string_file_nlinks (const file_entry_t *fe, int len);
154 static const char *string_inode (const file_entry_t *fe, int len);
155 static const char *string_file_nuid (const file_entry_t *fe, int len);
156 static const char *string_file_ngid (const file_entry_t *fe, int len);
157 static const char *string_file_owner (const file_entry_t *fe, int len);
158 static const char *string_file_group (const file_entry_t *fe, int len);
159 static const char *string_marked (const file_entry_t *fe, int len);
160 static const char *string_space (const file_entry_t *fe, int len);
161 static const char *string_dot (const file_entry_t *fe, int len);
162
163
164
165 static panel_field_t panel_fields[] = {
166 { "unsorted", 12, TRUE, J_LEFT_FIT,
167
168
169 N_ ("sort|u"), N_ ("&Unsorted"), TRUE, FALSE, string_file_name, (GCompareFunc) unsorted },
170 { "name", 12, TRUE, J_LEFT_FIT,
171
172
173 N_ ("sort|n"), N_ ("&Name"), TRUE, TRUE, string_file_name, (GCompareFunc) sort_name },
174 { "version", 12, TRUE, J_LEFT_FIT,
175
176
177 N_ ("sort|v"), N_ ("&Version"), TRUE, FALSE, string_file_name, (GCompareFunc) sort_vers },
178 { "extension", 12, TRUE, J_LEFT_FIT,
179
180
181 N_ ("sort|e"), N_ ("E&xtension"), TRUE, FALSE,
182 string_file_name,
183 (GCompareFunc) sort_ext },
184 { "size", 7, FALSE, J_RIGHT,
185
186
187 N_ ("sort|s"), N_ ("&Size"), TRUE, TRUE, string_file_size, (GCompareFunc) sort_size },
188 { "bsize", 7, FALSE, J_RIGHT, "", N_ ("Block Size"), FALSE, FALSE, string_file_size_brief,
189 (GCompareFunc) sort_size },
190 { "type", 1, FALSE, J_LEFT, "", "", FALSE, TRUE, string_file_type, NULL },
191 { "mtime", 12, FALSE, J_RIGHT,
192
193
194 N_ ("sort|m"), N_ ("&Modify time"), TRUE, TRUE, string_file_mtime, (GCompareFunc) sort_time },
195 { "atime", 12, FALSE, J_RIGHT,
196
197
198 N_ ("sort|a"), N_ ("&Access time"), TRUE, TRUE, string_file_atime,
199 (GCompareFunc) sort_atime },
200 { "ctime", 12, FALSE, J_RIGHT,
201
202
203 N_ ("sort|h"), N_ ("C&hange time"), TRUE, TRUE, string_file_ctime,
204 (GCompareFunc) sort_ctime },
205 { "perm", 10, FALSE, J_LEFT, "", N_ ("Permission"), FALSE, TRUE, string_file_permission, NULL },
206 { "mode", 6, FALSE, J_RIGHT, "", N_ ("Perm"), FALSE, TRUE, string_file_perm_octal, NULL },
207 { "nlink", 2, FALSE, J_RIGHT, "", N_ ("Nl"), FALSE, TRUE, string_file_nlinks, NULL },
208 { "inode", 5, FALSE, J_RIGHT,
209
210
211 N_ ("sort|i"), N_ ("&Inode"), TRUE, TRUE, string_inode, (GCompareFunc) sort_inode },
212 { "nuid", 5, FALSE, J_RIGHT, "", N_ ("UID"), FALSE, FALSE, string_file_nuid, NULL },
213 { "ngid", 5, FALSE, J_RIGHT, "", N_ ("GID"), FALSE, FALSE, string_file_ngid, NULL },
214 { "owner", 8, FALSE, J_LEFT_FIT, "", N_ ("Owner"), FALSE, TRUE, string_file_owner, NULL },
215 { "group", 8, FALSE, J_LEFT_FIT, "", N_ ("Group"), FALSE, TRUE, string_file_group, NULL },
216 { "mark", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, string_marked, NULL },
217 { "|", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, NULL, NULL },
218 { "space", 1, FALSE, J_RIGHT, "", " ", FALSE, TRUE, string_space, NULL },
219 { "dot", 1, FALSE, J_RIGHT, "", " ", FALSE, FALSE, string_dot, NULL },
220 { NULL, 0, FALSE, J_RIGHT, NULL, NULL, FALSE, FALSE, NULL, NULL },
221 };
222
223 static char *panel_sort_up_char = NULL;
224 static char *panel_sort_down_char = NULL;
225 static int panel_sort_up_indicator_width = 0;
226 static int panel_sort_down_indicator_width = 0;
227
228 static char *panel_hiddenfiles_show_char = NULL;
229 static char *panel_hiddenfiles_hide_char = NULL;
230 static char *panel_history_prev_item_char = NULL;
231 static char *panel_history_next_item_char = NULL;
232 static char *panel_history_show_list_char = NULL;
233 static char *panel_filename_scroll_left_char = NULL;
234 static char *panel_filename_scroll_right_char = NULL;
235
236
237 static WPanel *mouse_mark_panel = NULL;
238
239 static gboolean mouse_marking = FALSE;
240 static int state_mark = 0;
241
242 static GString *string_file_name_buffer;
243
244
245
246
247
248 static panelized_descr_t *
249 panelized_descr_new (void)
250 {
251 panelized_descr_t *p;
252
253 p = g_new0 (panelized_descr_t, 1);
254 p->list.len = -1;
255
256 return p;
257 }
258
259
260
261 static void
262 panelized_descr_free (panelized_descr_t *p)
263 {
264 if (p != NULL)
265 {
266 dir_list_free_list (&p->list);
267 vfs_path_free (p->root_vpath, TRUE);
268 g_free (p);
269 }
270 }
271
272
273
274 static void
275 set_colors (const WPanel *panel)
276 {
277 (void) panel;
278
279 tty_set_normal_attrs ();
280 tty_setcolor (CORE_NORMAL_COLOR);
281 }
282
283
284
285
286 static void
287 format_item_free (format_item_t *format)
288 {
289 g_free (format->title);
290 g_free (format);
291 }
292
293
294
295
296 static int
297 panel_lines (const WPanel *p)
298 {
299
300 return (CONST_WIDGET (p)->rect.lines - 3 - (panels_options.show_mini_info ? 2 : 0));
301 }
302
303
304
305
306 static void
307 add_permission_string (const char *dest, int width, file_entry_t *fe, file_attr_t attr, int color,
308 gboolean is_octal)
309 {
310 int i, r, l;
311
312 l = get_user_permissions (&fe->st);
313
314 if (is_octal)
315 {
316
317 l = width + l - 3;
318 r = l + 1;
319 }
320 else
321 {
322
323 l = l * 3 + 1;
324 r = l + 3;
325 }
326
327 for (i = 0; i < width; i++)
328 {
329 if (i >= l && i < r)
330 {
331 if (attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT)
332 tty_setcolor (CORE_MARKED_SELECTED_COLOR);
333 else
334 tty_setcolor (CORE_MARKED_COLOR);
335 }
336 else
337 tty_setcolor (color);
338
339 tty_print_char (dest[i]);
340 }
341 }
342
343
344
345
346 static const char *
347 string_file_name (const file_entry_t *fe, int len)
348 {
349 (void) len;
350
351 mc_g_string_copy (string_file_name_buffer, fe->fname);
352
353 return string_file_name_buffer->str;
354 }
355
356
357
358 static unsigned int
359 ilog10 (dev_t n)
360 {
361 unsigned int digits = 0;
362
363 do
364 {
365 digits++;
366 n /= 10;
367 }
368 while (n != 0);
369
370 return digits;
371 }
372
373
374
375 static void
376 format_device_number (char *buf, size_t bufsize, dev_t dev)
377 {
378 dev_t major_dev, minor_dev;
379 unsigned int major_digits, minor_digits;
380
381 major_dev = major (dev);
382 major_digits = ilog10 (major_dev);
383
384 minor_dev = minor (dev);
385 minor_digits = ilog10 (minor_dev);
386
387 g_assert (bufsize >= 1);
388
389 if (major_digits + 1 + minor_digits + 1 <= bufsize)
390 g_snprintf (buf, bufsize, "%lu,%lu", (unsigned long) major_dev, (unsigned long) minor_dev);
391 else
392 g_strlcpy (buf, _ ("[dev]"), bufsize);
393 }
394
395
396
397
398 static const char *
399 string_file_size (const file_entry_t *fe, int len)
400 {
401 static char buffer[BUF_TINY];
402
403
404 if (DIR_IS_DOTDOT (fe->fname->str))
405 return _ ("UP--DIR");
406
407 #ifdef HAVE_STRUCT_STAT_ST_RDEV
408 if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
409 format_device_number (buffer, len + 1, fe->st.st_rdev);
410 else
411 #endif
412 size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
413
414 return buffer;
415 }
416
417
418
419
420 static const char *
421 string_file_size_brief (const file_entry_t *fe, int len)
422 {
423 if (S_ISLNK (fe->st.st_mode) && !link_isdir (fe))
424 return _ ("SYMLINK");
425
426 if ((S_ISDIR (fe->st.st_mode) || link_isdir (fe)) && !fe->f.dir_size_computed
427 && !DIR_IS_DOTDOT (fe->fname->str))
428 return _ ("SUB-DIR");
429
430 return string_file_size (fe, len);
431 }
432
433
434
435
436 static const char *
437 string_file_type (const file_entry_t *fe, int len)
438 {
439 static char buffer[2];
440
441 (void) len;
442
443 if (S_ISDIR (fe->st.st_mode))
444 buffer[0] = PATH_SEP;
445 else if (S_ISLNK (fe->st.st_mode))
446 {
447 if (link_isdir (fe))
448 buffer[0] = '~';
449 else if (fe->f.stale_link != 0)
450 buffer[0] = '!';
451 else
452 buffer[0] = '@';
453 }
454 else if (S_ISCHR (fe->st.st_mode))
455 buffer[0] = '-';
456 else if (S_ISSOCK (fe->st.st_mode))
457 buffer[0] = '=';
458 else if (S_ISDOOR (fe->st.st_mode))
459 buffer[0] = '>';
460 else if (S_ISBLK (fe->st.st_mode))
461 buffer[0] = '+';
462 else if (S_ISFIFO (fe->st.st_mode))
463 buffer[0] = '|';
464 else if (S_ISNAM (fe->st.st_mode))
465 buffer[0] = '#';
466 else if (!S_ISREG (fe->st.st_mode))
467 buffer[0] = '?';
468 else if (is_exe (fe->st.st_mode))
469 buffer[0] = '*';
470 else
471 buffer[0] = ' ';
472 buffer[1] = '\0';
473 return buffer;
474 }
475
476
477
478
479 static const char *
480 string_file_mtime (const file_entry_t *fe, int len)
481 {
482 (void) len;
483
484 return file_date (fe->st.st_mtime);
485 }
486
487
488
489
490 static const char *
491 string_file_atime (const file_entry_t *fe, int len)
492 {
493 (void) len;
494
495 return file_date (fe->st.st_atime);
496 }
497
498
499
500
501 static const char *
502 string_file_ctime (const file_entry_t *fe, int len)
503 {
504 (void) len;
505
506 return file_date (fe->st.st_ctime);
507 }
508
509
510
511
512 static const char *
513 string_file_permission (const file_entry_t *fe, int len)
514 {
515 (void) len;
516
517 return string_perm (fe->st.st_mode);
518 }
519
520
521
522
523 static const char *
524 string_file_perm_octal (const file_entry_t *fe, int len)
525 {
526 static char buffer[10];
527
528 (void) len;
529
530 g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
531 return buffer;
532 }
533
534
535
536
537 static const char *
538 string_file_nlinks (const file_entry_t *fe, int len)
539 {
540 static char buffer[BUF_TINY];
541
542 (void) len;
543
544 g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
545 return buffer;
546 }
547
548
549
550
551 static const char *
552 string_inode (const file_entry_t *fe, int len)
553 {
554 static char buffer[10];
555
556 (void) len;
557
558 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_ino);
559 return buffer;
560 }
561
562
563
564
565 static const char *
566 string_file_nuid (const file_entry_t *fe, int len)
567 {
568 static char buffer[10];
569
570 (void) len;
571
572 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_uid);
573 return buffer;
574 }
575
576
577
578
579 static const char *
580 string_file_ngid (const file_entry_t *fe, int len)
581 {
582 static char buffer[10];
583
584 (void) len;
585
586 g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->st.st_gid);
587 return buffer;
588 }
589
590
591
592
593 static const char *
594 string_file_owner (const file_entry_t *fe, int len)
595 {
596 (void) len;
597
598 return get_owner (fe->st.st_uid);
599 }
600
601
602
603
604 static const char *
605 string_file_group (const file_entry_t *fe, int len)
606 {
607 (void) len;
608
609 return get_group (fe->st.st_gid);
610 }
611
612
613
614
615 static const char *
616 string_marked (const file_entry_t *fe, int len)
617 {
618 (void) len;
619
620 return fe->f.marked != 0 ? "*" : " ";
621 }
622
623
624
625
626 static const char *
627 string_space (const file_entry_t *fe, int len)
628 {
629 (void) fe;
630 (void) len;
631
632 return " ";
633 }
634
635
636
637
638 static const char *
639 string_dot (const file_entry_t *fe, int len)
640 {
641 (void) fe;
642 (void) len;
643
644 return ".";
645 }
646
647
648
649 static int
650 file_compute_color (const file_attr_t attr, file_entry_t *fe)
651 {
652 switch (attr)
653 {
654 case FATTR_CURRENT:
655 return CORE_SELECTED_COLOR;
656 case FATTR_MARKED:
657 return CORE_MARKED_COLOR;
658 case FATTR_MARKED_CURRENT:
659 return CORE_MARKED_SELECTED_COLOR;
660 case FATTR_STATUS:
661 return CORE_NORMAL_COLOR;
662 case FATTR_NORMAL:
663 default:
664 if (!panels_options.filetype_mode)
665 return CORE_NORMAL_COLOR;
666 }
667
668 return mc_fhl_get_color (mc_filehighlight, fe);
669 }
670
671
672
673
674 static int
675 panel_items (const WPanel *p)
676 {
677 return panel_lines (p) * p->list_cols;
678 }
679
680
681
682
683 static filename_scroll_flag_t
684 format_file (WPanel *panel, int file_index, int width, file_attr_t attr, gboolean isstatus,
685 int *field_length)
686 {
687 int color = CORE_NORMAL_COLOR;
688 int length = 0;
689 GSList *format, *home;
690 file_entry_t *fe = NULL;
691 filename_scroll_flag_t res = FILENAME_NOSCROLL;
692
693 *field_length = 0;
694
695 if (panel->dir.len != 0 && file_index < panel->dir.len)
696 {
697 fe = &panel->dir.list[file_index];
698 color = file_compute_color (attr, fe);
699 }
700
701 home = isstatus ? panel->status_format : panel->format;
702
703 for (format = home; format != NULL && length != width; format = g_slist_next (format))
704 {
705 format_item_t *fi = (format_item_t *) format->data;
706
707 if (fi->string_fn != NULL)
708 {
709 const char *txt = " ";
710 int len, perm = 0;
711 const char *prepared_text;
712 int name_offset = 0;
713
714 if (fe != NULL)
715 txt = fi->string_fn (fe, fi->field_len);
716
717 len = fi->field_len;
718 if (len + length > width)
719 len = width - length;
720 if (len <= 0)
721 break;
722
723 if (!isstatus && strcmp (fi->id, "name") == 0)
724 {
725 const int str_len = str_length (txt);
726 const unsigned int len_diff = (unsigned int) DOZ (str_len, len);
727
728 *field_length = len + 1;
729
730 panel->max_shift = MAX (panel->max_shift, len_diff);
731
732 if (len_diff != 0)
733 {
734 const unsigned int shift = MIN (panel->content_shift, len_diff);
735
736 if (shift != 0)
737 res |= FILENAME_SCROLL_LEFT;
738
739 name_offset = str_offset_to_pos (txt, shift);
740 if (str_length (txt + name_offset) > len)
741 res |= FILENAME_SCROLL_RIGHT;
742 }
743 }
744
745 if (panels_options.permission_mode)
746 {
747 if (strcmp (fi->id, "perm") == 0)
748 perm = 1;
749 else if (strcmp (fi->id, "mode") == 0)
750 perm = 2;
751 }
752
753 tty_setcolor (color);
754
755 if (!isstatus)
756 prepared_text = str_fit_to_term (txt + name_offset, len, HIDE_FIT (fi->just_mode));
757 else
758 prepared_text = str_fit_to_term (txt, len, fi->just_mode);
759
760 if (perm != 0 && fe != NULL)
761 add_permission_string (prepared_text, fi->field_len, fe, attr, color, perm != 1);
762 else
763 tty_print_string (prepared_text);
764
765 length += len;
766 }
767 else
768 {
769 if (attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT)
770 tty_setcolor (CORE_SELECTED_COLOR);
771 else
772 tty_setcolor (CORE_FRAME_COLOR);
773 tty_print_one_vline (TRUE);
774 length++;
775 }
776 }
777
778 if (length < width)
779 {
780 int y, x;
781
782 tty_getyx (&y, &x);
783 tty_draw_hline (y, x, ' ', width - length);
784 }
785
786 return res;
787 }
788
789
790
791 static void
792 repaint_file (WPanel *panel, int file_index, file_attr_t attr)
793 {
794 Widget *w = WIDGET (panel);
795
796 int nth_column = 0;
797 int width;
798 int offset = 0;
799 filename_scroll_flag_t ret_frm;
800 int ypos = 0;
801 int fln = 0;
802
803
804 width = w->rect.cols - 1;
805
806 nth_column = (file_index - panel->top) / panel_lines (panel);
807 width /= panel->list_cols;
808
809 offset = width * nth_column;
810
811 if (nth_column + 1 >= panel->list_cols)
812 width = w->rect.cols - offset - 1;
813
814 width--;
815
816
817 if (width <= 0)
818 return;
819
820 ypos = file_index - panel->top;
821 ypos %= panel_lines (panel);
822
823 ypos += 2;
824 widget_gotoyx (w, ypos, offset + 1);
825
826 ret_frm = format_file (panel, file_index, width, attr, FALSE, &fln);
827
828 if (nth_column + 1 < panel->list_cols)
829 {
830 tty_setcolor (CORE_FRAME_COLOR);
831 tty_print_one_vline (TRUE);
832 }
833
834 if (ret_frm != FILENAME_NOSCROLL)
835 {
836 if (panel->list_cols == 1 && fln > 0)
837 {
838 if (panel->list_format != list_long)
839 width = fln;
840 else
841 {
842 offset = width - fln + 1;
843 width = fln - 1;
844 }
845 }
846
847 const int file_color = attr == FATTR_CURRENT || attr == FATTR_MARKED_CURRENT
848 ? CORE_SELECTED_COLOR
849 : CORE_NORMAL_COLOR;
850
851 if ((ret_frm & FILENAME_SCROLL_LEFT) != 0)
852 {
853 const int scroll_left_char_color =
854 panel->list_format == list_long ? file_color : CORE_NORMAL_COLOR;
855
856 widget_gotoyx (w, ypos, offset);
857 tty_setcolor (scroll_left_char_color);
858 tty_print_string (panel_filename_scroll_left_char);
859 }
860
861 if ((ret_frm & FILENAME_SCROLL_RIGHT) != 0)
862 {
863 offset += width + 1;
864
865 const int scroll_right_char_color =
866 panel->list_format != list_long && g_slist_length (panel->format) > 2
867 ? file_color
868 : CORE_NORMAL_COLOR;
869
870 widget_gotoyx (w, ypos, offset);
871 tty_setcolor (scroll_right_char_color);
872 tty_print_string (panel_filename_scroll_right_char);
873 }
874 }
875 }
876
877
878
879 static void
880 repaint_status (WPanel *panel)
881 {
882 int width;
883
884 width = WIDGET (panel)->rect.cols - 2;
885 if (width > 0)
886 {
887 int fln = 0;
888
889 (void) format_file (panel, panel->current, width, FATTR_STATUS, TRUE, &fln);
890 }
891 }
892
893
894
895 static void
896 display_mini_info (WPanel *panel)
897 {
898 Widget *w = WIDGET (panel);
899 const file_entry_t *fe;
900
901 if (!panels_options.show_mini_info)
902 return;
903
904 widget_gotoyx (w, panel_lines (panel) + 3, 1);
905
906 if (panel->quick_search.active)
907 {
908 tty_setcolor (CORE_INPUT_COLOR);
909 tty_print_char ('/');
910 tty_print_string (
911 str_fit_to_term (panel->quick_search.buffer->str, w->rect.cols - 3, J_LEFT));
912 return;
913 }
914
915
916 set_colors (panel);
917
918 fe = panel_current_entry (panel);
919
920 if (fe == NULL)
921
922 repaint_status (panel);
923 else if (S_ISLNK (fe->st.st_mode))
924 {
925 char link_target[MC_MAXPATHLEN];
926 vfs_path_t *lc_link_vpath;
927 int len;
928
929 lc_link_vpath = vfs_path_append_new (panel->cwd_vpath, fe->fname->str, (char *) NULL);
930 len = mc_readlink (lc_link_vpath, link_target, MC_MAXPATHLEN - 1);
931 vfs_path_free (lc_link_vpath, TRUE);
932 if (len > 0)
933 {
934 link_target[len] = 0;
935 tty_print_string ("-> ");
936 tty_print_string (str_fit_to_term (link_target, w->rect.cols - 5, J_LEFT_FIT));
937 }
938 else
939 tty_print_string (str_fit_to_term (_ ("<readlink failed>"), w->rect.cols - 2, J_LEFT));
940 }
941 else if (DIR_IS_DOTDOT (fe->fname->str))
942 {
943
944
945
946
947 tty_print_string (str_fit_to_term (_ ("UP--DIR"), w->rect.cols - 2, J_LEFT));
948 }
949 else
950
951 repaint_status (panel);
952 }
953
954
955
956 static void
957 paint_dir (WPanel *panel)
958 {
959 int i;
960 int items;
961
962 items = panel_items (panel);
963
964 panel->max_shift = 0;
965
966 for (i = 0; i < items; i++)
967 {
968 file_attr_t attr = FATTR_NORMAL;
969 int n;
970 gboolean marked;
971
972 n = i + panel->top;
973 marked = (panel->dir.list[n].f.marked != 0);
974
975 if (n < panel->dir.len)
976 {
977 if (panel->current == n && widget_get_state (WIDGET (panel), WST_FOCUSED))
978 attr = marked ? FATTR_MARKED_CURRENT : FATTR_CURRENT;
979 else if (marked)
980 attr = FATTR_MARKED;
981 }
982
983 repaint_file (panel, n, attr);
984 }
985
986 tty_set_normal_attrs ();
987 }
988
989
990
991 static void
992 display_total_marked_size (const WPanel *panel, int y, int x, gboolean size_only)
993 {
994 const Widget *w = CONST_WIDGET (panel);
995
996 char buffer[BUF_SMALL], b_bytes[BUF_SMALL];
997 const char *buf;
998 int cols;
999
1000 if (panel->marked <= 0)
1001 return;
1002
1003 buf = size_only ? b_bytes : buffer;
1004 cols = w->rect.cols - 2;
1005
1006 g_strlcpy (b_bytes, size_trunc_sep (panel->total, panels_options.kilobyte_si),
1007 sizeof (b_bytes));
1008
1009 if (!size_only)
1010 g_snprintf (buffer, sizeof (buffer),
1011 ngettext ("%s in %d file", "%s in %d files", panel->marked), b_bytes,
1012 panel->marked);
1013
1014
1015 buf = str_trunc (buf, cols - 4);
1016
1017 if (x < 0)
1018
1019 x = (w->rect.cols - str_term_width1 (buf)) / 2 - 1;
1020
1021
1022
1023
1024
1025 widget_gotoyx (w, y, x);
1026 tty_setcolor (CORE_MARKED_COLOR);
1027 tty_printf (" %s ", buf);
1028 }
1029
1030
1031
1032 static void
1033 mini_info_separator (const WPanel *panel)
1034 {
1035 if (panels_options.show_mini_info)
1036 {
1037 int y;
1038
1039 y = panel_lines (panel) + 2;
1040
1041 tty_setcolor (CORE_NORMAL_COLOR);
1042
1043
1044 display_total_marked_size (panel, y, -1, FALSE);
1045 }
1046 }
1047
1048
1049
1050 static void
1051 show_free_space (const WPanel *panel)
1052 {
1053
1054 static struct my_statfs myfs_stats;
1055
1056 static char *old_cwd = NULL;
1057
1058
1059 if (!vfs_file_is_local (panel->cwd_vpath) || !free_space)
1060 return;
1061
1062 if (old_cwd == NULL || strcmp (old_cwd, vfs_path_as_str (panel->cwd_vpath)) != 0)
1063 {
1064 char rpath[PATH_MAX];
1065
1066 init_my_statfs ();
1067 g_free (old_cwd);
1068 old_cwd = g_strdup (vfs_path_as_str (panel->cwd_vpath));
1069
1070 if (mc_realpath (old_cwd, rpath) == NULL)
1071 return;
1072
1073 my_statfs (&myfs_stats, rpath);
1074 }
1075
1076 if (myfs_stats.avail != 0 || myfs_stats.total != 0)
1077 {
1078 const Widget *w = CONST_WIDGET (panel);
1079 char buffer1[6], buffer2[6], tmp[BUF_SMALL];
1080
1081 size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
1082 panels_options.kilobyte_si);
1083 size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
1084 panels_options.kilobyte_si);
1085 g_snprintf (tmp, sizeof (tmp), " %s / %s (%d%%) ", buffer1, buffer2,
1086 myfs_stats.total == 0
1087 ? 0
1088 : (int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
1089 widget_gotoyx (w, w->rect.lines - 1, w->rect.cols - 2 - (int) strlen (tmp));
1090 tty_setcolor (CORE_NORMAL_COLOR);
1091 tty_print_string (tmp);
1092 }
1093 }
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105 static char *
1106 panel_correct_path_to_show (const WPanel *panel)
1107 {
1108 vfs_path_t *last_vpath;
1109 const vfs_path_element_t *path_element;
1110 char *return_path;
1111 int elements_count;
1112
1113 elements_count = vfs_path_elements_count (panel->cwd_vpath);
1114
1115
1116 path_element = vfs_path_element_clone (vfs_path_get_by_index (panel->cwd_vpath, -1));
1117
1118 if (elements_count > 1
1119 && (strcmp (path_element->class->name, "cpiofs") == 0
1120 || strcmp (path_element->class->name, "extfs") == 0
1121 || strcmp (path_element->class->name, "tarfs") == 0))
1122 {
1123 const char *archive_name;
1124 const vfs_path_element_t *prev_path_element;
1125
1126
1127 prev_path_element = vfs_path_get_by_index (panel->cwd_vpath, -2);
1128 archive_name = strrchr (prev_path_element->path, PATH_SEP);
1129 if (archive_name != NULL)
1130 last_vpath = vfs_path_from_str_flags (archive_name + 1, VPF_NO_CANON);
1131 else
1132 {
1133 last_vpath = vfs_path_from_str_flags (prev_path_element->path, VPF_NO_CANON);
1134 last_vpath->relative = TRUE;
1135 }
1136 }
1137 else
1138 last_vpath = vfs_path_new (TRUE);
1139
1140 vfs_path_add_element (last_vpath, path_element);
1141 return_path = vfs_path_to_str_flags (last_vpath, 0,
1142 VPF_STRIP_HOME | VPF_STRIP_PASSWORD | VPF_HIDE_CHARSET);
1143 vfs_path_free (last_vpath, TRUE);
1144
1145 return return_path;
1146 }
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157 static char *
1158 panel_get_encoding_info_str (const WPanel *panel)
1159 {
1160 char *ret_str = NULL;
1161 const vfs_path_element_t *path_element;
1162
1163 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
1164 if (path_element->encoding != NULL)
1165 ret_str = g_strdup_printf ("[%s]", path_element->encoding);
1166
1167 return ret_str;
1168 }
1169
1170
1171
1172 static void
1173 show_vertical_separator_tee (const WPanel *panel, int col)
1174 {
1175 const Widget *w = CONST_WIDGET (panel);
1176
1177 widget_gotoyx (w, 0, col);
1178 tty_print_char (mc_tty_frm[MC_TTY_FRM_DTOPMIDDLE]);
1179
1180 if (panels_options.show_mini_info)
1181 {
1182 widget_gotoyx (w, w->rect.lines - 3, col);
1183 tty_print_char (mc_tty_frm[MC_TTY_FRM_BOTTOMMIDDLE]);
1184 }
1185 else
1186 {
1187 widget_gotoyx (w, w->rect.lines - 1, col);
1188 tty_print_char (mc_tty_frm[MC_TTY_FRM_DBOTTOMMIDDLE]);
1189 }
1190 }
1191
1192
1193
1194 static void
1195 show_dir (const WPanel *panel)
1196 {
1197 const Widget *w = CONST_WIDGET (panel);
1198 gchar *tmp;
1199 int col, i;
1200
1201
1202 tty_set_normal_attrs ();
1203 tty_setcolor (CORE_FRAME_COLOR);
1204 tty_draw_box (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, FALSE);
1205
1206
1207 if (panels_options.show_mini_info)
1208 {
1209 int y;
1210
1211 y = panel_lines (panel) + 2;
1212
1213 widget_gotoyx (w, y, 0);
1214 tty_print_char (mc_tty_frm[MC_TTY_FRM_DLEFTMIDDLE]);
1215 tty_draw_hline (w->rect.y + y, w->rect.x + 1, mc_tty_frm[MC_TTY_FRM_HORIZ],
1216 w->rect.cols - 2);
1217 widget_gotoyx (w, y, w->rect.cols - 1);
1218 tty_print_char (mc_tty_frm[MC_TTY_FRM_DRIGHTMIDDLE]);
1219 }
1220
1221
1222 col = 0;
1223 for (i = 0; i < panel->list_cols; i++)
1224 {
1225 GSList *format;
1226
1227 for (format = panel->format; format != NULL; format = g_slist_next (format))
1228 {
1229 format_item_t *fi = (format_item_t *) format->data;
1230
1231 if (fi->string_fn != NULL)
1232 col += fi->field_len;
1233 else
1234 show_vertical_separator_tee (panel, ++col);
1235 }
1236
1237 if (i < panel->list_cols - 1)
1238 show_vertical_separator_tee (panel, ++col);
1239 }
1240
1241 widget_gotoyx (w, 0, 1);
1242 tty_print_string (panel_history_prev_item_char);
1243
1244 tmp = panels_options.show_dot_files ? panel_hiddenfiles_show_char : panel_hiddenfiles_hide_char;
1245 tmp = g_strdup_printf ("%s[%s]%s", tmp, panel_history_show_list_char,
1246 panel_history_next_item_char);
1247
1248 widget_gotoyx (w, 0, w->rect.cols - 6);
1249 tty_print_string (tmp);
1250
1251 g_free (tmp);
1252
1253 tty_setcolor (CORE_NORMAL_COLOR);
1254 widget_gotoyx (w, 0, 3);
1255
1256 if (panel->is_panelized)
1257 tty_printf (" %s ", _ ("Panelize"));
1258 else
1259 {
1260 tmp = panel_get_encoding_info_str (panel);
1261 if (tmp != NULL)
1262 {
1263 tty_printf ("%s", tmp);
1264 widget_gotoyx (w, 0, 3 + strlen (tmp));
1265 g_free (tmp);
1266 }
1267 }
1268
1269 if (widget_get_state (WIDGET (panel), WST_FOCUSED))
1270 tty_setcolor (CORE_REVERSE_COLOR);
1271
1272 tmp = panel_correct_path_to_show (panel);
1273 tty_printf (" %s ", str_term_trim (tmp, MIN (MAX (w->rect.cols - 12, 0), w->rect.cols)));
1274 g_free (tmp);
1275
1276 if (!panels_options.show_mini_info)
1277 {
1278 if (panel->marked == 0)
1279 {
1280 const file_entry_t *fe;
1281
1282 fe = panel_current_entry (panel);
1283
1284
1285 if (fe != NULL && S_ISREG (fe->st.st_mode))
1286 {
1287 char buffer[BUF_SMALL];
1288
1289 g_snprintf (buffer, sizeof (buffer), " %s ",
1290 size_trunc_sep (fe->st.st_size, panels_options.kilobyte_si));
1291 tty_setcolor (CORE_NORMAL_COLOR);
1292 widget_gotoyx (w, w->rect.lines - 1, 4);
1293 tty_print_string (buffer);
1294 }
1295 }
1296 else
1297 {
1298
1299
1300 display_total_marked_size (panel, w->rect.lines - 1, 2, TRUE);
1301 }
1302 }
1303
1304 show_free_space (panel);
1305
1306 if (widget_get_state (WIDGET (panel), WST_FOCUSED))
1307 tty_set_normal_attrs ();
1308 }
1309
1310
1311
1312 static void
1313 adjust_top_file (WPanel *panel)
1314 {
1315 int items;
1316
1317 items = panel_items (panel);
1318
1319 if (panel->dir.len <= items || panel->current < 0)
1320 {
1321
1322
1323 panel->top = 0;
1324 }
1325 else
1326 {
1327 int i;
1328
1329
1330 panel->current = CLAMP (panel->current, 0, panel->dir.len - 1);
1331
1332
1333
1334
1335
1336
1337
1338 if (panel->top < 0)
1339 panel->top = 0;
1340
1341 i = panel->current - items + 1;
1342 if (panel->top < i)
1343 panel->top = i;
1344
1345 i = panel->dir.len - items;
1346 if (panel->top > i)
1347 panel->top = i;
1348
1349 if (panel->top > panel->current)
1350 panel->top = panel->current;
1351 }
1352 }
1353
1354
1355
1356
1357
1358
1359
1360
1361 static char *
1362 panel_save_name (WPanel *panel)
1363 {
1364
1365 if ((mc_global.midnight_shutdown && auto_save_setup) || saving_setup)
1366 return g_strdup (panel->name);
1367
1368 return g_strconcat ("Temporal:", panel->name, (char *) NULL);
1369 }
1370
1371
1372
1373 static void
1374 directory_history_add (WPanel *panel, const vfs_path_t *vpath)
1375 {
1376 char *tmp;
1377
1378 tmp = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
1379 panel->dir_history.list = list_append_unique (panel->dir_history.list, tmp);
1380 panel->dir_history.current = panel->dir_history.list;
1381 }
1382
1383
1384
1385
1386 static gboolean
1387 panel_load_history (const gchar *event_group_name, const gchar *event_name, gpointer init_data,
1388 gpointer data)
1389 {
1390 WPanel *p = PANEL (init_data);
1391 ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
1392
1393 (void) event_group_name;
1394 (void) event_name;
1395
1396 if (ev->receiver == NULL || ev->receiver == WIDGET (p))
1397 {
1398 if (ev->cfg != NULL)
1399 p->dir_history.list = mc_config_history_load (ev->cfg, p->dir_history.name);
1400 else
1401 p->dir_history.list = mc_config_history_get (p->dir_history.name);
1402
1403 directory_history_add (p, p->cwd_vpath);
1404 }
1405
1406 return TRUE;
1407 }
1408
1409
1410
1411
1412 static gboolean
1413 panel_save_history (const gchar *event_group_name, const gchar *event_name, gpointer init_data,
1414 gpointer data)
1415 {
1416 WPanel *p = PANEL (init_data);
1417 ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
1418
1419 (void) event_group_name;
1420 (void) event_name;
1421
1422 mc_config_history_save (ev->cfg, p->dir_history.name, p->dir_history.list);
1423
1424 return TRUE;
1425 }
1426
1427
1428
1429 static void
1430 panel_destroy (WPanel *p)
1431 {
1432 size_t i;
1433
1434 if (panels_options.auto_save_setup)
1435 {
1436 char *name;
1437
1438 name = panel_save_name (p);
1439 panel_save_setup (p, name);
1440 g_free (name);
1441 }
1442
1443 panel_clean_dir (p);
1444
1445
1446 if (p->dir_history.list != NULL)
1447 {
1448
1449 p->dir_history.list = g_list_first (p->dir_history.list);
1450 g_list_free_full (p->dir_history.list, g_free);
1451 }
1452 g_free (p->dir_history.name);
1453
1454 file_filter_clear (&p->filter);
1455
1456 g_slist_free_full (p->format, (GDestroyNotify) format_item_free);
1457 g_slist_free_full (p->status_format, (GDestroyNotify) format_item_free);
1458
1459 g_free (p->user_format);
1460 for (i = 0; i < LIST_FORMATS; i++)
1461 g_free (p->user_status_format[i]);
1462
1463 g_free (p->name);
1464
1465 panelized_descr_free (p->panelized_descr);
1466
1467 g_string_free (p->quick_search.buffer, TRUE);
1468 g_string_free (p->quick_search.prev_buffer, TRUE);
1469
1470 vfs_path_free (p->lwd_vpath, TRUE);
1471 vfs_path_free (p->cwd_vpath, TRUE);
1472 }
1473
1474
1475
1476 static void
1477 panel_paint_sort_info (const WPanel *panel)
1478 {
1479 if (*panel->sort_field->hotkey != '\0')
1480 {
1481 char str[BUF_TINY];
1482
1483 if (panel->sort_info.reverse)
1484 {
1485 g_snprintf (str, sizeof (str), "%s%s", panel_sort_up_char,
1486 Q_ (panel->sort_field->hotkey));
1487 panel_sort_up_indicator_width = str_term_width1 (str);
1488 }
1489 else
1490 {
1491 g_snprintf (str, sizeof (str), "%s%s", panel_sort_down_char,
1492 Q_ (panel->sort_field->hotkey));
1493 panel_sort_down_indicator_width = str_term_width1 (str);
1494 }
1495 widget_gotoyx (panel, 1, 1);
1496 tty_print_string (str);
1497 }
1498 }
1499
1500
1501
1502 static const char *
1503 panel_get_title_without_hotkey (const char *title)
1504 {
1505 static char translated_title[BUF_TINY];
1506
1507 if (title == NULL || title[0] == '\0')
1508 translated_title[0] = '\0';
1509 else
1510 {
1511 char *hkey;
1512
1513 g_snprintf (translated_title, sizeof (translated_title), "%s", _ (title));
1514
1515 hkey = strchr (translated_title, '&');
1516 if (hkey != NULL && hkey[1] != '\0')
1517 memmove (hkey, hkey + 1, strlen (hkey));
1518 }
1519
1520 return translated_title;
1521 }
1522
1523
1524
1525 static void
1526 panel_print_header (const WPanel *panel)
1527 {
1528 const Widget *w = CONST_WIDGET (panel);
1529
1530 int y, x;
1531 int i;
1532 GString *format_txt;
1533
1534 widget_gotoyx (w, 1, 1);
1535 tty_getyx (&y, &x);
1536 tty_setcolor (CORE_NORMAL_COLOR);
1537 tty_draw_hline (y, x, ' ', w->rect.cols - 2);
1538
1539 format_txt = g_string_new ("");
1540
1541 for (i = 0; i < panel->list_cols; i++)
1542 {
1543 GSList *format;
1544
1545 for (format = panel->format; format != NULL; format = g_slist_next (format))
1546 {
1547 format_item_t *fi = (format_item_t *) format->data;
1548
1549 if (fi->string_fn != NULL)
1550 {
1551 g_string_set_size (format_txt, 0);
1552
1553 if (panel->list_format == list_long && strcmp (fi->id, panel->sort_field->id) == 0)
1554 g_string_append (format_txt,
1555 panel->sort_info.reverse ? panel_sort_up_char
1556 : panel_sort_down_char);
1557
1558 g_string_append (format_txt, fi->title);
1559
1560 if (panel->filter.handler != NULL && strcmp (fi->id, "name") == 0)
1561 {
1562 g_string_append (format_txt, " [");
1563 g_string_append (format_txt, panel->filter.value);
1564 g_string_append (format_txt, "]");
1565 }
1566
1567 tty_setcolor (CORE_HEADER_COLOR);
1568 tty_print_string (str_fit_to_term (format_txt->str, fi->field_len, J_CENTER_LEFT));
1569 }
1570 else
1571 {
1572 tty_setcolor (CORE_FRAME_COLOR);
1573 tty_print_one_vline (TRUE);
1574 }
1575 }
1576
1577 if (i < panel->list_cols - 1)
1578 {
1579 tty_setcolor (CORE_FRAME_COLOR);
1580 tty_print_one_vline (TRUE);
1581 }
1582 }
1583
1584 g_string_free (format_txt, TRUE);
1585
1586 if (panel->list_format != list_long)
1587 panel_paint_sort_info (panel);
1588 }
1589
1590
1591
1592 static const char *
1593 parse_panel_size (WPanel *panel, const char *format, gboolean isstatus)
1594 {
1595 panel_display_t frame = frame_half;
1596
1597 format = skip_separators (format);
1598
1599 if (strncmp (format, "full", 4) == 0)
1600 {
1601 frame = frame_full;
1602 format += 4;
1603 }
1604 else if (strncmp (format, "half", 4) == 0)
1605 {
1606 frame = frame_half;
1607 format += 4;
1608 }
1609
1610 if (!isstatus)
1611 {
1612 panel->frame_size = frame;
1613 panel->list_cols = 1;
1614 }
1615
1616
1617 format = skip_separators (format);
1618
1619 if (g_ascii_isdigit (*format))
1620 {
1621 if (!isstatus)
1622 {
1623 panel->list_cols = g_ascii_digit_value (*format);
1624 if (panel->list_cols < 1)
1625 panel->list_cols = 1;
1626 }
1627
1628 format++;
1629 }
1630
1631 if (!isstatus)
1632 panel_update_cols (WIDGET (panel), panel->frame_size);
1633
1634 return skip_separators (format);
1635 }
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654 static GSList *
1655 parse_display_format (WPanel *panel, const char *format, char **error, gboolean isstatus,
1656 int *res_total_cols)
1657 {
1658 GSList *home = NULL;
1659 int total_cols = 0;
1660 size_t i;
1661
1662 static size_t i18n_timelength = 0;
1663
1664 *error = NULL;
1665
1666 if (i18n_timelength == 0)
1667 {
1668 i18n_timelength = i18n_checktimelength ();
1669
1670 for (i = 0; panel_fields[i].id != NULL; i++)
1671 if (strcmp ("time", panel_fields[i].id + 1) == 0)
1672 panel_fields[i].min_size = i18n_timelength;
1673 }
1674
1675
1676
1677
1678
1679 format = parse_panel_size (panel, format, isstatus);
1680
1681 while (*format != '\0')
1682 {
1683 format_item_t *darr;
1684 align_crt_t justify;
1685 gboolean set_justify = TRUE;
1686 gboolean found = FALSE;
1687 size_t klen = 0;
1688
1689 darr = g_new0 (format_item_t, 1);
1690 home = g_slist_append (home, darr);
1691
1692 format = skip_separators (format);
1693
1694 switch (*format)
1695 {
1696 case '<':
1697 justify = J_LEFT;
1698 format = skip_separators (format + 1);
1699 break;
1700 case '=':
1701 justify = J_CENTER;
1702 format = skip_separators (format + 1);
1703 break;
1704 case '>':
1705 justify = J_RIGHT;
1706 format = skip_separators (format + 1);
1707 break;
1708 default:
1709 justify = J_LEFT;
1710 set_justify = FALSE;
1711 break;
1712 }
1713
1714 for (i = 0; !found && panel_fields[i].id != NULL; i++)
1715 {
1716 klen = strlen (panel_fields[i].id);
1717 found = strncmp (format, panel_fields[i].id, klen) == 0;
1718 }
1719
1720 if (found)
1721 {
1722 i--;
1723 format += klen;
1724
1725 darr->requested_field_len = panel_fields[i].min_size;
1726 darr->string_fn = panel_fields[i].string_fn;
1727 darr->title = g_strdup (panel_get_title_without_hotkey (panel_fields[i].title_hotkey));
1728 darr->id = panel_fields[i].id;
1729 darr->expand = panel_fields[i].expands;
1730 darr->just_mode = panel_fields[i].default_just;
1731
1732 if (set_justify)
1733 {
1734 if (IS_FIT (darr->just_mode))
1735 darr->just_mode = MAKE_FIT (justify);
1736 else
1737 darr->just_mode = justify;
1738 }
1739
1740 format = skip_separators (format);
1741
1742
1743 if (*format == ':')
1744 {
1745 int req_length;
1746
1747
1748
1749
1750 darr->expand = FALSE;
1751 format++;
1752 req_length = atoi (format);
1753 darr->requested_field_len = req_length;
1754
1755 format = skip_numbers (format);
1756
1757
1758 if (*format == '+')
1759 {
1760 darr->expand = TRUE;
1761 format++;
1762 }
1763 }
1764 }
1765 else
1766 {
1767 size_t pos;
1768 char *tmp_format;
1769
1770 pos = strlen (format);
1771 if (pos > 8)
1772 pos = 8;
1773
1774 tmp_format = g_strndup (format, pos);
1775 g_slist_free_full (home, (GDestroyNotify) format_item_free);
1776 *error =
1777 g_strconcat (_ ("Unknown tag on display format:"), " ", tmp_format, (char *) NULL);
1778 g_free (tmp_format);
1779
1780 return NULL;
1781 }
1782
1783 total_cols += darr->requested_field_len;
1784 }
1785
1786 *res_total_cols = total_cols;
1787 return home;
1788 }
1789
1790
1791
1792 static GSList *
1793 use_display_format (WPanel *panel, const char *format, char **error, gboolean isstatus)
1794 {
1795 #define MAX_EXPAND 4
1796 int expand_top = 0;
1797 int usable_columns;
1798 int total_cols = 0;
1799 GSList *darr, *home;
1800
1801 if (format == NULL)
1802 format = DEFAULT_USER_FORMAT;
1803
1804 home = parse_display_format (panel, format, error, isstatus, &total_cols);
1805
1806 if (*error != NULL)
1807 return NULL;
1808
1809 panel->dirty = TRUE;
1810
1811
1812 usable_columns = WIDGET (panel)->rect.cols - 1;
1813
1814 if (!isstatus)
1815 usable_columns /= panel->list_cols;
1816 usable_columns--;
1817
1818
1819 for (darr = home; darr != NULL && expand_top < MAX_EXPAND; darr = g_slist_next (darr))
1820 {
1821 format_item_t *fi = (format_item_t *) darr->data;
1822
1823 fi->field_len = fi->requested_field_len;
1824 if (fi->expand)
1825 expand_top++;
1826 }
1827
1828
1829 if (total_cols > usable_columns)
1830 {
1831 int dif;
1832 int pdif = 0;
1833
1834 dif = total_cols - usable_columns;
1835
1836 while (dif != 0 && pdif != dif)
1837 {
1838 pdif = dif;
1839
1840 for (darr = home; darr != NULL; darr = g_slist_next (darr))
1841 {
1842 format_item_t *fi = (format_item_t *) darr->data;
1843
1844 if (dif != 0 && fi->field_len != 1)
1845 {
1846 fi->field_len--;
1847 dif--;
1848 }
1849 }
1850 }
1851
1852 total_cols = usable_columns;
1853 }
1854
1855
1856 if (usable_columns > total_cols && expand_top != 0)
1857 {
1858 int i;
1859 int spaces;
1860
1861 spaces = (usable_columns - total_cols) / expand_top;
1862
1863 for (i = 0, darr = home; darr != NULL && i < expand_top; darr = g_slist_next (darr))
1864 {
1865 format_item_t *fi = (format_item_t *) darr->data;
1866
1867 if (fi->expand)
1868 {
1869 fi->field_len += spaces;
1870 if (i == 0)
1871 fi->field_len += (usable_columns - total_cols) % expand_top;
1872 i++;
1873 }
1874 }
1875 }
1876
1877 return home;
1878 }
1879
1880
1881
1882
1883 static const char *
1884 panel_format (WPanel *panel)
1885 {
1886 switch (panel->list_format)
1887 {
1888 case list_long:
1889 return "full perm space nlink space owner space group space size space mtime space name";
1890
1891 case list_brief:
1892 {
1893 static char format[BUF_TINY];
1894 int brief_cols = panel->brief_cols;
1895
1896 if (brief_cols < 1)
1897 brief_cols = 2;
1898
1899 if (brief_cols > 9)
1900 brief_cols = 9;
1901
1902 g_snprintf (format, sizeof (format), "half %d type name", brief_cols);
1903 return format;
1904 }
1905
1906 case list_user:
1907 return panel->user_format;
1908
1909 default:
1910 case list_full:
1911 return "half type name | size | mtime";
1912 }
1913 }
1914
1915
1916
1917 static const char *
1918 mini_status_format (WPanel *panel)
1919 {
1920 if (panel->user_mini_status)
1921 return panel->user_status_format[panel->list_format];
1922
1923 switch (panel->list_format)
1924 {
1925 case list_long:
1926 return "full perm space nlink space owner space group space size space mtime space name";
1927
1928 case list_brief:
1929 return "half type name space bsize space perm space";
1930
1931 case list_full:
1932 return "half type name";
1933
1934 default:
1935 case list_user:
1936 return panel->user_format;
1937 }
1938 }
1939
1940
1941
1942
1943
1944
1945
1946 static void
1947 cd_up_dir (WPanel *panel)
1948 {
1949 vfs_path_t *up_dir;
1950
1951 up_dir = vfs_path_from_str ("..");
1952 panel_cd (panel, up_dir, cd_exact);
1953 vfs_path_free (up_dir, TRUE);
1954 }
1955
1956
1957
1958
1959 static cb_ret_t
1960 maybe_cd (WPanel *panel, gboolean move_up_dir)
1961 {
1962 if (panels_options.navigate_with_arrows && input_is_empty (cmdline))
1963 {
1964 const file_entry_t *fe;
1965
1966 if (move_up_dir)
1967 {
1968 cd_up_dir (panel);
1969 return MSG_HANDLED;
1970 }
1971
1972 fe = panel_current_entry (panel);
1973
1974 if (fe != NULL)
1975 {
1976 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe))
1977 {
1978 vfs_path_t *vpath;
1979
1980 vpath = vfs_path_from_str (fe->fname->str);
1981 panel_cd (panel, vpath, cd_exact);
1982 vfs_path_free (vpath, TRUE);
1983 }
1984
1985 return MSG_HANDLED;
1986 }
1987 }
1988
1989 return MSG_NOT_HANDLED;
1990 }
1991
1992
1993
1994
1995 static cb_ret_t
1996 force_maybe_cd (WPanel *panel)
1997 {
1998 if (input_is_empty (cmdline))
1999 {
2000 cd_up_dir (panel);
2001 return MSG_HANDLED;
2002 }
2003
2004 return MSG_NOT_HANDLED;
2005 }
2006
2007
2008
2009 static void
2010 unselect_item (WPanel *panel)
2011 {
2012 const file_entry_t *fe;
2013
2014 fe = panel_current_entry (panel);
2015 repaint_file (panel, panel->current,
2016 fe != NULL && fe->f.marked != 0 ? FATTR_MARKED : FATTR_NORMAL);
2017 }
2018
2019
2020
2021
2022 static void
2023 panel_select_ext_cmd (WPanel *panel)
2024 {
2025 const file_entry_t *fe;
2026 gboolean do_select;
2027 char *reg_exp, *cur_file_ext;
2028 mc_search_t *search;
2029 int i;
2030
2031 fe = panel_current_entry (panel);
2032 if (fe == NULL)
2033 return;
2034
2035 do_select = (fe->f.marked == 0);
2036
2037 cur_file_ext = str_regex_escape (extension (fe->fname->str));
2038 if (cur_file_ext[0] != '\0')
2039 reg_exp = g_strconcat ("^.*\\.", cur_file_ext, "$", (char *) NULL);
2040 else
2041 reg_exp = g_strdup ("^[^\\.]+$");
2042
2043 g_free (cur_file_ext);
2044
2045 search = mc_search_new (reg_exp, NULL);
2046 search->search_type = MC_SEARCH_T_REGEX;
2047 search->is_case_sensitive = FALSE;
2048
2049 for (i = 0; i < panel->dir.len; i++)
2050 {
2051 fe = &panel->dir.list[i];
2052
2053 if (DIR_IS_DOTDOT (fe->fname->str) || S_ISDIR (fe->st.st_mode))
2054 continue;
2055
2056 if (!mc_search_run (search, fe->fname->str, 0, fe->fname->len, NULL))
2057 continue;
2058
2059 do_file_mark (panel, i, do_select ? 1 : 0);
2060 }
2061
2062 mc_search_free (search);
2063 g_free (reg_exp);
2064 }
2065
2066
2067
2068 static void
2069 panel_set_current (WPanel *panel, int i)
2070 {
2071 if (i != panel->current)
2072 {
2073 panel->dirty = TRUE;
2074 panel->current = i;
2075 panel->top = panel->current - (WIDGET (panel)->rect.lines - 2) / 2;
2076 if (panel->top < 0)
2077 panel->top = 0;
2078 }
2079 }
2080
2081
2082
2083 static int
2084 panel_current_at_half (const WPanel *panel)
2085 {
2086 int lines, top;
2087
2088 lines = panel_lines (panel);
2089
2090
2091 top = panel->top;
2092 if (panel->list_cols > 1)
2093 top += lines * ((panel->current - top) / lines);
2094
2095 return (panel->current - top - lines / 2);
2096 }
2097
2098
2099
2100 static void
2101 move_down (WPanel *panel)
2102 {
2103 int items;
2104
2105 if (panel->dir.len == 0)
2106 return;
2107
2108 if (panel->current >= panel->dir.len - 1)
2109 {
2110 panel->current = panel->dir.len - 1;
2111 return;
2112 }
2113
2114 unselect_item (panel);
2115 panel->current++;
2116
2117 items = panel_items (panel);
2118
2119 if (panels_options.scroll_pages && panel->current - panel->top == items)
2120 {
2121
2122 panel->top += items / 2;
2123 if (panel->top > panel->dir.len - items)
2124 panel->top = panel->dir.len - items;
2125 paint_dir (panel);
2126 }
2127 else if (panels_options.scroll_center && panel_current_at_half (panel) > 0)
2128 {
2129
2130 panel->top++;
2131 if (panel->top > panel->dir.len - items)
2132 panel->top = panel->dir.len - items;
2133 }
2134 select_item (panel);
2135 }
2136
2137
2138
2139 static void
2140 move_up (WPanel *panel)
2141 {
2142 if (panel->dir.len == 0 || panel->current <= 0)
2143 return;
2144
2145 unselect_item (panel);
2146 panel->current--;
2147
2148 if (panels_options.scroll_pages && panel->current < panel->top)
2149 {
2150
2151 panel->top -= panel_items (panel) / 2;
2152 if (panel->top < 0)
2153 panel->top = 0;
2154 paint_dir (panel);
2155 }
2156 else if (panels_options.scroll_center && panel_current_at_half (panel) < 0)
2157 {
2158
2159 panel->top--;
2160 if (panel->top < 0)
2161 panel->top = 0;
2162 }
2163 select_item (panel);
2164 }
2165
2166
2167
2168
2169 static void
2170 panel_move_current (WPanel *panel, int lines)
2171 {
2172 int new_pos;
2173 gboolean adjust = FALSE;
2174
2175 if (panel->dir.len == 0 || panel->current < 0)
2176 return;
2177
2178 new_pos = panel->current + lines;
2179 if (new_pos >= panel->dir.len)
2180 new_pos = panel->dir.len - 1;
2181
2182 if (new_pos < 0)
2183 new_pos = 0;
2184
2185 unselect_item (panel);
2186 panel->current = new_pos;
2187
2188 if (panel->current - panel->top >= panel_items (panel))
2189 {
2190 panel->top += lines;
2191 adjust = TRUE;
2192 }
2193
2194 if (panel->current - panel->top < 0)
2195 {
2196 panel->top += lines;
2197 adjust = TRUE;
2198 }
2199
2200 if (adjust)
2201 {
2202 if (panel->top > panel->current)
2203 panel->top = panel->current;
2204 if (panel->top < 0)
2205 panel->top = 0;
2206 paint_dir (panel);
2207 }
2208 select_item (panel);
2209 }
2210
2211
2212
2213 static cb_ret_t
2214 move_left (WPanel *panel)
2215 {
2216 if (panel->list_cols > 1)
2217 {
2218 panel_move_current (panel, -panel_lines (panel));
2219 return MSG_HANDLED;
2220 }
2221
2222 return maybe_cd (panel, TRUE);
2223 }
2224
2225
2226
2227 static cb_ret_t
2228 move_right (WPanel *panel)
2229 {
2230 if (panel->list_cols > 1)
2231 {
2232 panel_move_current (panel, panel_lines (panel));
2233 return MSG_HANDLED;
2234 }
2235
2236 return maybe_cd (panel, FALSE);
2237 }
2238
2239
2240
2241 static void
2242 prev_page (WPanel *panel)
2243 {
2244 int items;
2245
2246 if (panel->dir.len == 0 || panel->current < 0 || (panel->current == 0 && panel->top == 0))
2247 return;
2248
2249 unselect_item (panel);
2250 items = panel_items (panel);
2251 if (panel->top < items)
2252 items = panel->top;
2253 if (items == 0)
2254 panel->current = 0;
2255 else
2256 panel->current -= items;
2257 panel->top -= items;
2258
2259 select_item (panel);
2260 paint_dir (panel);
2261 }
2262
2263
2264
2265 static void
2266 goto_parent_dir (WPanel *panel)
2267 {
2268 if (!panel->is_panelized)
2269 cd_up_dir (panel);
2270 else
2271 {
2272 const file_entry_t *fe;
2273 GString *fname;
2274 const char *bname;
2275 vfs_path_t *dname_vpath;
2276
2277 fe = panel_current_entry (panel);
2278 if (fe == NULL)
2279 return;
2280
2281 fname = fe->fname;
2282
2283 if (g_path_is_absolute (fname->str))
2284 fname = mc_g_string_dup (fname);
2285 else
2286 {
2287 char *fname2;
2288
2289 fname2 = mc_build_filename (vfs_path_as_str (panel->panelized_descr->root_vpath),
2290 fname->str, (char *) NULL);
2291
2292 fname = g_string_new_take (fname2);
2293 }
2294
2295 bname = x_basename (fname->str);
2296
2297 if (bname == fname->str)
2298 dname_vpath = vfs_path_from_str (".");
2299 else
2300 {
2301 g_string_truncate (fname, bname - fname->str);
2302 dname_vpath = vfs_path_from_str (fname->str);
2303 }
2304
2305 panel_cd (panel, dname_vpath, cd_exact);
2306 panel_set_current_by_name (panel, bname);
2307
2308 vfs_path_free (dname_vpath, TRUE);
2309 g_string_free (fname, TRUE);
2310 }
2311 }
2312
2313
2314
2315 static void
2316 next_page (WPanel *panel)
2317 {
2318 int items;
2319
2320 if (panel->dir.len == 0 || panel->current < 0 || panel->current == panel->dir.len - 1)
2321 return;
2322
2323 unselect_item (panel);
2324 items = panel_items (panel);
2325 if (panel->top > panel->dir.len - 2 * items)
2326 items = panel->dir.len - items - panel->top;
2327 if (panel->top + items < 0)
2328 items = -panel->top;
2329 if (items == 0)
2330 panel->current = panel->dir.len - 1;
2331 else
2332 panel->current += items;
2333 panel->top += items;
2334
2335 select_item (panel);
2336 paint_dir (panel);
2337 }
2338
2339
2340
2341 static void
2342 goto_child_dir (WPanel *panel)
2343 {
2344 const file_entry_t *fe;
2345
2346 fe = panel_current_entry (panel);
2347
2348 if (fe != NULL && (S_ISDIR (fe->st.st_mode) || link_isdir (fe)))
2349 {
2350 vfs_path_t *vpath;
2351
2352 vpath = vfs_path_from_str (fe->fname->str);
2353 panel_cd (panel, vpath, cd_exact);
2354 vfs_path_free (vpath, TRUE);
2355 }
2356 }
2357
2358
2359
2360 static void
2361 goto_top_file (WPanel *panel)
2362 {
2363 if (panel->dir.len == 0 || panel->current < 0)
2364 return;
2365
2366 unselect_item (panel);
2367 panel->current = panel->top;
2368 select_item (panel);
2369 }
2370
2371
2372
2373 static void
2374 goto_middle_file (WPanel *panel)
2375 {
2376 if (panel->dir.len == 0 || panel->current < 0)
2377 return;
2378
2379 unselect_item (panel);
2380 panel->current = panel->top + panel_items (panel) / 2;
2381 panel->current = MIN (panel->current, panel->dir.len - 1);
2382 select_item (panel);
2383 }
2384
2385
2386
2387 static void
2388 goto_bottom_file (WPanel *panel)
2389 {
2390 if (panel->dir.len == 0 || panel->current < 0)
2391 return;
2392
2393 unselect_item (panel);
2394 panel->current = panel->top + panel_items (panel) - 1;
2395 panel->current = MIN (panel->current, panel->dir.len - 1);
2396 select_item (panel);
2397 }
2398
2399
2400
2401 static void
2402 move_home (WPanel *panel)
2403 {
2404 if (panel->dir.len == 0 || panel->current <= 0)
2405 return;
2406
2407 unselect_item (panel);
2408
2409 panel->top = 0;
2410 panel->current = 0;
2411
2412 paint_dir (panel);
2413 select_item (panel);
2414 }
2415
2416
2417
2418 static void
2419 move_end (WPanel *panel)
2420 {
2421 if (panel->dir.len == 0 || panel->current < 0 || panel->current == panel->dir.len - 1)
2422 return;
2423
2424 unselect_item (panel);
2425
2426 panel->current = panel->dir.len - 1;
2427 paint_dir (panel);
2428 select_item (panel);
2429 }
2430
2431
2432
2433 static void
2434 do_mark_file (WPanel *panel, mark_act_t do_move)
2435 {
2436 const file_entry_t *fe;
2437
2438 fe = panel_current_entry (panel);
2439 if (fe == NULL)
2440 return;
2441
2442 do_file_mark (panel, panel->current, fe->f.marked ? 0 : 1);
2443
2444 if ((panels_options.mark_moves_down && do_move == MARK_DOWN) || do_move == MARK_FORCE_DOWN)
2445 move_down (panel);
2446 else if (do_move == MARK_FORCE_UP)
2447 move_up (panel);
2448 }
2449
2450
2451
2452 static inline void
2453 mark_file (WPanel *panel)
2454 {
2455 do_mark_file (panel, MARK_DOWN);
2456 }
2457
2458
2459
2460 static inline void
2461 mark_file_up (WPanel *panel)
2462 {
2463 do_mark_file (panel, MARK_FORCE_UP);
2464 }
2465
2466
2467
2468 static inline void
2469 mark_file_down (WPanel *panel)
2470 {
2471 do_mark_file (panel, MARK_FORCE_DOWN);
2472 }
2473
2474
2475
2476 static void
2477 mark_file_right (WPanel *panel)
2478 {
2479 int lines;
2480
2481 if (state_mark < 0)
2482 {
2483 const file_entry_t *fe;
2484
2485 fe = panel_current_entry (panel);
2486 if (fe == NULL)
2487 return;
2488
2489 state_mark = fe->f.marked ? 0 : 1;
2490 }
2491
2492 lines = panel_lines (panel);
2493 lines = MIN (lines, panel->dir.len - panel->current - 1);
2494 for (; lines != 0; lines--)
2495 {
2496 do_file_mark (panel, panel->current, state_mark);
2497 move_down (panel);
2498 }
2499 do_file_mark (panel, panel->current, state_mark);
2500 }
2501
2502
2503
2504 static void
2505 mark_file_left (WPanel *panel)
2506 {
2507 int lines;
2508
2509 if (state_mark < 0)
2510 {
2511 const file_entry_t *fe;
2512
2513 fe = panel_current_entry (panel);
2514 if (fe == NULL)
2515 return;
2516
2517 state_mark = fe->f.marked ? 0 : 1;
2518 }
2519
2520 lines = panel_lines (panel);
2521 lines = MIN (lines, panel->current + 1);
2522 for (; lines != 0; lines--)
2523 {
2524 do_file_mark (panel, panel->current, state_mark);
2525 move_up (panel);
2526 }
2527 do_file_mark (panel, panel->current, state_mark);
2528 }
2529
2530
2531
2532 static mc_search_t *
2533 panel_select_unselect_files_dialog (select_flags_t *flags, const char *title,
2534 const char *history_name, const char *help_section, char **str)
2535 {
2536 gboolean files_only = (*flags & SELECT_FILES_ONLY) != 0;
2537 gboolean case_sens = (*flags & SELECT_MATCH_CASE) != 0;
2538 gboolean shell_patterns = (*flags & SELECT_SHELL_PATTERNS) != 0;
2539
2540 char *reg_exp;
2541 mc_search_t *search;
2542
2543 quick_widget_t quick_widgets[] = {
2544
2545 QUICK_INPUT (INPUT_LAST_TEXT, history_name, ®_exp, NULL,
2546 FALSE, FALSE, INPUT_COMPLETE_FILENAMES),
2547 QUICK_START_COLUMNS,
2548 QUICK_CHECKBOX (_ ("&Files only"), &files_only, NULL),
2549 QUICK_CHECKBOX (_ ("&Using shell patterns"), &shell_patterns, NULL),
2550 QUICK_NEXT_COLUMN,
2551 QUICK_CHECKBOX (_ ("&Case sensitive"), &case_sens, NULL),
2552 QUICK_STOP_COLUMNS,
2553 QUICK_END,
2554
2555 };
2556
2557 WRect r = { -1, -1, 0, 50 };
2558
2559 quick_dialog_t qdlg = {
2560 .rect = r,
2561 .title = title,
2562 .help = help_section,
2563 .widgets = quick_widgets,
2564 .callback = NULL,
2565 .mouse_callback = NULL,
2566 };
2567
2568 if (quick_dialog (&qdlg) == B_CANCEL)
2569 return NULL;
2570
2571 if (*reg_exp == '\0')
2572 {
2573 g_free (reg_exp);
2574 if (str != NULL)
2575 *str = NULL;
2576 return SELECT_RESET;
2577 }
2578
2579 search = mc_search_new (reg_exp, NULL);
2580 search->search_type = shell_patterns ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
2581 search->is_entire_line = TRUE;
2582 search->is_case_sensitive = case_sens;
2583
2584 if (str != NULL)
2585 *str = reg_exp;
2586 else
2587 g_free (reg_exp);
2588
2589 if (!mc_search_prepare (search))
2590 {
2591 message (D_ERROR, MSG_ERROR, _ ("Malformed regular expression"));
2592 mc_search_free (search);
2593 return SELECT_ERROR;
2594 }
2595
2596
2597 *flags = 0;
2598 if (case_sens)
2599 *flags |= SELECT_MATCH_CASE;
2600 if (files_only)
2601 *flags |= SELECT_FILES_ONLY;
2602 if (shell_patterns)
2603 *flags |= SELECT_SHELL_PATTERNS;
2604
2605 return search;
2606 }
2607
2608
2609
2610 static void
2611 panel_select_unselect_files (WPanel *panel, const char *title, const char *history_name,
2612 const char *help_section, gboolean do_select)
2613 {
2614 mc_search_t *search;
2615 gboolean files_only;
2616 int i;
2617
2618 search = panel_select_unselect_files_dialog (&panels_options.select_flags, title, history_name,
2619 help_section, NULL);
2620 if (search == NULL || search == SELECT_RESET || search == SELECT_ERROR)
2621 return;
2622
2623 files_only = (panels_options.select_flags & SELECT_FILES_ONLY) != 0;
2624
2625 for (i = 0; i < panel->dir.len; i++)
2626 {
2627 if (DIR_IS_DOTDOT (panel->dir.list[i].fname->str))
2628 continue;
2629 if (S_ISDIR (panel->dir.list[i].st.st_mode) && files_only)
2630 continue;
2631
2632 if (mc_search_run (search, panel->dir.list[i].fname->str, 0, panel->dir.list[i].fname->len,
2633 NULL))
2634 do_file_mark (panel, i, do_select ? 1 : 0);
2635 }
2636
2637 mc_search_free (search);
2638 }
2639
2640
2641
2642 static void
2643 panel_select_files (WPanel *panel)
2644 {
2645 panel_select_unselect_files (panel, _ ("Select"), MC_HISTORY_FM_PANEL_SELECT,
2646 "[Select/Unselect Files]", TRUE);
2647 }
2648
2649
2650
2651 static void
2652 panel_unselect_files (WPanel *panel)
2653 {
2654 panel_select_unselect_files (panel, _ ("Unselect"), MC_HISTORY_FM_PANEL_UNSELECT,
2655 "[Select/Unselect Files]", FALSE);
2656 }
2657
2658
2659
2660 static void
2661 panel_select_invert_files (WPanel *panel)
2662 {
2663 int i;
2664
2665 for (i = 0; i < panel->dir.len; i++)
2666 {
2667 file_entry_t *file = &panel->dir.list[i];
2668
2669 if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode))
2670 do_file_mark (panel, i, file->f.marked ? 0 : 1);
2671 }
2672 }
2673
2674
2675
2676 static void
2677 panel_do_set_filter (WPanel *panel)
2678 {
2679 file_filter_t ff = {
2680 .value = NULL,
2681 .handler = NULL,
2682 .flags = panel->filter.flags,
2683 };
2684
2685 ff.handler = panel_select_unselect_files_dialog (
2686 &ff.flags, _ ("Filter"), MC_HISTORY_FM_PANEL_FILTER, "[Filter...]", &ff.value);
2687
2688 if (ff.handler == NULL || ff.handler == SELECT_ERROR)
2689 return;
2690
2691 if (ff.handler == SELECT_RESET)
2692 ff.handler = NULL;
2693
2694 panel_set_filter (panel, &ff);
2695 }
2696
2697
2698
2699
2700
2701
2702
2703 static void
2704 do_search (WPanel *panel, int c_code)
2705 {
2706 int curr;
2707 int i;
2708 gboolean wrapped = FALSE;
2709 char *act;
2710 mc_search_t *search;
2711 char *reg_exp, *esc_str;
2712 gboolean is_found = FALSE;
2713
2714 if (c_code == KEY_BACKSPACE)
2715 {
2716 if (panel->quick_search.buffer->len != 0)
2717 {
2718 act = panel->quick_search.buffer->str + panel->quick_search.buffer->len;
2719 str_prev_noncomb_char (&act, panel->quick_search.buffer->str);
2720 g_string_set_size (panel->quick_search.buffer, act - panel->quick_search.buffer->str);
2721 }
2722 panel->quick_search.chpoint = 0;
2723 }
2724 else
2725 {
2726 if (c_code != 0 && (gsize) panel->quick_search.chpoint < sizeof (panel->quick_search.ch))
2727 {
2728 panel->quick_search.ch[panel->quick_search.chpoint] = c_code;
2729 panel->quick_search.chpoint++;
2730 }
2731
2732 if (panel->quick_search.chpoint > 0)
2733 {
2734 switch (str_is_valid_char (panel->quick_search.ch, panel->quick_search.chpoint))
2735 {
2736 case -2:
2737 return;
2738 case -1:
2739 panel->quick_search.chpoint = 0;
2740 return;
2741 default:
2742 g_string_append_len (panel->quick_search.buffer, panel->quick_search.ch,
2743 panel->quick_search.chpoint);
2744 panel->quick_search.chpoint = 0;
2745 }
2746 }
2747 }
2748
2749 reg_exp = g_strdup_printf ("%s*", panel->quick_search.buffer->str);
2750 esc_str = str_escape (reg_exp, -1, ",|\\{}[]", TRUE);
2751 search = mc_search_new (esc_str, NULL);
2752 search->search_type = MC_SEARCH_T_GLOB;
2753 search->is_entire_line = TRUE;
2754
2755 switch (panels_options.qsearch_mode)
2756 {
2757 case QSEARCH_CASE_SENSITIVE:
2758 search->is_case_sensitive = TRUE;
2759 break;
2760 case QSEARCH_CASE_INSENSITIVE:
2761 search->is_case_sensitive = FALSE;
2762 break;
2763 default:
2764 search->is_case_sensitive = panel->sort_info.case_sensitive;
2765 break;
2766 }
2767
2768 curr = panel->current;
2769
2770 for (i = panel->current; !wrapped || i != panel->current; i++)
2771 {
2772 if (i >= panel->dir.len)
2773 {
2774 i = 0;
2775 if (wrapped)
2776 break;
2777 wrapped = TRUE;
2778 }
2779 if (mc_search_run (search, panel->dir.list[i].fname->str, 0, panel->dir.list[i].fname->len,
2780 NULL))
2781 {
2782 curr = i;
2783 is_found = TRUE;
2784 break;
2785 }
2786 }
2787 if (is_found)
2788 {
2789 unselect_item (panel);
2790 panel->current = curr;
2791 select_item (panel);
2792 widget_draw (WIDGET (panel));
2793 }
2794 else if (c_code != KEY_BACKSPACE)
2795 {
2796 act = panel->quick_search.buffer->str + panel->quick_search.buffer->len;
2797 str_prev_noncomb_char (&act, panel->quick_search.buffer->str);
2798 g_string_set_size (panel->quick_search.buffer, act - panel->quick_search.buffer->str);
2799 }
2800 mc_search_free (search);
2801 g_free (reg_exp);
2802 g_free (esc_str);
2803 }
2804
2805
2806
2807
2808
2809
2810 static void
2811 start_search (WPanel *panel)
2812 {
2813 if (panel->quick_search.active)
2814 {
2815 if (panel->current == panel->dir.len - 1)
2816 panel->current = 0;
2817 else
2818 move_down (panel);
2819
2820
2821
2822 if (panel->quick_search.buffer->len == 0)
2823 mc_g_string_copy (panel->quick_search.buffer, panel->quick_search.prev_buffer);
2824
2825 do_search (panel, 0);
2826 }
2827 else if (panel->dir.len != 0)
2828 {
2829 panel->quick_search.active = TRUE;
2830 g_string_set_size (panel->quick_search.buffer, 0);
2831 panel->quick_search.ch[0] = '\0';
2832 panel->quick_search.chpoint = 0;
2833 display_mini_info (panel);
2834 }
2835 }
2836
2837
2838
2839 static void
2840 stop_search (WPanel *panel)
2841 {
2842 if (!panel->quick_search.active)
2843 return;
2844
2845 panel->quick_search.active = FALSE;
2846
2847
2848
2849 if (panel->quick_search.buffer->len != 0)
2850 mc_g_string_copy (panel->quick_search.prev_buffer, panel->quick_search.buffer);
2851
2852 display_mini_info (panel);
2853 }
2854
2855
2856
2857
2858 static gboolean
2859 do_enter_on_file_entry (WPanel *panel, const file_entry_t *fe)
2860 {
2861 const char *fname = fe->fname->str;
2862 GString *fname_quoted;
2863 vfs_path_t *full_name_vpath;
2864 gboolean ok;
2865
2866
2867
2868
2869
2870 if (S_ISDIR (fe->st.st_mode) || link_isdir (fe) || (fe->st.st_mode == 0))
2871 {
2872 vfs_path_t *fname_vpath;
2873
2874 fname_vpath = vfs_path_from_str (fname);
2875 if (!panel_cd (panel, fname_vpath, cd_exact))
2876 cd_error_message (fname);
2877 vfs_path_free (fname_vpath, TRUE);
2878 return TRUE;
2879 }
2880
2881 full_name_vpath = vfs_path_append_new (panel->cwd_vpath, fname, (char *) NULL);
2882
2883
2884 ok = regex_command (full_name_vpath, "Open") != 0;
2885 vfs_path_free (full_name_vpath, TRUE);
2886 if (ok)
2887 return TRUE;
2888
2889
2890 full_name_vpath = vfs_path_append_new (panel->cwd_vpath, fname, (char *) NULL);
2891 ok = (is_exe (fe->st.st_mode) && if_link_is_exe (full_name_vpath, fe));
2892 vfs_path_free (full_name_vpath, TRUE);
2893 if (!ok)
2894 return FALSE;
2895
2896 if (confirm_execute
2897 && query_dialog (PACKAGE_NAME, _ ("Do you really want to execute?"), D_NORMAL, 2,
2898 _ ("&Yes"), _ ("&No"))
2899 != 0)
2900 return TRUE;
2901
2902 if (!vfs_current_is_local ())
2903 {
2904 int ret;
2905 vfs_path_t *tmp_vpath;
2906
2907 tmp_vpath = vfs_path_append_new (vfs_get_raw_current_dir (), fname, (char *) NULL);
2908 ret = mc_setctl (tmp_vpath, VFS_SETCTL_RUN, NULL);
2909 vfs_path_free (tmp_vpath, TRUE);
2910
2911 return confirm_execute || (ret == 0);
2912 }
2913
2914 fname_quoted = name_quote (fname, FALSE);
2915 if (fname_quoted != NULL)
2916 {
2917 char *cmd;
2918
2919 cmd = g_strconcat ("." PATH_SEP_STR, fname_quoted->str, (char *) NULL);
2920 g_string_free (fname_quoted, TRUE);
2921
2922 shell_execute (cmd, 0);
2923 g_free (cmd);
2924 }
2925
2926 mc_global.source_codepage = default_source_codepage;
2927
2928 return TRUE;
2929 }
2930
2931
2932
2933 static inline gboolean
2934 do_enter (WPanel *panel)
2935 {
2936 const file_entry_t *fe;
2937
2938 fe = panel_current_entry (panel);
2939
2940 return (fe == NULL ? FALSE : do_enter_on_file_entry (panel, fe));
2941 }
2942
2943
2944
2945 static void
2946 panel_cycle_listing_format (WPanel *panel)
2947 {
2948 panel->list_format = (panel->list_format + 1) % LIST_FORMATS;
2949
2950 if (set_panel_formats (panel) == 0)
2951 do_refresh ();
2952 }
2953
2954
2955
2956 static void
2957 chdir_other_panel (WPanel *panel)
2958 {
2959 const file_entry_t *entry;
2960 vfs_path_t *new_dir_vpath;
2961 char *curr_entry = NULL;
2962 WPanel *p;
2963
2964 entry = panel_current_entry (panel);
2965 if (entry == NULL)
2966 return;
2967
2968 if (get_other_type () != view_listing)
2969 create_panel (get_other_index (), view_listing);
2970
2971 if (S_ISDIR (entry->st.st_mode) || link_isdir (entry))
2972 new_dir_vpath = vfs_path_append_new (panel->cwd_vpath, entry->fname->str, (char *) NULL);
2973 else
2974 {
2975 new_dir_vpath = vfs_path_append_new (panel->cwd_vpath, "..", (char *) NULL);
2976 curr_entry = strrchr (vfs_path_get_last_path_str (panel->cwd_vpath), PATH_SEP);
2977 }
2978
2979 p = change_panel ();
2980 panel_cd (p, new_dir_vpath, cd_exact);
2981 vfs_path_free (new_dir_vpath, TRUE);
2982
2983 if (curr_entry != NULL)
2984 panel_set_current_by_name (p, curr_entry);
2985 (void) change_panel ();
2986
2987 move_down (panel);
2988 }
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998 static void
2999 panel_sync_other (const WPanel *panel)
3000 {
3001 if (get_other_type () != view_listing)
3002 create_panel (get_other_index (), view_listing);
3003
3004 panel_do_cd (other_panel, panel->cwd_vpath, cd_exact);
3005
3006
3007 if (!panel->is_panelized)
3008 {
3009 const file_entry_t *fe;
3010
3011 fe = panel_current_entry (panel);
3012 if (fe != NULL)
3013 panel_set_current_by_name (other_panel, fe->fname->str);
3014 }
3015 }
3016
3017
3018
3019 static void
3020 chdir_to_readlink (WPanel *panel)
3021 {
3022 const file_entry_t *fe;
3023 vfs_path_t *new_dir_vpath;
3024 char buffer[MC_MAXPATHLEN];
3025 int i;
3026 struct stat st;
3027 vfs_path_t *panel_fname_vpath;
3028 gboolean ok;
3029 WPanel *cpanel;
3030
3031 if (get_other_type () != view_listing)
3032 return;
3033
3034 fe = panel_current_entry (panel);
3035
3036 if (fe == NULL || !S_ISLNK (fe->st.st_mode))
3037 return;
3038
3039 i = readlink (fe->fname->str, buffer, MC_MAXPATHLEN - 1);
3040 if (i < 0)
3041 return;
3042
3043 panel_fname_vpath = vfs_path_from_str (fe->fname->str);
3044 ok = (mc_stat (panel_fname_vpath, &st) >= 0);
3045 vfs_path_free (panel_fname_vpath, TRUE);
3046 if (!ok)
3047 return;
3048
3049 buffer[i] = '\0';
3050 if (!S_ISDIR (st.st_mode))
3051 {
3052 char *p;
3053
3054 p = strrchr (buffer, PATH_SEP);
3055 if (p != NULL && p[1] == '\0')
3056 {
3057 *p = '\0';
3058 p = strrchr (buffer, PATH_SEP);
3059 }
3060 if (p == NULL)
3061 return;
3062
3063 p[1] = '\0';
3064 }
3065 if (IS_PATH_SEP (*buffer))
3066 new_dir_vpath = vfs_path_from_str (buffer);
3067 else
3068 new_dir_vpath = vfs_path_append_new (panel->cwd_vpath, buffer, (char *) NULL);
3069
3070 cpanel = change_panel ();
3071 panel_cd (cpanel, new_dir_vpath, cd_exact);
3072 vfs_path_free (new_dir_vpath, TRUE);
3073 (void) change_panel ();
3074
3075 move_down (panel);
3076 }
3077
3078
3079
3080
3081
3082
3083 static gsize
3084 panel_get_format_field_index_by_name (const WPanel *panel, const char *name)
3085 {
3086 GSList *format;
3087 gsize lc_index;
3088
3089 for (lc_index = 1, format = panel->format;
3090 format != NULL && strcmp (((format_item_t *) format->data)->title, name) != 0;
3091 format = g_slist_next (format), lc_index++)
3092 ;
3093
3094 if (format == NULL)
3095 lc_index = 0;
3096
3097 return lc_index;
3098 }
3099
3100
3101
3102 static const panel_field_t *
3103 panel_get_sortable_field_by_format (const WPanel *panel, gsize lc_index)
3104 {
3105 const panel_field_t *pfield;
3106 const format_item_t *format;
3107
3108 format = (const format_item_t *) g_slist_nth_data (panel->format, lc_index);
3109 if (format == NULL)
3110 return NULL;
3111
3112 pfield = panel_get_field_by_title (format->title);
3113 if (pfield == NULL)
3114 return NULL;
3115 if (pfield->sort_routine == NULL)
3116 return NULL;
3117 return pfield;
3118 }
3119
3120
3121
3122 static void
3123 panel_toggle_sort_order_prev (WPanel *panel)
3124 {
3125 gsize lc_index, i;
3126 const char *title;
3127 const panel_field_t *pfield = NULL;
3128
3129 title = panel_get_title_without_hotkey (panel->sort_field->title_hotkey);
3130 lc_index = panel_get_format_field_index_by_name (panel, title);
3131
3132 if (lc_index > 1)
3133 {
3134
3135 for (i = lc_index - 1;
3136 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--)
3137 ;
3138 }
3139
3140 if (pfield == NULL)
3141 {
3142
3143 for (i = g_slist_length (panel->format);
3144 i != 0 && (pfield = panel_get_sortable_field_by_format (panel, i - 1)) == NULL; i--)
3145 ;
3146 }
3147
3148 if (pfield != NULL)
3149 {
3150 panel->sort_field = pfield;
3151 panel_set_sort_order (panel, pfield);
3152 }
3153 }
3154
3155
3156
3157 static void
3158 panel_toggle_sort_order_next (WPanel *panel)
3159 {
3160 gsize lc_index, i;
3161 const panel_field_t *pfield = NULL;
3162 gsize format_field_count;
3163 const char *title;
3164
3165 format_field_count = g_slist_length (panel->format);
3166 title = panel_get_title_without_hotkey (panel->sort_field->title_hotkey);
3167 lc_index = panel_get_format_field_index_by_name (panel, title);
3168
3169 if (lc_index != 0 && lc_index != format_field_count)
3170 {
3171
3172 for (i = lc_index; i != format_field_count
3173 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL;
3174 i++)
3175 ;
3176 }
3177
3178 if (pfield == NULL)
3179 {
3180
3181 for (i = 0; i != format_field_count
3182 && (pfield = panel_get_sortable_field_by_format (panel, i)) == NULL;
3183 i++)
3184 ;
3185 }
3186
3187 if (pfield != NULL)
3188 {
3189 panel->sort_field = pfield;
3190 panel_set_sort_order (panel, pfield);
3191 }
3192 }
3193
3194
3195
3196 static void
3197 panel_select_sort_order (WPanel *panel)
3198 {
3199 const panel_field_t *sort_order;
3200
3201 sort_order = sort_box (&panel->sort_info, panel->sort_field);
3202 if (sort_order != NULL)
3203 {
3204 panel->sort_field = sort_order;
3205 panel_set_sort_order (panel, sort_order);
3206 }
3207 }
3208
3209
3210
3211
3212
3213
3214
3215
3216 static void
3217 panel_content_scroll_left (WPanel *panel)
3218 {
3219 if (panel->content_shift != 0)
3220 {
3221 if (panel->content_shift > panel->max_shift)
3222 panel->content_shift = panel->max_shift;
3223
3224 panel->content_shift--;
3225 show_dir (panel);
3226 paint_dir (panel);
3227 }
3228 }
3229
3230
3231
3232
3233
3234
3235
3236
3237 static void
3238 panel_content_scroll_right (WPanel *panel)
3239 {
3240 if (panel->content_shift == 0 || panel->content_shift < panel->max_shift)
3241 {
3242 panel->content_shift++;
3243 show_dir (panel);
3244 paint_dir (panel);
3245 }
3246 }
3247
3248
3249
3250
3251
3252
3253
3254
3255 static void
3256 panel_content_scroll_home (WPanel *panel)
3257 {
3258 panel->content_shift = 0;
3259 show_dir (panel);
3260 paint_dir (panel);
3261 }
3262
3263
3264
3265
3266
3267
3268
3269
3270 static void
3271 panel_content_scroll_end (WPanel *panel)
3272 {
3273
3274 panel->content_shift = UINT_MAX;
3275
3276 show_dir (panel);
3277 paint_dir (panel);
3278
3279
3280 if (panel->content_shift > panel->max_shift)
3281 panel->content_shift = panel->max_shift;
3282 }
3283
3284
3285
3286 static void
3287 panel_set_sort_type_by_id (WPanel *panel, const char *name)
3288 {
3289 if (strcmp (panel->sort_field->id, name) == 0)
3290 panel->sort_info.reverse = !panel->sort_info.reverse;
3291 else
3292 {
3293 const panel_field_t *sort_order;
3294
3295 sort_order = panel_get_field_by_id (name);
3296 if (sort_order == NULL)
3297 return;
3298
3299 panel->sort_field = sort_order;
3300 }
3301
3302 panel_set_sort_order (panel, panel->sort_field);
3303 }
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313 static const char *
3314 get_parent_dir_name (const vfs_path_t *cwd_vpath, const vfs_path_t *lwd_vpath)
3315 {
3316 size_t llen, clen;
3317 const char *p, *lwd;
3318
3319 llen = vfs_path_len (lwd_vpath);
3320 clen = vfs_path_len (cwd_vpath);
3321
3322 if (llen <= clen)
3323 return NULL;
3324
3325 lwd = vfs_path_as_str (lwd_vpath);
3326
3327 p = g_strrstr (lwd, VFS_PATH_URL_DELIMITER);
3328
3329 if (p == NULL)
3330 {
3331 const char *cwd;
3332
3333 cwd = vfs_path_as_str (cwd_vpath);
3334
3335 p = strrchr (lwd, PATH_SEP);
3336
3337 if (p != NULL && strncmp (cwd, lwd, (size_t) (p - lwd)) == 0
3338 && (clen == (size_t) (p - lwd) || (p == lwd && IS_PATH_SEP (cwd[0]) && cwd[1] == '\0')))
3339 return (p + 1);
3340
3341 return NULL;
3342 }
3343
3344
3345 while (--p > lwd && !IS_PATH_SEP (*p))
3346 ;
3347
3348 while (--p > lwd && !IS_PATH_SEP (*p))
3349 ;
3350
3351
3352 return (p != lwd || IS_PATH_SEP (*p)) ? p + 1 : p;
3353 }
3354
3355
3356
3357
3358
3359
3360
3361 static gboolean
3362 panel_do_cd_int (WPanel *panel, const vfs_path_t *new_dir_vpath, enum cd_enum cd_type)
3363 {
3364 vfs_path_t *olddir_vpath;
3365
3366
3367 if (cd_type == cd_parse_command)
3368 {
3369 const vfs_path_element_t *element;
3370
3371 element = vfs_path_get_by_index (new_dir_vpath, 0);
3372 if (strcmp (element->path, "-") == 0)
3373 new_dir_vpath = panel->lwd_vpath;
3374 }
3375
3376 if (mc_chdir (new_dir_vpath) == -1)
3377 return FALSE;
3378
3379
3380 olddir_vpath = vfs_path_clone (panel->cwd_vpath);
3381 panel_set_lwd (panel, panel->cwd_vpath);
3382 input_complete_free (cmdline);
3383
3384 vfs_path_free (panel->cwd_vpath, TRUE);
3385 vfs_setup_cwd ();
3386 panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
3387
3388 vfs_release_path (olddir_vpath);
3389
3390 #ifdef ENABLE_SUBSHELL
3391 subshell_chdir (panel->cwd_vpath);
3392 #endif
3393
3394
3395 panel_clean_dir (panel);
3396
3397 if (!dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
3398 &panel->sort_info, &panel->filter))
3399 message (D_ERROR, MSG_ERROR, _ ("Cannot read directory contents"));
3400
3401 if (panel->dir.len == 0)
3402 panel_set_current (panel, -1);
3403
3404 panel_set_current_by_name (panel, get_parent_dir_name (panel->cwd_vpath, olddir_vpath));
3405
3406 load_hint (FALSE);
3407 panel->dirty = TRUE;
3408 update_xterm_title_path ();
3409 update_terminal_cwd ();
3410
3411 vfs_path_free (olddir_vpath, TRUE);
3412
3413 return TRUE;
3414 }
3415
3416
3417
3418 static void
3419 directory_history_next (WPanel *panel)
3420 {
3421 gboolean ok;
3422
3423 do
3424 {
3425 GList *next;
3426
3427 ok = TRUE;
3428 next = g_list_next (panel->dir_history.current);
3429 if (next != NULL)
3430 {
3431 vfs_path_t *data_vpath;
3432
3433 data_vpath = vfs_path_from_str ((char *) next->data);
3434 ok = panel_do_cd_int (panel, data_vpath, cd_exact);
3435 vfs_path_free (data_vpath, TRUE);
3436 panel->dir_history.current = next;
3437 }
3438
3439 }
3440 while (!ok);
3441 }
3442
3443
3444
3445 static void
3446 directory_history_prev (WPanel *panel)
3447 {
3448 gboolean ok;
3449
3450 do
3451 {
3452 GList *prev;
3453
3454 ok = TRUE;
3455 prev = g_list_previous (panel->dir_history.current);
3456 if (prev != NULL)
3457 {
3458 vfs_path_t *data_vpath;
3459
3460 data_vpath = vfs_path_from_str ((char *) prev->data);
3461 ok = panel_do_cd_int (panel, data_vpath, cd_exact);
3462 vfs_path_free (data_vpath, TRUE);
3463 panel->dir_history.current = prev;
3464 }
3465
3466 }
3467 while (!ok);
3468 }
3469
3470
3471
3472 static void
3473 directory_history_list (WPanel *panel)
3474 {
3475 history_descriptor_t hd;
3476 gboolean ok = FALSE;
3477 size_t pos;
3478
3479 pos = g_list_position (panel->dir_history.current, panel->dir_history.list);
3480
3481 history_descriptor_init (&hd, WIDGET (panel)->rect.y, WIDGET (panel)->rect.x,
3482 panel->dir_history.list, (int) pos);
3483 history_show (&hd);
3484
3485 panel->dir_history.list = hd.list;
3486 if (hd.text != NULL)
3487 {
3488 vfs_path_t *s_vpath;
3489
3490 s_vpath = vfs_path_from_str (hd.text);
3491 ok = panel_do_cd (panel, s_vpath, cd_exact);
3492 if (ok)
3493 {
3494
3495 if (panel != current_panel)
3496 panel_do_cd_int (current_panel, current_panel->cwd_vpath, cd_exact);
3497 }
3498 else
3499 cd_error_message (hd.text);
3500 vfs_path_free (s_vpath, TRUE);
3501 g_free (hd.text);
3502 }
3503
3504 if (!ok)
3505 {
3506
3507
3508
3509 size_t i;
3510
3511 panel->dir_history.current = panel->dir_history.list;
3512
3513 for (i = 0; i < pos; i++)
3514 {
3515 GList *prev;
3516
3517 prev = g_list_previous (panel->dir_history.current);
3518 if (prev == NULL)
3519 break;
3520
3521 panel->dir_history.current = prev;
3522 }
3523 }
3524 }
3525
3526
3527
3528 static cb_ret_t
3529 panel_execute_cmd (WPanel *panel, long command)
3530 {
3531 int res = MSG_HANDLED;
3532
3533 if (command != CK_Search)
3534 stop_search (panel);
3535
3536 switch (command)
3537 {
3538 case CK_Up:
3539 case CK_Down:
3540 case CK_Left:
3541 case CK_Right:
3542 case CK_Bottom:
3543 case CK_Top:
3544 case CK_PageDown:
3545 case CK_PageUp:
3546
3547 state_mark = -1;
3548 break;
3549 default:
3550 break;
3551 }
3552
3553 switch (command)
3554 {
3555 case CK_CycleListingFormat:
3556 panel_cycle_listing_format (panel);
3557 break;
3558 case CK_PanelOtherCd:
3559 chdir_other_panel (panel);
3560 break;
3561 case CK_PanelOtherCdLink:
3562 chdir_to_readlink (panel);
3563 break;
3564 case CK_CopySingle:
3565 copy_cmd_local (panel);
3566 break;
3567 case CK_DeleteSingle:
3568 delete_cmd_local (panel);
3569 break;
3570 case CK_Enter:
3571 do_enter (panel);
3572 break;
3573 case CK_ViewRaw:
3574 view_raw_cmd (panel);
3575 break;
3576 case CK_EditNew:
3577 edit_cmd_new ();
3578 break;
3579 case CK_MoveSingle:
3580 rename_cmd_local (panel);
3581 break;
3582 case CK_SelectInvert:
3583 panel_select_invert_files (panel);
3584 break;
3585 case CK_Select:
3586 panel_select_files (panel);
3587 break;
3588 case CK_SelectExt:
3589 panel_select_ext_cmd (panel);
3590 break;
3591 case CK_Unselect:
3592 panel_unselect_files (panel);
3593 break;
3594 case CK_Filter:
3595 panel_do_set_filter (panel);
3596 break;
3597 case CK_PageDown:
3598 next_page (panel);
3599 break;
3600 case CK_PageUp:
3601 prev_page (panel);
3602 break;
3603 case CK_CdChild:
3604 goto_child_dir (panel);
3605 break;
3606 case CK_CdParent:
3607 goto_parent_dir (panel);
3608 break;
3609 case CK_History:
3610 directory_history_list (panel);
3611 break;
3612 case CK_HistoryNext:
3613 directory_history_next (panel);
3614 break;
3615 case CK_HistoryPrev:
3616 directory_history_prev (panel);
3617 break;
3618 case CK_BottomOnScreen:
3619 goto_bottom_file (panel);
3620 break;
3621 case CK_MiddleOnScreen:
3622 goto_middle_file (panel);
3623 break;
3624 case CK_TopOnScreen:
3625 goto_top_file (panel);
3626 break;
3627 case CK_Mark:
3628 mark_file (panel);
3629 break;
3630 case CK_MarkUp:
3631 mark_file_up (panel);
3632 break;
3633 case CK_MarkDown:
3634 mark_file_down (panel);
3635 break;
3636 case CK_MarkLeft:
3637 mark_file_left (panel);
3638 break;
3639 case CK_MarkRight:
3640 mark_file_right (panel);
3641 break;
3642 case CK_CdParentSmart:
3643 res = force_maybe_cd (panel);
3644 break;
3645 case CK_Up:
3646 move_up (panel);
3647 break;
3648 case CK_Down:
3649 move_down (panel);
3650 break;
3651 case CK_Left:
3652 res = move_left (panel);
3653 break;
3654 case CK_Right:
3655 res = move_right (panel);
3656 break;
3657 case CK_Bottom:
3658 move_end (panel);
3659 break;
3660 case CK_Top:
3661 move_home (panel);
3662 break;
3663 case CK_SelectCodepage:
3664 panel_change_encoding (panel);
3665 break;
3666 case CK_ScrollLeft:
3667 panel_content_scroll_left (panel);
3668 break;
3669 case CK_ScrollRight:
3670 panel_content_scroll_right (panel);
3671 break;
3672 case CK_ScrollHome:
3673 panel_content_scroll_home (panel);
3674 break;
3675 case CK_ScrollEnd:
3676 panel_content_scroll_end (panel);
3677 break;
3678 case CK_Search:
3679 start_search (panel);
3680 break;
3681 case CK_SearchStop:
3682 break;
3683 case CK_PanelOtherSync:
3684 panel_sync_other (panel);
3685 break;
3686 case CK_Sort:
3687 panel_select_sort_order (panel);
3688 break;
3689 case CK_SortPrev:
3690 panel_toggle_sort_order_prev (panel);
3691 break;
3692 case CK_SortNext:
3693 panel_toggle_sort_order_next (panel);
3694 break;
3695 case CK_SortReverse:
3696 panel->sort_info.reverse = !panel->sort_info.reverse;
3697 panel_set_sort_order (panel, panel->sort_field);
3698 break;
3699 case CK_SortByName:
3700 panel_set_sort_type_by_id (panel, "name");
3701 break;
3702 case CK_SortByVersion:
3703 panel_set_sort_type_by_id (panel, "version");
3704 break;
3705 case CK_SortByExt:
3706 panel_set_sort_type_by_id (panel, "extension");
3707 break;
3708 case CK_SortBySize:
3709 panel_set_sort_type_by_id (panel, "size");
3710 break;
3711 case CK_SortByMTime:
3712 panel_set_sort_type_by_id (panel, "mtime");
3713 break;
3714 default:
3715 res = MSG_NOT_HANDLED;
3716 break;
3717 }
3718
3719 return res;
3720 }
3721
3722
3723
3724 static cb_ret_t
3725 panel_key (WPanel *panel, int key)
3726 {
3727 long command;
3728
3729 if (is_abort_char (key))
3730 {
3731 stop_search (panel);
3732 return MSG_HANDLED;
3733 }
3734
3735 if (panel->quick_search.active && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
3736 {
3737 do_search (panel, key);
3738 return MSG_HANDLED;
3739 }
3740
3741 command = widget_lookup_key (WIDGET (panel), key);
3742 if (command != CK_IgnoreKey)
3743 return panel_execute_cmd (panel, command);
3744
3745 if (!command_prompt && ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE))
3746 {
3747 start_search (panel);
3748 do_search (panel, key);
3749 return MSG_HANDLED;
3750 }
3751
3752 return MSG_NOT_HANDLED;
3753 }
3754
3755
3756
3757 static cb_ret_t
3758 panel_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
3759 {
3760 WPanel *panel = PANEL (w);
3761 WDialog *h = DIALOG (w->owner);
3762 WButtonBar *bb;
3763
3764 switch (msg)
3765 {
3766 case MSG_INIT:
3767
3768 mc_event_add (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w, NULL);
3769
3770 mc_event_add (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w, NULL);
3771 return MSG_HANDLED;
3772
3773 case MSG_DRAW:
3774
3775 widget_erase (w);
3776 show_dir (panel);
3777 panel_print_header (panel);
3778 adjust_top_file (panel);
3779 paint_dir (panel);
3780 mini_info_separator (panel);
3781 display_mini_info (panel);
3782 panel->dirty = FALSE;
3783 return MSG_HANDLED;
3784
3785 case MSG_FOCUS:
3786 state_mark = -1;
3787 current_panel = panel;
3788
3789 if (mc_chdir (panel->cwd_vpath) != 0)
3790 {
3791 char *cwd;
3792
3793 cwd = vfs_path_to_str_flags (panel->cwd_vpath, 0, VPF_STRIP_PASSWORD);
3794 cd_error_message (cwd);
3795 g_free (cwd);
3796 }
3797 #ifdef ENABLE_SUBSHELL
3798 else
3799 subshell_chdir (panel->cwd_vpath);
3800 #endif
3801
3802 update_xterm_title_path ();
3803 update_terminal_cwd ();
3804 select_item (panel);
3805
3806 bb = buttonbar_find (h);
3807 midnight_set_buttonbar (bb);
3808
3809 widget_draw (WIDGET (bb));
3810 return MSG_HANDLED;
3811
3812 case MSG_UNFOCUS:
3813
3814 stop_search (panel);
3815 unselect_item (panel);
3816 return MSG_HANDLED;
3817
3818 case MSG_KEY:
3819 return panel_key (panel, parm);
3820
3821 case MSG_ACTION:
3822 return panel_execute_cmd (panel, parm);
3823
3824 case MSG_DESTROY:
3825 vfs_stamp_path (panel->cwd_vpath);
3826
3827 mc_event_del (h->event_group, MCEVENT_HISTORY_LOAD, panel_load_history, w);
3828
3829 mc_event_del (h->event_group, MCEVENT_HISTORY_SAVE, panel_save_history, w);
3830 panel_destroy (panel);
3831 free_my_statfs ();
3832 return MSG_HANDLED;
3833
3834 default:
3835 return widget_default_callback (w, sender, msg, parm, data);
3836 }
3837 }
3838
3839
3840
3841
3842
3843
3844 static void
3845 mouse_toggle_mark (WPanel *panel)
3846 {
3847 const file_entry_t *fe;
3848
3849 fe = panel_current_entry (panel);
3850 if (fe != NULL)
3851 {
3852 do_mark_file (panel, MARK_DONT_MOVE);
3853 mouse_marking = fe->f.marked != 0;
3854 mouse_mark_panel = current_panel;
3855 }
3856 }
3857
3858
3859
3860 static void
3861 mouse_set_mark (WPanel *panel)
3862 {
3863 if (mouse_mark_panel == panel)
3864 {
3865 const file_entry_t *fe;
3866
3867 fe = panel_current_entry (panel);
3868 if (fe != NULL)
3869 {
3870 if (mouse_marking && fe->f.marked == 0)
3871 do_mark_file (panel, MARK_DONT_MOVE);
3872 else if (!mouse_marking && fe->f.marked != 0)
3873 do_mark_file (panel, MARK_DONT_MOVE);
3874 }
3875 }
3876 }
3877
3878
3879
3880 static void
3881 mark_if_marking (WPanel *panel, const mouse_event_t *event, int previous_current)
3882 {
3883 if ((event->buttons & GPM_B_RIGHT) == 0)
3884 return;
3885
3886 if (event->msg == MSG_MOUSE_DOWN)
3887 mouse_toggle_mark (panel);
3888 else
3889 {
3890 int pcurr, curr1, curr2;
3891
3892 pcurr = panel->current;
3893 curr1 = MIN (previous_current, panel->current);
3894 curr2 = MAX (previous_current, panel->current);
3895
3896 for (; curr1 <= curr2; curr1++)
3897 {
3898 panel->current = curr1;
3899 mouse_set_mark (panel);
3900 }
3901
3902 panel->current = pcurr;
3903 }
3904 }
3905
3906
3907
3908
3909
3910
3911
3912 static void
3913 mouse_sort_col (WPanel *panel, int x)
3914 {
3915 int i = 0;
3916 GSList *format;
3917 const char *lc_sort_name = NULL;
3918 panel_field_t *col_sort_format = NULL;
3919
3920 const int sort_indicator_width =
3921 panel->sort_info.reverse ? panel_sort_up_indicator_width : panel_sort_down_indicator_width;
3922
3923
3924 if (x >= 2 && x < 2 + sort_indicator_width)
3925 {
3926 panel->sort_info.reverse = !panel->sort_info.reverse;
3927 panel_set_sort_order (panel, panel->sort_field);
3928 return;
3929 }
3930
3931 for (format = panel->format; format != NULL; format = g_slist_next (format))
3932 {
3933 format_item_t *fi = (format_item_t *) format->data;
3934
3935 i += fi->field_len;
3936 if (x < i + 1)
3937 {
3938
3939 lc_sort_name = fi->title;
3940 break;
3941 }
3942 }
3943
3944 if (lc_sort_name == NULL)
3945 return;
3946
3947 for (i = 0; panel_fields[i].id != NULL; i++)
3948 {
3949 const char *title;
3950
3951 title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey);
3952 if (panel_fields[i].sort_routine != NULL && strcmp (title, lc_sort_name) == 0)
3953 {
3954 col_sort_format = &panel_fields[i];
3955 break;
3956 }
3957 }
3958
3959 if (col_sort_format != NULL)
3960 {
3961 if (panel->sort_field == col_sort_format)
3962
3963 panel->sort_info.reverse = !panel->sort_info.reverse;
3964 else
3965
3966 panel->sort_info.reverse = FALSE;
3967
3968 panel_set_sort_order (panel, col_sort_format);
3969 }
3970 }
3971
3972
3973
3974 static int
3975 panel_mouse_is_on_item (const WPanel *panel, int y, int x)
3976 {
3977 int lines, col_width, col;
3978
3979 if (y < 0)
3980 return MOUSE_UPPER_FILE_LIST;
3981
3982 lines = panel_lines (panel);
3983 if (y >= lines)
3984 return MOUSE_BELOW_FILE_LIST;
3985
3986 col_width = (CONST_WIDGET (panel)->rect.cols - 2) / panel->list_cols;
3987
3988 col = x / col_width;
3989
3990 y += panel->top + lines * col;
3991
3992
3993 if (y >= panel->dir.len)
3994 return MOUSE_AFTER_LAST_FILE;
3995
3996
3997 return y;
3998 }
3999
4000
4001
4002 static void
4003 panel_mouse_callback (Widget *w, mouse_msg_t msg, mouse_event_t *event)
4004 {
4005 WPanel *panel = PANEL (w);
4006 gboolean is_active;
4007
4008 is_active = widget_is_active (w);
4009
4010 switch (msg)
4011 {
4012 case MSG_MOUSE_DOWN:
4013 if (event->y == 0)
4014 {
4015
4016 if (event->x == 1)
4017
4018 directory_history_prev (panel);
4019 else if (event->x == w->rect.cols - 2)
4020
4021 directory_history_next (panel);
4022 else if (event->x >= w->rect.cols - 5 && event->x <= w->rect.cols - 3)
4023
4024 directory_history_list (panel);
4025 else if (event->x == w->rect.cols - 6)
4026
4027 send_message (filemanager, NULL, MSG_ACTION, CK_ShowHidden, NULL);
4028 else
4029 {
4030
4031 event->result.abort = TRUE;
4032
4033 panel->dirty = FALSE;
4034 }
4035 break;
4036 }
4037
4038 if (event->y == 1)
4039 {
4040
4041 mouse_sort_col (panel, event->x + 1);
4042 break;
4043 }
4044
4045 if (!is_active)
4046 (void) change_panel ();
4047 MC_FALLTHROUGH;
4048
4049 case MSG_MOUSE_DRAG:
4050 {
4051 int my_index;
4052 int previous_current;
4053
4054 my_index = panel_mouse_is_on_item (panel, event->y - 2, event->x);
4055 previous_current = panel->current;
4056
4057 switch (my_index)
4058 {
4059 case MOUSE_UPPER_FILE_LIST:
4060 move_up (panel);
4061 mark_if_marking (panel, event, previous_current);
4062 break;
4063
4064 case MOUSE_BELOW_FILE_LIST:
4065 move_down (panel);
4066 mark_if_marking (panel, event, previous_current);
4067 break;
4068
4069 case MOUSE_AFTER_LAST_FILE:
4070 break;
4071
4072 default:
4073 if (my_index != panel->current)
4074 {
4075 unselect_item (panel);
4076 panel->current = my_index;
4077 select_item (panel);
4078 }
4079
4080 mark_if_marking (panel, event, previous_current);
4081 break;
4082 }
4083 }
4084 break;
4085
4086 case MSG_MOUSE_UP:
4087 break;
4088
4089 case MSG_MOUSE_CLICK:
4090 if ((event->count & GPM_DOUBLE) != 0 && (event->buttons & GPM_B_LEFT) != 0
4091 && panel_mouse_is_on_item (panel, event->y - 2, event->x) >= 0)
4092 do_enter (panel);
4093 break;
4094
4095 case MSG_MOUSE_MOVE:
4096 break;
4097
4098 case MSG_MOUSE_SCROLL_UP:
4099 if (is_active)
4100 {
4101 if (panels_options.mouse_move_pages && panel->top > 0)
4102 prev_page (panel);
4103 else
4104 move_up (panel);
4105 }
4106 break;
4107
4108 case MSG_MOUSE_SCROLL_DOWN:
4109 if (is_active)
4110 {
4111 if (panels_options.mouse_move_pages
4112 && panel->top + panel_items (panel) < panel->dir.len)
4113 next_page (panel);
4114 else
4115 move_down (panel);
4116 }
4117 break;
4118
4119 default:
4120 break;
4121 }
4122
4123 if (panel->dirty)
4124 widget_draw (w);
4125 }
4126
4127
4128
4129 static void
4130 reload_panelized (WPanel *panel)
4131 {
4132 int i, j;
4133 dir_list *list = &panel->dir;
4134
4135
4136 (void) mc_chdir (panel->cwd_vpath);
4137
4138 for (i = 0, j = 0; i < list->len; i++)
4139 {
4140 vfs_path_t *vpath;
4141
4142 vpath = vfs_path_from_str (list->list[i].fname->str);
4143 if (mc_lstat (vpath, &list->list[i].st) != 0)
4144 g_string_free (list->list[i].fname, TRUE);
4145 else
4146 {
4147 if (j != i)
4148 list->list[j] = list->list[i];
4149 j++;
4150 }
4151 vfs_path_free (vpath, TRUE);
4152 }
4153 if (j == 0)
4154 dir_list_init (list);
4155 else
4156 list->len = j;
4157
4158 recalculate_panel_summary (panel);
4159
4160 if (panel != current_panel)
4161 (void) mc_chdir (current_panel->cwd_vpath);
4162 }
4163
4164
4165
4166 static void
4167 update_one_panel_widget (WPanel *panel, panel_update_flags_t flags, const char *current_file)
4168 {
4169 gboolean free_pointer;
4170 char *my_current_file = NULL;
4171
4172 if ((flags & UP_RELOAD) != 0)
4173 {
4174 panel->is_panelized = FALSE;
4175 mc_setctl (panel->cwd_vpath, VFS_SETCTL_FLUSH, NULL);
4176 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
4177 }
4178
4179
4180 free_pointer = current_file == UP_KEEPSEL;
4181
4182 if (free_pointer)
4183 {
4184 const file_entry_t *fe;
4185
4186 fe = panel_current_entry (panel);
4187 if (fe != NULL)
4188 my_current_file = g_strndup (fe->fname->str, fe->fname->len);
4189 current_file = my_current_file;
4190 }
4191
4192 if (panel->is_panelized)
4193 reload_panelized (panel);
4194 else
4195 panel_reload (panel);
4196
4197 panel_set_current_by_name (panel, current_file);
4198 panel->dirty = TRUE;
4199
4200 if (free_pointer)
4201 g_free (my_current_file);
4202 }
4203
4204
4205
4206 static void
4207 update_one_panel (int which, panel_update_flags_t flags, const char *current_file)
4208 {
4209 if (get_panel_type (which) == view_listing)
4210 {
4211 WPanel *panel;
4212
4213 panel = PANEL (get_panel_widget (which));
4214 if (panel->is_panelized)
4215 flags &= ~UP_RELOAD;
4216 update_one_panel_widget (panel, flags, current_file);
4217 }
4218 }
4219
4220
4221
4222
4223 static gboolean
4224 event_update_panels (const gchar *event_group_name, const gchar *event_name, gpointer init_data,
4225 gpointer data)
4226 {
4227 (void) event_group_name;
4228 (void) event_name;
4229 (void) init_data;
4230 (void) data;
4231
4232 update_panels (UP_RELOAD, UP_KEEPSEL);
4233
4234 return TRUE;
4235 }
4236
4237
4238
4239
4240 static gboolean
4241 panel_save_current_file_to_clip_file (const gchar *event_group_name, const gchar *event_name,
4242 gpointer init_data, gpointer data)
4243 {
4244 (void) event_group_name;
4245 (void) event_name;
4246 (void) init_data;
4247 (void) data;
4248
4249 if (current_panel->marked == 0)
4250 {
4251 const file_entry_t *fe;
4252
4253 fe = panel_current_entry (current_panel);
4254 if (fe != NULL)
4255 mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file",
4256 (gpointer) fe->fname->str);
4257 }
4258 else
4259 {
4260 int i;
4261 gboolean first = TRUE;
4262 char *flist = NULL;
4263
4264 for (i = 0; i < current_panel->dir.len; i++)
4265 {
4266 const file_entry_t *fe = ¤t_panel->dir.list[i];
4267
4268 if (fe->f.marked != 0)
4269 {
4270 if (first)
4271 {
4272 flist = g_strndup (fe->fname->str, fe->fname->len);
4273 first = FALSE;
4274 }
4275 else
4276 {
4277
4278 char *tmp;
4279
4280 tmp = g_strconcat (flist, "\n", fe->fname->str, (char *) NULL);
4281 g_free (flist);
4282 flist = tmp;
4283 }
4284 }
4285 }
4286
4287 mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", (gpointer) flist);
4288 g_free (flist);
4289 }
4290 return TRUE;
4291 }
4292
4293
4294
4295 static vfs_path_t *
4296 panel_recursive_cd_to_parent (const vfs_path_t *vpath)
4297 {
4298 vfs_path_t *cwd_vpath;
4299
4300 cwd_vpath = vfs_path_clone (vpath);
4301
4302 while (mc_chdir (cwd_vpath) < 0)
4303 {
4304 const char *panel_cwd_path;
4305 vfs_path_t *tmp_vpath;
4306
4307
4308 panel_cwd_path = vfs_path_as_str (cwd_vpath);
4309 if (panel_cwd_path != NULL && IS_PATH_SEP (panel_cwd_path[0]) && panel_cwd_path[1] == '\0')
4310 {
4311 vfs_path_free (cwd_vpath, TRUE);
4312 return NULL;
4313 }
4314
4315 tmp_vpath = vfs_path_vtokens_get (cwd_vpath, 0, -1);
4316 vfs_path_free (cwd_vpath, TRUE);
4317 cwd_vpath =
4318 vfs_path_build_filename (PATH_SEP_STR, vfs_path_as_str (tmp_vpath), (char *) NULL);
4319 vfs_path_free (tmp_vpath, TRUE);
4320 }
4321
4322 return cwd_vpath;
4323 }
4324
4325
4326
4327 static void
4328 panel_dir_list_callback (dir_list_cb_state_t state, void *data)
4329 {
4330 static int count = 0;
4331
4332 (void) data;
4333
4334 switch (state)
4335 {
4336 case DIR_OPEN:
4337 count = 0;
4338 break;
4339
4340 case DIR_READ:
4341 count++;
4342 if ((count & 15) == 0)
4343 rotate_dash (TRUE);
4344 break;
4345
4346 case DIR_CLOSE:
4347 rotate_dash (FALSE);
4348 break;
4349
4350 default:
4351 g_assert_not_reached ();
4352 }
4353 }
4354
4355
4356
4357
4358
4359 file_entry_t *
4360 panel_current_entry (const WPanel *panel)
4361 {
4362 file_entry_t *fe;
4363
4364 if (panel->dir.len == 0 || panel->current < 0 || panel->current >= panel->dir.len)
4365 return NULL;
4366
4367 fe = &(panel->dir.list[panel->current]);
4368
4369 return fe->fname == NULL ? NULL : fe;
4370 }
4371
4372
4373
4374 void
4375 panel_set_current_by_name (WPanel *panel, const char *name)
4376 {
4377 int i;
4378 char *subdir;
4379
4380 if (panel->dir.len == 0)
4381 {
4382 panel_set_current (panel, -1);
4383 return;
4384 }
4385
4386 if (name == NULL)
4387 {
4388 panel_set_current (panel, 0);
4389 return;
4390 }
4391
4392
4393
4394
4395 if (panel->is_panelized)
4396 subdir = vfs_strip_suffix_from_filename (name);
4397 else
4398 subdir = vfs_strip_suffix_from_filename (x_basename (name));
4399
4400
4401
4402 for (i = 0; i < panel->dir.len; i++)
4403 if (strcmp (subdir, panel->dir.list[i].fname->str) == 0)
4404 {
4405 panel_set_current (panel, i);
4406 g_free (subdir);
4407 return;
4408 }
4409
4410
4411 if (panel->current >= panel->dir.len)
4412 panel_set_current (panel, panel->dir.len - 1);
4413 g_free (subdir);
4414
4415 select_item (panel);
4416 }
4417
4418
4419
4420 void
4421 panel_clean_dir (WPanel *panel)
4422 {
4423 panel->top = 0;
4424 panel->current = 0;
4425 panel->marked = 0;
4426 panel->dirs_marked = 0;
4427 panel->total = 0;
4428 panel->quick_search.active = FALSE;
4429 panel->is_panelized = FALSE;
4430 panel->dirty = TRUE;
4431 panel->content_shift = 0;
4432 panel->max_shift = 0;
4433
4434 dir_list_free_list (&panel->dir);
4435 }
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445 void
4446 panel_set_cwd (WPanel *panel, const vfs_path_t *vpath)
4447 {
4448 if (vpath != panel->cwd_vpath)
4449 {
4450 vfs_path_free (panel->cwd_vpath, TRUE);
4451 panel->cwd_vpath = vfs_path_clone (vpath);
4452 }
4453 }
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463 void
4464 panel_set_lwd (WPanel *panel, const vfs_path_t *vpath)
4465 {
4466 if (vpath != panel->lwd_vpath)
4467 {
4468 vfs_path_free (panel->lwd_vpath, TRUE);
4469 panel->lwd_vpath = vfs_path_clone (vpath);
4470 }
4471 }
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483 WPanel *
4484 panel_sized_empty_new (const char *panel_name, const WRect *r)
4485 {
4486 WPanel *panel;
4487 Widget *w;
4488 char *section;
4489 int i, err;
4490
4491 panel = g_new0 (WPanel, 1);
4492 w = WIDGET (panel);
4493 widget_init (w, r, panel_callback, panel_mouse_callback);
4494 w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
4495 w->keymap = panel_map;
4496
4497 panel->dir.size = DIR_LIST_MIN_SIZE;
4498 panel->dir.list = g_new (file_entry_t, panel->dir.size);
4499 panel->dir.len = 0;
4500 panel->dir.callback = panel_dir_list_callback;
4501
4502 panel->list_cols = 1;
4503 panel->brief_cols = 2;
4504 panel->dirty = TRUE;
4505 panel->content_shift = 0;
4506 panel->max_shift = 0;
4507
4508 panel->list_format = list_full;
4509 panel->user_format = g_strdup (DEFAULT_USER_FORMAT);
4510
4511 panel->filter.flags = FILE_FILTER_DEFAULT_FLAGS;
4512
4513 for (i = 0; i < LIST_FORMATS; i++)
4514 panel->user_status_format[i] = g_strdup (DEFAULT_USER_FORMAT);
4515
4516 panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
4517
4518 panel->frame_size = frame_half;
4519
4520 panel->quick_search.buffer = g_string_sized_new (MC_MAXFILENAMELEN);
4521 panel->quick_search.prev_buffer = g_string_sized_new (MC_MAXFILENAMELEN);
4522
4523 panel->name = g_strdup (panel_name);
4524 panel->dir_history.name = g_strconcat ("Dir Hist ", panel->name, (char *) NULL);
4525
4526
4527 section = g_strconcat ("Temporal:", panel->name, (char *) NULL);
4528 if (!mc_config_has_group (mc_global.main_config, section))
4529 {
4530 g_free (section);
4531 section = g_strdup (panel->name);
4532 }
4533 panel_load_setup (panel, section);
4534 g_free (section);
4535
4536 if (panel->filter.value != NULL)
4537 {
4538 gboolean case_sens = (panel->filter.flags & SELECT_MATCH_CASE) != 0;
4539 gboolean shell_patterns = (panel->filter.flags & SELECT_SHELL_PATTERNS) != 0;
4540
4541 panel->filter.handler = mc_search_new (panel->filter.value, NULL);
4542 panel->filter.handler->search_type = shell_patterns ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
4543 panel->filter.handler->is_entire_line = TRUE;
4544 panel->filter.handler->is_case_sensitive = case_sens;
4545
4546
4547 if (!mc_search_prepare (panel->filter.handler))
4548 file_filter_clear (&panel->filter);
4549 }
4550
4551
4552 err = set_panel_formats (panel);
4553 if (err != 0)
4554 set_panel_formats (panel);
4555
4556 return panel;
4557 }
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570 WPanel *
4571 panel_sized_with_dir_new (const char *panel_name, const WRect *r, const vfs_path_t *vpath)
4572 {
4573 WPanel *panel;
4574 char *curdir = NULL;
4575 const vfs_path_element_t *path_element;
4576
4577 panel = panel_sized_empty_new (panel_name, r);
4578
4579 if (vpath != NULL)
4580 {
4581 curdir = vfs_get_cwd ();
4582 panel_set_cwd (panel, vpath);
4583 }
4584 else
4585 {
4586 vfs_setup_cwd ();
4587 panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
4588 }
4589
4590 panel_set_lwd (panel, vfs_get_raw_current_dir ());
4591
4592 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
4593 if (path_element->encoding != NULL)
4594 panel->codepage = get_codepage_index (path_element->encoding);
4595
4596 if (mc_chdir (panel->cwd_vpath) != 0)
4597 {
4598 panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
4599 vfs_setup_cwd ();
4600 vfs_path_free (panel->cwd_vpath, TRUE);
4601 panel->cwd_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
4602 }
4603
4604
4605 if (!dir_list_load (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
4606 &panel->sort_info, &panel->filter))
4607 message (D_ERROR, MSG_ERROR, _ ("Cannot read directory contents"));
4608
4609 if (panel->dir.len == 0)
4610 panel_set_current (panel, -1);
4611
4612
4613 if (curdir != NULL)
4614 {
4615 vfs_path_t *tmp_vpath;
4616 int err;
4617
4618 tmp_vpath = vfs_path_from_str (curdir);
4619 mc_chdir (tmp_vpath);
4620 vfs_path_free (tmp_vpath, TRUE);
4621 (void) err;
4622 }
4623 g_free (curdir);
4624
4625 return panel;
4626 }
4627
4628
4629
4630 void
4631 panel_reload (WPanel *panel)
4632 {
4633 struct stat current_stat;
4634 vfs_path_t *cwd_vpath;
4635
4636 if (panels_options.fast_reload && stat (vfs_path_as_str (panel->cwd_vpath), ¤t_stat) == 0
4637 && current_stat.st_ctime == panel->dir_stat.st_ctime
4638 && current_stat.st_mtime == panel->dir_stat.st_mtime)
4639 return;
4640
4641 cwd_vpath = panel_recursive_cd_to_parent (panel->cwd_vpath);
4642 vfs_path_free (panel->cwd_vpath, TRUE);
4643
4644 if (cwd_vpath == NULL)
4645 {
4646 panel->cwd_vpath = vfs_path_from_str (PATH_SEP_STR);
4647 panel_clean_dir (panel);
4648 dir_list_init (&panel->dir);
4649 return;
4650 }
4651
4652 panel->cwd_vpath = cwd_vpath;
4653 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
4654 show_dir (panel);
4655
4656 if (!dir_list_reload (&panel->dir, panel->cwd_vpath, panel->sort_field->sort_routine,
4657 &panel->sort_info, &panel->filter))
4658 message (D_ERROR, MSG_ERROR, _ ("Cannot read directory contents"));
4659
4660 panel->dirty = TRUE;
4661
4662 if (panel->dir.len == 0)
4663 panel_set_current (panel, -1);
4664 else if (panel->current >= panel->dir.len)
4665 panel_set_current (panel, panel->dir.len - 1);
4666
4667 recalculate_panel_summary (panel);
4668 }
4669
4670
4671
4672
4673
4674
4675 int
4676 set_panel_formats (WPanel *p)
4677 {
4678 GSList *form;
4679 char *err = NULL;
4680 int retcode = 0;
4681
4682 form = use_display_format (p, panel_format (p), &err, FALSE);
4683
4684 if (err != NULL)
4685 {
4686 g_free (err);
4687 retcode = 1;
4688 }
4689 else
4690 {
4691 g_slist_free_full (p->format, (GDestroyNotify) format_item_free);
4692 p->format = form;
4693 }
4694
4695 if (panels_options.show_mini_info)
4696 {
4697 form = use_display_format (p, mini_status_format (p), &err, TRUE);
4698
4699 if (err != NULL)
4700 {
4701 g_free (err);
4702 retcode += 2;
4703 }
4704 else
4705 {
4706 g_slist_free_full (p->status_format, (GDestroyNotify) format_item_free);
4707 p->status_format = form;
4708 }
4709 }
4710
4711 panel_update_cols (WIDGET (p), p->frame_size);
4712
4713 if (retcode != 0)
4714 message (D_ERROR, _ ("Warning"),
4715 _ ("User supplied format looks invalid, reverting to default."));
4716 if ((retcode & 0x01) != 0)
4717 {
4718 g_free (p->user_format);
4719 p->user_format = g_strdup (DEFAULT_USER_FORMAT);
4720 }
4721 if ((retcode & 0x02) != 0)
4722 {
4723 g_free (p->user_status_format[p->list_format]);
4724 p->user_status_format[p->list_format] = g_strdup (DEFAULT_USER_FORMAT);
4725 }
4726
4727 return retcode;
4728 }
4729
4730
4731
4732 void
4733 panel_set_filter (WPanel *panel, const file_filter_t *filter)
4734 {
4735 MC_PTR_FREE (panel->filter.value);
4736 mc_search_free (panel->filter.handler);
4737 panel->filter.handler = NULL;
4738
4739
4740 if (filter != NULL)
4741 panel->filter = *filter;
4742
4743 reread_cmd ();
4744 }
4745
4746
4747
4748
4749 void
4750 select_item (WPanel *panel)
4751 {
4752 adjust_top_file (panel);
4753
4754 panel->dirty = TRUE;
4755
4756 execute_hooks (select_file_hook);
4757 }
4758
4759
4760
4761 void
4762 unmark_files (WPanel *panel)
4763 {
4764 if (panel->marked != 0)
4765 {
4766 int i;
4767
4768 for (i = 0; i < panel->dir.len; i++)
4769 file_mark (panel, i, 0);
4770
4771 panel->dirs_marked = 0;
4772 panel->marked = 0;
4773 panel->total = 0;
4774 }
4775 }
4776
4777
4778
4779
4780
4781 void
4782 recalculate_panel_summary (WPanel *panel)
4783 {
4784 int i;
4785
4786 panel->marked = 0;
4787 panel->dirs_marked = 0;
4788 panel->total = 0;
4789
4790 for (i = 0; i < panel->dir.len; i++)
4791 if (panel->dir.list[i].f.marked != 0)
4792 {
4793
4794
4795
4796 panel->dir.list[i].f.marked = 0;
4797 do_file_mark (panel, i, 1);
4798 }
4799 }
4800
4801
4802
4803
4804 void
4805 do_file_mark (WPanel *panel, int idx, int mark)
4806 {
4807 if (panel->dir.list[idx].f.marked == mark)
4808 return;
4809
4810
4811 if (DIR_IS_DOTDOT (panel->dir.list[idx].fname->str))
4812 return;
4813
4814 file_mark (panel, idx, mark);
4815 if (panel->dir.list[idx].f.marked != 0)
4816 {
4817 panel->marked++;
4818
4819 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
4820 {
4821 if (panel->dir.list[idx].f.dir_size_computed != 0)
4822 panel->total += (uintmax_t) panel->dir.list[idx].st.st_size;
4823 panel->dirs_marked++;
4824 }
4825 else
4826 panel->total += (uintmax_t) panel->dir.list[idx].st.st_size;
4827
4828 set_colors (panel);
4829 }
4830 else
4831 {
4832 if (S_ISDIR (panel->dir.list[idx].st.st_mode))
4833 {
4834 if (panel->dir.list[idx].f.dir_size_computed != 0)
4835 panel->total -= (uintmax_t) panel->dir.list[idx].st.st_size;
4836 panel->dirs_marked--;
4837 }
4838 else
4839 panel->total -= (uintmax_t) panel->dir.list[idx].st.st_size;
4840
4841 panel->marked--;
4842 }
4843 }
4844
4845
4846
4847
4848
4849
4850 gboolean
4851 panel_do_cd (WPanel *panel, const vfs_path_t *new_dir_vpath, enum cd_enum cd_type)
4852 {
4853 gboolean r;
4854
4855 r = panel_do_cd_int (panel, new_dir_vpath, cd_type);
4856 if (r)
4857 directory_history_add (panel, panel->cwd_vpath);
4858 return r;
4859 }
4860
4861
4862
4863 void
4864 file_mark (WPanel *panel, int lc_index, int val)
4865 {
4866 if (panel->dir.list[lc_index].f.marked != val)
4867 {
4868 panel->dir.list[lc_index].f.marked = val;
4869 panel->dirty = TRUE;
4870 }
4871 }
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884 const GString *
4885 panel_find_marked_file (const WPanel *panel, int *current_file)
4886 {
4887 while (panel->dir.list[*current_file].f.marked == 0 && *current_file < panel->dir.len)
4888 (*current_file)++;
4889
4890 return (*current_file >= panel->dir.len ? NULL : panel->dir.list[*current_file].fname);
4891 }
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905 const GString *
4906 panel_get_marked_file (const WPanel *panel, int *current_file)
4907 {
4908 const file_entry_t *fe;
4909
4910 if (panel->marked != 0)
4911 return panel_find_marked_file (panel, current_file);
4912
4913 fe = panel_current_entry (panel);
4914
4915 return (fe == NULL ? NULL : fe->fname);
4916 }
4917
4918
4919
4920 void
4921 panel_re_sort (WPanel *panel)
4922 {
4923 char *filename;
4924 const file_entry_t *fe;
4925 int i;
4926
4927 if (panel == NULL)
4928 return;
4929
4930 fe = panel_current_entry (panel);
4931 if (fe == NULL)
4932 return;
4933
4934 filename = g_strndup (fe->fname->str, fe->fname->len);
4935 unselect_item (panel);
4936 dir_list_sort (&panel->dir, panel->sort_field->sort_routine, &panel->sort_info);
4937 panel->current = -1;
4938
4939 for (i = panel->dir.len; i != 0; i--)
4940 if (strcmp (panel->dir.list[i - 1].fname->str, filename) == 0)
4941 {
4942 panel->current = i - 1;
4943 break;
4944 }
4945
4946 g_free (filename);
4947 panel->top = panel->current - panel_items (panel) / 2;
4948 select_item (panel);
4949 panel->dirty = TRUE;
4950 }
4951
4952
4953
4954 void
4955 panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order)
4956 {
4957 if (sort_order == NULL)
4958 return;
4959
4960 panel->sort_field = sort_order;
4961
4962
4963 if (sort_order->sort_routine == (GCompareFunc) unsorted)
4964 {
4965 const file_entry_t *fe;
4966 char *current_file = NULL;
4967
4968 fe = panel_current_entry (panel);
4969 if (fe != NULL)
4970 current_file = g_strndup (fe->fname->str, fe->fname->len);
4971 panel_reload (panel);
4972 panel_set_current_by_name (panel, current_file);
4973 g_free (current_file);
4974 }
4975 panel_re_sort (panel);
4976 }
4977
4978
4979
4980
4981
4982
4983
4984 void
4985 panel_change_encoding (WPanel *panel)
4986 {
4987 const char *encoding = NULL;
4988 char *errmsg;
4989
4990 const int r = select_charset (-1, -1, panel->codepage);
4991
4992 if (r == SELECT_CHARSET_CANCEL)
4993 return;
4994
4995 panel->codepage = r;
4996
4997 if (panel->codepage == SELECT_CHARSET_NO_TRANSLATE)
4998 {
4999
5000 vfs_path_t *cd_path_vpath;
5001
5002 g_free (init_translation_table (mc_global.display_codepage, mc_global.display_codepage));
5003 cd_path_vpath = remove_encoding_from_path (panel->cwd_vpath);
5004 panel_do_cd (panel, cd_path_vpath, cd_parse_command);
5005 show_dir (panel);
5006 vfs_path_free (cd_path_vpath, TRUE);
5007 return;
5008 }
5009
5010 errmsg = init_translation_table (panel->codepage, mc_global.display_codepage);
5011 if (errmsg != NULL)
5012 {
5013 message (D_ERROR, MSG_ERROR, "%s", errmsg);
5014 g_free (errmsg);
5015 return;
5016 }
5017
5018 encoding = get_codepage_id (panel->codepage);
5019 if (encoding != NULL)
5020 {
5021 vfs_path_change_encoding (panel->cwd_vpath, encoding);
5022
5023 if (!panel_do_cd (panel, panel->cwd_vpath, cd_parse_command))
5024 cd_error_message (vfs_path_as_str (panel->cwd_vpath));
5025 }
5026 }
5027
5028
5029
5030
5031
5032
5033
5034 vfs_path_t *
5035 remove_encoding_from_path (const vfs_path_t *vpath)
5036 {
5037 vfs_path_t *ret_vpath;
5038 GString *tmp_conv;
5039 int indx;
5040
5041 ret_vpath = vfs_path_new (FALSE);
5042
5043 tmp_conv = g_string_new ("");
5044
5045 for (indx = 0; indx < vfs_path_elements_count (vpath); indx++)
5046 {
5047 GIConv converter;
5048 vfs_path_element_t *path_element;
5049
5050 path_element = vfs_path_element_clone (vfs_path_get_by_index (vpath, indx));
5051
5052 if (path_element->encoding == NULL)
5053 {
5054 vfs_path_add_element (ret_vpath, path_element);
5055 continue;
5056 }
5057
5058 converter = str_crt_conv_to (path_element->encoding);
5059 if (converter == INVALID_CONV)
5060 {
5061 vfs_path_add_element (ret_vpath, path_element);
5062 continue;
5063 }
5064
5065 MC_PTR_FREE (path_element->encoding);
5066
5067 str_vfs_convert_from (converter, path_element->path, tmp_conv);
5068
5069 g_free (path_element->path);
5070 path_element->path = g_strndup (tmp_conv->str, tmp_conv->len);
5071
5072 g_string_set_size (tmp_conv, 0);
5073
5074 str_close_conv (converter);
5075 str_close_conv (path_element->dir.converter);
5076 path_element->dir.converter = INVALID_CONV;
5077 vfs_path_add_element (ret_vpath, path_element);
5078 }
5079 g_string_free (tmp_conv, TRUE);
5080 return ret_vpath;
5081 }
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098 void
5099 update_panels (panel_update_flags_t flags, const char *current_file)
5100 {
5101 WPanel *panel;
5102
5103
5104 if ((flags & UP_ONLY_CURRENT) == 0)
5105 update_one_panel (get_other_index (), flags, UP_KEEPSEL);
5106
5107 update_one_panel (get_current_index (), flags, current_file);
5108
5109 if (get_current_type () == view_listing)
5110 panel = PANEL (get_panel_widget (get_current_index ()));
5111 else
5112 panel = PANEL (get_panel_widget (get_other_index ()));
5113
5114 if (!panel->is_panelized)
5115 (void) mc_chdir (panel->cwd_vpath);
5116 }
5117
5118
5119
5120 gsize
5121 panel_get_num_of_sortable_fields (void)
5122 {
5123 gsize ret = 0, lc_index;
5124
5125 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
5126 if (panel_fields[lc_index].is_user_choice)
5127 ret++;
5128 return ret;
5129 }
5130
5131
5132
5133 char **
5134 panel_get_sortable_fields (gsize *array_size)
5135 {
5136 char **ret;
5137 gsize lc_index, i;
5138
5139 lc_index = panel_get_num_of_sortable_fields ();
5140
5141 ret = g_try_new0 (char *, lc_index + 1);
5142 if (ret == NULL)
5143 return NULL;
5144
5145 if (array_size != NULL)
5146 *array_size = lc_index;
5147
5148 lc_index = 0;
5149
5150 for (i = 0; panel_fields[i].id != NULL; i++)
5151 if (panel_fields[i].is_user_choice)
5152 ret[lc_index++] = g_strdup (_ (panel_fields[i].title_hotkey));
5153
5154 return ret;
5155 }
5156
5157
5158
5159 const panel_field_t *
5160 panel_get_field_by_id (const char *name)
5161 {
5162 gsize lc_index;
5163
5164 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
5165 if (panel_fields[lc_index].id != NULL && strcmp (name, panel_fields[lc_index].id) == 0)
5166 return &panel_fields[lc_index];
5167
5168 return NULL;
5169 }
5170
5171
5172
5173 const panel_field_t *
5174 panel_get_field_by_title_hotkey (const char *name)
5175 {
5176 gsize lc_index;
5177
5178 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
5179 if (panel_fields[lc_index].title_hotkey != NULL
5180 && strcmp (name, _ (panel_fields[lc_index].title_hotkey)) == 0)
5181 return &panel_fields[lc_index];
5182
5183 return NULL;
5184 }
5185
5186
5187
5188 const panel_field_t *
5189 panel_get_field_by_title (const char *name)
5190 {
5191 gsize lc_index;
5192
5193 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
5194 {
5195 const char *title;
5196
5197 title = panel_get_title_without_hotkey (panel_fields[lc_index].title_hotkey);
5198 if (strcmp (title, name) == 0)
5199 return &panel_fields[lc_index];
5200 }
5201
5202 return NULL;
5203 }
5204
5205
5206
5207 gsize
5208 panel_get_num_of_user_possible_fields (void)
5209 {
5210 gsize ret = 0, lc_index;
5211
5212 for (lc_index = 0; panel_fields[lc_index].id != NULL; lc_index++)
5213 if (panel_fields[lc_index].use_in_user_format)
5214 ret++;
5215
5216 return ret;
5217 }
5218
5219
5220
5221 char **
5222 panel_get_user_possible_fields (gsize *array_size)
5223 {
5224 char **ret;
5225 gsize lc_index, i;
5226
5227 lc_index = panel_get_num_of_user_possible_fields ();
5228
5229 ret = g_try_new0 (char *, lc_index + 1);
5230 if (ret == NULL)
5231 return NULL;
5232
5233 if (array_size != NULL)
5234 *array_size = lc_index;
5235
5236 lc_index = 0;
5237
5238 for (i = 0; panel_fields[i].id != NULL; i++)
5239 if (panel_fields[i].use_in_user_format)
5240 ret[lc_index++] = g_strdup (_ (panel_fields[i].title_hotkey));
5241
5242 return ret;
5243 }
5244
5245
5246
5247
5248
5249
5250
5251 void
5252 panel_panelize_restore (void)
5253 {
5254 WPanel *panel;
5255 int i;
5256 dir_list *list;
5257 panelized_descr_t *pdescr;
5258 dir_list *plist;
5259 gboolean panelized_same;
5260
5261 if (!SELECTED_IS_PANEL)
5262 create_panel (MENU_PANEL_IDX, view_listing);
5263
5264 panel = PANEL (get_panel_widget (MENU_PANEL_IDX));
5265
5266 dir_list_clean (&panel->dir);
5267
5268 if (panel->panelized_descr == NULL)
5269 panel->panelized_descr = panelized_descr_new ();
5270
5271 pdescr = panel->panelized_descr;
5272 plist = &pdescr->list;
5273
5274 if (pdescr->root_vpath == NULL)
5275 panel_panelize_change_root (panel, panel->cwd_vpath);
5276
5277 if (plist->len < 1)
5278 dir_list_init (plist);
5279 else if (plist->len > panel->dir.size)
5280 dir_list_grow (&panel->dir, plist->len - panel->dir.size);
5281
5282 list = &panel->dir;
5283 list->len = plist->len;
5284
5285 panelized_same = vfs_path_equal (pdescr->root_vpath, panel->cwd_vpath);
5286
5287 for (i = 0; i < plist->len; i++)
5288 {
5289 if (panelized_same || DIR_IS_DOTDOT (plist->list[i].fname->str))
5290 list->list[i].fname = mc_g_string_dup (plist->list[i].fname);
5291 else
5292 {
5293 vfs_path_t *tmp_vpath;
5294
5295 tmp_vpath =
5296 vfs_path_append_new (pdescr->root_vpath, plist->list[i].fname->str, (char *) NULL);
5297 list->list[i].fname = g_string_new_take (vfs_path_free (tmp_vpath, FALSE));
5298 }
5299 list->list[i].f.link_to_dir = plist->list[i].f.link_to_dir;
5300 list->list[i].f.stale_link = plist->list[i].f.stale_link;
5301 list->list[i].f.dir_size_computed = plist->list[i].f.dir_size_computed;
5302 list->list[i].f.marked = plist->list[i].f.marked;
5303 list->list[i].st = plist->list[i].st;
5304 list->list[i].name_sort_key = plist->list[i].name_sort_key;
5305 list->list[i].extension_sort_key = plist->list[i].extension_sort_key;
5306 }
5307
5308 panel->is_panelized = TRUE;
5309 panel_panelize_absolutize_if_needed (panel);
5310
5311 panel_set_current_by_name (panel, NULL);
5312 }
5313
5314
5315
5316
5317
5318
5319
5320
5321 void
5322 panel_panelize_change_root (WPanel *panel, const vfs_path_t *new_root)
5323 {
5324 if (panel->panelized_descr == NULL)
5325 panel->panelized_descr = panelized_descr_new ();
5326 else
5327 vfs_path_free (panel->panelized_descr->root_vpath, TRUE);
5328
5329 panel->panelized_descr->root_vpath = vfs_path_clone (new_root);
5330 }
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351 void
5352 panel_panelize_absolutize_if_needed (WPanel *panel)
5353 {
5354 const dir_list *const list = &panel->dir;
5355
5356
5357
5358 if (list->len > 1 && g_path_is_absolute (list->list[1].fname->str))
5359 {
5360 vfs_path_t *root;
5361
5362 root = vfs_path_from_str (PATH_SEP_STR);
5363 panel_set_cwd (panel, root);
5364 if (panel == current_panel)
5365 mc_chdir (root);
5366 vfs_path_free (root, TRUE);
5367 }
5368 }
5369
5370
5371
5372
5373
5374
5375
5376 void
5377 panel_panelize_save (WPanel *panel)
5378 {
5379 int i;
5380 dir_list *list = &panel->dir;
5381 dir_list *plist;
5382
5383 panel_panelize_change_root (panel, panel->cwd_vpath);
5384
5385 plist = &panel->panelized_descr->list;
5386
5387 if (plist->len > 0)
5388 dir_list_clean (plist);
5389 if (panel->dir.len == 0)
5390 return;
5391
5392 if (panel->dir.len > plist->size)
5393 dir_list_grow (plist, panel->dir.len - plist->size);
5394 plist->len = panel->dir.len;
5395
5396 for (i = 0; i < panel->dir.len; i++)
5397 {
5398 plist->list[i].fname = mc_g_string_dup (list->list[i].fname);
5399 plist->list[i].f.link_to_dir = list->list[i].f.link_to_dir;
5400 plist->list[i].f.stale_link = list->list[i].f.stale_link;
5401 plist->list[i].f.dir_size_computed = list->list[i].f.dir_size_computed;
5402 plist->list[i].f.marked = list->list[i].f.marked;
5403 plist->list[i].st = list->list[i].st;
5404 plist->list[i].name_sort_key = list->list[i].name_sort_key;
5405 plist->list[i].extension_sort_key = list->list[i].extension_sort_key;
5406 }
5407 }
5408
5409
5410
5411 void
5412 panel_init (void)
5413 {
5414 panel_sort_up_char = mc_skin_get ("widget-panel", "sort-up-char", "'");
5415 panel_sort_down_char = mc_skin_get ("widget-panel", "sort-down-char", ".");
5416 panel_hiddenfiles_show_char = mc_skin_get ("widget-panel", "hiddenfiles-show-char", ".");
5417 panel_hiddenfiles_hide_char = mc_skin_get ("widget-panel", "hiddenfiles-hide-char", ".");
5418 panel_history_prev_item_char = mc_skin_get ("widget-panel", "history-prev-item-char", "<");
5419 panel_history_next_item_char = mc_skin_get ("widget-panel", "history-next-item-char", ">");
5420 panel_history_show_list_char = mc_skin_get ("widget-panel", "history-show-list-char", "^");
5421 panel_filename_scroll_left_char =
5422 mc_skin_get ("widget-panel", "filename-scroll-left-char", "{");
5423 panel_filename_scroll_right_char =
5424 mc_skin_get ("widget-panel", "filename-scroll-right-char", "}");
5425
5426 string_file_name_buffer = g_string_sized_new (MC_MAXFILENAMELEN);
5427
5428 mc_event_add (MCEVENT_GROUP_FILEMANAGER, "update_panels", event_update_panels, NULL, NULL);
5429 mc_event_add (MCEVENT_GROUP_FILEMANAGER, "panel_save_current_file_to_clip_file",
5430 panel_save_current_file_to_clip_file, NULL, NULL);
5431 }
5432
5433
5434
5435 void
5436 panel_deinit (void)
5437 {
5438 g_free (panel_sort_up_char);
5439 g_free (panel_sort_down_char);
5440 g_free (panel_hiddenfiles_show_char);
5441 g_free (panel_hiddenfiles_hide_char);
5442 g_free (panel_history_prev_item_char);
5443 g_free (panel_history_next_item_char);
5444 g_free (panel_history_show_list_char);
5445 g_free (panel_filename_scroll_left_char);
5446 g_free (panel_filename_scroll_right_char);
5447 g_string_free (string_file_name_buffer, TRUE);
5448 }
5449
5450
5451
5452 gboolean
5453 panel_cd (WPanel *panel, const vfs_path_t *new_dir_vpath, enum cd_enum exact)
5454 {
5455 gboolean res;
5456 const vfs_path_t *_new_dir_vpath = new_dir_vpath;
5457
5458 if (panel->is_panelized)
5459 {
5460 size_t new_vpath_len;
5461
5462 new_vpath_len = vfs_path_len (new_dir_vpath);
5463 if (vfs_path_equal_len (new_dir_vpath, panel->panelized_descr->root_vpath, new_vpath_len))
5464 _new_dir_vpath = panel->panelized_descr->root_vpath;
5465 }
5466
5467 res = panel_do_cd (panel, _new_dir_vpath, exact);
5468
5469 if (res)
5470 {
5471 const vfs_path_element_t *path_element;
5472
5473 path_element = vfs_path_get_by_index (panel->cwd_vpath, -1);
5474 if (path_element->encoding != NULL)
5475 panel->codepage = get_codepage_index (path_element->encoding);
5476 else
5477 panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
5478 }
5479
5480 return res;
5481 }
5482
5483