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