~ubuntu-branches/ubuntu/maverick/newsbeuter/maverick

« back to all changes in this revision

Viewing changes to src/help_formaction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2009-04-21 14:06:18 UTC
  • mfrom: (4.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090421140618-osnjk19bgkebyg9h
Tags: 2.0-1
* New upstream release.
  - Remove dependeny on mrss and nxml and add libxml2, newsbeuter
    now comes with its own parser.
  - Remove debian/patches and quilt dependency.
* Bump to policy 3.8.1, no changes needed.
* debian/copyright: adjust years.
* Remove dh_clean -k call as it is deprecated -> dh_prep.
* Change newsbeuter homepage, it now has an official one.
* Fix watch file url, new upstream code location.
* Add bookmark-scuttle.sh to installed contrib files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include <view.h>
6
6
#include <listformatter.h>
7
7
#include <utils.h>
 
8
#include <keymap.h>
 
9
#include <cstring>
8
10
 
9
11
namespace newsbeuter {
10
12
 
52
54
                std::vector<keymap_desc> descs;
53
55
                v->get_keys()->get_keymap_descriptions(descs, v->get_keys()->get_flag_from_context(context));
54
56
 
 
57
                std::string highlighted_searchphrase = utils::strprintf("<hl>%s</>", searchphrase.c_str());
 
58
                std::vector<std::string> colors = utils::tokenize(v->get_cfg()->get_configvalue("search-highlight-colors"), " ");
 
59
                f->set("highlight", make_colorstring(colors));
55
60
                listformatter listfmt;
56
 
                
57
 
                for (std::vector<keymap_desc>::iterator it=descs.begin();it!=descs.end();++it) {
58
 
                        if (context.length() > 0 && it->ctx != context)
59
 
                                continue;
60
 
                        if (!apply_search || strcasestr(it->key.c_str(), searchphrase.c_str())!=NULL || 
61
 
                                        strcasestr(it->cmd.c_str(), searchphrase.c_str())!=NULL ||
62
 
                                        strcasestr(it->desc.c_str(), searchphrase.c_str())!=NULL) {
63
 
                                unsigned int how_often = 3 - (it->cmd.length() / 8);
64
 
                                char tabs[] = "\t\t\t";
65
 
                                tabs[how_often] = '\0';
66
 
                                listfmt.add_line(utils::strprintf("%s\t%s%s%s", it->key.c_str(), it->cmd.c_str(), tabs, it->desc.c_str()));
 
61
 
 
62
                unsigned int unbound_count = 0;
 
63
                unsigned int syskey_count = 0;
 
64
 
 
65
                for (unsigned int i=0;i<3;i++) {
 
66
                        for (std::vector<keymap_desc>::iterator it=descs.begin();it!=descs.end();++it) {
 
67
                                bool condition;
 
68
                                switch (i) {
 
69
                                        case 0: 
 
70
                                                condition = (it->key.length() == 0 || it->flags & KM_SYSKEYS); 
 
71
                                                if (it->key.length() == 0)
 
72
                                                        unbound_count++;
 
73
                                                if (it->flags & KM_SYSKEYS)
 
74
                                                        syskey_count++;
 
75
                                                break;
 
76
                                        case 1: 
 
77
                                                condition = !(it->flags & KM_SYSKEYS); 
 
78
                                                break;
 
79
                                        case 2: 
 
80
                                                condition = (it->key.length() > 0 || it->flags & KM_SYSKEYS); 
 
81
                                                break;
 
82
                                        default: condition = true; break;
 
83
                                }
 
84
                                if (context.length() > 0 && (it->ctx != context || condition))
 
85
                                        continue;
 
86
                                if (!apply_search || strcasestr(it->key.c_str(), searchphrase.c_str())!=NULL || 
 
87
                                                strcasestr(it->cmd.c_str(), searchphrase.c_str())!=NULL ||
 
88
                                                strcasestr(it->desc.c_str(), searchphrase.c_str())!=NULL) {
 
89
                                        char tabs_1[] = "                ";
 
90
                                        char tabs_2[] = "                        ";
 
91
                                        unsigned int how_often_1 = strlen(tabs_1) - it->key.length();
 
92
                                        unsigned int how_often_2 = strlen(tabs_2) - it->cmd.length();
 
93
                                        tabs_1[how_often_1] = '\0';
 
94
                                        tabs_2[how_often_2] = '\0';
 
95
                                        std::string line;
 
96
                                        switch (i) {
 
97
                                                case 0:
 
98
                                                case 1: line = utils::strprintf("%s%s%s%s%s", it->key.c_str(), tabs_1, it->cmd.c_str(), tabs_2, it->desc.c_str()); break;
 
99
                                                case 2: line = utils::strprintf("%s%s%s%s", it->cmd.c_str(), tabs_1, tabs_2, it->desc.c_str()); break;
 
100
                                        }
 
101
                                        LOG(LOG_DEBUG, "help_formaction::prepare: step 1 - line = %s", line.c_str());
 
102
                                        line = utils::quote_for_stfl(line);
 
103
                                        LOG(LOG_DEBUG, "help_formaction::prepare: step 2 - line = %s", line.c_str());
 
104
                                        if (apply_search && searchphrase.length() > 0) {
 
105
                                                line = utils::replace_all(line, searchphrase, highlighted_searchphrase);
 
106
                                                LOG(LOG_DEBUG, "help_formaction::prepare: step 3 - line = %s", line.c_str());
 
107
                                        }
 
108
                                        listfmt.add_line(line);
 
109
                                }
 
110
                        }
 
111
                        switch (i) {
 
112
                                case 0:
 
113
                                        if (syskey_count > 0) {
 
114
                                                listfmt.add_line("");
 
115
                                                listfmt.add_line(_("Generic bindings:"));
 
116
                                                listfmt.add_line("");
 
117
                                        }
 
118
                                        break;
 
119
                                case 1:
 
120
                                        if (unbound_count > 0) {
 
121
                                                listfmt.add_line("");
 
122
                                                listfmt.add_line(_("Unbound functions:"));
 
123
                                                listfmt.add_line("");
 
124
                                        }
 
125
                                break;
67
126
                        }
68
127
                }
69
128
 
89
148
}
90
149
 
91
150
void help_formaction::finished_qna(operation op) {
92
 
        searchphrase = qna_responses[0];
93
 
        apply_search = true;
94
 
        do_redraw = true;
 
151
        switch (op) {
 
152
        case OP_INT_START_SEARCH:
 
153
                searchphrase = qna_responses[0];
 
154
                apply_search = true;
 
155
                do_redraw = true;
 
156
                break;
 
157
        default:
 
158
                break;
 
159
        }
95
160
}
96
161
 
97
162
void help_formaction::set_context(const std::string& ctx) {
101
166
        }
102
167
}
103
168
 
 
169
std::string help_formaction::title() {
 
170
        return _("Help");
 
171
}
 
172
 
 
173
std::string help_formaction::make_colorstring(const std::vector<std::string>& colors) {
 
174
        std::string result;
 
175
        if (colors.size() > 0) {
 
176
                if (colors[0] != "default") {
 
177
                        result.append("fg=");
 
178
                        result.append(colors[0]);
 
179
                }
 
180
                if (colors.size() > 1) {
 
181
                        if (colors[1] != "default") {
 
182
                                if (result.length() > 0)
 
183
                                        result.append(",");
 
184
                                result.append("bg=");
 
185
                                result.append(colors[1]);
 
186
                        }
 
187
                }
 
188
                for (unsigned int i=2;i<colors.size();i++) {
 
189
                        if (result.length() > 0)
 
190
                                result.append(",");
 
191
                        result.append("attr=");
 
192
                        result.append(colors[i]);
 
193
                }
 
194
        }
 
195
        return result;
 
196
}
 
197
 
104
198
}