STR 3426: indicating in the title bar if the design is newer than the code file.

In this first version, we assume that the code file is newer whenever it is written,
until the current design is modified in any way. So instead of a status bar at the bottom
of the main window, the title bar will now show the status of the design and the code at
the same place.
This commit is contained in:
Matthias Melcher 2021-12-10 01:22:15 +01:00
parent a4b6175dbe
commit 5655f79d63
6 changed files with 106 additions and 65 deletions

View File

@ -25,6 +25,7 @@ Fl_Double_Window *project_window=(Fl_Double_Window *)0;
static void cb_Close(Fl_Button*, void*) {
project_window->hide();
set_modflag(-1, -1);
}
Fl_Input *header_file_input=(Fl_Input *)0;
@ -61,7 +62,6 @@ Fl_Double_Window* make_project_window() {
{ Fl_Tabs* o = new Fl_Tabs(10, 10, 378, 195);
o->selection_color((Fl_Color)12);
{ Fl_Group* o = new Fl_Group(10, 36, 378, 169, "Output");
o->hide();
{ Fl_Box* o = new Fl_Box(20, 49, 340, 49, "Use \"name.ext\" to set a file name or just \".ext\" to set extension.");
o->align(Fl_Align(132|FL_ALIGN_INSIDE));
} // Fl_Box* o
@ -94,6 +94,7 @@ Fl_Double_Window* make_project_window() {
o->end();
} // Fl_Group* o
{ Fl_Group* o = new Fl_Group(10, 36, 378, 169, "Internationalization");
o->hide();
{ i18n_type_chooser = new Fl_Choice(100, 48, 136, 25, "Use:");
i18n_type_chooser->tooltip("Type of internationalization to use.");
i18n_type_chooser->box(FL_THIN_UP_BOX);
@ -159,7 +160,7 @@ Fl_Check_Button *tooltips_button=(Fl_Check_Button *)0;
static void cb_tooltips_button(Fl_Check_Button*, void*) {
Fl_Tooltip::enable(tooltips_button->value());
fluid_prefs.set("show_tooltips", tooltips_button->value());
fluid_prefs.set("show_tooltips", tooltips_button->value());
}
Fl_Check_Button *completion_button=(Fl_Check_Button *)0;
@ -184,32 +185,32 @@ Fl_Check_Button *show_comments_button=(Fl_Check_Button *)0;
static void cb_show_comments_button(Fl_Check_Button*, void*) {
show_comments = show_comments_button->value();
fluid_prefs.set("show_comments", show_comments);
redraw_browser();
fluid_prefs.set("show_comments", show_comments);
redraw_browser();
}
Fl_Spinner *recent_spinner=(Fl_Spinner *)0;
static void cb_recent_spinner(Fl_Spinner*, void*) {
fluid_prefs.set("recent_files", recent_spinner->value());
load_history();
load_history();
}
Fl_Check_Button *use_external_editor_button=(Fl_Check_Button *)0;
static void cb_use_external_editor_button(Fl_Check_Button*, void*) {
G_use_external_editor = use_external_editor_button->value();
fluid_prefs.set("use_external_editor", G_use_external_editor);
redraw_browser();
fluid_prefs.set("use_external_editor", G_use_external_editor);
redraw_browser();
}
Fl_Input *editor_command_input=(Fl_Input *)0;
static void cb_editor_command_input(Fl_Input*, void*) {
strncpy(G_external_editor_command, editor_command_input->value(), sizeof(G_external_editor_command)-1);
G_external_editor_command[sizeof(G_external_editor_command)-1] = 0;
fluid_prefs.set("external_editor_command", G_external_editor_command);
redraw_browser();
G_external_editor_command[sizeof(G_external_editor_command)-1] = 0;
fluid_prefs.set("external_editor_command", G_external_editor_command);
redraw_browser();
}
static void cb_Close1(Fl_Button*, void*) {
@ -336,28 +337,28 @@ Fl_Check_Button *shell_use_fl_button=(Fl_Check_Button *)0;
static void cb_shell_use_fl_button(Fl_Check_Button*, void*) {
g_shell_use_fl_settings = shell_use_fl_button->value();
fluid_prefs.set("shell_use_fl", g_shell_use_fl_settings);
if (g_shell_use_fl_settings) {
shell_settings_read();
} else {
shell_prefs_get();
}
update_shell_window();
fluid_prefs.set("shell_use_fl", g_shell_use_fl_settings);
if (g_shell_use_fl_settings) {
shell_settings_read();
} else {
shell_prefs_get();
}
update_shell_window();
}
static void cb_save(Fl_Button*, void*) {
apply_shell_window();
shell_prefs_set();
shell_prefs_set();
}
static void cb_Run(Fl_Return_Button*, void*) {
apply_shell_window();
do_shell_command(NULL, NULL);
do_shell_command(NULL, NULL);
}
static void cb_Cancel(Fl_Button*, void*) {
shell_command_input->value(g_shell_command);
shell_window->hide();
shell_window->hide();
}
Fl_Double_Window *shell_run_window=(Fl_Double_Window *)0;
@ -368,11 +369,11 @@ Fl_Return_Button *shell_run_button=(Fl_Return_Button *)0;
static void cb_shell_run_button(Fl_Return_Button*, void*) {
Fl_Preferences pos(fluid_prefs, "shell_run_Window_pos");
pos.set("x", shell_run_window->x());
pos.set("y", shell_run_window->y());
pos.set("w", shell_run_window->w());
pos.set("h", shell_run_window->h());
shell_run_window->hide();
pos.set("x", shell_run_window->x());
pos.set("y", shell_run_window->y());
pos.set("w", shell_run_window->w());
pos.set("h", shell_run_window->h());
shell_run_window->hide();
}
Fl_Double_Window* make_shell_window() {
@ -689,7 +690,7 @@ Fl_Choice *wVisibleFocus=(Fl_Choice *)0;
static void cb_wVisibleFocus(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_VISIBLE_FOCUS][mode] = wVisibleFocus->value();
opt[Fl::OPTION_VISIBLE_FOCUS][mode] = wVisibleFocus->value();
}
Fl_Menu_Item menu_wVisibleFocus[] = {
@ -703,7 +704,7 @@ Fl_Choice *wArrowFocus=(Fl_Choice *)0;
static void cb_wArrowFocus(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_ARROW_FOCUS][mode] = wArrowFocus->value();
opt[Fl::OPTION_ARROW_FOCUS][mode] = wArrowFocus->value();
}
Fl_Menu_Item menu_wArrowFocus[] = {
@ -717,7 +718,7 @@ Fl_Choice *wShowTooltips=(Fl_Choice *)0;
static void cb_wShowTooltips(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_SHOW_TOOLTIPS][mode] = wShowTooltips->value();
opt[Fl::OPTION_SHOW_TOOLTIPS][mode] = wShowTooltips->value();
}
Fl_Menu_Item menu_wShowTooltips[] = {
@ -731,7 +732,7 @@ Fl_Choice *wDNDText=(Fl_Choice *)0;
static void cb_wDNDText(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_DND_TEXT][mode] = wDNDText->value();
opt[Fl::OPTION_DND_TEXT][mode] = wDNDText->value();
}
Fl_Menu_Item menu_wDNDText[] = {
@ -745,7 +746,7 @@ Fl_Choice *wGTKText=(Fl_Choice *)0;
static void cb_wGTKText(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_FNFC_USES_GTK ][mode] = wGTKText->value();
opt[Fl::OPTION_FNFC_USES_GTK ][mode] = wGTKText->value();
}
Fl_Menu_Item menu_wGTKText[] = {
@ -759,7 +760,7 @@ Fl_Choice *wPrintGTKText=(Fl_Choice *)0;
static void cb_wPrintGTKText(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_PRINTER_USES_GTK ][mode] = wPrintGTKText->value();
opt[Fl::OPTION_PRINTER_USES_GTK ][mode] = wPrintGTKText->value();
}
Fl_Menu_Item menu_wPrintGTKText[] = {
@ -773,7 +774,7 @@ Fl_Choice *wShowZoomFactor=(Fl_Choice *)0;
static void cb_wShowZoomFactor(Fl_Choice*, void*) {
int mode = wUserOrSystem->value();
opt[Fl::OPTION_SHOW_SCALING ][mode] = wShowZoomFactor->value();
opt[Fl::OPTION_SHOW_SCALING ][mode] = wShowZoomFactor->value();
}
Fl_Menu_Item menu_wShowZoomFactor[] = {
@ -801,7 +802,7 @@ static void cb_Cancel1(Fl_Button*, void*) {
static void cb_OK(Fl_Button*, void*) {
writePrefs();
global_settings_window->hide();
global_settings_window->hide();
}
Fl_Double_Window* make_global_settings_window() {

View File

@ -55,14 +55,15 @@ decl {extern struct Fl_Menu_Item *dbmanager_item;} {public local
Function {make_project_window()} {open
} {
Fl_Window project_window {
label {Project Settings}
label {Project Settings} open
xywh {473 246 399 252} type Double
code0 {\#include <FL/Fl_Preferences.H>}
code1 {\#include <FL/Fl_Tooltip.H>} modal visible
} {
Fl_Button {} {
label Close
callback {project_window->hide();}
callback {project_window->hide();
set_modflag(-1, -1);}
tooltip {Close this dialog.} xywh {328 216 60 25}
}
Fl_Tabs {} {open
@ -70,7 +71,7 @@ Function {make_project_window()} {open
} {
Fl_Group {} {
label Output open
xywh {10 36 378 169} hide
xywh {10 36 378 169}
} {
Fl_Box {} {
label {Use "name.ext" to set a file name or just ".ext" to set extension.}
@ -85,7 +86,7 @@ Function {make_project_window()} {open
Fl_Input code_file_input {
label {Code File:}
user_data 1 user_data_type {void*}
callback code_input_cb
callback code_input_cb selected
tooltip {The name of the generated code file.} xywh {119 128 252 20} box THIN_DOWN_BOX labelfont 1 when 1 textfont 4
}
Fl_Check_Button include_H_from_C_button {
@ -101,7 +102,7 @@ Function {make_project_window()} {open
}
Fl_Group {} {
label Internationalization open
xywh {10 36 378 169}
xywh {10 36 378 169} hide
} {
Fl_Choice i18n_type_chooser {
label {Use:}
@ -290,7 +291,7 @@ Function {make_shell_window()} {open
} {
Fl_Window shell_window {
label {Shell Command} open
xywh {468 233 365 200} type Double modal size_range {365 200 365 200} visible
xywh {287 318 365 200} type Double modal size_range {365 200 365 200} visible
} {
Fl_Group {} {open
xywh {0 0 365 165}
@ -320,7 +321,7 @@ if (g_shell_use_fl_settings) {
} else {
shell_prefs_get();
}
update_shell_window();} selected
update_shell_window();}
tooltip {check to read and write shell command from and to .fl files} xywh {82 110 180 19} down_box DOWN_BOX labelsize 12
}
Fl_Box {} {

View File

@ -138,6 +138,9 @@ static const char *filename = NULL;
/// Set if the current design has been modified compared to the associated .fl design file.
int modflag = 0;
/// Set if the code files are older than the current design.
int modflag_c = 0;
/// Application work directory, stored here when temporarily changing to the source code directory.
/// \see goto_source_dir()
static char* pwd = NULL;
@ -385,7 +388,7 @@ void save_cb(Fl_Widget *, void *v) {
}
if (v != (void *)2) {
set_modflag(0);
set_modflag(0, 1);
undo_save = undo_current;
}
}
@ -516,7 +519,7 @@ void revert_cb(Fl_Widget *,void *) {
return;
}
undo_resume();
set_modflag(0);
set_modflag(0, 0);
undo_clear();
}
@ -607,7 +610,7 @@ void apple_open_cb(const char *c) {
}
// Loaded a file; free the old filename...
set_modflag(0);
set_modflag(0, 0);
undo_resume();
undo_clear();
if (oldfilename) free((void *)oldfilename);
@ -661,7 +664,7 @@ void open_cb(Fl_Widget *, void *v) {
set_modflag(1);
} else {
// Loaded a file; free the old filename...
set_modflag(0);
set_modflag(0, 0);
undo_clear();
if (oldfilename) free((void *)oldfilename);
}
@ -698,7 +701,7 @@ void open_history_cb(Fl_Widget *, void *v) {
if (main_window) main_window->label(filename);
return;
}
set_modflag(0);
set_modflag(0, 0);
undo_resume();
undo_clear();
if (oldfilename) {
@ -731,6 +734,7 @@ void new_cb(Fl_Widget *, void *v) {
// Clear the current data...
delete_all();
set_filename(NULL);
set_modflag(0, 0);
}
/**
@ -863,7 +867,7 @@ int write_code_files() {
strlcpy(cname, fl_filename_name(filename), sizeof(cname));
fl_filename_setext(cname, sizeof(cname), code_file_name);
} else {
strlcpy(cname, code_file_name, sizeof(hname));
strlcpy(cname, code_file_name, sizeof(cname));
}
if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) {
strlcpy(hname, fl_filename_name(filename), sizeof(hname));
@ -881,8 +885,11 @@ int write_code_files() {
} else {
if (!x) {
fl_message("Can't write %s: %s", cname, strerror(errno));
} else if (completion_button->value()) {
fl_message("Wrote %s", cname);
} else {
set_modflag(-1, 0);
if (completion_button->value()) {
fl_message("Wrote %s", cname);
}
}
}
return 0;
@ -1552,13 +1559,37 @@ void set_filename(const char *c) {
/**
Set the "modified" flag and update the title of the main window.
\param[in] mf 0 to clear the modflag, 1 to mark the design "modified"
*/
void set_modflag(int mf) {
const char *basename;
static char title[FL_PATH_MAX];
modflag = mf;
The first argument sets the modifaction state of the current design against
the corresponding .fl design file. Any change to the widget tree will mark
the design 'modified'. Saving the design will mark it clean.
The second argument is optional and set the modification state of the current
design against the source code and header file. Any change to the tree,
including saving the tree, will mark the code 'outdated'. Generating source
code and header files will clear this flag until the next modification.
\param[in] mf 0 to clear the modflag, 1 to mark the design "modified", -1 to
ignore this parameter
\param[in] mfc default -1 to let \c mf control \c modflag_c, 0 to mark the
code files current, 1 to mark it out of date.
*/
void set_modflag(int mf, int mfc) {
const char *basename;
const char *code_ext = NULL;
static char title[FL_PATH_MAX];
// Update the modflag_c to the worst possible condition. We could be a bit
// more graceful and compare modification times of the files, but C++ has
// no API for that until C++17.
if (mf!=-1) {
modflag = mf;
if (mfc==-1 && mf==1)
mfc = mf;
}
if (mfc!=-1) {
modflag_c = mfc;
}
if (main_window) {
if (!filename) basename = "Untitled.fl";
@ -1568,10 +1599,16 @@ void set_modflag(int mf) {
#endif // _WIN32
else basename = filename;
if (modflag) {
snprintf(title, sizeof(title), "%s (modified)", basename);
main_window->label(title);
} else main_window->label(basename);
if (code_file_name)
code_ext = fl_filename_ext(code_file_name);
else
code_ext = ".cxx";
char mod_star = modflag ? '*' : ' ';
char mod_c_star = modflag_c ? '*' : ' ';
snprintf(title, sizeof(title), "%s%c %s%c",
basename, mod_star, code_ext, mod_c_star);
main_window->label(title);
}
// if the UI was modified in any way, update the Source View panel
if (sourceview_panel && sourceview_panel->visible() && sv_autorefresh->value())

View File

@ -92,7 +92,7 @@ extern int pasteoffset;
// ---- public functions
extern void set_filename(const char *c);
extern void set_modflag(int mf);
extern void set_modflag(int mf, int mfc=-1);
// ---- public callback functions

View File

@ -77,7 +77,7 @@ Fl_Input *v_input[4]={(Fl_Input *)0};
static void cb_1(Fl_Tile*, void* v) {
wComment->do_callback(wComment, v);
wCallback->do_callback(wCallback, v);
wCallback->do_callback(wCallback, v);
}
Fl_Text_Editor *wComment=(Fl_Text_Editor *)0;
@ -107,6 +107,7 @@ Fl_Double_Window* make_widget_panel() {
o->labelsize(11);
o->callback((Fl_Callback*)propagate_load);
o->when(FL_WHEN_NEVER);
o->hide();
{ Fl_Group* o = new Fl_Group(95, 40, 309, 20, "Label:");
o->labelfont(1);
o->labelsize(11);
@ -513,7 +514,6 @@ ive to the origin at construction time");
o->labelsize(11);
o->callback((Fl_Callback*)propagate_load);
o->when(FL_WHEN_NEVER);
o->hide();
{ Fl_Group* o = new Fl_Group(95, 40, 309, 20, "Label Font:");
o->labelfont(1);
o->labelsize(11);

View File

@ -2,6 +2,8 @@
version 1.0400
header_name {.h}
code_name {.cxx}
mac_shell_cmd {echo "Fluid is nice"}
mac_shell_flags 3
comment {//
// Widget panel for the Fast Light Tool Kit (FLTK).
//
@ -20,7 +22,7 @@ comment {//
} {in_source in_header
}
decl {\#include "Fl_Widget_Type.h"} {selected private global
decl {\#include "Fl_Widget_Type.h"} {private global
}
Function {make_widget_panel()} {
@ -38,7 +40,7 @@ Function {make_widget_panel()} {
Fl_Group {} {
label GUI
callback propagate_load
xywh {10 30 400 330} labelsize 11 when 0 resizable
xywh {10 30 400 330} labelsize 11 when 0 hide resizable
} {
Fl_Group {} {
label {Label:}
@ -434,8 +436,8 @@ Use Ctrl-J for newlines.} xywh {95 285 310 20} labelfont 1 labelsize 11 textsize
}
Fl_Group {} {
label Style
callback propagate_load
xywh {10 30 400 330} labelsize 11 when 0 hide
callback propagate_load selected
xywh {10 30 400 330} labelsize 11 when 0
} {
Fl_Group {} {
label {Label Font:}