On Fri, Oct 21, 2016 at 11:20:03AM +0200, Jean-Marc Lasgouttes wrote: > Le 21/10/2016 à 04:47, Scott Kostyshak a écrit : > > > Makes sense. I'll work on a better patch. > > > > Is the attached what you meant? If so I would audit the other calls to > > LFUN_SET_COLOR. > > Yes, I think so. Note that the double quotes are not really part of the > syntax, they can be omitted as before. They are just useful as they are in > bash scripting.
OK. > As for the annoying code to build the command line, I'd say it would be nice > to have some helpers like FuncRequuest::addArg(std::string) or something > like that. Done in the attached patch. > The idea would be to tend to some API where the actual syntax of the lfun > does not matter that much. This would be nice. I wonder if creating a type "argument" might be a start for cleaning things up. > I do not know where I am going with these remarks, but the idea is that, if > we had a proper syntax, we would be in a position to do some better > scripting, for example. Or just change syntax. I agree. Scott
From 57d007a7d84366e0453182f7fd78555b593d32af Mon Sep 17 00:00:00 2001 From: Scott Kostyshak <skost...@lyx.org> Date: Thu, 20 Oct 2016 22:41:31 -0400 Subject: [PATCH] Fix color when branch name has a space The arguments are now double-quoted. This is handled by a helper function, FuncRequest::addArg(). --- src/Buffer.cpp | 6 ++++-- src/FuncRequest.cpp | 6 ++++++ src/FuncRequest.h | 2 ++ src/frontends/qt4/GuiApplication.cpp | 4 ++-- src/frontends/qt4/GuiDocument.cpp | 12 ++++++++---- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index f2dbb88..9cbd80f 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2758,10 +2758,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) } else { undo().recordUndoBufferParams(CursorData()); branch_list.add(branch_name); + FuncRequest fr(LFUN_SET_COLOR); branch = branch_list.find(branch_name); + fr.addArg(branch_name); string const x11hexname = X11hexname(branch->color()); - docstring const str = branch_name + ' ' + from_ascii(x11hexname); - lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str)); + fr.addArg(from_ascii(x11hexname)); + lyx::dispatch(fr); dr.setError(false); dr.screenUpdate(Update::Force); } diff --git a/src/FuncRequest.cpp b/src/FuncRequest.cpp index a8d8859..574f534 100644 --- a/src/FuncRequest.cpp +++ b/src/FuncRequest.cpp @@ -119,6 +119,12 @@ string FuncRequest::getLongArg(unsigned int i) const } +void FuncRequest::addArg(docstring const & str) +{ + argument_ = argument_ + '"' + str + '"'; +} + + bool operator==(FuncRequest const & lhs, FuncRequest const & rhs) { return lhs.action() == rhs.action() && lhs.argument() == rhs.argument(); diff --git a/src/FuncRequest.h b/src/FuncRequest.h index a5822f4..dc5895e 100644 --- a/src/FuncRequest.h +++ b/src/FuncRequest.h @@ -85,6 +85,8 @@ public: /// argument parsing, extract argument i as std::string, /// eating all characters up to the end of the command line std::string getLongArg(unsigned int i) const; + /// Adds an argument + void addArg(docstring const &); /// static FuncRequest const unknown; diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 2f6f8f2..df8531e 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1735,8 +1735,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_SET_COLOR: { - string lyx_name; - string const x11_name = split(to_utf8(cmd.argument()), lyx_name, ' '); + string lyx_name = cmd.getArg(0); + string x11_name = cmd.getArg(1); if (lyx_name.empty() || x11_name.empty()) { if (current_view_) current_view_->message( diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 2a40873..d252409 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -3825,8 +3825,10 @@ void GuiDocument::dispatchParams() Branch const * branch = branchlist.find(current_branch); string const x11hexname = X11hexname(branch->color()); // display the new color - docstring const str = current_branch + ' ' + from_ascii(x11hexname); - dispatch(FuncRequest(LFUN_SET_COLOR, str)); + FuncRequest fr(LFUN_SET_COLOR); + fr.addArg(current_branch); + fr.addArg(from_ascii(x11hexname)); + dispatch(fr); } // Open insets of selected branches, close deselected ones @@ -3848,8 +3850,10 @@ void GuiDocument::dispatchParams() Index const * index = indiceslist.findShortcut(current_index); string const x11hexname = X11hexname(index->color()); // display the new color - docstring const str = current_index + ' ' + from_ascii(x11hexname); - dispatch(FuncRequest(LFUN_SET_COLOR, str)); + FuncRequest fr(LFUN_SET_COLOR); + fr.addArg(current_index); + fr.addArg(from_ascii(x11hexname)); + dispatch(fr); } } // FIXME LFUN -- 2.7.4
signature.asc
Description: PGP signature