some further work on the float lists

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1734 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-03-12 01:43:12 +00:00
parent 223552c65e
commit 46ab079b9f
12 changed files with 117 additions and 114 deletions

View File

@ -1,3 +1,18 @@
2001-03-12 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* buffer.h: add some typedefs
* buffer.C (getLists): use them
(getLists): renamed from getTocList.
add a counter for the different float types and use it in the
generated string.
(getLists): use the same counter for the NEW_INSETS and the "non"
NEW_INSETS
* lyx_cb.h: remove unused items, includes, using etc.
* ShareContainer.h: remove some commented code, add more comments
and "documentation".
2001-03-11 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* buffer.C (getTocList): make the list also when NEW_INSETS is

View File

@ -9,7 +9,13 @@
#include <boost/utility.hpp>
#include <boost/smart_ptr.hpp>
///
/// Share objects between several users.
/**
This class can be used to reduce memory consuption when you have a lot
of equal objects used all over you code.
\author Lars Gullik Bjønnes
*/
template<class Share>
class ShareContainer : public noncopyable {
public:
@ -17,7 +23,7 @@ public:
typedef std::vector<boost::shared_ptr<Share> > Params;
///
typedef typename Params::value_type value_type;
///
/// Return a shared_ptr that points to a element equal to ps.
value_type
get(Share const & ps) const {
// First see if we already have this ps in the container
@ -34,18 +40,18 @@ public:
// some (one) unique elemements some times
// but we should gain a lot in speed.
clean();
//std::sort(params.rbegin(), params.rend(), comp());
} else {
// yes we have it already
tmp = *it;
// move it forward
// move it forward - optimization
// makes the next find faster.
if (it != params.begin())
swap(*it, *(it - 1));
}
return tmp;
}
private:
///
/// A functor returning true if the elements are equal.
struct isEqual {
isEqual(Share const & s) : p_(s) {}
bool operator()(value_type const & p1) const {
@ -54,32 +60,26 @@ private:
private:
Share const & p_;
};
///
//struct comp {
// int operator()(value_type const & p1,
// value_type const & p2) const {
// return p1.use_count() < p2.use_count();
// }
//};
///
/// A functor returning true if the element is unque.
struct isUnique {
bool operator()(value_type const & p) const {
return p.unique();
}
};
///
/** Remove all unique items.
This removes all elements from params that is only referenced
from the private container. This can be considered a memory
optimizaton.
*/
void clean() const {
// Remove all unique items. (i.e. entries that only
// exists in the conatainer and does not have a
// corresponding paragrah.
Params::iterator it = std::remove_if(params.begin(),
params.end(),
isUnique());
params.erase(it, params.end());
}
///
/// The actual container.
mutable Params params;
};
#endif

View File

