#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"
return;
}
// open may fail, so we need to test it again
- if (theBufferList().exists(file)) {
- // if the current buffer is not that one, switch to it.
- if (lyx_view_->buffer()->fileName() != file) {
- if (switchToBuffer)
- dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
- else
- return;
- }
- // moveToPosition try paragraph id first and then paragraph (pit, pos).
- if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
- bm.top_id, bm.top_pos))
- return;
+ if (!theBufferList().exists(file))
+ return;
- // Cursor jump succeeded!
- Cursor const & cur = view()->cursor();
- pit_type new_pit = cur.pit();
- pos_type new_pos = cur.pos();
- int new_id = cur.paragraph().id();
+ // if the current buffer is not that one, switch to it.
+ if (lyx_view_->buffer()->fileName() != file) {
+ if (!switchToBuffer)
+ return;
+ dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
+ }
+ // moveToPosition try paragraph id first and then paragraph (pit, pos).
+ if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
+ bm.top_id, bm.top_pos))
+ return;
- // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
- // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
- if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos || bm.top_id != new_id )
- const_cast<BookmarksSection::Bookmark &>(bm).updatePos(new_pit, new_pos, new_id);
+ // Cursor jump succeeded!
+ Cursor const & cur = view()->cursor();
+ pit_type new_pit = cur.pit();
+ pos_type new_pos = cur.pos();
+ int new_id = cur.paragraph().id();
+
+ // if bottom_pit, bottom_pos or top_id has been changed, update bookmark
+ // see http://bugzilla.lyx.org/show_bug.cgi?id=3092
+ if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos
+ || bm.top_id != new_id) {
+ const_cast<BookmarksSection::Bookmark &>(bm).updatePos(
+ new_pit, new_pos, new_id);
}
}
-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
// 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);
break;
case LFUN_TOOLBAR_TOGGLE: {
- bool const current = lyx_view_->getToolbars().visible(cmd.getArg(0));
+ bool const current = lyx_view_->isToolbarVisible(cmd.getArg(0));
flag.setOnOff(current);
break;
}
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_EXECUTE:
BOOST_ASSERT(lyx_view_);
- lyx_view_->getToolbars().display("minibuffer", true);
- lyx_view_->focus_command_buffer();
+ lyx_view_->showMiniBuffer(true);
break;
case LFUN_CANCEL:
case LFUN_DROP_LAYOUTS_CHOICE:
BOOST_ASSERT(lyx_view_);
- lyx_view_->getToolbars().openLayoutList();
+ lyx_view_->openLayoutList();
break;
case LFUN_MENU_OPEN:
BOOST_ASSERT(lyx_view_);
- lyx_view_->getMenubar().openByName(from_utf8(argument));
+ lyx_view_->openMenu(from_utf8(argument));
break;
// --- lyxserver commands ----------------------------
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();
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+ 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();
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+ 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();
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+ 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.
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
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();
+ TextClass_ptr oldClass = buffer->params().getTextClass_ptr();
+ 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);
}
+void LyXFunc::updateLayout(TextClass_ptr 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().getTextClass_ptr(),
+ 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)