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