]> git.lyx.org Git - lyx.git/blob - src/FuncRequest.cpp
Fix bug #5131: Remember last file active.
[lyx.git] / src / FuncRequest.cpp
1 /**
2  * \file FuncRequest.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FuncRequest.h"
14 #include "LyXAction.h"
15
16 #include <iostream>
17 #include <sstream>
18 #include <vector>
19
20 using namespace std;
21
22 namespace lyx {
23
24 FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
25 FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
26
27 FuncRequest::FuncRequest(Origin o)
28         : action(LFUN_NOACTION), origin(o), x(0), y(0),
29           button_(mouse_button::none)
30 {}
31
32
33 FuncRequest::FuncRequest(FuncCode act, Origin o)
34         : action(act), origin(o), x(0), y(0), button_(mouse_button::none)
35 {}
36
37
38 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
39         : action(act), argument_(arg), origin(o), x(0), y(0),
40           button_(mouse_button::none)
41 {}
42
43
44 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
45         : action(act), argument_(from_utf8(arg)), origin(o), x(0), y(0),
46           button_(mouse_button::none)
47 {}
48
49
50 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
51                          mouse_button::state but, Origin o)
52         : action(act), origin(o), x(ax), y(ay), button_(but)
53 {}
54
55
56 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
57         : action(cmd.action), argument_(arg), origin(o),
58           x(cmd.x), y(cmd.y), button_(cmd.button_)
59 {}
60
61
62 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg, Origin o)
63         : action(cmd.action), argument_(from_utf8(arg)), origin(o),
64           x(cmd.x), y(cmd.y), button_(cmd.button_)
65 {}
66
67
68 mouse_button::state FuncRequest::button() const
69 {
70         return button_;
71 }
72
73
74 void splitArg(vector<string> & args, string const & str)
75 {
76         istringstream is(str);
77         while (is) {
78                 char c;
79                 string s;
80                 is >> c;
81                 if (is) {
82                         if (c == '"')
83                                 getline(is, s, '"');
84                         else {
85                                 is.putback(c);
86                                 is >> s;
87                         }
88                         args.push_back(s);
89                 }
90         }
91 }
92
93
94 string FuncRequest::getArg(unsigned int i) const
95 {
96         vector<string> args;
97         splitArg(args, to_utf8(argument_));
98         return i < args.size() ? args[i] : string();
99 }
100
101
102 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
103 {
104         return lhs.action == rhs.action && lhs.argument() == rhs.argument();
105 }
106
107
108 ostream & operator<<(ostream & os, FuncRequest const & cmd)
109 {
110         return os
111                 << " action: " << cmd.action 
112                 << " [" << lyxaction.getActionName(cmd.action) << "] " 
113                 << " arg: '" << to_utf8(cmd.argument()) << "'"
114                 << " x: " << cmd.x
115                 << " y: " << cmd.y;
116 }
117
118
119 } // namespace lyx