Extend Tracker scripting capabilities
* Allow EXECUTE on the Folder property to open a window for the passed ref and return a BMEssenger targetting that window. * Allog GET on the Folder property to return a messenger to the matching window, if one is already open. * Make scripting support mandatory and remove the define allowing to disable it.
This commit is contained in:
@@ -10,7 +10,6 @@ SubDirC++Flags
|
||||
-D_BUILDING_tracker=1
|
||||
# -D_INCLUDES_CLASS_DEVICE_MAP=1
|
||||
-D_SUPPORTS_RESOURCES=1
|
||||
-D_SUPPORTS_FEATURE_SCRIPTING=1
|
||||
# -D_SILENTLY_CORRECT_FILE_NAMES=1
|
||||
;
|
||||
|
||||
|
||||
@@ -51,11 +51,7 @@ All rights reserved.
|
||||
#define kPropertyPath "Path"
|
||||
|
||||
#ifndef _SCRIPTING_ONLY
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
#define _SCRIPTING_ONLY(x) x
|
||||
#else
|
||||
#define _SCRIPTING_ONLY(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// notes on PoseView scripting interface:
|
||||
@@ -95,8 +91,6 @@ doo Tracker delete Selection 'test/EL34' of Poses of Window test
|
||||
// - pose text widgets
|
||||
|
||||
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
|
||||
const property_info kPosesPropertyList[] = {
|
||||
{ kPropertyPath,
|
||||
{ B_GET_PROPERTY },
|
||||
@@ -203,29 +197,22 @@ const property_info kPosesPropertyList[] = {
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
status_t
|
||||
BPoseView::GetSupportedSuites(BMessage* _SCRIPTING_ONLY(data))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
data->AddString("suites", kPosesSuites);
|
||||
BPropertyInfo propertyInfo(
|
||||
const_cast<property_info*>(kPosesPropertyList));
|
||||
data->AddFlat("messages", &propertyInfo);
|
||||
|
||||
return _inherited::GetSupportedSuites(data);
|
||||
#else
|
||||
return B_UNSUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BPoseView::HandleScriptingMessage(BMessage* _SCRIPTING_ONLY(message))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
if (message->what != B_GET_PROPERTY
|
||||
&& message->what != B_SET_PROPERTY
|
||||
&& message->what != B_CREATE_PROPERTY
|
||||
@@ -285,9 +272,6 @@ BPoseView::HandleScriptingMessage(BMessage* _SCRIPTING_ONLY(message))
|
||||
}
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +280,6 @@ BPoseView::ExecuteProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
status_t result = B_OK;
|
||||
bool handled = false;
|
||||
if (strcmp(property, kPropertyEntry) == 0) {
|
||||
@@ -340,9 +323,6 @@ BPoseView::ExecuteProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
reply->AddInt32("error", result);
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -351,7 +331,6 @@ BPoseView::CreateProperty(BMessage* _SCRIPTING_ONLY(specifier), BMessage*,
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
status_t result = B_OK;
|
||||
bool handled = false;
|
||||
if (strcmp(property, kPropertySelection) == 0) {
|
||||
@@ -401,9 +380,6 @@ BPoseView::CreateProperty(BMessage* _SCRIPTING_ONLY(specifier), BMessage*,
|
||||
reply->AddInt32("error", result);
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -412,7 +388,6 @@ BPoseView::DeleteProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
status_t result = B_OK;
|
||||
bool handled = false;
|
||||
|
||||
@@ -504,9 +479,6 @@ BPoseView::DeleteProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
reply->AddInt32("error", result);
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -515,7 +487,6 @@ BPoseView::CountProperty(BMessage*, int32,
|
||||
const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
bool handled = false;
|
||||
//PRINT(("BPoseView::CountProperty, %s\n", property));
|
||||
|
||||
@@ -529,9 +500,6 @@ BPoseView::CountProperty(BMessage*, int32,
|
||||
}
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -540,7 +508,6 @@ BPoseView::GetProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
// PRINT(("GetProperty %s\n", property));
|
||||
bool handled = false;
|
||||
status_t result = B_OK;
|
||||
@@ -666,9 +633,6 @@ BPoseView::GetProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
||||
reply->AddInt32("error", result);
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -677,7 +641,6 @@ BPoseView::SetProperty(BMessage* _SCRIPTING_ONLY(message), BMessage*,
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property),
|
||||
BMessage* _SCRIPTING_ONLY(reply))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
status_t result = B_OK;
|
||||
bool handled = false;
|
||||
|
||||
@@ -739,9 +702,6 @@ BPoseView::SetProperty(BMessage* _SCRIPTING_ONLY(message), BMessage*,
|
||||
reply->AddInt32("error", result);
|
||||
|
||||
return handled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -750,7 +710,6 @@ BPoseView::ResolveSpecifier(BMessage* _SCRIPTING_ONLY(message),
|
||||
int32 _SCRIPTING_ONLY(index), BMessage* _SCRIPTING_ONLY(specifier),
|
||||
int32 _SCRIPTING_ONLY(form), const char* _SCRIPTING_ONLY(property))
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
BPropertyInfo propertyInfo(
|
||||
const_cast<property_info*>(kPosesPropertyList));
|
||||
|
||||
@@ -763,9 +722,6 @@ BPoseView::ResolveSpecifier(BMessage* _SCRIPTING_ONLY(message),
|
||||
}
|
||||
|
||||
return this;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -773,7 +729,6 @@ BPose*
|
||||
BPoseView::FindPose(const entry_ref* _SCRIPTING_ONLY(ref),
|
||||
int32 _SCRIPTING_ONLY(specifierForm), int32* _SCRIPTING_ONLY(index)) const
|
||||
{
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
// flavor of FindPose, used by previous/next specifiers
|
||||
|
||||
BPose* pose = FindPose(ref, index);
|
||||
@@ -784,7 +739,4 @@ BPoseView::FindPose(const entry_ref* _SCRIPTING_ONLY(ref),
|
||||
return PoseAtIndex(++*index);
|
||||
else
|
||||
return pose;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -36,8 +36,9 @@ All rights reserved.
|
||||
#include <Message.h>
|
||||
#include <PropertyInfo.h>
|
||||
|
||||
#include "Tracker.h"
|
||||
#include "ContainerWindow.h"
|
||||
#include "FSUtils.h"
|
||||
#include "Tracker.h"
|
||||
|
||||
|
||||
#define kPropertyTrash "Trash"
|
||||
@@ -45,19 +46,20 @@ All rights reserved.
|
||||
#define kPropertyPreferences "Preferences"
|
||||
|
||||
|
||||
#if 0
|
||||
/*
|
||||
Available scripting commands:
|
||||
|
||||
doo Tracker delete Trash
|
||||
doo Tracker create Folder to '/boot/home/Desktop/hello'
|
||||
doo Tracker create Folder to '/boot/home/Desktop/hello' # mkdir
|
||||
doo Tracker get Folder to '/boot/home/Desktop/hello' # get window for path
|
||||
doo Tracker execute Folder to '/boot/home/Desktop/hello' # open window
|
||||
|
||||
ToDo:
|
||||
Create file: on a "Tracker" "File" "B_CREATE_PROPERTY" "name"
|
||||
Create query: on a "Tracker" "Query" "B_CREATE_PROPERTY" "name"
|
||||
Open a folder: Tracker Execute "Folder" bla
|
||||
Find a window for a path
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
#if _SUPPORTS_FEATURE_SCRIPTING
|
||||
const property_info kTrackerPropertyList[] = {
|
||||
{
|
||||
kPropertyTrash,
|
||||
@@ -71,9 +73,11 @@ const property_info kTrackerPropertyList[] = {
|
||||
},
|
||||
{
|
||||
kPropertyFolder,
|
||||
{ B_CREATE_PROPERTY },
|
||||
{ B_CREATE_PROPERTY, B_GET_PROPERTY, B_EXECUTE_PROPERTY },
|
||||
{ B_DIRECT_SPECIFIER },
|
||||
"create Folder to path # creates a new folder",
|
||||
"create Folder to path # creates a new folder\n"
|
||||
"get Folder to path # get Tracker window pointing to folder\n"
|
||||
"execute Folder to path # opens Tracker window pointing to folder\n",
|
||||
0,
|
||||
{ B_REF_TYPE },
|
||||
{},
|
||||
@@ -168,7 +172,7 @@ TTracker::HandleScriptingMessage(BMessage* message)
|
||||
break;
|
||||
|
||||
case B_GET_PROPERTY:
|
||||
handled = GetProperty(&specifier, form, property, &reply);
|
||||
handled = GetProperty(message, form, property, &reply);
|
||||
break;
|
||||
|
||||
case B_SET_PROPERTY:
|
||||
@@ -185,7 +189,7 @@ TTracker::HandleScriptingMessage(BMessage* message)
|
||||
break;
|
||||
|
||||
case B_EXECUTE_PROPERTY:
|
||||
handled = ExecuteProperty(&specifier, form, property, &reply);
|
||||
handled = ExecuteProperty(message, form, property, &reply);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -255,46 +259,9 @@ TTracker::DeleteProperty(BMessage*, int32 form, const char* property, BMessage*)
|
||||
}
|
||||
|
||||
|
||||
#else // _SUPPORTS_FEATURE_SCRIPTING
|
||||
status_t
|
||||
TTracker::GetSupportedSuites(BMessage*)
|
||||
{
|
||||
return B_UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
BHandler*
|
||||
TTracker::ResolveSpecifier(BMessage*, int32, BMessage*, int32, const char*)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TTracker::HandleScriptingMessage(BMessage*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TTracker::CreateProperty(BMessage*, BMessage*, int32, const char*, BMessage*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TTracker::DeleteProperty(BMessage*, int32, const char*, BMessage*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _SUPPORTS_FEATURE_SCRIPTING
|
||||
|
||||
|
||||
bool
|
||||
TTracker::ExecuteProperty(BMessage*, int32 form, const char* property,
|
||||
BMessage*)
|
||||
TTracker::ExecuteProperty(BMessage* message, int32 form, const char* property,
|
||||
BMessage* reply)
|
||||
{
|
||||
if (strcmp(property, kPropertyPreferences) == 0) {
|
||||
if (form != B_DIRECT_SPECIFIER) {
|
||||
@@ -306,6 +273,29 @@ TTracker::ExecuteProperty(BMessage*, int32 form, const char* property,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(property, kPropertyFolder) == 0) {
|
||||
message->PrintToStream();
|
||||
if (form != B_DIRECT_SPECIFIER)
|
||||
return false;
|
||||
|
||||
// create new empty folders
|
||||
entry_ref ref;
|
||||
for (int32 index = 0;
|
||||
message->FindRef("data", index, &ref) == B_OK; index++) {
|
||||
status_t error = OpenRef(&ref, NULL, NULL, kOpen, NULL);
|
||||
|
||||
if (error == B_OK) {
|
||||
reply->AddMessenger("window",
|
||||
BMessenger(FindContainerWindow(&ref)));
|
||||
} else {
|
||||
reply->AddInt32("error", error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -318,8 +308,31 @@ TTracker::CountProperty(BMessage*, int32, const char*, BMessage*)
|
||||
|
||||
|
||||
bool
|
||||
TTracker::GetProperty(BMessage*, int32, const char*, BMessage*)
|
||||
TTracker::GetProperty(BMessage* message, int32 form, const char* property,
|
||||
BMessage* reply)
|
||||
{
|
||||
if (strcmp(property, kPropertyFolder) == 0) {
|
||||
message->PrintToStream();
|
||||
if (form != B_DIRECT_SPECIFIER)
|
||||
return false;
|
||||
|
||||
// create new empty folders
|
||||
entry_ref ref;
|
||||
for (int32 index = 0;
|
||||
message->FindRef("data", index, &ref) == B_OK; index++) {
|
||||
BHandler* window = FindContainerWindow(&ref);
|
||||
|
||||
if (window != NULL)
|
||||
reply->AddMessenger("window", BMessenger(window));
|
||||
else {
|
||||
reply->AddInt32("error", B_NAME_NOT_FOUND);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user