forked from MidnightCommander/mc
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.c
2493 lines (2094 loc) · 58.8 KB
/
screen.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Panel managing.
Copyright (C) 1994, 1995 Miguel de Icaza.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Written by: 1995 Miguel de Icaza
1997, 1999 Timur Bakeyev
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "global.h"
#include "tty.h"
#include "dir.h"
#include "panel.h"
#include "color.h"
#include "tree.h"
#include "win.h"
#include "ext.h" /* regexp_command */
#include "mouse.h" /* For Gpm_Event */
#include "layout.h" /* Most layout variables are here */
#include "wtools.h" /* for message (...) */
#include "cmd.h"
#include "key.h" /* XCTRL and ALT macros */
#include "setup.h" /* For loading/saving panel options */
#include "user.h"
#include "profile.h"
#include "execute.h"
#include "widget.h"
#include "menu.h" /* menubar_visible */
#define WANT_WIDGETS
#include "main.h" /* the_menubar */
#include "unixcompat.h"
#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
#define J_LEFT 1
#define J_RIGHT 2
#define J_CENTER 3
#define IS_FIT(x) ((x) & 0x0004)
#define MAKE_FIT(x) ((x) | 0x0004)
#define HIDE_FIT(x) ((x) & 0x0003)
#define J_LEFT_FIT 5
#define J_RIGHT_FIT 6
#define J_CENTER_FIT 7
#define NORMAL 0
#define SELECTED 1
#define MARKED 2
#define MARKED_SELECTED 3
#define STATUS 5
/*
* This describes a format item. The parse_display_format routine parses
* the user specified format and creates a linked list of format_e structures.
*/
typedef struct format_e {
struct format_e *next;
int requested_field_len;
int field_len;
int just_mode;
int expand;
const char *(*string_fn)(file_entry *, int len);
const char *title;
const char *id;
} format_e;
/* If true, show the mini-info on the panel */
int show_mini_info = 1;
/* If true, then use stat() on the cwd to determine directory changes */
int fast_reload = 0;
/* If true, use some usability hacks by Torben */
int torben_fj_mode = 0;
/* If true, up/down keys scroll the pane listing by pages */
int panel_scroll_pages = 1;
/* If 1, we use permission hilighting */
int permission_mode = 0;
/* If 1 - then add per file type hilighting */
int filetype_mode = 1;
/* The hook list for the select file function */
Hook *select_file_hook = 0;
static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
static int panel_event (Gpm_Event *event, void *);
static void paint_frame (WPanel *panel);
static const char *panel_format (WPanel *panel);
static const char *mini_status_format (WPanel *panel);
/* This macro extracts the number of available lines in a panel */
#define llines(p) (p->widget.lines-3 - (show_mini_info ? 2 : 0))
static void
set_colors (WPanel *panel)
{
standend ();
attrset (NORMAL_COLOR);
}
/* Delete format string, it is a linked list */
static void
delete_format (format_e *format)
{
format_e *next;
while (format){
next = format->next;
g_free (format);
format = next;
}
}
/* This code relies on the default justification!!! */
static void
add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
{
int i, r, l;
l = get_user_permissions (&fe->st);
if (is_octal){
/* Place of the access bit in octal mode */
l = width + l - 3;
r = l + 1;
} else {
/* The same to the triplet in string mode */
l = l * 3 + 1;
r = l + 3;
}
for(i = 0; i < width; i++){
if (i >= l && i < r){
if (attr == SELECTED || attr == MARKED_SELECTED)
attrset (MARKED_SELECTED_COLOR);
else
attrset (MARKED_COLOR);
} else
attrset (color);
addch (dest[i]);
}
}
/* String representations of various file attributes */
/* name */
static const char *
string_file_name (file_entry *fe, int len)
{
static char buffer [BUF_SMALL];
size_t i;
for (i = 0; i < sizeof(buffer) - 1; i++) {
char c;
c = fe->fname[i];
if (!c)
break;
if (!is_printable(c))
c = '?';
buffer[i] = c;
}
buffer[i] = 0;
return buffer;
}
static inline unsigned int ilog10(dev_t n)
{
unsigned int digits = 0;
do {
digits++, n /= 10;
} while (n != 0);
return digits;
}
static void format_device_number (char *buf, size_t bufsize, dev_t dev)
{
dev_t major_dev = major(dev);
dev_t minor_dev = minor(dev);
unsigned int major_digits = ilog10(major_dev);
unsigned int minor_digits = ilog10(minor_dev);
g_assert(bufsize >= 1);
if (major_digits + 1 + minor_digits + 1 <= bufsize) {
g_snprintf(buf, bufsize, "%lu,%lu", (unsigned long) major_dev,
(unsigned long) minor_dev);
} else {
g_strlcpy(buf, _("[dev]"), bufsize);
}
}
/* size */
static const char *
string_file_size (file_entry *fe, int len)
{
static char buffer [BUF_TINY];
/* Don't ever show size of ".." since we don't calculate it */
if (!strcmp (fe->fname, "..")) {
return _("UP--DIR");
}
#ifdef HAVE_STRUCT_STAT_ST_RDEV
if (S_ISBLK (fe->st.st_mode) || S_ISCHR (fe->st.st_mode))
format_device_number (buffer, len + 1, fe->st.st_rdev);
else
#endif
{
size_trunc_len (buffer, len, fe->st.st_size, 0);
}
return buffer;
}
/* bsize */
static const char *
string_file_size_brief (file_entry *fe, int len)
{
if (S_ISLNK (fe->st.st_mode) && !fe->f.link_to_dir) {
return _("SYMLINK");
}
if ((S_ISDIR (fe->st.st_mode) || fe->f.link_to_dir) && strcmp (fe->fname, "..")) {
return _("SUB-DIR");
}
return string_file_size (fe, len);
}
/* This functions return a string representation of a file entry */
/* type */
static const char *
string_file_type (file_entry *fe, int len)
{
static char buffer[2];
if (S_ISDIR (fe->st.st_mode))
buffer[0] = PATH_SEP;
else if (S_ISLNK (fe->st.st_mode)) {
if (fe->f.link_to_dir)
buffer[0] = '~';
else if (fe->f.stale_link)
buffer[0] = '!';
else
buffer[0] = '@';
} else if (S_ISCHR (fe->st.st_mode))
buffer[0] = '-';
else if (S_ISSOCK (fe->st.st_mode))
buffer[0] = '=';
else if (S_ISDOOR (fe->st.st_mode))
buffer[0] = '>';
else if (S_ISBLK (fe->st.st_mode))
buffer[0] = '+';
else if (S_ISFIFO (fe->st.st_mode))
buffer[0] = '|';
else if (S_ISNAM (fe->st.st_mode))
buffer[0] = '#';
else if (!S_ISREG (fe->st.st_mode))
buffer[0] = '?'; /* non-regular of unknown kind */
else if (is_exe (fe->st.st_mode))
buffer[0] = '*';
else
buffer[0] = ' ';
buffer[1] = '\0';
return buffer;
}
/* mtime */
static const char *
string_file_mtime (file_entry *fe, int len)
{
if (!strcmp (fe->fname, "..")) {
return "";
}
return file_date (fe->st.st_mtime);
}
/* atime */
static const char *
string_file_atime (file_entry *fe, int len)
{
if (!strcmp (fe->fname, "..")) {
return "";
}
return file_date (fe->st.st_atime);
}
/* ctime */
static const char *
string_file_ctime (file_entry *fe, int len)
{
if (!strcmp (fe->fname, "..")) {
return "";
}
return file_date (fe->st.st_ctime);
}
/* perm */
static const char *
string_file_permission (file_entry *fe, int len)
{
return string_perm (fe->st.st_mode);
}
/* mode */
static const char *
string_file_perm_octal (file_entry *fe, int len)
{
static char buffer [10];
g_snprintf (buffer, sizeof (buffer), "0%06lo", (unsigned long) fe->st.st_mode);
return buffer;
}
/* nlink */
static const char *
string_file_nlinks (file_entry *fe, int len)
{
static char buffer[BUF_TINY];
g_snprintf (buffer, sizeof (buffer), "%16d", (int) fe->st.st_nlink);
return buffer;
}
/* inode */
static const char *
string_inode (file_entry *fe, int len)
{
static char buffer [10];
g_snprintf (buffer, sizeof (buffer), "%lu",
(unsigned long) fe->st.st_ino);
return buffer;
}
/* nuid */
static const char *
string_file_nuid (file_entry *fe, int len)
{
static char buffer [10];
g_snprintf (buffer, sizeof (buffer), "%lu",
(unsigned long) fe->st.st_uid);
return buffer;
}
/* ngid */
static const char *
string_file_ngid (file_entry *fe, int len)
{
static char buffer [10];
g_snprintf (buffer, sizeof (buffer), "%lu",
(unsigned long) fe->st.st_gid);
return buffer;
}
/* owner */
static const char *
string_file_owner (file_entry *fe, int len)
{
return get_owner (fe->st.st_uid);
}
/* group */
static const char *
string_file_group (file_entry *fe, int len)
{
return get_group (fe->st.st_gid);
}
/* mark */
static const char *
string_marked (file_entry *fe, int len)
{
return fe->f.marked ? "*" : " ";
}
/* space */
static const char *
string_space (file_entry *fe, int len)
{
return " ";
}
/* dot */
static const char *
string_dot (file_entry *fe, int len)
{
return ".";
}
#define GT 1
static struct {
const char *id;
int min_size;
int expands;
int default_just;
const char *title;
int use_in_gui;
const char *(*string_fn)(file_entry *, int);
sortfn *sort_routine;
} formats [] = {
{ "name", 12, 1, J_LEFT_FIT, N_("Name"), 1, string_file_name, (sortfn *) sort_name },
{ "size", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size, (sortfn *) sort_size },
{ "bsize", 7, 0, J_RIGHT, N_("Size"), 1, string_file_size_brief, (sortfn *) sort_size },
{ "type", GT, 0, J_LEFT, "", 2, string_file_type, (sortfn *) sort_type },
{ "mtime", 12, 0, J_RIGHT, N_("MTime"), 1, string_file_mtime, (sortfn *) sort_time },
{ "atime", 12, 0, J_RIGHT, N_("ATime"), 1, string_file_atime, (sortfn *) sort_atime },
{ "ctime", 12, 0, J_RIGHT, N_("CTime"), 1, string_file_ctime, (sortfn *) sort_ctime },
{ "perm", 10, 0, J_LEFT, N_("Permission"),1,string_file_permission, NULL },
{ "mode", 6, 0, J_RIGHT, N_("Perm"), 1, string_file_perm_octal, NULL },
{ "nlink", 2, 0, J_RIGHT, N_("Nl"), 1, string_file_nlinks, (sortfn *) sort_links },
{ "inode", 5, 0, J_RIGHT, N_("Inode"), 1, string_inode, (sortfn *) sort_inode },
{ "nuid", 5, 0, J_RIGHT, N_("UID"), 1, string_file_nuid, (sortfn *) sort_nuid },
{ "ngid", 5, 0, J_RIGHT, N_("GID"), 1, string_file_ngid, (sortfn *) sort_ngid },
{ "owner", 8, 0, J_LEFT_FIT, N_("Owner"), 1, string_file_owner, (sortfn *) sort_owner },
{ "group", 8, 0, J_LEFT_FIT, N_("Group"), 1, string_file_group, (sortfn *) sort_group },
{ "mark", 1, 0, J_RIGHT, " ", 1, string_marked, NULL },
{ "|", 1, 0, J_RIGHT, " ", 0, NULL, NULL },
{ "space", 1, 0, J_RIGHT, " ", 0, string_space, NULL },
{ "dot", 1, 0, J_RIGHT, " ", 0, string_dot, NULL },
};
static char *
to_buffer (char *dest, int just_mode, int len, const char *txt)
{
int txtlen = strlen (txt);
int still, over;
/* Fill buffer with spaces */
memset (dest, ' ', len);
still = (over=(txtlen > len)) ? (txtlen - len) : (len - txtlen);
switch (HIDE_FIT(just_mode)){
case J_LEFT:
still = 0;
break;
case J_CENTER:
still /= 2;
break;
case J_RIGHT:
default:
break;
}
if (over){
if (IS_FIT(just_mode))
strcpy (dest, name_trunc(txt, len));
else
strncpy (dest, txt+still, len);
} else
strncpy (dest+still, txt, txtlen);
dest[len] = '\0';
return (dest + len);
}
static int
file_compute_color (int attr, file_entry *fe)
{
switch (attr) {
case SELECTED:
return (SELECTED_COLOR);
case MARKED:
return (MARKED_COLOR);
case MARKED_SELECTED:
return (MARKED_SELECTED_COLOR);
case STATUS:
return (NORMAL_COLOR);
case NORMAL:
default:
if (!filetype_mode)
return (NORMAL_COLOR);
}
/* if filetype_mode == true */
if (S_ISDIR (fe->st.st_mode))
return (DIRECTORY_COLOR);
else if (S_ISLNK (fe->st.st_mode)) {
if (fe->f.link_to_dir)
return (DIRECTORY_COLOR);
else if (fe->f.stale_link)
return (STALE_LINK_COLOR);
else
return (LINK_COLOR);
} else if (S_ISSOCK (fe->st.st_mode))
return (SPECIAL_COLOR);
else if (S_ISCHR (fe->st.st_mode))
return (DEVICE_COLOR);
else if (S_ISBLK (fe->st.st_mode))
return (DEVICE_COLOR);
else if (S_ISNAM (fe->st.st_mode))
return (DEVICE_COLOR);
else if (S_ISFIFO (fe->st.st_mode))
return (SPECIAL_COLOR);
else if (S_ISDOOR (fe->st.st_mode))
return (SPECIAL_COLOR);
else if (!S_ISREG (fe->st.st_mode))
return (STALE_LINK_COLOR); /* non-regular file of unknown kind */
else if (is_exe (fe->st.st_mode))
return (EXECUTABLE_COLOR);
else if (fe->fname && (!strcmp (fe->fname, "core")
|| !strcmp (extension (fe->fname), "core")))
return (CORE_COLOR);
return (NORMAL_COLOR);
}
/* Formats the file number file_index of panel in the buffer dest */
static void
format_file (char *dest, int limit, WPanel *panel, int file_index, int width, int attr, int isstatus)
{
int color, length, empty_line;
const char *txt;
char *old_pos;
char *cdest = dest;
format_e *format, *home;
file_entry *fe;
length = 0;
empty_line = (file_index >= panel->count);
home = (isstatus) ? panel->status_format : panel->format;
fe = &panel->dir.list [file_index];
if (!empty_line)
color = file_compute_color (attr, fe);
else
color = NORMAL_COLOR;
for (format = home; format; format = format->next){
if (length == width)
break;
if (format->string_fn){
int len;
if (empty_line)
txt = " ";
else
txt = (*format->string_fn)(fe, format->field_len);
old_pos = cdest;
len = format->field_len;
if (len + length > width)
len = width - length;
if (len + (cdest - dest) > limit)
len = limit - (cdest - dest);
if (len <= 0)
break;
cdest = to_buffer (cdest, format->just_mode, len, txt);
length += len;
attrset (color);
if (permission_mode && !strcmp(format->id, "perm"))
add_permission_string (old_pos, format->field_len, fe, attr, color, 0);
else if (permission_mode && !strcmp(format->id, "mode"))
add_permission_string (old_pos, format->field_len, fe, attr, color, 1);
else
addstr (old_pos);
} else {
if (attr == SELECTED || attr == MARKED_SELECTED)
attrset (SELECTED_COLOR);
else
attrset (NORMAL_COLOR);
one_vline ();
length++;
}
}
if (length < width){
int still = width - length;
while (still--)
addch (' ');
}
}
static void
repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
{
int second_column = 0;
int width, offset;
char buffer [BUF_MEDIUM];
offset = 0;
if (!isstatus && panel->split){
second_column = (file_index - panel->top_file) / llines (panel);
width = (panel->widget.cols - 2)/2 - 1;
if (second_column){
offset = 1 + width;
width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;
}
} else
width = (panel->widget.cols - 2);
/* Nothing to paint */
if (width <= 0)
return;
if (mv){
if (!isstatus && panel->split){
widget_move (&panel->widget,
(file_index - panel->top_file) %
llines (panel) + 2,
(offset + 1));
} else
widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
}
format_file (buffer, sizeof(buffer), panel, file_index, width, attr, isstatus);
if (!isstatus && panel->split){
if (second_column)
addch (' ');
else {
attrset (NORMAL_COLOR);
one_vline ();
}
}
}
static void
display_mini_info (WPanel *panel)
{
if (!show_mini_info)
return;
widget_move (&panel->widget, llines (panel)+3, 1);
if (panel->searching){
attrset (INPUT_COLOR);
printw ("/%-*s", panel->widget.cols-3, panel->search_buffer);
attrset (NORMAL_COLOR);
return;
}
/* Status displays total marked size */
if (panel->marked){
char buffer [BUF_SMALL];
const char *p = " %-*s";
int cols = panel->widget.cols-2;
attrset (MARKED_COLOR);
printw ("%*s", cols, " ");
widget_move (&panel->widget, llines (panel)+3, 1);
/* FIXME: use ngettext() here when gettext-0.10.35 becomes history */
g_snprintf (buffer, sizeof (buffer), (panel->marked == 1) ?
_("%s bytes in %d file") : _("%s bytes in %d files"),
size_trunc_sep (panel->total), panel->marked);
if ((int) strlen (buffer) > cols-2){
buffer [cols] = 0;
p += 2;
} else
cols -= 2;
printw ((char *) p, cols, buffer);
return;
}
/* Status resolves links and show them */
set_colors (panel);
if (S_ISLNK (panel->dir.list [panel->selected].st.st_mode)){
char *link, link_target [MC_MAXPATHLEN];
int len;
link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1);
g_free (link);
if (len > 0){
link_target[len] = 0;
printw ("-> %-*s", panel->widget.cols - 5,
name_trunc (link_target, panel->widget.cols - 5));
} else
printw ("%-*s", panel->widget.cols - 2, _("<readlink failed>"));
return;
}
/* Default behavior */
repaint_file (panel, panel->selected, 0, STATUS, 1);
return;
}
static void
paint_dir (WPanel *panel)
{
int i;
int color; /* Color value of the line */
int items; /* Number of items */
items = llines (panel) * (panel->split ? 2 : 1);
for (i = 0; i < items; i++){
if (i+panel->top_file >= panel->count)
color = 0;
else {
color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
color += (panel->selected==i+panel->top_file && panel->active);
}
repaint_file (panel, i+panel->top_file, 1, color, 0);
}
standend ();
}
static void
mini_info_separator (WPanel *panel)
{
if (!show_mini_info)
return;
standend ();
widget_move (&panel->widget, llines (panel) + 2, 1);
#ifdef HAVE_SLANG
attrset (NORMAL_COLOR);
hline (ACS_HLINE, panel->widget.cols - 2);
#else
hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
panel->widget.cols - 2);
#endif /* !HAVE_SLANG */
}
static void
show_dir (WPanel *panel)
{
char *tmp;
set_colors (panel);
draw_double_box (panel->widget.parent,
panel->widget.y, panel->widget.x,
panel->widget.lines, panel->widget.cols);
#ifdef HAVE_SLANG
if (show_mini_info) {
SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
panel->widget.x, SLSMG_LTEE_CHAR);
SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
panel->widget.x + panel->widget.cols - 1,
SLSMG_RTEE_CHAR);
}
#endif /* HAVE_SLANG */
if (panel->active)
attrset (REVERSE_COLOR);
widget_move (&panel->widget, 0, 3);
tmp = g_malloc (panel->widget.cols + 1);
tmp[panel->widget.cols] = '\0';
trim (strip_home_and_password (panel->cwd), tmp,
min (max (panel->widget.cols - 7, 0), panel->widget.cols) );
addstr (tmp);
g_free (tmp);
widget_move (&panel->widget, 0, 1);
addstr ("<");
widget_move (&panel->widget, 0, panel->widget.cols - 2);
addstr (">");
widget_move (&panel->widget, 0, panel->widget.cols - 3);
addstr ("v");
if (panel->active)
standend ();
}
/* To be used only by long_frame and full_frame to adjust top_file */
static void
adjust_top_file (WPanel *panel)
{
int old_top = panel->top_file;
if (panel->selected - old_top > llines (panel))
panel->top_file = panel->selected;
if (old_top - panel->count > llines (panel))
panel->top_file = panel->count - llines (panel);
}
/*
* Repaint everything that can change on the panel - title, entries and
* mini status. The rest of the frame and the mini status separator are
* not repainted.
*/
static void
panel_update_contents (WPanel *panel)
{
show_dir (panel);
paint_dir (panel);
display_mini_info (panel);
panel->dirty = 0;
}
/* Repaint everything, including frame and separator */
static void
paint_panel (WPanel *panel)
{
paint_frame (panel);
panel_update_contents (panel);
mini_info_separator (panel);
}
/*
* Repaint the contents of the panels without frames. To schedule panel
* for repainting, set panel->dirty to 1. There are many reasons why
* the panels need to be repainted, and this is a costly operation, so
* it's done once per event.
*/
void
update_dirty_panels (void)
{
if (current_panel->dirty)
panel_update_contents (current_panel);
if ((get_other_type () == view_listing) && other_panel->dirty)
panel_update_contents (other_panel);
}
static void
do_select (WPanel *panel, int i)
{
if (i != panel->selected) {
panel->dirty = 1;
panel->selected = i;
panel->top_file = panel->selected - (panel->widget.lines - 2) / 2;
if (panel->top_file < 0)
panel->top_file = 0;
}
}
static inline void
do_try_to_select (WPanel *panel, const char *name)
{
int i;
char *subdir;
if (!name) {
do_select(panel, 0);
return;
}
/* We only want the last component of the directory,
* and from this only the name without suffix. */
subdir = vfs_strip_suffix_from_filename (x_basename(name));
/* Search that subdirectory, if found select it */
for (i = 0; i < panel->count; i++){
if (strcmp (subdir, panel->dir.list [i].fname) == 0) {
do_select (panel, i);
g_free (subdir);
return;
}
}
/* Try to select a file near the file that is missing */
if (panel->selected >= panel->count)
do_select (panel, panel->count-1);
g_free (subdir);
}
void
try_to_select (WPanel *panel, const char *name)
{
do_try_to_select (panel, name);
select_item (panel);
}
void
panel_update_cols (Widget *widget, int frame_size)
{
int cols, origin;
if (horizontal_split){
widget->cols = COLS;
return;
}
if (frame_size == frame_full){
cols = COLS;
origin = 0;
} else {
if (widget == get_panel_widget (0)){
cols = first_panel_size;
origin = 0;
} else {
cols = COLS-first_panel_size;
origin = first_panel_size;
}
}
widget->cols = cols;
widget->x = origin;
}
static char *
panel_save_name (WPanel *panel)
{
extern int saving_setup;
/* If the program is shuting down */
if ((midnight_shutdown && auto_save_setup) || saving_setup)
return g_strdup (panel->panel_name);
else
return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL);
}
static void
panel_destroy (WPanel *p)
{
int i;
char *name = panel_save_name (p);
panel_save_setup (p, name);
panel_clean_dir (p);
/* save and clean history */
if (p->dir_history) {
history_put (p->hist_name, p->dir_history);
p->dir_history = g_list_first (p->dir_history);
g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
g_list_free (p->dir_history);
}
g_free (p->hist_name);
delete_format (p->format);
delete_format (p->status_format);
g_free (p->user_format);
for (i = 0; i < LIST_TYPES; i++)
g_free (p->user_status_format[i]);
g_free (p->dir.list);
g_free (p->panel_name);
g_free (name);
}
static void
panel_format_modified (WPanel *panel)
{
panel->format_modified = 1;
}
/* Panel creation */
/* The parameter specifies the name of the panel for setup retieving */
WPanel *
panel_new (const char *panel_name)
{
WPanel *panel;
char *section;
int i, err;
panel = g_new0 (WPanel, 1);
/* No know sizes of the panel at startup */
init_widget (&panel->widget, 0, 0, 0, 0, panel_callback, panel_event);
/* We do not want the cursor */
widget_want_cursor (panel->widget, 0);
mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
strcpy (panel->lwd, ".");
panel->hist_name = g_strconcat ("Dir Hist ", panel_name, (char *) NULL);
panel->dir_history = history_get (panel->hist_name);
directory_history_add (panel, panel->cwd);