This repository has been archived by the owner on Oct 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
formaction.h
95 lines (61 loc) · 2.52 KB
/
formaction.h
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
#ifndef NEWSBEUTER_FORMACTION__H
#define NEWSBEUTER_FORMACTION__H
#include <stflpp.h>
#include <keymap.h>
#include <rss.h>
#include <history.h>
#include <vector>
#include <string>
namespace newsbeuter {
class view;
struct keymap_hint_entry {
operation op;
char * text;
};
typedef std::pair<std::string,std::string> qna_pair;
class formaction {
public:
formaction(view *, std::string formstr);
virtual ~formaction();
virtual void prepare() = 0;
virtual void init() = 0;
std::tr1::shared_ptr<stfl::form> get_form();
virtual void set_redraw(bool b) { do_redraw = b; }
virtual keymap_hint_entry * get_keymap_hint() = 0;
virtual std::string id() const = 0;
virtual std::string get_value(const std::string& value);
virtual void handle_cmdline(const std::string& cmd);
void process_op(operation op, bool automatic = false, std::vector<std::string> * args = NULL);
virtual void finished_qna(operation op);
void start_cmdline();
virtual void recalculate_form();
inline std::string get_qna_response(unsigned int i) { return (qna_responses.size() >= (i + 1)) ? qna_responses[i] : ""; }
void start_qna(const std::vector<qna_pair>& prompts, operation finish_op, history * h = NULL);
inline void set_parent_formaction(std::tr1::shared_ptr<formaction> fa) { parent_formaction = fa; }
inline std::tr1::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);
protected:
virtual void process_operation(operation op, bool automatic = false, std::vector<std::string> * args = NULL) = 0;
virtual void set_keymap_hints();
void start_bookmark_qna(const std::string& default_title, const std::string& default_url, const std::string& default_desc);
view * v;
std::tr1::shared_ptr<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:
std::string prepare_keymap_hint(keymap_hint_entry * hints);
void start_next_question();
std::string make_title(const std::string& url);
std::vector<qna_pair> qna_prompts;
operation finish_operation;
history * qna_history;
std::tr1::shared_ptr<formaction> parent_formaction;
};
}
#endif