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
|
static filter_result
|
||||||
key_down_filter(BMessage* message, BHandler** handler, BMessageFilter* filter)
|
key_down_filter(BMessage* message, BHandler** handler, BMessageFilter* filter)
|
||||||
{
|
{
|
||||||
ASSERT(filter != NULL);
|
|
||||||
if (filter == NULL)
|
if (filter == NULL)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
TFilePanel* panel = dynamic_cast<TFilePanel*>(filter->Looper());
|
BLooper* looper = filter->Looper();
|
||||||
ASSERT(panel != NULL);
|
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;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
BPoseView* view = panel->PoseView();
|
BPoseView* view = panel->PoseView();
|
||||||
if (panel->TrackingMenu())
|
if (view == NULL)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
uchar key;
|
uchar key;
|
||||||
if (message->FindInt8("byte", (int8*)&key) != B_OK)
|
if (message->FindInt8("byte", (int8*)&key) != B_OK)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
int32 modifier = 0;
|
int32 modifiers = message->GetInt32("modifiers", 0);
|
||||||
message->FindInt32("modifiers", &modifier);
|
|
||||||
|
|
||||||
if (modifier & B_COMMAND_KEY && key == B_UP_ARROW) {
|
if ((modifiers & B_COMMAND_KEY) != 0) {
|
||||||
filter->Looper()->PostMessage(kOpenParentDir);
|
switch (key) {
|
||||||
return B_SKIP_MESSAGE;
|
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') {
|
if (modifiers == 0 && key == B_ESCAPE) {
|
||||||
filter->Looper()->PostMessage(kCancelButton);
|
if (view->ActivePose() != NULL)
|
||||||
return B_SKIP_MESSAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!modifier && key == B_ESCAPE) {
|
|
||||||
if (view->ActivePose())
|
|
||||||
view->CommitActivePose(false);
|
view->CommitActivePose(false);
|
||||||
else if (view->IsFiltering())
|
else if (view->IsFiltering())
|
||||||
filter->Looper()->PostMessage(B_CANCEL, *handler);
|
looper->PostMessage(B_CANCEL, *handler);
|
||||||
else
|
else
|
||||||
filter->Looper()->PostMessage(kCancelButton);
|
looper->PostMessage(kCancelButton);
|
||||||
|
|
||||||
return B_SKIP_MESSAGE;
|
return B_SKIP_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == B_RETURN && view->ActivePose()) {
|
if (key == B_RETURN && view->ActivePose() != NULL) {
|
||||||
view->CommitActivePose();
|
view->CommitActivePose();
|
||||||
|
|
||||||
return B_SKIP_MESSAGE;
|
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->SetFlags(fPoseView->Flags() | B_NAVIGABLE);
|
||||||
fPoseView->SetPoseEditing(false);
|
fPoseView->SetPoseEditing(false);
|
||||||
AddCommonFilter(new BMessageFilter(B_KEY_DOWN, key_down_filter));
|
AddCommonFilter(new BMessageFilter(B_KEY_DOWN, key_down_filter));
|
||||||
AddCommonFilter(new BMessageFilter(B_SIMPLE_DATA,
|
AddCommonFilter(new BMessageFilter(B_SIMPLE_DATA, TFilePanel::MessageDropFilter));
|
||||||
TFilePanel::MessageDropFilter));
|
|
||||||
AddCommonFilter(new BMessageFilter(B_NODE_MONITOR, TFilePanel::FSFilter));
|
AddCommonFilter(new BMessageFilter(B_NODE_MONITOR, TFilePanel::FSFilter));
|
||||||
|
|
||||||
// inter-application observing
|
// inter-application observing
|
||||||
@@ -292,8 +296,7 @@ TFilePanel::~TFilePanel()
|
|||||||
|
|
||||||
|
|
||||||
filter_result
|
filter_result
|
||||||
TFilePanel::MessageDropFilter(BMessage* message, BHandler**,
|
TFilePanel::MessageDropFilter(BMessage* message, BHandler**, BMessageFilter* filter)
|
||||||
BMessageFilter* filter)
|
|
||||||
{
|
{
|
||||||
if (message == NULL || !message->WasDropped())
|
if (message == NULL || !message->WasDropped())
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
@@ -534,8 +537,7 @@ TFilePanel::SetRefFilter(BRefFilter* filter)
|
|||||||
if (favoritesItem == NULL)
|
if (favoritesItem == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FavoritesMenu* favoritesSubMenu
|
FavoritesMenu* favoritesSubMenu = dynamic_cast<FavoritesMenu*>(favoritesItem->Submenu());
|
||||||
= dynamic_cast<FavoritesMenu*>(favoritesItem->Submenu());
|
|
||||||
if (favoritesSubMenu != NULL)
|
if (favoritesSubMenu != NULL)
|
||||||
favoritesSubMenu->SetRefFilter(filter);
|
favoritesSubMenu->SetRefFilter(filter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2668,10 +2668,8 @@ BPoseView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
TrackerSettings settings;
|
TrackerSettings settings;
|
||||||
bool hideDotFiles;
|
bool hideDotFiles;
|
||||||
if (message->FindBool("HideDotFiles",
|
if (message->FindBool("HideDotFiles", &hideDotFiles) == B_OK)
|
||||||
&hideDotFiles) == B_OK) {
|
|
||||||
settings.SetHideDotFiles(hideDotFiles);
|
settings.SetHideDotFiles(hideDotFiles);
|
||||||
}
|
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
break;
|
break;
|
||||||
@@ -3291,10 +3289,8 @@ BPoseView::UpdatePosesClipboardModeFromClipboard(BMessage* clipboardReport)
|
|||||||
|
|
||||||
if (!fullInvalidateNeeded) {
|
if (!fullInvalidateNeeded) {
|
||||||
if (ViewMode() == kListMode) {
|
if (ViewMode() == kListMode) {
|
||||||
if (fFiltering) {
|
if (fFiltering)
|
||||||
pose = fFilteredPoseList->FindPose(&clipNode->node,
|
pose = fFilteredPoseList->FindPose(&clipNode->node, &foundNodeIndex);
|
||||||
&foundNodeIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pose != NULL) {
|
if (pose != NULL) {
|
||||||
loc.y = foundNodeIndex * fListElemHeight;
|
loc.y = foundNodeIndex * fListElemHeight;
|
||||||
@@ -3455,8 +3451,7 @@ BPoseView::NewFolder(const BMessage* message)
|
|||||||
if (fFilteredPoseList->FindPose(&nodeRef, &index) == NULL) {
|
if (fFilteredPoseList->FindPose(&nodeRef, &index) == NULL) {
|
||||||
float scrollBy = 0;
|
float scrollBy = 0;
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds,
|
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true, &index);
|
||||||
scrollBy, true, &index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5692,8 +5687,7 @@ BPoseView::EntryMoved(const BMessage* message)
|
|||||||
if (!visible && FilterPose(pose)) {
|
if (!visible && FilterPose(pose)) {
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
float scrollBy = 0;
|
float scrollBy = 0;
|
||||||
AddPoseToList(fFilteredPoseList, true, true, pose,
|
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true);
|
||||||
bounds, scrollBy, true);
|
|
||||||
} else if (visible && !FilterPose(pose))
|
} else if (visible && !FilterPose(pose))
|
||||||
RemoveFilteredPose(pose, index);
|
RemoveFilteredPose(pose, index);
|
||||||
else if (visible)
|
else if (visible)
|
||||||
@@ -5860,10 +5854,8 @@ BPoseView::AttributeChanged(const BMessage* message)
|
|||||||
&index) != NULL;
|
&index) != NULL;
|
||||||
int32 poseListIndex = index;
|
int32 poseListIndex = index;
|
||||||
|
|
||||||
if (fFiltering) {
|
if (fFiltering)
|
||||||
visible = fFilteredPoseList->FindPose(
|
visible = fFilteredPoseList->FindPose(poseModel->NodeRef(), &index) != NULL;
|
||||||
poseModel->NodeRef(), &index) != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
BPoint loc(0, index * fListElemHeight);
|
BPoint loc(0, index * fListElemHeight);
|
||||||
if (attrName != NULL && poseModel->Node() != NULL) {
|
if (attrName != NULL && poseModel->Node() != NULL) {
|
||||||
@@ -5884,8 +5876,7 @@ BPoseView::AttributeChanged(const BMessage* message)
|
|||||||
visible = true;
|
visible = true;
|
||||||
float scrollBy = 0;
|
float scrollBy = 0;
|
||||||
BRect bounds = Bounds();
|
BRect bounds = Bounds();
|
||||||
AddPoseToList(fFilteredPoseList, true, true, pose, bounds,
|
AddPoseToList(fFilteredPoseList, true, true, pose, bounds, scrollBy, true);
|
||||||
scrollBy, true);
|
|
||||||
continue;
|
continue;
|
||||||
} else if (visible && !FilterPose(pose)) {
|
} else if (visible && !FilterPose(pose)) {
|
||||||
RemoveFilteredPose(pose, index);
|
RemoveFilteredPose(pose, index);
|
||||||
@@ -6688,10 +6679,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
|||||||
if (IsFilePanel())
|
if (IsFilePanel())
|
||||||
_inherited::KeyDown(bytes, count);
|
_inherited::KeyDown(bytes, count);
|
||||||
else {
|
else {
|
||||||
if (ViewMode() == kListMode
|
if (ViewMode() == kListMode && TrackerSettings().TypeAheadFiltering())
|
||||||
&& TrackerSettings().TypeAheadFiltering()) {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (fSelectionList->IsEmpty())
|
if (fSelectionList->IsEmpty())
|
||||||
sMatchString.Truncate(0);
|
sMatchString.Truncate(0);
|
||||||
@@ -6781,9 +6770,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
|||||||
{
|
{
|
||||||
// handle typeahead selection / filtering
|
// handle typeahead selection / filtering
|
||||||
|
|
||||||
if (ViewMode() == kListMode
|
if (ViewMode() == kListMode && TrackerSettings().TypeAheadFiltering()) {
|
||||||
&& TrackerSettings().TypeAheadFiltering()) {
|
if (key == ' ' && (modifiers() & B_SHIFT_KEY) != 0) {
|
||||||
if (key == ' ' && modifiers() & B_SHIFT_KEY) {
|
|
||||||
if (fFilterStrings.LastItem()->Length() == 0)
|
if (fFilterStrings.LastItem()->Length() == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -6812,10 +6800,8 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
|||||||
// figure out the time at which the keypress happened
|
// figure out the time at which the keypress happened
|
||||||
bigtime_t eventTime;
|
bigtime_t eventTime;
|
||||||
BMessage* message = Window()->CurrentMessage();
|
BMessage* message = Window()->CurrentMessage();
|
||||||
if (message == NULL
|
if (message == NULL || message->FindInt64("when", &eventTime) < B_OK)
|
||||||
|| message->FindInt64("when", &eventTime) < B_OK) {
|
|
||||||
eventTime = system_time();
|
eventTime = system_time();
|
||||||
}
|
|
||||||
|
|
||||||
// add char to existing matchString or start new match string
|
// add char to existing matchString or start new match string
|
||||||
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
if (eventTime - fLastKeyTime < (doubleClickSpeed * 2))
|
||||||
@@ -9839,8 +9825,7 @@ BPoseView::FrameForPose(BPose* targetPose, bool convert, BRect* poseRect)
|
|||||||
frameIsValid = false;
|
frameIsValid = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top
|
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top - IconPoseHeight()), true);
|
||||||
- IconPoseHeight()), true);
|
|
||||||
int32 poseCount = fVSPoseList->CountItems();
|
int32 poseCount = fVSPoseList->CountItems();
|
||||||
|
|
||||||
for (int32 index = startIndex; index < poseCount; index++) {
|
for (int32 index = startIndex; index < poseCount; index++) {
|
||||||
@@ -9985,8 +9970,7 @@ BPoseView::HiliteDropTarget(bool hiliteState)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int32 startIndex = FirstIndexAtOrBelow(
|
int32 startIndex = FirstIndexAtOrBelow((int32)(bounds.top - IconPoseHeight()), true);
|
||||||
(int32)(bounds.top - IconPoseHeight()), true);
|
|
||||||
int32 poseCount = fVSPoseList->CountItems();
|
int32 poseCount = fVSPoseList->CountItems();
|
||||||
|
|
||||||
for (int32 index = startIndex; index < poseCount; index++) {
|
for (int32 index = startIndex; index < poseCount; index++) {
|
||||||
@@ -10376,15 +10360,13 @@ BPoseView::FilterChanged()
|
|||||||
int32 stringCount = fFilterStrings.CountItems();
|
int32 stringCount = fFilterStrings.CountItems();
|
||||||
int32 length = fFilterStrings.LastItem()->CountChars();
|
int32 length = fFilterStrings.LastItem()->CountChars();
|
||||||
|
|
||||||
if (!fFiltering && (length > 0 || fRefFilter != NULL))
|
if (!fFiltering && (length > 0 || fRefFilter != NULL)) {
|
||||||
StartFiltering();
|
StartFiltering();
|
||||||
else if (fFiltering && stringCount == 1 && length == 0
|
} else if (fFiltering && stringCount == 1 && length == 0 && fRefFilter == NULL) {
|
||||||
&& fRefFilter == NULL) {
|
|
||||||
ClearFilter();
|
ClearFilter();
|
||||||
} else {
|
} else {
|
||||||
if (fLastFilterStringCount > stringCount
|
if (fLastFilterStringCount > stringCount
|
||||||
|| (fLastFilterStringCount == stringCount
|
|| (fLastFilterStringCount == stringCount && fLastFilterStringLength > length)
|
||||||
&& fLastFilterStringLength > length)
|
|
||||||
|| fRefFilter != NULL) {
|
|| fRefFilter != NULL) {
|
||||||
// something was removed, need to start over
|
// something was removed, need to start over
|
||||||
fFilteredPoseList->MakeEmpty();
|
fFilteredPoseList->MakeEmpty();
|
||||||
|
|||||||
Reference in New Issue
Block a user