]> git.lyx.org Git - lyx.git/blob - src/TocBuilder.cpp
Fix text direction issue for InsetInfo in RTL context
[lyx.git] / src / TocBuilder.cpp
1 /**
2  * \file TocBuilder.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Guillaume Munch
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "TocBuilder.h"
14
15 #include "TocBackend.h"
16
17 #include "support/lassert.h"
18
19 using namespace std;
20
21
22 namespace lyx {
23
24
25
26 TocBuilder::TocBuilder(shared_ptr<Toc> toc)
27         : toc_(toc ? toc : make_shared<Toc>()),
28           stack_()
29 {
30         LATTEST(toc);
31 }
32
33 void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
34                           bool output_active, bool is_captioned)
35 {
36         toc_->push_back(TocItem(dit, stack_.size(), s, output_active));
37         frame f = {
38                 toc_->size() - 1, //pos
39                 is_captioned, //is_captioned
40         };
41         stack_.push(f);
42 }
43
44 void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
45                              bool output_active)
46 {
47         // first show the float before moving to the caption
48         docstring arg = "paragraph-goto " + dit.paragraphGotoArgument();
49         if (!stack_.empty())
50                 arg = "paragraph-goto " +
51                         (*toc_)[stack_.top().pos].dit().paragraphGotoArgument() + ";" + arg;
52         FuncRequest func(LFUN_COMMAND_SEQUENCE, arg);
53
54         if (!stack_.empty() && !stack_.top().is_captioned) {
55                 // The float we entered has not yet been assigned a caption.
56                 // Assign the caption string to it.
57                 TocItem & captionable = (*toc_)[stack_.top().pos];
58                 captionable.str(s);
59                 captionable.setAction(func);
60                 stack_.top().is_captioned = true;
61         } else {
62                 // This is a new entry.
63                 pop();
64                 // the dit is at the float's level, e.g. for the contextual menu of
65                 // outliner entries
66                 DocIterator captionable_dit = dit;
67                 captionable_dit.pop_back();
68                 pushItem(captionable_dit, s, output_active, true);
69                 (*toc_)[stack_.top().pos].setAction(func);
70         }
71 }
72
73 void TocBuilder::argumentItem(docstring const & arg_str)
74 {
75         if (stack_.empty() || arg_str.empty())
76                 return;
77         TocItem & item = (*toc_)[stack_.top().pos];
78         docstring const & str = item.str();
79         string const & delim =
80                 (str.empty() || !stack_.top().is_captioned) ? "" :  ", ";
81         item.str(str + from_ascii(delim) + arg_str);
82         stack_.top().is_captioned = true;
83 }
84
85 void TocBuilder::pop()
86 {
87         if (!stack_.empty())
88                 stack_.pop();
89 }
90
91
92 } // namespace lyx