summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-12-04 21:55:21 +0100
committerMatthias Melcher <github@matthiasm.com>2023-12-04 22:03:55 +0100
commit5b96fca1c11daaae8a749090aab2d1d31d0b9510 (patch)
tree58cb7fbd45efca6094a43b5dadfa49ed475610af /fluid
parentc3849b0a97913add0fae4b3ba3e4bff2a706738d (diff)
#859: FLUID: Improves widget class code formatting
- categorizes multiple comments before a widget class member correctly vs. before a widget member - reintrodues newline characters for comment preview in the widget browser
Diffstat (limited to 'fluid')
-rw-r--r--fluid/code.cxx27
-rw-r--r--fluid/widget_browser.cxx5
2 files changed, 27 insertions, 5 deletions
diff --git a/fluid/code.cxx b/fluid/code.cxx
index 9f6e30118..8913f7aaf 100644
--- a/fluid/code.cxx
+++ b/fluid/code.cxx
@@ -679,6 +679,26 @@ bool is_class_member(Fl_Type *t) {
}
/**
+ Return true, if this is a comment, and if it is followed by a class member.
+ This must only be called if q is inside a widget class.
+ Widget classes can have widgets and members (functions/methods, declarations,
+ etc.) intermixed.
+ \param[in] q should be a comment type
+ \return true if this comment is followed by a class member
+ \return false if it is followed by a widget or code
+ \see is_class_member(Fl_Type *t)
+ */
+bool is_comment_before_class_member(Fl_Type *q) {
+ if (q->is_a(ID_Comment) && q->next && q->next->level==q->level) {
+ if (q->next->is_a(ID_Comment))
+ return is_comment_before_class_member(q->next);
+ if (is_class_member(q->next))
+ return true;
+ }
+ return false;
+}
+
+/**
Recursively dump code, putting children between the two parts of the parent code.
\param[in] p write this type and all its children
\return pointer to the next sibling
@@ -699,9 +719,7 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) {
// Handle widget classes specially
for (q = p->next; q && q->level > p->level;) {
// note: maybe declaration blocks should be handled like comments in the context
- // note: we don't handle comments before a comment before a member
- bool comment_before_member = (q->is_a(ID_Comment) && q->next && q->next->level==q->level && is_class_member(q->next));
- if (!is_class_member(q) && !comment_before_member) {
+ if (!is_class_member(q) && !is_comment_before_class_member(q)) {
q = write_code(q);
} else {
int level = q->level;
@@ -719,8 +737,7 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) {
if (write_sourceview) p->header2_end = (int)ftell(header_file);
for (q = p->next; q && q->level > p->level;) {
- bool comment_before_member = (q->is_a(ID_Comment) && q->next && q->next->level==q->level && is_class_member(q->next));
- if (is_class_member(q) || comment_before_member) {
+ if (is_class_member(q) || is_comment_before_class_member(q)) {
q = write_code(q);
} else {
int level = q->level;
diff --git a/fluid/widget_browser.cxx b/fluid/widget_browser.cxx
index b27d7a664..fa1690f12 100644
--- a/fluid/widget_browser.cxx
+++ b/fluid/widget_browser.cxx
@@ -146,6 +146,11 @@ static char *copy_trunc(char *p, const char *str, int maxl, int quote)
const char *end = str + strlen(str); // end of input string
if (quote) *p++ = '"'; // opening quote
while (size < maxl) { // maximum <maxl> characters
+ if (*str == '\n') {
+ *p++ = '\\'; *p++ = 'n';
+ str++; size++;
+ continue;
+ }
if (!(*str & (-32))) break; // end of string (0 or control char)
bs = fl_utf8len(*str); // size of next character
if (bs <= 0) break; // some error - leave