4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
33 struct Gadget busygadget
={
36 GFLG_GADGHNONE
,0,GTYP_BOOLGADGET
,
37 NULL
,NULL
,NULL
,0,NULL
,0,NULL
};
38 static int oldidcmp
,busyflag
;
43 busygadget
.TopEdge
=Window
->BorderTop
;
44 busygadget
.LeftEdge
=Window
->BorderLeft
;
45 busygadget
.Width
=Window
->Width
-Window
->BorderLeft
-Window
->BorderRight
;
46 busygadget
.Height
=Window
->Height
-Window
->BorderTop
-Window
->BorderBottom
;
47 AddGList(Window
,&busygadget
,0,1,NULL
);
48 oldidcmp
=Window
->IDCMPFlags
;
49 ModifyIDCMP(Window
,IDCMP_CLOSEWINDOW
);
50 Window
->Flags
|=WFLG_RMBTRAP
;
51 SetBusyPointer(Window
);
59 RemoveGList(Window
,&busygadget
,1);
60 ModifyIDCMP(Window
,oldidcmp
);
61 Window
->Flags
&=~WFLG_RMBTRAP
;
75 makefilebuffer(configname
);
76 filereq
.flags
=DFRF_SAVE
;
77 filereq
.title
=cfg_string
[STR_ENTER_CONFIGURATION_FILENAME
];
78 filereq
.window
=Window
;
79 if (!(FileRequest(&filereq
))) {
83 strcpy(configname
,dirbuf
);
84 TackOn(configname
,filebuf
,256);
85 if (!(stricmp(configname
,"DirectoryOpus.DefCFG"))) if (!(strstri(configname
,".CFG"))) StrConcat(configname
,".CFG",256);
88 if (!SaveConfig(configname
,&cstuff
)) {
89 lsprintf(buf
,cfg_string
[STR_SAVE_FAILED
],IoErr());
90 if (request(buf
)) goto trysave
;
92 else lchanged
=changed
=0;
99 char *path
,buf
[80],*menulist
[6],menuarray
[6],**ftypelist
,*typearray
;
100 struct DOpusRemember
*fkey
;
101 struct ConfigStuff
*newcstuff
;
102 struct dopusgadgetbanks
*bank
,*bank2
,*nbank
;
103 struct dopusfiletype
*ftype
,*ntype
;
104 struct dopushotkey
*fhotkey
,*nhotkey
,*curhotkey
;
105 int a
,b
,c
,freecon
=0,ret
,m1
,m2
;
111 if (type
==CFG_MAINMENU
) path
=configname
;
112 else path
=loadnamebuf
;
113 makefilebuffer(path
);
115 filereq
.title
=cfg_string
[STR_SELECT_CONFIGURATION_TO_LOAD
];
116 filereq
.window
=Window
;
117 if (!(FileRequest(&filereq
))) {
121 strcpy(loadnamebuf
,dirbuf
);
122 TackOn(loadnamebuf
,filebuf
,256);
123 if (!(strstri(loadnamebuf
,".CFG"))) StrConcat(loadnamebuf
,".CFG",256);
125 if (!(newcstuff
=AllocMem(sizeof(struct ConfigStuff
),MEMF_CLEAR
)) ||
126 !(newcstuff
->config
=AllocMem(sizeof(struct Config
),MEMF_CLEAR
))) {
127 if (newcstuff
) FreeMem(newcstuff
,sizeof(struct ConfigStuff
));
134 SetBusyPointer(Window
);
135 if ((a
=ReadConfig(loadnamebuf
,newcstuff
))!=1) {
136 ClearPointer(Window
);
137 if (a
==ERROR_NOT_CONFIG
) strcpy(buf
,cfg_string
[STR_FILE_NOT_VALID_CONFIGURATION
]);
138 else lsprintf(buf
,cfg_string
[STR_OPEN_FAILED
],a
);
139 if (request(buf
)) goto tryload
;
143 ClearPointer(Window
);
144 CheckConfig(newcstuff
);
148 DefaultConfig(newcstuff
);
156 CopyMem((char *)newcstuff
,(char *)&cstuff
,sizeof(struct ConfigStuff
));
157 cstuff
.config
=config
;
158 CopyMem((char *)newcstuff
->config
,(char *)config
,sizeof(struct Config
));
159 strcpy(configname
,loadnamebuf
);
163 CopyMem((char *)&newcstuff
->config
->copyflags
,(char *)&config
->copyflags
,
164 (offsetof(struct Config
,dynamicflags
)-offsetof(struct Config
,copyflags
))+1);
165 config
->dateformat
=newcstuff
->config
->dateformat
;
166 config
->formatflags
=newcstuff
->config
->formatflags
;
168 config
->sortmethod
[a
]=newcstuff
->config
->sortmethod
[a
];
169 config
->separatemethod
[a
]=newcstuff
->config
->separatemethod
[a
];
170 CopyMem((char *)newcstuff
->config
->displaypos
[a
],(char *)config
->displaypos
[a
],16);
171 CopyMem((UWORD
*)newcstuff
->config
->displaylength
[a
],(UWORD
*)config
->displaylength
[a
],32);
176 if (bank
=firstbank
) {
177 while (bank
->next
) bank
=bank
->next
;
179 bank2
=newcstuff
->firstbank
;
181 if (nbank
=(struct dopusgadgetbanks
*)
182 getcopy((char *)bank2
,sizeof(struct dopusgadgetbanks
),NULL
)) {
184 if (bank
) bank
->next
=nbank
;
185 else firstbank
=nbank
;
187 copygadgets(bank2
,bank
,NULL
);
191 cstuff
.firstbank
=firstbank
;
200 for (a
=0,b
=0;a
<5;a
++) {
201 if (newcstuff
->config
->menutit
[a
][0])
202 menulist
[b
++]=newcstuff
->config
->menutit
[a
];
205 !(dolistwindow(cfg_string
[STR_SELECT_MENUS_TO_IMPORT
],
206 332,40,menulist
,DLVF_MULTI
|DLVF_HIREC
,menuarray
,NULL
))) {
210 for (a
=0,b
=0;a
<5;a
++) {
211 m1
=a
*20; m2
=(a
+1)*20;
213 if (config
->menu
[c
].name
&& config
->menu
[c
].name
[0]) break;
215 while (!menuarray
[b
]) if ((++b
)>4) break;
217 for (c
=m1
;c
<m2
;c
++) freenewfunction(&config
->menu
[c
]);
218 CopyMem((char *)&newcstuff
->config
->menu
[b
*20],
219 (char *)&config
->menu
[m1
],sizeof(struct dopusfunction
)*20);
220 for (c
=m1
;c
<m2
;c
++) {
221 config
->menu
[c
].name
=getcopy(config
->menu
[c
].name
,-1,NULL
);
222 config
->menu
[c
].function
=getcopy(config
->menu
[c
].function
,-1,NULL
);
224 strcpy(config
->menutit
[a
],newcstuff
->config
->menutit
[b
]);
228 if ((a
== 5) && (menuarray
[b
])) ret
=2;
231 for (a
=0;a
<DRIVECOUNT
;a
++) freestring(config
->drive
[a
].function
);
232 CopyMem((char *)newcstuff
->config
->drive
,(char *)config
->drive
,sizeof(struct dopusfunction
)*DRIVECOUNT
);
233 for (a
=0;a
<DRIVECOUNT
;a
++)
234 config
->drive
[a
].function
=getcopy(newcstuff
->config
->drive
[a
].function
,-1,NULL
);
240 ftype
=newcstuff
->firsttype
;
245 if (!(ftypelist
=LAllocRemember(&fkey
,(b
+1)*4,MEMF_CLEAR
)) ||
246 !(typearray
=LAllocRemember(&fkey
,b
+1,MEMF_CLEAR
))) break;
247 ftype
=newcstuff
->firsttype
;
249 ftypelist
[a
]=ftype
->type
;
253 !(dolistwindow(cfg_string
[STR_SELECT_FILETYPES_TO_IMPORT
],
254 332,72,ftypelist
,DLVF_MULTI
|DLVF_HIREC
,typearray
,NULL
))) {
258 ftype
=newcstuff
->firsttype
; b
=0;
261 if (ntype
=(struct dopusfiletype
*)
262 getcopy((char *)ftype
,sizeof(struct dopusfiletype
),&typekey
)) {
264 ntype
->recognition
=getcopy(ftype
->recognition
,-1,&typekey
);
265 ntype
->iconpath
=getcopy(ftype
->iconpath
,-1,&typekey
);
266 for (a
=0;a
<FILETYPE_FUNCNUM
;a
++)
267 ntype
->function
[a
]=getcopy(ftype
->function
[a
],-1,&typekey
);
271 ftype
=ftype
->next
; ++b
;
273 cstuff
.firsttype
=firsttype
;
278 curhotkey
=firsthotkey
;
279 while (curhotkey
&& curhotkey
->next
) curhotkey
=curhotkey
->next
;
280 fhotkey
=newcstuff
->firsthotkey
;
283 fhotkey
=fhotkey
->next
;
285 if (!(ftypelist
=LAllocRemember(&fkey
,(b
+1)*4,MEMF_CLEAR
)) ||
286 !(typearray
=LAllocRemember(&fkey
,b
+1,MEMF_CLEAR
))) break;
287 fhotkey
=newcstuff
->firsthotkey
;
289 ftypelist
[a
]=fhotkey
->name
;
290 fhotkey
=fhotkey
->next
;
293 !(dolistwindow(cfg_string
[STR_SELECT_HOTKEYS_TO_IMPORT
],
294 332,72,ftypelist
,DLVF_MULTI
|DLVF_HIREC
,typearray
,NULL
))) {
298 fhotkey
=newcstuff
->firsthotkey
; b
=0;
301 if (nhotkey
=(struct dopushotkey
*)
302 getcopy((char *)fhotkey
,sizeof(struct dopushotkey
),NULL
)) {
304 nhotkey
->func
.function
=getcopy(fhotkey
->func
.function
,-1,NULL
);
305 if (curhotkey
) curhotkey
->next
=nhotkey
;
306 else firsthotkey
=nhotkey
;
310 fhotkey
=fhotkey
->next
; ++b
;
312 cstuff
.firsthotkey
=firsthotkey
;
315 /*HUX CopyMem((char *)&newcstuff->config->gadgettopcol,
316 (char *)&config->gadgettopcol,
317 offsetof(struct Config,pad4)-offsetof(struct Config,gadgettopcol));*/
318 CopyMem(newcstuff
->config
->fontsizes
,config
->fontsizes
,NUMFONTS
);
319 CopyMem(newcstuff
->config
->fontbufs
,config
->fontbufs
,NUMFONTS
*40);
320 config
->sliderbgcol
=newcstuff
->config
->sliderbgcol
;
321 config
->stringfgcol
=newcstuff
->config
->stringfgcol
;
322 config
->stringbgcol
=newcstuff
->config
->stringbgcol
;
323 config
->sliderwidth
=newcstuff
->config
->sliderwidth
;
324 config
->sliderheight
=newcstuff
->config
->sliderheight
;
325 config
->stringheight
=newcstuff
->config
->stringheight
;
326 config
->stringselfgcol
=newcstuff
->config
->stringselfgcol
;
327 config
->stringselbgcol
=newcstuff
->config
->stringselbgcol
;
328 config
->generalscreenflags
=newcstuff
->config
->generalscreenflags
;
329 CopyMem((char *)newcstuff
->config
->scrollborders
,
330 (char *)config
->scrollborders
,sizeof(struct Rectangle
)*2);
331 CopyMem((char *)newcstuff
->config
->new_palette
,
332 (char *)config
->new_palette
,sizeof(ULONG
)*48);
333 strcpy(config
->pubscreen_name
,newcstuff
->config
->pubscreen_name
);
334 config
->slider_pos
=newcstuff
->config
->slider_pos
;
338 CopyMem((char *)newcstuff
->config
->outputcmd
,(char *)config
->outputcmd
,
339 offsetof(struct Config
,gadgetrows
)-offsetof(struct Config
,outputcmd
));
340 CopyMem((char *)newcstuff
->config
->startupscript
,(char *)config
->startupscript
,
341 offsetof(struct Config
,pad8
)-offsetof(struct Config
,startupscript
));
342 strcpy(config
->uniconscript
,newcstuff
->config
->uniconscript
);
343 config
->addiconflags
=newcstuff
->config
->addiconflags
;
344 strcpy(config
->shellstartup
,newcstuff
->config
->shellstartup
);
345 strcpy(config
->language
,newcstuff
->config
->language
);
346 config
->loadexternal
=newcstuff
->config
->loadexternal
;
356 if (freecon
&2) FreeConfig(newcstuff
);
357 if (freecon
&1) FreeMem(newcstuff
->config
,sizeof(struct Config
));
358 FreeMem(newcstuff
,sizeof(struct ConfigStuff
));
360 LFreeRemember(&fkey
);
365 void copyconfigonly(config1
,config2
)
366 struct Config
*config1
,*config2
;
368 struct newdopusfunction
*menubackup
;
369 struct dopusfunction
*drivebackup
;
370 struct DOpusRemember
*key
;
373 menubackup
=(struct newdopusfunction
*)
374 getcopy((char *)config2
->menu
,sizeof(struct dopusfunction
)*MENUCOUNT
,&key
);
375 drivebackup
=(struct dopusfunction
*)
376 getcopy((char *)config2
->drive
,sizeof(struct dopusfunction
)*DRIVECOUNT
,&key
);
377 CopyMem((char *)config1
,(char *)config2
,sizeof(struct Config
));
378 if (menubackup
) CopyMem((char *)menubackup
,(char *)config2
->menu
,sizeof(struct newdopusfunction
)*MENUCOUNT
);
379 if (drivebackup
) CopyMem((char *)drivebackup
,(char *)config2
->drive
,sizeof(struct dopusfunction
)*DRIVECOUNT
);
383 dolistwindow(title
,w
,h
,items
,flags
,selarray
,item
)
392 struct DOpusListView
*view
;
395 int a
,gadgetid
,all
=1,count
;
401 if (selarray
&& flags
&DLVF_MULTI
) {
402 listokaygad
[0].NextGadget
=&listokaygad
[2];
403 listokaygad
[2].NextGadget
=&listokaygad
[1];
404 gadtxt
=listviewgads2
;
408 listokaygad
[0].NextGadget
=&listokaygad
[1];
412 listokaygad
[1].NextGadget
=NULL
;
414 setup_list_window(&requestwin
,&listlist
,listokaygad
,count
);
416 listlist
.items
=items
;
417 listlist
.selectarray
=selarray
;
418 listlist
.flags
=flags
;
419 listlist
.itemselected
=-1;
420 setuplist(&listlist
,-1,-1);
422 requestwin
.Title
=title
;
424 if (!(wind
=openwindow(&requestwin
))) return(0);
426 listlist
.window
=wind
;
427 if (!(AddListView(&listlist
,1))) {
432 SetAPen(wind
->RPort
,screen_pens
[1].pen
);
437 screen_pens
[config
->gadgettopcol
].pen
,screen_pens
[config
->gadgetbotcol
].pen
,1);
441 Wait(1<<wind
->UserPort
->mp_SigBit
);
442 while (IMsg
=(struct IntuiMessage
*)GetMsg(wind
->UserPort
)) {
443 if ((view
=ListViewIDCMP(&listlist
,IMsg
))==(struct DOpusListView
*)-1) {
444 class=IMsg
->Class
; code
=IMsg
->Code
;
445 if (class==IDCMP_GADGETUP
|| class==IDCMP_GADGETDOWN
)
446 gadgetid
=((struct Gadget
*)IMsg
->IAddress
)->GadgetID
;
447 ReplyMsg((struct Message
*)IMsg
);
448 if (class==IDCMP_VANILLAKEY
) {
451 else if (code
=='\e') a
=1;
453 SelectGadget(wind
,&listokaygad
[a
]);
454 class=GADGETUP
; gadgetid
=1-a
;
457 if (class==IDCMP_GADGETUP
) {
460 RemoveListView(&listlist
,1);
464 else if (gadgetid
==2 && flags
&DLVF_MULTI
) {
465 for (a
=0;a
<listlist
.count
;a
++) selarray
[a
]=all
;
466 RefreshListView(&listlist
,1);
472 if (flags
&DLVF_MULTI
)
473 selarray
[view
->itemselected
]=1-selarray
[view
->itemselected
];
475 if (item
) *item
=view
->itemselected
;
476 if (!(flags
&DLVF_LEAVE
)) {
478 RemoveListView(&cmdlist
,1);
488 void copytoclip(func
,funclist
,functype
,flagsel
)
489 struct dopusfunction
*func
;
490 char **funclist
,*functype
,*flagsel
;
492 struct Clip
*newclip
,*pos
;
495 if (newclip
=LAllocRemember(&clipkey
,sizeof(struct Clip
),MEMF_CLEAR
)) {
496 newclip
->func
.function
=compilefunclist(funclist
,functype
,&clipkey
);
497 newclip
->func
.which
=getselflags(flagsel
);
498 newclip
->func
.stack
=atoi(edit_stackbuf
);
499 newclip
->func
.pri
=atoi(edit_prioritybuf
);
500 newclip
->func
.delay
=atoi(edit_delaybuf
);
501 newclip
->func
.fpen
=func
->fpen
;
502 newclip
->func
.bpen
=func
->bpen
;
503 strcpy(newclip
->name
,edit_namebuf
);
505 while (pos
&& pos
->next
) pos
=pos
->next
;
506 if (pos
) pos
->next
=newclip
;
507 else firstclip
=newclip
;
513 pasteclip(func
,funclist
,functype
,displist
,flagsel
)
514 struct dopusfunction
*func
;
515 char **funclist
,*functype
,**displist
,*flagsel
;
518 struct DOpusRemember
*key
=NULL
;
522 if (!clipcount
) return(0);
523 if (!(cliplist
=LAllocRemember(&key
,(clipcount
+1)*4,MEMF_CLEAR
))) return(0);
526 for (a
=0;a
<clipcount
;a
++) {
528 if (!(cliplist
[a
]=LAllocRemember(&key
,40,MEMF_CLEAR
))) break;
529 strcpy(cliplist
[a
],clip
->name
);
533 if (dolistwindow(cfg_string
[STR_SELECT_FUNCTION_TO_PASTE
],
534 212,40,cliplist
,DLVF_LEAVE
|DLVF_HIREC
,NULL
,&a
)) {
536 for (b
=0;b
<a
;b
++) if (!(clip
=clip
->next
)) break;
538 erasefunction(func
,funclist
,displist
,flagsel
);
539 lsprintf(edit_stackbuf
,"%ld",clip
->func
.stack
);
540 lsprintf(edit_prioritybuf
,"%ld",clip
->func
.pri
);
541 lsprintf(edit_delaybuf
,"%ld",clip
->func
.delay
);
542 strcpy(edit_namebuf
,clip
->name
);
543 func
->key
=0; func
->qual
=0;
544 func
->fpen
=clip
->func
.fpen
; func
->bpen
=clip
->func
.bpen
;
545 makefunclist(clip
->func
.function
,funclist
,functype
);
546 for (a
=0;a
<MAXFUNCS
;a
++) makedispfunc(funclist
[a
],functype
[a
],displist
[a
]);
547 makeselflags(clip
->func
.which
,flagsel
);
556 void makefilebuffer(buf
)
562 ptr
=BaseName(dirbuf
);
567 else if (CheckExist(dirbuf
,NULL
)<1) {
573 char *strstri(string
,substring
)
574 char *string
,*substring
;
578 len
=(strlen(string
)-(sublen
=strlen(substring
)))+1;
579 if (len
<1) return(NULL
);
581 for (a
=0;a
<len
;a
++) {
582 if (LStrnCmpI(&string
[a
],substring
,sublen
)==0)