2004-04-29 09:54:59 +00:00
|
|
|
|
/**
|
2007-04-26 04:02:55 +00:00
|
|
|
|
* \file Toolbars.cpp
|
2004-04-29 09:54:59 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2007-06-08 07:58:19 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2004-04-29 09:54:59 +00:00
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-08-14 12:25:21 +00:00
|
|
|
|
#include "frontends/Toolbars.h"
|
|
|
|
|
|
|
|
|
|
#include "frontends/LyXView.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "FuncRequest.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2004-11-09 12:40:34 +00:00
|
|
|
|
#include "gettext.h"
|
2007-08-14 12:25:21 +00:00
|
|
|
|
#include "LyX.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXFunc.h"
|
2007-04-29 19:53:54 +00:00
|
|
|
|
#include "TextClass.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2007-08-14 09:54:59 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
Toolbars::Toolbars(LyXView & owner)
|
|
|
|
|
: owner_(owner),
|
|
|
|
|
layout_(0),
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.
The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory. More importantly, the use of a smart pointer allows modules to be modified on disk and then reloaded while LyX is running, and it will eventually allow the same for layout files.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19756 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-23 16:41:13 +00:00
|
|
|
|
last_textclass_(TextClass_ptr())
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{}
|
|
|
|
|
|
2007-04-19 19:43:15 +00:00
|
|
|
|
#define TurnOnFlag(x) flags |= ToolbarInfo::x
|
|
|
|
|
#define TurnOffFlag(x) flags &= ~ToolbarInfo::x
|
2006-11-02 16:01:36 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
void Toolbars::initFlags(ToolbarInfo & tbinfo)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
|
ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
unsigned int flags = static_cast<unsigned int>(tbinfo.flags);
|
2006-11-08 23:15:25 +00:00
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// Remove default.ui positions. Only when a valid postion is stored
|
2006-11-08 23:15:25 +00:00
|
|
|
|
// in the session file the default.ui value will be overwritten
|
|
|
|
|
unsigned int save = flags;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
TurnOffFlag(TOP);
|
|
|
|
|
TurnOffFlag(BOTTOM);
|
|
|
|
|
TurnOffFlag(RIGHT);
|
|
|
|
|
TurnOffFlag(LEFT);
|
|
|
|
|
|
|
|
|
|
bool valid_location = true;
|
2007-04-21 17:38:43 +00:00
|
|
|
|
// init tbinfo.flags with saved location
|
2006-11-02 16:01:36 +00:00
|
|
|
|
if (info.location == ToolbarSection::ToolbarInfo::TOP)
|
|
|
|
|
TurnOnFlag(TOP);
|
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM)
|
|
|
|
|
TurnOnFlag(BOTTOM);
|
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::RIGHT)
|
|
|
|
|
TurnOnFlag(RIGHT);
|
|
|
|
|
else if (info.location == ToolbarSection::ToolbarInfo::LEFT)
|
|
|
|
|
TurnOnFlag(LEFT);
|
|
|
|
|
else {
|
2006-11-08 23:15:25 +00:00
|
|
|
|
// use setting from default.ui
|
|
|
|
|
flags = save;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
valid_location = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// invalid location is for a new toolbar that has no saved information,
|
|
|
|
|
// so info.visible is not used for this case.
|
|
|
|
|
if (valid_location) {
|
2007-04-21 17:38:43 +00:00
|
|
|
|
// init tbinfo.flags with saved visibility,
|
2006-11-02 16:01:36 +00:00
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
|
TurnOffFlag(OFF);
|
|
|
|
|
TurnOffFlag(AUTO);
|
|
|
|
|
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
|
|
|
|
TurnOnFlag(ON);
|
|
|
|
|
else if (info.state == ToolbarSection::ToolbarInfo::OFF)
|
|
|
|
|
TurnOnFlag(OFF);
|
|
|
|
|
else
|
|
|
|
|
TurnOnFlag(AUTO);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
std::cout << "State " << info.state << " FLAGS: " << flags
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< " ON:" << (flags & ToolbarBackend::ON)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
<< " OFF:" << (flags & ToolbarBackend::OFF)
|
2007-05-28 22:27:45 +00:00
|
|
|
|
<< " L:" << (flags & ToolbarBackend::LEFT)
|
|
|
|
|
<< " R:" << (flags & ToolbarBackend::RIGHT)
|
|
|
|
|
<< " T:" << (flags & ToolbarBackend::TOP)
|
|
|
|
|
<< " B:" << (flags & ToolbarBackend::BOTTOM)
|
|
|
|
|
<< " MA:" << (flags & ToolbarBackend::MATH)
|
|
|
|
|
<< " RE:" << (flags & ToolbarBackend::REVIEW)
|
|
|
|
|
<< " TB:" << (flags & ToolbarBackend::TABLE)
|
|
|
|
|
<< " AU:" << (flags & ToolbarBackend::AUTO)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
<< std::endl;
|
|
|
|
|
*/
|
|
|
|
|
// now set the flags
|
2007-04-21 17:38:43 +00:00
|
|
|
|
tbinfo.flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
void Toolbars::init()
|
|
|
|
|
{
|
|
|
|
|
// extracts the toolbars from the backend
|
2006-11-02 16:01:36 +00:00
|
|
|
|
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
|
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
2007-01-31 02:39:46 +00:00
|
|
|
|
// init flags will also add these toolbars to session if they
|
|
|
|
|
// are not already there (e.g. first run of lyx).
|
|
|
|
|
for (; cit != end; ++cit)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
initFlags(*cit);
|
2007-01-31 02:39:46 +00:00
|
|
|
|
|
|
|
|
|
// add toolbars according the order in session
|
|
|
|
|
ToolbarSection::ToolbarList::const_iterator tb = LyX::ref().session().toolbars().begin();
|
|
|
|
|
ToolbarSection::ToolbarList::const_iterator te = LyX::ref().session().toolbars().end();
|
|
|
|
|
ToolbarSection::ToolbarInfo::Location last_loc = ToolbarSection::ToolbarInfo::NOTSET;
|
|
|
|
|
int last_posx = 0;
|
|
|
|
|
int last_posy = 0;
|
|
|
|
|
for (; tb != te; ++tb) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::INIT) << "Adding " << tb->get<0>() << " at position " << tb->get<1>().posx << " " << tb->get<1>().posy << endl;
|
2007-01-31 02:39:46 +00:00
|
|
|
|
// add toolbar break if posx or posy changes
|
|
|
|
|
bool newline = tb->get<1>().location == last_loc && (
|
|
|
|
|
// if two toolbars at the same location, assume uninitialized and add toolbar break
|
|
|
|
|
(tb->get<1>().posx == last_posx && tb->get<1>().posy == last_posy) ||
|
|
|
|
|
(last_loc == ToolbarSection::ToolbarInfo::TOP && tb->get<1>().posy != last_posy) ||
|
|
|
|
|
(last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->get<1>().posy != last_posy) ||
|
|
|
|
|
(last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->get<1>().posx != last_posx) ||
|
|
|
|
|
(last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->get<1>().posx != last_posx) );
|
|
|
|
|
// find the backend item and add
|
|
|
|
|
for (cit = toolbarbackend.begin(); cit != end; ++cit)
|
|
|
|
|
if (cit->name == tb->get<0>()) {
|
|
|
|
|
add(*cit, newline);
|
|
|
|
|
last_loc = tb->get<1>().location;
|
|
|
|
|
last_posx = tb->get<1>().posx;
|
|
|
|
|
last_posy = tb->get<1>().posy;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-24 07:13:07 +00:00
|
|
|
|
Toolbar * Toolbars::display(string const & name, bool show)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{
|
2006-11-18 20:38:41 +00:00
|
|
|
|
ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
|
ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
if (cit->name == name) {
|
2006-11-18 20:38:41 +00:00
|
|
|
|
unsigned int flags = cit->flags;
|
2007-05-23 22:08:07 +00:00
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
|
TurnOffFlag(OFF);
|
2006-11-18 20:38:41 +00:00
|
|
|
|
TurnOffFlag(AUTO);
|
2007-05-23 22:08:07 +00:00
|
|
|
|
if (show)
|
2006-11-18 20:38:41 +00:00
|
|
|
|
TurnOnFlag(ON);
|
2007-05-23 22:08:07 +00:00
|
|
|
|
else
|
2006-11-18 20:38:41 +00:00
|
|
|
|
TurnOnFlag(OFF);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
2007-08-24 07:13:07 +00:00
|
|
|
|
return displayToolbar(*cit, show);
|
2004-04-29 09:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named "
|
2004-04-29 09:54:59 +00:00
|
|
|
|
<< name << endl;
|
2007-08-24 07:13:07 +00:00
|
|
|
|
return 0;
|
2004-04-29 09:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-07-09 20:33:32 +00:00
|
|
|
|
ToolbarInfo * Toolbars::getToolbarInfo(string const & name)
|
2007-05-28 22:27:45 +00:00
|
|
|
|
{
|
2007-07-09 20:33:32 +00:00
|
|
|
|
return toolbarbackend.getUsedToolbarInfo(name);
|
2006-11-02 18:59:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-06 13:52:31 +00:00
|
|
|
|
void Toolbars::toggleToolbarState(string const & name, bool allowauto)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
{
|
2007-07-09 20:33:32 +00:00
|
|
|
|
ToolbarInfo * tbi = toolbarbackend.getUsedToolbarInfo(name);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
|
2007-07-09 20:33:32 +00:00
|
|
|
|
if (!tbi) {
|
|
|
|
|
LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named "
|
|
|
|
|
<< name << endl;
|
|
|
|
|
return;
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
2007-07-09 20:33:32 +00:00
|
|
|
|
|
|
|
|
|
int flags = tbi->flags;
|
|
|
|
|
// off -> on
|
|
|
|
|
if (flags & ToolbarInfo::OFF) {
|
|
|
|
|
TurnOffFlag(OFF);
|
|
|
|
|
TurnOnFlag(ON);
|
|
|
|
|
// auto -> off
|
|
|
|
|
} else if (flags & ToolbarInfo::AUTO) {
|
|
|
|
|
TurnOffFlag(AUTO);
|
|
|
|
|
TurnOnFlag(OFF);
|
|
|
|
|
} else if (allowauto
|
|
|
|
|
&& ((flags & ToolbarInfo::MATH)
|
|
|
|
|
|| (flags & ToolbarInfo::TABLE)
|
|
|
|
|
|| (flags & ToolbarInfo::REVIEW))) {
|
|
|
|
|
// for math etc, toggle from on -> auto
|
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
|
TurnOnFlag(AUTO);
|
|
|
|
|
} else {
|
|
|
|
|
// for others, toggle from on -> off
|
|
|
|
|
TurnOffFlag(ON);
|
|
|
|
|
TurnOnFlag(OFF);
|
|
|
|
|
}
|
|
|
|
|
tbi->flags = static_cast<ToolbarInfo::Flags>(flags);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
#undef TurnOnFlag
|
|
|
|
|
#undef TurnOffFlag
|
|
|
|
|
|
|
|
|
|
|
2006-10-29 22:50:24 +00:00
|
|
|
|
void Toolbars::update(bool in_math, bool in_table, bool review)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
// extracts the toolbars from the backend
|
|
|
|
|
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
|
|
|
|
|
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
|
|
|
|
|
|
|
|
|
|
for (; cit != end; ++cit) {
|
2007-04-19 19:43:15 +00:00
|
|
|
|
if (cit->flags & ToolbarInfo::ON)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
displayToolbar(*cit, true);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if (cit->flags & ToolbarInfo::OFF)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
displayToolbar(*cit, false);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH))
|
2004-04-29 09:54:59 +00:00
|
|
|
|
displayToolbar(*cit, in_math);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE))
|
2004-04-29 09:54:59 +00:00
|
|
|
|
displayToolbar(*cit, in_table);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW))
|
2006-10-29 22:50:24 +00:00
|
|
|
|
displayToolbar(*cit, review);
|
2004-04-29 09:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-23 22:08:07 +00:00
|
|
|
|
bool Toolbars::visible(string const & name) const
|
|
|
|
|
{
|
|
|
|
|
std::map<string, ToolbarPtr>::const_iterator it =
|
|
|
|
|
toolbars_.find(name);
|
|
|
|
|
if (it == toolbars_.end())
|
|
|
|
|
return false;
|
|
|
|
|
return it->second.get()->isVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-02 16:01:36 +00:00
|
|
|
|
void Toolbars::saveToolbarInfo()
|
|
|
|
|
{
|
|
|
|
|
ToolbarSection & tb = LyX::ref().session().toolbars();
|
|
|
|
|
|
|
|
|
|
for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
|
|
|
|
|
cit != toolbarbackend.end(); ++cit) {
|
|
|
|
|
ToolbarsMap::iterator it = toolbars_.find(cit->name);
|
|
|
|
|
BOOST_ASSERT(it != toolbars_.end());
|
|
|
|
|
// get toolbar info from session.
|
|
|
|
|
ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
if (cit->flags & ToolbarInfo::ON)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::ON;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if (cit->flags & ToolbarInfo::OFF)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::OFF;
|
2007-04-19 19:43:15 +00:00
|
|
|
|
else if (cit->flags & ToolbarInfo::AUTO)
|
2006-11-02 16:01:36 +00:00
|
|
|
|
info.state = ToolbarSection::ToolbarInfo::AUTO;
|
|
|
|
|
// save other information
|
|
|
|
|
// if auto, frontend should *not* set on/off
|
|
|
|
|
it->second->saveInfo(info);
|
|
|
|
|
// maybe it is useful to update flags with real status. I do not know
|
|
|
|
|
/*
|
2007-04-19 19:43:15 +00:00
|
|
|
|
if (!(cit->flags & ToolbarInfo::AUTO)) {
|
2006-11-02 16:01:36 +00:00
|
|
|
|
unsigned int flags = static_cast<unsigned int>(cit->flags);
|
2007-04-19 19:43:15 +00:00
|
|
|
|
flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
|
|
|
|
|
flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
if (info.state == ToolbarSection::ToolbarInfo::ON)
|
2007-04-19 19:43:15 +00:00
|
|
|
|
cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
|
2006-11-02 16:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
|
void Toolbars::setLayout(docstring const & layout)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->set(layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.
The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory. More importantly, the use of a smart pointer allows modules to be modified on disk and then reloaded while LyX is running, and it will eventually allow the same for layout files.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19756 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-23 16:41:13 +00:00
|
|
|
|
bool Toolbars::updateLayoutList(TextClass_ptr textclass)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{
|
|
|
|
|
// update the layout display
|
|
|
|
|
if (last_textclass_ != textclass) {
|
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->update();
|
|
|
|
|
last_textclass_ = textclass;
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::openLayoutList()
|
|
|
|
|
{
|
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::clearLayoutList()
|
|
|
|
|
{
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.
The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory. More importantly, the use of a smart pointer allows modules to be modified on disk and then reloaded while LyX is running, and it will eventually allow the same for layout files.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19756 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-23 16:41:13 +00:00
|
|
|
|
last_textclass_ = TextClass_ptr();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
void Toolbars::add(ToolbarInfo const & tbinfo, bool newline)
|
2004-04-29 09:54:59 +00:00
|
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
|
ToolbarPtr tb_ptr = owner_.makeToolbar(tbinfo, newline);
|
|
|
|
|
toolbars_[tbinfo.name] = tb_ptr;
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
2007-04-21 17:38:43 +00:00
|
|
|
|
if (tbinfo.flags & ToolbarInfo::ON)
|
2006-10-31 13:59:22 +00:00
|
|
|
|
tb_ptr->show(false);
|
|
|
|
|
else
|
|
|
|
|
tb_ptr->hide(false);
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
|
if (tb_ptr->layout())
|
|
|
|
|
layout_ = tb_ptr->layout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-24 07:13:07 +00:00
|
|
|
|
Toolbar * Toolbars::displayToolbar(ToolbarInfo const & tbinfo,
|
2004-04-29 09:54:59 +00:00
|
|
|
|
bool show_it)
|
|
|
|
|
{
|
2007-04-21 17:38:43 +00:00
|
|
|
|
ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
|
2004-04-29 09:54:59 +00:00
|
|
|
|
BOOST_ASSERT(it != toolbars_.end());
|
|
|
|
|
|
|
|
|
|
if (show_it)
|
|
|
|
|
it->second->show(true);
|
|
|
|
|
else
|
|
|
|
|
it->second->hide(true);
|
2007-08-24 07:13:07 +00:00
|
|
|
|
|
|
|
|
|
return it->second.get();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbars::update()
|
|
|
|
|
{
|
|
|
|
|
ToolbarsMap::const_iterator it = toolbars_.begin();
|
|
|
|
|
ToolbarsMap::const_iterator const end = toolbars_.end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
it->second->update();
|
|
|
|
|
|
2006-10-11 17:24:46 +00:00
|
|
|
|
bool const enable =
|
|
|
|
|
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
|
|
if (layout_)
|
|
|
|
|
layout_->setEnabled(enable);
|
|
|
|
|
}
|
2004-11-09 12:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
|
void layoutSelected(LyXView & lv, docstring const & name)
|
2004-11-09 12:40:34 +00:00
|
|
|
|
{
|
2007-04-29 19:53:54 +00:00
|
|
|
|
TextClass const & tc = lv.buffer()->params().getTextClass();
|
2004-11-09 12:40:34 +00:00
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
|
TextClass::const_iterator it = tc.begin();
|
|
|
|
|
TextClass::const_iterator const end = tc.end();
|
2004-11-09 12:40:34 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2007-07-11 13:39:08 +00:00
|
|
|
|
docstring const & itname = (*it)->name();
|
|
|
|
|
if (translateIfPossible(itname) == name) {
|
2004-11-26 14:52:54 +00:00
|
|
|
|
FuncRequest const func(LFUN_LAYOUT, itname,
|
2006-11-09 14:56:57 +00:00
|
|
|
|
FuncRequest::TOOLBAR);
|
2006-10-11 17:24:46 +00:00
|
|
|
|
lv.dispatch(func);
|
2004-11-09 12:40:34 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-11-26 14:52:54 +00:00
|
|
|
|
lyxerr << "ERROR (layoutSelected): layout not found!"
|
2004-11-09 12:40:34 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-08-14 09:54:59 +00:00
|
|
|
|
} // namespace frontend
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|