- new pimpled TocBackend member and associated accessors.

* toc.[Ch]: delete all toc related methods except outline.

* TocBackend:
  - goTo(): deleted, this gets rid of the LyXView dependency
  - made all accessors const.

* ControlToc: 
  - rework the controller to work exclusively with TocBackend.
  - goTo(): now call LyXView::dispatch() directly

all other files: update with the TocBackend or ControlToc API changes.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15852 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-11-11 00:35:14 +00:00
parent 46bd598fc5
commit 479e9054db
17 changed files with 102 additions and 200 deletions

View File

@ -35,7 +35,7 @@
#include "lyx_main.h" // for lastfiles
#include "lyxfunc.h"
#include "lyxlex.h"
#include "toc.h"
#include "TocBackend.h"
#include "ToolbarBackend.h"
#include "support/filetools.h"
@ -633,22 +633,22 @@ void expandCharStyleInsert(Menu & tomenu, Buffer const * buf)
Menu::size_type const max_number_of_items = 25;
void expandToc2(Menu & tomenu,
lyx::toc::Toc const & toc_list,
lyx::toc::Toc::size_type from,
lyx::toc::Toc::size_type to, int depth)
TocBackend::Toc const & toc_list,
TocBackend::Toc::size_type from,
TocBackend::Toc::size_type to, int depth)
{
int shortcut_count = 0;
// check whether depth is smaller than the smallest depth in toc.
int min_depth = 1000;
for (lyx::toc::Toc::size_type i = from; i < to; ++i)
for (TocBackend::Toc::size_type i = from; i < to; ++i)
min_depth = std::min(min_depth, toc_list[i].depth());
if (min_depth > depth)
depth = min_depth;
if (to - from <= max_number_of_items) {
for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
for (TocBackend::Toc::size_type i = from; i < to; ++i) {
docstring label(4 * max(0, toc_list[i].depth() - depth), char_type(' '));
label += limit_string_length(toc_list[i].str());
if (toc_list[i].depth() == depth
@ -660,9 +660,9 @@ void expandToc2(Menu & tomenu,
FuncRequest(toc_list[i].action())));
}
} else {
lyx::toc::Toc::size_type pos = from;
TocBackend::Toc::size_type pos = from;
while (pos < to) {
lyx::toc::Toc::size_type new_pos = pos + 1;
TocBackend::Toc::size_type new_pos = pos + 1;
while (new_pos < to &&
toc_list[new_pos].depth() > depth)
++new_pos;
@ -705,18 +705,18 @@ void expandToc(Menu & tomenu, Buffer const * buf)
}
FloatList const & floatlist = buf->params().getLyXTextClass().floats();
lyx::toc::TocList const & toc_list = lyx::toc::getTocList(*buf);
lyx::toc::TocList::const_iterator cit = toc_list.begin();
lyx::toc::TocList::const_iterator end = toc_list.end();
TocBackend::TocList const & toc_list = buf->tocBackend().tocs();
TocBackend::TocList::const_iterator cit = toc_list.begin();
TocBackend::TocList::const_iterator end = toc_list.end();
for (; cit != end; ++cit) {
// Handle this later
if (cit->first == "TOC")
if (cit->first == "tableofcontents")
continue;
// All the rest is for floats
auto_ptr<Menu> menu(new Menu);
lyx::toc::Toc::const_iterator ccit = cit->second.begin();
lyx::toc::Toc::const_iterator eend = cit->second.end();
TocBackend::Toc::const_iterator ccit = cit->second.begin();
TocBackend::Toc::const_iterator eend = cit->second.end();
for (; ccit != eend; ++ccit) {
docstring const label = limit_string_length(ccit->str());
menu->add(MenuItem(MenuItem::Command,
@ -730,7 +730,7 @@ void expandToc(Menu & tomenu, Buffer const * buf)
}
// Handle normal TOC
cit = toc_list.find("TOC");
cit = toc_list.find("tableofcontents");
if (cit == end) {
tomenu.addWithStatusCheck(MenuItem(MenuItem::Command,
_("No Table of contents"),

View File

@ -12,7 +12,7 @@
#include <config.h>
#include "toc.h"
#include "TocBackend.h"
#include "buffer.h"
#include "bufferparams.h"
@ -20,26 +20,19 @@
#include "funcrequest.h"
#include "LyXAction.h"
#include "paragraph.h"
#include "cursor.h"
#include "debug.h"
#include "frontends/LyXView.h"
#include "insets/insetfloat.h"
#include "insets/insetoptarg.h"
#include "insets/insetwrap.h"
#include "support/convert.h"
#include <iostream>
namespace lyx {
using std::vector;
using std::max;
using std::ostream;
using std::string;
using std::endl;
///////////////////////////////////////////////////////////////////////////
@ -108,12 +101,6 @@ docstring const TocBackend::Item::asString() const
}
void TocBackend::Item::goTo(LyXView & lv_) const
{
string const tmp = convert<string>(id());
lv_.dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
FuncRequest TocBackend::Item::action() const
{
return FuncRequest(LFUN_PARAGRAPH_GOTO, convert<string>(id()));
@ -126,7 +113,7 @@ FuncRequest TocBackend::Item::action() const
///////////////////////////////////////////////////////////////////////////
// TocBackend implementation
TocBackend::Toc const & TocBackend::toc(std::string const & type)
TocBackend::Toc const & TocBackend::toc(std::string const & type) const
{
// Is the type already supported?
TocList::const_iterator it = tocs_.find(type);
@ -202,7 +189,7 @@ void TocBackend::update()
if (tocstring.empty())
tocstring = pit->asString(*buffer_, true);
Item const item(pit, toclevel - min_toclevel, tocstring);
tocs_["TOC"].push_back(item);
tocs_["tableofcontents"].push_back(item);
}
}
@ -212,9 +199,10 @@ void TocBackend::update()
}
TocBackend::TocIterator const TocBackend::item(std::string const & type, ParConstIterator const & par_it)
TocBackend::TocIterator const TocBackend::item(
std::string const & type, ParConstIterator const & par_it) const
{
TocList::iterator toclist_it = tocs_.find(type);
TocList::const_iterator toclist_it = tocs_.find(type);
// Is the type supported?
BOOST_ASSERT(toclist_it != tocs_.end());

View File

@ -17,16 +17,17 @@
#define TOC_BACKEND_H
#include <map>
#include <iosfwd>
#include <vector>
#include <string>
#include "pariterator.h"
#include "support/docstream.h"
namespace lyx {
class Buffer;
class LyXView;
class Paragraph;
class FuncRequest;
class LCursor;
@ -63,8 +64,7 @@ public:
docstring const & str() const;
///
docstring const asString() const;
/// set cursor in LyXView to this Item
void goTo(LyXView & lv_) const;
/// the action corresponding to the goTo above
FuncRequest action() const;
@ -98,15 +98,15 @@ public:
///
void update();
///
TocList const & tocs()
TocList const & tocs() const
{ return tocs_; }
///
std::vector<std::string> const & types()
std::vector<std::string> const & types() const
{ return types_; }
///
Toc const & toc(std::string const & type);
Toc const & toc(std::string const & type) const;
/// Return the first Toc Item before the cursor
TocIterator const item(std::string const & type, ParConstIterator const &);
TocIterator const item(std::string const & type, ParConstIterator const &) const;
void asciiTocList(std::string const & type, odocstream & os) const;

View File

@ -47,6 +47,7 @@
#include "pariterator.h"
#include "sgml.h"
#include "texrow.h"
#include "TocBackend.h"
#include "undo.h"
#include "version.h"
@ -192,13 +193,16 @@ public:
///
MacroTable macros;
///
TocBackend toc_backend;
};
Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), file_fully_loaded(false),
inset(params)
filename(file), file_fully_loaded(false), inset(params),
toc_backend(&parent)
{
inset.setAutoBreakRows(true);
lyxvc.buffer(&parent);
@ -326,6 +330,18 @@ TexRow const & Buffer::texrow() const
}
TocBackend & Buffer::tocBackend()
{
return pimpl_->toc_backend;
}
TocBackend const & Buffer::tocBackend() const
{
return pimpl_->toc_backend;
}
string const Buffer::getLatexName(bool const no_path) const
{
string const name = changeExtension(makeLatexName(fileName()), ".tex");

View File

@ -54,6 +54,7 @@ class ParConstIterator;
class ParIterator;
class TeXErrors;
class TexRow;
class TocBackend;
class Undo;
class StableDocIterator;
@ -355,6 +356,11 @@ public:
ErrorList & errorList(std::string const & type);
//@}
//@{
TocBackend & tocBackend();
TocBackend const & tocBackend() const;
//@}
private:
/** Inserts a file into a document
\return \c false if method fails.

View File

@ -32,8 +32,8 @@
#include "pariterator.h"
#include "lyxvc.h"
#include "texrow.h"
#include "TocBackend.h"
#include "vc-backend.h"
#include "toc.h"
#include "frontends/Alert.h"
@ -587,7 +587,7 @@ void updateLabels(Buffer const & buf)
setLabel(buf, it);
}
toc::updateToc(buf);
const_cast<Buffer &>(buf).tocBackend().update();
}

View File

@ -13,10 +13,17 @@
#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 "BufferView.h"
#include "debug.h"
#include "frontends/LyXView.h"
#include "support/convert.h"
using std::vector;
using std::string;
@ -33,15 +40,16 @@ ControlToc::ControlToc(Dialog & d)
{}
void ControlToc::goTo(toc::TocItem const & item)
void ControlToc::goTo(TocBackend::Item const & item)
{
item.goTo(kernel().lyxview());
string const tmp = convert<string>(item.id());
kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
bool ControlToc::canOutline(string const & type)
{
return type == "TOC";
return type == "tableofcontents";
}
@ -71,39 +79,44 @@ void ControlToc::outlineOut()
vector<string> const & ControlToc::getTypes() const
{
return toc::getTypes(kernel().buffer());
return kernel().buffer().tocBackend().types();
}
toc::TocIterator const ControlToc::getCurrentTocItem(
TocBackend::Toc::const_iterator const ControlToc::getCurrentTocItem(
string const & type) const
{
BOOST_ASSERT(kernel().bufferview());
return toc::getCurrentTocItem(kernel().buffer(),
kernel().bufferview()->cursor(), type);
ParConstIterator it(kernel().bufferview()->cursor());
return kernel().buffer().tocBackend().item(type, it);
}
string const ControlToc::getGuiName(string const & type) const
{
if (type == "TOC")
if (type == "tableofcontents")
return lyx::to_utf8(_("Table of Contents"));
FloatList const & floats =
kernel().buffer().params().getLyXTextClass().floats();
if (floats.typeExist(type))
return floats.getType(type).name();
else
return lyx::to_utf8(_(toc::getGuiName(type, kernel().buffer())));
return lyx::to_utf8(_(type));
}
toc::Toc const empty_list;
TocBackend::Toc const empty_list;
toc::Toc const & ControlToc::getContents(string const & type) const
TocBackend::Toc const & ControlToc::getContents(string const & type) const
{
// This shouldn't be possible...
if (!kernel().isBufferAvailable()) {
return empty_list;
}
return toc::getToc(kernel().buffer(), type);
return kernel().buffer().tocBackend().toc(type);
}
} // namespace frontend

View File

@ -14,7 +14,8 @@
#include "ControlCommand.h"
#include "toc.h"
#include "TocBackend.h"
#include <vector>
namespace lyx {
@ -28,7 +29,7 @@ public:
ControlToc(Dialog &);
/// Goto this paragraph id
void goTo(toc::TocItem const &);
void goTo(TocBackend::Item const &);
/// Return the list of types available
std::vector<std::string> const & getTypes() const;
@ -37,11 +38,11 @@ public:
std::string const getGuiName(std::string const & type) const;
/// Return the first TocItem before the cursor
toc::TocIterator const getCurrentTocItem(
TocBackend::Toc::const_iterator const getCurrentTocItem(
std::string const & type) const;
/// Given a type, returns the contents
toc::Toc const & getContents(std::string const & type) const;
TocBackend::Toc const & getContents(std::string const & type) const;
/// Apply the selected outlining operation
void outlineUp();

View File

@ -108,7 +108,7 @@ void QToc::goTo(QModelIndex const & index)
<< "QToc::goTo " << lyx::to_utf8(it->str())
<< endl;
it->goTo(kernel().lyxview());
ControlToc::goTo(*it);
}
@ -127,7 +127,7 @@ void QToc::update()
return;
}
string const & selected_type = toc::getType(params().getCmdName());
string const & selected_type = params().getCmdName();
lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
QString gui_names_;

View File

@ -378,7 +378,7 @@ void InsetFloat::sideways(bool s, BufferParams const & bp)
}
void InsetFloat::addToToc(toc::TocList & toclist, Buffer const & buf) const
void InsetFloat::addToToc(TocBackend::TocList & toclist, Buffer const & buf) const
{
ParConstIterator pit = par_const_iterator_begin(*this);
ParConstIterator end = par_const_iterator_end(*this);
@ -390,7 +390,7 @@ void InsetFloat::addToToc(toc::TocList & toclist, Buffer const & buf) const
docstring const str =
convert<docstring>(toclist[type].size() + 1)
+ ". " + pit->asString(buf, false);
toc::TocItem const item(pit, 0, str);
TocBackend::Item const item(pit, 0, str);
toclist[type].push_back(item);
}
}

View File

@ -14,7 +14,7 @@
#define INSETFLOAT_H
#include "insetcollapsable.h"
#include "toc.h"
#include "TocBackend.h"
#include "mailinset.h"
@ -76,7 +76,7 @@ public:
///
void sideways(bool s, BufferParams const &);
///
void addToToc(toc::TocList &, Buffer const &) const;
void addToToc(TocBackend::TocList &, Buffer const &) const;
///
bool showInsetDialog(BufferView *) const;
///

View File

@ -23,7 +23,7 @@
#include "LaTeXFeatures.h"
#include "lyxlex.h"
#include "metricsinfo.h"
#include "toc.h"
#include "TocBackend.h"
#include "support/lstrings.h"
@ -133,7 +133,7 @@ int InsetFloatList::plaintext(Buffer const & buffer, odocstream & os,
{
os << getScreenLabel(buffer) << "\n\n";
toc::asciiTocList(to_ascii(getParam("type")), buffer, os);
buffer.tocBackend().asciiTocList(to_ascii(getParam("type")), os);
os << "\n";
return 0;

View File

@ -12,11 +12,12 @@
#include "insettoc.h"
#include "buffer.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "gettext.h"
#include "metricsinfo.h"
#include "toc.h"
#include "TocBackend.h"
#include "support/std_ostream.h"
@ -59,7 +60,7 @@ int InsetTOC::plaintext(Buffer const & buffer, odocstream & os,
{
os << getScreenLabel(buffer) << "\n\n";
toc::asciiTocList(lyx::toc::getType(getCmdName()), buffer, os);
buffer.tocBackend().asciiTocList(getCmdName(), os);
os << "\n";
return 0;

View File

@ -224,7 +224,7 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
}
void InsetWrap::addToToc(toc::TocList & toclist, Buffer const & buf) const
void InsetWrap::addToToc(TocBackend::TocList & toclist, Buffer const & buf) const
{
ParConstIterator pit = par_const_iterator_begin(*this);
ParConstIterator end = par_const_iterator_end(*this);
@ -236,7 +236,7 @@ void InsetWrap::addToToc(toc::TocList & toclist, Buffer const & buf) const
docstring const str =
convert<docstring>(toclist[type].size() + 1)
+ ". " + pit->asString(buf, false);
toc::TocItem const item(pit, 0, str);
TocBackend::Item const item(pit, 0, str);
toclist[type].push_back(item);
}
}

View File

@ -13,9 +13,9 @@
#define INSETWRAP_H
#include "insetcollapsable.h"
#include "toc.h"
#include "lyxlength.h"
#include "mailinset.h"
#include "TocBackend.h"
namespace lyx {
@ -64,7 +64,7 @@ public:
///
bool insetAllowed(InsetBase::Code) const;
///
void addToToc(toc::TocList &, Buffer const &) const;
void addToToc(TocBackend::TocList &, Buffer const &) const;
///
bool showInsetDialog(BufferView *) const;
///

View File

@ -16,7 +16,6 @@
#include "buffer.h"
#include "bufferparams.h"
#include "FloatList.h"
#include "funcrequest.h"
#include "lyxtext.h"
#include "LyXAction.h"
@ -26,98 +25,10 @@
#include "debug.h"
#include "undo.h"
#include "support/convert.h"
#include <map>
using std::map;
using std::pair;
using std::make_pair;
using std::vector;
using std::max;
using std::ostream;
using std::string;
using std::endl;
namespace lyx {
namespace toc {
typedef map<Buffer const *, TocBackend> TocMap;
static TocMap toc_backend_;
///////////////////////////////////////////////////////////////////////////
// Interface to toc_backend_
void updateToc(Buffer const & buf)
{
TocMap::iterator it = toc_backend_.find(&buf);
if (it == toc_backend_.end()) {
pair<TocMap::iterator, bool> result
= toc_backend_.insert(make_pair(&buf, TocBackend(&buf)));
if (!result.second)
return;
it = result.first;
}
it->second.update();
}
TocList const & getTocList(Buffer const & buf)
{
return toc_backend_[&buf].tocs();
}
Toc const & getToc(Buffer const & buf, std::string const & type)
{
return toc_backend_[&buf].toc(type);
}
TocIterator const getCurrentTocItem(Buffer const & buf, LCursor const & cur,
std::string const & type)
{
return toc_backend_[&buf].item(type, ParConstIterator(cur));
}
vector<string> const & getTypes(Buffer const & buf)
{
return toc_backend_[&buf].types();
}
void asciiTocList(string const & type, Buffer const & buf, odocstream & os)
{
toc_backend_[&buf].asciiTocList(type, os);
}
///////////////////////////////////////////////////////////////////////////
// Other functions
string const getType(string const & cmdName)
{
// special case
if (cmdName == "tableofcontents")
return "TOC";
else
return cmdName;
}
string const getGuiName(string const & type, Buffer const & buffer)
{
FloatList const & floats =
buffer.params().getLyXTextClass().floats();
if (floats.typeExist(type))
return floats.getType(type).name();
else
return type;
}
void outline(OutlineOp mode, LCursor & cur)
{
recordUndo(cur);

View File

@ -15,45 +15,11 @@
#ifndef TOC_H
#define TOC_H
#include "TocBackend.h"
class LCursor;
namespace lyx {
namespace toc {
typedef TocBackend::Item TocItem;
typedef TocBackend::Toc::const_iterator TocIterator;
typedef TocBackend::Toc Toc;
typedef TocBackend::TocList TocList;
///
void updateToc(Buffer const &);
///
TocList const & getTocList(Buffer const &);
///
Toc const & getToc(Buffer const & buf, std::string const & type);
///
std::vector<std::string> const & getTypes(Buffer const &);
/// Return the first TocItem before the cursor
TocIterator const getCurrentTocItem(Buffer const &, LCursor const &,
std::string const & type);
///
void asciiTocList(std::string const &, Buffer const &, odocstream &);
/** Given the cmdName of the TOC param, returns the type used
by ControlToc::getContents() */
std::string const getType(std::string const & cmdName);
/** Returns the guiname from a given @c type
The localization of the names will be done in the frontends */
std::string const getGuiName(std::string const & type, Buffer const &);
/// the type of outline operation
enum OutlineOp {
Up, // Move this header with text down