6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
37 #include <PropertyInfo.h>
39 #include "ContainerWindow.h"
44 #define kPropertyTrash "Trash"
45 #define kPropertyFolder "Folder"
46 #define kPropertyPreferences "Preferences"
50 Available scripting commands:
52 doo Tracker delete Trash
53 doo Tracker create Folder to '/boot/home/Desktop/hello' # mkdir
54 doo Tracker get Folder to '/boot/home/Desktop/hello' # get window for path
55 doo Tracker execute Folder to '/boot/home/Desktop/hello' # open window
58 Create file: on a "Tracker" "File" "B_CREATE_PROPERTY" "name"
59 Create query: on a "Tracker" "Query" "B_CREATE_PROPERTY" "name"
63 const property_info kTrackerPropertyList
[] = {
66 { B_DELETE_PROPERTY
},
67 { B_DIRECT_SPECIFIER
},
68 "delete Trash # Empties the Trash",
76 { B_CREATE_PROPERTY
, B_GET_PROPERTY
, B_EXECUTE_PROPERTY
},
77 { B_DIRECT_SPECIFIER
},
78 "create Folder to path # creates a new folder\n"
79 "get Folder to path # get Tracker window pointing to folder\n"
80 "execute Folder to path # opens Tracker window pointing to folder\n",
88 { B_EXECUTE_PROPERTY
},
89 { B_DIRECT_SPECIFIER
},
90 "shows Tracker preferences",
102 TTracker::GetSupportedSuites(BMessage
* data
)
104 data
->AddString("suites", kTrackerSuites
);
105 BPropertyInfo
propertyInfo(const_cast<property_info
*>(
106 kTrackerPropertyList
));
107 data
->AddFlat("messages", &propertyInfo
);
109 return _inherited::GetSupportedSuites(data
);
114 TTracker::ResolveSpecifier(BMessage
* message
, int32 index
, BMessage
* specifier
,
115 int32 form
, const char* property
)
117 BPropertyInfo
propertyInfo(const_cast<property_info
*>(
118 kTrackerPropertyList
));
120 int32 result
= propertyInfo
.FindMatch(message
, index
, specifier
, form
,
123 //PRINT(("FindMatch result %d %s\n", result, strerror(result)));
124 return _inherited::ResolveSpecifier(message
, index
, specifier
,
133 TTracker::HandleScriptingMessage(BMessage
* message
)
135 if (message
->what
!= B_GET_PROPERTY
136 && message
->what
!= B_SET_PROPERTY
137 && message
->what
!= B_CREATE_PROPERTY
138 && message
->what
!= B_COUNT_PROPERTIES
139 && message
->what
!= B_DELETE_PROPERTY
140 && message
->what
!= B_EXECUTE_PROPERTY
) {
144 // dispatch scripting messages
145 BMessage
reply(B_REPLY
);
146 const char* property
= NULL
;
147 bool handled
= false;
153 status_t result
= message
->GetCurrentSpecifier(&index
, &specifier
,
155 if (result
!= B_OK
|| index
== -1)
158 ASSERT(property
!= NULL
);
160 switch (message
->what
) {
161 case B_CREATE_PROPERTY
:
162 handled
= CreateProperty(message
, &specifier
, form
, property
,
167 handled
= GetProperty(message
, form
, property
, &reply
);
171 handled
= SetProperty(message
, &specifier
, form
, property
,
175 case B_COUNT_PROPERTIES
:
176 handled
= CountProperty(&specifier
, form
, property
, &reply
);
179 case B_DELETE_PROPERTY
:
180 handled
= DeleteProperty(&specifier
, form
, property
, &reply
);
183 case B_EXECUTE_PROPERTY
:
184 handled
= ExecuteProperty(message
, form
, property
, &reply
);
189 // done handling message, send a reply
190 message
->SendReply(&reply
);
198 TTracker::CreateProperty(BMessage
* message
, BMessage
*, int32 form
,
199 const char* property
, BMessage
* reply
)
201 bool handled
= false;
202 status_t error
= B_OK
;
204 if (strcmp(property
, kPropertyFolder
) == 0) {
205 if (form
!= B_DIRECT_SPECIFIER
)
208 // create new empty folders
210 for (int32 index
= 0;
211 message
->FindRef("data", index
, &ref
) == B_OK
; index
++) {
215 error
= FSCreateNewFolder(&ref
);
225 reply
->AddInt32("error", error
);
232 TTracker::DeleteProperty(BMessage
*, int32 form
, const char* property
, BMessage
*)
234 if (strcmp(property
, kPropertyTrash
) == 0) {
235 // deleting on a selection is handled as removing a part of the
236 // selection not to be confused with deleting a selected item
238 if (form
!= B_DIRECT_SPECIFIER
) {
239 // only support direct specifier
255 TTracker::ExecuteProperty(BMessage
* message
, int32 form
, const char* property
,
258 if (strcmp(property
, kPropertyPreferences
) == 0) {
259 if (form
!= B_DIRECT_SPECIFIER
) {
260 // only support direct specifier
263 ShowSettingsWindow();
268 if (strcmp(property
, kPropertyFolder
) == 0) {
269 message
->PrintToStream();
270 if (form
!= B_DIRECT_SPECIFIER
)
273 // create new empty folders
275 for (int32 index
= 0;
276 message
->FindRef("data", index
, &ref
) == B_OK
; index
++) {
277 status_t error
= OpenRef(&ref
, NULL
, NULL
, kOpen
, NULL
);
280 reply
->AddMessenger("window",
281 BMessenger(FindContainerWindow(&ref
)));
283 reply
->AddInt32("error", error
);
296 TTracker::CountProperty(BMessage
*, int32
, const char*, BMessage
*)
303 TTracker::GetProperty(BMessage
* message
, int32 form
, const char* property
,
306 if (strcmp(property
, kPropertyFolder
) == 0) {
307 message
->PrintToStream();
308 if (form
!= B_DIRECT_SPECIFIER
)
311 // create new empty folders
313 for (int32 index
= 0;
314 message
->FindRef("data", index
, &ref
) == B_OK
; index
++) {
315 BHandler
* window
= FindContainerWindow(&ref
);
318 reply
->AddMessenger("window", BMessenger(window
));
320 reply
->AddInt32("error", B_NAME_NOT_FOUND
);
333 TTracker::SetProperty(BMessage
*, BMessage
*, int32
, const char*, BMessage
*)