git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20800 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-06 20:35:44 +00:00
parent 64e0e5663b
commit e117f67786
7 changed files with 183 additions and 266 deletions

View File

@ -1,145 +0,0 @@
/**
* \file ControlToc.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "ControlToc.h"
#include "Buffer.h"
#include "BufferView.h"
#include "BufferParams.h"
#include "debug.h"
#include "FloatList.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "frontends/LyXView.h"
#include "support/convert.h"
using std::string;
namespace lyx {
namespace frontend {
ControlToc::ControlToc(Dialog & d)
: ControlCommand(d, "toc")
{
}
TocList const & ControlToc::tocs() const
{
return buffer().getMasterBuffer()->tocBackend().tocs();
}
bool ControlToc::initialiseParams(string const & data)
{
if (!ControlCommand::initialiseParams(data))
return false;
types_.clear();
type_names_.clear();
TocList const & tocs = buffer().getMasterBuffer()->
tocBackend().tocs();
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(getGuiName(it->first));
}
string selected_type ;
if(params()["type"].empty()) //Then plain toc...
selected_type = params().getCmdName();
else
selected_type = to_ascii(params()["type"]);
selected_type_ = -1;
for (size_t i = 0; i != types_.size(); ++i) {
if (selected_type == types_[i]) {
selected_type_ = i;
break;
}
}
return true;
}
void ControlToc::goTo(TocItem const & item)
{
string const tmp = convert<string>(item.id());
lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
bool ControlToc::canOutline(size_t type) const
{
return types_[type] == "tableofcontents";
}
void ControlToc::outlineUp()
{
dispatch(FuncRequest(LFUN_OUTLINE_UP));
}
void ControlToc::outlineDown()
{
dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
}
void ControlToc::outlineIn()
{
dispatch(FuncRequest(LFUN_OUTLINE_IN));
}
void ControlToc::outlineOut()
{
dispatch(FuncRequest(LFUN_OUTLINE_OUT));
}
void ControlToc::updateBackend()
{
buffer().getMasterBuffer()->tocBackend().update();
buffer().structureChanged();
}
TocIterator const ControlToc::getCurrentTocItem(size_t type) const
{
BOOST_ASSERT(bufferview());
ParConstIterator it(bufferview()->cursor());
Buffer const * master = buffer().getMasterBuffer();
return master->tocBackend().item(types_[type], it);
}
docstring const ControlToc::getGuiName(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());
else
return _(type);
}
} // namespace frontend
} // namespace lyx

View File

@ -1,78 +0,0 @@
// -*- C++ -*-
/**
* \file ControlToc.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#ifndef CONTROLTOC_H
#define CONTROLTOC_H
#include "ControlCommand.h"
#include "TocBackend.h"
#include <vector>
namespace lyx {
namespace frontend {
/** A controller for TOC dialogs.
*/
class ControlToc : public ControlCommand {
public:
///
ControlToc(Dialog &);
///
virtual ~ControlToc() {}
/// \c ControlCommand inherited method.
virtual bool initialiseParams(std::string const & data);
///
TocList const & tocs() const;
/// Goto this paragraph id
void goTo(TocItem const &);
/// Return the list of types available
std::vector<docstring> const & typeNames() const
{ return type_names_; }
///
int selectedType() { return selected_type_; }
/// Return the first TocItem before the cursor
TocIterator const getCurrentTocItem(size_t type) const;
/// Apply the selected outlining operation
void outlineUp();
///
void outlineDown();
///
void outlineIn();
///
void outlineOut();
/// Test if outlining operation is possible
bool canOutline(size_t type) const;
///
void updateBackend();
private:
std::vector<std::string> types_;
std::vector<docstring> type_names_;
int selected_type_;
/// Return the guiname from a given cmdName of the TOC param
docstring const getGuiName(std::string const & type) const;
};
} // namespace frontend
} // namespace lyx
#endif // CONTROLTOC_H

View File