@ -3599,14 +3599,10 @@ vector<string> const Buffer::getLabelList()
}
map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
Buffer::Lists const Buffer::getLists() const
{
#ifndef NEW_INSETS
int figs = 0;
int tables = 0;
int algs = 0;
#endif
map<string, vector<TocItem> > l;
map<string, int> count;
Lists l;
LyXParagraph * par = paragraph;
while (par) {
#ifndef NEW_INSETS
@ -3622,11 +3618,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
case LyXParagraph::FIG:
case LyXParagraph::WIDE_FIG:
{
tmp.str = tostr(++figs) + ". "
count["figs"]++;
tmp.str = tostr(count["figs"]) + ". "
+ tmp.str;
map<string, vector<TocItem> >::iterator it = l.find("LOF");
Lists::iterator it = l.find("LOF");
if (it == l.end()) {
vector<TocItem> vti;
SingleList vti;
vti.push_back(tmp);
l["LOF"] = vti;
} else {
@ -3638,11 +3635,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
case LyXParagraph::TAB:
case LyXParagraph::WIDE_TAB:
{
tmp.str = tostr(++tables) + ". "
count["tables"]++;
tmp.str = tostr(count["tables"]) + ". "
+ tmp.str;
map<string, vector<TocItem> >::iterator it = l.find("LOT");
Lists::iterator it = l.find("LOT");
if (it == l.end()) {
vector<TocItem> vti;
SingleList vti;
vti.push_back(tmp);
l["LOT"] = vti;
} else {
@ -3653,11 +3651,12 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
case LyXParagraph::ALGORITHM:
{
tmp.str = tostr(++algs) + ". "
count["algs"]++;
tmp.str = tostr(count["algs"]) + ". "
+ tmp.str;
map<string, vector<TocItem> >::iterator it = l.find("LOA");
Lists::iterator it = l.find("LOA");
if (it == l.end()) {
vector<TocItem> vti;
SingleList vti;
vti.push_back(tmp);
l["LOA"] = vti;
} else {
@ -3686,9 +3685,9 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
labeltype -
textclasslist.TextClass(params.textclass).maxcounter());
tmp.str = par->String(this, true);
map<string, vector<TocItem> >::iterator it = l.find("TOC");
Lists::iterator it = l.find("TOC");
if (it == l.end()) {
vector<TocItem> vti;
SingleList vti;
vti.push_back(tmp);
l["TOC"] = vti;
} else {
@ -3698,6 +3697,7 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
#ifdef NEW_INSETS
// For each paragrph, traverse its insets and look for
// FLOAT_CODE
LyXParagraph::inset_iterator it =
par->inset_iterator_begin();
LyXParagraph::inset_iterator end =
@ -3712,21 +3712,22 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
InsetFloat * il =
static_cast<InsetFloat*>(*it);
//lyxerr << "Found a float!" << endl;
string const type = il->type();
// Now find the caption in the float...
// We now tranverse the paragraphs of
// the inset...
LyXParagraph * tmp = il->inset->par;
while (tmp) {
if (tmp->layout == cap) {
count[type]++;
TocItem ti;
ti.par = tmp;
ti.depth = 0;
ti.str = tmp->String(this, false);
map<string, vector<TocItem> >::iterator it = l.find(type);
ti.str = tostr(count[type]) + ". " + tmp->String(this, false);
Lists::iterator it = l.find(type);
if (it == l.end()) {
vector<TocItem> vti;
SingleList vti;
vti.push_back(ti);
l[type] = vti;
} else {
@ -3735,7 +3736,6 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
}
tmp = tmp->next();
}
}
}
} else {
@ -3755,7 +3755,7 @@ map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
// This is also a buffer property (ale)
vector<pair<string,string> > const Buffer::getBibkeyList()
vector<pair<string, string> > const Buffer::getBibkeyList()
{
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990412]

View File

@ -273,7 +273,11 @@ public:
string str;
};
///
std::map<string, std::vector<TocItem> > const getTocList() const;
typedef std::vector<TocItem> SingleList;
///
typedef std::map<string, SingleList> Lists;
///
Lists const getLists() const;
///
std::vector<string> const getLabelList();

View File

@ -1,3 +1,11 @@
2001-03-12 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* FormToc.h: use Buffer::typedef
* Menubar_pimpl.C (add_toc): use the Buffer::typedefs
* FormToc.C (build): ditto
(updateToc): ditto
2001-03-11 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* FormToc.C (build): implement for dynamic number of lists

View File

@ -71,11 +71,9 @@ void FormToc::build()
fl_addto_choice(dialog_->choice_toc_type,
_(" TOC | LOF | LOT | LOA "));
#else
map<string, vector<Buffer::TocItem> > tmp =
lv_->view()->buffer()->getTocList();
string types;
map<string, vector<Buffer::TocItem> >::const_iterator cit = tmp.begin();
map<string, vector<Buffer::TocItem> >::const_iterator end = tmp.end();
Buffer::Lists const tmp = lv_->view()->buffer()->getLists();
Buffer::Lists::const_iterator cit = tmp.begin();
Buffer::Lists::const_iterator end = tmp.end();
for (; cit != end; ++cit) {
fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
}
@ -174,13 +172,12 @@ void FormToc::updateToc()
return;
}
map<string, vector<Buffer::TocItem> > tmp =
lv_->view()->buffer()->getTocList();
//int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
string type = fl_get_choice_item_text(dialog_->choice_toc_type,
fl_get_choice(dialog_->choice_toc_type));
Buffer::Lists tmp = lv_->view()->buffer()->getLists();
string const type =
fl_get_choice_item_text(dialog_->choice_toc_type,
fl_get_choice(dialog_->choice_toc_type));
map<string, vector<Buffer::TocItem> >::iterator it = tmp.find(type);
Buffer::Lists::iterator it = tmp.find(type);
if (it != tmp.end()) {
// Check if all elements are the same.
@ -209,8 +206,8 @@ void FormToc::updateToc()
fl_clear_browser(dialog_->browser_toc);
vector<Buffer::TocItem>::const_iterator cit = toclist.begin();
vector<Buffer::TocItem>::const_iterator end = toclist.end();
Buffer::SingleList::const_iterator cit = toclist.begin();
Buffer::SingleList::const_iterator end = toclist.end();
for (; cit != end; ++cit) {
string const line = string(4 * cit->depth, ' ') + cit->str;

View File

@ -50,7 +50,7 @@ private:
/// Real GUI implementation.
FD_form_toc * dialog_;
///
std::vector<Buffer::TocItem> toclist;
Buffer::SingleList toclist;
};
#endif

View File

@ -361,24 +361,21 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
toc_list[0], 0, toc_list[0].size(), 0);
#else
#warning Fix Me! (Lgb)
map<string, vector<Buffer::TocItem> > toc_list =
owner_->buffer()->getTocList();
map<string, vector<Buffer::TocItem> >::const_iterator cit =
toc_list.begin();
map<string, vector<Buffer::TocItem> >::const_iterator end =
toc_list.end();
Buffer::Lists toc_list = owner_->buffer()->getLists();
Buffer::Lists::const_iterator cit = toc_list.begin();
Buffer::Lists::const_iterator end = toc_list.end();
for (; cit != end; ++cit) {
// Handle this elsewhere
if (cit->first == "TOC") continue;
int menu2 = get_new_submenu(smn, win);
vector<Buffer::TocItem>::const_iterator ccit =
cit->second.begin();
vector<Buffer::TocItem>::const_iterator eend =
cit->second.end();
Buffer::SingleList::const_iterator ccit = cit->second.begin();
Buffer::SingleList::const_iterator eend = cit->second.end();
for (; ccit != eend; ++ccit) {
int const action = lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH, tostr(ccit->par->id()));
int const action =
lyxaction
.getPseudoAction(LFUN_GOTO_PARAGRAPH,
tostr(ccit->par->id()));
string label = fixlabel(ccit->str);
label = limit_string_length(label);
label += "%x" + tostr(action + action_offset);

View File

@ -1,3 +1,7 @@
2001-03-12 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* insettoc.C (Ascii): use the Buffer typedefs
2001-03-11 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* insettoc.C (Ascii): implement for dynamic number of lists

View File

@ -84,15 +84,12 @@ int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
else
type = "LOT";
map<string, vector<Buffer::TocItem> > const toc_list =
buffer->getTocList();
map<string, vector<Buffer::TocItem> >::const_iterator cit =
Buffer::Lists const toc_list = buffer->getLists();
Buffer::Lists::const_iterator cit =
toc_list.find(type);
if (cit != toc_list.end()) {
vector<Buffer::TocItem>::const_iterator ccit =
cit->second.begin();
vector<Buffer::TocItem>::const_iterator end =
cit->second.end();
Buffer::SingleList::const_iterator ccit = cit->second.begin();
Buffer::SingleList::const_iterator end = cit->second.end();
for (; ccit != end; ++ccit)
os << string(4 * ccit->depth, ' ')
<< ccit->str << endl;

View File

@ -21,9 +21,7 @@
#include "lyx_cb.h"
#include "insets/insetlabel.h"
#include "insets/figinset.h"
#include "lyxfunc.h"
#include "minibuffer.h"
#include "combox.h"
#include "bufferlist.h"
#include "frontends/FileDialog.h"
#include "lyx_gui_misc.h"
@ -37,37 +35,24 @@
#include "lyxrc.h"
#include "lyxtext.h"
using std::vector;
using std::ifstream;
using std::copy;
using std::back_inserter;
using std::endl;
using std::cout;
using std::ios;
using std::back_inserter;
using std::istream_iterator;
using std::pair;
using std::make_pair;
using std::vector;
using std::sort;
using std::equal;
extern BufferList bufferlist;
extern void show_symbols_form();
extern FD_form_figure * fd_form_figure;
extern BufferView * current_view; // called too many times in this file...
extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
extern void MenuSendto();
// this should be static, but I need it in buffer.C
bool quitting; // flag, that we are quitting the program
extern bool finished; // all cleanup done just let it run through now.
char ascii_type; /* for selection notify callbacks */
bool scrolling = false;
/*
This is the inset locking stuff needed for mathed --------------------
@ -179,15 +164,21 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
if (filename.empty()) {
FileDialog fileDlg(bv->owner(), _("Choose a filename to save document as"),
FileDialog fileDlg(bv->owner(),
_("Choose a filename to save document as"),
LFUN_WRITEAS,
make_pair(string(_("Documents")), string(lyxrc.document_path)),
make_pair(string(_("Templates")), string(lyxrc.template_path)));
make_pair(string(_("Documents")),
string(lyxrc.document_path)),
make_pair(string(_("Templates")),
string(lyxrc.template_path)));
if (!IsLyXFilename(fname))
fname += ".lyx";
FileDialog::Result result = fileDlg.Select(OnlyPath(fname), _("*.lyx|LyX Documents (*.lyx)"), OnlyFilename(fname));
FileDialog::Result result =
fileDlg.Select(OnlyPath(fname),
_("*.lyx|LyX Documents (*.lyx)"),
OnlyFilename(fname));
if (result.first == FileDialog::Later)
return false;
@ -204,7 +195,6 @@ bool WriteAs(BufferView * bv, Buffer * buffer, string const & filename)
} else
fname = filename;
// Same name as we have already?
if (!buffer->isUnnamed() && fname == oldname) {
if (!AskQuestion(_("Same name as document already has:"),
@ -670,13 +660,15 @@ void FigureApplyCB(FL_OBJECT *, long)
}
extern "C" void FigureCancelCB(FL_OBJECT *, long)
extern "C"
void FigureCancelCB(FL_OBJECT *, long)
{
fl_hide_form(fd_form_figure->form_figure);
}
extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
extern "C"
void FigureOKCB(FL_OBJECT * ob, long data)
{
FigureApplyCB(ob, data);
FigureCancelCB(ob, data);

View File

@ -3,21 +3,13 @@
#define LYX_CB_H
#include "LString.h"
#include "lyxfont.h"
class BufferParams;
class Buffer;
class BufferView;
class Combox;
///
extern bool quitting;
///
extern bool toggleall;
// When still false after reading lyxrc, warn user
//about failing \bind_file command. RVDK_PATCH_5
///
extern bool BindFileSet;
///
void ShowMessage(Buffer const * buf,
string const & msg1,
@ -26,7 +18,8 @@ void ShowMessage(Buffer const * buf,
///
bool MenuWrite(BufferView * bv, Buffer * buffer);
/// write the given file, or ask if no name given
bool WriteAs(BufferView * bv, Buffer * buffer, const string & filename = string());
bool WriteAs(BufferView * bv, Buffer * buffer,
string const & filename = string());
///
int MenuRunChktex(Buffer * buffer);
///
@ -40,14 +33,10 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph);
///
void MenuInsertLabel(BufferView * bv, string const & arg);
///
void MenuLayoutCharacter();
///
void MenuLayoutSave(BufferView * bv);
///
void Figure();
///
void Reconfigure(BufferView * bv);
#endif