Tracker: Code simplifications

BPoseView no longer keeps directory type state on switch directory.
BContainerWindow gets the state from the pose view on demand instead.

Rename IsDesktopWindow() to IsDesktop() which has the same meaning as
everywhere else: the Desktop but not the one in a regular window.
Store this information in the fIsDesktop parameter in pose view and
set it one time on PoseView::AttachedToWindow().

Consolidate ParentIsRoot() logic into method and call it.

BContainerWindow updates:
* Remove isDeskWindow param from constructor, only usesLayout now.

Prefer Selection version inside Tracker, e.g. kDeleteSelection

Change-Id: Ib114585a235931e96cbdcc0de6d7b8f6e9bc20c3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8226
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
John Scipione 2024-09-04 13:10:18 -04:00 committed by waddlesplash
parent 4b3c808eda
commit a4a5800e5f
13 changed files with 379 additions and 362 deletions

View File

@ -358,7 +358,7 @@ AddMimeTypeString(BStringList& list, Model* model)
BContainerWindow::BContainerWindow(LockingList<BWindow>* list, uint32 openFlags, window_look look,
window_feel feel, uint32 windowFlags, uint32 workspace, bool useLayout, bool isDeskWindow)
window_feel feel, uint32 windowFlags, uint32 workspace, bool useLayout)
:
BWindow(InitialWindowRect(feel), "TrackerWindow", look, feel, windowFlags, workspace),
fWindowList(list),
@ -392,10 +392,6 @@ BContainerWindow::BContainerWindow(LockingList<BWindow>* list, uint32 openFlags,
fSelectionWindow(NULL),
fTaskLoop(NULL),
fStateNeedsSaving(false),
fIsTrash(false),
fInTrash(false),
fIsPrinters(false),
fIsDesktop(isDeskWindow),
fBackgroundImage(NULL),
fSavedZoomRect(0, 0, -1, -1),
fDragMessage(NULL),
@ -609,32 +605,16 @@ BContainerWindow::NewPoseView(Model* model, uint32 viewMode)
}
void
BContainerWindow::UpdateIfTrash(Model* model)
{
BEntry entry(model->EntryRef());
if (entry.InitCheck() == B_OK) {
fIsTrash = model->IsTrash();
fInTrash = FSInTrashDir(model->EntryRef());
fIsPrinters = FSIsPrintersDir(&entry);
}
}
void
BContainerWindow::CreatePoseView(Model* model)
{
UpdateIfTrash(model);
fPoseView = NewPoseView(model, kListMode);
fBorderedView->GroupLayout()->AddView(fPoseView);
fBorderedView->GroupLayout()->SetInsets(1, 0, 1, 1);
fBorderedView->EnableBorderHighlight(false);
TrackerSettings settings;
if (settings.SingleWindowBrowse() && model->IsDirectory()
&& !fPoseView->IsFilePanel()) {
if (settings.SingleWindowBrowse() && model->IsDirectory() && !PoseView()->IsFilePanel()) {
fNavigator = new BNavigator(model);
fPoseContainer->GridLayout()->AddView(fNavigator, 0, 0, 2);
if (!settings.ShowNavigator())
@ -768,7 +748,7 @@ BContainerWindow::Init(const BMessage* message)
fMenuContainer->GroupLayout()->AddView(fMenuBar);
AddMenus();
if (!TargetModel()->IsRoot() && !IsTrash())
if (!TargetModel()->IsRoot() && !TargetModel()->IsTrash())
_AddFolderIcon();
} else {
// add equivalents of the menu shortcuts to the menuless
@ -777,7 +757,7 @@ BContainerWindow::Init(const BMessage* message)
}
AddContextMenus();
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDelete), PoseView());
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDeleteSelection), PoseView());
AddShortcut('K', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kCleanupAll), PoseView());
AddShortcut('Q', B_COMMAND_KEY | B_OPTION_KEY | B_SHIFT_KEY | B_CONTROL_KEY,
new BMessage(kQuitTracker));
@ -828,10 +808,10 @@ BContainerWindow::Init(const BMessage* message)
// using different attributes as titles in icon view modes
ShowAttributesMenu();
}
MarkAttributesMenu(fAttrMenu);
CheckScreenIntersect();
if (fBackgroundImage != NULL && !fIsDesktop && PoseView()->ViewMode() != kListMode)
bool isListMode = PoseView()->ViewMode() == kListMode;
if (fBackgroundImage != NULL && !PoseView()->IsDesktop() && !isListMode)
fBackgroundImage->Show(PoseView(), current_workspace());
Show();
@ -916,25 +896,24 @@ BContainerWindow::RestoreStateCommon()
// don't pick up backgrounds in safe mode
return;
WindowStateNodeOpener opener(this, false);
bool isDesktop = PoseView()->IsDesktop();
WindowStateNodeOpener opener(this, false);
if (!TargetModel()->IsRoot() && opener.Node() != NULL) {
// don't pick up background image for root disks
// to do this, would have to have a unique attribute for the
// disks window that doesn't collide with the desktop
// for R4 this was not done to make things simpler
// the default image will still work though
fBackgroundImage = BackgroundImage::GetBackgroundImage(
opener.Node(), fIsDesktop);
fBackgroundImage = BackgroundImage::GetBackgroundImage(opener.Node(), isDesktop);
// look for background image info in the window's node
}
BNode defaultingNode;
if (fBackgroundImage == NULL && !fIsDesktop
if (fBackgroundImage == NULL && !isDesktop
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode)) {
// look for background image info in the source for defaults
fBackgroundImage = BackgroundImage::GetBackgroundImage(&defaultingNode,
fIsDesktop);
fBackgroundImage = BackgroundImage::GetBackgroundImage(&defaultingNode, isDesktop);
}
}
@ -967,17 +946,17 @@ BContainerWindow::UpdateBackgroundImage()
WindowStateNodeOpener opener(this, false);
if (!TargetModel()->IsRoot() && opener.Node() != NULL) {
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage,
opener.Node(), fIsDesktop, PoseView());
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage, opener.Node(),
PoseView()->IsDesktop(), PoseView());
}
// look for background image info in the window's node
BNode defaultingNode;
if (!fBackgroundImage && !fIsDesktop
if (!fBackgroundImage && !PoseView()->IsDesktop()
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode)) {
// look for background image info in the source for defaults
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage,
&defaultingNode, fIsDesktop, PoseView());
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage, &defaultingNode,
PoseView()->IsDesktop(), PoseView());
}
}
@ -985,7 +964,7 @@ BContainerWindow::UpdateBackgroundImage()
void
BContainerWindow::FrameResized(float, float)
{
if (PoseView() != NULL && !fIsDesktop) {
if (PoseView() != NULL && !PoseView()->IsDesktop()) {
BRect extent = PoseView()->Extent();
float offsetX = extent.left - PoseView()->Bounds().left;
float offsetY = extent.top - PoseView()->Bounds().top;
@ -1326,6 +1305,10 @@ BContainerWindow::MessageReceived(BMessage* message)
break;
}
case kOpenParentDir:
PostMessage(message, PoseView());
break;
case kNewFolder:
PostMessage(message, PoseView());
break;
@ -1404,8 +1387,7 @@ BContainerWindow::MessageReceived(BMessage* message)
PoseView()->MoveSelectionInto(&model, this, false, false,
message->what == kCreateLink,
message->what == kCreateRelativeLink);
} else if (!TargetModel()->IsQuery()
&& !TargetModel()->IsVirtualDirectory()) {
} else if (!TargetModel()->IsQuery() && !TargetModel()->IsVirtualDirectory()) {
// no destination specified, create link in same dir as item
PoseView()->MoveSelectionInto(TargetModel(), this, false, false,
message->what == kCreateLink,
@ -1447,33 +1429,29 @@ BContainerWindow::MessageReceived(BMessage* message)
if (StateNeedsSaving())
SaveState(false);
bool wasInTrash = IsTrash() || InTrash();
bool isRoot = TargetModel()->IsRoot();
bool isVolume = TargetModel()->IsVolume();
bool wasInTrash = TargetModel()->IsTrash() || TargetModel()->InTrash();
bool wasRoot = TargetModel()->IsRoot();
bool wasVolume = TargetModel()->IsVolume();
// Switch dir and apply new state
WindowStateNodeOpener opener(this, false);
opener.SetTo(&entry, false);
// Update PoseView
// Update pose view and set directory type
PoseView()->SwitchDir(&ref, opener.StreamNode());
fIsTrash = FSIsTrashDir(&entry);
fInTrash = FSInTrashDir(&ref);
if (wasInTrash ^ (IsTrash() || InTrash()) || isRoot != TargetModel()->IsRoot()
|| isVolume != TargetModel()->IsVolume()) {
if (wasInTrash ^ (TargetModel()->IsTrash() || TargetModel()->InTrash())
|| wasRoot != TargetModel()->IsRoot() || wasVolume != TargetModel()->IsVolume()) {
RepopulateMenus();
}
// skip the rest for file panel
if (PoseView()->IsFilePanel())
break;
if (Navigator() != NULL) {
// update Navigation bar
int32 action = kActionSet;
if (message->FindInt32("action", &action) != B_OK) {
// Design problem? Why does FindInt32 touch
// 'action' at all if he can't find it??
action = kActionSet;
}
int32 action = message->GetInt32("action", kActionSet);
Navigator()->UpdateLocation(TargetModel(), action);
}
@ -1485,7 +1463,7 @@ BContainerWindow::MessageReceived(BMessage* message)
// Update draggable folder icon
if (fMenuBar != NULL) {
if (!TargetModel()->IsRoot() && !IsTrash()) {
if (!TargetModel()->IsRoot() && !TargetModel()->IsTrash()) {
// Folder icon should be visible, but in single
// window navigation, it might not be.
if (fDraggableIcon != NULL) {
@ -1493,10 +1471,14 @@ BContainerWindow::MessageReceived(BMessage* message)
if (fDraggableIcon->IsHidden())
fDraggableIcon->Show();
fDraggableIcon->Invalidate();
} else
} else {
// draggable icon visible
_AddFolderIcon();
} else if (fDraggableIcon != NULL)
}
} else if (fDraggableIcon != NULL) {
// hide for Root or Trash
fDraggableIcon->Hide();
}
}
// Update window title
@ -1550,49 +1532,40 @@ BContainerWindow::MessageReceived(BMessage* message)
SetPathWatchingEnabled(true);
}
if (IsPathWatchingEnabled()
&& !(settings.ShowNavigator()
|| settings.ShowFullPathInTitleBar())) {
&& !(settings.ShowNavigator() || settings.ShowFullPathInTitleBar())) {
SetPathWatchingEnabled(false);
}
break;
case kSingleWindowBrowseChanged:
if (settings.SingleWindowBrowse()
&& !Navigator()
&& TargetModel()->IsDirectory()
&& !PoseView()->IsFilePanel()
&& !PoseView()->IsDesktopWindow()) {
if (settings.SingleWindowBrowse() && Navigator() == NULL
&& TargetModel()->IsDirectory() && !PoseView()->IsFilePanel()
&& !PoseView()->IsDesktop()) {
fNavigator = new BNavigator(TargetModel());
fPoseContainer->GridLayout()->AddView(fNavigator,
0, 0, 2);
fPoseContainer->GridLayout()->AddView(fNavigator, 0, 0, 2);
fNavigator->Hide();
SetPathWatchingEnabled(settings.ShowNavigator()
|| settings.ShowFullPathInTitleBar());
}
if (!settings.SingleWindowBrowse()
&& !fIsDesktop && TargetModel()->IsDesktop()) {
if (!settings.SingleWindowBrowse() && !PoseView()->IsDesktop()
&& TargetModel()->IsDesktop()) {
// Close the "Desktop" window, but not the Desktop
this->Quit();
}
SetSingleWindowBrowseShortcuts(
settings.SingleWindowBrowse());
SetSingleWindowBrowseShortcuts(settings.SingleWindowBrowse());
break;
case kShowNavigatorChanged:
ShowNavigator(settings.ShowNavigator());
if (!IsPathWatchingEnabled()
&& settings.ShowNavigator()) {
if (!IsPathWatchingEnabled() && settings.ShowNavigator())
SetPathWatchingEnabled(true);
}
if (IsPathWatchingEnabled()
&& !(settings.ShowNavigator()
|| settings.ShowFullPathInTitleBar())) {
&& !(settings.ShowNavigator() || settings.ShowFullPathInTitleBar())) {
SetPathWatchingEnabled(false);
}
SetSingleWindowBrowseShortcuts(
settings.SingleWindowBrowse());
SetSingleWindowBrowseShortcuts(settings.SingleWindowBrowse());
break;
default:
@ -1796,7 +1769,8 @@ BContainerWindow::AddFileMenu(BMenu* menu)
}
if (!TargetModel()->IsQuery() && !TargetModel()->IsVirtualDirectory()
&& !IsTrash() && !IsPrintersDir() && !TargetModel()->IsRoot()) {
&& !TargetModel()->IsTrash() && !TargetModel()->IsPrintersDir()
&& !TargetModel()->IsRoot()) {
if (!PoseView()->IsFilePanel()) {
TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(),
B_TRANSLATE("New"));
@ -1817,16 +1791,16 @@ BContainerWindow::AddFileMenu(BMenu* menu)
menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
new BMessage(kEditItem), 'E'));
if (IsTrash() || InTrash()) {
if (TargetModel()->IsTrash() || TargetModel()->InTrash()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Restore"),
new BMessage(kRestoreFromTrash)));
if (IsTrash()) {
if (TargetModel()->IsTrash()) {
// add as first item in menu
menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
new BMessage(kEmptyTrash)), 0);
menu->AddItem(new BSeparatorItem(), 1);
}
} else if (IsPrintersDir()) {
} else if (TargetModel()->IsPrintersDir()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS),
new BMessage(kAddPrinter), 'N'), 0);
menu->AddItem(new BSeparatorItem(), 1);
@ -1847,7 +1821,7 @@ BContainerWindow::AddFileMenu(BMenu* menu)
menu->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Move to Trash"),
new BMessage(kMoveToTrash), 'T');
new BMessage(kMoveSelectionToTrash), 'T');
item->SetEnabled(PoseView()->CanMoveToTrashOrDuplicate());
menu->AddItem(item);
@ -1861,7 +1835,7 @@ BContainerWindow::AddFileMenu(BMenu* menu)
BMenuItem* cutItem = NULL;
BMenuItem* copyItem = NULL;
BMenuItem* pasteItem = NULL;
if (!IsPrintersDir()) {
if (!TargetModel()->IsPrintersDir()) {
menu->AddSeparatorItem();
if (!TargetModel()->IsRoot()) {
@ -1973,7 +1947,7 @@ BContainerWindow::AddWindowMenu(BMenu* menu)
item->SetTarget(PoseView());
menu->AddItem(item);
if (!IsTrash()) {
if (!TargetModel()->IsTrash()) {
item = new BMenuItem(B_TRANSLATE("Open parent"),
new BMessage(kOpenParentDir), B_UP_ARROW);
item->SetTarget(PoseView());
@ -2003,7 +1977,7 @@ void
BContainerWindow::AddShortcuts()
{
// add equivalents of the menu shortcuts to the menuless desktop window
ASSERT(!IsTrash());
ASSERT(!TargetModel()->IsTrash());
ASSERT(!PoseView()->IsFilePanel());
ASSERT(!TargetModel()->IsQuery());
ASSERT(!TargetModel()->IsVirtualDirectory());
@ -2025,7 +1999,7 @@ BContainerWindow::AddShortcuts()
AddShortcut('D', B_COMMAND_KEY,
new BMessage(kDuplicateSelection), PoseView());
AddShortcut('T', B_COMMAND_KEY,
new BMessage(kMoveToTrash), PoseView());
new BMessage(kMoveSelectionToTrash), PoseView());
AddShortcut('K', B_COMMAND_KEY,
new BMessage(kCleanup), PoseView());
AddShortcut('A', B_COMMAND_KEY,
@ -2101,7 +2075,7 @@ BContainerWindow::MenusBeginning()
AddMimeTypesToMenu(fAttrMenu);
if (IsPrintersDir())
if (TargetModel()->IsPrintersDir())
EnableNamedMenuItem(fFileMenu, kMakeActivePrinter, selectCount == 1);
}
@ -2391,14 +2365,14 @@ BContainerWindow::PopulateMoveCopyNavMenu(BNavMenu* navMenu, uint32 what,
void
BContainerWindow::SetupMoveCopyMenus(const entry_ref* item_ref, BMenu* parent)
{
if (IsTrash() || InTrash() || IsPrintersDir() || fMoveToItem == NULL
|| fCopyToItem == NULL || fCreateLinkItem == NULL
if (TargetModel()->IsTrash() || TargetModel()->InTrash() || TargetModel()->IsPrintersDir()
|| fMoveToItem == NULL || fCopyToItem == NULL || fCreateLinkItem == NULL
|| TargetModel()->IsRoot()) {
return;
}
// re-parent items to this menu since they're shared
BMenuItem* trash = parent->FindItem(kMoveToTrash);
BMenuItem* trash = parent->FindItem(kMoveSelectionToTrash);
int32 index = trash != NULL ? parent->IndexOf(trash) + 2 : 0;
if (fMoveToItem->Menu() != parent) {
@ -2613,11 +2587,12 @@ BContainerWindow::ShowContextMenu(BPoint where, const entry_ref* ref)
}
return;
} else if (TargetModel()->IsRoot() || model.IsVolume()) {
} else if (model.IsRoot() || model.IsVolume()) {
fContextMenu = fVolumeContextMenu;
showAsVolume = true;
} else
} else {
fContextMenu = fFileContextMenu;
}
if (fContextMenu == NULL)
return;
@ -2634,7 +2609,7 @@ BContainerWindow::ShowContextMenu(BPoint where, const entry_ref* ref)
} else if (showAsVolume) {
// non-volume enable/disable copy, move, identify
EnableNamedMenuItem(fContextMenu, kDuplicateSelection, false);
EnableNamedMenuItem(fContextMenu, kMoveToTrash, false);
EnableNamedMenuItem(fContextMenu, kMoveSelectionToTrash, false);
EnableNamedMenuItem(fContextMenu, kIdentifyEntry, false);
// volume model, enable/disable the Unmount item
@ -2660,8 +2635,8 @@ BContainerWindow::ShowContextMenu(BPoint where, const entry_ref* ref)
UpdateMenu(fContextMenu, kPosePopUpContext);
}
} else if (fWindowContextMenu != NULL) {
// Repopulate desktop menu if IsDesktop
if (fIsDesktop)
// Repopulate desktop menu
if (PoseView()->IsDesktop())
RepopulateMenus();
MenusEnded();
@ -2693,21 +2668,22 @@ BContainerWindow::AddFileContextMenus(BMenu* menu)
menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
new BMessage(kEditItem), 'E'));
if (!IsTrash() && !InTrash() && !IsPrintersDir()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Duplicate"),
new BMessage(kDuplicateSelection), 'D'));
}
BMessage* message = new BMessage(kDuplicateSelection);
if (!(TargetModel()->IsTrash() || TargetModel()->InTrash() || TargetModel()->IsPrintersDir()))
menu->AddItem(new BMenuItem(B_TRANSLATE("Duplicate"), message, 'D'));
if (!IsTrash() && !InTrash()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Move to Trash"),
new BMessage(kMoveToTrash), 'T'));
if (!IsPrintersDir()) {
if (!(TargetModel()->IsTrash() || TargetModel()->InTrash())) {
message = new BMessage(kMoveSelectionToTrash);
menu->AddItem( new BMenuItem(B_TRANSLATE("Move to Trash"), message, 'T'));
if (!TargetModel()->IsPrintersDir()) {
// add separator for copy to/move to items (navigation items)
menu->AddSeparatorItem();
}
} else {
menu->AddItem(new BMenuItem(B_TRANSLATE("Delete"), new BMessage(kDelete), 0));
menu->AddItem(new BMenuItem(B_TRANSLATE("Restore"), new BMessage(kRestoreFromTrash), 0));
message = new BMessage(kDeleteSelection);
menu->AddItem(new BMenuItem(B_TRANSLATE("Delete"), message, 0));
message = new BMessage(kRestoreSelectionFromTrash);
menu->AddItem(new BMenuItem(B_TRANSLATE("Restore"), message, 0));
}
#ifdef CUT_COPY_PASTE_IN_CONTEXT_MENU
@ -2724,7 +2700,7 @@ BContainerWindow::AddFileContextMenus(BMenu* menu)
#endif
menu->AddSeparatorItem();
BMessage* message = new BMessage(kIdentifyEntry);
message = new BMessage(kIdentifyEntry);
message->AddBool("force", false);
menu->AddItem(new BMenuItem(B_TRANSLATE("Identify"), message));
@ -2783,25 +2759,20 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
ASSERT(targetModel != NULL);
bool needSeparator = true;
if (IsTrash()) {
if (TargetModel()->IsTrash()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
new BMessage(kEmptyTrash)));
} else if (IsPrintersDir()) {
} else if (TargetModel()->IsPrintersDir()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Add printer" B_UTF8_ELLIPSIS),
new BMessage(kAddPrinter), 'N'));
} else if (InTrash() || targetModel->IsRoot()) {
} else if (targetModel->InTrash() || targetModel->IsRoot()) {
needSeparator = false;
} else if (!PoseView()->IsFilePanel()) {
TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(), B_TRANSLATE("New"));
menu->AddItem(templatesMenu);
templatesMenu->SetTargetForItems(PoseView());
} else {
if (!PoseView()->IsFilePanel()) {
TemplatesMenu* templatesMenu = new TemplatesMenu(PoseView(),
B_TRANSLATE("New"));
menu->AddItem(templatesMenu);
templatesMenu->SetTargetForItems(PoseView());
} else {
BMenuItem* item = new BMenuItem(B_TRANSLATE("New folder"),
new BMessage(kNewFolder), 'N');
menu->AddItem(item);
}
menu->AddItem(new BMenuItem(B_TRANSLATE("New folder"), new BMessage(kNewFolder), 'N'));
}
if (needSeparator)
@ -2824,7 +2795,7 @@ BContainerWindow::AddWindowContextMenus(BMenu* menu)
new BMessage(kShowSelectionWindow), 'A', B_SHIFT_KEY));
menu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
new BMessage(B_SELECT_ALL), 'A'));
if (!IsTrash()) {
if (!TargetModel()->IsTrash()) {
menu->AddItem(new BMenuItem(B_TRANSLATE("Open parent"),
new BMessage(kOpenParentDir), B_UP_ARROW));
}
@ -3039,18 +3010,15 @@ BContainerWindow::UpdateMenu(BMenu* menu, UpdateMenuContext context)
EnableNamedMenuItem(menu, kOpenSelection, selectCount > 0);
EnableNamedMenuItem(menu, kIdentifyEntry, selectCount > 0);
EnableNamedMenuItem(menu, kRestoreFromTrash, selectCount > 0);
EnableNamedMenuItem(menu, kDelete,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(menu, kDeleteSelection, PoseView()->CanMoveToTrashOrDuplicate());
}
if (context == kMenuBarContext || context == kPosePopUpContext) {
SetupEditQueryItem(menu);
EnableNamedMenuItem(menu, kEditItem, PoseView()->CanEditName());
EnableNamedMenuItem(menu, kMoveToTrash,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(menu, kDuplicateSelection,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(menu, kMoveSelectionToTrash, PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(menu, kDuplicateSelection, PoseView()->CanMoveToTrashOrDuplicate());
SetCutItem(menu);
SetCopyItem(menu);
@ -3100,19 +3068,7 @@ BContainerWindow::UpdateMenu(BMenu* menu, UpdateMenuContext context)
SetArrangeMenu(menu);
SetPasteItem(menu);
BEntry entry(TargetModel()->EntryRef());
BDirectory parent;
bool parentIsRoot = (entry.GetParent(&parent) == B_OK
&& parent.GetEntry(&entry) == B_OK
&& FSIsRootDir(&entry));
EnableNamedMenuItem(menu, kOpenParentDir, !TargetModel()->IsDesktop()
&& !TargetModel()->IsRoot()
&& (!parentIsRoot
|| TrackerSettings().SingleWindowBrowse()
|| TrackerSettings().ShowDisksIcon()
|| (modifiers() & B_CONTROL_KEY) != 0));
EnableNamedMenuItem(menu, kOpenParentDir, !PoseView()->ParentIsRoot());
EnableNamedMenuItem(menu, kEmptyTrash, poseCount > 0);
EnableNamedMenuItem(menu, B_SELECT_ALL, poseCount > 0);
@ -3333,7 +3289,7 @@ BContainerWindow::NewAttributesMenu(BMenu* menu)
menu->AddItem(NewAttributeMenuItem(B_TRANSLATE("Kind"),
kAttrMIMEType, B_MIME_STRING_TYPE, 145, B_ALIGN_LEFT, false, false));
if (IsTrash() || InTrash()) {
if (TargetModel()->IsTrash() || TargetModel()->InTrash()) {
menu->AddItem(NewAttributeMenuItem(B_TRANSLATE("Original name"),
kAttrOriginalPath, B_STRING_TYPE, 225, B_ALIGN_LEFT, false,
false));
@ -3781,7 +3737,7 @@ BContainerWindow::SetupDefaultState()
return;
}
if (fIsDesktop) {
if (PoseView()->IsDesktop()) {
// don't copy over the attributes if we are the Desktop
return;
}
@ -3822,7 +3778,7 @@ BContainerWindow::SetupDefaultState()
void
BContainerWindow::RestoreWindowState(AttributeStreamNode* node)
{
if (node == NULL || fIsDesktop) {
if (node == NULL || PoseView()->IsDesktop()) {
// don't restore any window state if we are the Desktop
return;
}
@ -3880,7 +3836,7 @@ BContainerWindow::RestoreWindowState(AttributeStreamNode* node)
void
BContainerWindow::RestoreWindowState(const BMessage& message)
{
if (fIsDesktop) {
if (PoseView()->IsDesktop()) {
// don't restore any window state if we are the Desktop
return;
}
@ -3933,7 +3889,7 @@ BContainerWindow::RestoreWindowState(const BMessage& message)
void
BContainerWindow::SaveWindowState(AttributeStreamNode* node)
{
if (fIsDesktop) {
if (TargetModel() != NULL && PoseView()->IsDesktop()) {
// don't save window state if we are the Desktop
return;
}
@ -3942,7 +3898,7 @@ BContainerWindow::SaveWindowState(AttributeStreamNode* node)
const char* rectAttributeName;
const char* workspaceAttributeName;
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
if (TargetModel()->IsRoot()) {
rectAttributeName = kAttrDisksFrame;
workspaceAttributeName = kAttrDisksWorkspace;
} else {
@ -4062,13 +4018,11 @@ BContainerWindow::ShowSelectionWindow()
void
BContainerWindow::ShowNavigator(bool show)
{
if (PoseView()->IsDesktopWindow() || !TargetModel()->IsDirectory()
|| PoseView()->IsFilePanel()) {
if (PoseView()->IsDesktop() || !TargetModel()->IsDirectory() || PoseView()->IsFilePanel())
return;
}
if (show) {
if (Navigator() && !Navigator()->IsHidden())
if (Navigator() != NULL && !Navigator()->IsHidden())
return;
if (Navigator() == NULL) {
@ -4082,7 +4036,7 @@ BContainerWindow::ShowNavigator(bool show)
if (PoseView()->VScrollBar())
PoseView()->UpdateScrollRange();
} else {
if (!Navigator() || Navigator()->IsHidden())
if (Navigator() == NULL || Navigator()->IsHidden())
return;
if (PoseView()->VScrollBar())
@ -4096,11 +4050,11 @@ BContainerWindow::ShowNavigator(bool show)
void
BContainerWindow::SetSingleWindowBrowseShortcuts(bool enabled)
{
if (PoseView()->IsDesktopWindow())
if (PoseView()->IsDesktop())
return;
if (enabled) {
if (!Navigator())
if (Navigator() == NULL)
return;
RemoveShortcut(B_DOWN_ARROW, B_COMMAND_KEY | B_OPTION_KEY);
@ -4242,13 +4196,13 @@ WindowStateNodeOpener::WindowStateNodeOpener(BContainerWindow* window,
fNode(NULL),
fStreamNode(NULL)
{
if (window->TargetModel() && window->TargetModel()->IsRoot()) {
if (window->TargetModel() != NULL && window->TargetModel()->IsRoot()) {
BDirectory dir;
if (FSGetDeskDir(&dir) == B_OK) {
fNode = new BDirectory(dir);
fStreamNode = new AttributeStreamFileNode(fNode);
}
} else if (window->TargetModel()){
} else if (window->TargetModel() != NULL) {
fModelOpener = new ModelNodeLazyOpener(window->TargetModel(),
forWriting, false);
if (fModelOpener->IsOpen(forWriting)) {

View File

@ -94,8 +94,7 @@ public:
window_look look = B_DOCUMENT_WINDOW_LOOK,
window_feel feel = B_NORMAL_WINDOW_FEEL,
uint32 windowFlags = B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION,
uint32 workspace = B_CURRENT_WORKSPACE,
bool useLayout = true, bool isDeskWindow = false);
uint32 workspace = B_CURRENT_WORKSPACE, bool useLayout = true);
virtual ~BContainerWindow();
@ -108,8 +107,6 @@ public:
virtual void Quit();
virtual bool QuitRequested();
virtual void UpdateIfTrash(Model*);
virtual void CreatePoseView(Model*);
virtual void ShowContextMenu(BPoint, const entry_ref*);
@ -128,10 +125,6 @@ public:
virtual void CheckScreenIntersect();
bool IsTrash() const;
bool InTrash() const;
bool IsPrintersDir() const;
virtual bool IsShowing(const node_ref*) const;
virtual bool IsShowing(const entry_ref*) const;
@ -311,11 +304,6 @@ protected:
bool fStateNeedsSaving;
bool fIsTrash;
bool fInTrash;
bool fIsPrinters;
bool fIsDesktop;
BackgroundImage* fBackgroundImage;
static LockingList<struct AddOnShortcut>* fAddOnsList;
@ -403,27 +391,6 @@ BContainerWindow::PoseView() const
}
inline bool
BContainerWindow::IsTrash() const
{
return fIsTrash;
}
inline bool
BContainerWindow::InTrash() const
{
return fInTrash;
}
inline bool
BContainerWindow::IsPrintersDir() const
{
return fIsPrinters;
}
inline void
BContainerWindow::SetupDiskMenu(BMenu*)
{

View File

@ -186,12 +186,10 @@ LoadAddOnDir(BDirectory directory, BDeskWindow* window,
BDeskWindow::BDeskWindow(LockingList<BWindow>* windowList, uint32 openFlags)
:
BContainerWindow(windowList, openFlags,
kDesktopWindowLook, kDesktopWindowFeel,
B_NOT_MOVABLE | B_WILL_ACCEPT_FIRST_CLICK
| B_NOT_ZOOMABLE | B_NOT_CLOSABLE | B_NOT_MINIMIZABLE
| B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_ALL_WORKSPACES, false, true),
BContainerWindow(windowList, openFlags, kDesktopWindowLook, kDesktopWindowFeel,
B_NOT_MOVABLE | B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_CLOSABLE
| B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS,
B_ALL_WORKSPACES, false),
fDeskShelf(NULL),
fNodeRef(NULL),
fShortcutsSettings(NULL)

View File

@ -71,21 +71,21 @@ DraggableContainerIcon::MouseDown(BPoint where)
ThrowOnAssert(window != NULL);
// we don't like the Trash icon (because it cannot be moved)
if (window->IsTrash() || window->IsPrintersDir())
if (window->TargetModel()->IsTrash() || window->TargetModel()->IsPrintersDir())
return;
uint32 buttons;
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(),
kNormalIcon, fIconSize)) {
if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(), kNormalIcon, fIconSize)) {
// The click hit the icon, initiate a drag
fDragButton = buttons
& (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON);
fDragStarted = false;
fClickPoint = where;
} else
} else {
fDragButton = 0;
}
if (!fDragButton)
Window()->Activate(true);

View File

@ -2840,6 +2840,22 @@ FSIsDeskDir(const BEntry* entry)
}
bool
FSInDeskDir(const entry_ref* ref)
{
BEntry entry(ref);
if (entry.InitCheck() != B_OK)
return false;
BPath path;
if (find_directory(B_DESKTOP_DIRECTORY, &path, true) != B_OK)
return false;
BDirectory desktop(path.Path());
return desktop.Contains(&entry);
}
bool
FSIsHomeDir(const BEntry* entry)
{
@ -2847,6 +2863,14 @@ FSIsHomeDir(const BEntry* entry)
}
bool
FSIsQueriesDir(const entry_ref* ref)
{
const BEntry entry(ref);
return DirectoryMatches(&entry, "queries", B_USER_DIRECTORY);
}
bool
FSIsRootDir(const BEntry* entry)
{
@ -2858,6 +2882,18 @@ FSIsRootDir(const BEntry* entry)
}
bool
FSInRootDir(const entry_ref* ref)
{
BEntry entry(ref);
if (entry.InitCheck() != B_OK)
return false;
BDirectory root("/");
return root.Contains(&entry);
}
bool
DirectoryMatchesOrContains(const BEntry* entry, directory_which which)
{

View File

@ -207,6 +207,9 @@ _IMPEXP_TRACKER status_t FSRecursiveCalcSize(BInfoWindow*,
CopyLoopControl* loopControl, BDirectory*, off_t* runningSize,
int32* fileCount, int32* dirCount);
bool FSInDeskDir(const entry_ref*);
bool FSIsQueriesDir(const entry_ref*);
bool FSInRootDir(const entry_ref*);
bool FSInTrashDir(const entry_ref*);
// doesn't need to be exported

View File

@ -547,17 +547,13 @@ TFilePanel::SetTo(const entry_ref* ref)
if (ref == NULL)
return;
entry_ref setToRef(*ref);
bool isDesktop = SwitchDirToDesktopIfNeeded(setToRef);
BEntry entry(&setToRef);
BEntry entry(ref);
if (entry.InitCheck() != B_OK || !entry.IsDirectory())
return;
PoseView()->SetIsDesktop(isDesktop);
PoseView()->SwitchDir(&setToRef);
SwitchDirMenuTo(&setToRef);
entry_ref _ref(*ref);
PoseView()->SetIsDesktop(SwitchDirToDesktopIfNeeded(_ref));
SwitchDirMenuTo(&_ref);
AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome));
// our shortcut got possibly removed because the home
@ -970,7 +966,7 @@ TFilePanel::AddFileContextMenus(BMenu* menu)
menu->AddItem(new BMenuItem(B_TRANSLATE("Duplicate"),
new BMessage(kDuplicateSelection), 'D'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Move to Trash"),
new BMessage(kMoveToTrash), 'T'));
new BMessage(kMoveSelectionToTrash), 'T'));
menu->AddSeparatorItem();
BMenuItem* cutItem = new BMenuItem(B_TRANSLATE("Cut"),
@ -1077,7 +1073,7 @@ TFilePanel::MenusBeginning()
&& !PoseView()->TargetVolumeIsReadOnly());
EnableNamedMenuItem(fMenuBar, kDuplicateSelection,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(fMenuBar, kMoveToTrash,
EnableNamedMenuItem(fMenuBar, kMoveSelectionToTrash,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(fMenuBar, kEditItem, PoseView()->CanEditName());
@ -1125,7 +1121,7 @@ TFilePanel::ShowContextMenu(BPoint where, const entry_ref* ref)
PoseView()->CanEditName());
EnableNamedMenuItem(fContextMenu, kDuplicateSelection,
PoseView()->CanMoveToTrashOrDuplicate());
EnableNamedMenuItem(fContextMenu, kMoveToTrash,
EnableNamedMenuItem(fContextMenu, kMoveSelectionToTrash,
PoseView()->CanMoveToTrashOrDuplicate());
SetCutItem(fContextMenu);

View File

@ -808,6 +808,28 @@ Model::SetPreferredAppSignature(const char* signature)
}
bool
Model::IsPrintersDir() const
{
BEntry entry(EntryRef());
return FSIsPrintersDir(&entry);
}
bool
Model::InRoot() const
{
return FSInRootDir(EntryRef());
}
bool
Model::InTrash() const
{
return FSInTrashDir(EntryRef());
}
const Model*
Model::ResolveIfLink() const
{

View File

@ -127,16 +127,19 @@ public:
void SetPreferredAppSignature(const char*);
// type getters
bool IsFile() const;
bool IsContainer() const;
bool IsDesktop() const;
bool IsDirectory() const;
bool IsFile() const;
bool IsQuery() const;
bool IsQueryTemplate() const;
bool IsContainer() const;
bool IsExecutable() const;
bool IsPrintersDir() const;
bool IsSymLink() const;
bool InRoot() const;
bool IsRoot() const;
bool InTrash() const;
bool IsTrash() const;
bool IsDesktop() const;
bool IsVolume() const;
bool IsVirtualDirectory() const;
@ -377,31 +380,57 @@ Model::LinkTo() const
inline bool
Model::IsFile() const
Model::IsContainer() const
{
return fBaseType == kPlainNode
|| fBaseType == kQueryNode
|| fBaseType == kQueryTemplateNode
|| fBaseType == kExecutableNode
|| fBaseType == kVirtualDirectoryNode;
// I guess as in should show container window -
// volumes show the volume window
return IsQuery() || IsDirectory() || IsVirtualDirectory();
}
inline bool
Model::IsVolume() const
Model::IsDesktop() const
{
return fBaseType == kVolumeNode;
return fBaseType == kDesktopNode;
}
inline bool
Model::IsDirectory() const
{
return fBaseType == kDirectoryNode
|| fBaseType == kVolumeNode
|| fBaseType == kRootNode
|| fBaseType == kTrashNode
|| fBaseType == kDesktopNode;
switch (fBaseType) {
case kDirectoryNode:
case kVolumeNode:
case kRootNode:
case kTrashNode:
case kDesktopNode:
return true;
}
return false;
}
inline bool
Model::IsFile() const
{
switch (fBaseType) {
case kPlainNode:
case kQueryNode:
case kQueryTemplateNode:
case kExecutableNode:
case kVirtualDirectoryNode:
return true;
}
return false;
}
inline bool
Model::IsExecutable() const
{
return fBaseType == kExecutableNode;
}
@ -420,11 +449,9 @@ Model::IsQueryTemplate() const
inline bool
Model::IsContainer() const
Model::IsSymLink() const
{
// I guess as in should show container window -
// volumes show the volume window
return IsQuery() || IsDirectory() || IsVirtualDirectory();
return fBaseType == kLinkNode;
}
@ -442,27 +469,6 @@ Model::IsTrash() const
}
inline bool
Model::IsDesktop() const
{
return fBaseType == kDesktopNode;
}
inline bool
Model::IsExecutable() const
{
return fBaseType == kExecutableNode;
}
inline bool
Model::IsSymLink() const
{
return fBaseType == kLinkNode;
}
inline bool
Model::IsVirtualDirectory() const
{
@ -470,6 +476,13 @@ Model::IsVirtualDirectory() const
}
inline bool
Model::IsVolume() const
{
return fBaseType == kVolumeNode;
}
inline bool
Model::HasLocalizedName() const
{

View File

@ -266,7 +266,6 @@ BPoseView::BPoseView(Model* model, uint32 viewMode)
fOkToMapIcons(false),
fEnsurePosesVisible(false),
fShouldAutoScroll(true),
fIsDesktopWindow(false),
fIsWatchingDateFormatChange(false),
fHasPosesInClipboard(false),
fCursorCheck(false),
@ -329,8 +328,6 @@ BPoseView::Init(const BMessage &message)
void
BPoseView::InitCommon()
{
BContainerWindow* window = ContainerWindow();
// Create the TitleView and CountView
fTitleView = new BTitleView(this);
if (ViewMode() != kListMode)
@ -363,7 +360,7 @@ BPoseView::InitCommon()
// turn on volume node monitor, metamime monitor, etc.
// populate the window
if (window != NULL && window->IsTrash())
if (TargetModel() != NULL && TargetModel()->IsTrash())
AddTrashPoses();
else
AddPoses(TargetModel());
@ -392,7 +389,7 @@ BPoseView::RestoreColumnState(AttributeStreamNode* node)
if (node != NULL) {
const char* columnsAttr;
const char* columnsAttrForeign;
if (TargetModel() && TargetModel()->IsRoot()) {
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
columnsAttr = kAttrDisksColumns;
columnsAttrForeign = kAttrDisksColumnsForeign;
} else {
@ -513,7 +510,7 @@ BPoseView::RestoreState(AttributeStreamNode* node)
const char* viewStateAttr;
const char* viewStateAttrForeign;
if (TargetModel() && TargetModel()->IsRoot()) {
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
viewStateAttr = kAttrDisksViewState;
viewStateAttrForeign = kAttrDisksViewStateForeign;
} else {
@ -551,7 +548,7 @@ BPoseView::RestoreState(AttributeStreamNode* node)
}
}
if (IsDesktopWindow() && ViewMode() == kListMode) {
if (IsDesktop() && ViewMode() == kListMode) {
// recover if desktop window view state set wrong
fViewState->SetViewMode(kIconMode);
}
@ -569,7 +566,7 @@ BPoseView::RestoreState(const BMessage &message)
fViewState = viewstate;
}
if (IsDesktopWindow() && ViewMode() == kListMode) {
if (IsDesktop() && ViewMode() == kListMode) {
// recover if desktop window view state set wrong
fViewState->SetViewMode(kIconMode);
}
@ -658,7 +655,7 @@ BPoseView::SaveColumnState(AttributeStreamNode* node)
const char* columnsAttr;
const char* columnsAttrForeign;
if (TargetModel() && TargetModel()->IsRoot()) {
if (TargetModel() != NULL && TargetModel()->IsRoot()) {
columnsAttr = kAttrDisksColumns;
columnsAttrForeign = kAttrDisksColumnsForeign;
} else {
@ -762,7 +759,7 @@ BPoseView::SavePoseLocations(BRect* frameIfDesktop)
return;
}
bool isDesktop = IsDesktopWindow() && (frameIfDesktop != NULL);
bool isDesktop = IsDesktop() && (frameIfDesktop != NULL);
int32 poseCount = fPoseList->CountItems();
for (int32 index = 0; index < poseCount; index++) {
@ -968,8 +965,8 @@ BPoseView::ScrollTo(BPoint where)
void
BPoseView::AttachedToWindow()
{
fIsDesktopWindow = dynamic_cast<BDeskWindow*>(Window()) != NULL;
if (fIsDesktopWindow)
fIsDesktop = dynamic_cast<BDeskWindow*>(Window()) != NULL;
if (fIsDesktop)
AddFilter(new TPoseViewFilter(this));
else
ApplyBackgroundColor();
@ -1781,7 +1778,7 @@ BPoseView::FinishPendingScroll(float &listViewScrollBy, BRect srcRect)
bool
BPoseView::AddPosesThreadValid(const entry_ref* ref) const
{
return *(TargetModel()->EntryRef()) == *ref || ContainerWindow()->IsTrash();
return *(TargetModel()->EntryRef()) == *ref || TargetModel()->IsTrash();
}
@ -2391,15 +2388,15 @@ BPoseView::MessageReceived(BMessage* message)
OpenSelectionUsing();
break;
case kRestoreFromTrash:
case kRestoreSelectionFromTrash:
RestoreSelectionFromTrash();
break;
case kDelete:
case kDeleteSelection:
DoDelete();
break;
case kMoveToTrash:
case kMoveSelectionToTrash:
DoMoveToTrash();
break;
@ -2441,14 +2438,8 @@ BPoseView::MessageReceived(BMessage* message)
break;
case kIdentifyEntry:
{
bool force;
if (message->FindBool("force", &force) != B_OK)
force = false;
IdentifySelection(force);
IdentifySelection(message->GetBool("force", false));
break;
}
case kEditItem:
{
@ -3076,7 +3067,7 @@ BPoseView::SetViewMode(uint32 newMode)
// if we are the desktop.
BPoint scaleOffset(0, 0);
bool iconSizeChanged = newMode == kIconMode && oldMode == kIconMode;
if (!IsDesktopWindow() && iconSizeChanged) {
if (!IsDesktop() && iconSizeChanged) {
// definitely changing the icon size, so we will need to scroll
BRect bounds(Bounds());
BPoint center(bounds.LeftTop());
@ -3121,7 +3112,7 @@ BPoseView::SetViewMode(uint32 newMode)
}
// check if we need to re-place poses when they are out of view
bool checkLocations = IsDesktopWindow() && iconSizeChanged;
bool checkLocations = IsDesktop() && iconSizeChanged;
BPoint oldOffset;
BPoint oldGrid;
@ -3579,7 +3570,7 @@ BPoseView::PlacePose(BPose* pose, BRect &viewBounds)
// make pose rect a little bigger to ensure space between poses
rect.InsetBy(-3, 0);
bool checkValidLocation = IsDesktopWindow();
bool checkValidLocation = IsDesktop();
// find an empty slot to put pose into
while (SlotOccupied(rect, viewBounds)
@ -3608,7 +3599,7 @@ BPoseView::PlacePose(BPose* pose, BRect &viewBounds)
bool
BPoseView::IsValidLocation(const BPose* pose)
{
if (!IsDesktopWindow())
if (!IsDesktop())
return true;
BRect rect(pose->CalcRect(this));
@ -3620,7 +3611,7 @@ BPoseView::IsValidLocation(const BPose* pose)
bool
BPoseView::IsValidLocation(const BRect& rect)
{
if (!IsDesktopWindow())
if (!IsDesktop())
return true;
// on the desktop, don't allow icons outside of the view bounds
@ -3698,7 +3689,7 @@ BPoseView::CheckAutoPlacedPoses()
void
BPoseView::CheckPoseVisibility(BRect* newFrame)
{
bool desktop = IsDesktopWindow() && newFrame != 0;
bool desktop = IsDesktop() && newFrame != 0;
BRect deskFrame;
if (desktop) {
@ -4014,7 +4005,7 @@ BPoseView::ScrollIntoView(BPose* pose, int32 index)
void
BPoseView::ScrollIntoView(BRect poseRect)
{
if (IsDesktopWindow())
if (IsDesktop())
return;
BPoint oldPos = Bounds().LeftTop(), newPos = oldPos;
@ -5489,7 +5480,7 @@ BPoseView::FSNotification(const BMessage* message)
BVolume volume(device);
if (volume.InitCheck() == B_OK)
CreateVolumePose(&volume, false);
} else if (ContainerWindow()->IsTrash()) {
} else if (TargetModel()->IsTrash()) {
// add trash items from newly mounted volume
BDirectory trashDir;
@ -5649,14 +5640,15 @@ BPoseView::EntryMoved(const BMessage* message)
ThrowOnAssert(targetModel != NULL);
node_ref thisDirNode;
if (ContainerWindow()->IsTrash()) {
if (TargetModel()->IsTrash()) {
BDirectory trashDir;
if (FSGetTrashDir(&trashDir, itemNode.device) != B_OK)
return true;
trashDir.GetNodeRef(&thisDirNode);
} else
} else {
thisDirNode = *targetModel->NodeRef();
}
// see if we need to update window title (and folder itself)
if (thisDirNode == itemNode) {
@ -5720,10 +5712,11 @@ BPoseView::EntryMoved(const BMessage* message)
}
if (pose != NULL)
pendingNodeMonitorCache.PoseCreatedOrMoved(this, pose);
} else if (oldDir == thisDirNode.node)
} else if (oldDir == thisDirNode.node) {
DeletePose(&itemNode);
else if (dirNode.node == thisDirNode.node)
} else if (dirNode.node == thisDirNode.node) {
EntryCreated(&dirNode, &itemNode, name);
}
TryUpdatingBrokenLinks();
@ -7101,8 +7094,7 @@ BPoseView::ShowContextMenu(BPoint where)
window->Activate();
window->UpdateIfNeeded();
window->ShowContextMenu(where, pose == NULL ? NULL
: pose->TargetModel()->EntryRef());
window->ShowContextMenu(where, pose == NULL ? NULL : pose->TargetModel()->EntryRef());
if (fSelectionChangedHook)
window->SelectionChanged();
@ -7365,7 +7357,7 @@ BPoseView::MouseDown(BPoint where)
if (window == NULL)
return;
if (IsDesktopWindow()) {
if (IsDesktop()) {
BScreen screen(Window());
rgb_color color = screen.DesktopColor();
SetLowColor(color);
@ -8202,13 +8194,9 @@ BPoseView::OpenSelection(BPose* clickedPose, int32* index)
}
// check if we can use the single window mode
if (settings.SingleWindowBrowse()
&& !IsDesktopWindow()
&& !IsFilePanel()
&& (modifiers() & B_OPTION_KEY) == 0
&& TargetModel()->IsDirectory()
&& singleWindowBrowsePose
&& singleWindowBrowsePose->ResolvedModel()
if (settings.SingleWindowBrowse() && !IsDesktop() && !IsFilePanel()
&& (modifiers() & B_OPTION_KEY) == 0 && TargetModel()->IsDirectory()
&& singleWindowBrowsePose && singleWindowBrowsePose->ResolvedModel()
&& singleWindowBrowsePose->ResolvedModel()->IsDirectory()) {
// Switch to new directory
BMessage msg(kSwitchDirectory);
@ -8218,7 +8206,6 @@ BPoseView::OpenSelection(BPose* clickedPose, int32* index)
// otherwise use standard method
OpenSelectionCommon(clickedPose, index, false);
}
}
@ -8245,11 +8232,8 @@ BPoseView::OpenSelectionCommon(BPose* clickedPose, int32* poseIndex,
// close parent window if option down and we're not the desktop
// and we're not in single window mode
if (dynamic_cast<TTracker*>(be_app) == NULL
|| (modifiers() & B_OPTION_KEY) == 0
|| IsFilePanel()
|| IsDesktopWindow()
|| TrackerSettings().SingleWindowBrowse()) {
if (dynamic_cast<TTracker*>(be_app) == NULL || (modifiers() & B_OPTION_KEY) == 0
|| IsFilePanel() || IsDesktop() || TrackerSettings().SingleWindowBrowse()) {
continue;
}
@ -8315,6 +8299,39 @@ BPoseView::ApplyBackgroundColor()
}
bool
BPoseView::CanUnmountSelection()
{
int32 selectCount = CountSelected();
if (selectCount == 0)
return false;
BVolume boot;
BVolumeRoster().GetBootVolume(&boot);
for (int32 index = 0; index < selectCount; index++) {
BPose* pose = fSelectionList->ItemAt(index);
if (pose == NULL)
continue;
// only volumes are unmountable
Model* model = pose->TargetModel();
if (!model->IsVolume())
return false;
BVolume volume(model->NodeRef()->device);
if (volume.InitCheck() != B_OK)
continue;
// boot volume is unmountable
if (volume == boot)
return false;
}
return true;
}
void
BPoseView::UnmountSelectedVolumes()
{
@ -8327,19 +8344,22 @@ BPoseView::UnmountSelectedVolumes()
if (pose == NULL)
continue;
// only volumes are unmountable
Model* model = pose->TargetModel();
if (model->IsVolume()) {
BVolume volume(model->NodeRef()->device);
if (volume != boot) {
TTracker* tracker = dynamic_cast<TTracker*>(be_app);
if (tracker != NULL)
tracker->SaveAllPoseLocations();
if (!model->IsVolume())
continue;
BMessage message(kUnmountVolume);
message.AddInt32("device_id", volume.Device());
be_app->PostMessage(&message);
}
}
BVolume volume(model->NodeRef()->device);
if (volume.InitCheck() != B_OK)
continue;
// skip boot volume
if (volume == boot)
continue;
BMessage message(kUnmountVolume);
message.AddInt32("device_id", volume.Device());
be_app->PostMessage(&message);
}
}
@ -8401,12 +8421,6 @@ BPoseView::SwitchDir(const entry_ref* newDirRef, AttributeStreamNode* node)
delete fModel;
fModel = model;
// check if model is a trash dir, if so
// update ContainerWindow's fIsTrash, etc.
// variables to indicate new state
if (ContainerWindow() != NULL)
ContainerWindow()->UpdateIfTrash(model);
StopWatching();
ClearPoses();
@ -8460,13 +8474,13 @@ BPoseView::SwitchDir(const entry_ref* newDirRef, AttributeStreamNode* node)
// be sure this happens after origin is set and window is sized
// properly for proper icon caching!
if (ContainerWindow() != NULL && ContainerWindow()->IsTrash())
if (TargetModel() != NULL && TargetModel()->IsTrash())
AddTrashPoses();
else
AddPoses(TargetModel());
TargetModel()->CloseNode();
if (!IsDesktopWindow()) {
if (!IsDesktop()) {
ApplyBackgroundColor();
if (ContainerWindow() != NULL)
ContainerWindow()->UpdateBackgroundImage();
@ -8608,38 +8622,25 @@ BPoseView::SetDefaultPrinter()
void
BPoseView::OpenParent()
{
if (!TargetModel() || TargetModel()->IsRoot() || IsDesktopWindow())
if (ParentIsRoot())
return;
BEntry entry(TargetModel()->EntryRef());
entry_ref ref;
if (FSGetParentVirtualDirectoryAware(entry, entry) != B_OK
|| entry.GetRef(&ref) != B_OK)
if (FSGetParentVirtualDirectoryAware(entry, entry) != B_OK || entry.GetRef(&ref) != B_OK)
return;
BEntry root("/");
if (!TrackerSettings().SingleWindowBrowse()
&& !TrackerSettings().ShowNavigator()
&& !TrackerSettings().ShowDisksIcon() && entry == root
&& (modifiers() & B_CONTROL_KEY) == 0)
return;
Model parentModel(&ref);
BMessage message(B_REFS_RECEIVED);
message.AddRef("refs", &ref);
if (dynamic_cast<TTracker*>(be_app)) {
// add information about the child, so that we can select it
// in the parent view
message.AddData("nodeRefToSelect", B_RAW_TYPE, TargetModel()->NodeRef(),
sizeof (node_ref));
if (dynamic_cast<TTracker*>(be_app) != NULL) {
// add information about the child, so that we can select it in the parent view
message.AddData("nodeRefToSelect", B_RAW_TYPE, TargetModel()->NodeRef(), sizeof(node_ref));
if ((modifiers() & B_OPTION_KEY) != 0 && !IsFilePanel()) {
// if option down, add instructions to close the parent
message.AddData("nodeRefsToClose", B_RAW_TYPE,
TargetModel()->NodeRef(), sizeof (node_ref));
message.AddData("nodeRefsToClose", B_RAW_TYPE, TargetModel()->NodeRef(),
sizeof(node_ref));
}
}
@ -8647,8 +8648,28 @@ BPoseView::OpenParent()
BMessage msg(kSwitchDirectory);
msg.AddRef("refs", &ref);
Window()->PostMessage(&msg);
} else
} else {
be_app->PostMessage(&message);
}
}
bool
BPoseView::ParentIsRoot()
{
if (TargetModel()->IsDesktop() || TargetModel()->IsRoot())
return true;
// override by holding control key
if ((modifiers() & B_CONTROL_KEY) != 0)
return false;
BEntry entry(TargetModel()->EntryRef());
bool isRoot = FSGetParentVirtualDirectoryAware(entry, entry) == B_OK && FSIsRootDir(&entry);
if (isRoot && (TrackerSettings().SingleWindowBrowse() || TrackerSettings().ShowDisksIcon()))
return false;
return isRoot;
}
@ -8838,6 +8859,7 @@ bool
BPoseView::SelectedVolumeIsReadOnly() const
{
BVolume volume;
BPose* pose;
BEntry entry;
BNode parent;
node_ref nref;
@ -8847,7 +8869,7 @@ BPoseView::SelectedVolumeIsReadOnly() const
// multiple items selected in query, consider the whole selection
// to be read-only if any item's volume is read-only
for (int32 i = 0; i < selectCount; i++) {
BPose* pose = fSelectionList->ItemAt(i);
pose = fSelectionList->ItemAt(i);
if (pose == NULL || pose->TargetModel() == NULL)
continue;
@ -8861,7 +8883,11 @@ BPoseView::SelectedVolumeIsReadOnly() const
}
} else if (selectCount > 0) {
// only check first item's volume, assume rest are the same
entry.SetTo(fSelectionList->FirstItem()->TargetModel()->EntryRef());
pose = fSelectionList->FirstItem();
if (pose->TargetModel()->IsRoot())
return true;
entry.SetTo(pose->TargetModel()->EntryRef());
if (FSGetParentVirtualDirectoryAware(entry, parent) == B_OK) {
parent.GetNodeRef(&nref);
volume.SetTo(nref.device);
@ -8881,8 +8907,7 @@ BPoseView::TargetVolumeIsReadOnly() const
Model* target = TargetModel();
BVolume volume(target->NodeRef()->device);
return target->IsQuery() || target->IsQueryTemplate()
|| target->IsVirtualDirectory()
return target->IsQuery() || target->IsQueryTemplate() || target->IsVirtualDirectory()
|| (volume.InitCheck() == B_OK && volume.IsReadOnly());
}
@ -9120,7 +9145,7 @@ BPoseView::BackColor(bool selected) const
void
BPoseView::Draw(BRect updateRect)
{
if (IsDesktopWindow()) {
if (IsDesktop()) {
BScreen screen(Window());
rgb_color color = screen.DesktopColor();
SetLowColor(color);
@ -9219,7 +9244,7 @@ BPoseView::ColumnRedraw(BRect updateRect)
ASSERT(ViewMode() == kListMode);
#if COLUMN_MODE_ON_DESKTOP
if (IsDesktopWindow()) {
if (IsDesktop()) {
BScreen screen(Window());
rgb_color d = screen.DesktopColor();
SetLowColor(d);

View File

@ -101,7 +101,7 @@ public:
Model* TargetModel() const;
virtual bool IsFilePanel() const;
bool IsDesktopWindow() const;
bool IsDesktop() const;
virtual bool IsDesktopView() const;
// state saving/restoring
@ -270,8 +270,13 @@ public:
void SetDefaultPrinter();
void IdentifySelection(bool force = false);
// unmounting
bool CanUnmountSelection();
void UnmountSelectedVolumes();
virtual void OpenParent();
virtual bool ParentIsRoot();
virtual void OpenSelection(BPose* clicked_pose = NULL,
int32* index = NULL);
@ -796,7 +801,7 @@ private:
bool fOkToMapIcons : 1;
bool fEnsurePosesVisible : 1;
bool fShouldAutoScroll : 1;
bool fIsDesktopWindow : 1;
bool fIsDesktop : 1;
bool fIsWatchingDateFormatChange : 1;
bool fHasPosesInClipboard : 1;
bool fCursorCheck : 1;
@ -1013,9 +1018,9 @@ BPoseView::IsFilePanel() const
inline bool
BPoseView::IsDesktopWindow() const
BPoseView::IsDesktop() const
{
return fIsDesktopWindow;
return fIsDesktop;
}

View File

@ -373,11 +373,10 @@ TTracker::QuitRequested()
= dynamic_cast<BContainerWindow*>(fWindowList.ItemAt(i));
if (window != NULL && window->Lock()) {
if (window->TargetModel() != NULL
&& !window->PoseView()->IsDesktopWindow()) {
if (window->TargetModel()->IsRoot())
if (window->TargetModel() != NULL && !window->TargetModel()->IsDesktop()) {
if (window->TargetModel()->IsRoot()) {
message.AddBool("open_disks_window", true);
else {
} else {
BEntry entry;
BPath path;
const entry_ref* ref = window->TargetModel()->EntryRef();
@ -486,7 +485,7 @@ TTracker::MessageReceived(BMessage* message)
OpenInfoWindows(message);
break;
case kMoveToTrash:
case kMoveSelectionToTrash:
MoveRefsToTrash(message);
break;
@ -1086,8 +1085,7 @@ TTracker::OpenContainerWindow(Model* model, BMessage* originalRefsList,
int32 windowCount = 0;
while (window != NULL) {
if ((window->Workspaces() & workspace) != 0
&& (dynamic_cast<BDeskWindow*>(window) == NULL
|| !TrackerSettings().SingleWindowBrowse())) {
&& (!model->IsDesktop() || !TrackerSettings().SingleWindowBrowse())) {
// We found at least one window that is open and is not Desktop
// or we're in spatial mode, activate it and make sure we don't
// jerk the workspaces around.
@ -1131,7 +1129,7 @@ TTracker::OpenContainerWindow(Model* model, BMessage* originalRefsList,
window = new BContainerWindow(&fWindowList, openFlags);
}
if (model != NULL && window->LockLooper()) {
if (model != NULL && window != NULL && window->LockLooper()) {
window->CreatePoseView(model);
if (window->PoseView() == NULL) {
// Failed initialization.

View File

@ -64,9 +64,9 @@ VirtualDirectoryPoseView::MessageReceived(BMessage* message)
case B_CUT:
case B_PASTE:
case kCutMoreSelectionToClipboard:
case kDelete:
case kDeleteSelection:
case kDuplicateSelection:
case kMoveToTrash:
case kMoveSelectionToTrash:
case kNewEntryFromTemplate:
case kNewFolder:
break;