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);
32 FuncRequest::FuncRequest(Origin o)
37 FuncRequest::FuncRequest(FuncCode act, Origin o)
38 : action_(act), origin_(o)
42 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
43 : action_(act), argument_(arg), origin_(o)
47 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
48 : FuncRequest(act, from_utf8(arg), o)
52 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
53 mouse_button::state button, KeyModifier modifier, Origin o)
54 : action_(act), origin_(o),
55 x_(ax), y_(ay), button_(button), modifier_(modifier)
59 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, Origin o)
60 : action_(cmd.action()), argument_(arg), origin_(o),
61 x_(cmd.x_), y_(cmd.y_), button_(cmd.button_)
67 // Extracts arguments from str into args. Arguments are delimited by
68 // whitespace or by double quotes.
69 // We extract at most max + 1 arguments, treating args[max] as
71 void splitArg(vector<string> & args, string const & str,
72 unsigned int max = UINT_MAX)
74 istringstream is(str);
76 if (args.size() == max) {
79 args.push_back(trim(s));
88 // get quote delimited argument
91 // get whitespace delimited argument
102 string FuncRequest::getArg(unsigned int i) const
105 splitArg(args, to_utf8(argument_));
106 return i < args.size() ? args[i] : string();
110 string FuncRequest::getLongArg(unsigned int i) const
113 splitArg(args, to_utf8(argument_), i);
114 return i < args.size() ? args[i] : string();
117 bool operator==(FuncRequest const & lhs, FuncRequest const & rhs)
119 return lhs.action() == rhs.action() && lhs.argument() == rhs.argument();
123 ostream & operator<<(ostream & os, FuncRequest const & cmd)
126 << " action: " << cmd.action()
127 << " [" << lyxaction.getActionName(cmd.action()) << "] "
128 << " arg: '" << to_utf8(cmd.argument()) << "'"
130 << " y: " << cmd.y();
134 LyXErr & operator<<(LyXErr &l, FuncRequest const &fr)
138 return l << oss.str();