From <jim_l@xxxxxxxxxxxx>:
jim_l@xxxxxxxxxxxx has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/5357 ;)
Change subject: Tracker: Restore search criteria when edit query * Have
FindPanel::AttachedToWindow check to see if a MIME type is already selected,
before it sets MIME type to the default value. * All changes outside the above
function are style clean-up. * Fixes #14946.
......................................................................
Tracker: Restore search criteria when edit query
* Have FindPanel::AttachedToWindow check to see if a MIME type is already
selected, before it sets MIME type to the default value.
* All changes outside the above function are style clean-up.
* Fixes #14946.
Change-Id: Iab3b9058bbc3ef1f055475ed54a72d4032643632
---
M src/kits/tracker/FindPanel.cpp
M src/kits/tracker/FindPanel.h
2 files changed, 217 insertions(+), 216 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/57/5357/1
diff --git a/src/kits/tracker/FindPanel.cpp b/src/kits/tracker/FindPanel.cpp
index a82003f..31f80bd 100644
--- a/src/kits/tracker/FindPanel.cpp
+++ b/src/kits/tracker/FindPanel.cpp
@@ -135,21 +135,21 @@
namespace BPrivate {
class MostUsedNames {
- public:
- MostUsedNames(const char* fileName, const char* directory,
- int32 maxCount = 5);
- ~MostUsedNames();
+public:
+
MostUsedNames(const char* fileName, const char* directory,
+ int32
maxCount = 5);
+
~MostUsedNames();
- bool ObtainList(BList* list);
- void ReleaseList();
+ bool ObtainList(BList* list);
+ void ReleaseList();
- void AddName(const char*);
+ void AddName(const char*);
- protected:
- struct list_entry {
- char* name;
- int32 count;
- };
+protected:
+ struct list_entry {
+ char* name;
+ int32 count;
+ };
static int CompareNames(const void* a, const void* b);
void LoadList();
@@ -935,9 +935,12 @@
}
fMimeTypeMenu->SetTargetForItems(this);
- BMenuItem* firstItem = fMimeTypeMenu->ItemAt(0);
- if (firstItem != NULL)
- firstItem->SetMarked(true);
+ // set the MIME type to the default value, if no value is already
selected
+ if (fMimeTypeMenu->FindMarked() == NULL) {
+ BMenuItem* firstItem = fMimeTypeMenu->ItemAt(0);
+ if (firstItem != NULL)
+ firstItem->SetMarked(true);
+ }
if (fDraggableIcon != NULL)
fDraggableIcon->SetTarget(BMessenger(this));
@@ -995,6 +998,7 @@
menuField->SetExplicitSize(size);
}
+
static void
PopUpMenuSetTitle(BMenu* menu, const char* title)
{
@@ -1339,8 +1343,9 @@
return NULL;
}
+
void
-FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const
+FindPanel::BuildAttrQuery(BQuery* query, bool& dynamicDate) const
{
dynamicDate = false;
@@ -1508,7 +1513,7 @@
void
-FindPanel::GetByAttrPredicate(BQuery* query, bool &dynamicDate) const
+FindPanel::GetByAttrPredicate(BQuery* query, bool& dynamicDate) const
{
ASSERT(Mode() == (int32)kByAttributeItem);
BuildAttrQuery(query, dynamicDate);
@@ -1957,12 +1962,14 @@
-1 : (entry1->second == entry2->second ? 0 : 1);
}
+
struct AddOneRecentParams {
BMenu* menu;
const BMessenger* target;
uint32 what;
};
+
static const entry_ref*
AddOneRecentItem(const entry_ref* ref, void* castToParams)
{
@@ -2692,7 +2699,7 @@
void
-FindPanel::RestoreAttrState(const BMessage &message, int32 index)
+FindPanel::RestoreAttrState(const BMessage& message, int32 index)
{
BMenuField* menuField
= dynamic_cast<BMenuField*>(FindAttrView("MenuField", index));
@@ -2840,7 +2847,7 @@
void
-FindPanel::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;
@@ -3137,20 +3144,17 @@
class DeleteTransientQueriesFunctor : public FunctionObjectWithResult<bool> {
public:
- DeleteTransientQueriesFunctor(DeleteTransientQueriesTask* task)
- : task(task)
- {}
+
DeleteTransientQueriesFunctor(DeleteTransientQueriesTask* task)
+ :
+
task(task)
+ {}
- virtual ~DeleteTransientQueriesFunctor()
- {
- delete task;
- }
+ virtual
~DeleteTransientQueriesFunctor() { delete task; }
- virtual void operator()()
- { result = task->DoSomeWork(); }
+ virtual void operator()() { result =
task->DoSomeWork(); }
private:
- DeleteTransientQueriesTask* task;
+ DeleteTransientQueriesTask* task;
};
diff --git a/src/kits/tracker/FindPanel.h b/src/kits/tracker/FindPanel.h
index d7da0d5..76cc018 100644
--- a/src/kits/tracker/FindPanel.h
+++ b/src/kits/tracker/FindPanel.h
@@ -77,100 +77,98 @@
BMenu* TrackerBuildRecentFindItemsMenu(const char* title);
struct MoreOptionsStruct {
- bool showMoreOptions;
- // Some options used to be in a collapsable part of the window,
but
- // this was removed. Now the options are always visible.
- bool searchTrash;
- int32 reserved1;
- bool temporary;
- bool reserved9;
- bool reserved10;
- bool reserved11;
- int32 reserved3;
- int32 reserved4;
- int32 reserved5;
- int32 reserved6;
- int32 reserved7;
- int32 reserved8;
- // reserve a bunch of fields so that we can add stuff later but not
- // make old queries incompatible. Reserved fields are set to 0 when
- // saved
+ // Some options used to be in a collapsable part of the
window, but
+ // this was removed. Now the options are always visible.
+ bool showMoreOptions;
+ bool searchTrash;
+ // reserve a bunch of fields so that we can add stuff
later but not
+ // make old queries incompatible. Reserved fields are
set to 0 when
+ // saved
+ int32 reserved1;
+ bool temporary;
+ bool reserved9;
+ bool reserved10;
+ bool reserved11;
+ int32 reserved3;
+ int32 reserved4;
+ int32 reserved5;
+ int32 reserved6;
+ int32 reserved7;
+ int32 reserved8;
- MoreOptionsStruct()
- :
- showMoreOptions(true),
- searchTrash(false),
- reserved1(0),
- temporary(true),
- reserved9(false),
- reserved10(false),
- reserved11(false),
- reserved3(0),
- reserved4(0),
- reserved5(0),
- reserved6(0),
- reserved7(0),
- reserved8(0)
- {
- }
+
MoreOptionsStruct()
+ :
+
showMoreOptions(true),
+
searchTrash(false),
+
reserved1(0),
+
temporary(true),
+
reserved9(false),
+
reserved10(false),
+
reserved11(false),
+
reserved3(0),
+
reserved4(0),
+
reserved5(0),
+
reserved6(0),
+
reserved7(0),
+
reserved8(0)
+ {}
- static void EndianSwap(void* castToThis);
+ static void EndianSwap(void* castToThis);
- static void SetQueryTemporary(BNode*, bool on);
- static bool QueryTemporary(const BNode*);
+ static void SetQueryTemporary(BNode*, bool
on);
+ static bool QueryTemporary(const BNode*);
};
class FindWindow : public BWindow {
public:
- FindWindow(const entry_ref* ref = NULL,
- bool editIfTemplateOnly = false);
- virtual ~FindWindow();
+
FindWindow(const entry_ref* ref = NULL,
+ bool
editIfTemplateOnly = false);
+ virtual ~FindWindow();
- FindPanel* BackgroundView() const
- { return fBackground; }
+ FindPanel* BackgroundView() const
{ return fBackground; }
- BNode* QueryNode() const
- { return fFile; }
+ BNode* QueryNode() const {
return fFile; }
- const char* QueryName() const;
- // reads in the query name from either a saved name in a
template
- // or form a saved query name
+ // reads in the query name from either a saved name in a template
+ // or form a saved query name
+ const char* QueryName() const;
- static bool IsQueryTemplate(BNode* file);
+ static bool IsQueryTemplate(BNode* file);
protected:
- virtual void MessageReceived(BMessage* message);
+ virtual void MessageReceived(BMessage*
message);
private:
- static BFile* TryOpening(const entry_ref* ref);
- static void GetDefaultQuery(BEntry &entry);
- // when opening an empty panel, use the default query to set the
- // panel up
- void SaveQueryAttributes(BNode* file, bool templateQuery);
+ static BFile* TryOpening(const entry_ref*
ref);
+ // when opening an empty panel, use the default query to set the panel
up
+ static void GetDefaultQuery(BEntry& entry);
+ void
SaveQueryAttributes(BNode* file, bool templateQuery);
- void Find();
- // retrieve the results
- void Save();
- // save the contents of the find window into the query file
+ // retrieve the results
+ void Find();
+ // save the contents of the find window into the query
file
+ void Save();
- void SwitchToTemplate(const entry_ref*);
- bool FindSaveCommon(bool find);
+ void SwitchToTemplate(const
entry_ref*);
+ bool FindSaveCommon(bool
find);
- status_t SaveQueryAsAttributes(BNode*, BEntry*, bool queryTemplate,
- const BMessage* oldAttributes = 0, const BPoint* oldLocation =
0);
+ status_t
SaveQueryAsAttributes(BNode*, BEntry*, bool queryTemplate,
+ const
BMessage* oldAttributes = 0,
+ const
BPoint* oldLocation = 0);
- void GetDefaultName(BString &);
- void GetPredicateString(BString &, bool &dynamicDate);
- // dynamic date is a date such as 'today'
+ void
GetDefaultName(BString&);
+ // dynamic date is a date such as 'today'
+ void
GetPredicateString(BString&, bool& dynamicDate);
- BFile* fFile;
- entry_ref fRef;
- bool fFromTemplate;
- bool fEditTemplateOnly;
- FindPanel* fBackground;
- mutable BString fQueryNameFromTemplate;
- BFilePanel* fSaveAsTemplatePanel;
+private:
+ BFile* fFile;
+ entry_ref fRef;
+ bool fFromTemplate;
+ bool fEditTemplateOnly;
+ FindPanel* fBackground;
+ mutable BString fQueryNameFromTemplate;
+ BFilePanel* fSaveAsTemplatePanel;
typedef BWindow _inherited;
};
@@ -178,114 +176,111 @@
class FindPanel : public BView {
public:
- FindPanel(BFile*, FindWindow* parent, bool fromTemplate,
- bool editTemplateOnly);
- virtual ~FindPanel();
+
FindPanel(BFile*, FindWindow* parent, bool fromTemplate,
+ bool
editTemplateOnly);
+ virtual ~FindPanel();
- virtual void AttachedToWindow();
- virtual void Draw(BRect updateRect);
- virtual void MessageReceived(BMessage*);
+ virtual void AttachedToWindow();
+ virtual void Draw(BRect updateRect);
+ virtual void MessageReceived(BMessage*);
- void BuildAttrQuery(BQuery*, bool& dynamicDate) const;
- BPopUpMenu* MimeTypeMenu() const
- { return fMimeTypeMenu; }
- BMenuItem* CurrentMimeType(const char** type = NULL) const;
- status_t SetCurrentMimeType(BMenuItem* item);
- status_t SetCurrentMimeType(const char* label);
+ void BuildAttrQuery(BQuery*,
bool& dynamicDate) const;
+ BPopUpMenu* MimeTypeMenu() const { return
fMimeTypeMenu; }
+ BMenuItem* CurrentMimeType(const
char** type = NULL) const;
+ status_t
SetCurrentMimeType(BMenuItem* item);
+ status_t
SetCurrentMimeType(const char* label);
- BPopUpMenu* VolMenu() const
- { return fVolMenu; }
- uint32 Mode() const
- { return fMode; }
+ BPopUpMenu* VolMenu() const { return
fVolMenu; }
+ uint32 Mode() const { return
fMode; }
- static uint32 InitialMode(const BNode* entry);
- void SaveWindowState(BNode*, bool editTemplate);
+ static uint32 InitialMode(const BNode* entry);
+ void SaveWindowState(BNode*,
bool editTemplate);
- void SwitchToTemplate(const BNode*);
+ void SwitchToTemplate(const
BNode*);
- void GetByAttrPredicate(BQuery*, bool &dynamicDate) const;
- // build up a query from by-attribute items
- void GetByNamePredicate(BQuery*) const;
- // build up a simple query from the name we are searching for
+ // build up a query from by-attribute items
+ void
GetByAttrPredicate(BQuery*, bool& dynamicDate) const;
+ // build up a simple query from the name we are
searching for
+ void
GetByNamePredicate(BQuery*) const;
- void GetDefaultName(BString&) const;
- void GetDefaultAttrName(BString&, int32) const;
- const char* UserSpecifiedName() const;
- // name filled out in the query name text field
+ void
GetDefaultName(BString&) const;
+ void
GetDefaultAttrName(BString&, int32) const;
+ // name filled out in the query name text field
+ const char* UserSpecifiedName() const;
- static void AddRecentQueries(BMenu*, bool addSaveAsItem,
- const BMessenger* target, uint32 what);
- // populate the recent query menu with query templates and
recent
- // queries
+ // populate the recent query menu with query templates and recent
queries
+ static void AddRecentQueries(BMenu*, bool
addSaveAsItem,
+ const
BMessenger* target, uint32 what);
private:
- void AddMimeTypesToMenu();
- // populates the type menu
- static bool AddOneMimeTypeToMenu(const ShortMimeInfo*, void*
castToMenu);
+ // populates the type menu
+ void AddMimeTypesToMenu();
+ static bool AddOneMimeTypeToMenu(const
ShortMimeInfo*, void* castToMenu);
- void AddVolumes(BMenu*);
- // populates the volume menu
- void ShowVolumeMenuLabel();
+ // populates the volume menu
+ void AddVolumes(BMenu*);
- void AddAttrRow();
- // add one more attribute item to the attr view
- void RemoveAttrRow();
- // remove the last attribute item
- void AddFirstAttr();
+ void ShowVolumeMenuLabel();
- // panel building/restoring calls
- void RestoreWindowState(const BNode*);
- void RestoreMimeTypeMenuSelection(const BNode*);
- void AddByAttributeItems(const BNode*);
- void RemoveByAttributeItems();
- void RemoveAttrViewItems(bool removeGrid = true);
- void ShowOrHideMimeTypeMenu();
- // MimeTypeWindow is only shown in kByNameItem and
- // kByAttributeItem modes
+ // add one more attribute item to the attr view
+ void AddAttrRow();
+ // remove the last attribute item
+ void RemoveAttrRow();
+ void AddFirstAttr();
- void AddAttributeControls(int32);
+ // panel building/restoring calls
+ void
RestoreWindowState(const BNode*);
+ void
RestoreMimeTypeMenuSelection(const BNode*);
+ void
AddByAttributeItems(const BNode*);
+ void
RemoveByAttributeItems();
+ void
RemoveAttrViewItems(bool removeGrid = true);
+ // MimeTypeWindow is only shown in kByNameItem and
kByAttributeItem modes
+ void
ShowOrHideMimeTypeMenu();
- 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 SetUpAddRemoveButtons();
+ void
AddAttributeControls(int32);
- void SwitchMode(uint32);
- // go from search by name to search by attribute, etc.
+ // fMode gets set by this and the call relies on it
being up-to-date
+ void
ShowOrHideMoreOptions(bool show);
+ static int32 InitialAttrCount(const BNode*);
+ void
FillCurrentQueryName(BTextControl*, FindWindow*);
+ void
AddByNameOrFormulaItems();
+ void SetUpAddRemoveButtons();
- void PushMimeType(BQuery* query) const;
+ // go from search by name to search by attribute, etc.
+ void SwitchMode(uint32);
- void SaveAsQueryOrTemplate(const entry_ref*, const char*, bool
queryTemplate);
+ void PushMimeType(BQuery*
query) const;
- BView* FindAttrView(const char*, int row) const;
+ void
SaveAsQueryOrTemplate(const entry_ref*,
+ const
char*, bool queryTemplate);
- 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);
+ BView* FindAttrView(const
char*, int row) const;
- void ResizeMenuField(BMenuField*);
+ 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);
- uint32 fMode;
- BGridLayout* fAttrGrid;
- BPopUpMenu* fMimeTypeMenu;
- BMenuField* fMimeTypeField;
- BPopUpMenu* fVolMenu;
- BPopUpMenu* fSearchModeMenu;
- BPopUpMenu* fRecentQueries;
- BBox* fMoreOptions;
- BTextControl* fQueryName;
- BString fInitialQueryName;
+ void
ResizeMenuField(BMenuField*);
- BCheckBox* fTemporaryCheck;
- BCheckBox* fSearchTrashCheck;
+private:
+ uint32 fMode;
+ BGridLayout* fAttrGrid;
+ BPopUpMenu* fMimeTypeMenu;
+ BMenuField* fMimeTypeField;
+ BPopUpMenu* fVolMenu;
+ BPopUpMenu* fSearchModeMenu;
+ BPopUpMenu* fRecentQueries;
+ BBox* fMoreOptions;
+ BTextControl* fQueryName;
+ BString fInitialQueryName;
- DraggableIcon* fDraggableIcon;
+ BCheckBox* fTemporaryCheck;
+ BCheckBox* fSearchTrashCheck;
+
+ DraggableIcon* fDraggableIcon;
typedef BView _inherited;
@@ -293,67 +288,69 @@
};
+// transient queries get deleted if they didn't get used in a while;
+// this is the task that takes care of it
class DeleteTransientQueriesTask {
- // transient queries get deleted if they didn't get used in a while;
- // this is the task that takes care of it
public:
- static void StartUpTransientQueryCleaner();
+ virtual
~DeleteTransientQueriesTask();
- bool DoSomeWork();
- virtual ~DeleteTransientQueriesTask();
+ static void StartUpTransientQueryCleaner();
+
+ // returns true when done
+ bool DoSomeWork();
protected:
- DeleteTransientQueriesTask();
- // returns true when done
+
DeleteTransientQueriesTask();
- enum State {
- kInitial,
- kAllocatedWalker,
- kTraversing,
- kError
- };
+ void Initialize();
+ bool GetSome();
- State state;
+ bool ProcessOneRef(Model*);
- void Initialize();
- bool GetSome();
+protected:
+ enum State {
+ kInitial,
+ kAllocatedWalker,
+ kTraversing,
+ kError
+ };
- bool ProcessOneRef(Model*);
+protected:
+ State state;
private:
- BTrackerPrivate::TNodeWalker* fWalker;
+ BTrackerPrivate::TNodeWalker* fWalker;
};
class RecentFindItemsMenu : public BMenu {
public:
- RecentFindItemsMenu(const char* title, const BMessenger* target,
- uint32 what);
+
RecentFindItemsMenu(const char* title,
+ const
BMessenger* target, uint32 what);
protected:
- virtual void AttachedToWindow();
+ virtual void AttachedToWindow();
private:
- BMessenger fTarget;
- uint32 fWhat;
+ BMessenger fTarget;
+ uint32 fWhat;
};
+// query/query template drag&drop helper
class DraggableQueryIcon : public DraggableIcon {
- // query/query template drag&drop helper
public:
- DraggableQueryIcon(BRect frame, const char* name,
- const BMessage* message, BMessenger target,
- uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP,
- uint32 flags = B_WILL_DRAW);
+
DraggableQueryIcon(BRect frame, const char* name,
+ const
BMessage* message, BMessenger target,
+ uint32
resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP,
+ uint32
flags = B_WILL_DRAW);
protected:
- virtual bool DragStarted(BMessage*);
+ virtual bool DragStarted(BMessage*);
};
} // namespace BPrivate
using namespace BPrivate;
-
#endif // _FIND_PANEL_H
--
To view, visit https://review.haiku-os.org/c/haiku/+/5357
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Iab3b9058bbc3ef1f055475ed54a72d4032643632
Gerrit-Change-Number: 5357
Gerrit-PatchSet: 1
Gerrit-Owner: jim_l@xxxxxxxxxxxx
Gerrit-MessageType: newchange