Tracker: Style fixes related to #13151
Some 100 char fixes Put looper in a variable and use it a few times Remove ASSERT statements, we B_DISPATCH_MESSAGE if NULL. Refactor command modifier key code to use a nested switch Explict comparisons to NULL Change-Id: I068a0123461290731b4b5388b802bb4cc7bb2455 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8688 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
844099afc1
commit
bd01f3f156
@@ -111,49 +111,54 @@ GetLinkFlavor(const Model* model, bool resolve = true)
|
||||
static filter_result
|
||||
key_down_filter(BMessage* message, BHandler** handler, BMessageFilter* filter)
|
||||
{
|
||||
ASSERT(filter != NULL);
|
||||
if (filter == NULL)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
TFilePanel* panel = dynamic_cast<TFilePanel*>(filter->Looper());
|
||||
ASSERT(panel != NULL);
|
||||
BLooper* looper = filter->Looper();
|
||||
if (looper == NULL)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
if (panel == NULL)
|
||||
TFilePanel* panel = dynamic_cast<TFilePanel*>(looper);
|
||||
if (panel == NULL || panel->TrackingMenu())
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
BPoseView* view = panel->PoseView();
|
||||
if (panel->TrackingMenu())
|
||||
if (view == NULL)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
uchar key;
|
||||
if (message->FindInt8("byte", (int8*)&key) != B_OK)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
int32 modifier = 0;
|
||||
message->FindInt32("modifiers", &modifier);
|
||||
int32 modifiers = message->GetInt32("modifiers", 0);
|
||||
|
||||
if (modifier & B_COMMAND_KEY && key == B_UP_ARROW) {
|
||||
filter->Looper()->PostMessage(kOpenParentDir);
|
||||
return B_SKIP_MESSAGE;
|
||||
if ((modifiers & B_COMMAND_KEY) != 0) {
|
||||
switch (key) {
|
||||
case B_UP_ARROW:
|
||||
looper->PostMessage(kOpenParentDir);
|
||||
return B_SKIP_MESSAGE;
|
||||
|
||||
case 'w':
|
||||
looper->PostMessage(kCancelButton);
|
||||
return B_SKIP_MESSAGE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (modifier & B_COMMAND_KEY && key == 'w') {
|
||||
filter->Looper()->PostMessage(kCancelButton);
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
if (!modifier && key == B_ESCAPE) {
|
||||
if (view->ActivePose())
|
||||
if (modifiers == 0 && key == B_ESCAPE) {
|
||||
if (view->ActivePose() != NULL)
|
||||
view->CommitActivePose(false);
|
||||
else if (view->IsFiltering())
|
||||
filter->Looper()->PostMessage(B_CANCEL, *handler);
|
||||
looper->PostMessage(B_CANCEL, *handler);
|
||||
else
|
||||
filter->Looper()->PostMessage(kCancelButton);
|
||||
looper->PostMessage(kCancelButton);
|
||||
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
if (key == B_RETURN && view->ActivePose()) {
|
||||
if (key == B_RETURN && view->ActivePose() != NULL) {
|
||||
view->CommitActivePose();
|
||||
|
||||
return B_SKIP_MESSAGE;
|
||||
@@ -264,8 +269,7 @@ TFilePanel::TFilePanel(file_panel_mode mode, BMessenger* target, const BEntry* s
|
||||
fPoseView->SetFlags(fPoseView->Flags() | B_NAVIGABLE);
|
||||
fPoseView->SetPoseEditing(false);
|
||||
AddCommonFilter(new BMessageFilter(B_KEY_DOWN, key_down_filter));
|
||||
AddCommonFilter(new BMessageFilter(B_SIMPLE_DATA,
|
||||
TFilePanel::MessageDropFilter));
|
||||
AddCommonFilter(new BMessageFilter(B_SIMPLE_DATA, TFilePanel::MessageDropFilter));
|
||||
AddCommonFilter(new BMessageFilter(B_NODE_MONITOR, TFilePanel::FSFilter));
|
||||
|
||||
// inter-application observing
|
||||
@@ -292,8 +296,7 @@ TFilePanel::~TFilePanel()
|
||||
|
||||
|
||||
filter_result
|
||||
TFilePanel::MessageDropFilter(BMessage* message, BHandler**,
|
||||
BMessageFilter* filter)
|
||||
TFilePanel::MessageDropFilter(BMessage* message, BHandler**, BMessageFilter* filter)
|
||||
{
|
||||
if (message == NULL || !message->WasDropped())
|
||||
return B_DISPATCH_MESSAGE;
|
||||
@@ -534,8 +537,7 @@ TFilePanel::SetRefFilter(BRefFilter* filter)
|
||||
if (favoritesItem == NULL)
|
||||
return;
|
||||
|
||||
FavoritesMenu* favoritesSubMenu
|
||||
= dynamic_cast<FavoritesMenu*>(favoritesItem->Submenu());
|
||||
FavoritesMenu* favoritesSubMenu = dynamic_cast<FavoritesMenu*>(favoritesItem->Submenu());
|
||||
if (favoritesSubMenu != NULL)
|
||||
favoritesSubMenu->SetRefFilter(filter);
|
||||
}
|
||||
|
||||
@@ -2668,10 +2668,8 @@ BPoseView::MessageReceived(BMessage* message)
|
||||
{
|
||||
TrackerSettings settings;
|
||||
bool hideDotFiles;
|
||||
if (message->FindBool("HideDotFiles",
|
||||
&hideDotFiles) == B_OK) {
|
||||
if (message->FindBool("HideDotFiles", &hideDotFiles) == B_OK)
|
||||
settings.SetHideDotFiles(hideDotFiles);
|
||||
}
|
||||
|
||||
Refresh();
|
||||
break;
|
||||
@@ -3291,10 +3289,8 @@ BPoseView::UpdatePosesClipboardModeFromClipboard(BMessage* clipboardReport)
|
||||
|
||||
if (!fullInvalidateNeeded) {
|
||||
if (ViewMode() == kListMode) {
|
||||
if (fFiltering) {
|
||||
pose = fFilteredPoseList->FindPose(&clipNode->node,
|
||||
&foundNodeIndex);
|
||||
}
|
||||
if (fFiltering)
|
||||
pose = fFilteredPoseList->FindPose(&clipNode->node, &foundNodeIndex);
|
||||
|
||||
if (pose != NULL) {
|
||||
loc.y = foundNodeIndex * fListElemHeight;
|
||||
@@ -3455,8 +3451,7 @@ BPoseView::NewFolder(const BMessage* message)
|
||||
if (fFilteredPoseList->FindPose(&nodeRef, &index) == NULL) {
|
||||
float scrollBy = 0;
|
||||
BRect bounds = Bounds();
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds,
|
||||
scrollBy, true, &index);
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true, &index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5692,8 +5687,7 @@ BPoseView::EntryMoved(const BMessage* message)
|
||||
if (!visible && FilterPose(pose)) {
|
||||
BRect bounds = Bounds();
|
||||
float scrollBy = 0;
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose,
|
||||
bounds, scrollBy, true);
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true);
|
||||
} else if (visible && !FilterPose(pose))
|
||||
RemoveFilteredPose(pose, index);
|
||||
else if (visible)
|
||||
@@ -5860,10 +5854,8 @@ BPoseView::AttributeChanged(const BMessage* message)
|
||||
&index) != NULL;
|
||||
int32 poseListIndex = index;
|
||||
|
||||
if (fFiltering) {
|
||||
visible = fFilteredPoseList->FindPose(
|
||||
poseModel->NodeRef(), &index) != NULL;
|
||||
}
|
||||
if (fFiltering)
|
||||
visible = fFilteredPoseList->FindPose(poseModel->NodeRef(), &index) != NULL;
|
||||
|
||||
BPoint loc(0, index * fListElemHeight);
|
||||
if (attrName != NULL && poseModel->Node() != NULL) {
|
||||
@@ -5884,8 +5876,7 @@ BPoseView::AttributeChanged(const BMessage* message)
|
||||
visible = true;
|
||||
float scrollBy = 0;
|
||||
BRect bounds = Bounds();
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds,
|
||||
scrollBy, true);
|
||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true);
|
||||
continue;
|
||||
} else if (visible && !FilterPose(pose)) {
|
||||
RemoveFilteredPose(pose, index);
|
||||
@@ -6688,10 +6679,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
||||
if (IsFilePanel())
|
||||
_inherited::KeyDown(bytes, count);
|
||||
else {
|
||||
if (ViewMode() == kListMode
|
||||
&& TrackerSettings().TypeAheadFiltering()) {
|
||||
if (ViewMode() == kListMode && TrackerSettings().TypeAheadFiltering())
|
||||
break;
|
||||
}
|
||||
|
||||
if (fSelectionList->IsEmpty())
|
||||
sMatchString.Truncate(0);
|
||||
@@ -6781,9 +6770,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
||||
{
|
||||
// handle typeahead selection / filtering
|
||||
|
||||
if (ViewMode() == kListMode
|
||||
&& TrackerSettings().TypeAheadFiltering()) {
|
||||
if (key == ' ' && modifiers() & B_SHIFT_KEY) {
|
||||
if (ViewMode() == kListMode && TrackerSettings().TypeAheadFiltering()) {
|
||||
if (key == ' ' && (modifiers() & B_SHIFT_KEY) != 0) {
|
||||
if (fFilterStrings.LastItem()->Length() == 0)
|
||||
break;
|
||||
|
||||
@@ -6812,10 +6800,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
||||
// figure out the time at which the keypress happened
|
||||
bigtime_t eventTime;
|
||||
BMessage* message = Window()->CurrentMessage();
|
||||
if (message == NULL
|
||||
|| message->FindInt64("when", &eventTime) < B_OK) {
|
||||
if (message == NULL || message->FindInt64("when", &eventTime) < B_OK)
|
||||
eventTime = system_time();
|
||||
}
|
||||
|
||||
// add char to existing matchString or start new match string
|
||||
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
||||
@@ -9839,8 +9825,7 @@ BPoseView::FrameForPose(BPose* targetPose, bool convert, BRect* poseRect)
|
||||
frameIsValid = false;
|
||||
}
|
||||
} else {
|
||||
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top
|
||||
- IconPoseHeight()), true);
|
||||
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top - IconPoseHeight()), true);
|
||||
int32 poseCount = fVSPoseList->CountItems();
|
||||
|
||||
for (int32 index = startIndex; index < poseCount; index++) {
|
||||
@@ -9985,8 +9970,7 @@ BPoseView::HiliteDropTarget(bool hiliteState)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int32 startIndex = FirstIndexAtOrBelow(
|
||||
(int32)(bounds.top - IconPoseHeight()), true);
|
||||
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top - IconPoseHeight()), true);
|
||||
int32 poseCount = fVSPoseList->CountItems();
|
||||
|
||||
for (int32 index = startIndex; index < poseCount; index++) {
|
||||
@@ -10376,15 +10360,13 @@ BPoseView::FilterChanged()
|
||||
int32 stringCount = fFilterStrings.CountItems();
|
||||
int32 length = fFilterStrings.LastItem()->CountChars();
|
||||
|
||||
if (!fFiltering && (length > 0 || fRefFilter != NULL))
|
||||
if (!fFiltering && (length > 0 || fRefFilter != NULL)) {
|
||||
StartFiltering();
|
||||
else if (fFiltering && stringCount == 1 && length == 0
|
||||
&& fRefFilter == NULL) {
|
||||
} else if (fFiltering && stringCount == 1 && length == 0 && fRefFilter == NULL) {
|
||||
ClearFilter();
|
||||
} else {
|
||||
if (fLastFilterStringCount > stringCount
|
||||
|| (fLastFilterStringCount == stringCount
|
||||
&& fLastFilterStringLength > length)
|
||||
|| (fLastFilterStringCount == stringCount && fLastFilterStringLength > length)
|
||||
|| fRefFilter != NULL) {
|
||||
// something was removed, need to start over
|
||||
fFilteredPoseList->MakeEmpty();
|
||||
|
||||
Reference in New Issue
Block a user