+2004-03-30 Angus Leeming <leeming@lyx.org>
+
+ * lfuns.h:
+ * LyXAction.C: new lfuns LFUN_LANGUAGE_BUFFER, LFUN_TEXTCLASS_APPLY,
+ LFUN_TEXTCLASS_LOAD, LFUN_SAVE_AS_DEFAULT, LFUN_BUFFERPARAMS_APPLY.
+
+ * lyxfunc.C (getStatus, dispatch): define the actions for these
+ lfuns. Little more than a cut and pste job from ControlDocument.C
+
+ * lyxtextclass.[Ch] (loaded): accessor for the private bool loaded_.
+
2004-03-30 Angus Leeming <leeming@lyx.org>
* lfuns.h:
{ LFUN_WORD_FIND, "word-find", Noop },
{ LFUN_WORD_REPLACE, "word-replace", Noop },
{ LFUN_KEYMAP_TOGGLE, "keymap-toggle", Noop },
+ { LFUN_LANGUAGE_BUFFER, "buffer-language", Noop },
+ { LFUN_TEXTCLASS_APPLY, "textclass-apply", Noop },
+ { LFUN_TEXTCLASS_LOAD, "textclass-load", Noop },
+ { LFUN_SAVE_AS_DEFAULT, "buffer-save-as-default", Noop },
+ { LFUN_BUFFERPARAMS_APPLY, "buffer-params-apply", Noop },
{ LFUN_NOACTION, "", Noop }
};
+2004-03-30 Angus Leeming <leeming@lyx.org>
+
+ * ControlDocument.[Ch]: move all of the 'apply' code into the core
+ and access it by dispatching the appropriate lfuns.
+
2004-03-30 Angus Leeming <leeming@lyx.org>
* ControlDocument.C (apply): replace the loop over paragraphs
#include "BranchList.h"
#include "buffer.h"
-#include "buffer_funcs.h"
#include "bufferparams.h"
-#include "BufferView.h"
-#include "CutAndPaste.h"
-#include "errorlist.h"
#include "funcrequest.h"
-#include "gettext.h"
#include "language.h"
#include "LColor.h"
#include "lyxtextclasslist.h"
-#include "lfuns.h"
-#include "paragraph.h"
-#include "ParagraphList_fwd.h"
-#include "frontends/Alert.h"
#include "frontends/LyXView.h"
-#include "support/filetools.h"
-#include "support/path_defines.h"
-
-using lyx::support::AddName;
-using lyx::support::AddPath;
-using lyx::support::bformat;
-using lyx::support::user_lyxdir;
+#include "support/std_sstream.h"
+using std::ostringstream;
using std::string;
{}
+void ControlDocument::setParams()
+{
+ if (!bp_.get())
+ bp_.reset(new BufferParams);
+
+ /// Set the buffer parameters
+ *bp_ = buffer()->params();
+}
+
+
BufferParams & ControlDocument::params()
{
BOOST_ASSERT(bp_.get());
}
+namespace {
+
+void dispatch_params(LyXView & lv, BufferParams const & bp, kb_action lfun)
+{
+ ostringstream ss;
+ bp.writeFile(ss);
+ ss << "\\end_header\n";
+ lv.dispatch(FuncRequest(lfun, ss.str()));
+}
+
+} // namespace anon
+
+
void ControlDocument::apply()
{
if (!bufferIsAvailable())
view().apply();
- // this must come first so that a language change
- // is correctly noticed
+ // This must come first so that a language change is correctly noticed
setLanguage();
- classApply();
-
- buffer()->params() = *bp_;
-
- lv_.view()->redoCurrentBuffer();
+ // Set the document class.
+ lyx::textclass_type const old_class = buffer()->params().textclass;
+ lyx::textclass_type const new_class = bp_->textclass;
- buffer()->markDirty();
+ if (new_class != old_class) {
+ string const name = textclasslist[new_class].name();
+ lv_.dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
+ }
- lv_.message(_("Document settings applied"));
+ // Apply the BufferParams.
+ dispatch_params(lv_, params(), LFUN_BUFFERPARAMS_APPLY);
- // branches
+ // Generate the colours requested by each new branch.
BranchList & branchlist = params().branchlist();
+ if (branchlist.empty())
+ return;
+
BranchList::const_iterator it = branchlist.begin();
BranchList::const_iterator const end = branchlist.end();
for (; it != end; ++it) {
}
-void ControlDocument::setParams()
-{
- if (!bp_.get())
- bp_.reset(new BufferParams);
-
- /// Set the buffer parameters
- *bp_ = buffer()->params();
-}
-
-
void ControlDocument::setLanguage()
{
- Language const * oldL = buffer()->params().language;
- Language const * newL = bp_->language;
+ Language const * const newL = bp_->language;
+ if (buffer()->params().language == newL)
+ return;
- if (oldL != newL) {
-
- if (oldL->RightToLeft() == newL->RightToLeft()
- && !lv_.buffer()->isMultiLingual())
- lv_.buffer()->changeLanguage(oldL, newL);
- else
- lv_.buffer()->updateDocLang(newL);
- }
-}
-
-
-void ControlDocument::classApply()
-{
- BufferParams & params = buffer()->params();
- lyx::textclass_type const old_class = params.textclass;
- lyx::textclass_type const new_class = bp_->textclass;
-
- // exit if nothing changes or if unable to load the new class
- if (new_class == old_class || !loadTextclass(new_class))
- return;
-
- // successfully loaded
- buffer()->params() = *bp_;
-
- lv_.message(_("Converting document to new document class..."));
-
- ErrorList el;
- lyx::cap::SwitchLayoutsBetweenClasses(old_class, new_class,
- lv_.buffer()->paragraphs(),
- el);
- bufferErrors(*buffer(), el);
- bufferview()->showErrorList(_("Class switch"));
+ string const lang_name = newL->lang();
+ lv_.dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
}
bool ControlDocument::loadTextclass(lyx::textclass_type tc) const
{
- bool const success = textclasslist[tc].load();
- if (success)
- return success;
-
- string s = bformat(_("The document could not be converted\n"
- "into the document class %1$s."),
- textclasslist[tc].name());
- Alert::error(_("Could not change class"), s);
+ string const name = textclasslist[tc].name();
+ lv_.dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
+ // Report back whether we were able to change the class.
+ bool const success = textclasslist[tc].loaded();
return success;
}
void ControlDocument::saveAsDefault()
{
-// Can somebody justify this ? I think it should be removed - jbl
-#if 0
- if (!Alert::askQuestion(_("Do you want to save the current settings"),
- _("for the document layout as default?"),
- _("(they will be valid for any new document)")))
- return;
-#endif
-
- lv_.buffer()->params().preamble = bp_->preamble;
-
- string const fname = AddName(AddPath(user_lyxdir(), "templates/"),
- "defaults.lyx");
- Buffer defaults(fname);
- defaults.params() = params();
-
- // add an empty paragraph. Is this enough?
- Paragraph par;
- par.layout(params().getLyXTextClass().defaultLayout());
- defaults.paragraphs().push_back(par);
-
- defaults.writeFile(defaults.fileName());
-
+ dispatch_params(lv_, params(), LFUN_SAVE_AS_DEFAULT);
}
///
void saveAsDefault();
///
- void classApply();
- ///
bool loadTextclass(lyx::textclass_type tc) const;
private:
/// apply settings
LFUN_KEYMAP_TOGGLE,
LFUN_NEXT_INSET_TOGGLE,
LFUN_ALL_INSETS_TOGGLE,
+ // 260
+ LFUN_LANGUAGE_BUFFER,
+ LFUN_TEXTCLASS_APPLY,
+ LFUN_TEXTCLASS_LOAD,
+ LFUN_SAVE_AS_DEFAULT,
+ LFUN_BUFFERPARAMS_APPLY,
+ // 265
LFUN_LASTACTION // end of the table
};
#include "bufferparams.h"
#include "BufferView.h"
#include "cursor.h"
+#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
#include "encoding.h"
+#include "errorlist.h"
#include "exporter.h"
#include "format.h"
#include "funcrequest.h"
#include "insetiterator.h"
#include "intl.h"
#include "kbmap.h"
+#include "language.h"
#include "LColor.h"
#include "lyx_cb.h"
#include "LyXAction.h"
#include "lyxfind.h"
+#include "lyxlex.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "lyxserver.h"
+#include "lyxtextclasslist.h"
#include "lyxvc.h"
#include "paragraph.h"
#include "pariterator.h"
case LFUN_FILE_INSERT_ASCII:
case LFUN_FILE_INSERT_ASCII_PARA:
case LFUN_ALL_INSETS_TOGGLE:
+ case LFUN_LANGUAGE_BUFFER:
+ case LFUN_TEXTCLASS_APPLY:
+ case LFUN_TEXTCLASS_LOAD:
+ case LFUN_SAVE_AS_DEFAULT:
+ case LFUN_BUFFERPARAMS_APPLY:
+
// these are handled in our dispatch()
break;
flag.enabled(false);
// Can we use a readonly buffer?
- if (buf && buf->isReadonly()
+ if (buf && buf->isReadonly()
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
setStatusMessage(N_("Document is read-only"));
Systemcall::DontWait,
command + QuoteName(dviname));
}
-
+
} else {
// case 1: print to a file
command += lyxrc.print_to_file
break;
}
+ case LFUN_LANGUAGE_BUFFER: {
+ Buffer & buffer = *owner->buffer();
+ Language const * oldL = buffer.params().language;
+ Language const * newL = languages.getLanguage(argument);
+ if (!newL || oldL == newL)
+ break;
+
+ if (oldL->RightToLeft() == newL->RightToLeft()
+ && !buffer.isMultiLingual())
+ buffer.changeLanguage(oldL, newL);
+ else
+ buffer.updateDocLang(newL);
+ break;
+ }
+
+ case LFUN_BUFFERPARAMS_APPLY: {
+ istringstream ss(argument);
+ LyXLex lex(0,0);
+ lex.setStream(ss);
+ int const unknown_tokens =
+ owner->buffer()->readHeader(lex);
+
+ if (unknown_tokens != 0) {
+ lyxerr << "Warning in LFUN_BUFFERPARAMS_APPLY!\n"
+ << unknown_tokens << " unknown token"
+ << (unknown_tokens == 1 ? "" : "s")
+ << endl;
+ }
+ break;
+ }
+
+ case LFUN_TEXTCLASS_APPLY: {
+ Buffer * buffer = owner->buffer();
+
+ lyx::textclass_type const old_class =
+ buffer->params().textclass;
+
+ dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, argument));
+
+ std::pair<bool, lyx::textclass_type> const tc_pair =
+ textclasslist.NumberOfClass(argument);
+
+ if (!tc_pair.first)
+ break;
+
+ lyx::textclass_type const new_class = tc_pair.second;
+ if (old_class == new_class)
+ // nothing to do
+ break;
+
+ owner->message(
+ _("Converting document to new document class..."));
+
+ ErrorList el;
+ lyx::cap::SwitchLayoutsBetweenClasses(
+ old_class, new_class,
+ buffer->paragraphs(), el);
+
+ bufferErrors(*buffer, el);
+ view()->showErrorList(_("Class switch"));
+ break;
+ }
+
+ case LFUN_TEXTCLASS_LOAD: {
+ std::pair<bool, lyx::textclass_type> const tc_pair =
+ textclasslist.NumberOfClass(argument);
+
+ if (!tc_pair.first) {
+ lyxerr << "Document class \"" << argument
+ << "\" does not exist."
+ << std::endl;
+ break;
+ }
+
+ lyx::textclass_type const tc = tc_pair.second;
+
+ bool const success = textclasslist[tc].load();
+ if (success)
+ break;
+
+ string s = bformat(_("The document could not be converted\n"
+ "into the document class %1$s."),
+ textclasslist[tc].name());
+ Alert::error(_("Could not change class"), s);
+
+ break;
+ }
+
default: {
DispatchResult res = view()->cursor().dispatch(cmd);
if (!res.dispatched());
provides_ = nothing;
titletype_ = TITLE_COMMAND_AFTER;
titlename_ = "maketitle";
- loaded = false;
+ loaded_ = false;
}
// Load textclass info if not loaded yet
bool LyXTextClass::load() const
{
- if (loaded)
+ if (loaded_)
return true;
// Read style-file
<< "'\n(Check `" << name_
<< "')\nCheck your installation and "
"try Options/Reconfigure..." << endl;
- loaded = false;
+ loaded_ = false;
}
- loaded = true;
- return loaded;
+ loaded_ = true;
+ return loaded_;
}
/// Sees to that the textclass structure has been loaded
bool load() const;
+ /// Has this layout file been loaded yet?
+ bool loaded() const { return loaded_; }
/// the list of floats defined in the document class
FloatList & floats();
boost::shared_ptr<Counters> ctrs_;
/// Has this layout file been loaded yet?
- mutable bool loaded;
+ mutable bool loaded_;
/// Is the TeX class available?
bool texClassAvail_;