Ticket #7051: Deskbar Persist Expanded State 3.diff
File Deskbar Persist Expanded State 3.diff, 5.6 KB (added by , 14 years ago) |
---|
-
src/apps/deskbar/BarView.cpp
diff --git src/apps/deskbar/BarView.cpp src/apps/deskbar/BarView.cpp index cac3472..7e95133 100644
const int32 kDefaultRecentAppCount = 10; 68 68 69 69 const int32 kMenuTrackMargin = 20; 70 70 71 BList TBarView::sExpandedItems; 72 73 71 74 TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, 72 75 bool showInterval, uint32 state, float, bool showTime) 73 76 : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), … … TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, 92 95 fDragRegion->AddChild(fReplicantTray); 93 96 if (fTrayLocation != 0) 94 97 AddChild(fDragRegion); 98 99 sExpandedItems.MakeEmpty(); 95 100 } 96 101 97 102 … … TBarView::~TBarView() 99 104 { 100 105 delete fDragMessage; 101 106 delete fCachedTypesList; 107 108 // Clean up the expanded items list 109 while (!sExpandedItems.IsEmpty()) 110 delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0)); 111 sExpandedItems.MakeEmpty(); 102 112 } 103 113 104 114 … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 453 463 PlaceTray(vertSwap, leftSwap, screenFrame); 454 464 455 465 // We need to keep track of what apps are expanded. 456 BList expandedItems; 457 BString* signature = NULL; 458 if (fVertical && Expando() 459 && static_cast<TBarApp*>(be_app)->Settings()->superExpando) { 460 // Get a list of the signatures of expanded apps. Can't use 461 // team_id because there can be more than one team per application 462 if (fVertical && Expando() && vertical && fExpando) { 463 for (int index = 0; index < fExpando->CountItems(); index++) { 464 TTeamMenuItem* item 465 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index)); 466 if (item != NULL && item->IsExpanded()) { 467 signature = new BString(item->Signature()); 468 expandedItems.AddItem((void*)signature); 469 } 470 } 471 } 472 } 466 SaveExpandedItems(); 473 467 474 468 PlaceApplicationBar(screenFrame); 475 469 SizeWindow(screenFrame); … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 477 471 Window()->UpdateIfNeeded(); 478 472 479 473 // Re-expand those apps. 480 if (expandedItems.CountItems() > 0) { 481 for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) { 482 signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex)); 483 if (signature == NULL) 484 continue; 485 486 // Start at the 'bottom' of the list working up. 487 // Prevents being thrown off by expanding items. 488 for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 489 TTeamMenuItem* item 490 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 491 if (item != NULL && !signature->Compare(item->Signature())) { 492 item->ToggleExpandState(false); 474 ExpandItems(); 475 Invalidate(); 476 } 477 478 479 void 480 TBarView::SaveExpandedItems() 481 { 482 if (!fExpando) 483 return; 484 485 // Get a list of the signatures of expanded apps. Can't use 486 // team_id because there can be more than one team per application 487 for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 488 TTeamMenuItem* teamItem 489 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 490 if (teamItem == NULL || teamItem->Signature() == NULL || 491 *teamItem->Signature() == '\0') 492 continue; 493 494 if (teamItem->IsExpanded()) { 495 // Expanded, if signature is not in the list add it 496 bool shouldAdd = true; 497 498 for (int32 sigIndex = sExpandedItems.CountItems(); 499 sigIndex-- > 0;) { 500 BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex); 501 if (signature->ICompare(teamItem->Signature()) == 0) { 502 // already in the list, don't add the signature 503 shouldAdd = false; 493 504 break; 494 505 } 495 506 } 496 }497 507 498 // Clean up expanded signature list. 499 while (!expandedItems.IsEmpty()) { 500 delete static_cast<BString*>(expandedItems.RemoveItem((int32)0)); 508 if (shouldAdd) { 509 // Add the signature to the list 510 BString* signature = new BString(teamItem->Signature()); 511 sExpandedItems.AddItem((void*)signature); 512 } 501 513 } 514 } 515 } 516 517 518 void 519 TBarView::ExpandItems() 520 { 521 if (!fExpando || !fVertical || !Expando() 522 || !static_cast<TBarApp*>(be_app)->Settings()->superExpando 523 || sExpandedItems.CountItems() <= 0) 524 return; 502 525 503 fExpando->SizeWindow(); 526 // Start at the 'bottom' of the list working up. 527 // Prevents being thrown off by expanding items. 528 for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 529 TTeamMenuItem* teamItem 530 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 531 if (teamItem == NULL || teamItem->Signature() == NULL 532 || *teamItem->Signature() == '\0') 533 continue; 534 535 for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) { 536 BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex); 537 538 if (signature->ICompare(teamItem->Signature()) == 0) { 539 teamItem->ToggleExpandState(false); 540 sExpandedItems.RemoveItem(sigIndex); 541 break; 542 } 543 } 504 544 } 505 545 506 Invalidate(); 546 // Clean up the expanded items list 547 while (!sExpandedItems.IsEmpty()) 548 delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0)); 549 sExpandedItems.MakeEmpty(); 550 551 fExpando->SizeWindow(); 507 552 } 508 553 509 554 -
src/apps/deskbar/BarView.h
diff --git src/apps/deskbar/BarView.h src/apps/deskbar/BarView.h index 8f4e5b8..dd0cfd7 100644
class TBarView : public BView { 146 146 void PlaceBeMenu(); 147 147 void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame); 148 148 void PlaceApplicationBar(BRect screenFrame); 149 void SaveExpandedItems(); 150 void ExpandItems(); 149 151 150 152 TBarMenuBar* fBarMenuBar; 151 153 TExpandoMenuBar* fExpando; … … class TBarView : public BView { 172 174 uint32 fMaxRecentApps; 173 175 174 176 TTeamMenuItem* fLastDragItem; 177 static BList sExpandedItems; 175 178 }; 176 179 177 180