Debian Codegraph @

FavoritesWindow.cxx

raw symbols SCIP
1 //
2 // "$Id: FavoritesWindow.cxx 386 2006-03-04 14:15:27Z mike $"
3 //
4 // FavoritesWindows widget code.
5 //
6 // Copyright 2005 by Michael Sweet.
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License v2 as published
10 // by the Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // Contents:
18 //
19 //
20
21 #include "FavoritesWindow.h"
22
23
24 //
25 // 'FavoritesWindow::FavoritesWindow()' - Create a favorites management window.
26 //
27
28 FavoritesWindow::FavoritesWindow()
29 : Fl_Double_Window(355, 150, "Manage Favorites"),
30 browser_(10, 10, 300, 95),
31 up_(320, 10, 25, 25, "@8>"),
32 delete_(320, 45, 25, 25, "X"),
33 down_(320, 80, 25, 25, "@2>"),
34 ok_(185, 115, 75, 25, "OK"),
35 cancel_(270, 115, 75, 25, "Cancel")
36 {
37 end();
38
39 modal();
40
41 browser_.type(FL_HOLD_BROWSER);
42 browser_.when(FL_WHEN_RELEASE_ALWAYS);
43 browser_.callback((Fl_Callback *)browser_cb, this);
44
45 up_.callback((Fl_Callback *)up_cb, this);
46
47 delete_.callback((Fl_Callback *)delete_cb, this);
48
49 down_.callback((Fl_Callback *)down_cb, this);
50
51 ok_.callback((Fl_Callback *)ok_cb, this);
52
53 cancel_.callback((Fl_Callback *)cancel_cb, this);
54 }
55
56
57 //
58 // 'FavoritesWindow::browser_cb()' - Handle clicks in the favorites list.
59 //
60
61 void
62 FavoritesWindow::browser_cb(Fl_File_Browser *b,
63 // I - Favorites browser
64 FavoritesWindow *fw)
65 // I - Favorites window
66 {
67 int i; // Current item
68
69
70 i = fw->browser_.value();
71 if (i)
72 {
73 if (i > 1)
74 fw->up_.activate();
75 else
76 fw->up_.deactivate();
77
78 fw->delete_.activate();
79
80 if (i < fw->browser_.size())
81 fw->down_.activate();
82 else
83 fw->down_.deactivate();
84 }
85 else
86 {
87 fw->up_.deactivate();
88 fw->delete_.deactivate();
89 fw->down_.deactivate();
90 }
91 }
92
93
94 //
95 // 'FavoritesWindow::cancel_cb()' - Cancel (close) the window.
96 //
97
98 void
99 FavoritesWindow::cancel_cb(Fl_Button *b,
100 // I - Cancel button
101 FavoritesWindow *fw)
102 // I - Favorites window
103 {
104 fw->hide();
105 }
106
107
108 //
109 // 'FavoritesWindow::delete_cb()' - Delete the current directory.
110 //
111
112 void
113 FavoritesWindow::delete_cb(Fl_Button *b,
114 // I - Delete button
115 FavoritesWindow *fw)
116 // I - Favorites window
117 {
118 int i; // Current item
119
120
121 i = fw->browser_.value();
122
123 fw->browser_.remove(i);
124
125 if (i > fw->browser_.size())
126 i --;
127 fw->browser_.select(i);
128
129 if (i < fw->browser_.size())
130 fw->down_.activate();
131 else
132 fw->down_.deactivate();
133
134 if (i > 1)
135 fw->up_.activate();
136 else
137 fw->up_.deactivate();
138
139 if (!i)
140 fw->delete_.deactivate();
141
142 fw->ok_.activate();
143 }
144
145
146 //
147 // 'FavoritesWindow::down_cb()' - Move the current directory down one line.
148 //
149
150 void
151 FavoritesWindow::down_cb(Fl_Button *b,
152 // I - Down button
153 FavoritesWindow *fw)
154 // I - Favorites window
155 {
156 int i; // Current item
157
158
159 i = fw->browser_.value();
160
161 fw->browser_.insert(i + 2, fw->browser_.text(i), fw->browser_.data(i));
162 fw->browser_.remove(i);
163 fw->browser_.select(i + 1);
164
165 if ((i + 1) == fw->browser_.size())
166 fw->down_.deactivate();
167
168 fw->up_.activate();
169
170 fw->ok_.activate();
171 }
172
173
174 //
175 // 'FavoritesWindow::load()' - Load the favorites list.
176 //
177
178 void
179 FavoritesWindow::load()
180 {
181 int i; // Looping var
182 char name[32], // Preference name
183 filename[1024]; // Directory in list
184 Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "filechooser");
185 // File chooser preferences
186
187
188 // Load the favorites list...
189 browser_.clear();
190 browser_.deselect();
191
192 for (i = 0; i < 100; i ++)
193 {
194 // Get favorite directory 0 to 99...
195 sprintf(name, "favorite%02d", i);
196
197 prefs.get(name, filename, "", sizeof(filename));
198
199 // Stop on the first empty favorite...
200 if (!filename[0])
201 break;
202
203 // Add the favorite to the list...
204 browser_.add(filename,
205 Fl_File_Icon::find(filename, Fl_File_Icon::DIRECTORY));
206 }
207
208 up_.deactivate();
209 delete_.deactivate();
210 down_.deactivate();
211 ok_.deactivate();
212 }
213
214
215 //
216 // 'FavoritesWindow::ok_cb()' - Save the favorites list and close.
217 //
218
219 void
220 FavoritesWindow::ok_cb(Fl_Return_Button *b,
221 // I - OK button
222 FavoritesWindow *fw)
223 // I - Favorites window
224 {
225 fw->save();
226 fw->hide();
227 }
228
229
230 //
231 // 'FavoritesWindow::save()' - Save the favorites list.
232 //
233
234 void
235 FavoritesWindow::save()
236 {
237 int i; // Looping var
238 char name[32], // Preference name
239 filename[1024]; // Directory in list
240 Fl_Preferences prefs(Fl_Preferences::USER, "fltk.org", "filechooser");
241 // File chooser preferences
242
243
244 // Copy the new list over...
245 for (i = 0; i < browser_.size(); i ++)
246 {
247 // Set favorite directory 0 to 99...
248 sprintf(name, "favorite%02d", i);
249
250 prefs.set(name, browser_.text(i + 1));
251 }
252
253 // Clear old entries as necessary...
254 for (; i < 100; i ++)
255 {
256 // Clear favorite directory 0 to 99...
257 sprintf(name, "favorite%02d", i);
258
259 prefs.get(name, filename, "", sizeof(filename));
260
261 if (filename[0])
262 prefs.set(name, "");
263 else
264 break;
265 }
266 }
267
268
269 //
270 // 'FavoritesWindow::show()' - Load the favorites list and show.
271 //
272
273 void
274 FavoritesWindow::show()
275 {
276 load();
277 Fl_Double_Window::show();
278 }
279
280
281 //
282 // 'FavoritesWindow::up_cb()' - Move the current directory up one line.
283 //
284
285 void
286 FavoritesWindow::up_cb(Fl_Button *b,
287 // I - Up button
288 FavoritesWindow *fw)
289 // I - Favorites window
290 {
291 int i; // Current item
292
293
294 i = fw->browser_.value();
295
296 fw->browser_.insert(i - 1, fw->browser_.text(i), fw->browser_.data(i));
297 fw->browser_.remove(i + 1);
298 fw->browser_.select(i - 1);
299
300 if (i == 2)
301 fw->up_.deactivate();
302
303 fw->down_.activate();
304
305 fw->ok_.activate();
306 }
307
308
309 //
310 // End of "$Id: FavoritesWindow.cxx 386 2006-03-04 14:15:27Z mike $".
311 //