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