tracker/FindPanel: style cleanup

* No functional change.

Change-Id: I8e5e941fe626a77134036e3828f23ab245d2f5c7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5358
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Jim906 2022-06-07 17:57:37 -04:00 committed by waddlesplash
parent 44d08ffc4a
commit c90d79f03a
2 changed files with 211 additions and 213 deletions

View File

@ -135,21 +135,21 @@ static const char* operatorLabels[] = {
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();
@ -995,6 +995,7 @@ FindPanel::ResizeMenuField(BMenuField* menuField)
menuField->SetExplicitSize(size);
}
static void
PopUpMenuSetTitle(BMenu* menu, const char* title)
{
@ -1339,8 +1340,9 @@ FindPanel::FindAttrView(const char* name, int row) const
return NULL;
}
void
FindPanel::BuildAttrQuery(BQuery* query, bool &dynamicDate) const
FindPanel::BuildAttrQuery(BQuery* query, bool& dynamicDate) const
{
dynamicDate = false;
@ -1508,7 +1510,7 @@ FindPanel::PushMimeType(BQuery* query) const
void
FindPanel::GetByAttrPredicate(BQuery* query, bool &dynamicDate) const
FindPanel::GetByAttrPredicate(BQuery* query, bool& dynamicDate) const
{
ASSERT(Mode() == (int32)kByAttributeItem);
BuildAttrQuery(query, dynamicDate);
@ -1957,12 +1959,14 @@ SortByDatePredicate(const EntryWithDate* entry1, const EntryWithDate* entry2)
-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 +2696,7 @@ FindPanel::AddAttributeControls(int32 gridRow)
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 +2844,7 @@ FindPanel::RemoveLogicMenu(int32 index)
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 +3141,17 @@ DeleteTransientQueriesTask::ProcessOneRef(Model* model)
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;
};

View File

@ -77,100 +77,98 @@ _IMPEXP_TRACKER
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 @@ private:
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 @@ private:
};
// 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