mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Display bookmarks in the workarea (take 2).
The bookmarks are shown with circled numbers in the right margin (or the left margin in RTL mode). A new color "bookmarks" has been added. Currently bookmark 0 (the return position) is not displayed because it is very disturbing in practice. To make this work, a new method BookmarksSection::bookmarksInPar retuns the list of bookmarks in a paragraph along with their position. Force redraw when using bookmark-save and bookmark-clear. Caveats: - this solution does not show the precise position of the bookmark (this is supposedly not a problem). - if several bookmarks are on the same row, they will currently be garbled. It would be easy to make sure that only one is shown ; what would be more difficult would be to move the second bookmark lower. - it is possible to make sure that the markers are correctly centered in the margin, and that the margin size is large enough to hold the marker (I did not try all fonts). Fixes bug #2496.
This commit is contained in:
parent
e4ab91d802
commit
42b23f3fb2
@ -1472,6 +1472,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
break;
|
||||
|
||||
case LFUN_BOOKMARK_SAVE:
|
||||
dr.screenUpdate(Update::Force);
|
||||
saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
|
||||
break;
|
||||
|
||||
|
@ -341,8 +341,9 @@ ColorSet::ColorSet()
|
||||
{ Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" },
|
||||
{ Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"},
|
||||
{ Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"},
|
||||
{ Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
|
||||
{ Color_regexpframe, N_("regexp frame"), "regexpframe", Green, green, "regexpframe" },
|
||||
{ Color_bookmark, N_("bookmark"), "bookmark", RoyalBlue, RoyalBlue, "bookmark" },
|
||||
{ Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
|
||||
{ Color_ignore, N_("ignore"), "ignore", black, Linen, "ignore" },
|
||||
{ Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
@ -228,6 +228,8 @@ enum ColorCode {
|
||||
Color_paragraphmarker,
|
||||
/// Preview frame color
|
||||
Color_previewframe,
|
||||
/// Bookmark indicator color
|
||||
Color_bookmark,
|
||||
|
||||
// Logical attributes
|
||||
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
RowList const & rows() const { return rows_; }
|
||||
///
|
||||
int rightMargin(BufferView const & bv) const;
|
||||
///
|
||||
Paragraph const & par() const { return *par_; }
|
||||
|
||||
/// dump some information to lyxerr
|
||||
void dump() const;
|
||||
|
@ -627,7 +627,18 @@ void RowPainter::paintSelection() const
|
||||
pi_.pain.fillRectangle(int(x), y1,
|
||||
int(xo_ + tm_.width()) - int(x), y2 - y1,
|
||||
Color_selection);
|
||||
}
|
||||
|
||||
|
||||
void RowPainter::paintBookmark(int num) const
|
||||
{
|
||||
int const x = row_.isRTL()
|
||||
? pi_.base.bv->workWidth() - pi_.base.bv->rightMargin() : 0;
|
||||
FontInfo fi = pi_.base.bv->buffer().params().getFont().fontInfo();
|
||||
fi.setColor(Color_bookmark);
|
||||
// ❶ U+2776 DINGBAT NEGATIVE CIRCLED DIGIT ONE
|
||||
char_type const ch = 0x2775 + num;
|
||||
pi_.pain.text(x, yo_, ch, fi);
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
void paintText();
|
||||
void paintOnlyInsets();
|
||||
void paintSelection() const;
|
||||
void paintBookmark(int num) const;
|
||||
|
||||
private:
|
||||
void paintLanguageMarkings(Row::Element const & e) const;
|
||||
|
@ -339,6 +339,20 @@ BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) co
|
||||
}
|
||||
|
||||
|
||||
BookmarksSection::BookmarkPosList
|
||||
BookmarksSection::bookmarksInPar(FileName const & fn, int const par_id) const
|
||||
{
|
||||
// FIXME: we do not consider the case of bottom_pit.
|
||||
// This is probably not a problem.
|
||||
BookmarksSection::BookmarkPosList bip;
|
||||
for (size_t i = 1; i < bookmarks.size(); ++i)
|
||||
if (bookmarks[i].filename == fn && bookmarks[i].top_id == par_id)
|
||||
bip.push_back({i, bookmarks[i].top_pos});
|
||||
|
||||
return bip;
|
||||
}
|
||||
|
||||
|
||||
LastCommandsSection::LastCommandsSection(unsigned int num) :
|
||||
default_num_last_commands(30),
|
||||
absolute_max_last_commands(100)
|
||||
|
@ -262,6 +262,12 @@ public:
|
||||
*/
|
||||
BookmarkList & load() { return bookmarks; }
|
||||
|
||||
///
|
||||
typedef std::vector<std::pair<unsigned int, pos_type>> BookmarkPosList;
|
||||
|
||||
/// return a list of bookmarks and position for this paragraph
|
||||
BookmarkPosList bookmarksInPar(support::FileName const & fn, int par_id) const;
|
||||
|
||||
private:
|
||||
|
||||
/// allow 9 regular bookmarks, bookmark 0 is temporary
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "MetricsInfo.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "RowPainter.h"
|
||||
#include "Session.h"
|
||||
#include "Text.h"
|
||||
#include "TextClass.h"
|
||||
#include "VSpace.h"
|
||||
@ -1857,6 +1858,9 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
|
||||
if (text_->isRTL(pit))
|
||||
swap(pi.leftx, pi.rightx);
|
||||
|
||||
BookmarksSection::BookmarkPosList bpl =
|
||||
theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.par().id());
|
||||
|
||||
for (size_t i = 0; i != nrows; ++i) {
|
||||
|
||||
Row const & row = pm.rows()[i];
|
||||
@ -1945,6 +1949,11 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
|
||||
rp.paintText();
|
||||
rp.paintTooLargeMarks(row_x + row.left_x() < 0,
|
||||
row_x + row.right_x() > bv_->workWidth());
|
||||
// indicate bookmarks presence in margin
|
||||
for (auto const & bp_p : bpl)
|
||||
if (bp_p.second >= row.pos() && bp_p.second < row.endpos())
|
||||
rp.paintBookmark(bp_p.first);
|
||||
|
||||
y += row.descent();
|
||||
|
||||
#if 0
|
||||
|
@ -2192,6 +2192,7 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
|
||||
case LFUN_BOOKMARK_CLEAR:
|
||||
theSession().bookmarks().clear();
|
||||
dr.screenUpdate(Update::Force);
|
||||
break;
|
||||
|
||||
case LFUN_DEBUG_LEVEL_SET:
|
||||
|
Loading…
Reference in New Issue
Block a user