+ // Don't dispatch function that does not apply to internal buffers.
+ if (buffer_.isInternal()
+ && lyxaction.funcHasFlag(cmd.action(), LyXAction::NoInternal))
+ return;
+
+ // We'll set this back to false if need be.
+ bool dispatched = true;
+ buffer_.undo().beginUndoGroup();
+
+ FuncCode const act = cmd.action();
+ switch (act) {
+
+ case LFUN_BUFFER_PARAMS_APPLY: {
+ DocumentClass const * const oldClass = buffer_.params().documentClassPtr();
+ cur.recordUndoFullDocument();
+ istringstream ss(to_utf8(cmd.argument()));
+ Lexer lex;
+ lex.setStream(ss);
+ int const unknown_tokens = buffer_.readHeader(lex);
+ if (unknown_tokens != 0) {
+ LYXERR0("Warning in LFUN_BUFFER_PARAMS_APPLY!\n"
+ << unknown_tokens << " unknown token"
+ << (unknown_tokens == 1 ? "" : "s"));
+ }
+ updateDocumentClass(oldClass);
+
+ // We are most certainly here because of a change in the document
+ // It is then better to make sure that all dialogs are in sync with
+ // current document settings.
+ dr.screenUpdate(Update::Force | Update::FitCursor);
+ dr.forceBufferUpdate();
+ break;
+ }
+
+ case LFUN_LAYOUT_MODULES_CLEAR: {
+ DocumentClass const * const oldClass =
+ buffer_.params().documentClassPtr();
+ cur.recordUndoFullDocument();
+ buffer_.params().clearLayoutModules();
+ buffer_.params().makeDocumentClass();
+ updateDocumentClass(oldClass);
+ dr.screenUpdate(Update::Force);
+ dr.forceBufferUpdate();
+ break;
+ }
+
+ case LFUN_LAYOUT_MODULE_ADD: {
+ BufferParams const & params = buffer_.params();
+ if (!params.moduleCanBeAdded(argument)) {
+ LYXERR0("Module `" << argument <<
+ "' cannot be added due to failed requirements or "
+ "conflicts with installed modules.");
+ break;
+ }
+ DocumentClass const * const oldClass = params.documentClassPtr();
+ cur.recordUndoFullDocument();
+ buffer_.params().addLayoutModule(argument);
+ buffer_.params().makeDocumentClass();
+ updateDocumentClass(oldClass);
+ dr.screenUpdate(Update::Force);
+ dr.forceBufferUpdate();
+ break;
+ }
+
+ case LFUN_TEXTCLASS_APPLY: {
+ // since this shortcircuits, the second call is made only if
+ // the first fails
+ bool const success =
+ LayoutFileList::get().load(argument, buffer_.temppath()) ||
+ LayoutFileList::get().load(argument, buffer_.filePath());
+ if (!success) {
+ docstring s = bformat(_("The document class `%1$s' "
+ "could not be loaded."), from_utf8(argument));
+ frontend::Alert::error(_("Could not load class"), s);
+ break;
+ }
+
+ LayoutFile const * old_layout = buffer_.params().baseClass();
+ LayoutFile const * new_layout = &(LayoutFileList::get()[argument]);
+
+ if (old_layout == new_layout)
+ // nothing to do
+ break;
+
+ // Save the old, possibly modular, layout for use in conversion.
+ DocumentClass const * const oldDocClass =
+ buffer_.params().documentClassPtr();
+ cur.recordUndoFullDocument();
+ buffer_.params().setBaseClass(argument);
+ buffer_.params().makeDocumentClass();
+ updateDocumentClass(oldDocClass);
+ dr.screenUpdate(Update::Force);
+ dr.forceBufferUpdate();
+ break;
+ }
+
+ case LFUN_TEXTCLASS_LOAD: {
+ // since this shortcircuits, the second call is made only if
+ // the first fails
+ bool const success =
+ LayoutFileList::get().load(argument, buffer_.temppath()) ||
+ LayoutFileList::get().load(argument, buffer_.filePath());
+ if (!success) {
+ docstring s = bformat(_("The document class `%1$s' "
+ "could not be loaded."), from_utf8(argument));
+ frontend::Alert::error(_("Could not load class"), s);
+ }
+ break;
+ }
+
+ case LFUN_LAYOUT_RELOAD: {
+ DocumentClass const * const oldClass = buffer_.params().documentClassPtr();
+ LayoutFileIndex bc = buffer_.params().baseClassID();
+ LayoutFileList::get().reset(bc);
+ buffer_.params().setBaseClass(bc);
+ buffer_.params().makeDocumentClass();
+ updateDocumentClass(oldClass);
+ dr.screenUpdate(Update::Force);
+ dr.forceBufferUpdate();
+ break;
+ }