summaryrefslogtreecommitdiff
path: root/src/menu_text_layout.cc
blob: ad0eba7a96c770e4bd7f1f647ad15381fed9e021 (plain)
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
// menu_text_layout.cc
//
//   Copyright (C) 2005, 2007 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_text_layout.h"

#include "aptitude.h"
#include "ui.h"

#include <generic/util/slotarg.h>

#include <vscreen/config/keybindings.h>
#include <vscreen/transcode.h>

bool menu_text_layout::find_search_enabled()
{
  return true;
}

bool menu_text_layout::find_search()
{
  prompt_string(transcode(_("Search for: ")),
		last_search,
		arg(sigc::mem_fun(this, &menu_text_layout::do_find_search)),
		NULL,
		NULL,
		&search_history);

  return true;
}

void menu_text_layout::do_find_search(const std::wstring &s)
{
  last_search_forward = true;

  if(!s.empty())
    {
      last_search = s;
      search_for(s, true);
    }
  else if(!last_search.empty())
    search_for(last_search, true);
  else
    beep();
}

bool menu_text_layout::find_search_back_enabled()
{
  return true;
}

bool menu_text_layout::find_search_back()
{
  prompt_string(_("Search backwards for: "),
		transcode(last_search),
		arg(sigc::mem_fun(this, &menu_text_layout::do_find_search_back)),
		NULL,
		NULL,
		&search_history);

  return true;
}

void menu_text_layout::do_find_search_back(const std::wstring &s)
{
  last_search_forward = false;

  if(!s.empty())
    {
      last_search = s;
      search_for(s, false);
    }
  else if(!last_search.empty())
    search_for(last_search, false);
  else
    beep();
}

bool menu_text_layout::find_research_enabled()
{
  return !last_search.empty();
}

bool menu_text_layout::find_research()
{
  if(last_search.empty())
    beep();
  else
    search_for(last_search, last_search_forward);

  return true;
}


bool menu_text_layout::find_repeat_search_back_enabled()
{
  return !last_search.empty();
}

bool menu_text_layout::find_repeat_search_back()
{
  if(last_search.empty())
    beep();
  else
    search_for(last_search, !last_search_forward);

  return true;
}


bool menu_text_layout::handle_key(const key &k)
{
  if(global_bindings.key_matches(k, "Search"))
    find_search();
  else if(global_bindings.key_matches(k, "SearchBack"))
    find_search_back();
  else if(global_bindings.key_matches(k, "ReSearch"))
    find_research();
  else if(global_bindings.key_matches(k, "RepeatSearchBack"))
    find_repeat_search_back();
  else
    return vs_text_layout::handle_key(k);

  return true;
}