2 * \file FuncRequest.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "FuncRequest.h"
14 #include "LyXAction.h"
16 #include "support/debug.h"
17 #include "support/lstrings.h"
25 using namespace lyx::support;
29 FuncRequest const FuncRequest::unknown(LFUN_UNKNOWN_ACTION);
30 FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
31 FuncRequest const FuncRequest::prefix(LFUN_COMMAND_PREFIX);
33 FuncRequest::FuncRequest(Origin o)
38 FuncRequest::FuncRequest(FuncCode act, Origin o)
39 : action_(act), origin_(o)
43 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
44 : action_(act), argument_(arg), origin_(o)
48 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
49 : FuncRequest(act, from_utf8(arg), o)
53 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
54 mouse_button::state button, KeyModifier modifier, Origin o)
55 : action_(act), origin_(o),
56 x_(ax), y_(ay), button_(button), modifier_(modifier)
60 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
61 : action_(cmd.action()), argument_(arg), origin_(o),
62 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
68 // Extracts arguments from str into args. Arguments are delimited by
69 // whitespace or by double quotes.
70 // We extract at most max + 1 arguments, treating args[max] as
72 void splitArg(vector<string> & args, string const & str,
73 unsigned int max = UINT_MAX)
75 istringstream is(str);
77 if (args.size() == max) {
80 args.push_back(trim(s));
89 // get quote delimited argument
92 // get whitespace delimited argument
103 string FuncRequest::getArg(unsigned int i) const
106 splitArg(args, to_utf8(argument_));
107 return i < args.size() ? args[i] : string();
111 string FuncRequest::getLongArg(unsigned int i) const
114 splitArg(args, to_utf8(argument_), i);
115 return i < args.size() ? args[i] : string();
119 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
121 return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
125 bool operator!=(FuncRequest const & lhs, FuncRequest const & rhs)
127 return !(lhs == rhs);
131 ostream & operator<<(ostream & os, FuncRequest const & cmd)
134 << " action: " << cmd.action()
135 << " [" << lyxaction.getActionName(cmd.action()) << "] "
136 << " arg: '" << to_utf8(cmd.argument()) << "'"
138 << " y: " << cmd.y();
142 LyXErr & operator<<(LyXErr &l, FuncRequest const &fr)
146 return l << oss.str();