1/*
2 * Copyright 2009-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		John Scipione, jscipione@gmail.com
7 *
8 * Corresponds to:
9 *		headers/os/storage/FilePanel.h	hrev47402
10 *		src/kits/tracker/FilePanel.cpp	hrev47402
11 */
12
13
14/*!
15	\file FilePanel.h
16	\ingroup storage
17	\ingroup libtracker
18	\brief Provides the BFilePanel and BRefFilter classes and support enums.
19*/
20
21
22/*!
23	\enum file_panel_mode
24	\ingroup storage
25	\brief Whether the file panel is a save or open panel.
26
27	\since BeOS R3
28*/
29
30
31/*!
32	\var file_panel_mode B_OPEN_PANEL
33
34	Open panel
35
36	\since BeOS R3
37*/
38
39
40/*!
41	\var file_panel_mode B_SAVE_PANEL
42
43
44	\since BeOS R3
45	Save panel
46*/
47
48
49/*!
50	\enum file_panel_button
51	\ingroup storage
52	\brief List of buttons used by the file panel.
53
54	\since BeOS R3
55*/
56
57
58/*!
59	\var file_panel_button B_CANCEL_BUTTON
60
61	Cancel button
62
63	\since BeOS R3
64*/
65
66
67/*!
68	\var file_panel_button B_DEFAULT_BUTTON
69
70	Default button
71
72	\since BeOS R3
73*/
74
75
76/*!
77	\class BRefFilter
78	\ingroup storage
79	\ingroup libtracker
80	\brief Allows you to filter the items displayed in a file panel.
81
82	\since BeOS R3
83*/
84
85
86/*!
87	\fn virtual bool BRefFilter::Filter(const entry_ref* ref, BNode* node,
88		struct stat_beos* stat, const char* mimeType)
89	\brief Hook method that's called on each file in the target directory
90	       displayed by a file panel.
91
92	\param ref The file currently under consideration.
93	\param node The node currently under consideration.
94	\param stat The stat information of the file.
95	\param mimeType The MIME type of the file.
96
97	\returns Whether or not the entry is a valid candidate for an open/save
98	         dialog.
99
100	\see BFilePanel::SetRefFilter()
101
102	\since BeOS R3
103*/
104
105
106/*!
107	\class BFilePanel
108	\ingroup storage
109	\ingroup libtracker
110	\brief Displays a standard Open/Save dialog.
111
112	A save panel looks like this:
113
114	\image html BFilePanel_example.png
115
116	An open dialog looks similar but doesn't have a text box for the file name.
117
118	You generally construct a BFilePanel object in response to a user action
119	for example the user clicks on a "Open" or "Save"/"Save As" menu item.
120	Constructing an open or save panel is easy:
121
122\code
123	BFilePanel* openPanel = new BFilePanel(B_OPEN_PANEL);
124	BFilePanel* savePanel = new BFilePanel(B_SAVE_PANEL);
125\endcode
126
127	You can then call methods to indicate what directory to display, whether
128	or not multiple selections are allowed, whether or not the user is
129	allowed to open a directory, what target view to send send notifications,
130	and more. See the constructor for details.
131
132	You can modify the look of your BFilePanel object by calling the
133	SetButtonLabel() and SetSaveText() methods. If you want to change the look
134	even more radically you can get alter the panel's BWindow and BView
135	objects. You get the window by calling the Window() method. With a pointer
136	to the panel's BWindow object you can drill down to the various views
137	contained therein.
138
139	Once you have constructed and customized your BFilePanel object you should
140	call the Show() method to display the panel to the user.
141
142	When the user confirms or cancels a BMessage object is constructed and sent
143	to the target of the BFilePanel object. You can specify a different
144	target in the constructor or by calling the SetTarget() method.
145
146	<b>Open Notifications</b>
147
148	For open notifications the default target is \c be_app_messenger and is
149	caught by the RefsReceived() method The \c what field is set to
150	\c B_REFS_RECEIVED. You can set your own message by calling the
151	SetMessage() method; in this case the message will be sent to the target's
152	MessageReceived() method instead.
153
154	The \c refs field of the message contains an \c entry_ref structure
155	for each entry that the user has selected. The \c refs field is of
156	type \c B_REF_TYPE. If the selected entry is a symlink to a file you'll 
157	need to dereference the file yourself. You can do this more easily by
158	turning the \c ref into a BEntry passing \c true into the \c traverse
159	argument like this:
160
161\code
162	BEntry entry(ref, true);
163\endcode
164
165	<b>Save Notifications</b>
166
167	Save notifications are always sent to the target's MessageReceived()
168	method unlike open notifications. The \c what field of the message is
169	set to \c B_SAVE_REQUESTED. The \c directory field contain a single
170	\c entry_ref structure that points to the directory that the entry is
171	saved to. The text that the user typed in the save panel's text view
172	is put in the \c name field and is of type \c B_STRING_TYPE.
173
174	<b>Cancel Notifications</b>
175
176	Cancel notifications are sent when the panel is hidden whether by the
177	user clicking the cancel button, closing the dialog, or confirming the
178	action (assuming hide-when-done is turned on).
179
180	Cancel notifications can be caught by the MessageReceived() method of
181	the target. The \c what field is set to \c B_CANCEL. The \c old_what
182	field is set to the previous what value which is useful if you have
183	overridden the default message. The \c what field of the message you
184	sent is put in the \c old_what field.
185
186	The \c source field is a pointer of \c B_POINTER_TYPE to the closed
187	BFilePanel object. When the BFilePanel object is closed it is not
188	destroyed, it is hidden instead. You can then delete the BFilePanel
189	object or leave it be and simply call Show() to use the panel next time
190	you need it.
191
192	\since BeOS R3
193*/
194
195
196/*!
197	\fn BFilePanel::BFilePanel(file_panel_mode mode, BMessenger* target,
198		const entry_ref* ref, uint32 nodeFlavors, bool multipleSelection,
199		BMessage* message, BRefFilter* filter, bool modal, bool hideWhenDone)
200	\brief Creates and initializes a BFilePanel object.
201
202	The constructor has many parameters but they may generally be set after
203	the object has been constructed. The only parameters that must be set
204	during construction are the \a mode, \a nodeFlavors, \a multipleSelection,
205	and \a modal parameters. The rest may be set after the object has been
206	constructed by the SetTarget(), SetPanelDirectory(), SetMessage(),
207	SetRefFilter(), and SetHideWhenDone() methods.
208
209	\param mode Set to \c B_OPEN_PANEL for an open panal or \c B_SAVE_PANEL
210	       for a save panel. Default is \c B_OPEN_PANEL.
211	\param target The BMessenger object that sends messages to the BLooper
212	       or BHandler controlled by the file panel.
213	\param ref The directory to display, by default the current working
214	       directory.
215	\param nodeFlavors One or more option flags, this applies to open panels
216	       only.
217	       - \c B_FILE_NODE Can select files and symlinks to files.
218	       - \c B_DIRECTORY_NODE Can select directories and symlinks to
219	         directories.
220	       - \c B_SYMLINK_NODE Can select symlinks only.
221	\param multipleSelection Whether or not the user is allowed to select more
222	       than one item to open. Save panels should always set this to
223	       \c false.
224	\param message Message sent by the file panel on confirms or cancels.
225	\param filter Hook method to call.
226	\param modal Whether or not the panel is modal, defaults to \c false.
227	\param hideWhenDone Set to \c false to keep the panel even after the user
228	       confirms or cancels. The close button will hide the panel
229	       regardless.
230
231	\since BeOS R3
232*/
233
234
235/*!
236	\fn BFilePanel::~BFilePanel()
237	\brief Destroys the file panel object.
238
239	If file panel is currently being displayed it is closed. The BRefFilter
240	object references by this panel is not destroyed by this method.
241
242	\since BeOS R3
243*/
244
245
246/*!
247	\fn void BFilePanel::Show()
248	\brief Displays the file panel on screen.
249
250	\since BeOS R3
251*/
252
253
254/*!
255	\fn void BFilePanel::Hide()
256	\brief Hides the file panel.
257
258	\since BeOS R3
259*/
260
261
262/*!
263	\fn bool BFilePanel::IsShowing() const
264	\brief Determines whether or not the file panel is shown.
265
266	\returns \c true if visible, \c false if hidden.
267
268	\see Show()
269
270	\since BeOS R3
271*/
272
273
274/*!
275	\fn void BFilePanel::SendMessage(const BMessenger* messenger,
276		BMessage* message)
277	\brief Sends the \a message to the target BHandler \a messenger.
278
279	\param messenger The target BHandler to send the message to.
280	\param message The message to send.
281
282	\see BMessenger::SendMessage()
283
284	\since BeOS R3
285*/
286
287
288/*!
289	\fn file_panel_mode BFilePanel::PanelMode() const
290	\brief Gets the panel mode, either \c B_OPEN_PANEL or \c B_SAVE_PANEL.
291
292	\returns \c B_OPEN_PANEL if the panel is an open panel, or \c B_SAVE_PANEL
293	         if the panel is a save panel.
294
295	\since BeOS R3
296*/
297
298
299/*!
300	\fn BMessenger BFilePanel::Messenger() const
301	\brief Gets the panel's target messenger object.
302
303	\returns The BMessenger object that sends messages for this panel.
304
305	\since BeOS R3
306*/
307
308
309/*!
310	\fn void BFilePanel::SetTarget(BMessenger target)
311	\brief Sets the target messenger.
312
313	\param target the target BMessenger object to set.
314
315	\since BeOS R3
316*/
317
318
319/*!
320	\fn void BFilePanel::SetMessage(BMessage* message)
321	\brief Sets the target messenge.
322
323	\param message The BMessage object to send on confirm.
324
325	\since BeOS R3
326*/
327
328
329/*!
330	\fn void BFilePanel::Refresh()
331	\brief Refresh the directory or the panel causing the entries to be re-run
332	       through the BRefFilter::Filter() method.
333
334	\since BeOS R3
335*/
336
337
338/*!
339	\fn BRefFilter* BFilePanel::RefFilter() const
340	\brief Gets the BRefFilter object associated with the panel.
341
342	\returns The BRefFilter set to the panel.
343
344	\see BRefFilter::Filter()
345
346	\since BeOS R3
347*/
348
349
350/*!
351	\fn void BFilePanel::SetRefFilter(BRefFilter* filter)
352	\brief Sets the BRefFilter used by the panel to filter entries.
353
354	\param filter The BRefFilter object to set.
355
356	\see BRefFilter::Filter()
357
358	\since BeOS R3
359*/
360
361
362/*!
363	\fn void BFilePanel::SetButtonLabel(file_panel_button button,
364		const char* text)
365	\brief Set the button label specified by \a button to \a text.
366
367	\param button The button to set the label of.
368	\param text The text to set the button label to.
369
370	\since BeOS R3
371*/
372
373
374/*!
375	\fn void BFilePanel::GetPanelDirectory(entry_ref* ref) const
376	\brief Gets the entry ref of the panel and sets \a ref to point to it.
377
378	\param ref The \c entry_ref pointer you want set.
379
380	\since BeOS R3
381*/
382
383
384/*!
385	\fn void BFilePanel::SetSaveText(const char* text)
386	\brief Set some save text to display in the save dialog.
387
388	\param text The text to display.
389
390	\since BeOS R3
391*/
392
393
394/*!
395	\fn void BFilePanel::SetPanelDirectory(const entry_ref* ref)
396	\brief Sets the entry ref of the panel to the directory contained
397	       by \a ref.
398
399	\param ref The entry contained by the desired panel directory.
400
401	\since BeOS R3
402*/
403
404
405/*!
406	\fn void BFilePanel::SetPanelDirectory(const char* path)
407	\brief Sets the entry ref of the panel to the directory referenced
408	       by \a path.
409
410	\param path The path of the desired directory.
411
412	\since BeOS R3
413*/
414
415
416/*!
417	\fn void BFilePanel::SetPanelDirectory(const BEntry* entry)
418	\brief Sets the entry ref of the panel to the directory referenced
419	       by \a entry.
420
421	\param entry The BEntry object pointing to the desired directory.
422
423	\since BeOS R3
424*/
425
426
427/*!
428	\fn void BFilePanel::SetPanelDirectory(const BDirectory* dir)
429	\brief Sets the entry ref of the panel to the directory referenced
430	       by \a dir.
431
432	\param dir The BDirectory object pointing to the desired directory.
433
434	\since BeOS R3
435*/
436
437
438/*!
439	\fn BWindow* BFilePanel::Window() const
440	\brief Gets a pointer to the BWindow object used by the file panel.
441
442	\returns A pointer to the BWindow object used by the file panel.
443
444	\since BeOS R3
445*/
446
447
448/*!
449	\fn void BFilePanel::Rewind()
450	\brief Sets the entry ref back to the top of the list.
451
452	\see SelectionChanged()
453
454	\since BeOS R3
455*/
456
457
458/*!
459	\fn status_t BFilePanel::GetNextSelectedRef(entry_ref* ref)
460	\brief Sets the \a ref pointer to the next entry in the directory.
461
462	\returns a status message.
463	\retval B_OK Everything went fine.
464	\retval B_ERROR Couldn't attain a lock on the window.
465	\retval B_ENTRY_NOT_FOUND End of the entry list.
466
467	\see Rewind()
468	\see SelectionChanged()
469
470	\since BeOS R3
471*/
472
473
474/*!
475	\fn void BFilePanel::SetHideWhenDone(bool on)
476	\brief Sets whether or not the panel should hide on confirm or cancel.
477
478	\param on \c true to hide, \c false to not hide when done.
479
480	\since BeOS R3
481*/
482
483
484/*!
485	\fn bool BFilePanel::HidesWhenDone(void) const
486	\brief Gets whether or not the panel should hide on confirm or cancel.
487
488	Panel always hides if the user clicks the window's close button.
489
490	\returns \c true if panel will hide, \c false if panel will not hide.
491
492	\see SetHideWhenDone()
493
494	\since BeOS R3
495*/
496
497
498/*!
499	\name Hook Methods
500*/
501
502
503//! @{
504
505
506/*!
507	\fn void BFilePanel::WasHidden()
508	\brief Hook method that gets called when the file panel is hidden due to
509	       a user action.
510
511	WasHidden() is not called if you call Hide() manually.
512
513	\since BeOS R3
514*/
515
516
517/*!
518	\fn void BFilePanel::SelectionChanged()
519	\brief Hook method that gets called when the entry ref references by the
520	       file panel changes.
521
522	\see GetNextSelectedRef()
523	\see Rewind()
524
525	\since BeOS R3
526*/
527
528
529//! @}
530