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
|
#ifndef NEWSBOAT_FORMACTION_H_
#define NEWSBOAT_FORMACTION_H_
#include <memory>
#include <string>
#include <vector>
#include "history.h"
#include "keymap.h"
#include "listwidget.h"
#include "stflpp.h"
namespace newsboat {
class ConfigContainer;
class RssFeed;
class View;
typedef std::pair<std::string, std::string> QnaPair;
enum class CommandType {
QUIT,
SAVE,
GOTO,
TAG,
SET,
SOURCE,
DUMPCONFIG,
EXEC,
UNKNOWN, /// Unknown/non-existing command. Tokenized input is stored in Command.args
INVALID, /// differs from UNKNOWN in that no input was parsed
};
struct Command {
CommandType type;
std::vector<std::string> args;
};
class FormAction {
public:
FormAction(View*, std::string formstr, ConfigContainer* cfg);
virtual ~FormAction();
virtual void prepare() = 0;
virtual void init() = 0;
virtual void set_redraw(bool b)
{
do_redraw = b;
}
virtual const std::vector<KeyMapHintEntry>& get_keymap_hint() const = 0;
virtual std::string id() const = 0;
std::string get_value(const std::string& name);
void set_value(const std::string& name, const std::string& value);
void draw_form();
std::string draw_form_wait_for_event(unsigned int timeout);
void recalculate_widget_dimensions();
virtual void handle_cmdline(const std::string& cmd);
bool process_op(Operation op,
bool automatic = false,
std::vector<std::string>* args = nullptr);
virtual void finished_qna(Operation op);
void start_cmdline(std::string default_value = "");
void start_qna(const std::vector<QnaPair>& prompts,
Operation finish_op,
History* h = nullptr);
void finish_qna_question();
void cancel_qna();
void qna_next_history();
void qna_previous_history();
void set_parent_formaction(std::shared_ptr<FormAction> fa)
{
parent_formaction = fa;
}
std::shared_ptr<FormAction> get_parent_formaction() const
{
return parent_formaction;
}
virtual std::string title() = 0;
virtual std::vector<std::string> get_suggestions(
const std::string& fragment);
static void load_histories(const std::string& searchfile,
const std::string& cmdlinefile);
static void save_histories(const std::string& searchfile,
const std::string& cmdlinefile,
unsigned int limit);
std::string bookmark(const std::string& url,
const std::string& title,
const std::string& description,
const std::string& feed_title);
protected:
virtual bool process_operation(Operation op,
bool automatic = false,
std::vector<std::string>* args = nullptr) = 0;
virtual void set_keymap_hints();
/// The name of the "main" STFL widget, i.e. the one that should be focused
/// by default.
virtual std::string main_widget() const = 0;
void start_bookmark_qna(const std::string& default_title,
const std::string& default_url,
const std::string& default_feed_title);
static Command parse_command(const std::string& input,
std::string delimiters = " \r\n\t");
void handle_parsed_command(const Command& command);
bool handle_list_operations(ListWidget& list, Operation op);
View* v;
ConfigContainer* cfg;
Stfl::Form f;
bool do_redraw;
std::vector<std::string> qna_responses;
static History searchhistory;
static History cmdlinehistory;
std::vector<std::string> valid_cmds;
private:
void start_next_question();
bool handle_single_argument_set(std::string argument);
void handle_set(const std::vector<std::string>& args);
void handle_quit();
void handle_source(const std::vector<std::string>& args);
void handle_dumpconfig(const std::vector<std::string>& args);
void handle_exec(const std::vector<std::string>& args);
std::vector<QnaPair> qna_prompts;
Operation finish_operation;
History* qna_history;
std::shared_ptr<FormAction> parent_formaction;
};
} // namespace newsboat
#endif /* NEWSBOAT_FORMACTION_H_ */
|