diff options
-rw-r--r-- | doc/ScintillaDoc.html | 7 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | include/Scintilla.h | 2 | ||||
-rw-r--r-- | include/Scintilla.iface | 6 | ||||
-rw-r--r-- | src/ContractionState.cxx | 8 | ||||
-rw-r--r-- | src/ContractionState.h | 1 | ||||
-rw-r--r-- | src/EditModel.cxx | 18 | ||||
-rw-r--r-- | src/EditModel.h | 4 | ||||
-rw-r--r-- | src/EditView.cxx | 7 | ||||
-rw-r--r-- | src/Editor.cxx | 8 | ||||
-rw-r--r-- | src/UniqueString.h | 4 | ||||
-rw-r--r-- | test/simpleTests.py | 5 |
12 files changed, 64 insertions, 11 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 127d33694..5d441ff0e 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -5986,6 +5986,8 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ <a class="message" href="#SCI_TOGGLEFOLDSHOWTEXT">SCI_TOGGLEFOLDSHOWTEXT(int line, const char *text)</a><br /> <a class="message" href="#SCI_FOLDDISPLAYTEXTSETSTYLE">SCI_FOLDDISPLAYTEXTSETSTYLE(int style)</a><br /> <a class="message" href="#SCI_FOLDDISPLAYTEXTGETSTYLE">SCI_FOLDDISPLAYTEXTGETSTYLE → int</a><br /> + <a class="message" href="#SCI_SETDEFAULTFOLDDISPLAYTEXT">SCI_SETDEFAULTFOLDDISPLAYTEXT(const char *text)</a><br /> + <a class="message" href="#SCI_GETDEFAULTFOLDDISPLAYTEXT">SCI_GETDEFAULTFOLDDISPLAYTEXT(<unused>, char *text)</a><br /> <a class="message" href="#SCI_FOLDLINE">SCI_FOLDLINE(int line, int action)</a><br /> <a class="message" href="#SCI_FOLDCHILDREN">SCI_FOLDCHILDREN(int line, int action)</a><br /> <a class="message" href="#SCI_FOLDALL">SCI_FOLDALL(int action)</a><br /> @@ -6145,6 +6147,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ <p>An optional text tag may be shown to the right of the folded text with the <code class="parameter">text</code> argument to <code>SCI_TOGGLEFOLDSHOWTEXT</code>. + The default text for all header lines can be set with <code><a class="message" href="#SCI_SETDEFAULTFOLDDISPLAYTEXT">SCI_SETDEFAULTFOLDDISPLAYTEXT</a></code>. The text is drawn with the <code><a class="message" href="#StyleDefinition">STYLE_FOLDDISPLAYTEXT</a></code> style.</p> @@ -6182,6 +6185,10 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ </tbody> </table> + <p><b id="SCI_SETDEFAULTFOLDDISPLAYTEXT">SCI_SETDEFAULTFOLDDISPLAYTEXT(const char *text)</b><br /> + <b id="SCI_GETDEFAULTFOLDDISPLAYTEXT">SCI_GETDEFAULTFOLDDISPLAYTEXT(<unused>, char *text) → int</b><br /> + These messages set and get the default text displayed at the right of the folded text.</p> + <p><b id="SCI_SETFOLDEXPANDED">SCI_SETFOLDEXPANDED(int line, bool expanded)</b><br /> <b id="SCI_GETFOLDEXPANDED">SCI_GETFOLDEXPANDED(int line) → bool</b><br /> These messages set and get the expanded state of a single line. The set message has no effect diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 1a6b34f49..cce4dbdd5 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -572,6 +572,11 @@ <li> Avoid potential long hangs with idle styling for huge documents on Cocoa and GTK. </li> + <li> + Set default fold display text SCI_SETDEFAULTFOLDDISPLAYTEXT(text). + <a href="https://sourceforge.net/p/scintilla/feature-requests/1272/">Feature #1272</a>. + </li> + </ul> <ul> <a href="https://sourceforge.net/projects/scintilla/files/scintilla/3.10.3/scintilla3103.zip/download">Release 3.10.3</a> </h3> diff --git a/include/Scintilla.h b/include/Scintilla.h index 1845b677a..88610672b 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -493,6 +493,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_FOLDDISPLAYTEXT_BOXED 2 #define SCI_FOLDDISPLAYTEXTSETSTYLE 2701 #define SCI_FOLDDISPLAYTEXTGETSTYLE 2707 +#define SCI_SETDEFAULTFOLDDISPLAYTEXT 2722 +#define SCI_GETDEFAULTFOLDDISPLAYTEXT 2723 #define SC_FOLDACTION_CONTRACT 0 #define SC_FOLDACTION_EXPAND 1 #define SC_FOLDACTION_TOGGLE 2 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index c2dec218d..d5360a201 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1239,6 +1239,12 @@ set void FoldDisplayTextSetStyle=2701(int style,) # Get the style of fold display text. get int FoldDisplayTextGetStyle=2707(,) +# Set the default fold display text. +fun void SetDefaultFoldDisplayText=2722(, string text) + +# Get the default fold display text. +fun int GetDefaultFoldDisplayText=2723(, stringresult text) + enu FoldAction=SC_FOLDACTION_ val SC_FOLDACTION_CONTRACT=0 val SC_FOLDACTION_EXPAND=1 diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index c5e352180..47f345ada 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -74,7 +74,6 @@ public: bool HiddenLines() const override; const char *GetFoldDisplayText(Sci::Line lineDoc) const override; - bool GetFoldDisplayTextShown(Sci::Line lineDoc) const override; bool SetFoldDisplayText(Sci::Line lineDoc, const char *text) override; bool GetExpanded(Sci::Line lineDoc) const override; @@ -277,16 +276,11 @@ const char *ContractionState<LINE>::GetFoldDisplayText(Sci::Line lineDoc) const } template <typename LINE> -bool ContractionState<LINE>::GetFoldDisplayTextShown(Sci::Line lineDoc) const { - return !GetExpanded(lineDoc) && GetFoldDisplayText(lineDoc); -} - -template <typename LINE> bool ContractionState<LINE>::SetFoldDisplayText(Sci::Line lineDoc, const char *text) { EnsureData(); const char *foldText = foldDisplayTexts->ValueAt(lineDoc).get(); if (!foldText || !text || 0 != strcmp(text, foldText)) { - UniqueString uns = UniqueStringCopy(text); + UniqueString uns = IsNullOrEmpty(text) ? UniqueString() : UniqueStringCopy(text); foldDisplayTexts->SetValueAt(lineDoc, std::move(uns)); Check(); return true; diff --git a/src/ContractionState.h b/src/ContractionState.h index 90f5c0784..f9ec7b645 100644 --- a/src/ContractionState.h +++ b/src/ContractionState.h @@ -32,7 +32,6 @@ public: virtual bool HiddenLines() const=0; virtual const char *GetFoldDisplayText(Sci::Line lineDoc) const=0; - virtual bool GetFoldDisplayTextShown(Sci::Line lineDoc) const=0; virtual bool SetFoldDisplayText(Sci::Line lineDoc, const char *text)=0; virtual bool GetExpanded(Sci::Line lineDoc) const=0; diff --git a/src/EditModel.cxx b/src/EditModel.cxx index 6288fd1b6..99520f3cb 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -77,3 +77,21 @@ EditModel::~EditModel() { pdoc->Release(); pdoc = nullptr; } + +void EditModel::SetDefaultFoldDisplayText(const char *text) { + defaultFoldDisplayText = IsNullOrEmpty(text) ? UniqueString() : UniqueStringCopy(text); +} + +const char *EditModel::GetDefaultFoldDisplayText() const noexcept { + return defaultFoldDisplayText.get(); +} + +const char *EditModel::GetFoldDisplayText(Sci::Line lineDoc) const { + if (foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_HIDDEN || pcs->GetExpanded(lineDoc)) { + return nullptr; + } + + const char *text = pcs->GetFoldDisplayText(lineDoc); + return text ? text : defaultFoldDisplayText.get(); +} + diff --git a/src/EditModel.h b/src/EditModel.h index 5cc9d51d1..ab5c23cdb 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -40,6 +40,7 @@ public: int foldFlags; int foldDisplayTextStyle; + UniqueString defaultFoldDisplayText; std::unique_ptr<IContractionState> pcs; // Hotspot support Range hotspot; @@ -61,6 +62,9 @@ public: virtual Point GetVisibleOriginInMain() const = 0; virtual Sci::Line LinesOnScreen() const = 0; virtual Range GetHotSpotRange() const noexcept = 0; + void SetDefaultFoldDisplayText(const char *text); + const char *GetDefaultFoldDisplayText() const noexcept; + const char *GetFoldDisplayText(Sci::Line lineDoc) const; }; } diff --git a/src/EditView.cxx b/src/EditView.cxx index e82f09ee2..fa01a0385 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -985,7 +985,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle rcSegment.left = rcLine.left; rcSegment.right = rcLine.right; - const bool fillRemainder = !lastSubLine || model.foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_HIDDEN || !model.pcs->GetFoldDisplayTextShown(line); + const bool fillRemainder = !lastSubLine || !model.GetFoldDisplayText(line); if (fillRemainder) { // Fill the remainder of the line FillLineRemainder(surface, model, vsDraw, ll, line, rcSegment, subLine); @@ -1105,11 +1105,12 @@ void EditView::DrawFoldDisplayText(Surface *surface, const EditModel &model, con if (!lastSubLine) return; - if ((model.foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_HIDDEN) || !model.pcs->GetFoldDisplayTextShown(line)) + const char *text = model.GetFoldDisplayText(line); + if (!text) return; PRectangle rcSegment = rcLine; - const char *foldDisplayText = model.pcs->GetFoldDisplayText(line); + const char *foldDisplayText = text; const int lengthFoldDisplayText = static_cast<int>(strlen(foldDisplayText)); FontAlias fontText = vsDraw.styles[STYLE_FOLDDISPLAYTEXT].font; const int widthFoldDisplayText = static_cast<int>(surface->WidthText(fontText, foldDisplayText, lengthFoldDisplayText)); diff --git a/src/Editor.cxx b/src/Editor.cxx index 08a4ac76c..d67f97df7 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7191,6 +7191,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_FOLDDISPLAYTEXTGETSTYLE: return foldDisplayTextStyle; + case SCI_SETDEFAULTFOLDDISPLAYTEXT: + SetDefaultFoldDisplayText(CharPtrFromSPtr(lParam)); + Redraw(); + break; + + case SCI_GETDEFAULTFOLDDISPLAYTEXT: + return StringResult(lParam, GetDefaultFoldDisplayText()); + case SCI_TOGGLEFOLD: FoldLine(static_cast<Sci::Line>(wParam), SC_FOLDACTION_TOGGLE); break; diff --git a/src/UniqueString.h b/src/UniqueString.h index 18c31283e..8d95cb1ab 100644 --- a/src/UniqueString.h +++ b/src/UniqueString.h @@ -11,6 +11,10 @@ namespace Scintilla { +constexpr bool IsNullOrEmpty(const char *text) noexcept { + return text == nullptr || *text == '\0'; +} + using UniqueString = std::unique_ptr<const char[]>; /// Equivalent to strdup but produces a std::unique_ptr<const char[]> allocation to go diff --git a/test/simpleTests.py b/test/simpleTests.py index b5260c8a8..9a170a2f9 100644 --- a/test/simpleTests.py +++ b/test/simpleTests.py @@ -1639,6 +1639,11 @@ class TestStyleAttributes(unittest.TestCase): self.ed.FoldDisplayTextSetStyle(self.ed.SC_FOLDDISPLAYTEXT_BOXED) self.assertEquals(self.ed.FoldDisplayTextGetStyle(), self.ed.SC_FOLDDISPLAYTEXT_BOXED) + def testDefaultFoldDisplayText(self): + self.assertEquals(self.ed.GetDefaultFoldDisplayText(), b"") + self.ed.SetDefaultFoldDisplayText(0, b"...") + self.assertEquals(self.ed.GetDefaultFoldDisplayText(), b"...") + class TestIndices(unittest.TestCase): def setUp(self): self.xite = Xite.xiteFrame |