Ticket #3560: bug#3560-status-line-enhancement-005.patch
File bug#3560-status-line-enhancement-005.patch, 6.7 KB (added by , 9 years ago) |
---|
-
src/kits/tracker/CountView.cpp
From c87d5b9e1723f610016712b0d4adc8c90b314712 Mon Sep 17 00:00:00 2001 From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com> Date: Mon, 15 Dec 2014 13:06:35 +0000 Subject: [PATCH] Status line enhancement v2.0 --- src/kits/tracker/CountView.cpp | 126 ++++++++++++++++++++++++++++++++++------- src/kits/tracker/CountView.h | 7 ++- src/kits/tracker/PoseView.cpp | 2 +- 3 files changed, 114 insertions(+), 21 deletions(-) diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp index a1d3c7c..7931705 100644
a b All rights reserved. 47 47 #include "Bitmaps.h" 48 48 #include "ContainerWindow.h" 49 49 #include "DirMenu.h" 50 #include "Entry.h" 51 #include "Model.h" 50 52 #include "PoseView.h" 53 #include "StringForSize.h" 51 54 #include "Utilities.h" 52 55 53 56 … … BCountView::BCountView(BRect bounds, BPoseView* view) 66 69 BView(bounds, "CountVw", B_FOLLOW_LEFT + B_FOLLOW_BOTTOM, 67 70 B_PULSE_NEEDED | B_WILL_DRAW), 68 71 fLastCount(-1), 72 fLastSelectionCount(0), 73 fFileCount(0), 74 fDirCount(0), 75 fTotalFilesSize(0), 69 76 fPoseView(view), 77 fMoreFiles(false), 70 78 fShowingBarberPole(false), 71 79 fBorderHighlighted(false), 72 80 fBarberPoleMap(NULL), 73 81 fLastBarberPoleOffset(5), 74 82 fStartSpinningAfter(0), 83 fStatusString(""), 75 84 fTypeAheadString(""), 76 85 fFilterString("") 77 86 { … … BCountView::TextAndBarberPoleRect() const 195 204 void 196 205 BCountView::CheckCount() 197 206 { 207 PoseList* selectionList = fPoseView->SelectionList(); 198 208 // invalidate the count text area if necessary 199 if (fLastCount != fPoseView->CountItems()) { 209 if (fLastCount != fPoseView->CountItems() || 210 fLastSelectionCount != selectionList->CountItems()){ 200 211 fLastCount = fPoseView->CountItems(); 212 fLastSelectionCount = selectionList->CountItems(); 213 _UpdateCountsAndSizes(fLastSelectionCount); 201 214 Invalidate(TextInvalRect()); 202 215 } 203 216 … … BCountView::CheckCount() 207 220 208 221 209 222 void 223 BCountView::_UpdateCountsAndSizes(int32 selectionCount) 224 { 225 fFileCount = 0; 226 fDirCount = 0; 227 fTotalFilesSize = 0; 228 fLastCount = fPoseView->CountItems(); 229 fMoreFiles = false; 230 bool hasSelection = selectionCount==0?false:true; 231 232 node_ref ref; 233 Model* model = fPoseView->TargetModel(); 234 if (model->IsDirectory()) 235 ref = *model->NodeRef(); 236 else { 237 // we can't check for files and folders if model is not a directory 238 return; 239 } 240 241 BDirectory dir(&ref); 242 BEntry entry; 243 while (dir.GetNextEntry(&entry) == B_OK) { 244 StatStruct statbuf; 245 status_t status = entry.GetStat(&statbuf); 246 if (status != B_OK) { 247 fMoreFiles = true; 248 continue; 249 } 250 251 if (S_ISDIR(statbuf.st_mode)) 252 fDirCount++; 253 else { 254 fFileCount++; 255 fTotalFilesSize += statbuf.st_size; 256 } 257 } 258 259 BString itemString,selectionString; 260 BString fileString, folderString, sizeString; 261 BString empty = "--"; 262 fStatusString = ""; 263 if (IsTypingAhead()) 264 fStatusString << TypeAhead(); 265 else if (IsFiltering()) { 266 fStatusString << fLastCount << " " << Filter(); 267 } else { 268 if (fLastCount == 0) 269 fStatusString << B_TRANSLATE("no items"); 270 else { 271 if (!hasSelection) { 272 fStatusString = ""; 273 static BMessageFormat itemFormat(B_TRANSLATE_COMMENT( 274 "{0, plural, one{# item} other{# items}}", 275 "Number of selected items: \"1 item\" or \"2 items\"")); 276 itemFormat.Format(itemString, fLastCount); 277 fStatusString += itemString; 278 279 fStatusString += " | "; 280 static BMessageFormat folderFormat(B_TRANSLATE_COMMENT( 281 "{0, plural, one{# folder} other{# folders}}", 282 "Number of selected folders: \"1 folder\" or \"2 folders\"")); 283 folderFormat.Format(folderString, fDirCount); 284 fStatusString += folderString; 285 286 fStatusString += " | "; 287 static BMessageFormat fileFormat(B_TRANSLATE_COMMENT( 288 "{0, plural, one{#%more% file} other{#%more% files}} (%size%)", 289 "Number of selected files: \"1 file\" or \"2 files\"")); 290 fileFormat.Format(fileString, fFileCount); 291 fileString.ReplaceFirst("%more%", (fMoreFiles?"+":"") ); 292 char sizeBuffer[128]; 293 sizeString = string_for_size((double)fTotalFilesSize, 294 sizeBuffer, sizeof(sizeBuffer)); 295 fileString.ReplaceFirst("%size%", 296 (sizeString.Length()==0?empty:sizeString)); 297 fStatusString += fileString; 298 } 299 else { 300 fStatusString = ""; 301 static BMessageFormat selectionFormat(B_TRANSLATE_COMMENT( 302 "{0, plural, one{# item} other{# items}} selected", 303 "Number of selected items: \"1 item selected\"" 304 "or \"2 items selected\"")); 305 selectionFormat.Format(selectionString, selectionCount); 306 fStatusString += selectionString; 307 } 308 } 309 } 310 } 311 312 313 void 210 314 BCountView::Draw(BRect updateRect) 211 315 { 212 316 BRect bounds(Bounds()); … … BCountView::Draw(BRect updateRect) 223 327 ViewColor()); 224 328 } 225 329 226 BString itemString;227 if (IsTypingAhead())228 itemString << TypeAhead();229 else if (IsFiltering()) {230 itemString << fLastCount << " " << Filter();231 } else {232 if (fLastCount == 0)233 itemString << B_TRANSLATE("no items");234 else {235 static BMessageFormat format(B_TRANSLATE_COMMENT(236 "{0, plural, one{# item} other{# items}}",237 "Number of selected items: \"1 item\" or \"2 items\""));238 format.Format(itemString, fLastCount);239 }240 }241 242 330 BRect textRect(TextInvalRect()); 243 331 244 TruncateString(& itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING332 TruncateString(&fStatusString, IsTypingAhead() ? B_TRUNCATE_BEGINNING 245 333 : IsFiltering() ? B_TRUNCATE_MIDDLE : B_TRUNCATE_END, 246 334 textRect.Width()); 247 335 … … BCountView::Draw(BRect updateRect) 253 341 SetHighColor(0, 0, 0); 254 342 255 343 MovePenTo(textRect.LeftBottom()); 256 DrawString( itemString.String());344 DrawString(fStatusString.String()); 257 345 258 346 bounds.top++; 259 347 -
src/kits/tracker/CountView.h
diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h index 52ad97e..24009b1 100644
a b private: 78 78 BRect TextInvalRect() const; 79 79 BRect TextAndBarberPoleRect() const; 80 80 void TrySpinningBarberPole(); 81 void _UpdateCountsAndSizes(int32); 81 82 82 int32 fLastCount; 83 int32 fLastCount, fLastSelectionCount; 84 int32 fFileCount, fDirCount; 85 off_t fTotalFilesSize; 83 86 BPoseView* fPoseView; 87 bool fMoreFiles : 1; 84 88 bool fShowingBarberPole : 1; 85 89 bool fBorderHighlighted : 1; 86 90 BBitmap* fBarberPoleMap; 87 91 float fLastBarberPoleOffset; 88 92 bigtime_t fStartSpinningAfter; 93 BString fStatusString; 89 94 BString fTypeAheadString; 90 95 BString fFilterString; 91 96 }; -
src/kits/tracker/PoseView.cpp
diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 486c3c8..9c078e5 100644
a b using std::max; 111 111 112 112 113 113 const float kDoubleClickTresh = 6; 114 const float kCountViewWidth = 76;114 const float kCountViewWidth = 250; 115 115 116 116 const uint32 kAddNewPoses = 'Tanp'; 117 117 const uint32 kAddPosesCompleted = 'Tapc';