mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
5 new lfuns, move all apply code out of ControlDocument and into the core.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8565 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
991b0ec589
commit
eddeb13d2d
@ -1,3 +1,14 @@
|
||||
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:
|
||||
|
@ -329,6 +329,11 @@ void LyXAction::init()
|
||||
{ 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 }
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
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
|
||||
|
@ -15,31 +15,17 @@
|
||||
|
||||
#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;
|
||||
|
||||
|
||||
@ -52,6 +38,16 @@ ControlDocument::~ControlDocument()
|
||||
{}
|
||||
|
||||
|
||||
void ControlDocument::setParams()
|
||||
{
|
||||
if (!bp_.get())
|
||||
bp_.reset(new BufferParams);
|
||||
|
||||
/// Set the buffer parameters
|
||||
*bp_ = buffer()->params();
|
||||
}
|
||||
|
||||
|
||||
BufferParams & ControlDocument::params()
|
||||
{
|
||||
BOOST_ASSERT(bp_.get());
|
||||
@ -65,6 +61,19 @@ LyXTextClass ControlDocument::textClass()
|
||||
}
|
||||
|
||||
|
||||
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())
|
||||
@ -72,22 +81,26 @@ void ControlDocument::apply()
|
||||
|
||||
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();
|
||||
// Set the document class.
|
||||
lyx::textclass_type const old_class = buffer()->params().textclass;
|
||||
lyx::textclass_type const new_class = bp_->textclass;
|
||||
|
||||
buffer()->params() = *bp_;
|
||||
if (new_class != old_class) {
|
||||
string const name = textclasslist[new_class].name();
|
||||
lv_.dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
|
||||
}
|
||||
|
||||
lv_.view()->redoCurrentBuffer();
|
||||
// Apply the BufferParams.
|
||||
dispatch_params(lv_, params(), LFUN_BUFFERPARAMS_APPLY);
|
||||
|
||||
buffer()->markDirty();
|
||||
|
||||
lv_.message(_("Document settings applied"));
|
||||
|
||||
// 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) {
|
||||
@ -107,93 +120,29 @@ void ControlDocument::apply()
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -40,8 +40,6 @@ public:
|
||||
///
|
||||
void saveAsDefault();
|
||||
///
|
||||
void classApply();
|
||||
///
|
||||
bool loadTextclass(lyx::textclass_type tc) const;
|
||||
private:
|
||||
/// apply settings
|
||||
|
@ -340,6 +340,13 @@ enum kb_action {
|
||||
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
|
||||
};
|
||||
|
103
src/lyxfunc.C
103
src/lyxfunc.C
@ -28,9 +28,11 @@
|
||||
#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"
|
||||
@ -39,13 +41,16 @@
|
||||
#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"
|
||||
@ -496,6 +501,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
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;
|
||||
|
||||
@ -507,7 +518,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
||||
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"));
|
||||
@ -817,7 +828,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
Systemcall::DontWait,
|
||||
command + QuoteName(dviname));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// case 1: print to a file
|
||||
command += lyxrc.print_to_file
|
||||
@ -1271,6 +1282,94 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
||||
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());
|
||||
|
@ -72,7 +72,7 @@ LyXTextClass::LyXTextClass(string const & fn, string const & cln,
|
||||
provides_ = nothing;
|
||||
titletype_ = TITLE_COMMAND_AFTER;
|
||||
titlename_ = "maketitle";
|
||||
loaded = false;
|
||||
loaded_ = false;
|
||||
}
|
||||
|
||||
|
||||
@ -840,7 +840,7 @@ bool LyXTextClass::delete_layout(string const & name)
|
||||
// Load textclass info if not loaded yet
|
||||
bool LyXTextClass::load() const
|
||||
{
|
||||
if (loaded)
|
||||
if (loaded_)
|
||||
return true;
|
||||
|
||||
// Read style-file
|
||||
@ -852,10 +852,10 @@ bool LyXTextClass::load() const
|
||||
<< "'\n(Check `" << name_
|
||||
<< "')\nCheck your installation and "
|
||||
"try Options/Reconfigure..." << endl;
|
||||
loaded = false;
|
||||
loaded_ = false;
|
||||
}
|
||||
loaded = true;
|
||||
return loaded;
|
||||
loaded_ = true;
|
||||
return loaded_;
|
||||
}
|
||||
|
||||
|
||||
|
@ -84,6 +84,8 @@ public:
|
||||
|
||||
/// 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();
|
||||
@ -235,7 +237,7 @@ private:
|
||||
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_;
|
||||
|
Loading…
Reference in New Issue
Block a user