@ -19,7 +19,6 @@ SOURCEFILES = \
ControlPrefs.cpp \
ControlPrint.cpp \
ControlSearch.cpp \
ControlToc.cpp \
frontend_helpers.cpp
HEADERFILES = \
@ -34,7 +33,6 @@ HEADERFILES = \
ControlPrefs.h \
ControlPrint.h \
ControlSearch.h \
ControlToc.h \
frontend_helpers.h
if MONOLITHIC_CONTROLLERS

View File

@ -29,7 +29,6 @@
#include "GuiPrint.h"
#include "GuiSearch.h"
#include "GuiShowFile.h"
#include "GuiToc.h"
#include "GuiView.h"
#include "TocWidget.h"
#include "GuiURL.h"
@ -116,6 +115,7 @@ Dialog * createGuiSpellchecker(LyXView & lv);
Dialog * createGuiTabularCreate(LyXView & lv);
Dialog * createGuiTabular(LyXView & lv);
Dialog * createGuiTexInfo(LyXView & lv);
Dialog * createGuiToc(LyXView & lv);
Dialog * createGuiThesaurus(LyXView & lv);
Dialog * createGuiURL(LyXView & lv);
Dialog * createGuiVSpace(LyXView & lv);
@ -216,15 +216,8 @@ Dialog * Dialogs::build(string const & name)
if (name == "thesaurus")
return createGuiThesaurus(lyxview_);
#endif
if (name == "toc") {
#ifdef Q_WS_MACX
// On Mac show as a drawer at the right
return new DockView<GuiToc, TocWidget>(guiview, name,
Qt::RightDockWidgetArea, Qt::Drawer);
#else
return new DockView<GuiToc, TocWidget>(guiview, name);
#endif
}
if (name == "toc")
return createGuiToc(lyxview_);
if (name == "url")
return new GuiURLDialog(lyxview_);
if (name == "vspace")

View File

@ -5,6 +5,7 @@
*
* \author John Levon
* \author Abdelrazak Younes
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
@ -12,34 +13,40 @@
#include <config.h>
#include "GuiToc.h"
#include "GuiView.h"
#include "DockView.h"
#include "TocWidget.h"
#include "TocModel.h"
#include "qt_helpers.h"
#include "Buffer.h"
#include "BufferView.h"
#include "BufferParams.h"
#include "debug.h"
#include "FloatList.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "frontends/LyXView.h"
#include "support/convert.h"
#include <algorithm>
using std::endl;
using std::string;
namespace lyx {
namespace frontend {
GuiToc::GuiToc(Dialog & dialog)
: ControlToc(dialog)
: ControlCommand(dialog, "toc")
{
}
bool GuiToc::canOutline(int type) const
{
if (type < 0)
return false;
return ControlToc::canOutline(type);
}
int GuiToc::getTocDepth(int type)
{
if (type < 0)
@ -68,7 +75,7 @@ QStandardItemModel * GuiToc::tocModel(int type)
}
QModelIndex const GuiToc::getCurrentIndex(int type) const
QModelIndex GuiToc::currentIndex(int type) const
{
if (type < 0)
return QModelIndex();
@ -79,7 +86,7 @@ QModelIndex const GuiToc::getCurrentIndex(int type) const
if(!canOutline(type))
return QModelIndex();
return toc_models_[type]->modelIndex(getCurrentTocItem(type));
return toc_models_[type]->modelIndex(currentTocItem(type));
}
@ -99,17 +106,8 @@ void GuiToc::goTo(int type, QModelIndex const & index)
LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
ControlToc::goTo(*it);
}
bool GuiToc::initialiseParams(std::string const & data)
{
if (!ControlToc::initialiseParams(data))
return false;
updateView();
modelReset();
return true;
string const tmp = convert<string>(it->id());
lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
@ -123,6 +121,120 @@ void GuiToc::updateView()
}
TocList const & GuiToc::tocs() const
{
return buffer().getMasterBuffer()->tocBackend().tocs();
}
bool GuiToc::initialiseParams(string const & data)
{
if (!ControlCommand::initialiseParams(data))
return false;
updateView();
modelReset();
types_.clear();
type_names_.clear();
TocList const & tocs = buffer().getMasterBuffer()->
tocBackend().tocs();
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));
}
string selected_type ;
if(params()["type"].empty()) //Then plain toc...
selected_type = params().getCmdName();
else
selected_type = to_ascii(params()["type"]);
selected_type_ = -1;
for (size_t i = 0; i != types_.size(); ++i) {
if (selected_type == types_[i]) {
selected_type_ = i;
break;
}
}
return true;
}
bool GuiToc::canOutline(int type) const
{
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()
{
buffer().getMasterBuffer()->tocBackend().update();
buffer().structureChanged();
}
TocIterator GuiToc::currentTocItem(int type) const
{
BOOST_ASSERT(bufferview());
ParConstIterator it(bufferview()->cursor());
Buffer const * master = buffer().getMasterBuffer();
return master->tocBackend().item(types_[type], it);
}
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);
}
Dialog * createGuiToc(LyXView & lv)
{
GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
#ifdef Q_WS_MACX
// On Mac show as a drawer at the right
return new DockView<GuiToc, TocWidget>(guiview, "toc",
Qt::RightDockWidgetArea, Qt::Drawer);
#else
return new DockView<GuiToc, TocWidget>(guiview, "toc");
#endif
}
} // namespace frontend
} // namespace lyx

