From 54dd4c335c7f39b141e0854991f8b5fb25dd2e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 21 Dec 2010 19:48:12 +0000 Subject: [PATCH] Based on remarks from Stephan and Axel. Thanks for reviewing. * The list now owns its items * MakeEmpty() is used to clear the list (also on destruction) * RemoveIconAt() lets ItemAt() check the provided index and delete the item * SlideToIcon(), SlideToNext(), SlideToPrevious() don't need to check invalid values as ItemAt() will return a NULL pointer in this case. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39915 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/notifications/IconRule.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/preferences/notifications/IconRule.cpp b/src/preferences/notifications/IconRule.cpp index 89eaf08c32..7e64d5616c 100644 --- a/src/preferences/notifications/IconRule.cpp +++ b/src/preferences/notifications/IconRule.cpp @@ -23,6 +23,7 @@ const int32 kBorderOffset = 1; BIconRule::BIconRule(const char* name) : BView(name, B_WILL_DRAW), + fIcons(5, true), fSelIndex(-1) { } @@ -157,18 +158,14 @@ BIconRule::AddIcon(const char* label, const BBitmap* icon) void BIconRule::RemoveIconAt(int32 index) { - int32 count = fIcons.CountItems(); - if (index < count && index >= (int32)0) - fIcons.RemoveItemAt((int32)index); + delete fIcons.RemoveItemAt(index); } void BIconRule::RemoveAllIcons() { - int32 count = fIcons.CountItems(); - for (int32 i = 0; i < count; i++) - fIcons.RemoveItemAt(i); + fIcons.MakeEmpty(); } @@ -182,10 +179,6 @@ BIconRule::CountIcons() const void BIconRule::SlideToIcon(int32 index) { - // Ignore invalid items - if ((index < 0) || (index > CountIcons() - 1)) - return; - BIconItem* item = fIcons.ItemAt(index); if (item) { // Deselect previously selected item @@ -208,8 +201,6 @@ BIconRule::SlideToIcon(int32 index) void BIconRule::SlideToNext() { - if (fSelIndex + 1 < CountIcons() - 1) - return; SlideToIcon(fSelIndex + 1); } @@ -217,8 +208,6 @@ BIconRule::SlideToNext() void BIconRule::SlideToPrevious() { - if (fSelIndex <= 0) - return; SlideToIcon(fSelIndex - 1); }