2002-10-09 08:59:02 +00:00
|
|
|
/**
|
|
|
|
* \file ControlDocument.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author Edwin Leuven
|
2002-10-09 08:59:02 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-10-09 08:59:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlDocument.h"
|
2004-03-30 19:18:14 +00:00
|
|
|
#include "Kernel.h"
|
2002-10-09 08:59:02 +00:00
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
#include "BranchList.h"
|
2002-10-09 08:59:02 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
#include "funcrequest.h"
|
2002-10-09 08:59:02 +00:00
|
|
|
#include "language.h"
|
2003-12-14 16:33:56 +00:00
|
|
|
#include "LColor.h"
|
2002-10-09 08:59:02 +00:00
|
|
|
#include "lyxtextclasslist.h"
|
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
#include "support/std_sstream.h"
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2002-10-09 08:59:02 +00:00
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
ControlDocument::ControlDocument(Dialog & parent)
|
|
|
|
: Dialog::Controller(parent)
|
2003-05-13 09:48:57 +00:00
|
|
|
{}
|
|
|
|
|
2002-10-09 08:59:02 +00:00
|
|
|
|
|
|
|
ControlDocument::~ControlDocument()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
bool ControlDocument::initialiseParams(std::string const &)
|
2004-03-30 16:19:50 +00:00
|
|
|
{
|
2004-03-30 19:18:14 +00:00
|
|
|
bp_.reset(new BufferParams);
|
|
|
|
*bp_ = kernel().buffer().params();
|
|
|
|
return true;
|
|
|
|
}
|
2004-03-30 16:19:50 +00:00
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
|
|
|
|
void ControlDocument::clearParams()
|
|
|
|
{
|
|
|
|
bp_.reset();
|
2004-03-30 16:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
BufferParams & ControlDocument::params() const
|
2002-10-09 08:59:02 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(bp_.get());
|
2002-10-09 08:59:02 +00:00
|
|
|
return *bp_;
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
LyXTextClass const & ControlDocument::textClass() const
|
2002-10-09 08:59:02 +00:00
|
|
|
{
|
|
|
|
return textclasslist[bp_->textclass];
|
|
|
|
}
|
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
namespace {
|
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
|
|
|
|
kb_action lfun)
|
2004-03-30 16:19:50 +00:00
|
|
|
{
|
2004-04-03 08:37:12 +00:00
|
|
|
ostringstream ss;
|
|
|
|
bp.writeFile(ss);
|
|
|
|
ss << "\\end_header\n";
|
|
|
|
kernel.dispatch(FuncRequest(lfun, ss.str()));
|
2004-03-30 16:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
void ControlDocument::dispatchParams()
|
2002-10-09 08:59:02 +00:00
|
|
|
{
|
2004-03-30 16:19:50 +00:00
|
|
|
// This must come first so that a language change is correctly noticed
|
2003-02-25 18:52:13 +00:00
|
|
|
setLanguage();
|
2003-06-06 14:47:43 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
// Set the document class.
|
2004-04-03 08:37:12 +00:00
|
|
|
lyx::textclass_type const old_class =
|
2004-03-30 19:18:14 +00:00
|
|
|
kernel().buffer().params().textclass;
|
2004-04-03 08:37:12 +00:00
|
|
|
lyx::textclass_type const new_class = bp_->textclass;
|
2002-10-09 08:59:02 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
if (new_class != old_class) {
|
|
|
|
string const name = textclasslist[new_class].name();
|
2004-03-30 19:18:14 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
|
2004-03-30 16:19:50 +00:00
|
|
|
}
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
// Apply the BufferParams.
|
2004-04-03 08:37:12 +00:00
|
|
|
dispatch_bufferparams(kernel(), params(), LFUN_BUFFERPARAMS_APPLY);
|
2003-08-17 11:28:23 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
// Generate the colours requested by each new branch.
|
2003-12-14 16:33:56 +00:00
|
|
|
BranchList & branchlist = params().branchlist();
|
2004-03-30 16:19:50 +00:00
|
|
|
if (branchlist.empty())
|
|
|
|
return;
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
BranchList::const_iterator it = branchlist.begin();
|
|
|
|
BranchList::const_iterator const end = branchlist.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
string const & current_branch = it->getBranch();
|
|
|
|
Branch const * branch = branchlist.find(current_branch);
|
|
|
|
string x11hexname = branch->getColor();
|
|
|
|
// check that we have a valid color!
|
|
|
|
if (x11hexname.empty() || x11hexname[0] != '#')
|
|
|
|
x11hexname = lcolor.getX11Name(LColor::background);
|
|
|
|
// display the new color
|
|
|
|
string const str = current_branch + ' ' + x11hexname;
|
2004-03-30 19:18:14 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
|
2003-12-14 16:33:56 +00:00
|
|
|
}
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
// Open insets of selected branches, close deselected ones
|
2004-03-30 19:18:14 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE, "toggle branch"));
|
2002-10-09 08:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
void ControlDocument::setLanguage() const
|
2002-10-09 08:59:02 +00:00
|
|
|
{
|
2004-03-30 16:19:50 +00:00
|
|
|
Language const * const newL = bp_->language;
|
2004-03-30 19:18:14 +00:00
|
|
|
if (kernel().buffer().params().language == newL)
|
2004-04-03 08:37:12 +00:00
|
|
|
return;
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
string const lang_name = newL->lang();
|
|
|
|
kernel().dispatch(FuncRequest(LFUN_LANGUAGE_BUFFER, lang_name));
|
2002-11-22 10:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ControlDocument::loadTextclass(lyx::textclass_type tc) const
|
|
|
|
{
|
2004-03-30 16:19:50 +00:00
|
|
|
string const name = textclasslist[tc].name();
|
2004-03-30 19:18:14 +00:00
|
|
|
kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
|
2003-03-31 01:15:44 +00:00
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
// Report back whether we were able to change the class.
|
|
|
|
bool const success = textclasslist[tc].loaded();
|
2002-11-22 10:47:56 +00:00
|
|
|
return success;
|
2002-10-09 08:59:02 +00:00
|
|
|
}
|
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2004-03-30 19:18:14 +00:00
|
|
|
void ControlDocument::saveAsDefault() const
|
2002-10-09 08:59:02 +00:00
|
|
|
{
|
2004-04-03 08:37:12 +00:00
|
|
|
dispatch_bufferparams(kernel(), params(), LFUN_SAVE_AS_DEFAULT);
|
2002-10-09 08:59:02 +00:00
|
|
|
}
|