]> git.lyx.org Git - features.git/commitdiff
dynamic number of lists
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 11 Mar 2001 18:39:00 +0000 (18:39 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 11 Mar 2001 18:39:00 +0000 (18:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1732 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/CutAndPaste.C
src/CutAndPaste.h
src/buffer.C
src/buffer.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormToc.C
src/frontends/xforms/Menubar_pimpl.C
src/insets/ChangeLog
src/insets/insettoc.C
src/text2.C

index de19ca161057e2b185333402cc0a79cedf856a09..cc74b5eb3158af67d5afdf47e1e36ac61c26d00a 100644 (file)
@@ -1,5 +1,14 @@
 2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
 
+       * buffer.h: remove TocType
+
+       * buffer.C (getTocList): change to return a map<string,
+       vector<TocItem> >, implement for dynamic number of list.
+
+       * CutAndPaste.[Ch] (checkPastePossible): remove unused arg
+       * text2.C (PasteSelection): adjust
+       * CutAndPaste.C (pasteSelection): adjust
+
        * FloatList.C (FloatList): update from the new_insets branch.
        * Floating.[Ch]: ditto
        * LaTeXFeatures.C: ditto
index 6e0c7c117b14acb69750241b878dcebd6f4912c7..82e14306a175e4ebc57bd1b0694a050eaaa96506 100644 (file)
@@ -291,7 +291,7 @@ bool CutAndPaste::copySelection(LyXParagraph * startpar, LyXParagraph * endpar,
 bool CutAndPaste::pasteSelection(LyXParagraph ** par, LyXParagraph ** endpar,
                                 int & pos, char tc)
 {
-    if (!checkPastePossible(*par, pos))
+    if (!checkPastePossible(*par))
        return false;
 
 #ifndef NEW_INSETS
@@ -537,7 +537,7 @@ int CutAndPaste::SwitchLayoutsBetweenClasses(LyXTextClassList::size_type c1,
 }
 
 
-bool CutAndPaste::checkPastePossible(LyXParagraph * par, int)
+bool CutAndPaste::checkPastePossible(LyXParagraph * par)
 {
     if (!buf) return false;
 
index 825b11d210b0a0ff047b64ee1225d33789264906..3835d553fe8969e53c153679350a2ac275f55ed9 100644 (file)
@@ -48,7 +48,7 @@ public:
                                        LyXParagraph * par);
        ///
        static
-       bool checkPastePossible(LyXParagraph *, int pos);
+       bool checkPastePossible(LyXParagraph *);
 };
 
 #endif
index 812da251d5c45be0e19a13bb7c968a02313add78..e1f383d8f3c652d4b5735a0792d16a8837e663ab 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <fstream>
 #include <iomanip>
+#include <map>
 
 #include <cstdlib>
 #include <cmath>
@@ -3598,14 +3599,14 @@ vector<string> const Buffer::getLabelList()
 }
 
 
-vector<vector<Buffer::TocItem> > const Buffer::getTocList() const
+map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
 {
 #ifndef NEW_INSETS
        int figs = 0;
        int tables = 0;
        int algs = 0;
 #endif
-       vector<vector<TocItem> > l(4);
+       map<string, vector<TocItem> > l;
        LyXParagraph * par = paragraph;
        while (par) {
 #ifndef NEW_INSETS
@@ -3620,21 +3621,51 @@ vector<vector<Buffer::TocItem> > const Buffer::getTocList() const
                                switch (par->footnotekind) {
                                case LyXParagraph::FIG:
                                case LyXParagraph::WIDE_FIG:
+                               {
                                        tmp.str = tostr(++figs) + ". "
                                                + tmp.str;
-                                       l[TOC_LOF].push_back(tmp);
+                                       map<string, vector<TocItem> >::iterator it = l.find("LOF");
+                                       if (it == l.end()) {
+                                               vector<TocItem> vti;
+                                               vti.push_back(tmp);
+                                               l["LOF"] = vti;
+                                       } else {
+                                               it->second.push_back(tmp);
+                                       }
                                        break;
+                               }
+                               
                                case LyXParagraph::TAB:
                                case LyXParagraph::WIDE_TAB:
+                               {
                                        tmp.str = tostr(++tables) + ". "
                                                + tmp.str;
-                                       l[TOC_LOT].push_back(tmp);
+                                       map<string, vector<TocItem> >::iterator it = l.find("LOT");
+                                       if (it == l.end()) {
+                                               vector<TocItem> vti;
+                                               vti.push_back(tmp);
+                                               l["LOT"] = vti;
+                                       } else {
+                                               it->second.push_back(tmp);
+                                       }
                                        break;
+                               }
+                               
                                case LyXParagraph::ALGORITHM:
+                               {
                                        tmp.str = tostr(++algs) + ". "
                                                + tmp.str;
-                                       l[TOC_LOA].push_back(tmp);
+                                       map<string, vector<TocItem> >::iterator it = l.find("LOA");
+                                       if (it == l.end()) {
+                                               vector<TocItem> vti;
+                                               vti.push_back(tmp);
+                                               l["LOA"] = vti;
+                                       } else {
+                                               it->second.push_back(tmp);
+                                       }
                                        break;
+                               }
+                               
                                case LyXParagraph::FOOTNOTE:
                                case LyXParagraph::MARGIN:
                                        break;
@@ -3655,8 +3686,29 @@ vector<vector<Buffer::TocItem> > const Buffer::getTocList() const
                                                labeltype - 
                                                textclasslist.TextClass(params.textclass).maxcounter());
                                tmp.str =  par->String(this, true);
-                               l[TOC_TOC].push_back(tmp);
+                               map<string, vector<TocItem> >::iterator it = l.find("TOC");
+                               if (it == l.end()) {
+                                       vector<TocItem> vti;
+                                       vti.push_back(tmp);
+                                       l["TOC"] = vti;
+                               } else {
+                                       it->second.push_back(tmp);
+                               }
                        }
+#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 =
+                               par->inset_iterator_end();
+                       for (; it != end; ++it) {
+                               if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
+                                       lyxerr << "Found a float!" << endl;
+                                       // Now find the caption in the float...
+                               }
+                       }
+#endif
 #ifndef NEW_INSETS
                }
                par = par->next_;
index 9d2a7cbd87c4950d2f84249f95e4dd544308f9b3..4e1eeee2ea97a0f0251331d984b06a2ea8b72303 100644 (file)
@@ -262,7 +262,7 @@ public:
        ///
        string const getIncludeonlyList(char delim = ',');
        ///
-       std::vector<std::pair<string,string> > const getBibkeyList();
+       std::vector<std::pair<string, string> > const getBibkeyList();
        ///
        struct TocItem {
                ///
@@ -272,15 +272,8 @@ public:
                ///
                string str;
        };
-       /// The different content list types.
-       enum TocType {
-               TOC_TOC = 0, ///< Table of Contents
-               TOC_LOF, ///< List of Figures
-               TOC_LOT, ///< List of Tables
-               TOC_LOA ///< List of Algorithms
-       };
        ///
-       std::vector<std::vector<TocItem> > const getTocList() const;
+       std::map<string, std::vector<TocItem> > const getTocList() const;
        ///
        std::vector<string> const getLabelList();
 
index 952461b5af39e6bfd1f5850d0f285fcddcb4fcb2..fd7b79f2a923bd29d526c7c6899b1ec05dd1126a 100644 (file)
@@ -1,3 +1,9 @@
+2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
+
+       * FormToc.C (build): implement for dynamic number of lists
+       (updateToc): ditto
+       * Menubar_pimpl.C (add_toc): ditto
+
 2001-03-07  Edwin Leuven  <leuven@fee.uva.nl>
 
         * added credits:
index 39805699deb26a2d7eae8a897c48c412df793502..baad36d8b74a2e651b061026e4bd146bd399fcde 100644 (file)
@@ -67,9 +67,19 @@ void FormToc::build()
 {
        dialog_ = build_toc();
 
+#if 0
        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();
+       for (; cit != end; ++cit) {
+               fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
+       }
+#endif
        // Don't need to limit size of this dialog
        // (but fixing min size is a GOOD thing).
        // Workaround dumb xforms sizing bug
@@ -84,6 +94,7 @@ void FormToc::build()
 
 void FormToc::update()
 {
+#if 0
        Buffer::TocType type;
 
        if (params.getCmdName() == "tableofcontents" )
@@ -99,13 +110,16 @@ void FormToc::update()
                type = Buffer::TOC_LOT;
        
        fl_set_choice( dialog_->choice_toc_type, type+1 );
-
+#else
+#warning Reimplement (Lgb)
+#endif
        updateToc();
 }
 
 
 void FormToc::updateToc()
 {
+#if 0
        if (!lv_->view()->available()) {
                toclist.clear();
                fl_clear_browser( dialog_->browser_toc );
@@ -150,6 +164,62 @@ void FormToc::updateToc()
 
        fl_set_browser_topline( dialog_->browser_toc, topline );
        fl_select_browser_line( dialog_->browser_toc, line );
+#else
+#warning Fix Me! (Lgb)
+       if (!lv_->view()->available()) {
+               toclist.clear();
+               fl_clear_browser( dialog_->browser_toc );
+               fl_add_browser_line( dialog_->browser_toc,
+                                    _("*** No Document ***"));
+               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));
+
+       map<string, vector<Buffer::TocItem> >::iterator it = tmp.find(type);
+
+       if (it != tmp.end()) {
+               // Check if all elements are the same.
+               if (toclist == it->second) {
+                       return;
+               }
+       } else if (it == tmp.end()) {
+               toclist.clear();
+               fl_clear_browser(dialog_->browser_toc);
+               fl_add_browser_line(dialog_->browser_toc,
+                                   _("*** No Lists ***"));
+               return;
+       }
+       
+       // List has changed. Update browser
+       toclist = it->second;
+
+       static Buffer * buffer = 0;
+       int topline = 0;
+       int line = 0;
+       if (buffer == lv_->view()->buffer()) {
+               topline = fl_get_browser_topline(dialog_->browser_toc);
+               line = fl_get_browser( dialog_->browser_toc );
+       } else
+               buffer = lv_->view()->buffer();
+
+       fl_clear_browser(dialog_->browser_toc);
+
+       vector<Buffer::TocItem>::const_iterator cit = toclist.begin();
+       vector<Buffer::TocItem>::const_iterator end = toclist.end();
+       
+       for (; cit != end; ++cit) {
+               string const line = string(4 * cit->depth, ' ') + cit->str;
+               fl_add_browser_line(dialog_->browser_toc, line.c_str());
+       }
+       
+       fl_set_browser_topline(dialog_->browser_toc, topline);
+       fl_select_browser_line(dialog_->browser_toc, line);
+#endif
 }
 
  
index 85ebbff8d39c4c4a9d3b36df6007f0251b19812f..0a86334e27c07609bcf5348834803dd1e33799af 100644 (file)
@@ -309,6 +309,7 @@ void add_toc2(int menu, string const & extra_label,
 void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
                             vector<int> & smn, Window win)
 {
+#if 0
        //xgettext:no-c-format
        static char const * MenuNames[3] = { N_("List of Figures%m"),
        //xgettext:no-c-format
@@ -358,7 +359,49 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
 
        add_toc2(menu, extra_label, smn, win,
                 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();
+       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();
+               for (; ccit != eend; ++ccit) {
+                       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);
+                       fl_addtopup(menu2, label.c_str());
+                       lyxerr << "[" << cit->first << "] " << label << endl;
+               }
+               string const m = cit->first + "%m";
+               fl_addtopup(menu, m.c_str(), menu2);
+       }
+       
+       
+       // Handle normal TOC
+       cit = toc_list.find("TOC");
+       if (cit == end) {
+               string const tmp = _("No Table of contents%i") + extra_label;
+               fl_addtopup(menu, tmp.c_str());
+               return;
+       } else {
+               add_toc2(menu, extra_label, smn, win,
+                        cit->second, 0, cit->second.size(), 0);
+       }
+       
+#endif
 }
 
 int Menubar::Pimpl::create_submenu(Window win, LyXView * view, 
index ecf8b6eea7305aeae5e2765d9bbc7c1c89c5e037..4fcccd7dceee739a67d61aab1221a125eb9ab51e 100644 (file)
@@ -1,5 +1,7 @@
 2001-03-11  Lars Gullik Bjønnes  <larsbj@trylle.birdstep.com>
 
+       * insettoc.C (Ascii): implement for dynamic number of lists
+
        * insetcaption.[Ch]: update from new_insets branch
        * insetfloat.[Ch]: ditto
        
index b4bc07b8ebfaf838fabb6318cdcc9a2e83169105..a4dd80b0055c68d977c8d4a52a9c4b02485021fe 100644 (file)
@@ -53,6 +53,7 @@ int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
 {
        os << getScreenLabel() << endl << endl;
 
+#if 0
        Buffer::TocType type;
        string cmdname = getCmdName();
        if (cmdname == "tableofcontents" )
@@ -70,7 +71,33 @@ int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
        for (vector<Buffer::TocItem>::const_iterator it = toc.begin();
             it != toc.end(); ++it)
                os << string(4 * it->depth, ' ') << it->str << endl;
+#else
+#warning Fix Me! (Lgb)
+       string type;
+       string cmdname = getCmdName();
+       if (cmdname == "tableofcontents" )
+               type = "TOC";
+       else if (cmdname == "listofalgorithms" )
+               type = "LOA";
+       else if (cmdname == "listoffigures" )
+               type = "LOF";
+       else 
+               type = "LOT";
 
+       map<string, vector<Buffer::TocItem> > const toc_list =
+                buffer->getTocList();
+       map<string, vector<Buffer::TocItem> >::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();
+               for (; ccit != end; ++ccit)
+                       os << string(4 * ccit->depth, ' ')
+                          << ccit->str << endl;
+       }
+#endif
        os << endl;
        return 0;
 }
index c64bfdf1d0cf1c04c5e5a616c2bd4ef4f4e10ddf..a443d7f9a8a4d7378f039a588ff6f7107eaa0c07 100644 (file)
@@ -2374,7 +2374,7 @@ void LyXText::PasteSelection(BufferView * bview)
        CutAndPaste cap;
 
        // this does not make sense, if there is nothing to paste
-       if (!cap.checkPastePossible(cursor.par(), cursor.pos()))
+       if (!cap.checkPastePossible(cursor.par()))
                return;
 
        SetUndo(bview->buffer(), Undo::INSERT,