diff options
author | Neil <nyamatongwe@gmail.com> | 2019-04-05 08:32:58 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-04-05 08:32:58 +1100 |
commit | 006b224af96d10452655ecced49ba3859c1d62ab (patch) | |
tree | 3fc3107e8819d4955eaf6ca325098d883d914c5f | |
parent | a5b810a701d3dd4b9b717d5ba036aef6d7f34445 (diff) | |
download | scintilla-mirror-006b224af96d10452655ecced49ba3859c1d62ab.tar.gz |
Feature [feature-requests:#1272]. Add API to set default fold display text.
-rw-r--r-- | doc/ScintillaDoc.html | 7 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 6 | ||||
-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 | 17 | ||||
-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, 63 insertions, 12 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index b9f15e267..ddebc65a9 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -6013,6 +6013,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 /> @@ -6172,6 +6174,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> @@ -6209,6 +6212,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 8e8d734dd..b92fbcfb9 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -583,7 +583,11 @@ <li> Avoid potential long hangs with idle styling for huge documents on Cocoa and GTK. </li> - <ul> + <li> + Set default fold display text SCI_SETDEFAULTFOLDDISPLAYTEXT(text). + <a href="https://sourceforge.net/p/scintilla/feature-requests/1272/">Feature #1272</a>. + </li> + </ul> <h3> <a href="https://www.scintilla.org/scite414.zip">Release 4.1.4</a> </h3> diff --git a/include/Scintilla.h b/include/Scintilla.h index 6187bc612..386d372ee 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 2b69adef3..7960bdbc6 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 1dd25cc4d..565f9e141 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -75,7 +75,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; @@ -278,16 +277,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 83cade5ef..db8682efb 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -88,3 +88,20 @@ bool EditModel::BidirectionalEnabled() const { bool EditModel::BidirectionalR2L() const { return bidirectional == Bidirectional::bidiR2L; } + +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 5fb6a0f02..b63f2129f 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -42,6 +42,7 @@ public: int foldFlags; int foldDisplayTextStyle; + UniqueString defaultFoldDisplayText; std::unique_ptr<IContractionState> pcs; // Hotspot support Range hotspot; @@ -65,6 +66,9 @@ public: virtual Range GetHotSpotRange() const noexcept = 0; bool BidirectionalEnabled() const; bool BidirectionalR2L() const; + 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 91d5da13d..a26412954 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -1048,7 +1048,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); @@ -1196,11 +1196,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 std::string_view foldDisplayText = model.pcs->GetFoldDisplayText(line); + const std::string_view foldDisplayText(text); FontAlias fontText = vsDraw.styles[STYLE_FOLDDISPLAYTEXT].font; const int widthFoldDisplayText = static_cast<int>(surface->WidthText(fontText, foldDisplayText)); diff --git a/src/Editor.cxx b/src/Editor.cxx index f269326a2..aa0b9723c 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7204,6 +7204,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 |