Ticket #7051: Deskbar Persist Expanded State 5.diff
File Deskbar Persist Expanded State 5.diff, 7.1 KB (added by , 13 years ago) |
---|
-
src/apps/deskbar/BarApp.cpp
diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 58664f7..f7bcc1d 100644
a b TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref) 645 645 646 646 sBarTeamInfoList.AddItem(barInfo); 647 647 648 // If expandNewTeams is set, add the item to the list of 649 // expanded items. 650 if (fSettings.expandNewTeams) { 651 // Expanded, if signature is not in the list add it 652 bool shouldAdd = true; 653 654 for (int32 sigIndex = BarView()->sExpandedItems.CountItems(); 655 sigIndex-- > 0;) { 656 BString *signature = 657 (BString *)BarView()->sExpandedItems.ItemAt(sigIndex); 658 if (signature->ICompare(sig) == 0) { 659 // already in the list, don't add the signature 660 shouldAdd = false; 661 break; 662 } 663 } 664 665 if (shouldAdd) { 666 // Add the signature to the list 667 BString* signature = new BString(sig); 668 BarView()->sExpandedItems.AddItem((void *)signature); 669 } 670 } 671 648 672 int32 subsCount = sSubscribers.CountItems(); 649 673 if (subsCount > 0) { 650 674 for (int32 i = 0; i < subsCount; i++) { -
src/apps/deskbar/BarView.cpp
diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 6e71956..906365e 100644
a b 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(); 100 if (static_cast<TBarApp*>(be_app)->Settings()->expandNewTeams) { 101 // Add the Tracker to the list of expanded items so that it 102 // will be expanded on startup. 103 BString* signature = new BString(kTrackerSignature); 104 sExpandedItems.AddItem((void *)signature); 105 } 95 106 } 96 107 97 108 … … TBarView::~TBarView() 99 110 { 100 111 delete fDragMessage; 101 112 delete fCachedTypesList; 113 114 // Clean up the expanded items list 115 while (!sExpandedItems.IsEmpty()) 116 delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0)); 117 sExpandedItems.MakeEmpty(); 102 118 } 103 119 104 120 … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 529 545 PlaceTray(vertSwap, leftSwap, screenFrame); 530 546 531 547 // We need to keep track of what apps are expanded. 532 BList expandedItems; 533 BString* signature = NULL; 534 if (fVertical && Expando() 535 && static_cast<TBarApp*>(be_app)->Settings()->superExpando) { 536 // Get a list of the signatures of expanded apps. Can't use 537 // team_id because there can be more than one team per application 538 if (fVertical && Expando() && vertical && fExpando) { 539 for (int index = 0; index < fExpando->CountItems(); index++) { 540 TTeamMenuItem* item 541 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(index)); 542 if (item != NULL && item->IsExpanded()) { 543 signature = new BString(item->Signature()); 544 expandedItems.AddItem((void*)signature); 545 } 546 } 547 } 548 } 548 SaveExpandedItems(); 549 549 550 550 PlaceApplicationBar(screenFrame); 551 551 SizeWindow(screenFrame); … … TBarView::ChangeState(int32 state, bool vertical, bool left, bool top) 553 553 Window()->UpdateIfNeeded(); 554 554 555 555 // Re-expand those apps. 556 if (expandedItems.CountItems() > 0) { 557 for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) { 558 signature = static_cast<BString*>(expandedItems.ItemAt(sigIndex)); 559 if (signature == NULL) 560 continue; 561 562 // Start at the 'bottom' of the list working up. 563 // Prevents being thrown off by expanding items. 564 for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 565 TTeamMenuItem* item 566 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 567 if (item != NULL && !signature->Compare(item->Signature())) { 568 item->ToggleExpandState(false); 556 ExpandItems(); 557 Invalidate(); 558 } 559 560 561 void 562 TBarView::SaveExpandedItems() 563 { 564 if (!fExpando) 565 return; 566 567 // Get a list of the signatures of expanded apps. Can't use 568 // team_id because there can be more than one team per application 569 for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 570 TTeamMenuItem* teamItem 571 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 572 if (teamItem == NULL || teamItem->Signature() == NULL || 573 *teamItem->Signature() == '\0') 574 continue; 575 576 if (teamItem->IsExpanded()) { 577 // Expanded, if signature is not in the list add it 578 bool shouldAdd = true; 579 580 for (int32 sigIndex = sExpandedItems.CountItems(); 581 sigIndex-- > 0;) { 582 BString *signature = (BString *)sExpandedItems.ItemAt(sigIndex); 583 if (signature->ICompare(teamItem->Signature()) == 0) { 584 // already in the list, don't add the signature 585 shouldAdd = false; 569 586 break; 570 587 } 571 588 } 572 }573 589 574 // Clean up expanded signature list. 575 while (!expandedItems.IsEmpty()) { 576 delete static_cast<BString*>(expandedItems.RemoveItem((int32)0)); 590 if (shouldAdd) { 591 // Add the signature to the list 592 BString* signature = new BString(teamItem->Signature()); 593 sExpandedItems.AddItem((void *)signature); 594 } 577 595 } 596 } 597 } 578 598 579 fExpando->SizeWindow(); 599 600 void 601 TBarView::ExpandItems() 602 { 603 if (!fExpando || !fVertical || !Expando() 604 || !static_cast<TBarApp*>(be_app)->Settings()->superExpando 605 || sExpandedItems.CountItems() <= 0) 606 return; 607 608 // Start at the 'bottom' of the list working up. 609 // Prevents being thrown off by expanding items. 610 for (int32 teamIndex = fExpando->CountItems(); teamIndex-- > 0;) { 611 TTeamMenuItem* teamItem 612 = dynamic_cast<TTeamMenuItem*>(fExpando->ItemAt(teamIndex)); 613 if (teamItem == NULL || teamItem->Signature() == NULL 614 || *teamItem->Signature() == '\0') 615 continue; 616 617 for (int32 sigIndex = sExpandedItems.CountItems(); sigIndex-- > 0;) { 618 BString* signature = (BString *)sExpandedItems.ItemAt(sigIndex); 619 620 if (signature->ICompare(teamItem->Signature()) == 0) { 621 teamItem->ToggleExpandState(false); 622 sExpandedItems.RemoveItem(sigIndex); 623 break; 624 } 625 } 580 626 } 581 627 582 Invalidate(); 628 // Clean up the expanded items list 629 while (!sExpandedItems.IsEmpty()) 630 delete static_cast<BString*>(sExpandedItems.RemoveItem((int32)0)); 631 sExpandedItems.MakeEmpty(); 632 633 fExpando->SizeWindow(); 583 634 } 584 635 585 636 -
src/apps/deskbar/BarView.h
diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index 9e165cb..158b28d 100644
a b class TBarView : public BView { 141 141 TExpandoMenuBar* ExpandoMenuBar() const; 142 142 TBarMenuBar* BarMenuBar() const; 143 143 TDragRegion* DragRegion() const { return fDragRegion; } 144 144 static BList sExpandedItems; 145 145 146 private: 146 147 friend class TBeMenu; 147 148 friend class PreferencesWindow; … … class TBarView : public BView { 151 152 void PlaceBeMenu(); 152 153 void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame); 153 154 void PlaceApplicationBar(BRect screenFrame); 155 void SaveExpandedItems(); 156 void ExpandItems(); 154 157 155 158 TBarMenuBar* fBarMenuBar; 156 159 TExpandoMenuBar* fExpando;