hrev47504 adds 2 changesets to branch 'master' old head: dd03c93fbffc21c83f9188e6560c6a023c056fd6 new head: 8f367d30c81b4107020b090c89ebe3c89a289490 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=8f367d3+%5Edd03c93 ---------------------------------------------------------------------------- ceb65ce: 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. 8f367d3: Rewrite "open containing folder" in a safer way. * Tracker has support for this in its RefsReceived handler, which results in simpler code than going through BRoster to open the folder. * Avoids a race condition, possible confusion of Tracker windows with the same title, and makes the code more readable (and working). * Fixes #11008. Thanks to Axeld for pointing the support in RefsReceived, which wasn't used anywhere outside of Tracker, yet. [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 82 insertions(+), 137 deletions(-) src/apps/webpositive/DownloadProgressView.cpp | 55 ++++------- src/kits/tracker/Jamfile | 1 - src/kits/tracker/PoseViewScripting.cpp | 48 --------- src/kits/tracker/TrackerScripting.cpp | 115 ++++++++++++---------- ############################################################################ Commit: ceb65ce14e12c13cea8f46843d3695e52e1dea0a URL: http://cgit.haiku-os.org/haiku/commit/?id=ceb65ce Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Wed Jul 16 13:53:49 2014 UTC 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. ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/Jamfile b/src/kits/tracker/Jamfile index 031400f..c9486e1 100644 --- a/src/kits/tracker/Jamfile +++ b/src/kits/tracker/Jamfile @@ -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 ; diff --git a/src/kits/tracker/PoseViewScripting.cpp b/src/kits/tracker/PoseViewScripting.cpp index effef12..a742f0c 100644 --- a/src/kits/tracker/PoseViewScripting.cpp +++ b/src/kits/tracker/PoseViewScripting.cpp @@ -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 } diff --git a/src/kits/tracker/TrackerScripting.cpp b/src/kits/tracker/TrackerScripting.cpp index ebdb324..a94fc95 100644 --- a/src/kits/tracker/TrackerScripting.cpp +++ b/src/kits/tracker/TrackerScripting.cpp @@ -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; } ############################################################################ Revision: hrev47504 Commit: 8f367d30c81b4107020b090c89ebe3c89a289490 URL: http://cgit.haiku-os.org/haiku/commit/?id=8f367d3 Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Wed Jul 16 14:24:58 2014 UTC Ticket: https://dev.haiku-os.org/ticket/11008 Rewrite "open containing folder" in a safer way. * Tracker has support for this in its RefsReceived handler, which results in simpler code than going through BRoster to open the folder. * Avoids a race condition, possible confusion of Tracker windows with the same title, and makes the code more readable (and working). * Fixes #11008. Thanks to Axeld for pointing the support in RefsReceived, which wasn't used anywhere outside of Tracker, yet. ---------------------------------------------------------------------------- diff --git a/src/apps/webpositive/DownloadProgressView.cpp b/src/apps/webpositive/DownloadProgressView.cpp index cca09bd..59cb172 100644 --- a/src/apps/webpositive/DownloadProgressView.cpp +++ b/src/apps/webpositive/DownloadProgressView.cpp @@ -505,51 +505,32 @@ DownloadProgressView::MessageReceived(BMessage* message) break; case OPEN_CONTAINING_FOLDER: if (fPath.InitCheck() == B_OK) { + BEntry selected(fPath.Path()); + if (!selected.Exists()) + break; + BPath containingFolder; if (fPath.GetParent(&containingFolder) != B_OK) break; - BEntry entry(containingFolder.Path()); - if (!entry.Exists()) - break; entry_ref ref; - if (entry.GetRef(&ref) != B_OK) + if (get_ref_for_path(containingFolder.Path(), &ref) != B_OK) break; - be_roster->Launch(&ref); - - // Use Tracker scripting and select the download pose - // in the window. - // TODO: We should somehow get the window that just openend. - // Using the name like this is broken when there are multiple - // windows open with this name. Also Tracker does not scroll - // to this entry. - BString windowName = ref.name; - BString fullWindowName = containingFolder.Path(); + // Ask Tracker to open the containing folder and select the + // file inside it. BMessenger trackerMessenger("application/x-vnd.Be-TRAK"); - if (trackerMessenger.IsValid() - && get_ref_for_path(fPath.Path(), &ref) == B_OK) { - // We need to wait a bit until the folder is open. - // TODO: This is also too fragile... we should be able - // to wait for the roster message. - snooze(250000); - int32 tries = 2; - while (tries > 0) { - BMessage selectionCommand(B_SET_PROPERTY); - selectionCommand.AddSpecifier("Selection"); - selectionCommand.AddSpecifier("Poses"); - selectionCommand.AddSpecifier("Window", - windowName.String()); - selectionCommand.AddRef("data", &ref); - BMessage reply; - trackerMessenger.SendMessage(&selectionCommand, &reply); - int32 error; - if (reply.FindInt32("error", &error) != B_OK - || error == B_OK) { - break; - } - windowName = fullWindowName; - tries--; + + if (trackerMessenger.IsValid()) { + BMessage selectionCommand(B_REFS_RECEIVED); + selectionCommand.AddRef("refs", &ref); + + node_ref selectedRef; + if (selected.GetNodeRef(&selectedRef) == B_OK) { + selectionCommand.AddData("nodeRefToSelect", B_RAW_TYPE, + (void*)&selectedRef, sizeof(node_ref)); } + + trackerMessenger.SendMessage(&selectionCommand); } } break;