[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-commits
Subject:    [haiku-commits] haiku: hrev57255 - in src: kits/tracker add-ons/tracker/zipomatic
From:       waddlesplash <waddlesplash () gmail ! com>
Date:       2023-08-31 19:25:19
Message-ID: 20230831192519.573D93FC72 () turing ! freelists ! org
[Download RAW message or body]

hrev57255 adds 2 changesets to branch 'master'
old head: 46a6070b5792be7cb677dcda67400127b3c921c3
new head: 56241aab2ff36ab09b28340384651d3b78b16620
overview: https://git.haiku-os.org/haiku/log/?qt=range&q=56241aab2ff3+%5E46a6070b5792

----------------------------------------------------------------------------

711b36b44cec: Tracker: Merge SelectPosesListMode and SelectPosesIconMode.
  
  There was a TODO comment about this, which dated all the way back
  to the original OpenTracker import over 20 years ago.
  
  There's still more cleanup needed, so I left another TODO.

56241aab2ff3: Zip-O-Matic: Fix and enable _SelectInTracker().
  
  Based on a code example from humdinger.

                              [ Augustin Cavalier <waddlesplash@gmail.com> ]

----------------------------------------------------------------------------

4 files changed, 59 insertions(+), 187 deletions(-)
src/add-ons/tracker/zipomatic/ZipperThread.cpp | 112 +++---------------
src/add-ons/tracker/zipomatic/ZipperThread.h   |   2 +-
src/kits/tracker/PoseView.cpp                  | 129 +++++++--------------
src/kits/tracker/PoseView.h                    |   3 +-

############################################################################

Commit:      711b36b44cec475112da53d90ba9fdb0d81ed04a
URL:         https://git.haiku-os.org/haiku/commit/?id=711b36b44cec
Author:      Augustin Cavalier <waddlesplash@gmail.com>
Date:        Thu Aug 31 19:13:06 2023 UTC

Tracker: Merge SelectPosesListMode and SelectPosesIconMode.

There was a TODO comment about this, which dated all the way back
to the original OpenTracker import over 20 years ago.

There's still more cleanup needed, so I left another TODO.

----------------------------------------------------------------------------

diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
index a6ef37d27d..afce345cc4 100644
--- a/src/kits/tracker/PoseView.cpp
+++ b/src/kits/tracker/PoseView.cpp
@@ -7190,13 +7190,8 @@ BPoseView::_UpdateSelectionRect(const BPoint& point)
 		fIsDrawingSelectionRect = true;
 
 		// use current selection rectangle to scan poses
-		if (ViewMode() == kListMode) {
-			SelectPosesListMode(fSelectionRectInfo.rect,
-				&fSelectionRectInfo.selection);
-		} else {
-			SelectPosesIconMode(fSelectionRectInfo.rect,
-				&fSelectionRectInfo.selection);
-		}
+		SelectPoses(fSelectionRectInfo.rect,
+			&fSelectionRectInfo.selection);
 
 		Window()->UpdateIfNeeded();
 
@@ -7832,31 +7827,44 @@ BPoseView::GetDragRect(int32 clickedPoseIndex)
 }
 
 
-// TODO: SelectPosesListMode and SelectPosesIconMode are terrible and share
-// most code
 void
