summaryrefslogtreecommitdiff
path: root/FileRequest.c
blob: b6c82fc328e7f5748646f4ebeaac79cb20c0f338 (plain)
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
/****** FileRequest *********************************************************
*
*   NAME
*       FileRequest -- Bring up an ASL file requester
*
*   SYNOPSIS
*       name = FileRequest(title, postext, path, name)
*
*       STRPTR FileRequest(STRPTR, STRPTR, STRPTR, STRPTR);
*
*   FUNCTION
*       Shows a file requester.
*
*   INPUTS
*       title    - The window title
*       postext  - Text of the left gadget
*       path     - Buffer for the path. This will be modifierd.
*       name     - Buffer for the name. This will be modifierd.
*
*   RESULTS
*       pathname - Pathname of the selected file, or NULL if cancel.
*
*   SEE ALSO
*       asl.library
*
****************************************************************************/

#include <exec/execbase.h>
#include <proto/dos.h>
#include <dos/dosextens.h>
#include <proto/asl.h>
#include <libraries/asl.h>

#include <string.h>


extern struct TextAttr	MyScreenTextAttr;
extern struct Screen	*mainscreen;


STRPTR FileRequest(STRPTR wtitle, STRPTR postext, STRPTR drawer, STRPTR file)
{
	if (AslBase)
	{
		struct FileRequester	*f;
		char					*filename=NULL;
		static char				buf[256];

		if (f = AllocAslRequestTags( ASL_FileRequest,
			ASLFR_Screen,			mainscreen,
			ASLFR_TextAttr,			&MyScreenTextAttr,
			ASLFR_TitleText,		wtitle,
			ASLFR_InitialFile,		file,

			(drawer != NULL) ? ASLFR_InitialDrawer : ASLFR_DrawersOnly,
			(drawer != NULL) ? drawer : (STRPTR)TRUE,
			TAG_DONE
		))
		{
			if (AslRequest(f, NULL))
			{
				strcpy(drawer, f->fr_Drawer);
				strcpy(file,   f->fr_File);
				strcpy(buf, drawer );
				AddPart(buf, file, sizeof(buf));
				filename = buf;
			}

			FreeAslRequest(f);
		}

		return filename;
	}
	else return "";
}