#include "LyXFunc.h"
#include "BranchList.h"
-#include "Buffer.h"
#include "buffer_funcs.h"
+#include "Buffer.h"
#include "BufferList.h"
#include "BufferParams.h"
#include "BufferView.h"
-#include "bufferview_funcs.h"
+#include "callback.h"
+#include "Color.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "debug.h"
#include "Intl.h"
#include "KeyMap.h"
#include "Language.h"
-#include "Color.h"
-#include "Session.h"
-#include "LyX.h"
-#include "callback.h"
+#include "Lexer.h"
#include "LyXAction.h"
#include "lyxfind.h"
-#include "Lexer.h"
+#include "LyX.h"
#include "LyXRC.h"
-#include "Row.h"
-#include "Server.h"
-#include "TextClassList.h"
#include "LyXVC.h"
#include "Paragraph.h"
-#include "ParIterator.h"
#include "ParagraphParameters.h"
+#include "ParIterator.h"
+#include "Row.h"
+#include "Server.h"
+#include "Session.h"
+#include "TextClassList.h"
+#include "ToolbarBackend.h"
#include "Undo.h"
#include "insets/InsetBox.h"
#include "frontends/Gui.h"
#include "frontends/KeySymbol.h"
#include "frontends/LyXView.h"
-#include "frontends/Menubar.h"
#include "frontends/Selection.h"
-#include "frontends/Toolbars.h"
#include "frontends/WorkArea.h"
#include "support/environment.h"
namespace lyx {
-using bv_funcs::freefont2string;
-
using frontend::LyXView;
using support::absolutePath;
namespace {
-bool getLocalStatus(Cursor cursor,
- FuncRequest const & cmd, FuncStatus & status)
+bool getLocalStatus(Cursor cursor, FuncRequest const & cmd, FuncStatus & status)
{
// Try to fix cursor in case it is broken.
cursor.fixIfBroken();
}
+
LyXFunc::LyXFunc()
- : lyx_view_(0),
- encoded_last_key(0),
- meta_fake_bit(key_modifier::none)
+ : lyx_view_(0), encoded_last_key(0), meta_fake_bit(key_modifier::none)
{
}
void LyXFunc::initKeySequences(KeyMap * kb)
{
- keyseq.reset(new KeySequence(kb, kb));
- cancel_meta_seq.reset(new KeySequence(kb, kb));
+ keyseq = KeySequence(kb, kb);
+ cancel_meta_seq = KeySequence(kb, kb);
}
{
char_type c = encoded_last_key;
- if (keyseq->length())
+ if (keyseq.length())
c = 0;
BOOST_ASSERT(lyx_view_ && lyx_view_->view());
c, get_accent(action).accent, view()->cursor().innerText(), view()->cursor());
// Need to clear, in case the minibuffer calls these
// actions
- keyseq->clear();
+ keyseq.clear();
// copied verbatim from do_accent_char
view()->cursor().resetAnchor();
view()->update();
}
-void LyXFunc::processKeySym(KeySymbolPtr keysym, key_modifier::state state)
+void LyXFunc::processKeySym(KeySymbol const & keysym,
+ key_modifier::state state)
{
- LYXERR(Debug::KEY) << "KeySym is " << keysym->getSymbolName() << endl;
+ LYXERR(Debug::KEY) << "KeySym is " << keysym.getSymbolName() << endl;
// Do nothing if we have nothing (JMarc)
- if (!keysym->isOK()) {
+ if (!keysym.isOK()) {
LYXERR(Debug::KEY) << "Empty kbd action (probably composing)"
<< endl;
return;
}
- if (keysym->isModifier()) {
+ if (keysym.isModifier()) {
LYXERR(Debug::KEY) << "isModifier true" << endl;
return;
}
//Encoding const * encoding = view()->cursor().getEncoding();
- //encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
+ //encoded_last_key = keysym.getISOEncoded(encoding ? encoding->name() : "");
// FIXME: encoded_last_key shadows the member variable of the same
// name. Is that intended?
- char_type encoded_last_key = keysym->getUCSEncoded();
+ char_type encoded_last_key = keysym.getUCSEncoded();
// Do a one-deep top-level lookup for
// cancel and meta-fake keys. RVDK_PATCH_5
- cancel_meta_seq->reset();
+ cancel_meta_seq.reset();
- FuncRequest func = cancel_meta_seq->addkey(keysym, state);
+ FuncRequest func = cancel_meta_seq.addkey(keysym, state);
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
<< " action first set to [" << func.action << ']'
<< endl;
// Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) {
// remove Caps Lock and Mod2 as a modifiers
- func = keyseq->addkey(keysym, (state | meta_fake_bit));
+ func = keyseq.addkey(keysym, (state | meta_fake_bit));
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
<< "action now set to ["
<< func.action << ']' << endl;
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
<< " Key [action="
<< func.action << "]["
- << to_utf8(keyseq->print(false)) << ']'
+ << to_utf8(keyseq.print(false)) << ']'
<< endl;
// already here we know if it any point in going further
// why not return already here if action == -1 and
// num_bytes == 0? (Lgb)
- if (keyseq->length() > 1) {
- lyx_view_->message(keyseq->print(true));
+ if (keyseq.length() > 1) {
+ lyx_view_->message(keyseq.print(true));
}
if (func.action == LFUN_UNKNOWN_ACTION &&
state == key_modifier::shift) {
LYXERR(Debug::KEY) << "Trying without shift" << endl;
- func = keyseq->addkey(keysym, key_modifier::none);
+ func = keyseq.addkey(keysym, key_modifier::none);
LYXERR(Debug::KEY) << "Action now " << func.action << endl;
}
// Hmm, we didn't match any of the keysequences. See
// if it's normal insertable text not already covered
// by a binding
- if (keysym->isText() && keyseq->length() == 1) {
+ if (keysym.isText() && keyseq.length() == 1) {
LYXERR(Debug::KEY) << "isText() is true, inserting." << endl;
func = FuncRequest(LFUN_SELF_INSERT,
FuncRequest::KEYBOARD);
case LFUN_BUFFER_WRITE_AS:
case LFUN_BUFFER_UPDATE:
case LFUN_BUFFER_VIEW:
+ case LFUN_MASTER_BUFFER_UPDATE:
+ case LFUN_MASTER_BUFFER_VIEW:
case LFUN_BUFFER_IMPORT:
case LFUN_BUFFER_AUTO_SAVE:
case LFUN_RECONFIGURE:
case LFUN_TEXTCLASS_LOAD:
case LFUN_BUFFER_SAVE_AS_DEFAULT:
case LFUN_BUFFER_PARAMS_APPLY:
+ case LFUN_LAYOUT_MODULES_CLEAR:
+ case LFUN_LAYOUT_MODULE_ADD:
+ case LFUN_LAYOUT_RELOAD:
case LFUN_LYXRC_APPLY:
case LFUN_BUFFER_NEXT:
case LFUN_BUFFER_PREVIOUS:
}
-void loadTextclass(string const & name)
+void loadTextClass(string const & name)
{
std::pair<bool, textclass_type> const tc_pair =
textclasslist.numberOfClass(name);
textclass_type const tc = tc_pair.second;
if (!textclasslist[tc].load()) {
- docstring s = bformat(_("The document could not be converted\n"
- "into the document class %1$s."),
+ docstring s = bformat(_("The document class %1$s."
+ "could not be loaded."),
from_utf8(textclasslist[tc].name()));
- Alert::error(_("Could not change class"), s);
+ Alert::error(_("Could not load class"), s);
}
}
case LFUN_COMMAND_PREFIX:
BOOST_ASSERT(lyx_view_);
- lyx_view_->message(keyseq->printOptions(true));
+ lyx_view_->message(keyseq.printOptions(true));
break;
case LFUN_COMMAND_EXECUTE:
case LFUN_CANCEL:
BOOST_ASSERT(lyx_view_ && lyx_view_->view());
- keyseq->reset();
+ keyseq.reset();
meta_fake_bit = key_modifier::none;
if (lyx_view_->buffer())
// cancel any selection
case LFUN_META_PREFIX:
meta_fake_bit = key_modifier::alt;
- setMessage(keyseq->print(true));
+ setMessage(keyseq.print(true));
break;
case LFUN_BUFFER_TOGGLE_READ_ONLY:
Exporter::preview(lyx_view_->buffer(), argument);
break;
+ case LFUN_MASTER_BUFFER_UPDATE:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->getMasterBuffer());
+ Exporter::Export(lyx_view_->buffer()->getMasterBuffer(), argument, true);
+ break;
+
+ case LFUN_MASTER_BUFFER_VIEW:
+ BOOST_ASSERT(lyx_view_ && lyx_view_->buffer() && lyx_view_->buffer()->getMasterBuffer());
+ Exporter::preview(lyx_view_->buffer()->getMasterBuffer(), argument);
+ break;
+
case LFUN_BUILD_PROGRAM:
BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
Exporter::Export(lyx_view_->buffer(), "program", true);
case LFUN_RECONFIGURE:
BOOST_ASSERT(lyx_view_);
- reconfigure(*lyx_view_);
+ // argument is any additional parameter to the configure.py command
+ reconfigure(*lyx_view_, argument);
break;
case LFUN_HELP_OPEN: {
case LFUN_MENU_OPEN:
BOOST_ASSERT(lyx_view_);
- lyx_view_->getMenubar().openByName(from_utf8(argument));
+ lyx_view_->openMenu(from_utf8(argument));
break;
// --- lyxserver commands ----------------------------
break;
case LFUN_SERVER_NOTIFY:
- dispatch_buffer = keyseq->print(false);
+ dispatch_buffer = keyseq.print(false);
theServer().notifyClient(to_utf8(dispatch_buffer));
break;
InsetBranchParams p;
data = InsetBranchMailer::params2string(p);
} else if (name == "citation") {
- InsetCommandParams p("cite");
+ InsetCommandParams p("citation");
data = InsetCommandMailer::params2string(name, p);
} else if (name == "ert") {
data = InsetERTMailer::params2string(InsetCollapsable::Open);
arg = token(argument, '|', 0);
opt1 = token(argument, '|', 1);
}
- InsetCommandParams icp("cite");
+ InsetCommandParams icp("citation");
icp["key"] = from_utf8(arg);
if (!opt1.empty())
icp["before"] = from_utf8(opt1);
case LFUN_BUFFER_PARAMS_APPLY: {
BOOST_ASSERT(lyx_view_);
- biblio::CiteEngine const engine =
- lyx_view_->buffer()->params().getEngine();
+ biblio::CiteEngine const oldEngine =
+ lyx_view_->buffer()->params().getEngine();
+
+ Buffer * buffer = lyx_view_->buffer();
+ TextClassPtr oldClass = buffer->params().getTextClassPtr();
+ recordUndoFullDocument(view());
+
istringstream ss(argument);
Lexer lex(0,0);
lex.setStream(ss);
- int const unknown_tokens =
- lyx_view_->buffer()->readHeader(lex);
+ int const unknown_tokens = buffer->readHeader(lex);
if (unknown_tokens != 0) {
lyxerr << "Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
- << unknown_tokens << " unknown token"
- << (unknown_tokens == 1 ? "" : "s")
- << endl;
+ << unknown_tokens << " unknown token"
+ << (unknown_tokens == 1 ? "" : "s")
+ << endl;
}
- if (engine == lyx_view_->buffer()->params().getEngine())
- break;
-
- Cursor & cur = view()->cursor();
- FuncRequest fr(LFUN_INSET_REFRESH);
-
- Inset & inset = lyx_view_->buffer()->inset();
- InsetIterator it = inset_iterator_begin(inset);
- InsetIterator const end = inset_iterator_end(inset);
- for (; it != end; ++it)
- if (it->lyxCode() == Inset::CITE_CODE)
- it->dispatch(cur, fr);
+
+ updateLayout(oldClass, buffer);
+
+ biblio::CiteEngine const newEngine =
+ lyx_view_->buffer()->params().getEngine();
+
+ if (oldEngine != newEngine) {
+ Cursor & cur = view()->cursor();
+ FuncRequest fr(LFUN_INSET_REFRESH);
+
+ Inset & inset = lyx_view_->buffer()->inset();
+ InsetIterator it = inset_iterator_begin(inset);
+ InsetIterator const end = inset_iterator_end(inset);
+ for (; it != end; ++it)
+ if (it->lyxCode() == Inset::CITE_CODE)
+ it->dispatch(cur, fr);
+ }
+
+ updateFlags = Update::Force | Update::FitCursor;
+ break;
+ }
+
+ case LFUN_LAYOUT_MODULES_CLEAR: {
+ BOOST_ASSERT(lyx_view_);
+ Buffer * buffer = lyx_view_->buffer();
+ TextClassPtr oldClass = buffer->params().getTextClassPtr();
+ recordUndoFullDocument(view());
+ buffer->params().clearLayoutModules();
+ updateLayout(oldClass, buffer);
+ updateFlags = Update::Force | Update::FitCursor;
+ break;
+ }
+
+ case LFUN_LAYOUT_MODULE_ADD: {
+ BOOST_ASSERT(lyx_view_);
+ Buffer * buffer = lyx_view_->buffer();
+ TextClassPtr oldClass = buffer->params().getTextClassPtr();
+ recordUndoFullDocument(view());
+ buffer->params().addLayoutModule(argument);
+ updateLayout(oldClass, buffer);
+ updateFlags = Update::Force | Update::FitCursor;
break;
}
BOOST_ASSERT(lyx_view_);
Buffer * buffer = lyx_view_->buffer();
- textclass_type const old_class =
- buffer->params().textclass;
-
- loadTextclass(argument);
+ loadTextClass(argument);
std::pair<bool, textclass_type> const tc_pair =
textclasslist.numberOfClass(argument);
if (!tc_pair.first)
break;
+ textclass_type const old_class = buffer->params().getBaseClass();
textclass_type const new_class = tc_pair.second;
+
if (old_class == new_class)
// nothing to do
break;
- lyx_view_->message(_("Converting document to new document class..."));
+ //Save the old, possibly modular, layout for use in conversion.
+ TextClassPtr oldClass = buffer->params().getTextClassPtr();
recordUndoFullDocument(view());
- buffer->params().textclass = new_class;
- StableDocIterator backcur(view()->cursor());
- ErrorList & el = buffer->errorList("Class Switch");
- cap::switchBetweenClasses(
- old_class, new_class,
- static_cast<InsetText &>(buffer->inset()), el);
-
- view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
-
- buffer->errors("Class Switch");
- updateLabels(*buffer);
+ buffer->params().setBaseClass(new_class);
+ updateLayout(oldClass, buffer);
+ updateFlags = Update::Force | Update::FitCursor;
+ break;
+ }
+
+ case LFUN_LAYOUT_RELOAD: {
+ BOOST_ASSERT(lyx_view_);
+ Buffer * buffer = lyx_view_->buffer();
+ TextClassPtr oldClass = buffer->params().getTextClassPtr();
+ textclass_type const tc = buffer->params().getBaseClass();
+ textclasslist.reset(tc);
+ buffer->params().setBaseClass(tc);
+ updateLayout(oldClass, buffer);
updateFlags = Update::Force | Update::FitCursor;
break;
}
case LFUN_TEXTCLASS_LOAD:
- loadTextclass(argument);
+ loadTextClass(argument);
break;
case LFUN_LYXRC_APPLY: {
}
}
if (!quitting && lyx_view_) {
- lyx_view_->updateMenubar();
lyx_view_->updateToolbars();
// Some messages may already be translated, so we cannot use _()
sendDispatchMessage(translateIfPossible(getMessage()), cmd);
{
// When meta-fake key is pressed, show the key sequence so far + "M-".
if (wasMetaKey())
- return keyseq->print(true) + "M-";
+ return keyseq.print(true) + "M-";
// Else, when a non-complete key sequence is pressed,
// show the available options.
- if (keyseq->length() > 0 && !keyseq->deleted())
- return keyseq->printOptions(true);
+ if (keyseq.length() > 0 && !keyseq.deleted())
+ return keyseq.printOptions(true);
BOOST_ASSERT(lyx_view_);
if (!lyx_view_->buffer())
}
+void LyXFunc::updateLayout(TextClassPtr const & oldlayout,
+ Buffer * buffer)
+{
+ lyx_view_->message(_("Converting document to new document class..."));
+
+ StableDocIterator backcur(view()->cursor());
+ ErrorList & el = buffer->errorList("Class Switch");
+ cap::switchBetweenClasses(
+ oldlayout, buffer->params().getTextClassPtr(),
+ static_cast<InsetText &>(buffer->inset()), el);
+
+ view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
+
+ buffer->errors("Class Switch");
+ updateLabels(*buffer);
+}
+
+
namespace {
void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)