diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-10-24 14:28:56 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-10-24 14:29:01 +0200 |
| commit | e8d218109e246b14df0cdf2d818e2575c8108e9f (patch) | |
| tree | 64c3f3ae1acd99f81fd54d6391591663981c9b23 /fluid/sourceview_panel.cxx | |
| parent | 5a8a28cbb5fd627dfd032b996cd83d0965d9ac5e (diff) | |
FLUID: Adds much more detailed CodeView
in preparation for "find" and "reveal"
Diffstat (limited to 'fluid/sourceview_panel.cxx')
| -rw-r--r-- | fluid/sourceview_panel.cxx | 108 |
1 files changed, 95 insertions, 13 deletions
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); |
