From 994541a836bf1e8e64bd7ab3b516e2c7c917dd92 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 29 Jan 2009 23:49:57 +0000 Subject: [PATCH] Refactor MoveSelectionTo a bit to reuse other code instead of duplicating most of it practically verbatim with different variable names. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29092 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/tracker/PoseView.cpp | 141 +--------------------------------- 1 file changed, 1 insertion(+), 140 deletions(-) diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index a6bf7f47f3..021095051a 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -4488,147 +4488,8 @@ BPoseView::MoveSelectionTo(BPoint dropPt, BPoint clickPt, if (srcWindow != window && !TargetModel()->IsDropTarget()) return; - // if drop was done with control key or secondary button - // then we need to show a context menu for drop location uint32 buttons = (uint32)window->CurrentMessage()->FindInt32("buttons"); - bool createLink = false; - bool forceCopy = false; - bool forceMove = false; - bool createRelativeLink = false; - bool dropOnGrid = (modifiers() & B_COMMAND_KEY) != 0; - - if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers() & B_CONTROL_KEY)) { - - switch (window->ShowDropContextMenu(dropPt)) { - case kCreateRelativeLink: - createRelativeLink = true; - break; - - case kCreateLink: - createLink = true; - break; - - case kMoveSelectionTo: - forceMove = true; - break; - - case kCopySelectionTo: - if (srcWindow == window) { - DuplicateSelection(&clickPt, &dropPt); - return; - } - forceCopy = true; - break; - - case kCancelButton: - default: - // user canceled context menu - return; - } - } - - if (!createLink && !createRelativeLink && srcWindow == window) { // dropped in same window - if (ViewMode() == kListMode) // can't move in list view - return; - - BPoint delta(dropPt - clickPt); - int32 count = fSelectionList->CountItems(); - for (int32 index = 0; index < count; index++) { - BPose *pose = fSelectionList->ItemAt(index); - - // remove pose from VSlist before changing location - // so that we "find" the correct pose to remove - // need to do this because bsearch uses top of pose - // to locate pose to remove - RemoveFromVSList(pose); - - BRect oldBounds(pose->CalcRect(this)); - BPoint location(pose->Location() + delta); - if (dropOnGrid) - location = PinToGrid(location, fGrid, fOffset); - - pose->MoveTo(location, this); - - RemoveFromExtent(oldBounds); - AddToExtent(pose->CalcRect(this)); - - // remove and reinsert pose to keep VSlist sorted - AddToVSList(pose); - } - } else { - AutoLock lock(srcWindow); - if (!lock) - return; - - // dropped from another window - // CopyTask will delete pointList - PoseList *selectionList = srcWindow->PoseView()->SelectionList(); - int32 count = selectionList->CountItems(); - BList *pointList = GetDropPointList(clickPt, dropPt, selectionList, - srcWindow->PoseView()->ViewMode() == kListMode, dropOnGrid); - - // perform asynch copy/move - forceCopy = forceCopy || (modifiers() & B_OPTION_KEY); - bool okToMove = true; - BEntry *destEntry = new BEntry(TargetModel()->EntryRef()); - bool destIsTrash = FSIsTrashDir(destEntry); - - // don't prompt if we're going to end up copying anyway - if (srcWindow->PoseView()->TargetModel()->IsQuery() - && !forceCopy - && !createLink - && !destIsTrash) { - srcWindow->UpdateIfNeeded(); - okToMove = (new BAlert("", kOkToMoveStr, "Cancel", "Move", NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go() == 1; - } - - // can't copy items into the trash - if (forceCopy && destIsTrash) { - (new BAlert("", kNoCopyToTrashStr, "Cancel", NULL, NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); - okToMove = false; - } - - // can't create symlinks into the trash - if ((createLink || createRelativeLink) && destIsTrash) { - (new BAlert("", kNoLinkToTrashStr, "Cancel", NULL, NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); - okToMove = false; - } - - if (okToMove) { - // create dup Model list, dest Model for CopyTask - BObjectList *srcList = new BObjectList(count, true); - CopySelectionListToBListAsEntryRefs(selectionList, srcList); - uint32 moveMode; - if (forceCopy) - moveMode = kCopySelectionTo; - else if (forceMove) - moveMode = kMoveSelectionTo; - else if (createRelativeLink) - moveMode = kCreateRelativeLink; - else if (createLink) - moveMode = kCreateLink; - else { - moveMode = kMoveSelectionTo; - entry_ref *srcRef = srcList->ItemAt(0); - BDirectory destDir (destEntry); - struct stat deststat; - destDir.GetStat(&deststat); - - if (srcRef->device != deststat.st_dev) - moveMode = kCopySelectionTo; - } - FSMoveToFolder(srcList, destEntry, moveMode, pointList); - } else { - if (pointList) { - pointList->DoForEach(delete_point); - delete pointList; - } - delete destEntry; - } - } + MoveSelectionInto(TargetModel(), srcWindow, window, buttons, dropPt, false); }