diff options
| -rw-r--r-- | fluid/CodeEditor.cxx | 13 | ||||
| -rw-r--r-- | fluid/CodeEditor.h | 3 | ||||
| -rw-r--r-- | fluid/Fl_Type.cxx | 23 | ||||
| -rw-r--r-- | fluid/Fl_Type.h | 11 | ||||
| -rw-r--r-- | fluid/code.cxx | 55 | ||||
| -rw-r--r-- | fluid/file.cxx | 10 | ||||
| -rw-r--r-- | fluid/file.h | 7 | ||||
| -rw-r--r-- | fluid/fluid.cxx | 1 | ||||
| -rw-r--r-- | fluid/sourceview_panel.cxx | 108 | ||||
| -rw-r--r-- | fluid/sourceview_panel.fl | 121 | ||||
| -rw-r--r-- | fluid/sourceview_panel.fl2 | 365 | ||||
| -rw-r--r-- | fluid/sourceview_panel.h | 6 |
12 files changed, 652 insertions, 71 deletions
diff --git a/fluid/CodeEditor.cxx b/fluid/CodeEditor.cxx index 119090628..2243db2fe 100644 --- a/fluid/CodeEditor.cxx +++ b/fluid/CodeEditor.cxx @@ -316,3 +316,16 @@ TextViewer::~TextViewer() { buffer(0); delete buf; } + +/** + Tricking Fl_Text_Display into using bearable colors for this specific task. + */ +void TextViewer::draw() +{ + Fl_Color c = Fl::get_color(FL_SELECTION_COLOR); + Fl::set_color(FL_SELECTION_COLOR, fl_color_average(FL_BACKGROUND_COLOR, FL_FOREGROUND_COLOR, 0.9f)); + Fl_Text_Display::draw(); + Fl::set_color(FL_SELECTION_COLOR, c); +} + + diff --git a/fluid/CodeEditor.h b/fluid/CodeEditor.h index f8e7f8299..50908ebe5 100644 --- a/fluid/CodeEditor.h +++ b/fluid/CodeEditor.h @@ -66,13 +66,14 @@ protected: void draw() FL_OVERRIDE; }; -// ---- DesignViewer declaration +// ---- Project File Text Viewe declaration class TextViewer : public Fl_Text_Display { public: TextViewer(int X, int Y, int W, int H, const char *L=0); ~TextViewer(); int top_line() { return get_absolute_top_line_number(); } + void draw() FL_OVERRIDE; }; #endif // !CodeEditor_h diff --git a/fluid/Fl_Type.cxx b/fluid/Fl_Type.cxx index dc187c260..6142a0beb 100644 --- a/fluid/Fl_Type.cxx +++ b/fluid/Fl_Type.cxx @@ -347,7 +347,16 @@ void update_visibility_flag(Fl_Type *p) { /** Constructor and base for any node in the widget tree. */ -Fl_Type::Fl_Type() { +Fl_Type::Fl_Type() : +code_include_start(-1), code_include_end(-1), +code_static_start(-1), code_static_end(-1), +code1_start(-1), code1_end(-1), +code2_start(-1), code2_end(-1), +header_start(-1), header_end(-1), +header_static_start(-1), header_static_end(-1), +proj1_start(-1), proj1_end(-1), +proj2_start(-1), proj2_end(-1) +{ factory = 0; parent = 0; next = prev = 0; @@ -360,8 +369,6 @@ Fl_Type::Fl_Type() { callback_ = 0; comment_ = 0; level = 0; - code_position = header_position = -1; - code_position_end = header_position_end = -1; } /** @@ -669,6 +676,8 @@ void Fl_Type::move_before(Fl_Type* g) { // write a widget and all its children: void Fl_Type::write(Fd_Project_Writer &f) { + if (f.write_sourceview()) proj1_start = (int)ftell(f.file()) + 1; + if (f.write_sourceview()) proj2_start = (int)ftell(f.file()) + 1; f.write_indent(level); f.write_word(type_name()); @@ -683,13 +692,19 @@ void Fl_Type::write(Fd_Project_Writer &f) { write_properties(f); if (parent) parent->write_parent_properties(f, this, true); f.write_close(level); - if (!is_parent()) return; + if (f.write_sourceview()) proj1_end = (int)ftell(f.file()); + if (!is_parent()) { + if (f.write_sourceview()) proj2_end = (int)ftell(f.file()); + return; + } // now do children: f.write_open(level); Fl_Type *child; for (child = next; child && child->level > level; child = child->next) if (child->level == level+1) child->write(f); + if (f.write_sourceview()) proj2_start = (int)ftell(f.file()) + 1; f.write_close(level); + if (f.write_sourceview()) proj2_end = (int)ftell(f.file()); } void Fl_Type::write_properties(Fd_Project_Writer &f) { diff --git a/fluid/Fl_Type.h b/fluid/Fl_Type.h index b33690f58..0226696f5 100644 --- a/fluid/Fl_Type.h +++ b/fluid/Fl_Type.h @@ -144,8 +144,15 @@ public: // things that should not be public: Fl_Type *factory; const char *callback_name(Fd_Code_Writer& f); - int code_position, header_position; - int code_position_end, header_position_end; + // text positions of this type in code, header, and project file (see SourceView) + int code_include_start, code_include_end; + int code_static_start, code_static_end; + int code1_start, code1_end; + int code2_start, code2_end; + int header_start, header_end; + int header_static_start, header_static_end; + int proj1_start, proj1_end; + int proj2_start, proj2_end; protected: int user_defined(const char* cbname) const; diff --git a/fluid/code.cxx b/fluid/code.cxx index f9f28c3ec..b4c5c9c9d 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -649,15 +649,14 @@ void Fd_Code_Writer::write_c_indented(const char *textlines, int inIndent, char Recursively dump code, putting children between the two parts of the parent code. */ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) { - if (write_sourceview) { - p->code_position = (int)ftell(code_file); - if (p->header_position_end==-1) - p->header_position = (int)ftell(header_file); - } + if (write_sourceview) p->header_start = (int)ftell(header_file); // write all code that come before the children code // (but don't write the last comment until the very end) - if (!(p==Fl_Type::last && p->is_a(ID_Comment))) + if (!(p==Fl_Type::last && p->is_a(ID_Comment))) { + if (write_sourceview) p->code1_start = (int)ftell(code_file); p->write_code1(*this); + if (write_sourceview) p->code1_end = (int)ftell(code_file); + } // recursively write the code of all children Fl_Type* q; if (p->is_widget() && p->is_class()) { @@ -673,7 +672,9 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) { } // write all code that come after the children + if (write_sourceview) p->code2_start = (int)ftell(header_file); p->write_code2(*this); + if (write_sourceview) p->code2_end = (int)ftell(code_file); for (q = p->next; q && q->level > p->level;) { if (q->is_a(ID_Function)) q = write_code(q); @@ -690,13 +691,11 @@ Fl_Type* Fd_Code_Writer::write_code(Fl_Type* p) { } else { for (q = p->next; q && q->level > p->level;) q = write_code(q); // write all code that come after the children + if (write_sourceview) p->code2_start = (int)ftell(code_file); p->write_code2(*this); + if (write_sourceview) p->code2_end = (int)ftell(code_file); } - if (write_sourceview) { - p->code_position_end = (int)ftell(code_file); - if (p->header_position_end==-1) - p->header_position_end = (int)ftell(header_file); - } + if (write_sourceview) p->header_end = (int)ftell(header_file); return q; } @@ -735,14 +734,14 @@ int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_sourceview) Fl_Type* first_type = Fl_Type::first; if (first_type && first_type->is_a(ID_Comment)) { if (write_sourceview) { - first_type->code_position = (int)ftell(code_file); - first_type->header_position = (int)ftell(header_file); + first_type->code1_start = first_type->code2_start = (int)ftell(code_file); + first_type->header_start = (int)ftell(header_file); } // it is ok to write non-recursive code here, because comments have no children or code2 blocks first_type->write_code1(*this); if (write_sourceview) { - first_type->code_position_end = (int)ftell(code_file); - first_type->header_position_end = (int)ftell(header_file); + first_type->code1_end = first_type->code2_end = (int)ftell(code_file); + first_type->header_end = (int)ftell(header_file); } first_type = first_type->next; } @@ -827,19 +826,17 @@ int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_sourceview) } for (Fl_Type* p = first_type; p;) { // write all static data for this & all children first - if (write_sourceview) p->header_position = (int)ftell(header_file); + if (write_sourceview) p->header_static_start = (int)ftell(header_file); + if (write_sourceview) p->code_static_start = (int)ftell(code_file); p->write_static(*this); - if (write_sourceview) { - p->header_position_end = (int)ftell(header_file); - if (p->header_position==p->header_position_end) p->header_position_end = -1; - } + if (write_sourceview) p->code_static_end = (int)ftell(code_file); + if (write_sourceview) p->header_static_end = (int)ftell(header_file); for (Fl_Type* q = p->next; q && q->level > p->level; q = q->next) { - if (write_sourceview) q->header_position = (int)ftell(header_file); + if (write_sourceview) q->header_static_start = (int)ftell(header_file); + if (write_sourceview) q->code_static_start = (int)ftell(code_file); q->write_static(*this); - if (write_sourceview) { - q->header_position_end = (int)ftell(header_file); - if (q->header_position==q->header_position_end) q->header_position_end = -1; - } + if (write_sourceview) q->code_static_end = (int)ftell(code_file); + if (write_sourceview) q->header_static_end = (int)ftell(header_file); } // then write the nested code: p = write_code(p); @@ -852,13 +849,13 @@ int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_sourceview) Fl_Type* last_type = Fl_Type::last; if (last_type && last_type->is_a(ID_Comment)) { if (write_sourceview) { - last_type->code_position = (int)ftell(code_file); - last_type->header_position = (int)ftell(header_file); + last_type->code1_start = last_type->code2_start = (int)ftell(code_file); + last_type->header_start = (int)ftell(header_file); } last_type->write_code1(*this); if (write_sourceview) { - last_type->code_position_end = (int)ftell(code_file); - last_type->header_position_end = (int)ftell(header_file); + last_type->code1_end = last_type->code2_end = (int)ftell(code_file); + last_type->header_end = (int)ftell(header_file); } } int x = 0, y = 0; diff --git a/fluid/file.cxx b/fluid/file.cxx index a62294203..fdfc203a7 100644 --- a/fluid/file.cxx +++ b/fluid/file.cxx @@ -73,9 +73,9 @@ int read_file(const char *filename, int merge, Strategy strategy) { is used to implement copy and paste. \return 0 if the operation failed, 1 if it succeeded */ -int write_file(const char *filename, int selected_only) { +int write_file(const char *filename, int selected_only, bool to_sourceview) { Fd_Project_Writer out; - return out.write_project(filename, selected_only); + return out.write_project(filename, selected_only, to_sourceview); } /** @@ -718,7 +718,8 @@ void Fd_Project_Reader::read_fdesign() { /** \brief Construct local project writer. */ Fd_Project_Writer::Fd_Project_Writer() : fout(NULL), - needspace(0) + needspace(0), + write_sourceview_(false) { } @@ -763,7 +764,8 @@ int Fd_Project_Writer::close_write() { is used to implement copy and paste. \return 0 if the operation failed, 1 if it succeeded */ -int Fd_Project_Writer::write_project(const char *filename, int selected_only) { +int Fd_Project_Writer::write_project(const char *filename, int selected_only, bool sv) { + write_sourceview_ = sv; undo_suspend(); if (!open_write(filename)) { undo_resume(); diff --git a/fluid/file.h b/fluid/file.h index e45bd4256..3db9a974b 100644 --- a/fluid/file.h +++ b/fluid/file.h @@ -26,7 +26,7 @@ class Fl_Type; extern int fdesign_flip; int read_file(const char *, int merge, Strategy strategy=kAddAsLastChild); -int write_file(const char *, int selected_only = 0); +int write_file(const char *, int selected_only = 0, bool to_sourceview = false); class Fd_Project_Reader { @@ -62,18 +62,21 @@ class Fd_Project_Writer protected: FILE *fout; int needspace; + bool write_sourceview_; public: Fd_Project_Writer(); ~Fd_Project_Writer(); int open_write(const char *s); int close_write(); - int write_project(const char *filename, int selected_only); + int write_project(const char *filename, int selected_only, bool sourceview); void write_word(const char *); void write_string(const char *,...) __fl_attr((__format__ (__printf__, 2, 3))); void write_indent(int n); void write_open(int); void write_close(int n); + FILE *file() const { return fout; } + bool write_sourceview() const { return write_sourceview_; } }; #endif // _FLUID_FILE_H diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index ae4284f3c..c75958493 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -826,6 +826,7 @@ void exit_cb(Fl_Widget *,void *) { svp.set("autorefresh", sv_autorefresh->value()); svp.set("autoposition", sv_autoposition->value()); svp.set("tab", sv_tab->find(sv_tab->value())); + svp.set("code_choice", sv_code_choice); save_position(sourceview_panel,"sourceview_pos"); delete sourceview_panel; sourceview_panel = 0; diff --git a/fluid/sourceview_panel.cxx b/fluid/sourceview_panel.cxx index 0c57ae9f4..bfee26654 100644 --- a/fluid/sourceview_panel.cxx +++ b/fluid/sourceview_panel.cxx @@ -25,11 +25,12 @@ static char *sv_source_filename = NULL; static char *sv_header_filename = NULL; static char *sv_design_filename = NULL; +int sv_code_choice; /** Update the header and source code highlighting depending on the currently selected object - + The Source View system offers an immediate preview of the code files that will be generated by FLUID. It also marks the code generated for the last selected item in the header and the source @@ -43,27 +44,83 @@ void update_sourceview_position() { if (sourceview_panel && sourceview_panel->visible() && Fl_Type::current) { int pos0, pos1; if (sv_source->visible_r()) { - pos0 = Fl_Type::current->code_position; - pos1 = Fl_Type::current->code_position_end; + switch (sv_code_choice) { + case 0: // prolog: not yet (include statements) + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code2_end; + break; + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->code_static_start; + pos1 = Fl_Type::current->code_static_end; + break; + case 2: // code: entire implementation block including children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code2_end; + break; + case 3: // code1: all implementation code before the children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code1_end; + break; + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->code2_start; + pos1 = Fl_Type::current->code2_end; + break; + } if (pos0>=0) { if (pos1<pos0) - pos1 = pos0; + pos1 = sv_source->buffer()->line_end(pos0); sv_source->buffer()->highlight(pos0, pos1); int line = sv_source->buffer()->count_lines(0, pos0); sv_source->scroll(line, 0); } } if (sv_header->visible_r()) { - pos0 = Fl_Type::current->header_position; - pos1 = Fl_Type::current->header_position_end; + switch (sv_code_choice) { + case 2: // code: entire implementation block including children + case 3: // code1: all implementation code before the children + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->header_start; + pos1 = Fl_Type::current->header_end; + break; + case 0: // prolog: not yet (include statements) + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->header_static_start; + pos1 = Fl_Type::current->header_static_end; + break; + } if (pos0>=0) { if (pos1<pos0) - pos1 = pos0; + pos1 = sv_header->buffer()->line_end(pos0); sv_header->buffer()->highlight(pos0, pos1); int line = sv_header->buffer()->count_lines(0, pos0); sv_header->scroll(line, 0); } } + if (sv_project->visible_r()) { + switch (sv_code_choice) { + case 0: // prolog: not yet (include statements) + case 1: // static: callbacks, menu declarations + case 2: // code: entire implementation block including children + pos0 = Fl_Type::current->proj1_start; + pos1 = Fl_Type::current->proj2_end; + break; + case 3: // code1: all implementation code before the children + pos0 = Fl_Type::current->proj1_start; + pos1 = Fl_Type::current->proj1_end; + break; + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->proj2_start; + pos1 = Fl_Type::current->proj2_end; + break; + } + if (pos0>=0) { + if (pos1<pos0) + pos1 = sv_project->buffer()->line_end(pos0); + sv_project->buffer()->highlight(pos0, pos1); + int line = sv_project->buffer()->count_lines(0, pos0); + sv_project->scroll(line, 0); + } + } } } @@ -102,7 +159,7 @@ void update_sourceview_cb(class Fl_Button*, void*) { } if (sv_project->visible_r()) { - write_file(sv_design_filename); + write_file(sv_design_filename, false, true); int top = sv_project->top_line(); sv_project->buffer()->loadfile(sv_design_filename); sv_project->scroll(top, 0); @@ -177,6 +234,8 @@ void sourceview_toggle_visibility() { int tab; svp.get("tab", tab, 0); if (tab>=0 && tab<sv_tab->children()) sv_tab->value(sv_tab->child(tab)); + svp.get("code_choice", sv_code_choice, 2); + sv_code_choice_w->value(sv_code_choice_w->find_item_with_argument(sv_code_choice)); if (!position_window(sourceview_panel,"sourceview_pos", 0, 320, 120, 550, 500)) return; } @@ -206,6 +265,22 @@ Fl_Light_Button *sv_autorefresh=(Fl_Light_Button *)0; Fl_Light_Button *sv_autoposition=(Fl_Light_Button *)0; +Fl_Choice *sv_code_choice_w=(Fl_Choice *)0; + +static void cb_sv_code_choice_w(Fl_Choice* o, void*) { + sv_code_choice = (int)o->mvalue()->argument(); + update_sourceview_position(); +} + +Fl_Menu_Item menu_sv_code_choice_w[] = { + {"prolog", 0, 0, (void*)(0), 16, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"static", 0, 0, (void*)(1), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"code", 0, 0, (void*)(2), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"code 1", 0, 0, (void*)(3), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"code 2", 0, 0, (void*)(4), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {0,0,0,0,0,0,0,0,0} +}; + Fl_Double_Window* make_sourceview() { { sourceview_panel = new Fl_Double_Window(520, 490, "Code View"); sourceview_panel->callback((Fl_Callback*)toggle_sourceview_cb); @@ -301,25 +376,32 @@ Fl_Double_Window* make_sourceview() { sv_tab->end(); Fl_Group::current()->resizable(sv_tab); } // Fl_Tabs* sv_tab - { Fl_Group* o = new Fl_Group(10, 460, 500, 20); + { Fl_Group* o = new Fl_Group(10, 460, 500, 22); { Fl_Button* o = new Fl_Button(10, 460, 61, 20, "Refresh"); o->labelsize(11); o->callback((Fl_Callback*)update_sourceview_cb); } // Fl_Button* o - { Fl_Light_Button* o = sv_autorefresh = new Fl_Light_Button(76, 460, 91, 20, "Auto-Refresh"); + { Fl_Light_Button* o = sv_autorefresh = new Fl_Light_Button(77, 460, 91, 20, "Auto-Refresh"); sv_autorefresh->labelsize(11); o->callback((Fl_Callback*)update_sourceview_cb); } // Fl_Light_Button* sv_autorefresh { sv_autoposition = new Fl_Light_Button(172, 460, 89, 20, "Auto-Position"); sv_autoposition->labelsize(11); } // Fl_Light_Button* sv_autoposition + { sv_code_choice_w = new Fl_Choice(265, 460, 70, 20); + sv_code_choice_w->down_box(FL_BORDER_BOX); + sv_code_choice_w->labelsize(11); + sv_code_choice_w->textsize(11); + sv_code_choice_w->callback((Fl_Callback*)cb_sv_code_choice_w); + sv_code_choice_w->menu(menu_sv_code_choice_w); + } // Fl_Choice* sv_code_choice_w + { Fl_Box* o = new Fl_Box(375, 460, 80, 20); + Fl_Group::current()->resizable(o); + } // Fl_Box* o { Fl_Button* o = new Fl_Button(460, 460, 50, 20, "Close"); o->labelsize(11); o->callback((Fl_Callback*)toggle_sourceview_b_cb); } // Fl_Button* o - { Fl_Box* o = new Fl_Box(265, 460, 190, 20); - Fl_Group::current()->resizable(o); - } // Fl_Box* o o->end(); } // Fl_Group* o sourceview_panel->size_range(384, 120); diff --git a/fluid/sourceview_panel.fl b/fluid/sourceview_panel.fl index 61f6242a9..7f221c43e 100644 --- a/fluid/sourceview_panel.fl +++ b/fluid/sourceview_panel.fl @@ -44,6 +44,9 @@ decl {char *sv_header_filename = NULL;} {private local decl {char *sv_design_filename = NULL;} {private local } +decl {int sv_code_choice;} {public local +} + Function {update_sourceview_position()} { comment {Update the header and source code highlighting depending on the currently selected object @@ -60,27 +63,83 @@ file.} open return_type void if (sourceview_panel && sourceview_panel->visible() && Fl_Type::current) { int pos0, pos1; if (sv_source->visible_r()) { - pos0 = Fl_Type::current->code_position; - pos1 = Fl_Type::current->code_position_end; + switch (sv_code_choice) { + case 0: // prolog: not yet (include statements) + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code2_end; + break; + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->code_static_start; + pos1 = Fl_Type::current->code_static_end; + break; + case 2: // code: entire implementation block including children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code2_end; + break; + case 3: // code1: all implementation code before the children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code1_end; + break; + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->code2_start; + pos1 = Fl_Type::current->code2_end; + break; + } if (pos0>=0) { if (pos1<pos0) - pos1 = pos0; + pos1 = sv_source->buffer()->line_end(pos0); sv_source->buffer()->highlight(pos0, pos1); int line = sv_source->buffer()->count_lines(0, pos0); sv_source->scroll(line, 0); } } if (sv_header->visible_r()) { - pos0 = Fl_Type::current->header_position; - pos1 = Fl_Type::current->header_position_end; + switch (sv_code_choice) { + case 2: // code: entire implementation block including children + case 3: // code1: all implementation code before the children + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->header_start; + pos1 = Fl_Type::current->header_end; + break; + case 0: // prolog: not yet (include statements) + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->header_static_start; + pos1 = Fl_Type::current->header_static_end; + break; + } if (pos0>=0) { if (pos1<pos0) - pos1 = pos0; + pos1 = sv_header->buffer()->line_end(pos0); sv_header->buffer()->highlight(pos0, pos1); int line = sv_header->buffer()->count_lines(0, pos0); sv_header->scroll(line, 0); } } + if (sv_project->visible_r()) { + switch (sv_code_choice) { + case 0: // prolog: not yet (include statements) + case 1: // static: callbacks, menu declarations + case 2: // code: entire implementation block including children + pos0 = Fl_Type::current->proj1_start; + pos1 = Fl_Type::current->proj2_end; + break; + case 3: // code1: all implementation code before the children + pos0 = Fl_Type::current->proj1_start; + pos1 = Fl_Type::current->proj1_end; + break; + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->proj2_start; + pos1 = Fl_Type::current->proj2_end; + break; + } + if (pos0>=0) { + if (pos1<pos0) + pos1 = sv_project->buffer()->line_end(pos0); + sv_project->buffer()->highlight(pos0, pos1); + int line = sv_project->buffer()->count_lines(0, pos0); + sv_project->scroll(line, 0); + } + } }} {} } @@ -117,7 +176,7 @@ and load those into the Code Viewer widgets.} open return_type void } if (sv_project->visible_r()) { - write_file(sv_design_filename); + write_file(sv_design_filename, false, true); int top = sv_project->top_line(); sv_project->buffer()->loadfile(sv_design_filename); sv_project->scroll(top, 0); @@ -156,8 +215,7 @@ and load those into the Code Viewer widgets.} open return_type void g_project.code_file_name = code_file_name_bak; g_project.header_file_name = header_file_name_bak; - }} {selected - } + }} {} } Function {update_sourceview_timer(void*)} { @@ -194,6 +252,8 @@ The state is stored in the app preferences. int tab; svp.get("tab", tab, 0); if (tab>=0 && tab<sv_tab->children()) sv_tab->value(sv_tab->child(tab)); + svp.get("code_choice", sv_code_choice, 2); + sv_code_choice_w->value(sv_code_choice_w->find_item_with_argument(sv_code_choice)); if (!position_window(sourceview_panel,"sourceview_pos", 0, 320, 120, 550, 500)) return; } @@ -215,7 +275,7 @@ Function {make_sourceview()} {open xywh {400 569 520 490} type Double align 80 resizable size_range {384 120 0 0} visible } { Fl_Tabs sv_tab { - callback update_sourceview_position_cb open + callback update_sourceview_position_cb open selected xywh {10 10 500 440} selection_color 4 labelcolor 7 resizable } { Fl_Group {} { @@ -266,7 +326,7 @@ Function {make_sourceview()} {open } } Fl_Group {} {open - xywh {10 460 500 20} + xywh {10 460 500 22} } { Fl_Button {} { label Refresh @@ -275,21 +335,52 @@ Function {make_sourceview()} {open } Fl_Light_Button sv_autorefresh { label {Auto-Refresh} - xywh {76 460 91 20} labelsize 11 + xywh {77 460 91 20} labelsize 11 code0 {o->callback((Fl_Callback*)update_sourceview_cb);} } Fl_Light_Button sv_autoposition { label {Auto-Position} xywh {172 460 89 20} labelsize 11 } + Fl_Choice sv_code_choice_w { + callback {sv_code_choice = (int)o->mvalue()->argument(); +update_sourceview_position();} open + xywh {265 460 70 20} down_box BORDER_BOX labelsize 11 textsize 11 + } { + MenuItem {} { + label prolog + user_data 0 user_data_type long + tooltip {Include statements in header or source code} xywh {0 0 100 20} labelsize 11 hide + } + MenuItem {} { + label static + user_data 1 user_data_type long + tooltip {static declarations in source code} xywh {10 10 100 20} labelsize 11 + } + MenuItem {} { + label code + user_data 2 user_data_type long + tooltip {widget code block including children} xywh {20 20 100 20} labelsize 11 + } + MenuItem {} { + label {code 1} + user_data 3 user_data_type long + tooltip {widget code block before children} xywh {30 30 100 20} labelsize 11 + } + MenuItem {} { + label {code 2} + user_data 4 user_data_type long + tooltip {widget code block after children} xywh {40 40 100 20} labelsize 11 + } + } + Fl_Box {} { + xywh {375 460 80 20} resizable + } Fl_Button {} { label Close callback toggle_sourceview_b_cb xywh {460 460 50 20} labelsize 11 } - Fl_Box {} { - xywh {265 460 190 20} resizable - } } } } diff --git a/fluid/sourceview_panel.fl2 b/fluid/sourceview_panel.fl2 new file mode 100644 index 000000000..bc4179292 --- /dev/null +++ b/fluid/sourceview_panel.fl2 @@ -0,0 +1,365 @@ +# data file for the Fltk User Interface Designer (fluid) +version 1.0400 +header_name {.h} +code_name {.cxx} +comment {// +// Code dialogs for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2023 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// +} {in_source in_header +} + +decl {\#include "fluid.h"} {private local +} + +decl {\#include "file.h"} {private local +} + +decl {\#include "../src/flstring.h"} {private local +} + +decl {\#include <FL/Fl_Tabs.H>} {private local +} + +decl {\#include <FL/Fl_Button.H>} {private local +} + +decl {char *sv_source_filename = NULL;} {private local +} + +decl {char *sv_header_filename = NULL;} {private local +} + +decl {char *sv_design_filename = NULL;} {private local +} + +decl {int sv_code_choice;} {public local +} + +Function {update_sourceview_position()} { + comment {Update the header and source code highlighting depending on the +currently selected object + +The Source View system offers an immediate preview of the code +files that will be generated by FLUID. It also marks the code +generated for the last selected item in the header and the source +file.} open return_type void +} { + code {if (!sourceview_panel || !sourceview_panel->visible()) + return; + if (sv_autoposition->value()==0) + return; + if (sourceview_panel && sourceview_panel->visible() && Fl_Type::current) { + int pos0, pos1; + if (sv_source->visible_r()) { + switch (sv_code_choice) { + case 0: // prolog: not yet (include statements) + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code1_end; + break; + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->code_static_start; + pos1 = Fl_Type::current->code_static_end; + break; + case 2: // code: entire implementation block including children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code2_end; + break; + case 3: // code1: all implementation code before the children + pos0 = Fl_Type::current->code1_start; + pos1 = Fl_Type::current->code1_end; + break; + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->code2_start; + pos1 = Fl_Type::current->code2_end; + break; + } + if (pos0>=0) { + if (pos1<pos0) + pos1 = pos0; + sv_source->buffer()->highlight(pos0, pos1); + int line = sv_source->buffer()->count_lines(0, pos0); + sv_source->scroll(line, 0); + } + } + if (sv_header->visible_r()) { + switch (sv_code_choice) { + case 2: // code: entire implementation block including children + case 3: // code1: all implementation code before the children + case 4: // code1: all implementation code before the children + pos0 = Fl_Type::current->header_start; + pos1 = Fl_Type::current->header_end; + break; + case 0: // prolog: not yet (include statements) + case 1: // static: callbacks, menu declarations + pos0 = Fl_Type::current->header_static_start; + pos1 = Fl_Type::current->header_static_end; + break; + } + if (pos0>=0) { + if (pos1<pos0) + pos1 = pos0; + sv_header->buffer()->highlight(pos0, pos1); + int line = sv_header->buffer()->count_lines(0, pos0); + sv_header->scroll(line, 0); + } + } + }} {} +} + +Function {update_sourceview_position_cb(class Fl_Tabs*, void*)} { + comment {Callback to update the sourceview position.} open return_type void +} { + code {// make sure that the selected tab shows the current view + update_sourceview_cb(0,0); + // highlight the selected widget in the selected tab + update_sourceview_position();} {} +} + +Function {update_sourceview_cb(class Fl_Button*, void*)} { + comment {Generate a header, source, strings, or design file in a temporary directory +and load those into the Code Viewer widgets.} open return_type void +} { + code {if (!sourceview_panel || !sourceview_panel->visible()) + return; + + if (!sv_source_filename) { + sv_source_filename = (char*)malloc(FL_PATH_MAX); + fl_strlcpy(sv_source_filename, get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcat(sv_source_filename, "source_view_tmp.cxx", FL_PATH_MAX); + } + if (!sv_header_filename) { + sv_header_filename = (char*)malloc(FL_PATH_MAX); + fl_strlcpy(sv_header_filename, get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcat(sv_header_filename, "source_view_tmp.h", FL_PATH_MAX); + } + if (!sv_design_filename) { + sv_design_filename = (char*)malloc(FL_PATH_MAX); + fl_strlcpy(sv_design_filename, get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcat(sv_design_filename, "source_view_tmp.fl", FL_PATH_MAX); + } + + if (sv_project->visible_r()) { + write_file(sv_design_filename); + int top = sv_project->top_line(); + sv_project->buffer()->loadfile(sv_design_filename); + sv_project->scroll(top, 0); + } else if (sv_strings->visible_r()) { + static const char *exts[] = { ".txt", ".po", ".msg" }; + char fn[FL_PATH_MAX+1]; + fl_strlcpy(fn, get_tmpdir().c_str(), FL_PATH_MAX); + fl_strlcat(fn, "strings", FL_PATH_MAX); + fl_filename_setext(fn, FL_PATH_MAX, exts[g_project.i18n_type]); + write_strings(fn); + int top = sv_strings->top_line(); + sv_strings->buffer()->loadfile(fn); + sv_strings->scroll(top, 0); + } else if (sv_source->visible_r() || sv_header->visible_r()) { + Fl_String code_file_name_bak = g_project.code_file_name; + g_project.code_file_name = sv_source_filename; + Fl_String header_file_name_bak = g_project.header_file_name; + g_project.header_file_name = sv_header_filename; + + // generate the code and load the files + Fd_Code_Writer f; + // generate files + if (f.write_code(sv_source_filename, sv_header_filename, true)) + { + // load file into source editor + int pos = sv_source->top_line(); + sv_source->buffer()->loadfile(sv_source_filename); + sv_source->scroll(pos, 0); + // load file into header editor + pos = sv_header->top_line(); + sv_header->buffer()->loadfile(sv_header_filename); + sv_header->scroll(pos, 0); + // update the source code highlighting + update_sourceview_position(); + } + + g_project.code_file_name = code_file_name_bak; + g_project.header_file_name = header_file_name_bak; + }} {} +} + +Function {update_sourceview_timer(void*)} { + comment {This is called by the timer itself +} open return_type void +} { + code {update_sourceview_cb(0,0);} {} +} + +Function {sourceview_defer_update()} {open return_type void +} { + code {// we will only update earliest 0.5 seconds after the last change, and only + // if no other change was made, so dragging a widget will not generate any + // CPU load + Fl::remove_timeout(update_sourceview_timer, 0); + Fl::add_timeout(0.5, update_sourceview_timer, 0);} {} +} + +Function {sourceview_toggle_visibility()} { + comment {Show or hide the source code preview. +The state is stored in the app preferences. +} open return_type void +} { + code {if (!sourceview_panel) { + make_sourceview(); + sourceview_panel->callback((Fl_Callback*)toggle_sourceview_cb); + Fl_Preferences svp(fluid_prefs, "sourceview"); + int autorefresh; + svp.get("autorefresh", autorefresh, 1); + sv_autorefresh->value(autorefresh); + int autoposition; + svp.get("autoposition", autoposition, 1); + sv_autoposition->value(autoposition); + int tab; + svp.get("tab", tab, 0); + if (tab>=0 && tab<sv_tab->children()) sv_tab->value(sv_tab->child(tab)); + svp.get("code_choice", sv_code_choice, 2); + sv_code_choice_w->value(sv_code_choice_w->find_item_with_argument(sv_code_choice)); + if (!position_window(sourceview_panel,"sourceview_pos", 0, 320, 120, 550, 500)) return; + } + + if (sourceview_panel->visible()) { + sourceview_panel->hide(); + sourceview_item->label("Show Source Code..."); + } else { + sourceview_panel->show(); + sourceview_item->label("Hide Source Code..."); + update_sourceview_cb(0,0); + }} {} +} + +Function {make_sourceview()} {open +} { + Fl_Window sourceview_panel { + label {Code View} + callback toggle_sourceview_cb open + xywh {400 569 520 490} type Double align 80 resizable size_range {384 120 0 0} visible + } { + Fl_Tabs sv_tab { + callback update_sourceview_position_cb open + xywh {10 10 500 440} selection_color 4 labelcolor 7 resizable + } { + Fl_Group {} { + label Source open + xywh {10 35 500 415} labelsize 13 resizable + } { + Fl_Text_Editor sv_source {selected + xywh {20 50 480 390} textfont 4 textsize 11 resizable + code0 {\#include "CodeEditor.h"} + code1 {o->linenumber_width(60);} + code2 {o->linenumber_size(o->Fl_Text_Display::textsize());} + class CodeViewer + } + } + Fl_Group {} { + label Header open + xywh {10 35 500 415} labelsize 13 hide + } { + Fl_Text_Editor sv_header { + xywh {20 50 480 390} textfont 4 textsize 11 resizable + code0 {\#include "CodeEditor.h"} + code1 {o->linenumber_width(60);} + code2 {o->linenumber_size(o->Fl_Text_Display::textsize());} + class CodeViewer + } + } + Fl_Group {} { + label Strings open + xywh {10 35 500 415} labelsize 13 hide + } { + Fl_Text_Display sv_strings { + xywh {20 50 480 390} textfont 4 textsize 11 resizable + code1 {o->linenumber_width(60);} + code2 {o->linenumber_size(o->Fl_Text_Display::textsize());} + class TextViewer + } + } + Fl_Group {} { + label Project open + xywh {10 35 500 415} labelsize 13 hide + } { + Fl_Text_Display sv_project { + xywh {20 50 480 390} textfont 4 textsize 11 resizable + code1 {o->linenumber_width(60);} + code2 {o->linenumber_size(o->Fl_Text_Display::textsize());} + class TextViewer + } + } + } + Fl_Group {} {open + xywh {10 460 500 22} + } { + Fl_Button {} { + label Refresh + callback update_sourceview_cb + xywh {10 460 61 20} labelsize 11 + } + Fl_Light_Button sv_autorefresh { + label {Auto-Refresh} + xywh {77 460 91 20} labelsize 11 + code0 {o->callback((Fl_Callback*)update_sourceview_cb);} + } + Fl_Light_Button sv_autoposition { + label {Auto-Position} + xywh {172 460 89 20} labelsize 11 + } + Fl_Choice sv_code_choice_w { + callback {sv_code_choice = (int)o->mvalue()->argument(); +update_sourceview_position();} open + xywh {265 460 70 20} down_box BORDER_BOX labelsize 11 textsize 11 + } { + MenuItem {} { + label prolog + user_data 0 user_data_type long + tooltip {Include statements in header or source code} xywh {0 0 100 20} labelsize 11 + } + MenuItem {} { + label static + user_data 1 user_data_type long + tooltip {static declarations in source code} xywh {10 10 100 20} labelsize 11 + } + MenuItem {} { + label code + user_data 2 user_data_type long + tooltip {widget code block including children} xywh {20 20 100 20} labelsize 11 + } + MenuItem {} { + label {code 1} + user_data 3 user_data_type long + tooltip {widget code block before children} xywh {30 30 100 20} labelsize 11 + } + MenuItem {} { + label {code 2} + user_data 4 user_data_type long + tooltip {widget code block after children} xywh {40 40 100 20} labelsize 11 + } + } + Fl_Box {} { + xywh {375 460 80 20} resizable + } + Fl_Button {} { + label Close + callback toggle_sourceview_b_cb + xywh {460 460 50 20} labelsize 11 + } + } + } +} + +comment { +//} {in_source in_header +} diff --git a/fluid/sourceview_panel.h b/fluid/sourceview_panel.h index 88b37450c..52b3a9566 100644 --- a/fluid/sourceview_panel.h +++ b/fluid/sourceview_panel.h @@ -19,6 +19,7 @@ #ifndef sourceview_panel_h #define sourceview_panel_h #include <FL/Fl.H> +extern int sv_code_choice; void update_sourceview_position(); void update_sourceview_position_cb(class Fl_Tabs*, void*); void update_sourceview_cb(class Fl_Button*, void*); @@ -40,9 +41,12 @@ extern TextViewer *sv_project; #include <FL/Fl_Light_Button.H> extern Fl_Light_Button *sv_autorefresh; extern Fl_Light_Button *sv_autoposition; -extern void toggle_sourceview_b_cb(Fl_Button*, void*); +#include <FL/Fl_Choice.H> +extern Fl_Choice *sv_code_choice_w; #include <FL/Fl_Box.H> +extern void toggle_sourceview_b_cb(Fl_Button*, void*); Fl_Double_Window* make_sourceview(); +extern Fl_Menu_Item menu_sv_code_choice_w[]; #endif // |
