Tracker: Style fixes

This commit is contained in:
John Scipione
2014-06-10 00:36:10 -04:00
parent 12bd3f0452
commit 9437e677ba
18 changed files with 304 additions and 194 deletions
+107 -70
View File
@@ -32,9 +32,8 @@ names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#include <string.h>
#include <stdlib.h>
#include <image.h>
#include "ContainerWindow.h"
#include <Alert.h>
#include <Application.h>
@@ -59,6 +58,9 @@ All rights reserved.
#include <Roster.h>
#include <fs_attr.h>
#include <image.h>
#include <string.h>
#include <stdlib.h>
#include <memory>
@@ -67,7 +69,6 @@ All rights reserved.
#include "AutoLock.h"
#include "BackgroundImage.h"
#include "Commands.h"
#include "ContainerWindow.h"
#include "CountView.h"
#include "DeskWindow.h"
#include "FavoritesMenu.h"
@@ -95,6 +96,7 @@ All rights reserved.
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ContainerWindow"
const uint32 kRedo = 'REDO';
// this is the same as B_REDO in Dano/Zeta/Haiku
@@ -104,9 +106,11 @@ _IMPEXP_BE
#endif
void do_minimize_team(BRect zoomRect, team_id team, bool zoom);
// Amount you have to move the mouse before a drag starts
const float kDragSlop = 3.0f;
namespace BPrivate {
class DraggableContainerIcon : public BView {
@@ -130,6 +134,7 @@ class DraggableContainerIcon : public BView {
} // namespace BPrivate
struct AddOneAddonParams {
BObjectList<BMenuItem>* primaryList;
BObjectList<BMenuItem>* secondaryList;
@@ -139,16 +144,19 @@ struct StaggerOneParams {
bool rectFromParent;
};
const int32 kContainerWidthMinLimit = 120;
const int32 kContainerWindowHeightLimit = 85;
const int32 kWindowStaggerBy = 17;
BRect BContainerWindow::sNewWindRect(85, 50, 548, 280);
LockingList<AddonShortcut>* BContainerWindow::fAddonsList
= new LockingList<struct AddonShortcut>(10, true);
namespace BPrivate {
filter_result
@@ -276,6 +284,7 @@ OffsetFrameOne(const char* DEBUG_ONLY(name), uint32, off_t, void* castToRect,
return false;
((BRect*)castToRect)->OffsetBy(kWindowStaggerBy, kWindowStaggerBy);
return true;
}
@@ -294,6 +303,7 @@ AddMimeTypeString(BObjectList<BString> &list, Model* model)
return;
}
}
list.AddItem(mimeType);
}
}
@@ -304,7 +314,8 @@ AddMimeTypeString(BObjectList<BString> &list, Model* model)
DraggableContainerIcon::DraggableContainerIcon(BRect rect, const char* name,
uint32 resizeMask)
: BView(rect, name, resizeMask, B_WILL_DRAW | B_FRAME_EVENTS),
:
BView(rect, name, resizeMask, B_WILL_DRAW | B_FRAME_EVENTS),
fDragButton(0),
fDragStarted(false)
{
@@ -383,7 +394,7 @@ DraggableContainerIcon::MouseMoved(BPoint point, uint32 /*transit*/,
float height = ceilf(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading + 2 + Bounds().Height() + 8);
BRect rect(0, 0, max_c(Bounds().Width(),
BRect rect(0, 0, std::max(Bounds().Width(),
font.StringWidth(model->Name()) + 4), height);
BBitmap* dragBitmap = new BBitmap(rect, B_RGBA32, true);
@@ -571,9 +582,9 @@ BContainerWindow::BContainerWindow(LockingList<BWindow>* list,
}
// ToDo: remove me once we have undo/redo menu items
// (that is, move them to AddShortcuts())
AddShortcut('Z', B_COMMAND_KEY, new BMessage(B_UNDO), this);
AddShortcut('Z', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kRedo), this);
// (that is, move them to AddShortcuts())
AddShortcut('Z', B_COMMAND_KEY, new BMessage(B_UNDO), this);
AddShortcut('Z', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kRedo), this);
}
@@ -596,7 +607,7 @@ BContainerWindow::~BContainerWindow()
delete fDragMessage;
delete fCachedTypesList;
if (fSelectionWindow && fSelectionWindow->Lock())
if (fSelectionWindow != NULL && fSelectionWindow->Lock())
fSelectionWindow->Quit();
}
@@ -631,9 +642,10 @@ BContainerWindow::QuitRequested()
// means to say close all your windows. It might be better to have it
// send a kCloseAllWindows message and have windowless apps stay running,
// which is what we will do for the Tracker
if (CurrentMessage()
&& (CurrentMessage()->FindInt32("modifiers") & B_CONTROL_KEY))
if (CurrentMessage() != NULL
&& ((CurrentMessage()->FindInt32("modifiers") & B_CONTROL_KEY)) != 0) {
be_app->PostMessage(kCloseAllWindows);
}
Hide();
// this will close the window instantly, even if
@@ -739,18 +751,17 @@ BContainerWindow::CreatePoseView(Model* model)
BRect rect(Bounds());
TrackerSettings settings;
if (settings.SingleWindowBrowse()
&& settings.ShowNavigator()
&& model->IsDirectory())
if (settings.SingleWindowBrowse() && settings.ShowNavigator()
&& model->IsDirectory()) {
rect.top += BNavigator::CalcNavigatorHeight() + 1;
}
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
fPoseView = NewPoseView(model, rect, kListMode);
AddChild(fPoseView);
if (settings.SingleWindowBrowse()
&& model->IsDirectory()
if (settings.SingleWindowBrowse() && model->IsDirectory()
&& !fPoseView->IsFilePanel()) {
BRect rect(Bounds());
rect.top = 0;
@@ -760,8 +771,10 @@ BContainerWindow::CreatePoseView(Model* model)
fNavigator = new BNavigator(model, rect);
if (!settings.ShowNavigator())
fNavigator->Hide();
AddChild(fNavigator);
}
SetPathWatchingEnabled(settings.ShowNavigator()
|| settings.ShowFullPathInTitleBar());
}
@@ -996,9 +1009,10 @@ BContainerWindow::Init(const BMessage* message)
MarkAttributeMenu(fAttrMenu);
CheckScreenIntersect();
if (fBackgroundImage && !dynamic_cast<BDeskWindow*>(this)
&& PoseView()->ViewMode() != kListMode)
if (fBackgroundImage != NULL && dynamic_cast<BDeskWindow*>(this) == NULL
&& PoseView()->ViewMode() != kListMode) {
fBackgroundImage->Show(PoseView(), current_workspace());
}
Show();
@@ -1048,8 +1062,8 @@ BContainerWindow::RestoreStateCommon()
WindowStateNodeOpener opener(this, false);
bool isDesktop = dynamic_cast<BDeskWindow*>(this);
if (!TargetModel()->IsRoot() && opener.Node())
bool isDesktop = dynamic_cast<BDeskWindow*>(this) != NULL;
if (!TargetModel()->IsRoot() && opener.Node()) {
// 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
@@ -1058,13 +1072,15 @@ BContainerWindow::RestoreStateCommon()
fBackgroundImage = BackgroundImage::GetBackgroundImage(
opener.Node(), isDesktop);
// look for background image info in the window's node
}
BNode defaultingNode;
if (!fBackgroundImage && !isDesktop
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode))
if (fBackgroundImage == NULL && !isDesktop
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode)) {
// look for background image info in the source for defaults
fBackgroundImage
= BackgroundImage::GetBackgroundImage(&defaultingNode, isDesktop);
fBackgroundImage = BackgroundImage::GetBackgroundImage(&defaultingNode,
isDesktop);
}
}
@@ -1077,13 +1093,15 @@ BContainerWindow::UpdateTitle()
BPath path;
TargetModel()->GetPath(&path);
SetTitle(path.Path());
} else
} else {
// use the default look
SetTitle(TargetModel()->Name());
}
if (Navigator())
if (Navigator() != NULL) {
Navigator()->UpdateLocation(PoseView()->TargetModel(),
kActionUpdatePath);
}
}
@@ -1096,24 +1114,26 @@ BContainerWindow::UpdateBackgroundImage()
bool isDesktop = dynamic_cast<BDeskWindow*>(this) != NULL;
WindowStateNodeOpener opener(this, false);
if (!TargetModel()->IsRoot() && opener.Node())
if (!TargetModel()->IsRoot() && opener.Node()) {
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage,
opener.Node(), isDesktop, PoseView());
}
// look for background image info in the window's node
BNode defaultingNode;
if (!fBackgroundImage && !isDesktop
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode))
&& DefaultStateSourceNode(kDefaultFolderTemplate, &defaultingNode)) {
// look for background image info in the source for defaults
fBackgroundImage = BackgroundImage::Refresh(fBackgroundImage,
&defaultingNode, isDesktop, PoseView());
}
}
void
BContainerWindow::FrameResized(float, float)
{
if (PoseView() && dynamic_cast<BDeskWindow*>(this) == NULL) {
if (PoseView() != NULL && dynamic_cast<BDeskWindow*>(this) == NULL) {
BRect extent = PoseView()->Extent();
float offsetX = extent.left - PoseView()->Bounds().left;
float offsetY = extent.top - PoseView()->Bounds().top;
@@ -1170,7 +1190,7 @@ BContainerWindow::ViewModeChanged(uint32 oldMode, uint32 newMode)
view->FrameMoved(view->Frame().LeftTop());
}
if (!fBackgroundImage)
if (fBackgroundImage == NULL)
return;
if (newMode == kListMode)
@@ -1205,8 +1225,10 @@ BContainerWindow::SaveState(bool hide)
WindowStateNodeOpener opener(this, true);
if (opener.StreamNode())
SaveWindowState(opener.StreamNode());
if (hide)
Hide();
if (opener.StreamNode())
fPoseView->SaveState(opener.StreamNode());
@@ -1216,7 +1238,7 @@ BContainerWindow::SaveState(bool hide)
void
BContainerWindow::SaveState(BMessage &message) const
BContainerWindow::SaveState(BMessage& message) const
{
if (SaveStateIsEnabled()) {
SaveWindowState(message);
@@ -1235,8 +1257,7 @@ BContainerWindow::StateNeedsSaving() const
status_t
BContainerWindow::GetLayoutState(BNode* node, BMessage* message)
{
// ToDo:
// get rid of this, use AttrStream instead
// ToDo: get rid of this, use AttrStream instead
status_t result = node->InitCheck();
if (result != B_OK)
return result;
@@ -1254,16 +1275,18 @@ BContainerWindow::GetLayoutState(BNode* node, BMessage* message)
&& strcmp(attrName, kAttrColumns) != 0
&& strcmp(attrName, kAttrViewState) != 0
&& strcmp(attrName, kAttrColumnsForeign) != 0
&& strcmp(attrName, kAttrViewStateForeign) != 0)
&& strcmp(attrName, kAttrViewStateForeign) != 0) {
continue;
}
char* buffer = new char[info.size];
if (node->ReadAttr(attrName, info.type, 0, buffer,
(size_t)info.size) == info.size) {
message->AddData(attrName, info.type, buffer, (ssize_t)info.size);
}
delete [] buffer;
delete[] buffer;
}
return B_OK;
}
@@ -1305,6 +1328,7 @@ BContainerWindow::SetLayoutState(BNode* node, const BMessage* message)
globalIndex++;
}
}
return B_OK;
}
@@ -1350,9 +1374,8 @@ BContainerWindow::Zoom(BPoint, float, float)
fSavedZoomRect = Frame();
ResizeToFit();
if (fSavedZoomRect == Frame())
if (oldZoomRect.IsValid())
ResizeTo(oldZoomRect.Width(), oldZoomRect.Height());
if (fSavedZoomRect == Frame() && oldZoomRect.IsValid())
ResizeTo(oldZoomRect.Width(), oldZoomRect.Height());
}
@@ -1454,9 +1477,9 @@ BContainerWindow::MessageReceived(BMessage* message)
PoseView()->DuplicateSelection();
else
PoseView()->MoveSelectionInto(&model, this, true);
break;
}
case kMoveSelectionTo:
{
entry_ref ref;
@@ -1748,8 +1771,9 @@ BContainerWindow::SetCopyItem(BMenu* menu)
{
BMenuItem* item;
if ((item = menu->FindItem(B_COPY)) == NULL
&& (item = menu->FindItem(kCopyMoreSelectionToClipboard)) == NULL)
&& (item = menu->FindItem(kCopyMoreSelectionToClipboard)) == NULL) {
return;
}
item->SetEnabled(PoseView()->SelectionList()->CountItems() > 0
|| PoseView() != CurrentFocus());
@@ -1771,8 +1795,9 @@ BContainerWindow::SetPasteItem(BMenu* menu)
{
BMenuItem* item;
if ((item = menu->FindItem(B_PASTE)) == NULL
&& (item = menu->FindItem(kPasteLinksFromClipboard)) == NULL)
&& (item = menu->FindItem(kPasteLinksFromClipboard)) == NULL) {
return;
}
item->SetEnabled(FSClipboardHasRefs() || PoseView() != CurrentFocus());
@@ -1793,8 +1818,9 @@ BContainerWindow::SetArrangeMenu(BMenu* menu)
{
BMenuItem* item;
if ((item = menu->FindItem(kCleanup)) == NULL
&& (item = menu->FindItem(kCleanupAll)) == NULL)
&& (item = menu->FindItem(kCleanupAll)) == NULL) {
return;
}
item->Menu()->SetEnabled(PoseView()->CountItems() > 0
&& (PoseView()->ViewMode() != kListMode));
@@ -1812,6 +1838,7 @@ BContainerWindow::SetArrangeMenu(BMenu* menu)
item->SetMessage(new BMessage(kCleanup));
arrangeMenu = item->Menu();
}
MarkArrangeByMenu(arrangeMenu);
}
@@ -1821,8 +1848,9 @@ BContainerWindow::SetCloseItem(BMenu* menu)
{
BMenuItem* item;
if ((item = menu->FindItem(B_QUIT_REQUESTED)) == NULL
&& (item = menu->FindItem(kCloseAllWindows)) == NULL)
&& (item = menu->FindItem(kCloseAllWindows)) == NULL) {
return;
}
if (modifiers() & B_SHIFT_KEY) {
item->SetLabel(B_TRANSLATE("Close all"));
@@ -1950,8 +1978,10 @@ BContainerWindow::AddFileMenu(BMenu* menu)
menu->SetTargetForItems(PoseView());
if (cutItem)
cutItem->SetTarget(this);
if (copyItem)
copyItem->SetTarget(this);
if (pasteItem)
pasteItem->SetTarget(this);
}
@@ -2142,13 +2172,14 @@ BContainerWindow::AddShortcuts()
void
BContainerWindow::MenusBeginning()
{
if (!fMenuBar)
if (fMenuBar == NULL)
return;
if (CurrentMessage() && CurrentMessage()->what == B_MOUSE_DOWN)
if (CurrentMessage() != NULL && CurrentMessage()->what == B_MOUSE_DOWN) {
// don't commit active pose if only a keyboard shortcut is
// invoked - this would prevent Cut/Copy/Paste from working
fPoseView->CommitActivePose();
}
// File menu
int32 selectCount = PoseView()->SelectionList()->CountItems();
@@ -2185,9 +2216,9 @@ void
BContainerWindow::SetupNavigationMenu(const entry_ref* ref, BMenu* parent)
{
// start by removing nav item (and separator) from old menu
if (fNavigationItem) {
if (fNavigationItem != NULL) {
BMenu* menu = fNavigationItem->Menu();
if (menu) {
if (menu != NULL) {
menu->RemoveItem(fNavigationItem);
BMenuItem* item = menu->RemoveItem((int32)0);
ASSERT(item != fNavigationItem);
@@ -2196,7 +2227,7 @@ BContainerWindow::SetupNavigationMenu(const entry_ref* ref, BMenu* parent)
}
// if we weren't passed a ref then we're navigating this window
if (!ref)
if (ref == NULL)
ref = TargetModel()->EntryRef();
BEntry entry;
@@ -2208,8 +2239,9 @@ BContainerWindow::SetupNavigationMenu(const entry_ref* ref, BMenu* parent)
entry_ref resolvedRef;
if (model.InitCheck() != B_OK
|| (!model.IsContainer() && !model.IsSymLink()))
|| (!model.IsContainer() && !model.IsSymLink())) {
return;
}
if (model.IsSymLink()) {
if (entry.SetTo(model.EntryRef(), true) != B_OK)
@@ -2223,7 +2255,7 @@ BContainerWindow::SetupNavigationMenu(const entry_ref* ref, BMenu* parent)
ref = &resolvedRef;
}
if (!fNavigationItem) {
if (fNavigationItem == NULL) {
fNavigationItem = new ModelMenuItem(&model,
new BNavMenu(model.Name(), B_REFS_RECEIVED, be_app, this));
}
@@ -2278,11 +2310,9 @@ BContainerWindow::SetUpEditQueryItem(BMenu* menu)
// if the view is a query pose view, add edit query menu item
BMenuItem* item = menu->FindItem(kEditQuery);
if (!poseViewIsQuery && !queryInSelection && item)
if (!poseViewIsQuery && !queryInSelection && item != NULL)
item->Menu()->RemoveItem(item);
else if ((poseViewIsQuery || queryInSelection) && !item) {
else if ((poseViewIsQuery || queryInSelection) && item == NULL) {
// add edit query item after Open
item = menu->FindItem(kOpenSelection);
if (item) {
@@ -2302,20 +2332,22 @@ BContainerWindow::SetupOpenWithMenu(BMenu* parent)
// start by removing nav item (and separator) from old menu
if (fOpenWithItem) {
BMenu* menu = fOpenWithItem->Menu();
if (menu)
if (menu != NULL)
menu->RemoveItem(fOpenWithItem);
delete fOpenWithItem;
fOpenWithItem = 0;
}
if (PoseView()->SelectionList()->CountItems() == 0)
if (PoseView()->SelectionList()->CountItems() == 0) {
// no selection, nothing to open
return;
}
if (TargetModel()->IsRoot())
if (TargetModel()->IsRoot()) {
// don't add ourselves if we are root
return;
}
// ToDo:
// check if only item in selection list is the root
@@ -2325,7 +2357,7 @@ BContainerWindow::SetupOpenWithMenu(BMenu* parent)
BMenuItem* item = parent->FindItem(kOpenSelection);
int32 count = PoseView()->SelectionList()->CountItems();
if (!count)
if (count == 0)
return;
// build a list of all refs to open
@@ -2443,9 +2475,10 @@ BContainerWindow::PopulateMoveCopyNavMenu(BNavMenu* navMenu, uint32 what,
// add root dir
if (volume.GetRootDirectory(&directory) == B_OK
&& directory.GetEntry(&entry) == B_OK
&& model.SetTo(&entry) == B_OK)
&& model.SetTo(&entry) == B_OK) {
navMenu->AddNavDir(&model, what, this, true);
// ask NavMenu to populate submenu for us
}
}
}
}
@@ -2634,7 +2667,8 @@ BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
// reset in DetachedFromWindow
// see the notes in SlowContextPopup::AttachedToWindow
if (!FSIsPrintersDir(&entry) && !fDragContextMenu->IsShowing()) {
if (!FSIsPrintersDir(&entry)
&& !fDragContextMenu->IsShowing()) {
//printf("ShowContextMenu - target is %s %i\n",
// ref->name, IsShowing(ref));
fDragContextMenu->ClearMenu();
@@ -2653,17 +2687,18 @@ BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
fDragContextMenu->SetTypesList(fCachedTypesList);
fDragContextMenu->SetTarget(BMessenger(this));
BPoseView* poseView = PoseView();
if (poseView) {
if (poseView != NULL) {
BMessenger target(poseView);
fDragContextMenu->InitTrackingHook(
&BPoseView::MenuTrackingHook, &target,
fDragMessage);
fDragMessage);
}
// this is now asynchronous so that we don't
// deadlock in Window::Quit,
fDragContextMenu->Go(global, true, false, true);
}
return;
} else if (TargetModel()->IsRoot() || model.IsVolume()) {
fContextMenu = fVolumeContextMenu;
@@ -2673,7 +2708,7 @@ BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
// clean up items from last context menu
if (fContextMenu) {
if (fContextMenu != NULL) {
if (fContextMenu->Window())
return;
else
@@ -2714,7 +2749,7 @@ BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
fContextMenu->Go(global, true, true, true);
}
}
} else if (fWindowContextMenu) {
} else if (fWindowContextMenu != NULL) {
if (fWindowContextMenu->Window())
return;
@@ -2731,6 +2766,7 @@ BContainerWindow::ShowContextMenu(BPoint loc, const entry_ref* ref, BView*)
fWindowContextMenu->Go(global, true, true, true);
}
fContextMenu = NULL;
}
@@ -2740,8 +2776,8 @@ BContainerWindow::AddFileContextMenus(BMenu* menu)
{
menu->AddItem(new BMenuItem(B_TRANSLATE("Open"),
new BMessage(kOpenSelection), 'O'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"), new BMessage(kGetInfo),
'I'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Get info"),
new BMessage(kGetInfo), 'I'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
new BMessage(kEditItem), 'E'));
@@ -3118,7 +3154,6 @@ BContainerWindow::UpdateMenu(BMenu* menu, UpdateMenuContext context)
SetArrangeMenu(menu);
SetPasteItem(menu);
BEntry entry(TargetModel()->EntryRef());
BDirectory parent;
entry_ref ref;
@@ -3761,9 +3796,10 @@ BContainerWindow::SetUpDefaultState()
void
BContainerWindow::RestoreWindowState(AttributeStreamNode* node)
{
if (!node || dynamic_cast<BDeskWindow*>(this))
if (node == NULL || dynamic_cast<BDeskWindow*>(this)) {
// don't restore any window state if we are a desktop window
return;
}
const char* rectAttributeName;
const char* workspaceAttributeName;
@@ -3814,9 +3850,10 @@ BContainerWindow::RestoreWindowState(AttributeStreamNode* node)
void
BContainerWindow::RestoreWindowState(const BMessage &message)
{
if (dynamic_cast<BDeskWindow*>(this))
if (dynamic_cast<BDeskWindow*>(this)) {
// don't restore any window state if we are a desktop window
return;
}
const char* rectAttributeName;
const char* workspaceAttributeName;