diff options
| author | Matthias Melcher <github@matthiasm.com> | 2026-01-05 00:36:28 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2026-01-05 00:36:28 +0100 |
| commit | 48617a8075e86b6991030d34df1b31fe86cd01b3 (patch) | |
| tree | ae05c0bb0326b74adc03e1c42a99298d28d19da6 | |
| parent | 296f2fc5da9c2bcdef10221e40971864e6457f20 (diff) | |
Fluid: Modernize use of strings.
Testing MergeBack at the same time.
| -rw-r--r-- | fluid/nodes/Function_Node.cxx | 138 | ||||
| -rw-r--r-- | fluid/nodes/Function_Node.h | 48 | ||||
| -rw-r--r-- | fluid/panels/widget_panel.cxx | 74 | ||||
| -rw-r--r-- | fluid/panels/widget_panel.fl | 80 |
4 files changed, 163 insertions, 177 deletions
diff --git a/fluid/nodes/Function_Node.cxx b/fluid/nodes/Function_Node.cxx index 66e425533..a05bba271 100644 --- a/fluid/nodes/Function_Node.cxx +++ b/fluid/nodes/Function_Node.cxx @@ -741,14 +741,6 @@ void CodeBlock_Node::write_code2(fld::io::Code_Writer& f) { Decl_Node Decl_Node::prototype; /** - Constructor. - */ -Decl_Node::Decl_Node() : - public_(0), - static_(1) -{ } - -/** Return 1 if this declaration and its parents are public. */ int Decl_Node::is_public() const @@ -911,21 +903,6 @@ void Decl_Node::write_code1(fld::io::Code_Writer& f) { Data_Node Data_Node::prototype; /** - Constructor. - */ -Data_Node::Data_Node() : - Decl_Node() -{ } - -/** - Destructor. - */ -Data_Node::~Data_Node() { - if (filename_) - free((void*)filename_); -} - -/** Create an empty inline data node. \param[in] strategy add after current or as last child \return new inline data node @@ -942,7 +919,7 @@ Node *Data_Node::make(Strategy strategy) { Data_Node *o = new Data_Node(); o->public_ = 1; o->static_ = 1; - o->filename_ = nullptr; + o->filename_.clear(); o->output_format_ = 0; o->name("myInlineData"); o->add(anchor, strategy); @@ -957,9 +934,9 @@ Node *Data_Node::make(Strategy strategy) { */ void Data_Node::write_properties(fld::io::Project_Writer &f) { Decl_Node::write_properties(f); - if (filename_) { + if (!filename().empty()) { f.write_string("filename"); - f.write_word(filename_); + f.write_word(filename().c_str()); } switch (output_format_) { case 1: f.write_string("textmode"); break; @@ -1005,14 +982,14 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { const char *message = nullptr; const char *c = name(); if (!c) return; - const char *fn = filename_; + std::string fn = filename(); char *data = nullptr; int nData = -1; int uncompressedDataSize = 0; // path should be set correctly already - if (filename_ && !f.write_codeview) { + if (!filename().empty() && !f.write_codeview) { Fluid.proj.enter_project_dir(); - FILE *f = fl_fopen(filename_, "rb"); + FILE *f = fl_fopen(filename().c_str(), "rb"); Fluid.proj.leave_project_dir(); if (!f) { message = "Can't include data from file. Can't open"; @@ -1036,7 +1013,8 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { fclose(f); } } else { - fn = filename_ ? filename_ : "<no filename>"; + if (filename().empty()) + fn = "<no filename>"; } if (is_in_class()) { f.write_public(public_); @@ -1045,13 +1023,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { write_comment_c(f); if (output_format_ == 1) { f.write_h("%sstatic const char *%s;\n", f.indent(1), c); - f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn); + f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str()); } else { f.write_h_once("#include <string>"); f.write_h("%sstatic const std::string %s;\n", f.indent(1), c); - f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn); + f.write_c("const std::string %s::%s = /* text inlined from %s */\n", class_name(1), c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { f.write_h("%sstatic int %s_size;\n", f.indent(1), c); @@ -1060,28 +1038,28 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { f.write_c("int %s::%s_size = %d;\n", class_name(1), c, uncompressedDataSize); if (output_format_ == 2) { f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); - f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn); + f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn.c_str()); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c); - f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn); + f.write_c("std::vector<uint8_t> %s::%s = /* data compressed and inlined from %s */\n", class_name(1), c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } else { f.write_c("\n"); write_comment_c(f); if (output_format_ == 0) { f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); - f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn); + f.write_c("unsigned char %s::%s[%d] = /* data inlined from %s */\n", class_name(1), c, nData, fn.c_str()); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("%sstatic std::vector<uint8_t> %s;\n", f.indent(1), c); - f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn); + f.write_c("std::vector<uint8_t> %s::%s = /* data inlined from %s */\n", class_name(1), c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } f.write_c(";\n"); @@ -1094,13 +1072,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { write_comment_c(f); if (output_format_ == 1) { f.write_h("extern const char *%s;\n", c); - f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); + f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str()); } else { f.write_h_once("#include <string>"); f.write_h("extern const std::string %s;\n", c); - f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn); + f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { f.write_h("extern int %s_size;\n", c); @@ -1109,34 +1087,34 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); if (output_format_ == 2) { f.write_h("extern unsigned char %s[%d];\n", c, nData); - f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str()); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("extern std::vector<uint8_t> %s;\n", c); - f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn); + f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } else { f.write_c("\n"); write_comment_c(f); if (output_format_ == 0) { f.write_h("extern unsigned char %s[%d];\n", c, nData); - f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn); + f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str()); } else { f.write_h_once("#include <stdint.h>"); f.write_h_once("#include <vector>"); f.write_h("extern std::vector<uint8_t> %s;\n", c); - f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn); + f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } f.write_c(";\n"); } else { write_comment_h(f); - f.write_h("#error Unsupported declaration loading inline data %s\n", fn); + f.write_h("#error Unsupported declaration loading inline data %s\n", fn.c_str()); if (output_format_ == 1) f.write_h("const char *%s = \"abc...\";\n", c); else @@ -1148,39 +1126,39 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { if ((output_format_ == 1) || (output_format_ == 4)) { if (output_format_ == 1) { if (static_) f.write_c("static "); - f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); + f.write_c("const char *%s = /* text inlined from %s */\n", c, fn.c_str()); } else { f.write_c_once("#include <string>"); if (static_) f.write_c("static "); - f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn); + f.write_c("const std::string %s = /* text inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cstring(data, nData); } else if ((output_format_ == 2) || (output_format_ == 5)) { if (static_) f.write_c("static "); f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); if (output_format_ == 2) { if (static_) f.write_c("static "); - f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn.c_str()); } else { f.write_c_once("#include <stdint.h>"); f.write_c_once("#include <vector>"); if (static_) f.write_c("static "); - f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn); + f.write_c("std::vector<uint8_t> %s = /* data compressed and inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } else { if (output_format_ == 0) { if (static_) f.write_c("static "); - f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn); + f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn.c_str()); } else { f.write_c_once("#include <stdint.h>"); f.write_c_once("#include <vector>"); if (static_) f.write_c("static "); - f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn); + f.write_c("std::vector<uint8_t> %s = /* data inlined from %s */\n", c, fn.c_str()); } - if (message) f.write_c("#error %s %s\n", message, fn); + if (message) f.write_c("#error %s %s\n", message, fn.c_str()); f.write_cdata(data, nData); } f.write_c(";\n"); @@ -1190,17 +1168,13 @@ void Data_Node::write_code1(fld::io::Code_Writer& f) { // giving the error: (Fluid.batch_mode && !write_codeview) ??? if (message && !f.write_codeview) { if (Fluid.batch_mode) - fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn); + fprintf(stderr, "FLUID ERROR: %s %s\n", message, fn.c_str()); else - fl_alert("%s\n%s\n", message, fn); + fl_alert("%s\n%s\n", message, fn.c_str()); } if (data) free(data); } -void Data_Node::filename(const char* fn) { - storestring(fn, filename_); -} - // ---- DeclBlock_Node declaration @@ -1216,19 +1190,6 @@ void Data_Node::filename(const char* fn) { DeclBlock_Node DeclBlock_Node::prototype; /** - Constructor. - */ -DeclBlock_Node::DeclBlock_Node() -: Node() -{ } - -/** - Destructor. - */ -DeclBlock_Node::~DeclBlock_Node() { -} - -/** Return 1 if this block is public. */ int DeclBlock_Node::is_public() const { @@ -1363,15 +1324,6 @@ void DeclBlock_Node::write_code2(fld::io::Code_Writer& f) { Comment_Node Comment_Node::prototype; /** - Constructor. - */ -Comment_Node::Comment_Node() : - in_c_(1), - in_h_(1), - style_(0) -{ } - -/** Make a new comment node. \param[in] strategy add after current or as last child \return new Comment node @@ -1505,20 +1457,6 @@ void Comment_Node::write_code1(fld::io::Code_Writer& f) { Class_Node Class_Node::prototype; /** - Constructor. - */ -Class_Node::Class_Node() : - Node(), - public_(1) -{ } - -/** - Destructor. - */ -Class_Node::~Class_Node() { -} - -/** Return 1 if this class is marked public. */ int Class_Node::is_public() const { diff --git a/fluid/nodes/Function_Node.h b/fluid/nodes/Function_Node.h index c35a26705..4196c202a 100644 --- a/fluid/nodes/Function_Node.h +++ b/fluid/nodes/Function_Node.h @@ -144,12 +144,15 @@ class Decl_Node : public Node public: typedef Node super; static Decl_Node prototype; + protected: - char public_; // public = 0, private = 1, protected = 2 - char static_; + char public_ = 0; // public = 0, private = 1, protected = 2 + char static_ = 1; public: - Decl_Node(); + Decl_Node() = default; + ~Decl_Node() override = default; + Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override { } @@ -174,12 +177,13 @@ public: typedef Decl_Node super; static Data_Node prototype; private: - const char *filename_ { nullptr }; + std::string filename_; int output_format_ { 0 }; public: - Data_Node(); - ~Data_Node(); + Data_Node() = default; + ~Data_Node() override = default; + Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override {} @@ -189,8 +193,8 @@ public: void read_property(fld::io::Project_Reader &f, const char *) override; Type type() const override { return Type::Data; } bool is_a(Type inType) const override { return (inType==Type::Data) ? true : super::is_a(inType); } - void filename(const char* fn); - const char* filename() { return filename_; } + void filename(const std::string& fn) { storestring(fn, filename_); } + std::string filename() { return filename_; } int output_format() { return output_format_; } void output_format(int fmt) { output_format_ = fmt; } }; @@ -210,12 +214,13 @@ public: }; private: - std::string end_code_; ///< code after all children of this block - int write_map_ { CODE_IN_SOURCE }; ///< see enum above + std::string end_code_; ///< code after all children of this block + int write_map_ = CODE_IN_SOURCE; ///< see enum above public: - DeclBlock_Node(); - ~DeclBlock_Node(); + DeclBlock_Node() = default; + ~DeclBlock_Node() override = default; + Node *make(Strategy strategy) override; void write_static(fld::io::Code_Writer& f) override; void write_static_after(fld::io::Code_Writer& f) override; @@ -245,10 +250,14 @@ public: static Comment_Node prototype; private: - char in_c_, in_h_, style_; + char in_c_ = 1; + char in_h_ = 1; + char style_ = 0; public: - Comment_Node(); + Comment_Node() = default; + ~Comment_Node() override = default; + Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override { } @@ -276,14 +285,16 @@ public: private: std::string base_class_; std::string prefix_; - char public_; + char public_ = 1; public: - Class_Node(); - ~Class_Node(); - // state variables for output: + Class_Node() = default; + ~Class_Node() override = default; + + // State variables used when writing code to file char write_public_state; // true when public: has been printed Class_Node* parent_class; // save class if nested + Node *make(Strategy strategy) override; void write_code1(fld::io::Code_Writer& f) override; void write_code2(fld::io::Code_Writer& f) override; @@ -306,7 +317,6 @@ public: char visibility() { return public_; } void visibility(char v) { public_ = v; } - // class prefix attribute access /** Get the text between `class` and the class name */ std::string prefix() const { return prefix_; } /** Set the text between `class` and the class name */ diff --git a/fluid/panels/widget_panel.cxx b/fluid/panels/widget_panel.cxx index 57c1b4b1b..679a52c6c 100644 --- a/fluid/panels/widget_panel.cxx +++ b/fluid/panels/widget_panel.cxx @@ -17,7 +17,6 @@ // generated by Fast Light User Interface Designer (fluid) version 1.0500 #include "widget_panel.h" -#include <stdlib.h> // free() #include "Fluid.h" #include "app/Snap_Action.h" #include "app/Image_Asset.h" @@ -32,6 +31,8 @@ #include <FL/Fl_Menu_Item.H> #include <FL/Fl_File_Chooser.H> #include <ctype.h> +#include <stdlib.h> // free() +#include <functional> // std::function #define ZERO_ENTRY 1000 extern const char* when_symbol_name(int n); extern void set_whenmenu(int n); @@ -51,11 +52,43 @@ extern int haderror; Allow widget navigation on text fields with Tab. */ static int use_tab_navigation(int, Fl_Text_Editor*) { -//fl ▼ ------------------------ code ---~=--~~-~~=~~==~=-=-~- ▼ fl// +//fl ▼ ------------------------ code ------=-~--==~-~=----=-- ▼ fl// return 0; //fl ▲ ----------~~-~=---~-------------~-=--~~-=~=-~~--~-~=-- ▲ fl// } +static void update_current(Fl_Input* o, void *v, + std::function<std::string()> getter, + std::function<void(std::string)> setter) { +//fl ▼ ------------------------ code --~---=~--=-=-=---~=~~=~ ▼ fl// + if (v == LOAD) { + o->value( getter().c_str() ); + } else { + std::string v = o->value(); + if (v != getter()) { + setter(v); + Fluid.proj.set_modflag(1); + } + } +//fl ▲ ----------~~~=~---=~-------------~=-~--~=~~-=--=-==~-= ▲ fl// +} + +static void update_current(Fl_Text_Editor* o, void *v, + std::function<std::string()> getter, + std::function<void(std::string)> setter) { +//fl ▼ ------------------------ code ----~-~-=~~~~=-~-==--~-- ▼ fl// + if (v == LOAD) { + o->buffer()->text( getter().c_str() ); + } else { + std::string v = o->buffer()->text(); + if (v != getter()) { + setter(v); + Fluid.proj.set_modflag(1); + } + } +//fl ▲ ----------~~-=-~=--=-=----------~-~~=-~-~~-~~==~~--=~- ▲ fl// +} + Fl_Double_Window *image_panel_window=(Fl_Double_Window *)0; static void cb_image_panel_window(Fl_Double_Window* o, void* v) { @@ -2586,21 +2619,11 @@ static void cb_wp_data_filename(Fl_Input* o, void* v) { //fl ▼ ---------------------- callback ~-~=~~~~~~-=~~=~-==--- ▼ fl// if (!current_node || !current_node->is_a(Type::Data)) return; Data_Node* nd = (Data_Node*)current_node; - - if (v == LOAD) { - const char *fn = nd->filename(); - o->value( fn ? fn : "" ); - } else { - const char *c = o->value(); - const char *fn = nd->filename(); - if ( ( fn && (strcmp(fn, c) != 0)) - || (!fn && (strcmp("", c) != 0)) ) - { - nd->filename(c); - Fluid.proj.set_modflag(1); - } - } -//fl ▲ ----------~=-~--=--~------------~~-~-----~=~-~=~--~-~- ▲ fl// + update_current(o, v, + [nd](){return nd->filename();}, + [nd](std::string s){nd->filename(s);} + ); +//fl ▲ ----------~=-~--=--~------------~-~==--==-~=---==--~-~ ▲ fl// } static void cb_fileopen(Fl_Button*, void* v) { @@ -2995,16 +3018,11 @@ static void cb_End(Fl_Input* o, void* v) { //fl ▼ ---------------------- callback -~-~--~-----=-~~~~~=-~ ▼ fl// if (!current_node || !current_node->is_a(Type::DeclBlock)) return; DeclBlock_Node* nd = (DeclBlock_Node*)current_node; - if (v == LOAD) { - o->value( nd->end_code().c_str() ); - } else { - std::string v = o->value(); - if (v != nd->end_code()) { - nd->end_code( v ); - Fluid.proj.set_modflag(1); - } - } -//fl ▲ ----------=~~~~~~=~-=-----------~~-~~---=--=-~~=---=~- ▲ fl// + update_current(o, v, + [nd](){return nd->end_code();}, + [nd](std::string s){nd->end_code(s);} + ); +//fl ▲ ----------=~~~~~~=~-=-------------=~--~=~--=~~~=~~-~~= ▲ fl// } static void cb_implementations(Fl_Check_Button* o, void* v) { @@ -4548,6 +4566,7 @@ Fl_Double_Window* make_widget_panel() { wp_data_filename->textsize(11); wp_data_filename->callback((Fl_Callback*)cb_wp_data_filename); wp_data_filename->align(Fl_Align(132)); + Fl_Group::current()->resizable(wp_data_filename); } // Fl_Input* wp_data_filename { Fl_Button* o = new Fl_Button(365, 125, 40, 20, "@fileopen"); o->labelcolor((Fl_Color)134); @@ -4561,7 +4580,6 @@ Fl_Double_Window* make_widget_panel() { o->textsize(11); o->callback((Fl_Callback*)cb_Comment); o->align(Fl_Align(FL_ALIGN_LEFT)); - Fl_Group::current()->resizable(o); o->buffer(new Fl_Text_Buffer()); o->add_key_binding(FL_Tab, 0, use_tab_navigation); } // Fl_Text_Editor* o diff --git a/fluid/panels/widget_panel.fl b/fluid/panels/widget_panel.fl index 287baf023..090aeaf6a 100644 --- a/fluid/panels/widget_panel.fl +++ b/fluid/panels/widget_panel.fl @@ -27,9 +27,6 @@ comment {// } {uid 901f in_source in_header } -decl {\#include <stdlib.h> // free()} {uid 053c private global -} - decl {\#include "panels/widget_panel/Grid_Child_Tab.h"} {uid c26d public global } @@ -84,6 +81,12 @@ decl {\#include <FL/Fl_File_Chooser.H>} {uid 2160 private global decl {\#include <ctype.h>} {uid 43de private global } +decl {\#include <stdlib.h> // free()} {uid 053c private global +} + +decl {\#include <functional> // std::function} {uid 29a1 private global +} + decl {\#define ZERO_ENTRY 1000} {uid e18b private global } @@ -113,6 +116,38 @@ Function {use_tab_navigation(int, Fl_Text_Editor*)} {uid 42b9 } } +Function {update_current(Fl_Input* o, void *v, + std::function<std::string()> getter, + std::function<void(std::string)> setter)} {uid a6e0 open private return_type void +} { + code {if (v == LOAD) { + o->value( getter().c_str() ); +} else { + std::string v = o->value(); + if (v != getter()) { + setter(v); + Fluid.proj.set_modflag(1); + } +}} {uid e438 + } +} + +Function {update_current(Fl_Text_Editor* o, void *v, + std::function<std::string()> getter, + std::function<void(std::string)> setter)} {uid 7c05 open private return_type void +} { + code {if (v == LOAD) { + o->buffer()->text( getter().c_str() ); +} else { + std::string v = o->buffer()->text(); + if (v != getter()) { + setter(v); + Fluid.proj.set_modflag(1); + } +}} {uid c364 + } +} + Function {make_image_panel()} {uid b832 comment {Create a panel for editing widget image data} } { @@ -484,7 +519,7 @@ Function {make_widget_panel()} {uid 9310 } { Fl_Window {} {uid 30ee comment {Use a Double Window to avoid flickering.} open - xywh {485 255 420 400} type Double labelsize 11 align 80 resizable hotspot + xywh {406 252 420 400} type Double labelsize 11 align 80 resizable hotspot code0 {o->size_range(o->w(), o->h());} size_range {420 400 0 0} visible } { Fl_Wizard tabs_wizard {uid 647f @@ -493,7 +528,7 @@ Function {make_widget_panel()} {uid 9310 } { Fl_Tabs widget_tabs {uid ce20 callback {if (current_widget) - propagate_load((Fl_Group *)o,v);} + propagate_load((Fl_Group *)o,v);} selected xywh {10 10 400 350} selection_color 12 labelsize 11 labelcolor 7 when 0 code0 {o->show();} } { @@ -2746,21 +2781,11 @@ if (v == LOAD) { label {Filename:} callback {if (!current_node || !current_node->is_a(Type::Data)) return; Data_Node* nd = (Data_Node*)current_node; - -if (v == LOAD) { - const char *fn = nd->filename(); - o->value( fn ? fn : "" ); -} else { - const char *c = o->value(); - const char *fn = nd->filename(); - if ( ( fn && (strcmp(fn, c) != 0)) - || (!fn && (strcmp("", c) != 0)) ) - { - nd->filename(c); - Fluid.proj.set_modflag(1); - } -}} - tooltip {name and path of file that will be inlined} xywh {95 125 270 20} labelfont 1 labelsize 11 align 132 textfont 4 textsize 11 +update_current(o, v, + [nd](){return nd->filename();}, + [nd](std::string s){nd->filename(s);} +);} + tooltip {name and path of file that will be inlined} xywh {95 125 270 20} labelfont 1 labelsize 11 align 132 textfont 4 textsize 11 resizable } Fl_Button {} {uid a0fe label {@fileopen} @@ -2799,7 +2824,7 @@ if (v == LOAD) { } free(c); }} - xywh {95 150 310 105} box DOWN_BOX labelfont 1 labelsize 11 align 4 textfont 4 textsize 11 resizable + xywh {95 150 310 105} box DOWN_BOX labelfont 1 labelsize 11 align 4 textfont 4 textsize 11 code0 {o->buffer(new Fl_Text_Buffer());} code1 {o->add_key_binding(FL_Tab, 0, use_tab_navigation);} } @@ -3171,15 +3196,10 @@ if (v == LOAD) { label {End Code:} callback {if (!current_node || !current_node->is_a(Type::DeclBlock)) return; DeclBlock_Node* nd = (DeclBlock_Node*)current_node; - if (v == LOAD) { - o->value( nd->end_code().c_str() ); -} else { - std::string v = o->value(); - if (v != nd->end_code()) { - nd->end_code( v ); - Fluid.proj.set_modflag(1); - } -}} +update_current(o, v, + [nd](){return nd->end_code();}, + [nd](std::string s){nd->end_code(s);} +);} tooltip {`\#endif` or similar declaration code block} xywh {95 75 305 20} labelfont 1 labelsize 11 textfont 4 textsize 11 } Fl_Group {} {uid 9b63 |
