Reorganized Fluid Template feature (STR #3336).

This commit is contained in:
Matthias Melcher 2019-02-01 23:16:49 +01:00
parent af8e406f88
commit d6294ac2fc
5 changed files with 98 additions and 15 deletions

View File

@ -145,6 +145,7 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2019
Bug Fixes
- (add new items here)
- Reorganized Fluid Template feature (STR #3336).
- Updated Fluid documentation and image (STR #3328).
- Duplicating Widget Class in Fluid no longer crashes (STR #3445).
- Fl_Check_Browser::add(item) now accepts NULL (STR #3498).

View File

@ -16,6 +16,7 @@ Subchapters:
\li \ref fluid_compiling_fl_files
\li \ref fluid_tutorial
\li \ref fluid_references
\li \ref fluid_templates
\li \ref fluid_i18n
\li \ref fluid_limitations
@ -1445,6 +1446,33 @@ RGB or grayscale data to the source file. PNG images can provide
a full alpha channel for partial transparency, and FLTK supports
this as best as possible on each platform.
\section fluid_templates FLUID Templates
\par
Fluid can store a number of project templates. Project templates
are great for storing often used boilerplate code for fast access.
A common use would be projects with readily prepared copyright
messages.
\par
A sample template for FLTK projects is included with Fluid.
\par
Choose "File > New From Template..." to create a new project
based on a template file. In the template dialog, select one of
the existing templates. All occurrences of the word
"@INSTANCE@" in the template are replaced with the text in
the "Instance" field. To create the new project click "New".
\par
To add your current project as a new template, choose
"File > Save As Template...", fill in a name, and click "Save".
\par
To delete a template, open the template dialog using
"New from Template" or "Save As Template", the select any
existing template, and click "Delete Template".
\section fluid_i18n Internationalization with FLUID
FLUID supports internationalization (I18N for short) of label

View File

@ -581,13 +581,21 @@ void new_cb(Fl_Widget *, void *v) {
"Save", "Don't Save"))
{
case 0 : /* Cancel */
return;
return;
case 1 : /* Save */
save_cb(NULL, NULL);
if (modflag) return; // Didn't save!
save_cb(NULL, NULL);
if (modflag) return; // Didn't save!
}
}
// Clear the current data...
delete_all();
set_filename(NULL);
}
void new_from_template_cb(Fl_Widget *w, void *v) {
new_cb(w, v);
// Setup the template panel...
if (!template_panel) make_template_panel();
@ -602,17 +610,17 @@ void new_cb(Fl_Widget *, void *v) {
template_instance->deactivate();
template_instance->value("");
template_delete->hide();
template_delete->show();
template_submit->label("New");
template_submit->deactivate();
template_panel->label("New");
if ( template_browser->size() == 1 ) { // only one item?
//if ( template_browser->size() == 1 ) { // only one item?
template_browser->value(1); // select it
template_browser->do_callback();
}
//}
// Show the panel and wait for the user to do something...
template_panel->show();
@ -622,10 +630,6 @@ void new_cb(Fl_Widget *, void *v) {
int item = template_browser->value();
if (item < 1) return;
// Clear the current data...
delete_all();
set_filename(NULL);
// Load the template, if any...
const char *tname = (const char *)template_browser->data(item);
@ -1041,14 +1045,15 @@ void toggle_sourceview_cb(Fl_Double_Window *, void *);
Fl_Menu_Item Main_Menu[] = {
{"&File",0,0,0,FL_SUBMENU},
{"&New...", FL_COMMAND+'n', new_cb, 0},
{"&New", FL_COMMAND+'n', new_cb, 0},
{"&Open...", FL_COMMAND+'o', open_cb, 0},
{"&Insert...", FL_COMMAND+'i', open_cb, (void*)1, FL_MENU_DIVIDER},
{"&Save", FL_COMMAND+'s', save_cb, 0},
{"Save &As...", FL_COMMAND+FL_SHIFT+'s', save_cb, (void*)1},
{"Sa&ve A Copy...", 0, save_cb, (void*)2},
{"Save &Template...", 0, save_template_cb},
{"&Revert...", 0, revert_cb, 0, FL_MENU_DIVIDER},
{"New &From Template...", FL_COMMAND+'N', new_from_template_cb, 0},
{"Save As &Template...", 0, save_template_cb, 0, FL_MENU_DIVIDER},
{"&Print...", FL_COMMAND+'p', print_menu_cb},
{"Write &Code...", FL_COMMAND+FL_SHIFT+'c', write_cb, 0},
{"&Write Strings...", FL_COMMAND+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER},

View File

@ -220,6 +220,30 @@ void template_load() {
fluid_prefs.getUserdataPath(path, sizeof(path));
strlcat(path, "templates", sizeof(path));
int sample_templates_generated = 0;
fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0);
if (!sample_templates_generated) {
strcpy(filename, path);
strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb");
if (f) {
fputs(
"# data file for the Fltk User Interface Designer (fluid)\nversion 1.0400\nheader_name {.h}\n"
"code_name {.cxx}\ncomment {//\n// \"$Id$\"\n//\n// @INSTANCE@ for the Fast Light Tool Kit (FLT"
"K).\n//\n// Copyright 1998-2019 by Bill Spitzak and others.\n//\n// This library is free sof"
"tware. Distribution and use rights are outlined in\n// the file \"COPYING\" which should have "
"been included with this file. If this\n// file is missing or damaged, see the license at:\n"
"//\n// http://www.fltk.org/COPYING.php\n//\n// Please report all bugs and problems on th"
"e following page:\n//\n// http://www.fltk.org/str.php\n//\n} {selected in_source in_head"
"er\n}\n\ncomment {\n//\n// End of \"$Id$\".\n//} {in_source in_header\n}\n", f);
fclose(f);
}
sample_templates_generated = 1;
fluid_prefs.set("sample_templates_generated", sample_templates_generated);
fluid_prefs.flush();
}
num_files = fl_filename_list(path, &files);
for (i = 0; i < num_files; i ++) {

View File

@ -129,7 +129,7 @@ if (img) {
callback {if (strlen(template_name->value())) {
template_submit->activate();
if (Fl::event_key() == FL_Enter) template_panel->hide();
} else template_submit->deactivate();} selected
} else template_submit->deactivate();}
xywh {198 288 252 25} labelfont 1 when 3 textfont 4
}
Fl_Input template_instance {
@ -206,7 +206,7 @@ template_browser->remove(item);
template_browser->do_callback();} {}
}
Function {template_load()} {return_type void
Function {template_load()} {open return_type void
} {
code {int i;
char name[1024], filename[1024], path[1024], *ptr;
@ -216,6 +216,30 @@ int num_files;
fluid_prefs.getUserdataPath(path, sizeof(path));
strlcat(path, "templates", sizeof(path));
int sample_templates_generated = 0;
fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0);
if (!sample_templates_generated) {
strcpy(filename, path);
strcat(filename, "/FLTK_License.fl");
FILE *f = fopen(filename, "wb");
if (f) {
fputs(
"\# data file for the Fltk User Interface Designer (fluid)\\nversion 1.0400\\nheader_name {.h}\\n"
"code_name {.cxx}\\ncomment {//\\n// \\"$Id$\\"\\n//\\n// @INSTANCE@ for the Fast Light Tool Kit (FLT"
"K).\\n//\\n// Copyright 1998-2019 by Bill Spitzak and others.\\n//\\n// This library is free sof"
"tware. Distribution and use rights are outlined in\\n// the file \\"COPYING\\" which should have "
"been included with this file. If this\\n// file is missing or damaged, see the license at:\\n"
"//\\n// http://www.fltk.org/COPYING.php\\n//\\n// Please report all bugs and problems on th"
"e following page:\\n//\\n// http://www.fltk.org/str.php\\n//\\n} {selected in_source in_head"
"er\\n}\\n\\ncomment {\\n//\\n// End of \\"$Id$\\".\\n//} {in_source in_header\\n}\\n", f);
fclose(f);
}
sample_templates_generated = 1;
fluid_prefs.set("sample_templates_generated", sample_templates_generated);
fluid_prefs.flush();
}
num_files = fl_filename_list(path, &files);
for (i = 0; i < num_files; i ++) {
@ -237,7 +261,8 @@ for (i = 0; i < num_files; i ++) {
free(files[i]);
}
if (num_files > 0) free(files);} {}
if (num_files > 0) free(files);} {selected
}
}
comment {