xref: /haiku/src/kits/tracker/FavoritesMenu.h (revision e85e399fd7b229b8bc92f28928a059876d7216d3)
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 #ifndef __FAVORITES_MENU__
35 #define __FAVORITES_MENU__
36 
37 
38 #include <vector>
39 
40 #include "NavMenu.h"
41 #include "ObjectList.h"
42 
43 
44 class BRefFilter;
45 
46 namespace BPrivate {
47 
48 class EntryListBase;
49 
50 #define kGoDirectory "Tracker/Go"
51 
52 
53 class FavoritesMenu : public BSlowMenu {
54 	// FavoritesMenu is used in the FilePanel -
55 	// displays recent files, recent folders and favorites items
56 	public:
57 		FavoritesMenu(const char* title, BMessage* openFolderMessage,
58 			BMessage* openFileMessage, const BMessenger &,
59 			bool isSavePanel, BRefFilter* filter = NULL);
60 		virtual ~FavoritesMenu();
61 
62 		void SetRefFilter(BRefFilter* filter);
63 
64 	private:
65 		// override the necessary SlowMenu hooks
66 		virtual bool StartBuildingItemList();
67 		virtual bool AddNextItem();
68 		virtual void DoneBuildingItemList();
69 		virtual void ClearMenuBuildingState();
70 
71 		bool ShouldShowModel(const Model* model);
72 
73 		BMessage* fOpenFolderMessage;
74 		BMessage* fOpenFileMessage;
75 		BMessenger fTarget;
76 
77 		enum State {
78 			kStart,
79 			kAddingFavorites,
80 			kAddingFiles,
81 			kAddingFolders,
82 			kDone
83 		};
84 
85 		State fState;
86 
87 		int32 fIndex;
88 		int32 fSectionItemCount;
89 		bool fAddedSeparatorForSection;
90 			// keeps track whether a separator will be needed before the
91 			// next inserted item
92 		BMessage fItems;
93 
94 		EntryListBase* fContainer;
95 		BObjectList<BMenuItem>* fItemList;
96 		int32 fInitialItemCount;
97 		std::vector<entry_ref> fUniqueRefCheck;
98 		bool fIsSavePanel;
99 		BRefFilter* fRefFilter;
100 
101 		typedef BSlowMenu _inherited;
102 };
103 
104 
105 enum recent_type {
106 	kRecentDocuments = 0,
107 	kRecentApplications = 1,
108 	kRecentFolders = 2
109 };
110 
111 
112 class RecentsMenu : public BNavMenu {
113 	public:
114 		RecentsMenu(const char* name, int32 which, uint32 what,
115 			BHandler* target);
116 
117 		void			DetachedFromWindow();
118 
119 		int32			RecentsCount();
120 
121 	private:
122 		virtual	bool	StartBuildingItemList();
123 		virtual	bool	AddNextItem();
124 				bool	AddRecents(int32 count);
125 		virtual	void	DoneBuildingItemList();
126 		virtual	void	ClearMenuBuildingState();
127 
128 	private:
129 		int32			fWhich;
130 		int32			fRecentsCount;
131 
132 		int32 			fItemIndex;
133 		BMessage		fRecentList;
134 };
135 
136 } // namespace BPrivate
137 
138 using namespace BPrivate;
139 
140 #endif
141