• Extending the initial example again, to make a persistent clipboard text tool

    1.  The clipStore program needs an additional refinement.

    2.  The text needs to be saved when the program concludes, and restored in the next session.

    3.  This is done by making a new persistentClipStore class that extends the clipStore class.


      persistentClipStore.roo

        -- persistentClipStore.roo
        
        persistentClipStore  :  class extends clipStore explicitly
        
        shared clipStoreName
        
        initialize  :  method
        
          'base' ~ initialize -- no parameters for base initialization method
        
          clipStoreName = arg(1)
        
          if clipStoreName = '' then
            clipStoreName = 'clipStore.clippings'
        
          inClips = ^^ inLineFile( clipStoreName, 'NoPrompt' )
        
          loop ix over inClips
            parse value inClips[ ix ] with key '=' value
            ^ setAt( key, value )
            end 
        
          return ''
        
        save  :  method
          call lineout clipStoreName, ^ listAll
          call lineout clipStoreName
          return ''
        


    4.  Now the store.rooProgram needs to create an instance of a persistentClipStore class instead of a clipStore class.

    5.  No other changes are required.


      store.rooProgram

        -- store.rooProgram
        
        store = ^^ persistentClipStore -- prepare the 'persistentClipStore' object
        
        call showUsage
        
        signal on halt
        
        do forever
        
          parse linein request +1 key '=' value
        
          key = strip( key )
          value = strip( value )
        
          select 
            when request = '' then
              nop 
            when request = '+' then
              store ~ remember( key, value )
            when request = '?' then
              say store ~ remember( key )
            when request = '-' then
              store ~ forget( key )
            when request = 'k' then
              say store ~ listKeys
            when request = '!' then
              say store ~ listAll
            when translate( request ) = 'Q' then
              exit 0
            otherwise 
              call showUsage
            end 
        
          end 
        
        halt :
        
        exit 0
        
        showUsage  :  procedure
          say 'Usage:'
          say '  + key = value -- adds a value'
          say '  ? key         -- locates value associated with key'
          say '  - key         -- forgets value associated with key'
          say '  k             -- lists all keys'
          say '  !             -- lists all associations'
          say '  Q             -- terminates'
          return 
        


       Now you have a useful text clipping tool.