Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Fl_Menu_Settings.H"
  19. #include <string.h>
  20. /* code to dump and restore (portions of) an Fl_Menu_ */
  21. void
  22. Fl_Menu_Settings::remove_ampersands ( char *str, int n )
  23. {
  24. char *d = str;
  25. char *s = str;
  26. while ( n-- )
  27. {
  28. if ( *s == '&' )
  29. {
  30. ++s;
  31. continue;
  32. }
  33. *(d++) = *(s++);
  34. }
  35. *d = '\0';
  36. }
  37. void
  38. Fl_Menu_Settings::indent ( FILE *fp, int n )
  39. {
  40. while ( n-- )
  41. fprintf( fp, "\t" );
  42. }
  43. int
  44. Fl_Menu_Settings::item_pathname_x ( char *path, int n, Fl_Menu_Item *item )
  45. {
  46. Fl_Menu_::item_pathname( path, n, item );
  47. remove_ampersands( path, n );
  48. }
  49. /** dump options from submenu /menu/ of menubar /bar/ to file /fp/ */
  50. Fl_Menu_Item *
  51. Fl_Menu_Settings::dump ( Fl_Menu_ *bar, Fl_Menu_Item *menu, FILE *fp, int depth )
  52. {
  53. static char path[256];
  54. Fl_Menu_Item *m = menu;
  55. for ( ; m->text; ++m )
  56. {
  57. bool is_radio = false;
  58. if ( m->flags & FL_SUBMENU )
  59. {
  60. strcpy( path, m->text );
  61. remove_ampersands( path, sizeof( path ) - 1 );
  62. indent( fp, depth );
  63. fprintf( fp, "%s\n", path );
  64. /* recurse */
  65. m = dump( bar, ++m, fp, depth + 1 );
  66. continue;
  67. }
  68. if ( m->flags & FL_MENU_RADIO )
  69. is_radio = true;
  70. // bar->item_pathname( path, sizeof( path ) - 1, m );
  71. item_pathname_x( path, sizeof( path ) - 1, m );
  72. if ( m->flags & FL_MENU_TOGGLE || m->flags & FL_MENU_RADIO )
  73. {
  74. if ( ! is_radio )
  75. {
  76. indent( fp, depth );
  77. fprintf( fp, "%s\n", rindex( path, '/' ) + 1 );
  78. indent( fp, depth + 1 );
  79. fprintf( fp, "%s\n", m->flags & FL_MENU_VALUE ? "true" : "false" );
  80. }
  81. else if ( m->flags & FL_MENU_VALUE )
  82. {
  83. indent( fp, depth );
  84. *rindex( path, '/' ) = '\0';
  85. fprintf( fp, "%s\n", rindex( path, '/' ) + 1 );
  86. indent( fp, depth + 1 );
  87. fprintf( fp, "%s\n", path + strlen( path ) + 1 );
  88. }
  89. }
  90. }
  91. return m;
  92. }
  93. int
  94. Fl_Menu_Settings::dump ( Fl_Menu_Item *item, const char *name )
  95. {
  96. FILE *fp = fopen( name, "w" );
  97. if ( ! fp )
  98. return false;
  99. dump( this, item, fp, 0 );
  100. fclose( fp );
  101. return true;
  102. }