View File

@ -6,6 +6,7 @@
*
* \author John Levon
* \author Kalle Dalheimer
* \author Angus Leeming
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
@ -14,18 +15,21 @@
#ifndef GUITOC_H
#define GUITOC_H
#include "ControlToc.h"
#include "ControlCommand.h"
#include "TocBackend.h"
#include <QObject>
#include <QStandardItemModel>
#include <QStringListModel>
#include <vector>
namespace lyx {
namespace frontend {
class TocModel;
class GuiToc : public QObject, public ControlToc
class GuiToc : public QObject, public ControlCommand
{
Q_OBJECT
@ -33,16 +37,16 @@ public:
///
GuiToc(Dialog &);
/// \c ControlToc inherited method.
virtual bool initialiseParams(std::string const & data);
///
bool initialiseParams(std::string const & data);
///
void updateView();
///
/// Test if outlining operation is possible
bool canOutline(int type) const;
QStandardItemModel * tocModel(int type);
///
QModelIndex const getCurrentIndex(int type) const;
QModelIndex currentIndex(int type) const;
///
void goTo(int type, QModelIndex const & index);
///
@ -55,8 +59,41 @@ Q_SIGNALS:
void modelReset();
private:
friend class TocWidget;
///
std::vector<TocModel *> toc_models_;
///
TocList const & tocs() const;
/// Return the list of types available
std::vector<docstring> const & typeNames() const
{ return type_names_; }
///
int selectedType() { return selected_type_; }
/// Return the first TocItem before the cursor
TocIterator currentTocItem(int type) const;
/// Apply the selected outlining operation
void outlineUp();
///
void outlineDown();
///
void outlineIn();
///
void outlineOut();
///
void updateBackend();
private:
std::vector<std::string> types_;
std::vector<docstring> type_names_;
int selected_type_;
/// Return the guiname from a given cmdName of the TOC param
docstring guiName(std::string const & type) const;
};
} // namespace frontend

View File

@ -232,7 +232,7 @@ void TocWidget::enableControls(bool enable)
void TocWidget::updateView()
{
LYXERR(Debug::GUI) << "In TocWidget::updateView()" << endl;
select(form_.getCurrentIndex(typeCO->currentIndex()));
select(form_.currentIndex(typeCO->currentIndex()));
}
@ -289,7 +289,7 @@ void TocWidget::setTocModel(size_t type)
LYXERR(Debug::GUI) << "In TocWidget::updateGui()" << endl;
select(form_.getCurrentIndex(typeCO->currentIndex()));
select(form_.currentIndex(typeCO->currentIndex()));
if (toc_model) {
LYXERR(Debug::GUI)