Author: aldeck Date: 2011-08-30 23:25:14 +0200 (Tue, 30 Aug 2011) New Revision: 42702 Changeset: https://dev.haiku-os.org/changeset/42702 Added: haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/ haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/Jamfile haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/PoseViewTest.cpp Modified: haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/ContainerWindow.cpp haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/DefaultControls.cpp haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseView.cpp haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseViewController.cpp haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/Jamfile Log: * Added a simple PoseViewTest to ease the decoupling work since PoseView can almost be used like a customisable control now (i.e independent of BContainerWindow). * The test app already helped to spot remaining BContainerWindow coupling issues in BPoseView. * Addded missing _NotifySelectionChanged call in the recent _EndSelectionRect method * Some cleanup, enhanced comments Modified: haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/ContainerWindow.cpp =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/ContainerWindow.cpp 2011-08-30 20:46:07 UTC (rev 42701) +++ haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/ContainerWindow.cpp 2011-08-30 21:25:14 UTC (rev 42702) @@ -765,15 +765,6 @@ fWindowContextMenu = new BPopUpMenu("WindowContext", false, false); fWindowContextMenu->SetFont(be_plain_font); AddWindowContextMenus(fWindowContextMenu); - - // TODO: disabled until menu system rework - /* - Controller()->MenuBar()->RemoveItem(Controller()->WindowMenu()); - delete Controller()->WindowMenu(); - //Controller()->WindowMenu() = new BMenu(B_TRANSLATE("Window")); - Controller()->MenuBar()->AddItem(Controller()->WindowMenu()); - Controller()->AddWindowMenu(Controller()->WindowMenu()); - */ } Modified: haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/DefaultControls.cpp =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/DefaultControls.cpp 2011-08-30 20:46:07 UTC (rev 42701) +++ haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/DefaultControls.cpp 2011-08-30 21:25:14 UTC (rev 42702) @@ -249,6 +249,7 @@ AddSeparatorItem(); + // TODO: check and clean old comments // The "Move To", "Copy To", "Create Link" menus are inserted // at this place, have a look at: // BContainerWindow::SetupMoveCopyMenus() @@ -328,7 +329,7 @@ MoveMenu::MoveMenu(const char* itemName, uint32 messageWhat, PoseViewController* controller) : - BNavMenu(itemName, messageWhat, controller->PoseView()->ContainerWindow()), + BNavMenu(itemName, messageWhat, controller->PoseView()->Window()), fController(controller), fMessageWhat(messageWhat) { @@ -369,7 +370,7 @@ // TODO check if the entry has changed since the last _Populate? - BHandler* target = fController->PoseView()->ContainerWindow(); + BHandler* target = fController->PoseView()->Window(); BVolume volume; BVolumeRoster volumeRoster; @@ -545,7 +546,7 @@ item = new BMenuItem(B_TRANSLATE("Resize to fit"), new BMessage(kResizeToFit), 'Y'); - item->SetTarget(poseView->ContainerWindow()); + item->SetTarget(poseView->Window()); AddItem(item); item = new BMenuItem(B_TRANSLATE("Clean up"), new BMessage(kCleanup), 'K'); Modified: haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseView.cpp =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseView.cpp 2011-08-30 20:46:07 UTC (rev 42701) +++ haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseView.cpp 2011-08-30 21:25:14 UTC (rev 42702) @@ -320,7 +320,7 @@ void BPoseView::_InitCommon() { - printf("(%p) BPoseView::_InitCommon() model=%p\n", this, TargetModel()); + printf("(%p) BPoseView::_InitCommon() model=%p '%s'\n", this, TargetModel(), TargetModel()->Name()); BPoint origin; if (ViewMode() == kListMode) origin = fViewState->ListOrigin(); @@ -1128,7 +1128,7 @@ void BPoseView::AddPoses(Model *model) { - printf("BPoseView::AddPoses model = %p\n", model); + printf("BPoseView::AddPoses model = %p (%s)\n", model, model->Name()); // if model is zero, PoseView has other means of iterating through all // the entries that it adds // TODO: move up in Init() @@ -6607,6 +6607,8 @@ fSelectionPivotPose = NULL; if (fRealPivotPose && !fSelectionList->HasItem(fRealPivotPose)) fRealPivotPose = NULL; + + _NotifySelectionChanged(); } @@ -7795,7 +7797,9 @@ void BPoseView::_NotifySelectionChanged() { - ContainerWindow()->SelectionChanged(); + // TODO remove back reference and make BContainerWindow a PoseViewListener + // when needed + //ContainerWindow()->SelectionChanged(); ListenerList::iterator it = fListeners.begin(); for (; it != fListeners.end(); it++) { Modified: haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseViewController.cpp =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseViewController.cpp 2011-08-30 20:46:07 UTC (rev 42701) +++ haiku/branches/developer/aldeck/tracker_layout/src/kits/tracker/PoseViewController.cpp 2011-08-30 21:25:14 UTC (rev 42702) @@ -37,8 +37,9 @@ #define B_TRANSLATE_CONTEXT "libtracker" -// Note: actually, PoseviewController is the user interface manager, it should be renamed -// accordingly, PoseviewControlManager or Poseview(default)UserInterface +// Note: actually, PoseviewController is the user interface manager, +// it should be renamed accordingly, PoseviewControlManager +// or Poseview(default)UserInterface PoseViewController::PoseViewController() : @@ -97,7 +98,7 @@ new BScrollBar("VScrollBar", fPoseView, 0, 100, B_VERTICAL); } else { printf("Error! PoseViewController::CreateControls you must set a " - "poseview before calling this method!"); + "poseview before calling this method!\n"); } } @@ -179,7 +180,8 @@ if (trash) index = newParent->IndexOf(trash) + 2; else { - printf("PoseViewController::ReparentSharedMenus cant find 'Move to trash' item!\n"); + printf("PoseViewController::ReparentSharedMenus " + "cant find 'Move to trash' item!\n"); newParent = NULL; // will detach the menu } } @@ -188,7 +190,8 @@ if (!ReparentMenu(fMoveToMenu, newParent, index++) || !ReparentMenu(fCopyToMenu, newParent, index++) || !ReparentMenu(fCreateLinkMenu, newParent, index)) { - printf("PoseViewController::ReparentSharedMenus Error reparenting 'Move To/Copy To' menus!\n"); + printf("PoseViewController::ReparentSharedMenus " + "Error reparenting 'Move To/Copy To' menus!\n"); } // This is needed because we want to FindItem by command later @@ -208,20 +211,24 @@ if (openItem) index = newParent->IndexOf(openItem) + 1; else { - printf("PoseViewController::ReparentSharedMenus cant find 'Open' item!\n"); + printf("PoseViewController::ReparentSharedMenus " + "cant find 'Open' item!\n"); newParent = NULL; // will detach the menu } } - if (!ReparentMenu(fOpenWithMenu, newParent, index)) - printf("PoseViewController::ReparentSharedMenus Error reparenting 'Open with' menu!\n"); - else if (fOpenWithMenu != NULL && fOpenWithMenu->Superitem() != NULL) { + if (!ReparentMenu(fOpenWithMenu, newParent, index)) { + printf("PoseViewController::ReparentSharedMenus " + "Error reparenting 'Open with' menu!\n"); + } else if (fOpenWithMenu != NULL && fOpenWithMenu->Superitem() != NULL) { // TODO put the code below in a JustInstalled hook fOpenWithMenu->Superitem()->SetTarget(fPoseView); - fOpenWithMenu->Superitem()->SetShortcut('O', B_COMMAND_KEY | B_CONTROL_KEY); + fOpenWithMenu->Superitem()->SetShortcut('O', + B_COMMAND_KEY | B_CONTROL_KEY); int32 count = PoseView()->SelectionList()->CountItems(); fOpenWithMenu->Superitem()->SetEnabled(count > 0); - fOpenWithMenu->Superitem()->SetMessage(new BMessage(kOpenSelectionWith)); + fOpenWithMenu->Superitem()->SetMessage( + new BMessage(kOpenSelectionWith)); } } @@ -401,7 +408,7 @@ // TODO: autohiding scrollbars doesn't play well with the window"s // sizelimits - /*if (fHorizontalScrollBar) { + if (fHorizontalScrollBar) { SetControlVisible(fHorizontalScrollBar, fHorizontalScrollBar->Proportion() < 1.0); } @@ -409,7 +416,7 @@ if (fVerticalScrollBar) { SetControlVisible(fVerticalScrollBar, fVerticalScrollBar->Proportion() < 1.0); - }*/ + } } Modified: haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/Jamfile =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/Jamfile 2011-08-30 20:46:07 UTC (rev 42701) +++ haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/Jamfile 2011-08-30 21:25:14 UTC (rev 42702) @@ -13,5 +13,6 @@ SubInclude HAIKU_TOP src tests kits shared ; SubInclude HAIKU_TOP src tests kits storage ; SubInclude HAIKU_TOP src tests kits support ; +SubInclude HAIKU_TOP src tests kits tracker ; SubInclude HAIKU_TOP src tests kits translation ; Added: haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/Jamfile =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/Jamfile (rev 0) +++ haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/Jamfile 2011-08-30 21:25:14 UTC (rev 42702) @@ -0,0 +1,13 @@ +SubDir HAIKU_TOP src tests kits tracker ; + +UsePrivateHeaders tracker shared ; + +SubDirHdrs $(HAIKU_TOP) src kits tracker ; + +#SEARCH_SOURCE += [ FDirName $(TOP) src kits tracker ] ; + +SimpleTest PoseViewTest : + PoseViewTest.cpp + : be tracker $(TARGET_LIBSUPC++) + ; + Added: haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/PoseViewTest.cpp =================================================================== --- haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/PoseViewTest.cpp (rev 0) +++ haiku/branches/developer/aldeck/tracker_layout/src/tests/kits/tracker/PoseViewTest.cpp 2011-08-30 21:25:14 UTC (rev 42702) @@ -0,0 +1,140 @@ +/* + * Copyright 2011, Alexandre Deckner. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include <Application.h> +#include <LayoutBuilder.h> +#include <Window.h> + +#include "IconCache.h" +#include "PoseView.h" +#include "PoseViewController.h" + +#include "CountView.h" +#include "Navigator.h" +#include <MenuBar.h> + +#include <stdio.h> + + +class Window : public BWindow { + public: + Window(); + + virtual bool QuitRequested(); +}; + + +Window::Window() + : BWindow(BRect(100, 100, 520, 430), "PoseViewTest /boot/home", + B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) +{ + BEntry entry("/boot/home/"); + entry_ref ref; + entry.GetRef(&ref); + Model* model = new Model(&ref, true); + if (model->InitCheck() != B_OK || !model->IsDirectory()) { + printf("Error initializing Model, ref = '%s'\n", ref.name); + delete model; + return; + } + + IconCache::sIconCache = new IconCache(); + + BPoseView* poseView = new BPoseView(model, kListMode); + PoseViewController* controller = new PoseViewController(); + controller->SetPoseView(poseView); + controller->CreateControls(model); + + BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f) + //.Add(poseView) + .Add(controller->MenuBar()) + .Add(controller->Navigator()) + .Add(controller->TitleView()) + .AddGroup(B_HORIZONTAL, 0.0f) + .Add(controller->PoseView()) + .Add(controller->VerticalScrollBar()) + .End() + .AddGroup(B_HORIZONTAL, 0.0f) + .Add(controller->CountView()) + .Add(controller->HorizontalScrollBar(), 3.0f) + .SetInsets(0, 0, B_V_SCROLL_BAR_WIDTH, 0) + .End(); + + bool forWriting = true; + ModelNodeLazyOpener *modelOpener = + new ModelNodeLazyOpener(model, forWriting, false); + AttributeStreamFileNode* streamNode = NULL; + if (modelOpener->IsOpen(forWriting)) { + streamNode = new AttributeStreamFileNode(modelOpener->TargetModel()->Node()); + poseView->Init(streamNode); + } + + //RestoreState(); // TODO shouldn't be part of BContainerWindow, check if it was restoring the poseview + + controller->CreateMenus(); + //AddContextMenus(); // TODO shouldn't be part of BContainerWindow + //AddCommonShortcuts(); + + //CheckScreenIntersect(); + // check window frame TODO: should be done after/in restorewindowstate + + // TODO: this kind of call could come from a ViewMode object hook that + // customizes the ui + if (poseView->ViewMode() == kListMode) + controller->ShowAttributesMenu(); + + controller->SetControlVisible(controller->Navigator(), true); + controller->CreateMoveCopyMenus(); + + controller->TitleView()->Reset(); +} + + +bool +Window::QuitRequested() +{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +// #pragma mark - + + +class Application : public BApplication { + public: + Application(); + + virtual void ReadyToRun(void); +}; + + +Application::Application() + : BApplication("application/x-vnd.Haiku-poseview-test") +{ +} + + +void +Application::ReadyToRun(void) +{ + BWindow *window = new Window(); + window->Show(); +} + + +// #pragma mark - + + +int +main(int argc, char **argv) +{ + Application app; + + app.Run(); + return 0; +} +