-BPoseView::SelectPosesListMode(BRect selectionRect, BList** oldList)
+BPoseView::SelectPoses(BRect selectionRect, BList** oldList)
 {
-	ASSERT(ViewMode() == kListMode);
+	// TODO: This is a mess due to pose rect calculation and list management
+	// being different for list vs. icon modes. Refactoring needed.
+
+	const bool inListMode = (ViewMode() == kListMode);
 
 	// collect all the poses which are enclosed inside the selection rect
 	BList* newList = new BList;
 	BRect bounds(Bounds());
-	SetDrawingMode(B_OP_COPY);
-		// TODO: I _think_ there is no more synchronous drawing here,
-		// so this should be save to remove
 
-	int32 startIndex = (int32)(selectionRect.top / fListElemHeight);
+	int32 startIndex;
+	if (inListMode) {
+		startIndex = (int32)(selectionRect.top / fListElemHeight);
+	} else {
+		startIndex = FirstIndexAtOrBelow(
+			(int32)(selectionRect.top - IconPoseHeight()), true);
+	}
 	if (startIndex < 0)
 		startIndex = 0;
 
-	BPoint loc(0, startIndex * fListElemHeight);
+	BPoint listLoc;
+	if (inListMode)
+		listLoc.Set(0, startIndex * fListElemHeight);
 
-	PoseList* poseList = CurrentPoseList();
-	int32 poseCount = poseList->CountItems();
+	PoseList* poseList = inListMode ? CurrentPoseList() : fVSPoseList;
+	const int32 poseCount = inListMode ? poseList->CountItems() : \
fPoseList->CountItems();  for (int32 index = startIndex; index < poseCount; index++) \
{  BPose* pose = poseList->ItemAt(index);
-		BRect poseRect(pose->CalcRect(loc, this));
+		if (pose == NULL)
+			continue;
+
+		BRect poseRect;
+		if (inListMode)
+			poseRect = pose->CalcRect(listLoc, this);
+		else
+			poseRect = pose->CalcRect(this);
 
 		if (selectionRect.Intersects(poseRect)) {
 			bool selected = pose->IsSelected();
@@ -7870,74 +7878,16 @@ BPoseView::SelectPosesListMode(BRect selectionRect, BList** \
oldList)  Invalidate(poseRect);
 			}
 
-			// First Pose selected gets to be the pivot.
+			// first Pose selected gets to be the pivot.
 			if ((fSelectionPivotPose == NULL) && (selected == false))
 				fSelectionPivotPose = pose;
 		}
 
-		loc.y += fListElemHeight;
-		if (loc.y > selectionRect.bottom)
-			break;
-	}
-
-	// take the old set of enclosed poses and invert selection state
-	// on those which are no longer enclosed
-	int32 count = (*oldList)->CountItems();
-	for (int32 index = 0; index < count; index++) {
-		int32 oldIndex = (addr_t)(*oldList)->ItemAt(index);
-
-		if (!newList->HasItem((void*)(addr_t)oldIndex)) {
-			BPose* pose = poseList->ItemAt(oldIndex);
-			pose->Select(!pose->IsSelected());
-			loc.Set(0, oldIndex * fListElemHeight);
-			BRect poseRect(pose->CalcRect(loc, this));
-
-			if (poseRect.Intersects(bounds))
-				Invalidate(poseRect);
-		}
-	}
-
-	delete* oldList;
-	*oldList = newList;
-}
-
-
-void
-BPoseView::SelectPosesIconMode(BRect selectionRect, BList** oldList)
-{
-	ASSERT(ViewMode() != kListMode);
-
-	// collect all the poses which are enclosed inside the selection rect
-	BList* newList = new BList;
-	BRect bounds(Bounds());
-	SetDrawingMode(B_OP_COPY);
-
-	int32 startIndex = FirstIndexAtOrBelow(
-		(int32)(selectionRect.top - IconPoseHeight()), true);
-	if (startIndex < 0)
-		startIndex = 0;
-
-	int32 poseCount = fPoseList->CountItems();
-	for (int32 index = startIndex; index < poseCount; index++) {
-		BPose* pose = fVSPoseList->ItemAt(index);
-		if (pose != NULL) {
-			BRect poseRect(pose->CalcRect(this));
-
-			if (selectionRect.Intersects(poseRect)) {
-				bool selected = pose->IsSelected();
-				pose->Select(!fSelectionList->HasItem(pose));
-				newList->AddItem((void*)(addr_t)index);
-
-				if ((selected != pose->IsSelected())
-					&& poseRect.Intersects(bounds)) {
-					Invalidate(poseRect);
-				}
-
-				// first Pose selected gets to be the pivot
-				if ((fSelectionPivotPose == NULL) && (selected == false))
-					fSelectionPivotPose = pose;
-			}
-
+		if (inListMode) {
+			listLoc.y += fListElemHeight;
+			if (listLoc.y > selectionRect.bottom)
+				break;
+		} else {
 			if (pose->Location(this).y > selectionRect.bottom)
 				break;
 		}
@@ -7950,16 +7900,23 @@ BPoseView::SelectPosesIconMode(BRect selectionRect, BList** \
oldList)  int32 oldIndex = (addr_t)(*oldList)->ItemAt(index);
 
 		if (!newList->HasItem((void*)(addr_t)oldIndex)) {
-			BPose* pose = fVSPoseList->ItemAt(oldIndex);
+			BPose* pose = poseList->ItemAt(oldIndex);
 			pose->Select(!pose->IsSelected());
-			BRect poseRect(pose->CalcRect(this));
+
+			BRect poseRect;
+			if (inListMode) {
+				listLoc.Set(0, oldIndex * fListElemHeight);
+				poseRect = pose->CalcRect(listLoc, this);
+			} else {
+				poseRect = pose->CalcRect(this);
+			}
 
 			if (poseRect.Intersects(bounds))
 				Invalidate(poseRect);
 		}
 	}
 
-	delete* oldList;
+	delete *oldList;
 	*oldList = newList;
 }
 
diff --git a/src/kits/tracker/PoseView.h b/src/kits/tracker/PoseView.h
index 71e0a4ba03..b4bb4e5165 100644
--- a/src/kits/tracker/PoseView.h
+++ b/src/kits/tracker/PoseView.h
@@ -608,8 +608,7 @@ protected:
 		BPoint mouseLocation) const;
 
 	// selection
