5
* $Date: 2004/08/31 01:41:29 $
6
* $Date: 2006/05/07 00:22:25 $
10
11
* Declare file local prototypes.
12
static BINDFN_PROTO(completeFilenameCB);
13
static BINDFN_PROTO(displayFileInfoCB);
14
static BINDFN_PROTO(fselectAdjustScrollCB);
15
static char *errorMessage(char *format);
13
static BINDFN_PROTO (completeFilenameCB);
14
static BINDFN_PROTO (displayFileInfoCB);
15
static BINDFN_PROTO (fselectAdjustScrollCB);
16
static char *contentToPath (CDKFSELECT *fselect, char *content);
17
static char *errorMessage (char *format);
16
18
static char *expandTilde (char *filename);
17
19
static char *format1Date (char *format, time_t value);
18
static char *format1Number(char *format, long value);
19
static char *format1String(char *format, char *string);
20
static char *format3String(char *format, char *s1, char *s2, char *s3);
21
static char *format1StrVal(char *format, char *string, int value);
20
static char *format1Number (char *format, long value);
21
static char *format1String (char *format, char *string);
22
static char *format3String (char *format, char *s1, char *s2, char *s3);
23
static char *format1StrVal (char *format, char *string, int value);
22
24
static char *trim1Char (char *source);
25
static int createList (CDKFSELECT *widget, char **list, int listSize);
23
26
static void setPWD (CDKFSELECT *fselect);
25
DeclareSetXXchar(static, _setMy);
26
DeclareCDKObjects(FSELECT, Fselect, _setMy, String);
28
DeclareSetXXchar (static, _setMy);
29
DeclareCDKObjects (FSELECT, Fselect, _setMy, String);
29
32
* This creates a file selection widget.
31
CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, chtype fieldAttribute, chtype fillerChar, chtype highlight, char *dAttribute, char *fAttribute, char *lAttribute, char *sAttribute, boolean Box, boolean shadow)
34
CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen,
41
chtype fieldAttribute,
33
51
CDKFSELECT *fselect = 0;
34
int parentWidth = getmaxx(cdkscreen->window);
35
int parentHeight = getmaxy(cdkscreen->window);
52
int parentWidth = getmaxx (cdkscreen->window);
53
int parentHeight = getmaxy (cdkscreen->window);
36
54
int boxWidth = width;
37
55
int boxHeight = height;
43
61
chtype *chtypeString;
46
static const struct { int from; int to; } bindings[] = {
47
{ CDK_BACKCHAR, KEY_PPAGE },
48
{ CDK_FORCHAR, KEY_NPAGE },
70
{ CDK_BACKCHAR, KEY_PPAGE },
71
{ CDK_FORCHAR, KEY_NPAGE },
51
if ((fselect = newCDKObject(CDKFSELECT, &my_funcs)) == 0)
74
if ((fselect = newCDKObject (CDKFSELECT, &my_funcs)) == 0)
54
77
setCDKFselectBox (fselect, Box);
57
* If the height is a negative value, the height will
58
* be ROWS-height, otherwise, the height will be the
80
* If the height is a negative value, the height will
81
* be ROWS-height, otherwise, the height will be the
61
84
boxHeight = setWidgetDimension (parentHeight, height, 0);
64
* If the width is a negative value, the width will
65
* be COLS-width, otherwise, the width will be the
87
* If the width is a negative value, the width will
88
* be COLS-width, otherwise, the width will be the
68
91
boxWidth = setWidgetDimension (parentWidth, width, 0);
70
93
/* Rejustify the x and y positions if we need to. */
80
103
/* Is the window null? */
81
104
if (fselect->win == 0)
83
destroyCDKObject(fselect);
106
destroyCDKObject (fselect);
86
109
keypad (fselect->win, TRUE);
88
111
/* Set some variables. */
89
ScreenOf(fselect) = cdkscreen;
112
ScreenOf (fselect) = cdkscreen;
90
113
fselect->parent = cdkscreen->window;
91
114
fselect->dirAttribute = copyChar (dAttribute);
92
115
fselect->fileAttribute = copyChar (fAttribute);
99
122
fselect->boxWidth = boxWidth;
100
123
fselect->fileCounter = 0;
101
124
fselect->pwd = 0;
102
initExitType(fselect);
103
ObjOf(fselect)->inputWindow = fselect->win;
125
initExitType (fselect);
126
ObjOf (fselect)->inputWindow = fselect->win;
104
127
fselect->shadow = shadow;
105
128
fselect->shadowWin = 0;
107
130
/* Get the present working directory. */
110
133
/* Get the contents of the current directory. */
111
134
setCDKFselectDirContents (fselect);
113
136
/* Create the entry field in the selector. */
114
137
chtypeString = char2Chtype (label, &labelLen, &junk);
115
138
freeChtype (chtypeString);
116
tempWidth = (isFullWidth(width)
118
: boxWidth - 2 - labelLen);
139
tempWidth = (isFullWidth (width)
141
: boxWidth - 2 - labelLen);
119
142
fselect->entryField = newCDKEntry (cdkscreen,
120
getbegx(fselect->win),
121
getbegy(fselect->win),
123
fieldAttribute, fillerChar,
124
vMIXED, tempWidth, 0, 512,
143
getbegx (fselect->win),
144
getbegy (fselect->win),
146
fieldAttribute, fillerChar,
147
vMIXED, tempWidth, 0, 512,
127
150
/* Make sure the widget was created. */
128
151
if (fselect->entryField == 0)
130
destroyCDKObject(fselect);
153
destroyCDKObject (fselect);
141
164
bindCDKObject (vENTRY, fselect->entryField, KEY_DOWN, fselectAdjustScrollCB, fselect);
142
165
bindCDKObject (vENTRY, fselect->entryField, KEY_NPAGE, fselectAdjustScrollCB, fselect);
143
166
bindCDKObject (vENTRY, fselect->entryField, KEY_TAB, completeFilenameCB, fselect);
144
bindCDKObject (vENTRY, fselect->entryField, CTRL('^'), displayFileInfoCB, fselect);
167
bindCDKObject (vENTRY, fselect->entryField, CTRL ('^'), displayFileInfoCB, fselect);
146
169
/* Put the current working directory in the entry field. */
147
170
setCDKEntryValue (fselect->entryField, fselect->pwd);
149
172
/* Create the scrolling list in the selector. */
150
tempHeight = getmaxy(fselect->entryField->win) - BorderOf(fselect);
151
tempWidth = (isFullWidth(width)
173
tempHeight = getmaxy (fselect->entryField->win) - BorderOf (fselect);
174
tempWidth = (isFullWidth (width)
154
177
fselect->scrollField = newCDKScroll (cdkscreen,
155
getbegx(fselect->win),
156
getbegy(fselect->win) + tempHeight,
178
getbegx (fselect->win),
179
getbegy (fselect->win) + tempHeight,
158
boxHeight - tempHeight,
181
boxHeight - tempHeight,
161
184
fselect->dirContents,
176
199
/* Setup the key bindings. */
177
for (x = 0; x < (int) SIZEOF(bindings); ++x)
200
for (x = 0; x < (int) SIZEOF (bindings); ++x)
178
201
bindCDKObject (vFSELECT, fselect, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to);
180
/* Register this baby. */
181
203
registerCDKObject (cdkscreen, vFSELECT, fselect);
183
/* Return the file selector pointer. */
184
205
return (fselect);
203
224
* This moves the fselect field to the given location.
205
static void _moveCDKFselect (CDKOBJS *object, int xplace, int yplace, boolean relative, boolean refresh_flag)
226
static void _moveCDKFselect (CDKOBJS *object,
230
boolean refresh_flag)
207
232
CDKFSELECT *fselect = (CDKFSELECT *)object;
208
int currentX = getbegx(fselect->win);
209
int currentY = getbegy(fselect->win);
233
int currentX = getbegx (fselect->win);
234
int currentY = getbegy (fselect->win);
210
235
int xpos = xplace;
211
236
int ypos = yplace;
221
xpos = getbegx(fselect->win) + xplace;
222
ypos = getbegy(fselect->win) + yplace;
246
xpos = getbegx (fselect->win) + xplace;
247
ypos = getbegy (fselect->win) + yplace;
225
250
/* Adjust the window if we need to. */
226
alignxy (WindowOf(fselect), &xpos, &ypos, fselect->boxWidth, fselect->boxHeight);
251
alignxy (WindowOf (fselect), &xpos, &ypos, fselect->boxWidth, fselect->boxHeight);
228
253
/* Get the difference. */
229
254
xdiff = currentX - xpos;
230
255
ydiff = currentY - ypos;
232
257
/* Move the window to the new location. */
233
moveCursesWindow(fselect->win, -xdiff, -ydiff);
234
moveCursesWindow(fselect->shadowWin, -xdiff, -ydiff);
258
moveCursesWindow (fselect->win, -xdiff, -ydiff);
259
moveCursesWindow (fselect->shadowWin, -xdiff, -ydiff);
236
261
/* Move the sub-widgets. */
237
262
moveCDKEntry (fselect->entryField, xplace, yplace, relative, FALSE);
238
263
moveCDKScroll (fselect->scrollField, xplace, yplace, relative, FALSE);
239
touchwin (fselect->entryField->win);
240
touchwin (fselect->scrollField->win);
242
265
/* Redraw the window, if they asked for it. */
243
266
if (refresh_flag)
245
drawCDKFselect (fselect, ObjOf(fselect)->box);
268
drawCDKFselect (fselect, ObjOf (fselect)->box);
273
* The fselect's focus resides in the entry widget. But the scroll widget
274
* will not draw items highlighted unless it has focus. Temporarily adjust the
275
* focus of the scroll widget when drawing on it to get the right highlighting.
277
#define SaveFocus(widget) \
278
boolean save = HasFocusObj (ObjOf (widget->scrollField)); \
279
HasFocusObj (ObjOf (widget->scrollField)) = \
280
HasFocusObj (ObjOf (widget->entryField))
282
#define RestoreFocus(widget) \
283
HasFocusObj (ObjOf (widget->scrollField)) = save
285
static void drawMyScroller (CDKFSELECT *widget)
288
drawCDKScroll (widget->scrollField, ObjOf (widget->scrollField)->box);
289
RestoreFocus (widget);
292
static void injectMyScroller (CDKFSELECT *widget, chtype key)
295
injectCDKScroll (widget->scrollField, key);
296
RestoreFocus (widget);
250
300
* This draws the file selector widget.
252
302
static void _drawCDKFselect (CDKOBJS *object, boolean Box GCC_UNUSED)
274
324
char *activateCDKFselect (CDKFSELECT *fselect, chtype *actions)
276
326
chtype input = 0;
279
330
/* Draw the widget. */
280
drawCDKFselect (fselect, ObjOf(fselect)->box);
331
drawCDKFselect (fselect, ObjOf (fselect)->box);
282
/* Check if 'actions' is null. */
283
333
if (actions == 0)
288
input = getcCDKObject (ObjOf(fselect->entryField));
337
input = getchCDKObject (ObjOf (fselect->entryField), &functionKey);
290
339
/* Inject the character into the widget. */
291
340
ret = injectCDKFselect (fselect, input);
331
380
filename = injectCDKEntry (fselect->entryField, input);
333
382
/* Copy the entry field exitType to the fileselector. */
334
copyExitType(fselect, fselect->entryField);
383
copyExitType (fselect, fselect->entryField);
336
385
/* If we exited early, make sure we don't interpret it as a file. */
337
386
if (fselect->exitType == vEARLY_EXIT)
358
407
/* Set the file selector information. */
359
408
setCDKFselect (fselect, filename,
360
fselect->fieldAttribute, fselect->fillerCharacter,
362
fselect->dirAttribute, fselect->fileAttribute,
363
fselect->linkAttribute, fselect->sockAttribute,
364
ObjOf(fselect)->box);
409
fselect->fieldAttribute, fselect->fillerCharacter,
411
fselect->dirAttribute, fselect->fileAttribute,
412
fselect->linkAttribute, fselect->sockAttribute,
413
ObjOf (fselect)->box);
366
415
/* Redraw the scrolling list. */
367
drawCDKScroll (fselect->scrollField, ObjOf(fselect->scrollField)->box);
371
setExitType(fselect, 0);
374
ResultOf(fselect).valueString = ret;
416
drawMyScroller (fselect);
420
setExitType (fselect, 0);
422
ResultOf (fselect).valueString = ret;
375
423
return (ret != unknownString);
379
427
* This function sets the information inside the file selector.
381
void setCDKFselect (CDKFSELECT *fselect, char *directory, chtype fieldAttrib, chtype filler, chtype highlight, char *dirAttribute, char *fileAttribute, char *linkAttribute, char *sockAttribute, boolean Box GCC_UNUSED)
429
void setCDKFselect (CDKFSELECT *fselect,
438
boolean Box GCC_UNUSED)
383
440
CDKSCROLL *fscroll = fselect->scrollField;
384
441
CDKENTRY *fentry = fselect->entryField;
408
newDirectory = copyChar(directory);
465
newDirectory = copyChar (directory);
411
468
/* Change directories. */
412
469
if (chdir (newDirectory) != 0)
416
473
/* Could not get into the directory, pop up a little message. */
417
mesg[0] = format1String("<C>Could not change into %s", newDirectory);
418
mesg[1] = errorMessage("<C></U>%s");
419
mesg[2] = copyChar(" ");
420
mesg[3] = copyChar("<C>Press Any Key To Continue.");
474
mesg[0] = format1String ("<C>Could not change into %s", newDirectory);
475
mesg[1] = errorMessage ("<C></U>%s");
476
mesg[2] = copyChar (" ");
477
mesg[3] = copyChar ("<C>Press Any Key To Continue.");
422
479
/* Pop Up a message. */
423
popupLabel (ScreenOf(fselect), mesg, 4);
480
popupLabel (ScreenOf (fselect), mesg, 4);
425
482
/* Clean up some memory. */
426
483
freeCharList (mesg, 4);
428
485
/* Get out of here. */
429
486
eraseCDKFselect (fselect);
430
drawCDKFselect (fselect, ObjOf(fselect)->box);
487
drawCDKFselect (fselect, ObjOf (fselect)->box);
431
488
freeChar (newDirectory);
470
527
/* Set the contents of the entry field. */
471
528
setCDKEntryValue (fentry, fselect->pwd);
472
drawCDKEntry (fentry, ObjOf(fentry)->box);
529
drawCDKEntry (fentry, ObjOf (fentry)->box);
474
531
/* Get the directory contents. */
475
532
if (setCDKFselectDirContents (fselect) == 0)
481
538
/* Set the values in the scrolling list. */
482
539
setCDKScrollItems (fscroll,
483
fselect->dirContents,
484
fselect->fileCounter,
540
fselect->dirContents,
541
fselect->fileCounter,
521
580
if (((fileStat.st_mode & S_IXUSR) != 0) ||
522
((fileStat.st_mode & S_IXGRP) != 0) ||
523
((fileStat.st_mode & S_IXOTH) != 0))
581
((fileStat.st_mode & S_IXGRP) != 0) ||
582
((fileStat.st_mode & S_IXOTH) != 0))
529
switch (mode2Filetype(fileStat.st_mode)) {
588
switch (mode2Filetype (fileStat.st_mode))
531
591
attr = fselect->linkAttribute;
644
706
/* Make sure they are not the same. */
645
707
if (fselect->dirAttribute != attribute)
647
/* Clean out the old attribute, and set the new. */
648
709
freeChar (fselect->dirAttribute);
649
710
fselect->dirAttribute = copyChar (attribute);
652
* We need to reset the contents of the scrolling
653
* list using the new attribute.
655
712
setCDKFselectDirContents (fselect);
669
726
/* Make sure they are not the same. */
670
727
if (fselect->linkAttribute != attribute)
672
/* Clean out the old attribute, and set the new. */
673
729
freeChar (fselect->linkAttribute);
674
730
fselect->linkAttribute = copyChar (attribute);
677
* We need to reset the contents of the scrolling
678
* list using the new attribute.
680
732
setCDKFselectDirContents (fselect);
694
746
/* Make sure they are not the same. */
695
747
if (fselect->sockAttribute != attribute)
697
/* Clean out the old attribute, and set the new. */
698
749
freeChar (fselect->sockAttribute);
699
750
fselect->sockAttribute = copyChar (attribute);
702
* We need to reset the contents of the scrolling
703
* list using the new attribute.
705
752
setCDKFselectDirContents (fselect);
719
766
/* Make sure they are not the same. */
720
767
if (fselect->fileAttribute != attribute)
722
/* Clean out the old attribute, and set the new. */
723
769
freeChar (fselect->fileAttribute);
724
770
fselect->fileAttribute = copyChar (attribute);
727
* We need to reset the contents of the scrolling
728
* list using the new attribute.
730
772
setCDKFselectDirContents (fselect);
741
783
void setCDKFselectBox (CDKFSELECT *fselect, boolean Box)
743
ObjOf(fselect)->box = Box;
744
ObjOf(fselect)->borderSize = Box ? 1 : 0;
785
ObjOf (fselect)->box = Box;
786
ObjOf (fselect)->borderSize = Box ? 1 : 0;
746
788
boolean getCDKFselectBox (CDKFSELECT *fselect)
748
return ObjOf(fselect)->box;
790
return ObjOf (fselect)->box;
794
* This sets the contents of the widget
796
void setCDKFselectContents (CDKFSELECT *widget,
800
CDKSCROLL *scrollp = widget->scrollField;
801
CDKENTRY *entry = widget->entryField;
803
if (!createList (widget, list, listSize))
806
/* Set the information in the scrolling list. */
807
setCDKScroll (scrollp,
812
ObjOf (scrollp)->box);
814
/* Clean out the entry field. */
815
setCDKFselectCurrentItem (widget, 0);
816
cleanCDKEntry (entry);
818
/* Redraw the widget. */
819
eraseCDKFselect (widget);
820
drawCDKFselect (widget, ObjOf (widget)->box);
823
char **getCDKFselectContents (CDKFSELECT *widget,
826
(*size) = widget->fileCounter;
827
return widget->dirContents;
831
* Get/set the current position in the scroll-widget.
833
int getCDKFselectCurrentItem (CDKFSELECT *widget)
835
return getCDKScrollCurrent (widget->scrollField);
838
void setCDKFselectCurrentItem (CDKFSELECT *widget,
841
if (widget->fileCounter != 0)
845
setCDKScrollCurrent (widget->scrollField, item);
847
data = contentToPath (widget,
848
widget->dirContents[getCDKScrollCurrentItem (widget->scrollField)]);
849
setCDKEntryValue (widget->entryField, data);
754
858
static void _setMyULchar (CDKOBJS *object, chtype character)
756
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
860
CDKFSELECT *fselect = (CDKFSELECT *)object;
758
862
setCDKEntryULChar (fselect->entryField, character);
760
864
static void _setMyURchar (CDKOBJS *object, chtype character)
762
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
866
CDKFSELECT *fselect = (CDKFSELECT *)object;
764
868
setCDKEntryURChar (fselect->entryField, character);
766
870
static void _setMyLLchar (CDKOBJS *object, chtype character)
768
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
872
CDKFSELECT *fselect = (CDKFSELECT *)object;
770
874
setCDKScrollLLChar (fselect->scrollField, character);
772
876
static void _setMyLRchar (CDKOBJS *object, chtype character)
774
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
878
CDKFSELECT *fselect = (CDKFSELECT *)object;
776
880
setCDKScrollLRChar (fselect->scrollField, character);
778
882
static void _setMyVTchar (CDKOBJS *object, chtype character)
780
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
884
CDKFSELECT *fselect = (CDKFSELECT *)object;
782
886
setCDKEntryVerticalChar (fselect->entryField, character);
783
887
setCDKScrollVerticalChar (fselect->scrollField, character);
785
889
static void _setMyHZchar (CDKOBJS *object, chtype character)
787
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
891
CDKFSELECT *fselect = (CDKFSELECT *)object;
789
893
setCDKEntryHorizontalChar (fselect->entryField, character);
790
894
setCDKScrollHorizontalChar (fselect->scrollField, character);
792
896
static void _setMyBXattr (CDKOBJS *object, chtype character)
794
CDKALPHALIST *fselect = (CDKALPHALIST *)object;
898
CDKFSELECT *fselect = (CDKFSELECT *)object;
796
900
setCDKEntryBoxAttribute (fselect->entryField, character);
797
901
setCDKScrollBoxAttribute (fselect->scrollField, character);
852
959
* This is a callback to the scrolling list which displays information
853
960
* about the current file. (and the whole directory as well)
855
static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED)
962
static int displayFileInfoCB (EObjectType objectType GCC_UNUSED,
965
chtype key GCC_UNUSED)
857
967
CDKENTRY *entry = (CDKENTRY *)object;
858
968
CDKFSELECT *fselect = (CDKFSELECT *)clientData;
866
976
char stringMode[15];
869
980
/* Get the file name. */
870
filename = fselect->entryField->info;
981
filename = fselect->entryField->info;
872
983
/* Get specific information about the files. */
873
984
lstat (filename, &fileStat);
875
986
/* Determine the file type. */
876
switch (mode2Filetype(fileStat.st_mode)) {
987
switch (mode2Filetype (fileStat.st_mode))
878
990
filetype = "Symbolic Link";
926
1038
drawCDKLabel (infoLabel, TRUE);
927
getcCDKObject (ObjOf(infoLabel));
1039
getchCDKObject (ObjOf (infoLabel), &functionKey);
929
1041
/* Clean up some memory. */
930
1042
destroyCDKLabel (infoLabel);
931
1043
freeCharList (mesg, 9);
933
1045
/* Redraw the file selector. */
934
drawCDKFselect (fselect, ObjOf(fselect)->box);
1046
drawCDKFselect (fselect, ObjOf (fselect)->box);
938
static char *make_pathname(char *directory, char *filename)
1050
static char *make_pathname (char *directory, char *filename)
940
unsigned need = strlen(filename) + 2;
1052
unsigned need = strlen (filename) + 2;
941
1053
bool root = (strcmp (directory, "/") == 0);
945
need += strlen(directory);
946
if ((result = (char *)malloc(need)) != 0)
1057
need += strlen (directory);
1058
if ((result = (char *)malloc (need)) != 0)
949
1061
sprintf (result, "/%s", filename);
1069
* Return the plain string that corresponds to an item in dirContents[].
1071
static char *contentToPath (CDKFSELECT *fselect, char *content)
1078
tempChtype = char2Chtype (content, &j, &j2);
1079
tempChar = chtype2Char (tempChtype);
1080
trim1Char (tempChar); /* trim the 'mode' stored on the end */
1082
/* Create the pathname. */
1083
result = make_pathname (fselect->pwd, tempChar);
1086
freeChtype (tempChtype);
1087
freeChar (tempChar);
957
1092
* This tries to complete the filename.
959
static int completeFilenameCB (EObjectType objectType GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key GCC_UNUSED)
1094
static int completeFilenameCB (EObjectType objectType GCC_UNUSED,
1095
void *object GCC_UNUSED,
1097
chtype key GCC_UNUSED)
961
1099
CDKFSELECT *fselect = (CDKFSELECT *)clientData;
962
CDKSCROLL *scrollp = (CDKSCROLL *)fselect->scrollField;
963
CDKENTRY *entry = (CDKENTRY *)fselect->entryField;
1100
CDKSCROLL *scrollp = fselect->scrollField;
1101
CDKENTRY *entry = fselect->entryField;
964
1102
char *filename = copyChar (entry->info);
965
1103
char *mydirname = dirName (filename);
966
1104
char *newFilename = 0;
967
chtype *tempChtype = 0;
969
1105
unsigned filenameLen = 0;
970
1106
int currentIndex = 0;
971
1107
int matches = 0;
973
1109
int secondaryMatches = 0;
974
1110
int isDirectory;
977
int Index, pos, j, j2, x;
978
1113
int difference, absoluteDifference;
980
1115
/* Make sure the filename is not null/empty. */
982
|| (filenameLen = strlen(filename)) == 0)
1116
if (filename == 0 ||
1117
(filenameLen = strlen (filename)) == 0)
1120
freeChar (filename);
1008
1143
fselect->fileAttribute,
1009
1144
fselect->linkAttribute,
1010
1145
fselect->sockAttribute,
1011
ObjOf(fselect)->box);
1146
ObjOf (fselect)->box);
1012
1147
freeChar (mydirname);
1014
1149
/* If we can, change into the directory. */
1015
1150
if (isDirectory)
1018
* Set the entry field with the filename so the current
1019
* filename selection shows up.
1153
* Set the entry field with the filename so the current
1154
* filename selection shows up.
1021
1156
setCDKEntryValue (entry, filename);
1022
drawCDKEntry (entry, ObjOf(entry)->box);
1157
drawCDKEntry (entry, ObjOf (entry)->box);
1025
1160
/* Create the file list. */
1026
if ((list = typeMallocN(char *, fselect->fileCounter)) != 0)
1161
if ((list = typeMallocN (char *, fselect->fileCounter)) != 0)
1028
for (x=0; x < fselect->fileCounter; x++)
1163
for (x = 0; x < fselect->fileCounter; x++)
1030
/* We need to remove the special characters from the filenames. */
1031
tempChtype = char2Chtype (fselect->dirContents[x], &j, &j2);
1032
tempChar = chtype2Char (tempChtype);
1034
/* Create the pathname. */
1035
list[x] = make_pathname(fselect->pwd, tempChar);
1038
freeChtype (tempChtype);
1039
freeChar (tempChar);
1165
list[x] = contentToPath (fselect, fselect->dirContents[x]);
1042
1168
/* Look for a unique filename match. */
1045
1171
/* If the index is less than zero, return we didn't find a match. */
1052
/* Create the filename of the found file. */
1053
temp = copyChar(list[Index]);
1054
temp[strlen(temp)-1] = '\0'; /* setCDKFselectDirContents 'mode' */
1056
1178
/* Move to the current item in the scrolling list. */
1057
1179
difference = Index - scrollp->currentItem;
1058
1180
absoluteDifference = abs (difference);
1059
1181
if (difference < 0)
1061
for (x=0; x < absoluteDifference; x++)
1183
for (x = 0; x < absoluteDifference; x++)
1063
injectCDKScroll (scrollp, KEY_UP);
1185
injectMyScroller (fselect, KEY_UP);
1066
1188
else if (difference > 0)
1068
for (x=0; x < absoluteDifference; x++)
1190
for (x = 0; x < absoluteDifference; x++)
1070
injectCDKScroll (scrollp, KEY_DOWN);
1192
injectMyScroller (fselect, KEY_DOWN);
1073
drawCDKScroll (scrollp, ObjOf(scrollp)->box);
1195
drawMyScroller (fselect);
1075
1197
/* Ok, we found a match, is the next item similar? */
1076
1198
if (Index+1 < fselect->fileCounter &&
1123
1245
/* Set the entry field with the found item. */
1124
setCDKEntryValue (entry, temp);
1125
drawCDKEntry (entry, ObjOf(entry)->box);
1246
setCDKEntryValue (entry, list[Index]);
1247
drawCDKEntry (entry, ObjOf (entry)->box);
1129
1250
freeCharList (list, fselect->fileCounter);
1147
1268
/* Get the filename which is to be deleted. */
1148
1269
filename = chtype2Char (fscroll->item[fscroll->currentItem]);
1149
trim1Char(filename);
1270
trim1Char (filename);
1151
1272
/* Create the dialog message. */
1152
mesg[0] = copyChar("<C>Are you sure you want to delete the file:");
1153
mesg[1] = format1String("<C></U>%s?", filename);
1273
mesg[0] = copyChar ("<C>Are you sure you want to delete the file:");
1274
mesg[1] = format1String ("<C></U>\"%s\"?", filename);
1155
1276
/* Create the dialog box. */
1156
question = newCDKDialog (ScreenOf(fselect), CENTER, CENTER,
1157
mesg, 2, buttons, 2, A_REVERSE,
1277
question = newCDKDialog (ScreenOf (fselect), CENTER, CENTER,
1278
mesg, 2, buttons, 2, A_REVERSE,
1159
1280
freeCharList (mesg, 2);
1161
1282
/* If the said yes then try to nuke it. */
1167
1288
/* Set the file selector information. */
1168
1289
setCDKFselect (fselect, fselect->pwd,
1169
fselect->fieldAttribute, fselect->fillerCharacter, fselect->highlight,
1170
fselect->dirAttribute, fselect->fileAttribute,
1171
fselect->linkAttribute, fselect->sockAttribute,
1172
ObjOf(fselect)->box);
1290
fselect->fieldAttribute,
1291
fselect->fillerCharacter,
1293
fselect->dirAttribute,
1294
fselect->fileAttribute,
1295
fselect->linkAttribute,
1296
fselect->sockAttribute,
1297
ObjOf (fselect)->box);
1176
1301
/* Pop up a message. */
1177
mesg[0] = copyChar(errorMessage ("<C>Cannot delete file: %s"));
1178
mesg[1] = copyChar(" ");
1179
mesg[2] = copyChar("<C>Press any key to continue.");
1180
popupLabel (ScreenOf(fselect), mesg, 3);
1302
mesg[0] = copyChar (errorMessage ("<C>Cannot delete file: %s"));
1303
mesg[1] = copyChar (" ");
1304
mesg[2] = copyChar ("<C>Press any key to continue.");
1305
popupLabel (ScreenOf (fselect), mesg, 3);
1181
1306
freeCharList (mesg, 3);
1221
/* Move the scrolling list. */
1222
injectCDKScroll (fselect->scrollField, key);
1224
/* Get the currently highlighted filename. */
1225
current = chtype2Char (scrollp->item[scrollp->currentItem]);
1228
temp = make_pathname(fselect->pwd, current);
1230
/* Set the value in the entry field. */
1231
setCDKEntryValue (entry, temp);
1232
drawCDKEntry (entry, ObjOf(entry)->box);
1349
if (scrollp->listSize > 0)
1351
/* Move the scrolling list. */
1352
injectMyScroller (fselect, key);
1354
/* Get the currently highlighted filename. */
1355
current = chtype2Char (scrollp->item[scrollp->currentItem]);
1356
trim1Char (current);
1358
temp = make_pathname (fselect->pwd, current);
1360
/* Set the value in the entry field. */
1361
setCDKEntryValue (entry, temp);
1362
drawCDKEntry (entry, ObjOf (entry)->box);
1373
* trim the 'mode' from a copy of a dirContents[] entry.
1239
1375
static char *trim1Char (char *source)
1243
if ((len = strlen(source)) != 0)
1379
if ((len = strlen (source)) != 0)
1244
1380
source[--len] = '\0';
1251
1387
char *temp = ctime (&value);
1253
if ((result = (char *)malloc(strlen(format) + strlen(temp))) != 0)
1389
if ((result = (char *)malloc (strlen (format) + strlen (temp))) != 0)
1255
sprintf (result, format, trim1Char(temp));
1391
sprintf (result, format, trim1Char (temp));
1260
static char *format1Number(char *format, long value)
1264
if ((result = (char *)malloc(strlen(format) + 20)) != 0)
1265
sprintf(result, format, value);
1269
static char *format3String(char *format, char *s1, char *s2, char *s3)
1273
if ((result = (char *)malloc(strlen(format) + strlen(s1) + strlen(s2) + strlen(s3))) != 0)
1274
sprintf(result, format, s1, s2, s3);
1278
static char *format1String(char *format, char *string)
1282
if ((result = (char *)malloc(strlen(format) + strlen(string))) != 0)
1283
sprintf(result, format, string);
1287
static char *format1StrVal(char *format, char *string, int value)
1291
if ((result = (char *)malloc(strlen(format) + strlen(string) + 20)) != 0)
1292
sprintf(result, format, string, value);
1296
static char *errorMessage(char *format)
1396
static char *format1Number (char *format, long value)
1400
if ((result = (char *)malloc (strlen (format) + 20)) != 0)
1401
sprintf (result, format, value);
1405
static char *format3String (char *format, char *s1, char *s2, char *s3)
1409
if ((result = (char *)malloc (strlen (format) +
1413
sprintf (result, format, s1, s2, s3);
1417
static char *format1String (char *format, char *string)
1421
if ((result = (char *)malloc (strlen (format) + strlen (string))) != 0)
1422
sprintf (result, format, string);
1426
static char *format1StrVal (char *format, char *string, int value)
1430
if ((result = (char *)malloc (strlen (format) + strlen (string) + 20)) != 0)
1431
sprintf (result, format, string, value);
1435
static char *errorMessage (char *format)
1299
1438
#ifdef HAVE_STRERROR
1379
1518
char buffer[512];
1380
1519
freeChar (fselect->pwd);
1381
if (getcwd(buffer, sizeof(buffer)) == 0)
1382
strcpy(buffer, ".");
1383
fselect->pwd = copyChar(buffer);
1388
dummyUnfocus(Fselect)
1390
dummyRefreshData(Fselect)
1392
dummySaveData(Fselect)
1520
if (getcwd (buffer, sizeof (buffer)) == 0)
1521
strcpy (buffer, ".");
1522
fselect->pwd = copyChar (buffer);
1525
static void destroyInfo (CDKFSELECT *widget)
1527
CDKfreeStrings (widget->dirContents);
1528
widget->dirContents = 0;
1530
widget->fileCounter = 0;
1533
static int createList (CDKFSELECT *widget, char **list, int listSize)
1539
char **newlist = typeCallocN (char *, listSize + 1);
1545
/* Copy in the new information. */
1547
for (x = 0; x < listSize; x++)
1549
if ((newlist[x] = copyChar (list[x])) == 0)
1557
destroyInfo (widget);
1558
widget->fileCounter = listSize;
1559
widget->dirContents = newlist;
1563
CDKfreeStrings (newlist);
1569
destroyInfo (widget);
1575
static void _focusCDKFselect (CDKOBJS *object)
1577
CDKFSELECT *widget = (CDKFSELECT *)object;
1579
FocusObj (ObjOf (widget->entryField));
1582
static void _unfocusCDKFselect (CDKOBJS *object)
1584
CDKFSELECT *widget = (CDKFSELECT *)object;
1586
UnfocusObj (ObjOf (widget->entryField));
1589
dummyRefreshData (Fselect)
1591
dummySaveData (Fselect)