2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiToc.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
2007-10-06 20:35:44 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc.h"
|
2007-10-06 20:35:44 +00:00
|
|
|
#include "GuiView.h"
|
|
|
|
#include "DockView.h"
|
|
|
|
#include "TocWidget.h"
|
2007-10-07 18:58:47 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "insets/InsetCommand.h"
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include "TocModel.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "BufferParams.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "debug.h"
|
2007-10-06 20:35:44 +00:00
|
|
|
#include "FloatList.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "gettext.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2007-10-06 20:35:44 +00:00
|
|
|
|
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
|
|
#include "support/convert.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::endl;
|
2007-10-06 20:35:44 +00:00
|
|
|
using std::string;
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
2007-10-19 17:22:55 +00:00
|
|
|
: DockView(parent, "toc", area, flags), params_(TOC_CODE)
|
2007-10-08 20:14:58 +00:00
|
|
|
{
|
|
|
|
widget_ = new TocWidget(*this);
|
|
|
|
setWidget(widget_);
|
|
|
|
setWindowTitle(widget_->windowTitle());
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-10-09 09:29:27 +00:00
|
|
|
GuiToc::~GuiToc()
|
|
|
|
{
|
|
|
|
delete widget_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
int GuiToc::getTocDepth(int type)
|
2006-11-25 22:16:22 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return 0;
|
2007-03-16 14:14:55 +00:00
|
|
|
return toc_models_[type]->modelDepth();
|
2006-11-25 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
QStandardItemModel * GuiToc::tocModel(int type)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-01-03 22:03:26 +00:00
|
|
|
if (toc_models_.empty()) {
|
2007-08-31 05:53:55 +00:00
|
|
|
LYXERR(Debug::GUI) << "GuiToc::tocModel(): no types available " << endl;
|
2006-12-30 14:50:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2007-08-31 05:53:55 +00:00
|
|
|
<< "GuiToc: type " << type
|
2006-04-18 09:57:47 +00:00
|
|
|
<< " toc_models_.size() " << toc_models_.size()
|
|
|
|
<< endl;
|
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
|
|
|
return toc_models_[type];
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
QModelIndex GuiToc::currentIndex(int type) const
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-03-16 14:14:55 +00:00
|
|
|
if (type < 0)
|
2007-03-12 17:03:42 +00:00
|
|
|
return QModelIndex();
|
|
|
|
|
2007-05-15 18:01:22 +00:00
|
|
|
// FIXME: The TocBackend infrastructure is not ready for LOF and LOT
|
|
|
|
// This is because a proper ParConstIterator is not constructed in
|
|
|
|
// InsetCaption::addToToc()
|
|
|
|
if(!canOutline(type))
|
|
|
|
return QModelIndex();
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
return toc_models_[type]->modelIndex(currentTocItem(type));
|
2006-04-19 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiToc::goTo(int type, QModelIndex const & index)
|
2006-04-18 09:57:47 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
if (type < 0 || !index.isValid()
|
2007-03-16 14:14:55 +00:00
|
|
|
|| index.model() != toc_models_[type]) {
|
2007-04-01 10:09:49 +00:00
|
|
|
LYXERR(Debug::GUI)
|
2007-08-31 05:53:55 +00:00
|
|
|
<< "GuiToc::goTo(): QModelIndex is invalid!"
|
2006-04-18 09:57:47 +00:00
|
|
|
<< endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-22 18:48:28 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
|
2007-03-12 17:03:42 +00:00
|
|
|
|
2007-03-16 14:14:55 +00:00
|
|
|
TocIterator const it = toc_models_[type]->tocIterator(index);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
string const tmp = convert<string>(it->id());
|
|
|
|
lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::updateView()
|
|
|
|
{
|
2007-10-09 08:06:36 +00:00
|
|
|
widget_->updateView();
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TocList const & GuiToc::tocs() const
|
|
|
|
{
|
2007-10-20 10:03:45 +00:00
|
|
|
return buffer().masterBuffer()->tocBackend().tocs();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
bool GuiToc::initialiseParams(string const & data)
|
2007-04-03 13:07:38 +00:00
|
|
|
{
|
2007-10-07 18:58:47 +00:00
|
|
|
InsetCommandMailer::string2params("toc", data, params_);
|
2007-10-06 20:35:44 +00:00
|
|
|
|
|
|
|
types_.clear();
|
|
|
|
type_names_.clear();
|
2007-10-09 08:06:36 +00:00
|
|
|
toc_models_.clear();
|
2007-10-20 10:03:45 +00:00
|
|
|
TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
|
2007-10-06 20:35:44 +00:00
|
|
|
TocList::const_iterator it = tocs.begin();
|
|
|
|
TocList::const_iterator end = tocs.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
types_.push_back(it->first);
|
|
|
|
type_names_.push_back(guiName(it->first));
|
2007-10-09 08:06:36 +00:00
|
|
|
toc_models_.push_back(new TocModel(it->second));
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string selected_type ;
|
2007-10-07 18:58:47 +00:00
|
|
|
if (params_["type"].empty()) //Then plain toc...
|
|
|
|
selected_type = params_.getCmdName();
|
2007-10-06 20:35:44 +00:00
|
|
|
else
|
2007-10-07 18:58:47 +00:00
|
|
|
selected_type = to_ascii(params_["type"]);
|
2007-10-06 20:35:44 +00:00
|
|
|
selected_type_ = -1;
|
|
|
|
for (size_t i = 0; i != types_.size(); ++i) {
|
|
|
|
if (selected_type == types_[i]) {
|
|
|
|
selected_type_ = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:06:36 +00:00
|
|
|
modelReset();
|
2007-04-03 13:07:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
bool GuiToc::canOutline(int type) const
|
2006-03-29 16:57:47 +00:00
|
|
|
{
|
2007-10-06 20:35:44 +00:00
|
|
|
return types_[type] == "tableofcontents";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineUp()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_UP));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineDown()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineIn()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_IN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::outlineOut()
|
|
|
|
{
|
|
|
|
dispatch(FuncRequest(LFUN_OUTLINE_OUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiToc::updateBackend()
|
|
|
|
{
|
2007-10-20 10:03:45 +00:00
|
|
|
buffer().masterBuffer()->tocBackend().update();
|
2007-10-06 20:35:44 +00:00
|
|
|
buffer().structureChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TocIterator GuiToc::currentTocItem(int type) const
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(bufferview());
|
|
|
|
ParConstIterator it(bufferview()->cursor());
|
2007-10-20 10:03:45 +00:00
|
|
|
return buffer().masterBuffer()->tocBackend().item(types_[type], it);
|
2007-10-06 20:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring GuiToc::guiName(string const & type) const
|
|
|
|
{
|
|
|
|
if (type == "tableofcontents")
|
|
|
|
return _("Table of Contents");
|
|
|
|
|
|
|
|
FloatList const & floats = buffer().params().getTextClass().floats();
|
|
|
|
if (floats.typeExist(type))
|
|
|
|
return _(floats.getType(type).listName());
|
|
|
|
|
|
|
|
return _(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 18:58:47 +00:00
|
|
|
void GuiToc::dispatchParams()
|
|
|
|
{
|
|
|
|
string const lfun =
|
|
|
|
InsetCommandMailer::params2string("toc", params_);
|
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:35:44 +00:00
|
|
|
Dialog * createGuiToc(LyXView & lv)
|
|
|
|
{
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiView & guiview = static_cast<GuiView &>(lv);
|
2007-10-06 20:35:44 +00:00
|
|
|
#ifdef Q_WS_MACX
|
|
|
|
// On Mac show as a drawer at the right
|
2007-10-08 20:14:58 +00:00
|
|
|
return new GuiToc(guiview, Qt::RightDockWidgetArea, Qt::Drawer);
|
2007-10-06 20:35:44 +00:00
|
|
|
#else
|
2007-10-08 20:14:58 +00:00
|
|
|
return new GuiToc(guiview);
|
2007-10-06 20:35:44 +00:00
|
|
|
#endif
|
2006-03-29 16:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-03-12 14:23:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiToc_moc.cpp"
|