template_panel.fl 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # data file for the Fltk User Interface Designer (fluid)
  2. version 1.0300
  3. header_name {.h}
  4. code_name {.cxx}
  5. comment {//
  6. // "$Id: template_panel.fl 8864 2011-07-19 04:49:30Z greg.ercolano $"
  7. //
  8. // FLUID template support for the Fast Light Tool Kit (FLTK).
  9. //
  10. // Copyright 1998-2010 by Bill Spitzak and others.
  11. //
  12. // This library is free software. Distribution and use rights are outlined in
  13. // the file "COPYING" which should have been included with this file. If this
  14. // file is missing or damaged, see the license at:
  15. //
  16. // http://www.fltk.org/COPYING.php
  17. //
  18. // Please report all bugs and problems on the following page:
  19. //
  20. // http://www.fltk.org/str.php
  21. //
  22. } {in_source in_header
  23. }
  24. decl {\#include <stdio.h>} {}
  25. decl {\#include <stdlib.h>} {}
  26. decl {\#include "../src/flstring.h"} {}
  27. decl {\#include <errno.h>} {}
  28. decl {\#include <FL/filename.H>} {}
  29. decl {\#include <FL/fl_ask.H>} {}
  30. decl {\#include <FL/Fl_Shared_Image.H>} {}
  31. decl {\#include <FL/Fl_Preferences.H>} {}
  32. declblock {\#if defined(WIN32) && !defined(__CYGWIN__)} {after {\#endif // WIN32 && !__CYGWIN__}
  33. } {
  34. decl {\#include <io.h>} {}
  35. decl {\#else} {}
  36. decl {\#include <unistd.h>} {}
  37. }
  38. decl {extern Fl_Preferences fluid_prefs;} {}
  39. Function {make_template_panel()} {} {
  40. Fl_Window template_panel {
  41. label {New/Save Template}
  42. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  43. if (img) img->release();
  44. template_preview->image(0);
  45. template_browser->deselect();
  46. template_name->value("");
  47. template_instance->value("");
  48. template_panel->hide();} open
  49. xywh {340 237 460 355} type Double resizable modal visible
  50. } {
  51. Fl_Browser template_browser {
  52. label {Available Templates:}
  53. callback {if (Fl::event_clicks()) {
  54. template_panel->hide();
  55. return;
  56. }
  57. Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  58. if (img) img->release();
  59. template_preview->image(0);
  60. template_preview->redraw();
  61. int item = template_browser->value();
  62. if (item <= 1) template_instance->deactivate();
  63. else template_instance->activate();
  64. if (item < 1) {
  65. template_submit->deactivate();
  66. template_delete->deactivate();
  67. return;
  68. }
  69. template_submit->activate();
  70. const char *flfile = (const char *)template_browser->data(item);
  71. if (!flfile) {
  72. template_delete->deactivate();
  73. return;
  74. }
  75. template_name->value(template_browser->text(item));
  76. template_delete->activate();
  77. char pngfile[1024], *ext;
  78. strlcpy(pngfile, flfile, sizeof(pngfile));
  79. if ((ext = strrchr(pngfile, '.')) == NULL) return;
  80. strcpy(ext, ".png");
  81. img = Fl_Shared_Image::get(pngfile);
  82. if (img) {
  83. template_preview->image(img);
  84. template_preview->redraw();
  85. }}
  86. xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3
  87. }
  88. Fl_Box template_preview {
  89. xywh {200 28 250 250} box THIN_DOWN_BOX align 85 resizable
  90. }
  91. Fl_Input template_name {
  92. label {Template Name:}
  93. callback {if (strlen(template_name->value())) {
  94. template_submit->activate();
  95. if (Fl::event_key() == FL_Enter) template_panel->hide();
  96. } else template_submit->deactivate();}
  97. xywh {124 288 326 25} labelfont 1 when 3 textfont 4
  98. }
  99. Fl_Input template_instance {
  100. label {Instance Name:}
  101. xywh {124 288 326 25} labelfont 1 textfont 4 hide
  102. }
  103. Fl_Group {} {
  104. xywh {10 323 440 25}
  105. } {
  106. Fl_Button template_delete {
  107. label {Delete Template}
  108. callback template_delete_cb
  109. xywh {10 323 133 25}
  110. }
  111. Fl_Box {} {
  112. xywh {153 323 126 25} resizable
  113. }
  114. Fl_Button {} {
  115. label Cancel
  116. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  117. if (img) img->release();
  118. template_preview->image(0);
  119. template_browser->deselect();
  120. template_name->value("");
  121. template_instance->value("");
  122. template_panel->hide();}
  123. xywh {289 323 72 25}
  124. }
  125. Fl_Return_Button template_submit {
  126. label Save
  127. callback {Fl_Shared_Image *img = (Fl_Shared_Image *)template_preview->image();
  128. if (img) img->release();
  129. template_preview->image(0);
  130. template_panel->hide();}
  131. xywh {371 323 79 25}
  132. }
  133. }
  134. }
  135. }
  136. Function {template_clear()} {return_type void
  137. } {
  138. code {int i;
  139. void *filename;
  140. for (i = 1; i <= template_browser->size(); i ++) {
  141. if ((filename = template_browser->data(i)) != NULL) free(filename);
  142. }
  143. template_browser->deselect();
  144. template_browser->clear();} {}
  145. }
  146. Function {template_delete_cb(Fl_Button *, void *)} {selected return_type void
  147. } {
  148. code {int item = template_browser->value();
  149. if (item < 1) return;
  150. const char *name = template_browser->text(item);
  151. const char *flfile = (const char *)template_browser->data(item);
  152. if (!flfile) return;
  153. if (!fl_choice("Are you sure you want to delete the template \\"%s\\"?",
  154. "Cancel", "Delete", 0, name)) return;
  155. if (unlink(flfile)) {
  156. fl_alert("Unable to delete template \\"%s\\":\\n%s", name, strerror(errno));
  157. return;
  158. }
  159. template_browser->remove(item);
  160. template_browser->do_callback();} {}
  161. }
  162. Function {template_load()} {return_type void
  163. } {
  164. code {int i;
  165. char name[1024], filename[1024], path[1024], *ptr;
  166. struct dirent **files;
  167. int num_files;
  168. fluid_prefs.getUserdataPath(path, sizeof(path));
  169. strlcat(path, "templates", sizeof(path));
  170. num_files = fl_filename_list(path, &files);
  171. for (i = 0; i < num_files; i ++) {
  172. if (fl_filename_match(files[i]->d_name, "*.fl")) {
  173. // Format the name as the filename with "_" replaced with " "
  174. // and without the trailing ".fl"...
  175. strlcpy(name, files[i]->d_name, sizeof(name));
  176. *strstr(name, ".fl") = '\\0';
  177. for (ptr = name; *ptr; ptr ++) {
  178. if (*ptr == '_') *ptr = ' ';
  179. }
  180. // Add the template to the browser...
  181. snprintf(filename, sizeof(filename), "%s/%s", path, files[i]->d_name);
  182. template_browser->add(name, strdup(filename));
  183. }
  184. free(files[i]);
  185. }
  186. if (num_files > 0) free(files);} {}
  187. }
  188. comment {
  189. //
  190. // End of "$Id: template_panel.fl 8864 2011-07-19 04:49:30Z greg.ercolano $".
  191. //} {in_source in_header
  192. }