xref: /haiku/src/kits/tracker/FavoritesMenu.h (revision fccd8899fcb583bfb73c5c26c9fcd714b963959b)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #ifndef __FAVORITES_MENU__
36 #define __FAVORITES_MENU__
37 
38 #include <vector>
39 
40 #include "NavMenu.h"
41 #include "ObjectList.h"
42 
43 class BRefFilter;
44 
45 namespace BPrivate {
46 
47 class EntryListBase;
48 
49 #define kGoDirectory "Tracker/Go"
50 
51 class FavoritesMenu : public BSlowMenu {
52 	// FavoritesMenu is used in the FilePanel -
53 	// displays recent files, recent folders and favorites items
54 	public:
55 		FavoritesMenu(const char *title, BMessage *openFolderMessage,
56 			BMessage *openFileMessage, const BMessenger &,
57 			bool isSavePanel, BRefFilter *filter = NULL);
58 		virtual ~FavoritesMenu();
59 
60 		void SetRefFilter(BRefFilter *filter);
61 
62 	private:
63 		// override the necessary SlowMenu hooks
64 		virtual bool StartBuildingItemList();
65 		virtual bool AddNextItem();
66 		virtual void DoneBuildingItemList();
67 		virtual void ClearMenuBuildingState();
68 
69 		bool ShouldShowModel(const Model *model);
70 
71 		BMessage *fOpenFolderMessage;
72 		BMessage *fOpenFileMessage;
73 		BMessenger fTarget;
74 
75 		enum State {
76 			kStart,
77 			kAddingFavorites,
78 			kAddingFiles,
79 			kAddingFolders,
80 			kDone
81 		};
82 
83 		State fState;
84 
85 		int32 fIndex;
86 		int32 fSectionItemCount;
87 		bool fAddedSeparatorForSection;
88 			// keeps track whether a separator will be needed before the
89 			// next inserted item
90 		BMessage fItems;
91 
92 		EntryListBase *fContainer;
93 		BObjectList<BMenuItem> *fItemList;
94 		int32 fInitialItemCount;
95 		std::vector<entry_ref> fUniqueRefCheck;
96 		bool fIsSavePanel;
97 		BRefFilter *fRefFilter;
98 
99 		typedef BSlowMenu _inherited;
100 };
101 
102 
103 enum recent_type {
104 	kRecentDocuments = 0,
105 	kRecentApplications = 1,
106 	kRecentFolders = 2
107 };
108 
109 class RecentsMenu : public BNavMenu {
110 	public:
111 		RecentsMenu(const char *name,int32 which,uint32 what,BHandler *target);
112 
113 		void			DetachedFromWindow();
114 
115 		int32			RecentsCount();
116 
117 	private:
118 		virtual	bool	StartBuildingItemList();
119 		virtual	bool	AddNextItem();
120 				bool	AddRecents(int32 count);
121 		virtual	void	DoneBuildingItemList();
122 		virtual	void	ClearMenuBuildingState();
123 
124 	private:
125 		int32			fWhich;
126 		int32			fRecentsCount;
127 
128 		int32 			fItemIndex;
129 		BMessage		fRecentList;
130 };
131 
132 } // namespace BPrivate
133 
134 using namespace BPrivate;
135 
136 #endif
137