diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2005-11-03 20:43:19 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2005-11-03 20:43:19 +0000 |
| commit | 1a5288e8feb3673fa864d4aa4e4c09c9577a0670 (patch) | |
| tree | a23a587c1f13fcc490ae35e57dc0735007d9ee01 /fluid/fluid.cxx | |
| parent | 5cdf984737d7a7f55006e3ca04f28451dfe2099c (diff) | |
Fluid Source Code preview panel with automatic refresh and selected object code highlighting.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4630 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'fluid/fluid.cxx')
| -rw-r--r-- | fluid/fluid.cxx | 150 |
1 files changed, 149 insertions, 1 deletions
diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index 789d1bac0..cf52c3260 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -381,6 +381,14 @@ void exit_cb(Fl_Widget *,void *) { save_position(widgetbin_panel,"widgetbin_pos"); delete widgetbin_panel; } + if (sourceview_panel) { + Fl_Preferences svp(fluid_prefs, "sourceview"); + svp.set("autorefresh", sv_autorefresh->value()); + svp.set("autoposition", sv_autoposition->value()); + svp.set("tab", sv_tab->find(sv_tab->value())); + save_position(sourceview_panel,"sourceview_pos"); + delete sourceview_panel; + } if (about_panel) delete about_panel; if (help_dialog) @@ -1550,6 +1558,7 @@ void print_cb(Fl_Return_Button *, void *) { extern Fl_Menu_Item New_Menu[]; void toggle_widgetbin_cb(Fl_Widget *, void *); +void toggle_sourceview_cb(Fl_Double_Window *, void *); Fl_Menu_Item Main_Menu[] = { {"&File",0,0,0,FL_SUBMENU}, @@ -1596,7 +1605,9 @@ Fl_Menu_Item Main_Menu[] = { {"Ung&roup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER}, {"Hide O&verlays",FL_CTRL+FL_SHIFT+'o',toggle_overlays}, #define WIDGETBIN_ITEM 41 - {"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_cb, 0, FL_MENU_DIVIDER}, + {"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_cb}, +#define SOURCEVIEW_ITEM 42 + {"Show Source Code...",FL_ALT+FL_SHIFT+'s', (Fl_Callback*)toggle_sourceview_cb, 0, FL_MENU_DIVIDER}, {"Pro&ject Settings...",FL_ALT+'p',show_project_cb}, {"GU&I Settings...",FL_ALT+FL_SHIFT+'p',show_settings_cb}, {0}, @@ -1688,6 +1699,37 @@ void toggle_widgetbin_cb(Fl_Widget *, void *) { } +void toggle_sourceview_cb(Fl_Double_Window *, void *) { + 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)); + if (!position_window(sourceview_panel,"sourceview_pos", 0, 320, 120, 550, 500)) return; + } + + if (sourceview_panel->visible()) { + sourceview_panel->hide(); + Main_Menu[SOURCEVIEW_ITEM].label("Show Source Code..."); + } else { + sourceview_panel->show(); + Main_Menu[SOURCEVIEW_ITEM].label("Hide Source Code..."); + update_sourceview_cb(0,0); + } +} + +void toggle_sourceview_b_cb(Fl_Button*, void *) { + toggle_sourceview_cb(0,0); +} + void make_main_window() { fluid_prefs.get("snap", snap, 1); fluid_prefs.get("gridx", gridx, 5); @@ -1933,6 +1975,102 @@ void set_filename(const char *c) { set_modflag(modflag); } +// +// 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. +// +// Can we patent this? ;-) - Matt, mm@matthiasm.com +// + +// +// Update the header and source code highlighting depending on the +// currently selected object +// +void update_sourceview_position() +{ + if (sv_autoposition->value()==0) + return; + if (sourceview_panel && sourceview_panel->visible() && Fl_Type::current) { + int pos0, pos1; + if (sv_source->visible_r()) { + pos0 = Fl_Type::current->code_line; + pos1 = Fl_Type::current->code_line_end; + 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()) { + pos0 = Fl_Type::current->header_line; + pos1 = Fl_Type::current->header_line_end; + 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); + } + } + } +} + +void update_sourceview_position_cb(Fl_Tabs*, void*) +{ + update_sourceview_position(); +} + +static char *sv_source_filename = 0; +static char *sv_header_filename = 0; + +// +// Generate a header and source file in a temporary directory and +// load those into the Code Viewer widgets. +// +void update_sourceview_cb(Fl_Button*, void*) +{ + // generate space for the source and header file filenames + if (!sv_source_filename) { + sv_source_filename = (char*)malloc(FL_PATH_MAX); + fluid_prefs.getUserdataPath(sv_source_filename, FL_PATH_MAX); + strlcat(sv_source_filename, "source_view_tmp.cxx", FL_PATH_MAX); + } + if (!sv_header_filename) { + sv_header_filename = (char*)malloc(FL_PATH_MAX); + fluid_prefs.getUserdataPath(sv_header_filename, FL_PATH_MAX); + strlcat(sv_header_filename, "source_view_tmp.h", FL_PATH_MAX); + } + // generate the code and load the files + if (sourceview_panel && sourceview_panel->visible()) + { + write_sourceview = 1; + // generate files + if (write_code(sv_source_filename, sv_header_filename)) + { + // 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(); + } + write_sourceview = 0; + } +} + +void update_sourceview_timer(void*) +{ + update_sourceview_cb(0,0); +} + // Set the "modified" flag and update the title of the main window... void set_modflag(int mf) { const char *basename; @@ -1953,6 +2091,15 @@ void set_modflag(int mf) { main_window->label(title); } else main_window->label(basename); } + // if the UI was modified in any way, update the Source View panel + if (sourceview_panel && sourceview_panel->visible() && sv_autorefresh->value()) + { + // we will only update ealiest 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); + } // Enable/disable the Save menu item... if (modflag) Main_Menu[SAVE_ITEM].activate(); @@ -2030,6 +2177,7 @@ int main(int argc,char **argv) { position_window(main_window,"main_window_pos", 1, 10, 30, WINWIDTH, WINHEIGHT ); main_window->show(argc,argv); toggle_widgetbin_cb(0,0); + toggle_sourceview_cb(0,0); if (!c && openlast_button->value() && absolute_history[0][0]) { // Open previous file when no file specified... open_history_cb(0, absolute_history[0]); |
