Debian Codegraph @

src/tools/dlgedit/gui_recent_files.h

raw
1 /*
2 Copyright (C) 2011 Kai Sterker <[email protected]>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file common/gui_recent_files.h
21 *
22 * @author Kai Sterker
23 * @brief Keeps a list of recent files.
24 */
25
26 #ifndef GUI_RECENT_FILES_H
27 #define GUI_RECENT_FILES_H
28
29 #include <string>
30 #include <gtk/gtk.h>
31
32 /**
33 * Interface for anyone interested in recent file actions.
34 */
35 class GuiRecentFileListener
36 {
37 public:
38 virtual void OnRecentFileActivated (const std::string & file) = 0;
39 };
40
41 /**
42 * Keeps a list of recently opened file for the application.
43 * Also adds the file to the desktop-wide recent file list
44 * and allows to launch the program with that file.
45 */
46 class GuiRecentFiles
47 {
48 public:
49 /**
50 * Create a recent files list for the given application
51 * @param cmd the executable
52 * @param args the required command line arguments
53 */
54 GuiRecentFiles (const std::string & cmd, const std::string & args);
55
56 /**
57 * Destructor.
58 */
59 virtual ~GuiRecentFiles();
60
61 /**
62 * Register the given file with given mimetype as a recently opened file.
63 * @param file the absolute pathname to the file.
64 * @param type the files mimetype.
65 */
66 void registerFile (const std::string & file, const std::string & type);
67
68 /**
69 * Register a listener to get notified when a recent file
70 * has been selected.
71 * @param listener the new listener to set
72 */
73 void setListener (GuiRecentFileListener *listener)
74 {
75 Listener = listener;
76 }
77
78 /**
79 * Get the listener that wants to be notified when a recent
80 * file has been selected.
81 * @return the current listener
82 */
83 GuiRecentFileListener *getListener () const
84 {
85 return Listener;
86 }
87
88 /**
89 * Return a menu with the list of recent files.
90 */
91 GtkWidget *recentFileMenu () const
92 {
93 return Menu;
94 }
95
96 private:
97 /// the application to launch
98 std::string Command;
99 /// the command line arguments
100 std::string Arguments;
101 /// the recent files manager
102 GtkRecentManager* Manager;
103 /// the menu displaying recently used files
104 GtkWidget *Menu;
105 /// listener to notify when a recent file was selected
106 GuiRecentFileListener *Listener;
107 };
108
109 #endif /* GUI_RECENT_FILES_H_ */