1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
// menu_tree.cc
//
// Copyright (C) 2005, 2007-2008 Daniel Burrows
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
#include "menu_tree.h"
#include "aptitude.h"
#include "pkg_item.h"
#include "pkg_tree.h" // For pkg_tree::bindings(?!?!)
#include "pkg_ver_item.h"
#include "solution_item.h"
#include "ui.h"
#include "view_changelog.h"
#include <generic/apt/apt.h>
#include <generic/apt/apt_undo_group.h>
#include <generic/apt/config_signal.h>
#include <generic/apt/matching/match.h>
#include <generic/apt/matching/parse.h>
#include <generic/apt/matching/pattern.h>
#include <generic/util/undo.h>
#include <sigc++/adaptors/bind.h>
namespace cw = cwidget;
namespace cwidget
{
using namespace widgets;
}
namespace matching = aptitude::matching;
using cwidget::util::ref_ptr;
cw::editline::history_list menu_tree::search_history;
class pattern_search:public cw::tree_search_func
{
ref_ptr<matching::pattern> pattern;
ref_ptr<matching::search_cache> cache;
public:
pattern_search(const ref_ptr<matching::pattern> &_pattern,
const ref_ptr<matching::search_cache> &_cache)
: pattern(_pattern),
cache(matching::search_cache::create())
{
}
bool operator()(const cw::treeitem &item)
{
// EWW
const pkg_item *pitem=dynamic_cast<const pkg_item *>(&item);
if(pitem)
return matching::get_match(pattern,
pitem->get_package(),
cache,
*apt_cache_file,
*apt_package_records).valid();
else {
const pkg_ver_item *pvitem=dynamic_cast<const pkg_ver_item *>(&item);
if(pvitem)
return matching::get_match(pattern,
pvitem->get_package(),
pvitem->get_version(),
cache,
*apt_cache_file,
*apt_package_records).valid();
else
return false;
}
}
};
menu_tree::menu_tree()
:last_search_pattern(), doing_incsearch(false),
pre_incsearch_selected(get_end())
{
aptcfg->connect(PACKAGE "::UI::Incremental-Search",
sigc::mem_fun(*this, &menu_tree::do_cancel_incsearch));
}
menu_tree::~menu_tree()
{
}
bool menu_tree::proxy_redirect(bool (menu_redirect::*call)())
{
if(!get_visible())
return false;
cw::treeiterator curr = get_selection();
if(curr == get_end())
return false;
menu_redirect *proxied = dynamic_cast<menu_redirect *>(&*curr);
if(proxied == NULL)
return false;
return (proxied->*call)();
}
bool menu_tree::package_enabled()
{
return proxy_redirect(&menu_redirect::package_enabled);
}
bool menu_tree::package_install()
{
return proxy_redirect(&menu_redirect::package_install);
}
bool menu_tree::package_remove()
{
return proxy_redirect(&menu_redirect::package_remove);
}
bool menu_tree::package_purge()
{
return proxy_redirect(&menu_redirect::package_purge);
}
bool menu_tree::package_keep()
{
return proxy_redirect(&menu_redirect::package_keep);
}
bool menu_tree::package_hold()
{
return proxy_redirect(&menu_redirect::package_hold);
}
bool menu_tree::package_mark_auto()
{
return proxy_redirect(&menu_redirect::package_mark_auto);
}
bool menu_tree::package_unmark_auto()
{
return proxy_redirect(&menu_redirect::package_unmark_auto);
}
bool menu_tree::package_forbid_enabled()
{
return proxy_redirect(&menu_redirect::package_forbid_enabled);
}
bool menu_tree::package_forbid()
{
return proxy_redirect(&menu_redirect::package_forbid);
}
bool menu_tree::package_changelog_enabled()
{
return proxy_redirect(&menu_redirect::package_changelog_enabled);
}
bool menu_tree::package_changelog()
{
return proxy_redirect(&menu_redirect::package_changelog);
}
bool menu_tree::package_information_enabled()
{
return proxy_redirect(&menu_redirect::package_information_enabled);
}
bool menu_tree::package_information()
{
return proxy_redirect(&menu_redirect::package_information);
}
bool menu_tree::resolver_toggle_rejected()
{
return proxy_redirect(&menu_redirect::resolver_toggle_rejected);
}
bool menu_tree::resolver_toggle_rejected_enabled()
{
return proxy_redirect(&menu_redirect::resolver_toggle_rejected_enabled);
}
bool menu_tree::resolver_toggle_approved()
{
return proxy_redirect(&menu_redirect::resolver_toggle_approved);
}
bool menu_tree::resolver_toggle_approved_enabled()
{
return proxy_redirect(&menu_redirect::resolver_toggle_approved_enabled);
}
bool menu_tree::resolver_view_target()
{
return proxy_redirect(&menu_redirect::resolver_view_target);
}
bool menu_tree::resolver_view_target_enabled()
{
return proxy_redirect(&menu_redirect::resolver_view_target_enabled);
}
bool menu_tree::find_search_enabled()
{
return get_visible();
}
bool menu_tree::find_search()
{
prompt_string(W_("Search for: "),
last_search_term,
cw::util::arg(sigc::bind(sigc::mem_fun(*this, &menu_tree::do_search), false)),
cw::util::arg(sigc::mem_fun(*this, &menu_tree::do_cancel_incsearch)),
cw::util::arg(sigc::bind(sigc::mem_fun(*this, &menu_tree::do_incsearch), false)),
&search_history);
return true;
}
bool menu_tree::find_search_back_enabled()
{
return get_visible();
}
bool menu_tree::find_search_back()
{
prompt_string(W_("Search backwards for: "),
last_search_term,
cw::util::arg(sigc::bind(sigc::mem_fun(*this, &menu_tree::do_search), true)),
cw::util::arg(sigc::mem_fun(*this, &menu_tree::do_cancel_incsearch)),
cw::util::arg(sigc::bind(sigc::mem_fun(*this, &menu_tree::do_incsearch), true)),
&search_history);
return true;
}
bool menu_tree::find_research_enabled()
{
return last_search_pattern.valid();
}
bool menu_tree::find_research()
{
if(last_search_pattern.valid())
{
pattern_search searcher(last_search_pattern,
matching::search_cache::create());
if(last_search_backwards)
search_back_for(searcher);
else
search_for(searcher);
return true;
}
else
{
beep();
return true;
}
}
bool menu_tree::find_repeat_search_back_enabled()
{
return last_search_pattern.valid();
}
bool menu_tree::find_repeat_search_back()
{
if(last_search_pattern.valid())
{
pattern_search searcher(last_search_pattern,
matching::search_cache::create());
if(!last_search_backwards)
search_back_for(searcher);
else
search_for(searcher);
return true;
}
else
{
beep();
return true;
}
}
bool menu_tree::find_limit_enabled()
{
return false;
}
bool menu_tree::find_limit()
{
return false;
}
bool menu_tree::find_reset_limit_enabled()
{
return false;
}
bool menu_tree::find_reset_limit()
{
return false;
}
bool menu_tree::find_broken_enabled()
{
return get_visible();
}
bool menu_tree::find_broken()
{
if(!get_visible())
return false;
do_search(L"~b", false);
return true;
}
void menu_tree::do_search(std::wstring s, bool backward)
{
if(s.size()!=0)
{
last_search_term=s;
last_search_pattern = matching::parse(cw::util::transcode(s));
}
if(doing_incsearch)
doing_incsearch=false;
else
{
if(last_search_term.size() != 0 && last_search_pattern.valid())
{
last_search_backwards = backward;
pattern_search searcher(last_search_pattern,
matching::search_cache::create());
if(backward)
search_back_for(searcher);
else
search_for(searcher);
}
else
beep();
}
}
void menu_tree::do_incsearch(std::wstring s, bool backward)
{
if(!aptcfg->FindB(PACKAGE "::UI::Incremental-Search", true))
return;
if(!doing_incsearch)
{
doing_incsearch=true;
pre_incsearch_selected=get_selection();
}
ref_ptr<matching::pattern> p = matching::parse(cw::util::transcode(s), false, true);
set_selection(pre_incsearch_selected);
if(p.valid())
{
pattern_search searcher(p,
matching::search_cache::create());
last_search_backwards = backward;
if(backward)
search_back_for(searcher);
else
search_for(searcher);
}
}
void menu_tree::do_cancel_incsearch()
{
if(doing_incsearch)
{
set_selection(pre_incsearch_selected);
doing_incsearch=false;
}
}
void menu_tree::reset_incsearch()
{
doing_incsearch=false;
pre_incsearch_selected=get_end();
}
bool menu_tree::handle_key(const cw::config::key &k)
{
// ick -- but having our own bindings is also ugly. hm.
if(pkg_tree::bindings->key_matches(k, "Search"))
find_search();
else if(pkg_tree::bindings->key_matches(k, "SearchBack"))
find_search_back();
else if(pkg_tree::bindings->key_matches(k, "ReSearch"))
find_research();
else if(pkg_tree::bindings->key_matches(k, "RepeatSearchBack"))
find_repeat_search_back();
else if(pkg_tree::bindings->key_matches(k, "SearchBroken"))
find_broken();
else
return cw::tree::handle_key(k);
return true;
}
|