hrev45573 adds 17 changesets to branch 'master' old head: a10aec9c5c49f10496c5c4728f88ebd7aa69b2c3 new head: e94d7e41e8c0b8d16ec43276f9630551b6d06c95 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e94d7e4+%5Ea10aec9 ---------------------------------------------------------------------------- 21fd580: Update Tracker's Find Panel to use the Layout API. Signed-off-by: John Scipione <jscipione@xxxxxxxxx> [ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ] 1b98948: Style fixes [ John Scipione <jscipione@xxxxxxxxx> ] a12df99: Use font relative spacing units [ John Scipione <jscipione@xxxxxxxxx> ] 8e8b861: Set the initial rect to 0 and center the window on screen [ John Scipione <jscipione@xxxxxxxxx> ] 56fe9fa: Refactor attaching FindPanel to FindWindow [ John Scipione <jscipione@xxxxxxxxx> ] c00d064: Right align Add and Remove buttons [ John Scipione <jscipione@xxxxxxxxx> ] c65c2a5: Rename add and remove to add button and remove button [ John Scipione <jscipione@xxxxxxxxx> ] 16c46df: Remove dead code, de-indent comment [ John Scipione <jscipione@xxxxxxxxx> ] 1db0bf0: Make the logic menu fields non-navigatable, tab order [ John Scipione <jscipione@xxxxxxxxx> ] e8a7812: Sentence case Recent queries, clip count from 0 to 10 [ John Scipione <jscipione@xxxxxxxxx> ] d3277fa: Tweak the latch position [ John Scipione <jscipione@xxxxxxxxx> ] bedc696: Put checkboxes under query box in more options [ John Scipione <jscipione@xxxxxxxxx> ] f7467fd: Set the PaneSwitch arrow rect based on the be_plain_font size [ John Scipione <jscipione@xxxxxxxxx> ] 0184cbe: Eliminate variable, set directly [ John Scipione <jscipione@xxxxxxxxx> ] 35e34dd: Use sentence case lowercasing the word "query" [ John Scipione <jscipione@xxxxxxxxx> ] 43f6509: Turn off radio mode and set label from marked for fRecentQueries [ John Scipione <jscipione@xxxxxxxxx> ] e94d7e4: Remove the And/Or menu field when you remove a row [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 516 insertions(+), 586 deletions(-) src/kits/tracker/DialogPane.cpp | 4 +- src/kits/tracker/FindPanel.cpp | 1027 +++++++++++++++++------------------ src/kits/tracker/FindPanel.h | 71 +-- ############################################################################ Commit: 21fd5809a72834b2224334ab55799826a5764914 URL: http://cgit.haiku-os.org/haiku/commit/?id=21fd580 Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Fri Apr 26 18:43:16 2013 UTC Committer: John Scipione <jscipione@xxxxxxxxx> Commit-Date: Sat Apr 27 23:34:17 2013 UTC Update Tracker's Find Panel to use the Layout API. Signed-off-by: John Scipione <jscipione@xxxxxxxxx> ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 6f92e7d..f421f54 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -38,11 +38,15 @@ All rights reserved. #include <Button.h> #include <Catalog.h> #include <CheckBox.h> +#include <ControlLook.h> #include <Debug.h> #include <Directory.h> #include <FindDirectory.h> #include <File.h> #include <FilePanel.h> +#include <GridLayoutBuilder.h> +#include <InterfaceDefs.h> +#include <LayoutBuilder.h> #include <Locale.h> #include <MenuField.h> #include <MenuItem.h> @@ -51,6 +55,9 @@ All rights reserved. #include <PopUpMenu.h> #include <Path.h> #include <Query.h> +#include <SeparatorView.h> +#include <Size.h> +#include <SpaceLayoutItem.h> #include <TextControl.h> #include <TextView.h> #include <View.h> @@ -72,7 +79,6 @@ All rights reserved. #include "FunctionObject.h" #include "IconMenuItem.h" #include "MimeTypes.h" -#include "MiniMenuField.h" #include "Tracker.h" #include "Utilities.h" @@ -82,7 +88,7 @@ All rights reserved. const char* kAllMimeTypes = "mime/ALLTYPES"; -const BRect kInitialRect(100, 100, 530, 210); +const BRect kInitialRect(100, 100, 0, 0); const int32 kInitialAttrModeWindowHeight = 140; const int32 kIncrementPerAttribute = 30; const float kMoreOptionsDelta = 20; @@ -91,6 +97,7 @@ const uint32 kMoreOptionsMessage = 'mrop'; const uint32 kNameModifiedMessage = 'nmmd'; const uint32 kSwitchToQueryTemplate = 'swqt'; const uint32 kRunSaveAsTemplatePanel = 'svtm'; +const uint32 kLatchChanged = 'ltch'; const char* kDragNDropTypes [] = { B_QUERY_MIMETYPE, @@ -177,7 +184,7 @@ MoreOptionsStruct::QueryTemporary(const BNode* node) FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly) : BWindow(kInitialRect, B_TRANSLATE("Find"), B_TITLED_WINDOW, - B_NOT_RESIZABLE | B_NOT_ZOOMABLE), + B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS), fFile(TryOpening(newRef)), fFromTemplate(false), fEditTemplateOnly(false), @@ -212,16 +219,13 @@ FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly) } } - if (fFile) { - BRect initialRect(FindPanel::InitialViewSize(fFile)); - ResizeTo(initialRect.Width(), initialRect.Height()); - } - fFromTemplate = IsQueryTemplate(fFile); - fBackground = new FindPanel(Bounds(), fFile, this, fFromTemplate, + fBackground = new FindPanel(fFile, this, fFromTemplate, fEditTemplateOnly); - AddChild(fBackground); + BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) + .SetInsets(0, 0, 0, 0) + .Add(fBackground); } @@ -279,11 +283,12 @@ FindWindow::SwitchToTemplate(const entry_ref* ref) BFile templateFile(&entry, O_RDONLY); ThrowOnInitCheckError(&templateFile); - DisableUpdates(); + //DisableUpdates(); // turn off updates to reduce flicker while re-populating the // window + // #9689 : couldn't get to work since changing to Layout API fBackground->SwitchToTemplate(&templateFile); - EnableUpdates(); + //EnableUpdates(); } catch (...) { } @@ -669,10 +674,11 @@ FindWindow::MessageReceived(BMessage* message) // #pragma mark - -FindPanel::FindPanel(BRect frame, BFile* node, FindWindow* parent, +FindPanel::FindPanel(BFile* node, FindWindow* parent, bool , bool editTemplateOnly) - : BView(frame, "MainView", B_FOLLOW_ALL, B_WILL_DRAW), + : BView("MainView", B_WILL_DRAW), fMode(kByNameItem), + fAttrGrid(NULL), fDraggableIcon(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -680,39 +686,20 @@ FindPanel::FindPanel(BRect frame, BFile* node, FindWindow* parent, uint32 initialMode = InitialMode(node); - BRect bounds(Bounds()); - BRect boxBounds(bounds); - - boxBounds.InsetBy(15, 30); - boxBounds.bottom -= 10; - AddChild(new BBox(boxBounds, "Box")); - - BRect rect(boxBounds); - rect.top -= 25; - rect.right = rect.left + 20; - rect.bottom = rect.top + 20; - BMessenger self(this); - fRecentQueries = new BPopUpMenu("RecentQueries"); - FindPanel::AddRecentQueries(fRecentQueries, true, &self, + fRecentQueries = new BPopUpMenu(B_TRANSLATE("Recent Queries")); + AddRecentQueries(fRecentQueries, true, &self, kSwitchToQueryTemplate); - AddChild(new MiniMenuField(rect, "RecentQueries", fRecentQueries)); - - rect.left = rect.right + 15; - // add popup for mime types fMimeTypeMenu = new BPopUpMenu("MimeTypeMenu"); fMimeTypeMenu->SetRadioMode(false); AddMimeTypesToMenu(); - rect.right = rect.left + 150; - fMimeTypeField = new BMenuField(rect, "MimeTypeMenu", "", fMimeTypeMenu); + fMimeTypeField = new BMenuField("MimeTypeMenu", "", fMimeTypeMenu); fMimeTypeField->SetDivider(0.0f); fMimeTypeField->MenuItem()->SetLabel( B_TRANSLATE("All files and folders")); - AddChild(fMimeTypeField); - // add popup for search criteria fSearchModeMenu = new BPopUpMenu("searchMode"); fSearchModeMenu->AddItem(new BMenuItem(B_TRANSLATE("by name"), @@ -725,24 +712,17 @@ FindPanel::FindPanel(BRect frame, BFile* node, FindWindow* parent, fSearchModeMenu->ItemAt(initialMode == kByNameItem ? 0 : (initialMode == kByAttributeItem ? 1 : 2))->SetMarked(true); // mark the appropriate mode - rect.left = rect.right + 10; - rect.right = rect.left + 100; - rect.bottom = rect.top + 15; - BMenuField* menuField = new BMenuField(rect, "", "", fSearchModeMenu); - menuField->SetDivider(0.0f); - AddChild(menuField); + BMenuField* searchModeField = new BMenuField("", "", fSearchModeMenu); + searchModeField->SetDivider(0.0f); // add popup for volume list - rect.right = bounds.right - 15; - rect.left = rect.right - 100; fVolMenu = new BPopUpMenu("", false, false); // don't radioMode - menuField = new BMenuField(rect, "", B_TRANSLATE("On"), fVolMenu); - menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 8); - AddChild(menuField); + BMenuField* volumeField = new BMenuField("", B_TRANSLATE("On"), fVolMenu); + volumeField->SetDivider(volumeField->StringWidth(volumeField->Label()) + 8); AddVolumes(fVolMenu); if (!editTemplateOnly) { - BPoint draggableIconOrigin(15, bounds.bottom - 35); + BPoint draggableIconOrigin(0, 0); BMessage dragNDropMessage(B_SIMPLE_DATA); dragNDropMessage.AddInt32("be:actions", B_COPY_TARGET); dragNDropMessage.AddString("be:types", B_FILE_MIME_TYPE); @@ -754,88 +734,109 @@ FindPanel::FindPanel(BRect frame, BFile* node, FindWindow* parent, B_TRANSLATE_NOCOLLECT(kDragNDropActionSpecifiers[1])); BMessenger self(this); - fDraggableIcon = new DraggableQueryIcon(DraggableIcon::PreferredRect( - draggableIconOrigin, B_LARGE_ICON), "saveHere", &dragNDropMessage, - self, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - AddChild(fDraggableIcon); + BRect draggableRect = DraggableIcon::PreferredRect(draggableIconOrigin, + B_LARGE_ICON); + fDraggableIcon = new DraggableQueryIcon(draggableRect, + "saveHere", &dragNDropMessage, self, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + fDraggableIcon->SetExplicitMaxSize(BSize(draggableRect.right - draggableRect.left, + draggableRect.bottom - draggableRect.top)); } - // add the more options collapsible pane - BRect paneInitialRect(bounds); - paneInitialRect.InsetBy(80, 5); - paneInitialRect.right = paneInitialRect.left + 255; - paneInitialRect.top = paneInitialRect.bottom - 30; - BRect paneExpandedRect(paneInitialRect); - paneExpandedRect.bottom += kMoreOptionsDelta; - fMoreOptionsPane = new DialogPane(paneInitialRect, paneExpandedRect, 0, - "moreOptions", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - AddChild(fMoreOptionsPane); - - fMoreOptionsPane->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fMoreOptionsPane->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - // set up the contents of the more options pane - BRect expandedBounds(paneExpandedRect); - expandedBounds.OffsetTo(0, 0); - expandedBounds.InsetBy(5, 5); - - rect = expandedBounds; - rect.right = rect.left + 200; - rect.bottom = rect.top + 20; - fQueryName = new BTextControl(rect, "queryName", - B_TRANSLATE("Query name:"), "", B_FOLLOW_NONE, - B_NAVIGABLE | B_NAVIGABLE_JUMP); - fQueryName->SetDivider(fQueryName->StringWidth(fQueryName->Label()) + 5); - fMoreOptionsPane->AddItem(fQueryName, 1); + fQueryName = new BTextControl("query name", B_TRANSLATE("Query name:"), + "", NULL, B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP); FillCurrentQueryName(fQueryName, parent); + fSearchTrashCheck = new BCheckBox("searchTrash", + B_TRANSLATE("Include trash"), NULL); + fTemporaryCheck = new BCheckBox("temporary", + B_TRANSLATE("Temporary"), NULL); + fTemporaryCheck->SetValue(B_CONTROL_ON); - rect.top = rect.bottom + 6; - rect.bottom = rect.top + 16; - rect.right = rect.left + 100; - fSearchTrashCheck = new BCheckBox(rect, "searchTrash", - B_TRANSLATE("Include trash"), 0); - fSearchTrashCheck->ResizeToPreferred(); - fMoreOptionsPane->AddItem(fSearchTrashCheck, 1); - - rect.OffsetBy(fSearchTrashCheck->Bounds().Width() + 8, 0); - fTemporaryCheck = new BCheckBox(rect, "temporary", - B_TRANSLATE("Temporary"), 0); - fMoreOptionsPane->AddItem(fTemporaryCheck, 1); - fTemporaryCheck->SetValue(1); - - BRect latchRect(paneInitialRect); - latchRect.left -= 20; - latchRect.right = latchRect.left + 10; - latchRect.top = paneInitialRect.top + paneInitialRect.Height() / 2 - 5; - - latchRect.bottom = latchRect.top + 12; - - fLatch = new PaneSwitch(latchRect, "moreOptionsLatch", true, - B_FOLLOW_BOTTOM | B_FOLLOW_LEFT); - AddChild(fLatch); - fMoreOptionsPane->SetSwitch(fLatch); - - if (initialMode != kByAttributeItem) - AddByNameOrFormulaItems(); - else - AddByAttributeItems(node); + // add the more options collapsible pane + fMoreOptions = new BBox(B_NO_BORDER, BLayoutBuilder::Group<>() + .AddGroup(B_VERTICAL) + .Add(fQueryName) + .AddGroup(B_HORIZONTAL) + .Add(fSearchTrashCheck) + .Add(fTemporaryCheck) + .End() + .End() + .View()); + + fLatch = new PaneSwitch("optionsLatch", true, B_WILL_DRAW); + fLatch->SetLabels(B_TRANSLATE("Fewer options"), B_TRANSLATE("More options")); + fLatch->SetValue(0); + fLatch->SetMessage(new BMessage(kLatchChanged)); + fLatch->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); + fMoreOptions->Hide(); // add Search button - rect = bounds; - rect.left = rect.right - 80; - rect.top = rect.bottom - 30; - rect.right = rect.left + 60; - rect.bottom = rect.top + 20; BButton* button; if (editTemplateOnly) { - button = new BButton(rect, "save", B_TRANSLATE("Save"), + button = new BButton("save", B_TRANSLATE("Save"), new BMessage(kSaveButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); } else { - button = new BButton(rect, "find", B_TRANSLATE("Search"), + button = new BButton("find", B_TRANSLATE("Search"), new BMessage(kFindButton), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); } - AddChild(button); button->MakeDefault(true); + + BView* icon = fDraggableIcon; + if (icon == NULL) { + icon = new BBox("no draggable icon", B_WILL_DRAW, B_NO_BORDER); + icon->SetExplicitMaxSize(BSize(0, 0)); + } + + BView* mimeTypeFieldSpacer = new BBox("MimeTypeMenuSpacer", B_WILL_DRAW, B_NO_BORDER); + mimeTypeFieldSpacer->SetExplicitMaxSize(BSize(0, 0)); + + BBox* queryControls = new BBox("Box"); + queryControls->SetBorder(B_NO_BORDER); + + BBox* queryBox = new BBox("Outer Controls"); + BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL, fRecentQueries); + queryBox->SetLabel(recentQueriesMenuField); + + BGroupView* queryBoxView = new BGroupView(B_VERTICAL, 10.0); + queryBoxView->GroupLayout()->SetInsets(10, 10, 10, 10); + queryBox->AddChild(queryBoxView); + + icon->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_BOTTOM)); + button->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); + + BLayoutBuilder::Group<>(queryBoxView, B_VERTICAL, 10.0) + .SetInsets(10, 10, 10, 10) + .AddGroup(B_HORIZONTAL, 1.0) + .Add(fMimeTypeField) + .Add(mimeTypeFieldSpacer) + .Add(searchModeField) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(B_USE_DEFAULT_SPACING)) + .Add(volumeField) + .End() + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(queryControls); + BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) + .SetInsets(10, 10, 10, 10) + .Add(queryBox) + .AddGroup(B_HORIZONTAL, 10.0) + .Add(icon) + .AddGroup(B_VERTICAL) + .AddGroup(B_HORIZONTAL) + .Add(fLatch) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .End() + .Add(fMoreOptions) + .End() + .Add(button) + .End(); + + if (initialMode != kByAttributeItem) + AddByNameOrFormulaItems(); + else + AddByAttributeItems(node); + + ResizeMenuField(fMimeTypeField); + ResizeMenuField(searchModeField); + ResizeMenuField(volumeField); } @@ -850,7 +851,7 @@ FindPanel::AttachedToWindow() BNode* node = dynamic_cast<FindWindow*>(Window())->QueryNode(); fSearchModeMenu->SetTargetForItems(this); fQueryName->SetTarget(this); - fLatch->SetTarget(fMoreOptionsPane); + fLatch->SetTarget(this); RestoreMimeTypeMenuSelection(node); // preselect the mime we used the last time have to do it here // because AddByAttributeItems will build different menus based @@ -864,7 +865,7 @@ FindPanel::AttachedToWindow() if (!textControl) { // pick the last text control in the attribute view BString title("TextEntry"); - title << (fAttrViewList.CountItems() - 1); + title << (fAttrGrid->CountRows() - 1); textControl = dynamic_cast<BTextControl*>(FindView(title.String())); } @@ -890,67 +891,62 @@ FindPanel::AttachedToWindow() } fMimeTypeMenu->SetTargetForItems(this); - if (fDraggableIcon) fDraggableIcon->SetTarget(BMessenger(this)); fRecentQueries->SetTargetForItems(Window()); } -const float kAttrViewDelta = 30; -BRect -FindPanel::InitialViewSize(const BNode* node) +void +FindPanel::ResizeMenuField(BMenuField* menuField) { - if (!node || InitialMode(node) != (int32)kByAttributeItem) - return kInitialRect; + BSize size; + menuField->GetPreferredSize(&size.width, &size.height); - int32 numAttributes = InitialAttrCount(node); - if (numAttributes < 1) - numAttributes = 1; + BMenu* menu = menuField->Menu(); - BRect result = kInitialRect; - result.bottom = result.top + kInitialAttrModeWindowHeight - + (numAttributes - 1) * kIncrementPerAttribute; - - return result; -} - - -float -FindPanel::ViewHeightForMode(uint32 mode, bool moreOptions) -{ - float result = moreOptions ? kMoreOptionsDelta : 0; - switch (mode) { - case kByFormulaItem: - case kByNameItem: - return 110 + result; - - case kByAttributeItem: - return 110 + result + kAttrViewDelta; + float padding = 0.0; + float width = size.width; + BMenuItem* markedItem = menu->FindMarked(); + if (markedItem != NULL) { + if (markedItem->Submenu() != NULL) { + BMenuItem* markedSubItem = markedItem->Submenu()->FindMarked(); + if (markedSubItem != NULL && markedSubItem->Label() != NULL) { + float labelWidth = StringWidth(markedSubItem->Label()); + padding = size.width - labelWidth; + } + } else if (markedItem->Label() != NULL) { + float labelWidth = StringWidth(markedItem->Label()); + padding = size.width - labelWidth; + } } - TRESPASS(); - return 0; -} - - -float -FindPanel::BoxHeightForMode(uint32 mode, bool /*moreOptions*/) -{ - switch (mode) { - case kByFormulaItem: - case kByNameItem: - return 40; - - case kByAttributeItem: - return 40 + kAttrViewDelta; + for (int32 index = menu->CountItems(); index-- > 0; ) { + BMenuItem* item = menu->ItemAt(index); + if (item->Label() != NULL) { + float labelWidth = StringWidth(item->Label()); + if (labelWidth > width) { + width = labelWidth; + } + } + BMenu* submenu = item->Submenu(); + if (submenu != NULL) { + for (int32 subIndex = submenu->CountItems(); subIndex-- > 0; ) { + BMenuItem* subItem = submenu->ItemAt(subIndex); + if (subItem->Label() != NULL) { + float labelWidth = StringWidth(subItem->Label()); + if (labelWidth > width) + width = labelWidth; + } + } + } } - TRESPASS(); - return 0; -} + size.width = width + padding; + menuField->SetExplicitMinSize(size); +} static void PopUpMenuSetTitle(BMenu* menu, const char* title) @@ -1007,10 +1003,44 @@ FindPanel::ShowVolumeMenuLabel() void +FindPanel::Draw(BRect) +{ + if (fAttrGrid == NULL) + return; + + for (int32 index = 0; index < fAttrGrid->CountRows(); index++) { + + BMenuField* menuField + = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); + if (!menuField) + return; + + BMenuItem* item = menuField->Menu()->FindMarked(); + if (!item) + return; + + if (item->Submenu()->FindMarked()) { + BLayoutItem* stringView = fAttrGrid->ItemAt(1, index); + if (stringView == NULL) + stringView = fAttrGrid->AddView(new BStringView("", + item->Submenu()->FindMarked()->Label()), 1, index); + else + dynamic_cast<BStringView*>(stringView->View())->SetText( + item->Submenu()->FindMarked()->Label()); + + stringView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, + B_ALIGN_VERTICAL_UNSET)); + } + } +} + + +void FindPanel::MessageReceived(BMessage* message) { entry_ref dir; const char* name; + BMenuItem* item; switch (message->what) { case kVolumeItem: @@ -1065,11 +1095,11 @@ FindPanel::MessageReceived(BMessage* message) break; case kAddItem: - AddAttrView(); + AddAttrRow(); break; case kRemoveItem: - RemoveAttrView(); + RemoveAttrRow(); break; case kMIMETypeItem: @@ -1089,17 +1119,9 @@ FindPanel::MessageReceived(BMessage* message) // the attributes for this type may be different, // rip out the existing ones - RemoveAttrViewItems(); - - Window()->ResizeTo(Window()->Frame().Width(), - ViewHeightForMode(kByAttributeItem, fLatch->Value() != 0)); - - BBox* box = dynamic_cast<BBox*>(FindView("Box")); - ASSERT(box); - box->ResizeTo(box->Bounds().Width(), - BoxHeightForMode(kByAttributeItem, fLatch->Value() != 0)); + RemoveAttrViewItems(false); - AddAttrView(); + AddAttrRow(); break; } @@ -1108,6 +1130,35 @@ FindPanel::MessageReceived(BMessage* message) fTemporaryCheck->SetValue(0); break; + case kAttributeItem: + if (message->FindPointer("source", (void**)&item) != B_OK) + return; + + item->Menu()->Superitem()->SetMarked(true); + Invalidate(); + break; + + case kAttributeItemMain: + // in case someone selected just an attribute without the + // comparator + if (message->FindPointer("source", (void**)&item) != B_OK) + return; + + if (item->Submenu()->ItemAt(0)) + item->Submenu()->ItemAt(0)->SetMarked(true); + Invalidate(); + break; + + case kLatchChanged: + int32 value; + if (message->FindInt32("be:value", &value) == B_OK) { + if (value == 0 && !fMoreOptions->IsHidden(this)) + fMoreOptions->Hide(); + else if (value == 1 && fMoreOptions->IsHidden(this)) + fMoreOptions->Show(); + } + break; + case B_SAVE_REQUESTED: { // finish saving query template from a SaveAs panel @@ -1202,25 +1253,46 @@ FindPanel::SaveAsQueryOrTemplate(const entry_ref* dir, const char* name, } +BView* +FindPanel::FindAttrView(const char* name, int row) const +{ + for (int32 index = 0; index < fAttrGrid->CountColumns(); index++) { + + BLayoutItem* item = fAttrGrid->ItemAt(index, row); + if (item == NULL) + continue; + + BView* view = item->View(); + if (view == NULL) + continue; + + view = view->FindView(name); + if (view != NULL) + return view; + + } + + return NULL; +} + void FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const { dynamicDate = false; // go through each attrview and add the attr and comparison info - for (int32 index = 0; index < fAttrViewList.CountItems(); index++) { + for (int32 index = 0; index < fAttrGrid->CountRows(); index++) { - TAttrView* view = fAttrViewList.ItemAt(index); BString title; title << "TextEntry" << index; BTextControl* textControl = dynamic_cast<BTextControl*> - (view->FindView(title.String())); + (FindAttrView(title, index)); if (!textControl) return; BMenuField* menuField - = dynamic_cast<BMenuField*>(view->FindView("MenuField")); + = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); if (!menuField) return; @@ -1331,9 +1403,8 @@ FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const // add logic based on selection in Logic menufield if (index > 0) { - TAttrView* prevView = fAttrViewList.ItemAt(index - 1); menuField - = dynamic_cast<BMenuField*>(prevView->FindView("Logic")); + = dynamic_cast<BMenuField*>(FindAttrView("Logic", index - 1)); if (menuField) { item = menuField->Menu()->FindMarked(); if (item) { @@ -1404,10 +1475,9 @@ FindPanel::GetDefaultName(BString &result) const BMenuItem* item = fMimeTypeMenu->FindMarked(); if (item != NULL) result << item->Label() << ": "; - - for (int32 i = 0; i < fAttrViewList.CountItems(); i++) { - fAttrViewList.ItemAt(i)->GetDefaultName(result); - if (i + 1 < fAttrViewList.CountItems()) + for (int32 i = 0; i < fAttrGrid->CountRows(); i++) { + GetDefaultAttrName(result, i); + if (i + 1 < fAttrGrid->CountRows()) result << ", "; } break; @@ -1454,9 +1524,6 @@ FindPanel::SwitchMode(uint32 mode) // no work, bail return; - BBox* box = dynamic_cast<BBox*>(FindView("Box")); - ASSERT(box); - uint32 oldMode = fMode; BString buffer; @@ -1477,16 +1544,6 @@ FindPanel::SwitchMode(uint32 mode) case kByNameItem: { fMode = mode; - Window()->ResizeTo(Window()->Frame().Width(), - ViewHeightForMode(mode, fLatch->Value() != 0)); - BRect bounds(Bounds()); - bounds.InsetBy(15, 30); - bounds.bottom -= 10; - if (fLatch->Value()) - bounds.bottom -= kMoreOptionsDelta; - box->ResizeTo(bounds.Width(), BoxHeightForMode(mode, - fLatch->Value() != 0)); - RemoveByAttributeItems(); ShowOrHideMimeTypeMenu(); AddByNameOrFormulaItems(); @@ -1504,12 +1561,6 @@ FindPanel::SwitchMode(uint32 mode) case kByAttributeItem: { fMode = mode; - box->ResizeTo(box->Bounds().Width(), - BoxHeightForMode(mode, fLatch->Value() != 0)); - - Window()->ResizeTo(Window()->Frame().Width(), - ViewHeightForMode(mode, fLatch->Value() != 0)); - BTextControl* textControl = dynamic_cast<BTextControl*>(FindView("TextControl")); if (textControl) { @@ -1518,7 +1569,7 @@ FindPanel::SwitchMode(uint32 mode) } ShowOrHideMimeTypeMenu(); - AddAttrView(); + AddAttrRow(); break; } } @@ -1901,46 +1952,28 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, void -FindPanel::AddOneAttributeItem(BBox* box, BRect rect) -{ - TAttrView* attrView = new TAttrView(rect, fAttrViewList.CountItems()); - fAttrViewList.AddItem(attrView); - - box->AddChild(attrView); - attrView->MakeTextViewFocus(); -} - - -void FindPanel::SetUpAddRemoveButtons(BBox* box) { - BButton* button = Window() != NULL - ? dynamic_cast<BButton*>(Window()->FindView("remove")) - : NULL; - if (button == NULL) { - BRect rect = box->Bounds(); - rect.InsetBy(5, 10); - rect.top = rect.bottom - 20; - rect.right = rect.left + 22 - + be_plain_font->StringWidth(B_TRANSLATE("Add")); - - button = new BButton(rect, "add", B_TRANSLATE("Add"), - new BMessage(kAddItem), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); - button->SetTarget(this); - box->AddChild(button); + BButton* removeButton = dynamic_cast<BButton*>(box->FindView("remove")); + if (removeButton == NULL) { + BButton* addButton = new BButton("add", B_TRANSLATE("Add"), + new BMessage(kAddItem)); + addButton->SetTarget(this); - rect.OffsetBy(rect.Width() + 6, 0); - rect.right = rect.left + 22 - + be_plain_font->StringWidth(B_TRANSLATE("Remove")); - button = new BButton(rect, "remove", B_TRANSLATE("Remove"), - new BMessage(kRemoveItem), B_FOLLOW_RIGHT + B_FOLLOW_BOTTOM); + removeButton = new BButton("remove", B_TRANSLATE("Remove"), + new BMessage(kRemoveItem)); + removeButton->SetEnabled(false); + removeButton->SetTarget(this); - button->SetEnabled(false); - button->SetTarget(this); - box->AddChild(button); + BGroupLayout* layout = dynamic_cast<BGroupLayout*>(box->GetLayout()); + BLayoutBuilder::Group<>(layout) + .AddGroup(B_HORIZONTAL) + .Add(addButton) + .Add(removeButton) + .AddGlue(); } // enable remove button as needed - button->SetEnabled(fAttrViewList.CountItems() > 1); + removeButton->SetEnabled(fAttrGrid->CountRows() > 1); } @@ -1953,72 +1986,64 @@ FindPanel::FillCurrentQueryName(BTextControl* queryName, FindWindow* window) void -FindPanel::AddAttrView() +FindPanel::AddAttrRow() { BBox* box = dynamic_cast<BBox*>(FindView("Box")); - BRect bounds(Bounds()); + BGridView* grid = dynamic_cast<BGridView*>(box->FindView("AttrFields")); - TAttrView* previous = fAttrViewList.LastItem(); + if (grid == NULL) { + // reset layout + BLayoutBuilder::Group<>(box, B_VERTICAL); - if (previous) - Window()->ResizeBy(0, 30); + grid = new BGridView("AttrFields"); + //box->SetBorder(B_FANCY_BORDER); + box->AddChild(grid); + } - bounds = Bounds(); - bounds.InsetBy(15, 30); - bounds.bottom -= 10 + (fLatch->Value() ? kAttrViewDelta : 0); + fAttrGrid = grid->GridLayout(); - if (previous) { - box->ResizeTo(bounds.Width(), bounds.Height()); - bounds = previous->Frame(); - bounds.OffsetBy(0, 30); - } else { - bounds = box->Bounds(); - bounds.InsetBy(5, 5); - bounds.bottom = bounds.top + 25; - } - AddOneAttributeItem(box, bounds); + AddAttributeControls(fAttrGrid->CountRows()); // add logic to previous attrview - if (previous) - previous->AddLogicMenu(); + if (fAttrGrid->CountRows() > 1) + AddLogicMenu(fAttrGrid->CountRows() - 2); SetUpAddRemoveButtons(box); - - // populate mime popup - TAttrView* last = fAttrViewList.LastItem(); - last->AddMimeTypeAttrs(); } void -FindPanel::RemoveAttrView() +FindPanel::RemoveAttrRow() { - if (fAttrViewList.CountItems() < 2) + if (fAttrGrid->CountRows() < 2) return; - BBox* box = dynamic_cast<BBox*>(FindView("Box")); - TAttrView* attrView = fAttrViewList.LastItem(); - if (!box || !attrView) - return; + BView* view; - Window()->ResizeBy(0, -30); - BRect bounds(Bounds()); - bounds.InsetBy(15, 30); - bounds.bottom -= 10 + (fLatch->Value() ? kAttrViewDelta : 0); - box->ResizeTo(bounds.Width(), bounds.Height()); + int32 row = fAttrGrid->CountRows() - 1; + for (int32 col = fAttrGrid->CountColumns(); col > 0; col--) { + BLayoutItem* item = fAttrGrid->ItemAt(col - 1, row); + if (item == NULL) + continue; + + view = item->View(); + if (view == NULL) + continue; - fAttrViewList.RemoveItem(attrView); - attrView->RemoveSelf(); - delete attrView; + view->RemoveSelf(); + delete view; + } - attrView = fAttrViewList.LastItem(); - attrView->RemoveLogicMenu(); - attrView->MakeTextViewFocus(); + BString string = "TextEntry"; + string << (row - 1); + view = FindAttrView(string.String(), row - 1); + if (view != NULL) + view->MakeFocus(); - if (fAttrViewList.CountItems() != 1) + if (fAttrGrid->CountRows() != 1) return; - BButton* button = dynamic_cast<BButton*>(Window()->FindView("remove")); + BButton* button = dynamic_cast<BButton*>(FindView("remove")); if (button) button->SetEnabled(false); } @@ -2107,12 +2132,12 @@ FindPanel::SaveWindowState(BNode* node, bool editTemplate) case kByAttributeItem: { BMessage message; - int32 count = fAttrViewList.CountItems(); + int32 count = fAttrGrid->CountRows(); node->WriteAttr(kAttrQueryInitialNumAttrs, B_INT32_TYPE, 0, &count, sizeof(int32)); for (int32 index = 0; index < count; index++) - fAttrViewList.ItemAt(index)->SaveState(&message, index); + SaveAttrState(&message, index); ssize_t size = message.FlattenedSize(); char* buffer = new char[size]; @@ -2143,25 +2168,12 @@ FindPanel::SaveWindowState(BNode* node, bool editTemplate) void FindPanel::SwitchToTemplate(const BNode* node) { - if (fLatch->Value()) { - // this is kind of a hack - the following code up to - // RestoreWindowState assumes the latch is closed - // Would be nicer if all the size of the window were set once - // and correctly - this is not easy thought because the latch - // controls the window size in relative increments - fLatch->SetValue(0); - fMoreOptionsPane->SetMode(0); - } - SwitchMode(InitialMode(node)); // update the menu to correspond to the mode MarkNamedMenuItem(fSearchModeMenu, InitialMode(node), true); - BRect initialRect(InitialViewSize(node)); - Window()->ResizeTo(initialRect.Width(), initialRect.Height()); if (Mode() == (int32)kByAttributeItem) { RemoveByAttributeItems(); - ResizeAttributeBox(node); AddByAttributeItems(node); } @@ -2205,7 +2217,10 @@ FindPanel::RestoreWindowState(const BNode* node) (saveMoreOptions.showMoreOptions != 0); fLatch->SetValue(saveMoreOptions.showMoreOptions); - fMoreOptionsPane->SetMode(saveMoreOptions.showMoreOptions); + if (saveMoreOptions.showMoreOptions == 1 && fMoreOptions->IsHidden()) + fMoreOptions->Show(); + else if (saveMoreOptions.showMoreOptions == 0 && !fMoreOptions->IsHidden()) + fMoreOptions->Hide(); fSearchTrashCheck->SetValue(saveMoreOptions.searchTrash); fTemporaryCheck->SetValue(saveMoreOptions.temporary); @@ -2270,8 +2285,7 @@ FindPanel::RestoreWindowState(const BNode* node) BMessage message; if (message.Unflatten(buffer) == B_OK) for (int32 index = 0; index < count; index++) { - fAttrViewList.ItemAt(index)->RestoreState(message, - index); + RestoreAttrState(message, index); } } delete[] buffer; @@ -2316,37 +2330,14 @@ FindPanel::RestoreWindowState(const BNode* node) void -FindPanel::ResizeAttributeBox(const BNode* node) -{ - BBox* box = dynamic_cast<BBox*>(FindView("Box")); - BRect bounds(box->Bounds()); - int32 count = InitialAttrCount(node); - - bounds.bottom = count * 30 + 40; - box->ResizeTo(bounds.Width(), bounds.Height()); -} - - -void FindPanel::AddByAttributeItems(const BNode* node) { - BBox* box = dynamic_cast<BBox*>(FindView("Box")); - ASSERT(box); - BRect bounds(box->Bounds()); - int32 numAttributes = InitialAttrCount(node); if (numAttributes < 1) numAttributes = 1; - BRect rect(bounds); - rect.InsetBy(5, 5); - rect.bottom = rect.top + 25; - - for (int32 index = 0; index < numAttributes; index ++) { - AddOneAttributeItem(box, rect); - rect.OffsetBy(0, 30); - } - SetUpAddRemoveButtons(box); + for (int32 index = 0; index < numAttributes; index ++) + AddAttrRow(); } @@ -2354,29 +2345,35 @@ void FindPanel::AddByNameOrFormulaItems() { BBox* box = dynamic_cast<BBox*>(FindView("Box")); + // reset layout + BLayoutBuilder::Group<>(box, B_VERTICAL); - BRect bounds(box->Bounds()); - bounds.InsetBy(10, 10); - BTextControl* textControl = new BTextControl(bounds, "TextControl", + BTextControl* textControl = new BTextControl("TextControl", "", "", NULL); textControl->SetDivider(0.0f); + box->SetBorder(B_NO_BORDER); box->AddChild(textControl); textControl->MakeFocus(); } void -FindPanel::RemoveAttrViewItems() +FindPanel::RemoveAttrViewItems(bool removeGrid) { - for (;;) { - BView* view = FindView("AttrView"); - if (view == NULL) - break; + if (fAttrGrid == NULL) + return; + + BView* view = fAttrGrid->View(); + for (int32 index = view->CountChildren(); index > 0; index--) { + BView* child = view->ChildAt(index - 1); + child->RemoveSelf(); + delete child; + } + if (removeGrid) { view->RemoveSelf(); delete view; + fAttrGrid = NULL; } - - fAttrViewList.MakeEmpty(); } @@ -2396,7 +2393,7 @@ FindPanel::RemoveByAttributeItems() delete view; } - view = dynamic_cast<BTextControl*>(FindView("TextControl")); + view = FindView("TextControl"); if (view) { view->RemoveSelf(); delete view; @@ -2407,25 +2404,26 @@ FindPanel::RemoveByAttributeItems() void FindPanel::ShowOrHideMimeTypeMenu() { + BView* menuFieldSpacer = FindView("MimeTypeMenuSpacer"); BMenuField* menuField = dynamic_cast<BMenuField*>(FindView("MimeTypeMenu")); - if (Mode() == (int32)kByFormulaItem && !menuField->IsHidden()) + if (Mode() == (int32)kByFormulaItem && !menuField->IsHidden(this)) { + BSize size = menuField->ExplicitMinSize(); menuField->Hide(); - else if (menuField->IsHidden()) + menuFieldSpacer->SetExplicitMinSize(size); + menuFieldSpacer->SetExplicitMaxSize(size); + if (menuFieldSpacer->IsHidden(this)) + menuFieldSpacer->Show(); + } else if (menuField->IsHidden(this)) { + menuFieldSpacer->Hide(); menuField->Show(); + } } -// #pragma mark - - - -TAttrView::TAttrView(BRect frame, int32 index) - : - BView(frame, "AttrView", B_FOLLOW_NONE, B_WILL_DRAW) +void +FindPanel::AddAttributeControls(int32 gridRow) { - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - BPopUpMenu* menu = new BPopUpMenu("PopUp"); // add NAME attribute to popup @@ -2502,56 +2500,33 @@ TAttrView::TAttrView(BRect frame, int32 index) message->AddInt32("operator", B_GE); submenu->AddItem(new BMenuItem(B_TRANSLATE("after"), message)); - BRect bounds(Bounds()); - bounds.right = bounds.left + 100; - bounds.bottom = bounds.top + 15; - fMenuField = new BMenuField(bounds, "MenuField", "", menu); - fMenuField->SetDivider(0.0f); - - // add text entry box - bounds = Bounds(); - bounds.left += bounds.right - 180; - bounds.top += 2; - bounds.right -= 42; - BString title("TextEntry"); - title << index; - fTextControl = new BTextControl(bounds, title.String(), "", "", NULL); - fTextControl->SetDivider(0.0f); - AddChild(fTextControl); - - AddChild(fMenuField); - // add attributes from currently selected mimetype -} - - -TAttrView::~TAttrView() -{ -} + BMenuField* menuField = new BMenuField("MenuField", "", menu); + menuField->SetDivider(0.0f); + fAttrGrid->AddView(menuField, 0, gridRow); + BString title("TextEntry"); + title << gridRow; + BTextControl* textControl = new BTextControl(title.String(), "", "", NULL); + textControl->SetDivider(0.0f); + fAttrGrid->AddView(textControl, 2, gridRow); + textControl->MakeFocus(); -void -TAttrView::AttachedToWindow() -{ - BMenu* menu = fMenuField->Menu(); // target everything menu->SetTargetForItems(this); for (int32 index = menu->CountItems() - 1; index >= 0; index--) menu->SubmenuAt(index)->SetTargetForItems(this); -} - -void -TAttrView::MakeTextViewFocus() -{ - fTextControl->MakeFocus(); + // populate mime popup + AddMimeTypeAttrs(menu); } void -TAttrView::RestoreState(const BMessage &message, int32 index) +FindPanel::RestoreAttrState(const BMessage &message, int32 index) { - BMenu* menu = fMenuField->Menu(); + BMenu* menu = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)) + ->Menu(); // decode menu selections AddMimeTypeAttrs(menu); @@ -2568,27 +2543,32 @@ TAttrView::RestoreState(const BMessage &message, int32 index) } // decode attribute text - ASSERT(fTextControl); + BString bstring = "TextEntry"; + bstring << index; + BTextControl* textControl + = dynamic_cast<BTextControl*>(FindAttrView(bstring.String(), index)); + ASSERT(textControl); const char* string; if (message.FindString("attrViewText", index, &string) == B_OK) - fTextControl->TextView()->SetText(string); + textControl->TextView()->SetText(string); int32 logicMenuSelectedIndex; - BMenuField* field = dynamic_cast<BMenuField*>(FindView("Logic")); + BMenuField* field = dynamic_cast<BMenuField*>(FindAttrView("Logic", index)); if (message.FindInt32("logicalRelation", index, &logicMenuSelectedIndex) == B_OK) { if (field) field->Menu()->ItemAt(logicMenuSelectedIndex)->SetMarked(true); else - AddLogicMenu(logicMenuSelectedIndex == 0); + AddLogicMenu(index, logicMenuSelectedIndex == 0); } } void -TAttrView::SaveState(BMessage* message, int32) +FindPanel::SaveAttrState(BMessage* message, int32 index) { - BMenu* menu = fMenuField->Menu(); + BMenu* menu = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)) + ->Menu(); // encode main attribute menu selection BMenuItem* item = menu->FindMarked(); @@ -2607,10 +2587,14 @@ TAttrView::SaveState(BMessage* message, int32) message->AddString("subMenuSelection", label); // encode attribute text - ASSERT(fTextControl); - message->AddString("attrViewText", fTextControl->TextView()->Text()); + BString string = "TextEntry"; + string << index; + BTextControl* textControl + = dynamic_cast<BTextControl*>(FindAttrView(string.String(), index)); + ASSERT(textControl); + message->AddString("attrViewText", textControl->TextView()->Text()); - BMenuField* field = dynamic_cast<BMenuField*>(FindView("Logic")); + BMenuField* field = dynamic_cast<BMenuField*>(FindAttrView("Logic", index)); if (field) { BMenuItem* item = field->Menu()->FindMarked(); ASSERT(item); @@ -2619,8 +2603,9 @@ TAttrView::SaveState(BMessage* message, int32) } } + void -TAttrView::AddLogicMenu(bool selectAnd) +FindPanel::AddLogicMenu(int32 index, bool selectAnd) { // add "AND/OR" menu BPopUpMenu* menu = new BPopUpMenu(""); @@ -2640,20 +2625,19 @@ TAttrView::AddLogicMenu(bool selectAnd) menu->SetTargetForItems(this); - BRect bounds(Bounds()); - bounds.left = bounds.right - 40; - bounds.bottom = bounds.top + 15; - BMenuField* menufield = new BMenuField(bounds, "Logic", "", menu); + BMenuField* menufield = new BMenuField("Logic", "", menu); menufield->SetDivider(0.0f); - menufield->HidePopUpMarker(); - AddChild(menufield); + + menufield->SetExplicitMaxSize(menufield->MinSize()); + + fAttrGrid->AddView(menufield, 3, index); } void -TAttrView::RemoveLogicMenu() +FindPanel::RemoveLogicMenu(int32 index) { - BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("Logic")); + BMenuField* menufield = dynamic_cast<BMenuField*>(FindAttrView("Logic", index)); if (menufield) { menufield->RemoveSelf(); delete menufield; @@ -2662,67 +2646,7 @@ TAttrView::RemoveLogicMenu() void -TAttrView::Draw(BRect) -{ - BMenuItem* item = fMenuField->Menu()->FindMarked(); - if (!item) - return; - - if (item->Submenu()->FindMarked()) { - float width = StringWidth(item->Submenu()->FindMarked()->Label()); - BRect bounds(fTextControl->Frame()); - - // draws the is/contains, etc. string - bounds.left -= (width + 10); - bounds.bottom -= 6; - DrawString(item->Submenu()->FindMarked()->Label(), - bounds.LeftBottom()); - } -} - - -void -TAttrView::MessageReceived(BMessage* message) -{ - BMenuItem* item; - - switch (message->what) { - case kAttributeItem: - if (message->FindPointer("source", (void**)&item) != B_OK) - return; - - item->Menu()->Superitem()->SetMarked(true); - Invalidate(); - break; - - case kAttributeItemMain: - // in case someone selected just and attribute without the - // comparator - if (message->FindPointer("source", (void**)&item) != B_OK) - return; - - if (item->Submenu()->ItemAt(0)) - item->Submenu()->ItemAt(0)->SetMarked(true); - Invalidate(); - break; - - default: - _inherited::MessageReceived(message); - break; - } -} - - -void -TAttrView::AddMimeTypeAttrs() -{ - BMenu* menu = fMenuField->Menu(); - AddMimeTypeAttrs(menu); -} - - -void -TAttrView::AddAttributes(BMenu* menu, const BMimeType &mimeType) +FindPanel::AddAttributes(BMenu* menu, const BMimeType &mimeType) { // only add things to menu which have "user-visible" data BMessage attributeMessage; @@ -2835,15 +2759,10 @@ TAttrView::AddAttributes(BMenu* menu, const BMimeType &mimeType) void -TAttrView::AddMimeTypeAttrs(BMenu* menu) +FindPanel::AddMimeTypeAttrs(BMenu* menu) { - FindPanel* mainView = dynamic_cast<FindPanel*>(Parent()-> - Parent()->FindView("MainView")); - if (!mainView) - return; - const char* typeName; - if (mainView->CurrentMimeType(&typeName) == NULL) + if (CurrentMimeType(&typeName) == NULL) return; BMimeType mimeType(typeName); @@ -2862,11 +2781,13 @@ TAttrView::AddMimeTypeAttrs(BMenu* menu) void -TAttrView::GetDefaultName(BString &result) const +FindPanel::GetDefaultAttrName(BString &result, int32 row) const { BMenuItem* item = NULL; - if (fMenuField->Menu() != NULL) - item = fMenuField->Menu()->FindMarked(); + BMenuField* menuField + = dynamic_cast<BMenuField*>(fAttrGrid->ItemAt(0, row)->View()); + if (menuField->Menu() != NULL) + item = menuField->Menu()->FindMarked(); if (item != NULL) result << item->Label(); else @@ -2882,7 +2803,9 @@ TAttrView::GetDefaultName(BString &result) const else result << " = "; - result << fTextControl->Text(); + BTextControl* textControl + = dynamic_cast<BTextControl*>(fAttrGrid->ItemAt(2, row)->View()); + result << textControl->Text(); } diff --git a/src/kits/tracker/FindPanel.h b/src/kits/tracker/FindPanel.h index 5bed25d..3a4c94d 100644 --- a/src/kits/tracker/FindPanel.h +++ b/src/kits/tracker/FindPanel.h @@ -54,6 +54,7 @@ class BCheckBox; class BMenuField; class BFile; class BPopUpMenu; +class BGridLayout; namespace BPrivate { @@ -173,11 +174,12 @@ class FindWindow : public BWindow { class FindPanel : public BView { public: - FindPanel(BRect, BFile*, FindWindow* parent, bool fromTemplate, + FindPanel(BFile*, FindWindow* parent, bool fromTemplate, bool editTemplateOnly); virtual ~FindPanel(); virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); virtual void MessageReceived(BMessage*); void BuildAttrQuery(BQuery*, bool &dynamicDate) const; @@ -192,10 +194,6 @@ class FindPanel : public BView { uint32 Mode() const { return fMode; } - static BRect InitialViewSize(const BNode*); - // used when showing window, does not account for more options, - // those if used will force a resize later - static uint32 InitialMode(const BNode* entry); void SaveWindowState(BNode*, bool editTemplate); @@ -207,6 +205,7 @@ class FindPanel : public BView { // build up a simple query from the name we are searching for void GetDefaultName(BString &) const; + void GetDefaultAttrName(BString &, int32) const; const char* UserSpecifiedName() const; // name filled out in the query name text field @@ -216,11 +215,6 @@ class FindPanel : public BView { // queries private: - static float ViewHeightForMode(uint32 mode, bool moreOptions); - // accouts for moreOptions - // if in attributeView, only returns valid result if one attr only - static float BoxHeightForMode(uint32 mode, bool moreOptions); - void AddMimeTypesToMenu(); // populates the type menu static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void* castToMenu); @@ -229,9 +223,9 @@ class FindPanel : public BView { // populates the volume menu void ShowVolumeMenuLabel(); - void AddAttrView(); + void AddAttrRow(); // add one more attribute item to the attr view - void RemoveAttrView(); + void RemoveAttrRow(); // remove the last attribute item void AddFirstAttr(); @@ -239,20 +233,20 @@ class FindPanel : public BView { void RestoreWindowState(const BNode*); void RestoreMimeTypeMenuSelection(const BNode*); void AddByAttributeItems(const BNode*); - void ResizeAttributeBox(const BNode*); void RemoveByAttributeItems(); - void RemoveAttrViewItems(); + void RemoveAttrViewItems(bool removeGrid = true); void ShowOrHideMimeTypeMenu(); // MimeTypeWindow is only shown in kByNameItem and // kByAttributeItem modes + void AddAttributeControls(int32); + void ShowOrHideMoreOptions(bool show); // fMode gets set by this and the call relies on it being // up-to-date static int32 InitialAttrCount(const BNode*); void FillCurrentQueryName(BTextControl*, FindWindow*); void AddByNameOrFormulaItems(); - void AddOneAttributeItem(BBox* box, BRect); void SetUpAddRemoveButtons(BBox* box); void SwitchMode(uint32); @@ -262,14 +256,25 @@ class FindPanel : public BView { void SaveAsQueryOrTemplate(const entry_ref*, const char*, bool queryTemplate); + BView* FindAttrView(const char*, int row) const; + + void AddAttributes(BMenu* menu, const BMimeType &type); + void AddMimeTypeAttrs(BMenu* menu); + void RestoreAttrState(const BMessage &, int32); + void SaveAttrState(BMessage*, int32); + void AddLogicMenu(int32, bool selectAnd = true); + void RemoveLogicMenu(int32); + + void ResizeMenuField(BMenuField*); + uint32 fMode; - BObjectList<TAttrView> fAttrViewList; + BGridLayout* fAttrGrid; BPopUpMenu* fMimeTypeMenu; BMenuField* fMimeTypeField; BPopUpMenu* fVolMenu; BPopUpMenu* fSearchModeMenu; BPopUpMenu* fRecentQueries; - DialogPane* fMoreOptionsPane; + BBox* fMoreOptions; BTextControl* fQueryName; BString fInitialQueryName; @@ -284,38 +289,6 @@ class FindPanel : public BView { friend class RecentQueriesPopUp; }; -class TAttrView : public BView { - // a single attribute item - the search by attribute view - // can add several of these - public: - TAttrView(BRect frame, int32 index); - ~TAttrView(); - - virtual void AttachedToWindow(); - - void RestoreState(const BMessage &settings, int32 index); - void SaveState(BMessage* settings, int32 index); - - virtual void Draw(BRect updateRect); - virtual void MessageReceived(BMessage* message); - - void AddLogicMenu(bool selectAnd = true); - void RemoveLogicMenu(); - void AddMimeTypeAttrs(); - void MakeTextViewFocus(); - - void GetDefaultName(BString &result) const; - - private: - void AddAttributes(BMenu* menu, const BMimeType &type); - void AddMimeTypeAttrs(BMenu* menu); - - BMenuField* fMenuField; - BTextControl* fTextControl; - - typedef BView _inherited; -}; - class DeleteTransientQueriesTask { // transient queries get deleted if they didn't get used in a while; ############################################################################ Commit: 1b98948370a153b1c70d56aaad2cbe342da452bb URL: http://cgit.haiku-os.org/haiku/commit/?id=1b98948 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:12:13 2013 UTC Style fixes ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index f421f54..5ea1f6e 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -86,6 +86,7 @@ All rights reserved. #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "FindPanel" + const char* kAllMimeTypes = "mime/ALLTYPES"; const BRect kInitialRect(100, 100, 0, 0); @@ -140,6 +141,7 @@ class MostUsedNames { int32 fCount; }; + MostUsedNames gMostUsedMimeTypes("MostUsedMimeTypes", "Tracker"); @@ -171,8 +173,9 @@ MoreOptionsStruct::QueryTemporary(const BNode* node) if (ReadAttr(node, kAttrQueryMoreOptions, kAttrQueryMoreOptionsForeign, B_RAW_TYPE, 0, &saveMoreOptions, sizeof(MoreOptionsStruct), - &MoreOptionsStruct::EndianSwap) == kReadAttrFailed) + &MoreOptionsStruct::EndianSwap) == kReadAttrFailed) { return false; + } return saveMoreOptions.temporary; } @@ -190,7 +193,7 @@ FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly) fEditTemplateOnly(false), fSaveAsTemplatePanel(NULL) { - if (fFile) { + if (fFile != NULL) { fRef = *newRef; if (editIfTemplateOnly) { char type[B_MIME_TYPE_LENGTH]; @@ -283,13 +286,7 @@ FindWindow::SwitchToTemplate(const entry_ref* ref) BFile templateFile(&entry, O_RDONLY); ThrowOnInitCheckError(&templateFile); - //DisableUpdates(); - // turn off updates to reduce flicker while re-populating the - // window - // #9689 : couldn't get to work since changing to Layout API fBackground->SwitchToTemplate(&templateFile); - //EnableUpdates(); - } catch (...) { } } @@ -394,8 +391,7 @@ FindWindow::SaveQueryAttributes(BNode* file, bool queryTemplate) status_t FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, - bool queryTemplate, const BMessage* oldAttributes, - const BPoint* oldLocation) + bool queryTemplate, const BMessage* oldAttributes, const BPoint* oldLocation) { if (oldAttributes) // revive old window settings @@ -422,10 +418,10 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, // write some useful info to help locate the volume to query BMenuItem* item = fBackground->VolMenu()->FindMarked(); - if (item) { + if (item != NULL) { dev_t dev; BMessage message; - int32 count = 0; + uint32 count = 0; int32 itemCount = fBackground->VolMenu()->CountItems(); for (int32 index = 2; index < itemCount; index++) { @@ -442,7 +438,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, EmbedUniqueVolumeInfo(&message, &volume); } - if (count) { + if (count > 0) { // do we need to embed any volumes ssize_t size = message.FlattenedSize(); BString buffer; @@ -463,7 +459,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, // be reopened and edited later BView* focusedItem = CurrentFocus(); - if (focusedItem) { + if (focusedItem != NULL) { // text controls never get the focus, their internal text views do BView* parent = focusedItem->Parent(); if (dynamic_cast<BTextControl*>(parent)) @@ -482,6 +478,7 @@ FindWindow::SaveQueryAsAttributes(BNode* file, BEntry* entry, &selEnd, sizeof(selEnd)); } } + return B_OK; } @@ -505,10 +502,11 @@ FindWindow::Find() TTracker* tracker = dynamic_cast<TTracker*>(be_app); ASSERT(tracker); for (int32 timeOut = 0; ; timeOut++) { - if (!tracker->EntryHasWindowOpen(&fRef)) + if (!tracker->EntryHasWindowOpen(&fRef)) { // window quit, we can post refs received to open a // new copy break; + } // PRINT(("waiting for query window to quit, %d\n", timeOut)); if (timeOut == 5000) { @@ -631,8 +629,7 @@ FindWindow::MessageReceived(BMessage* message) fFile = TryOpening(&tmpRef); if (fFile) { fRef = tmpRef; - SaveQueryAsAttributes(fFile, &entry, queryTemplate, - 0, 0); + SaveQueryAsAttributes(fFile, &entry, queryTemplate, 0, 0); // try to save whatever state we aleady have // to the new query so that if the user // opens it before runing it from the find panel, @@ -643,15 +640,16 @@ FindWindow::MessageReceived(BMessage* message) break; case kSwitchToQueryTemplate: - { - entry_ref ref; - if (message->FindRef("refs", &ref) == B_OK) - SwitchToTemplate(&ref); - } + { + entry_ref ref; + if (message->FindRef("refs", &ref) == B_OK) + SwitchToTemplate(&ref); + break; + } case kRunSaveAsTemplatePanel: - if (fSaveAsTemplatePanel) + if (fSaveAsTemplatePanel != NULL) fSaveAsTemplatePanel->Show(); else { BMessenger panel(BackgroundView()); @@ -674,12 +672,13 @@ FindWindow::MessageReceived(BMessage* message) // #pragma mark - -FindPanel::FindPanel(BFile* node, FindWindow* parent, - bool , bool editTemplateOnly) - : BView("MainView", B_WILL_DRAW), - fMode(kByNameItem), - fAttrGrid(NULL), - fDraggableIcon(NULL) +FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, + bool editTemplateOnly) + : + BView("MainView", B_WILL_DRAW), + fMode(kByNameItem), + fAttrGrid(NULL), + fDraggableIcon(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -716,7 +715,7 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, searchModeField->SetDivider(0.0f); // add popup for volume list - fVolMenu = new BPopUpMenu("", false, false); // don't radioMode + fVolMenu = new BPopUpMenu("", false, false); BMenuField* volumeField = new BMenuField("", B_TRANSLATE("On"), fVolMenu); volumeField->SetDivider(volumeField->StringWidth(volumeField->Label()) + 8); AddVolumes(fVolMenu); @@ -738,8 +737,9 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, B_LARGE_ICON); fDraggableIcon = new DraggableQueryIcon(draggableRect, "saveHere", &dragNDropMessage, self, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - fDraggableIcon->SetExplicitMaxSize(BSize(draggableRect.right - draggableRect.left, - draggableRect.bottom - draggableRect.top)); + fDraggableIcon->SetExplicitMaxSize( + BSize(draggableRect.right - draggableRect.left, + draggableRect.bottom - draggableRect.top)); } fQueryName = new BTextControl("query name", B_TRANSLATE("Query name:"), @@ -766,7 +766,8 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, fLatch->SetLabels(B_TRANSLATE("Fewer options"), B_TRANSLATE("More options")); fLatch->SetValue(0); fLatch->SetMessage(new BMessage(kLatchChanged)); - fLatch->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); + fLatch->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, + B_ALIGN_VERTICAL_CENTER)); fMoreOptions->Hide(); // add Search button @@ -786,14 +787,16 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, icon->SetExplicitMaxSize(BSize(0, 0)); } - BView* mimeTypeFieldSpacer = new BBox("MimeTypeMenuSpacer", B_WILL_DRAW, B_NO_BORDER); + BView* mimeTypeFieldSpacer = new BBox("MimeTypeMenuSpacer", B_WILL_DRAW, + B_NO_BORDER); mimeTypeFieldSpacer->SetExplicitMaxSize(BSize(0, 0)); BBox* queryControls = new BBox("Box"); queryControls->SetBorder(B_NO_BORDER); BBox* queryBox = new BBox("Outer Controls"); - BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL, fRecentQueries); + BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL, + fRecentQueries); queryBox->SetLabel(recentQueriesMenuField); BGroupView* queryBoxView = new BGroupView(B_VERTICAL, 10.0); @@ -862,7 +865,7 @@ FindPanel::AttachedToWindow() // try to pick a good focus if we restore to one already BTextControl* textControl = dynamic_cast<BTextControl*>(FindView("TextControl")); - if (!textControl) { + if (textControl == NULL) { // pick the last text control in the attribute view BString title("TextEntry"); title << (fAttrGrid->CountRows() - 1); @@ -956,7 +959,7 @@ PopUpMenuSetTitle(BMenu* menu, const char* title) ASSERT(bar); ASSERT(bar->ItemAt(0)); - if (!bar || !bar->ItemAt(0)) + if (bar == NULL || !bar->ItemAt(0)) return; bar->ItemAt(0)->SetLabel(title); @@ -1012,11 +1015,11 @@ FindPanel::Draw(BRect) BMenuField* menuField = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); - if (!menuField) + if (menuField == NULL) return; BMenuItem* item = menuField->Menu()->FindMarked(); - if (!item) + if (item == NULL) return; if (item->Submenu()->FindMarked()) { @@ -1288,16 +1291,16 @@ FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const BTextControl* textControl = dynamic_cast<BTextControl*> (FindAttrView(title, index)); - if (!textControl) + if (textControl == NULL) return; BMenuField* menuField = dynamic_cast<BMenuField*>(FindAttrView("MenuField", index)); - if (!menuField) + if (menuField == NULL) return; BMenuItem* item = menuField->Menu()->FindMarked(); - if (!item) + if (item == NULL) continue; BMessage* message = item->Message(); @@ -1596,9 +1599,9 @@ FindPanel::CurrentMimeType(const char** type) const } } - if (type && item != NULL) { + if (type != NULL && item != NULL) { BMessage* message = item->Message(); - if (!message) + if (message == NULL) return NULL; if (message->FindString("mimetype", type) != B_OK) @@ -1631,7 +1634,7 @@ FindPanel::SetCurrentMimeType(BMenuItem* item) for (int32 i = 2; (search = MimeTypeMenu()->ItemAt(i)) != NULL; i++) { if (item == search || !search->Label()) continue; - if (!strcmp(item->Label(),search->Label())) { + if (strcmp(item->Label(),search->Label()) == 0) { search->SetMarked(true); break; } @@ -1639,7 +1642,7 @@ FindPanel::SetCurrentMimeType(BMenuItem* item) if (submenu) { for (int32 j = submenu->CountItems();j-- > 0;) { BMenuItem* sub = submenu->ItemAt(j); - if (!strcmp(item->Label(),sub->Label())) { + if (strcmp(item->Label(),sub->Label()) == 0) { sub->SetMarked(true); break; } @@ -1676,14 +1679,14 @@ FindPanel::SetCurrentMimeType(const char* label) for (int32 subIndex = submenu->CountItems(); subIndex-- > 0;) { BMenuItem* subItem = submenu->ItemAt(subIndex); if (subItem->Label() != NULL - && !strcmp(label, subItem->Label())) { + && strcmp(label, subItem->Label()) == 0) { subItem->SetMarked(true); found = true; } } } - if (item->Label() != NULL && !strcmp(label, item->Label())) { + if (item->Label() != NULL && strcmp(label, item->Label()) == 0) { item->SetMarked(true); return B_OK; } @@ -1885,7 +1888,6 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, while (roster.GetNextVolume(&volume) == B_OK) { if (volume.IsPersistent() && volume.KnowsQuery() && volume.KnowsAttr()) { - BQuery query; query.SetVolume(&volume); query.SetPredicate("_trk/recentQuery == 1"); @@ -1912,7 +1914,6 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, recentQueries.AddItem(new EntryWithDate(ref, changeTime)); } - } } } @@ -2052,7 +2053,7 @@ FindPanel::RemoveAttrRow() uint32 FindPanel::InitialMode(const BNode* node) { - if (!node || node->InitCheck() != B_OK) + if (node == NULL || node->InitCheck() != B_OK) return kByNameItem; uint32 result; @@ -2067,7 +2068,7 @@ FindPanel::InitialMode(const BNode* node) int32 FindPanel::InitialAttrCount(const BNode* node) { - if (!node || node->InitCheck() != B_OK) + if (node == NULL || node->InitCheck() != B_OK) return 1; int32 result; @@ -2184,8 +2185,10 @@ FindPanel::SwitchToTemplate(const BNode* node) void FindPanel::RestoreMimeTypeMenuSelection(const BNode* node) { - if (Mode() == (int32)kByFormulaItem || node == NULL || node->InitCheck() != B_OK) + if (Mode() == (int32)kByFormulaItem || node == NULL + || node->InitCheck() != B_OK) { return; + } BString buffer; if (node->ReadAttrString(kAttrQueryInitialMime, &buffer) == B_OK) @@ -2197,7 +2200,7 @@ void FindPanel::RestoreWindowState(const BNode* node) { fMode = InitialMode(node); - if (!node || node->InitCheck() != B_OK) + if (node == NULL || node->InitCheck() != B_OK) return; ShowOrHideMimeTypeMenu(); @@ -2207,7 +2210,7 @@ FindPanel::RestoreWindowState(const BNode* node) bool storesMoreOptions = ReadAttr(node, kAttrQueryMoreOptions, kAttrQueryMoreOptionsForeign, B_RAW_TYPE, 0, &saveMoreOptions, sizeof(saveMoreOptions), &MoreOptionsStruct::EndianSwap) - != kReadAttrFailed; + != kReadAttrFailed; if (storesMoreOptions) { // need to sanitize to true or false here, could have picked @@ -3108,7 +3111,7 @@ MostUsedNames::~MostUsedNames() bool MostUsedNames::ObtainList(BList* list) { - if (!list) + if (list == NULL) return false; if (!fLoaded) @@ -3163,9 +3166,8 @@ MostUsedNames::AddName(const char* name) if (entry == NULL) { for (int32 i = 0; - (entry = static_cast<list_entry*>(fList.ItemAt(i))) != NULL; - i++) { - if (!strcmp(entry->name, name)) + (entry = static_cast<list_entry*>(fList.ItemAt(i))) != NULL; i++) { + if (strcmp(entry->name, name) == 0) break; } } ############################################################################ Commit: a12df99d53ffeb033f00159ec12391119e20275e URL: http://cgit.haiku-os.org/haiku/commit/?id=a12df99 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:21:35 2013 UTC Use font relative spacing units ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 5ea1f6e..c1fd29b 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -799,16 +799,16 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, fRecentQueries); queryBox->SetLabel(recentQueriesMenuField); - BGroupView* queryBoxView = new BGroupView(B_VERTICAL, 10.0); - queryBoxView->GroupLayout()->SetInsets(10, 10, 10, 10); + BGroupView* queryBoxView = new BGroupView(B_VERTICAL, B_USE_DEFAULT_SPACING); + queryBoxView->GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING); queryBox->AddChild(queryBoxView); icon->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_BOTTOM)); button->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); - BLayoutBuilder::Group<>(queryBoxView, B_VERTICAL, 10.0) - .SetInsets(10, 10, 10, 10) - .AddGroup(B_HORIZONTAL, 1.0) + BLayoutBuilder::Group<>(queryBoxView, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_DEFAULT_SPACING) + .AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING) .Add(fMimeTypeField) .Add(mimeTypeFieldSpacer) .Add(searchModeField) @@ -817,10 +817,10 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, .End() .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(queryControls); - BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) - .SetInsets(10, 10, 10, 10) + BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_DEFAULT_SPACING) .Add(queryBox) - .AddGroup(B_HORIZONTAL, 10.0) + .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .Add(icon) .AddGroup(B_VERTICAL) .AddGroup(B_HORIZONTAL) ############################################################################ Commit: 8e8b861c83ab6beec20ea7323c6fa88185f2aa9e URL: http://cgit.haiku-os.org/haiku/commit/?id=8e8b861 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:25:34 2013 UTC Set the initial rect to 0 and center the window on screen ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index c1fd29b..c9db671 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -89,7 +89,7 @@ All rights reserved. const char* kAllMimeTypes = "mime/ALLTYPES"; -const BRect kInitialRect(100, 100, 0, 0); +const BRect kInitialRect(0, 0, 0, 0); const int32 kInitialAttrModeWindowHeight = 140; const int32 kIncrementPerAttribute = 30; const float kMoreOptionsDelta = 20; @@ -229,6 +229,7 @@ FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly) BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) .SetInsets(0, 0, 0, 0) .Add(fBackground); + CenterOnScreen(); } ############################################################################ Commit: 56fe9fad2311909291e9ddec035589e702c24d43 URL: http://cgit.haiku-os.org/haiku/commit/?id=56fe9fa Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:31:37 2013 UTC Refactor attaching FindPanel to FindWindow ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index c9db671..3b358a3 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -226,9 +226,8 @@ FindWindow::FindWindow(const entry_ref* newRef, bool editIfTemplateOnly) fBackground = new FindPanel(fFile, this, fFromTemplate, fEditTemplateOnly); - BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) - .SetInsets(0, 0, 0, 0) - .Add(fBackground); + SetLayout(new BGroupLayout(B_VERTICAL)); + GetLayout()->AddView(fBackground); CenterOnScreen(); } ############################################################################ Commit: c00d0642521eacb77038c0b1e1a35698eba4b710 URL: http://cgit.haiku-os.org/haiku/commit/?id=c00d064 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:38:56 2013 UTC Right align Add and Remove buttons ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 3b358a3..9da5090 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -1956,25 +1956,27 @@ void FindPanel::SetUpAddRemoveButtons(BBox* box) { BButton* removeButton = dynamic_cast<BButton*>(box->FindView("remove")); - if (removeButton == NULL) { - BButton* addButton = new BButton("add", B_TRANSLATE("Add"), - new BMessage(kAddItem)); - addButton->SetTarget(this); - - removeButton = new BButton("remove", B_TRANSLATE("Remove"), - new BMessage(kRemoveItem)); - removeButton->SetEnabled(false); - removeButton->SetTarget(this); - - BGroupLayout* layout = dynamic_cast<BGroupLayout*>(box->GetLayout()); - BLayoutBuilder::Group<>(layout) - .AddGroup(B_HORIZONTAL) - .Add(addButton) - .Add(removeButton) - .AddGlue(); + if (removeButton != NULL) { + removeButton->SetEnabled(fAttrGrid->CountRows() > 1); + return; } - // enable remove button as needed - removeButton->SetEnabled(fAttrGrid->CountRows() > 1); + + removeButton = new BButton("remove", B_TRANSLATE("Remove"), + new BMessage(kRemoveItem)); + removeButton->SetEnabled(false); + removeButton->SetTarget(this); + + BButton* addButton = new BButton("add", B_TRANSLATE("Add"), + new BMessage(kAddItem)); + addButton->SetTarget(this); + + BGroupLayout* layout = dynamic_cast<BGroupLayout*>(box->GetLayout()); + BLayoutBuilder::Group<>(layout) + .AddGroup(B_HORIZONTAL) + .AddGlue() + .Add(removeButton) + .Add(addButton) + .End(); } ############################################################################ Commit: c65c2a54bd08687e9046d812f0cab9d6038da65f URL: http://cgit.haiku-os.org/haiku/commit/?id=c65c2a5 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:40:07 2013 UTC Rename add and remove to add button and remove button ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 9da5090..69f629e 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -876,11 +876,11 @@ FindPanel::AttachedToWindow() textControl->MakeFocus(); } - BButton* button = dynamic_cast<BButton*>(FindView("remove")); + BButton* button = dynamic_cast<BButton*>(FindView("remove button")); if (button) button->SetTarget(this); - button = dynamic_cast<BButton*>(FindView("add")); + button = dynamic_cast<BButton*>(FindView("add button")); if (button) button->SetTarget(this); @@ -1955,18 +1955,18 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, void FindPanel::SetUpAddRemoveButtons(BBox* box) { - BButton* removeButton = dynamic_cast<BButton*>(box->FindView("remove")); + BButton* removeButton = dynamic_cast<BButton*>(box->FindView("remove button")); if (removeButton != NULL) { removeButton->SetEnabled(fAttrGrid->CountRows() > 1); return; } - removeButton = new BButton("remove", B_TRANSLATE("Remove"), + removeButton = new BButton("remove button", B_TRANSLATE("Remove"), new BMessage(kRemoveItem)); removeButton->SetEnabled(false); removeButton->SetTarget(this); - BButton* addButton = new BButton("add", B_TRANSLATE("Add"), + BButton* addButton = new BButton("add button", B_TRANSLATE("Add"), new BMessage(kAddItem)); addButton->SetTarget(this); @@ -2046,7 +2046,7 @@ FindPanel::RemoveAttrRow() if (fAttrGrid->CountRows() != 1) return; - BButton* button = dynamic_cast<BButton*>(FindView("remove")); + BButton* button = dynamic_cast<BButton*>(FindView("remove button")); if (button) button->SetEnabled(false); } @@ -2386,13 +2386,13 @@ void FindPanel::RemoveByAttributeItems() { RemoveAttrViewItems(); - BView* view = FindView("add"); + BView* view = FindView("add button"); if (view) { view->RemoveSelf(); delete view; } - view = FindView("remove"); + view = FindView("remove button"); if (view) { view->RemoveSelf(); delete view; ############################################################################ Commit: 16c46df9b1855e6efd194dc4a7685968af651be9 URL: http://cgit.haiku-os.org/haiku/commit/?id=16c46df Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:45:56 2013 UTC Remove dead code, de-indent comment ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 69f629e..3924905 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -1999,7 +1999,6 @@ FindPanel::AddAttrRow() BLayoutBuilder::Group<>(box, B_VERTICAL); grid = new BGridView("AttrFields"); - //box->SetBorder(B_FANCY_BORDER); box->AddChild(grid); } @@ -2007,7 +2006,7 @@ FindPanel::AddAttrRow() AddAttributeControls(fAttrGrid->CountRows()); - // add logic to previous attrview + // add logic to previous attrview if (fAttrGrid->CountRows() > 1) AddLogicMenu(fAttrGrid->CountRows() - 2); ############################################################################ Commit: 1db0bf0058d256e7ad9fbc661f4f5088188a750c URL: http://cgit.haiku-os.org/haiku/commit/?id=1db0bf0 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 26 23:46:30 2013 UTC Make the logic menu fields non-navigatable, tab order ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 3924905..fedd749 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -2629,7 +2629,7 @@ FindPanel::AddLogicMenu(int32 index, bool selectAnd) menu->SetTargetForItems(this); - BMenuField* menufield = new BMenuField("Logic", "", menu); + BMenuField* menufield = new BMenuField("Logic", "", menu, B_WILL_DRAW); menufield->SetDivider(0.0f); menufield->SetExplicitMaxSize(menufield->MinSize()); ############################################################################ Commit: e8a78127bd507beda7e50f2689fb24ed2e36598c URL: http://cgit.haiku-os.org/haiku/commit/?id=e8a7812 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 00:00:38 2013 UTC Sentence case Recent queries, clip count from 0 to 10 ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index fedd749..cb5fbeb 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -686,7 +686,7 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, uint32 initialMode = InitialMode(node); BMessenger self(this); - fRecentQueries = new BPopUpMenu(B_TRANSLATE("Recent Queries")); + fRecentQueries = new BPopUpMenu(B_TRANSLATE("Recent queries")); AddRecentQueries(fRecentQueries, true, &self, kSwitchToQueryTemplate); @@ -1929,11 +1929,13 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, templates.EachElement(AddOneRecentItem, ¶ms); int32 count = recentQueries.CountItems(); - // show only up to 10 recent queries - if (count > 10) + if (count > 10) { + // show only up to 10 recent queries count = 10; + } else if (count < 0) + count = 0; - if (templates.CountItems() && count) + if (templates.CountItems() > 0 && count > 0) menu->AddSeparatorItem(); for (int32 index = 0; index < count; index++) @@ -1941,7 +1943,7 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, if (addSaveAsItem) { // add a Save as template item - if (count || templates.CountItems()) + if (count > 0 || templates.CountItems() > 0) menu->AddSeparatorItem(); BMessage* message = new BMessage(kRunSaveAsTemplatePanel); ############################################################################ Commit: d3277fa8e74c51a612e123d5fe5b070d54f7a104 URL: http://cgit.haiku-os.org/haiku/commit/?id=d3277fa Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 21:54:04 2013 UTC Tweak the latch position ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/DialogPane.cpp b/src/kits/tracker/DialogPane.cpp index 8473c24..6d22296 100644 --- a/src/kits/tracker/DialogPane.cpp +++ b/src/kits/tracker/DialogPane.cpp @@ -498,7 +498,7 @@ void PaneSwitch::DrawInState(PaneSwitch::State state) { BRect rect(0, 0, 12, 12); - rect.OffsetBy(-1, -1); + rect.OffsetBy(1, 1); rgb_color arrowColor = state == kPressed ? kHighlightColor : kNormalColor; int32 arrowDirection = BControlLook::B_RIGHT_ARROW; ############################################################################ Commit: bedc69662e93edcf631b64f2321b189839a1cfbd URL: http://cgit.haiku-os.org/haiku/commit/?id=bedc696 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 22:11:54 2013 UTC Put checkboxes under query box in more options ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index cb5fbeb..8b3e299 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -751,14 +751,18 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, B_TRANSLATE("Temporary"), NULL); fTemporaryCheck->SetValue(B_CONTROL_ON); + BView* checkboxGroup = BLayoutBuilder::Group<>(B_HORIZONTAL) + .Add(fSearchTrashCheck) + .Add(fTemporaryCheck) + .View(); + // add the more options collapsible pane fMoreOptions = new BBox(B_NO_BORDER, BLayoutBuilder::Group<>() - .AddGroup(B_VERTICAL) - .Add(fQueryName) - .AddGroup(B_HORIZONTAL) - .Add(fSearchTrashCheck) - .Add(fTemporaryCheck) - .End() + .AddGrid(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) + .Add(fQueryName->CreateLabelLayoutItem(), 0, 0) + .Add(fQueryName->CreateTextViewLayoutItem(), 1, 0) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(0), 0, 1) + .Add(checkboxGroup, 1, 1) .End() .View()); ############################################################################ Commit: f7467fd1ffc5df5bcbf782e57a1f6168203f97bf URL: http://cgit.haiku-os.org/haiku/commit/?id=f7467fd Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 23:28:32 2013 UTC Set the PaneSwitch arrow rect based on the be_plain_font size ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/DialogPane.cpp b/src/kits/tracker/DialogPane.cpp index 6d22296..6f4575c 100644 --- a/src/kits/tracker/DialogPane.cpp +++ b/src/kits/tracker/DialogPane.cpp @@ -497,7 +497,7 @@ PaneSwitch::Track(BPoint point, uint32) void PaneSwitch::DrawInState(PaneSwitch::State state) { - BRect rect(0, 0, 12, 12); + BRect rect(0, 0, be_plain_font->Size(), be_plain_font->Size()); rect.OffsetBy(1, 1); rgb_color arrowColor = state == kPressed ? kHighlightColor : kNormalColor; ############################################################################ Commit: 0184cbec0a39b90025ef7a19515fa44f9b513b05 URL: http://cgit.haiku-os.org/haiku/commit/?id=0184cbe Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 23:30:52 2013 UTC Eliminate variable, set directly ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 8b3e299..ccdaf97 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -799,9 +799,7 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, queryControls->SetBorder(B_NO_BORDER); BBox* queryBox = new BBox("Outer Controls"); - BMenuField* recentQueriesMenuField = new BMenuField("RecentQueries", NULL, - fRecentQueries); - queryBox->SetLabel(recentQueriesMenuField); + queryBox->SetLabel(new BMenuField("RecentQueries", NULL, fRecentQueries)); BGroupView* queryBoxView = new BGroupView(B_VERTICAL, B_USE_DEFAULT_SPACING); queryBoxView->GroupLayout()->SetInsets(B_USE_DEFAULT_SPACING); ############################################################################ Commit: 35e34dda8af5d0186a72cd7f9e25537858f2322a URL: http://cgit.haiku-os.org/haiku/commit/?id=35e34dd Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 23:31:32 2013 UTC Use sentence case lowercasing the word "query" ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index ccdaf97..74e2789 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -1950,7 +1950,7 @@ FindPanel::AddRecentQueries(BMenu* menu, bool addSaveAsItem, BMessage* message = new BMessage(kRunSaveAsTemplatePanel); BMenuItem* item = new BMenuItem( - B_TRANSLATE("Save Query as template" B_UTF8_ELLIPSIS), message); + B_TRANSLATE("Save query as template" B_UTF8_ELLIPSIS), message); menu->AddItem(item); } } ############################################################################ Commit: 43f6509cd08637822c5333bb5418844bdc394e53 URL: http://cgit.haiku-os.org/haiku/commit/?id=43f6509 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sat Apr 27 23:32:26 2013 UTC Turn off radio mode and set label from marked for fRecentQueries ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 74e2789..62e73f1 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -686,9 +686,9 @@ FindPanel::FindPanel(BFile* node, FindWindow* parent, bool fromTemplate, uint32 initialMode = InitialMode(node); BMessenger self(this); - fRecentQueries = new BPopUpMenu(B_TRANSLATE("Recent queries")); - AddRecentQueries(fRecentQueries, true, &self, - kSwitchToQueryTemplate); + fRecentQueries = new BPopUpMenu(B_TRANSLATE("Recent queries"), false, + false); + AddRecentQueries(fRecentQueries, true, &self, kSwitchToQueryTemplate); // add popup for mime types fMimeTypeMenu = new BPopUpMenu("MimeTypeMenu"); ############################################################################ Revision: hrev45573 Commit: e94d7e41e8c0b8d16ec43276f9630551b6d06c95 URL: http://cgit.haiku-os.org/haiku/commit/?id=e94d7e4 Author: John Scipione <jscipione@xxxxxxxxx> Date: Sun Apr 28 00:26:46 2013 UTC Remove the And/Or menu field when you remove a row ---------------------------------------------------------------------------- diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp index 62e73f1..3dce126 100644 --- a/src/kits/tracker/FindPanel.cpp +++ b/src/kits/tracker/FindPanel.cpp @@ -2046,12 +2046,39 @@ FindPanel::RemoveAttrRow() if (view != NULL) view->MakeFocus(); - if (fAttrGrid->CountRows() != 1) + if (fAttrGrid->CountRows() > 1) { + // remove the And/Or menu field of the previous row + BLayoutItem* item = fAttrGrid->ItemAt(3, row - 1); + if (item == NULL) + return; + + view = item->View(); + if (view == NULL) + return; + + view->RemoveSelf(); + delete view; return; + } + + // only one row remains + // disable the remove button BButton* button = dynamic_cast<BButton*>(FindView("remove button")); - if (button) + if (button != NULL) button->SetEnabled(false); + + // remove the And/Or menu field + BLayoutItem* item = fAttrGrid->RemoveItem(3); + if (item == NULL) + return; + + view = item->View(); + if (view == NULL) + return; + + view->RemoveSelf(); + delete view; }