-	void SelectPosesListMode(BRect, BList**);
-	void SelectPosesIconMode(BRect, BList**);
+	void SelectPoses(BRect, BList**);
 	void AddRemoveSelectionRange(BPoint where, bool extendSelection,
 		BPose* pose);
 

############################################################################

Revision:    hrev57255
Commit:      56241aab2ff36ab09b28340384651d3b78b16620
URL:         https://git.haiku-os.org/haiku/commit/?id=56241aab2ff3
Author:      Augustin Cavalier <waddlesplash@gmail.com>
Date:        Thu Aug 31 19:25:06 2023 UTC

Zip-O-Matic: Fix and enable _SelectInTracker().

Based on a code example from humdinger.

----------------------------------------------------------------------------

diff --git a/src/add-ons/tracker/zipomatic/ZipperThread.cpp \
b/src/add-ons/tracker/zipomatic/ZipperThread.cpp index e2cb04ee5c..d8cd43a09e 100644
--- a/src/add-ons/tracker/zipomatic/ZipperThread.cpp
+++ b/src/add-ons/tracker/zipomatic/ZipperThread.cpp
@@ -23,6 +23,8 @@
 #include <Path.h>
 #include <Volume.h>
 
+#include <private/tracker/tracker_private.h>
+
 #include "ZipOMaticMisc.h"
 #include "ZipOMaticWindow.h"
 
@@ -211,7 +213,7 @@ ZipperThread::ThreadShutdown()
 	close(fStdOut);
 	close(fStdErr);
 
-	// _SelectInTracker();
+	_SelectInTracker();
 
 	return B_OK;
 }
@@ -410,10 +412,8 @@ ZipperThread::WaitOnExternalZip()
 
 
 status_t
