the fair gds editor ToolbarStorageMacro

Save and restore the toolbar state

The toolbar state like visibility, position and size of any toolbar can be stored and loaded. This can be used e.g. for a application or user specific toolbar setup or to transfer the setup to a different system. This macro shows how to store and load a toolbar state to a file.

Download: Toolbar.layout

   1 #!/Applications/layout.app/Contents/MacOS/layout
   2 #name=Maintain Toolbar
   3 #help=Save and restore the toolbar state
   4 
   5 
   6 /***************************************************************
   7 Name:           Toolbar.layout
   8 Rev:            1
   9 Recorded:       April 26, 2016
  10 By:                     Jim Carroll, PhotomaskPORTAL
  11 
  12 Change Log:
  13         Rev 20160427 - Added error-handling.
  14         Rev 20160426 - Initial program.
  15 
  16 Summary: 
  17         This macro saves the state of the toolbar in a text file in the user's
  18         macro directory. The toolbar can be restored to this state.
  19 
  20 Notes:
  21         1 -     Save macros with UNIX LF and Unicode (UTF-8) encoding
  22         2 -     For help with macro commands see http://www.layouteditor.net/wiki/CategoryMacroClass
  23         3 - For help with control structures see http://www.layouteditor.net/wiki/pseudoC-C%2B%2B
  24         4 - For Linux use #!/usr/bin/layout
  25 ***************************************************************/
  26 
  27 int main()
  28         {       
  29                 string desired_function = layout->getText("Question","Do you want to SAVE or RESTORE the toolbar ?","Save");
  30                         
  31                 file f;
  32                 bool b;
  33                 string s;
  34                 f.filename = "toolbar_state.txt";
  35                 
  36                         
  37                 if ((desired_function.left(1) == "s") || (desired_function.left(1) == "S")) 
  38                         {       
  39                                 b = false;
  40                                 f.open(b);
  41 
  42                                 s = layout->getToolbarState();
  43   
  44                                 f.write(s);
  45                                 f.close();
  46 
  47                                 layout->showMessage("Information","Your toolbar state has been saved as file toolbar_state.txt.");
  48                         }
  49 
  50                 else if (((desired_function.left(1) == "r") || (desired_function.left(1) == "R")) && f.exists()) 
  51                         {       
  52                                 b = true;
  53                                 f.open(b);
  54                                 s = f.read();
  55                                 f.close();
  56 
  57                                 layout->setToolbarState(s);
  58                                 layout->showMessage("Information","Your saved toolbar state has been restored.");
  59                         }
  60                         
  61                 else if (((desired_function.left(1) == "r") || (desired_function.left(1) == "R")) && (f.exists() == false)) 
  62                         {
  63                                 layout->showMessage("Info",             "********** Error **********\n" +
  64                                                                                                 "\nThe settings do not exist." +
  65                                                                                                 "\n\nPlease first save a toolbar state." +
  66                                                                                                 "\n\nProgram terminated.");
  67                                 return 1;               
  68                         }
  69                         
  70                 else
  71                         {       
  72                                 layout->showMessage("Error",    "********** Error **********\n" +
  73                                                                                                 "\nWe did not understand your response: " +     desired_function +
  74                                                                                                 "\n\nPlease answer SAVE or RESTORE." +
  75                                                                                                 "\n\nProgram terminated.");
  76                                 return 1;
  77                         }
  78                         
  79         } /* end main program */

See also


CategoryMacro


ToolbarStorageMacro (last edited 2016-04-27 14:23:59 by JurgenThies)