-ZipperThread::_SelectInTracker(int32 tryNumber)
+ZipperThread::_SelectInTracker()
 {
-	// work in progress - unreliable - not ready to be used
-
 	entry_ref parentRef;
 	BEntry entry(&fOutputEntryRef);
 
@@ -423,108 +423,24 @@ ZipperThread::_SelectInTracker(int32 tryNumber)
 	entry.GetParent(&entry);
 	entry.GetRef(&parentRef);
 
-	BMessenger trackerMessenger("application/x-vnd.Be-TRAK");
+	BMessenger trackerMessenger(kTrackerSignature);
 	if (!trackerMessenger.IsValid())
 		return B_ERROR;
 
-	BMessage request;
-	BMessage reply;
-	status_t status;
-
-	if (tryNumber == 0) {
-		request.MakeEmpty();
-		request.what = B_REFS_RECEIVED;
-		request.AddRef("refs", &parentRef);
-		trackerMessenger.SendMessage(&request, &reply);
-	}
-
-	if (tryNumber > 20)
-		return B_ERROR;
-
-	snooze(200000);
-
-	// find out the number of Tracker windows
-	request.MakeEmpty();
-	request.what = B_COUNT_PROPERTIES;
-	request.AddSpecifier("Window");
-	reply.MakeEmpty();
-
-	status = trackerMessenger.SendMessage(&request, &reply);
+	BMessage request, reply;
+	request.what = B_REFS_RECEIVED;
+	request.AddRef("refs", &parentRef);
+	status_t status = trackerMessenger.SendMessage(&request, &reply);
 	if (status != B_OK)
 		return status;
 
-	int32 windowCount;
-	status = reply.FindInt32("result", &windowCount);
-	if (status != B_OK)
-		return status;
+	// Wait 0.3 seconds to give Tracker time to populate.
+	snooze(300000);
 
-	// find a likely parent window
-	bool foundWindow = false;
-	int32 index = 0;
-	for (; index < windowCount; index++) {
-		request.MakeEmpty();
-		request.what = B_GET_PROPERTY;
-		request.AddSpecifier("Path");
-		request.AddSpecifier("Poses");
-		request.AddSpecifier("Window", index);
-		reply.MakeEmpty();
-
-		status = trackerMessenger.SendMessage(&request, &reply);
-		if (status != B_OK)
-			continue;
-
-		entry_ref windowRef;
-		status = reply.FindRef("result", &windowRef);
-		if (status != B_OK)
-			continue;
-
-		if (windowRef == parentRef) {
-			foundWindow = true;
-			break;
-		}
-	}
-
-	if (!foundWindow)
-		return _SelectInTracker(tryNumber + 1);
-
-	// find entry_ref in window - a newly opened window might
-	// be filling and the entry_ref perhaps not there yet?
 	request.MakeEmpty();
-	request.what = B_GET_PROPERTY;
-	request.AddSpecifier("Entry");
-	request.AddSpecifier("Poses");
-	request.AddSpecifier("Window", index);
-	reply.MakeEmpty();
-
-	status = trackerMessenger.SendMessage(&request, &reply);
-	if (status != B_OK)
-		return _SelectInTracker(tryNumber + 1);
+	request.what = BPrivate::kSelect;
+	request.AddRef("refs", &fOutputEntryRef);
 
-	bool foundRef = false;
-	entry_ref ref;
-	for (int32 m = 0;; m++) {
-		status = reply.FindRef("result", m, &ref);
-		if (status != B_OK)
-			break;
-		if (ref == fOutputEntryRef)
-			foundRef = true;
-	}
-
-	// if entry_ref not found in window, start over
-	if (!foundRef)
-		return _SelectInTracker(tryNumber + 1);
-
-	// select archive file in Tracker window
-	request.MakeEmpty();
-	request.what = B_SET_PROPERTY;
-	request.AddRef("data", &fOutputEntryRef);
-	request.AddSpecifier("Selection");
-	request.AddSpecifier("Poses");
-	request.AddSpecifier("Window", index);
 	reply.MakeEmpty();
-
-	status = trackerMessenger.SendMessage(&request, &reply);
-
-	return status;
+	return trackerMessenger.SendMessage(&request, &reply);
 }
-
diff --git a/src/add-ons/tracker/zipomatic/ZipperThread.h \
b/src/add-ons/tracker/zipomatic/ZipperThread.h index aab3aab7a7..6a85d1494a 100644
--- a/src/add-ons/tracker/zipomatic/ZipperThread.h
+++ b/src/add-ons/tracker/zipomatic/ZipperThread.h
@@ -52,7 +52,7 @@ private:
 								const char* name = NULL,
 								const char* value = NULL);
 
-			status_t		_SelectInTracker(int32 tryNumber = 0);
+			status_t		_SelectInTracker();
 
 			BMessenger		fWindowMessenger;
 			thread_id		fZipProcess;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic