Christoph Wilhelms wrote:

> > Antidote Reopener changed to use global PropertiesManager
> > (instead of writing its own Properties file).
>
> Hi Jack!
>
> I just wanted to apply your patch, but other then the first one I had
> problems with this one! CVS simply said, that the file contains no valid
> patch!

Oops, I forgot the -c , as in

     cvs diff -c

Resending.

> The code looks good, thoug, and I think it'll do, waht it is meant to be

Oh, it does, at least, as far as I have tested it.

    1. Delete antidote.reopen.properties
    2. Start antidote.
    3. Open a few files.
    4. Exit.
    5. Examine ~/apache.ant.antidote.persistent.properties (unless you used the 
-p switch to specify a props file, then examine that one.)
    6. Start antidote again.
    7. See what's on the reopen menu (and what order they are in).

--
Jack J. Woehr      # You measure democracy by the freedom it
Senior Consultant  # gives its dissidents, not the freedom
Purematrix, Inc.   # it gives its assimilated conformists.
www.purematrix.com #         - Abbie Hoffman


Index: org/apache/tools/ant/gui/modules/Reopener.java
===================================================================
RCS file: 
/home/cvspublic/ant-antidote/src/java/org/apache/tools/ant/gui/modules/Reopener.java,v
retrieving revision 1.4
diff -c -r1.4 Reopener.java
*** org/apache/tools/ant/gui/modules/Reopener.java      28 Sep 2003 13:02:59 
-0000      1.4
--- org/apache/tools/ant/gui/modules/Reopener.java      29 Sep 2003 06:07:22 
-0000
***************
*** 75,80 ****
--- 75,81 ----
  import org.apache.tools.ant.gui.core.AntMenu;
  import org.apache.tools.ant.gui.core.AntModule;
  import org.apache.tools.ant.gui.core.AppContext;
+ import org.apache.tools.ant.gui.core.PropertiesManager;
  import org.apache.tools.ant.gui.event.BusFilter;
  import org.apache.tools.ant.gui.event.BusMember;
  import org.apache.tools.ant.gui.event.EventBus;
***************
*** 84,91 ****
  /**
   * Adds a "Reopen" menu which contains a list of files which
   * have been opened and closed.
!  * 
!  * @version $Revision: 1.4 $ 
   * @author Nick Davis
   */
  public class Reopener extends AntModule {
--- 85,92 ----
  /**
   * Adds a "Reopen" menu which contains a list of files which
   * have been opened and closed.
!  *
!  * @version $Revision: 1.4 $
   * @author Nick Davis
   */
  public class Reopener extends AntModule {
***************
*** 96,125 ****
      private JMenu _menu = null;
      /** Used to format the time the file was closed */
      private SimpleDateFormat _formatter
!           = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz");
      /** The title of our menu */
      private String _menuName = null;
      /** The menu we put our menu after */
      private String _insertAfterMenuName = null;
      /** The number of files to display */
      private static final int NUMBER_MENU_ITEMS = 10;
!         
!     /** 
       * Register our event listener
!      * 
       * @param context Application context.
       */
      public void contextualize(AppContext context) {
          setContext(context);
          
          _menuName =
!             context.getResources().getString(getClass(), "menuName");
          _insertAfterMenuName =
!             context.getResources().getString(getClass(), 
"insertAfterMenuName");
          
          context.getEventBus().addMember(EventBus.RESPONDING, new Handler());
      }
! 
      /**
       *  Insert our menu into the main menu bar
       *
--- 97,167 ----
      private JMenu _menu = null;
      /** Used to format the time the file was closed */
      private SimpleDateFormat _formatter
!     = new SimpleDateFormat("yyyy.MM.dd G 'at' hh:mm:ss a zzz");
      /** The title of our menu */
      private String _menuName = null;
      /** The menu we put our menu after */
      private String _insertAfterMenuName = null;
      /** The number of files to display */
      private static final int NUMBER_MENU_ITEMS = 10;
!     
!     /** The string prefixed to every reopener filelist entry in our 
Properties */
!     public static final String 
REOPENER_FILELIST_PROPERTY_PREFIX="Reopener.filelist.";
!     
!     /** Test if a key (i.e., a Properties file key in our persistent 
properties)
!      * is a key written/read by the Reopener as a filelist member.
!      * @param key A string used as a properties file key.
!      * @return true if indeed the string represents a Reopener filelist key.
!      */
!     public static boolean isReopenerFilelistKey(String key) {
!         boolean result = false;
!         if (null != key) {
!             result = key.startsWith(REOPENER_FILELIST_PROPERTY_PREFIX);
!         }
!         return result;
!     }
!     
!     /** Make a file key intended to be stored in our persistent properties
!      * into a key written/read by the Reopener as a filelist member by 
prefixing
!      * it correctly.
!      * @param key A string used by the Reopener intended to be used as a 
properties file key.
!      * @return The same string prefixed with the Reopener filelist key.
!      */
!     public static String makeReopenerFilelistKey(String protoKey) {
!         String result= REOPENER_FILELIST_PROPERTY_PREFIX + protoKey;
!         return result;
!     }
!     
!     /** Make a file key intended to be stored in our persistent properties
!      * into a the kind of key understood by the Reopener as a filelist member 
by
!      * stripping the prefix that identifies it as a Reopener key in the 
properties file.
!      * @param key A string used as a properties file key.
!      * @return The same string with the prefix for a Reopener filelist key 
stripped from it.
!      */
!     public static String stripReopenerFilelistKey(String protoKey) {
!         String result = protoKey;
!         if (isReopenerFilelistKey(protoKey)) {
!             result = 
protoKey.substring(REOPENER_FILELIST_PROPERTY_PREFIX.length());
!         }
!         return result;
!     }
!     
!     /**
       * Register our event listener
!      *
       * @param context Application context.
       */
      public void contextualize(AppContext context) {
          setContext(context);
          
          _menuName =
!         context.getResources().getString(getClass(), "menuName");
          _insertAfterMenuName =
!         context.getResources().getString(getClass(), "insertAfterMenuName");
          
          context.getEventBus().addMember(EventBus.RESPONDING, new Handler());
      }
!     
      /**
       *  Insert our menu into the main menu bar
       *
***************
*** 132,138 ****
          
          // Load the list of files
          loadList();
! 
          // Loop throught the menus and look for the menu
          // we put our menu after.
          boolean breakOut = false;
--- 174,180 ----
          
          // Load the list of files
          loadList();
!         
          // Loop throught the menus and look for the menu
          // we put our menu after.
          boolean breakOut = false;
***************
*** 158,166 ****
          }
          updateMenu();
      }
! 
      /**
!      * 
       */
      protected void updateMenu() {
          
--- 200,208 ----
          }
          updateMenu();
      }
!     
      /**
!      *
       */
      protected void updateMenu() {
          
***************
*** 182,188 ****
                  map.put(new Long(date.getTime() * -1), key);
              } catch (Exception e) {}
          }
! 
          // Remove all of our menu items.
          _menu.removeAll();
          
--- 224,230 ----
                  map.put(new Long(date.getTime() * -1), key);
              } catch (Exception e) {}
          }
!         
          // Remove all of our menu items.
          _menu.removeAll();
          
***************
*** 197,213 ****
              // Setup an event which will be sent when
              // the menu item is pressed.
              OpenRequestEvent event = new OpenRequestEvent(
!                 getContext(), new File(name));
              AntMenu subMenu = new AntMenu(getContext(),
!                 event, name);
              
              JMenuItem item = _menu.add(subMenu);
              item.setAccelerator(
!                 KeyStroke.getKeyStroke("control " + count));
              count++;
          }
      }
! 
      /**
       * Remove the oldest entries from the list,
       * if the list is too large.
--- 239,255 ----
              // Setup an event which will be sent when
              // the menu item is pressed.
              OpenRequestEvent event = new OpenRequestEvent(
!             getContext(), new File(name));
              AntMenu subMenu = new AntMenu(getContext(),
!             event, name);
              
              JMenuItem item = _menu.add(subMenu);
              item.setAccelerator(
!             KeyStroke.getKeyStroke("control " + count));
              count++;
          }
      }
!     
      /**
       * Remove the oldest entries from the list,
       * if the list is too large.
***************
*** 226,232 ****
          
          // Remove any extra entries
          while (map.size() > NUMBER_MENU_ITEMS) {
!             map.remove(map.firstKey());
          }
          
          // Transfer the temp map to the real map.
--- 268,278 ----
          
          // Remove any extra entries
          while (map.size() > NUMBER_MENU_ITEMS) {
!             Object key = map.firstKey();
!             map.remove(key); // Remove it from our temp list used to 
reinstance _fileList
!             // .AND. remove it from our global properties (first converting 
key into form
!             // our persistent properties knows about!).
!             
getContext().getPropertiesManager().remove(makeReopenerFilelistKey(key.toString()));
          }
          
          // Transfer the temp map to the real map.
***************
*** 238,312 ****
              _fileList.put(value, key);
          }
      }
! 
!     /**
!      * @return the file used to save the list
!      */
!     protected File getSaveFile() {
!         String home = System.getProperty("user.home");
!         return new File(home + "/antidote.reopen.properties");
!     }
! 
      /**
!      * Saves the list
       */
      protected void saveList() {
          try {
!             File file = getSaveFile();
!             if (!file.exists()) {
!                 file.createNewFile();
!             }
!             FileOutputStream out = new FileOutputStream(file);
!             _fileList.store(out, null);
!         } catch (IOException e) {
!             e.printStackTrace();
          }
      }
! 
      /**
!      * Loads the list
       */
      protected void loadList() {
!         try {
!             File file = getSaveFile();
!             if (file.exists())
!             {
!                 FileInputStream in = new FileInputStream(file);
!                 _fileList.load(in);
              }
-         } catch (IOException e) {
-             e.printStackTrace();
          }
      }
      
      /** Class for handling project events. */
      private class Handler implements BusMember {
          private final Filter _filter = new Filter();
! 
!         /** 
           * Get the filter to that is used to determine if an event should
           * to to the member.
!          * 
           * @return Filter to use.
           */
          public BusFilter getBusFilter() {
              return _filter;
          }
          
!         /** 
           * Called when an event is to be posed to the member.
!          * 
           * @param event Event to post.
           * @return true if event should be propogated, false if
           * it should be cancelled.
           */
          public boolean eventPosted(EventObject event) {
! 
              // We should only get project closed events
! 
              // Find the name of the file which was just closed.
              ACSProjectElement project =
!                 getContext().getSelectionManager().getSelectedProject();
              URL url = project.getLocation();
              if (url == null) {
                  return true;
--- 284,358 ----
              _fileList.put(value, key);
          }
      }
!     
      /**
!      * Saves the list to the global PropertiesManager and causes a props file 
save.
       */
      protected void saveList() {
+         Iterator i = _fileList.keySet().iterator();
+         PropertiesManager pm = getContext().getPropertiesManager();
+         while(i.hasNext()) {
+             String key = (String) i.next();
+             String value = (String) _fileList.get(key);
+             pm.setProperty(makeReopenerFilelistKey(key), value);
+         }
          try {
!             getContext().saveProperties();
!         }
!         catch (java.io.FileNotFoundException e) {
!             // Log error? Show dialog? Couldn't save.
!         }
!         catch (java.io.IOException e) {
!             // Log error? Show dialog? Couldn't save.
          }
      }
!     
      /**
!      * Refreshes the Properties used by the Reopened from the global 
PropertiesManager.
       */
      protected void loadList() {
!         _fileList.clear();
!         PropertiesManager pm = getContext().getPropertiesManager();
!         Iterator i = pm.keySet().iterator();
!         String key = null;
!         String value = null;
!         while(i.hasNext()) {
!             key = (String) i.next();
!             if (isReopenerFilelistKey(key)) {
!                 value = (String) pm.getProperty(key);
!                 _fileList.setProperty(stripReopenerFilelistKey(key), value);
              }
          }
      }
      
      /** Class for handling project events. */
      private class Handler implements BusMember {
          private final Filter _filter = new Filter();
!         
!         /**
           * Get the filter to that is used to determine if an event should
           * to to the member.
!          *
           * @return Filter to use.
           */
          public BusFilter getBusFilter() {
              return _filter;
          }
          
!         /**
           * Called when an event is to be posed to the member.
!          *
           * @param event Event to post.
           * @return true if event should be propogated, false if
           * it should be cancelled.
           */
          public boolean eventPosted(EventObject event) {
!             
              // We should only get project closed events
!             
              // Find the name of the file which was just closed.
              ACSProjectElement project =
!             getContext().getSelectionManager().getSelectedProject();
              URL url = project.getLocation();
              if (url == null) {
                  return true;
***************
*** 319,338 ****
              
              // Add the file to the list
              _fileList.put(file, dateString);
! 
              // Update the menu and save.
              updateMenu();
              saveList();
              return true;
          }
      }
! 
      /** Class providing filtering for project events. */
      private static class Filter implements BusFilter {
          
!         /** 
           * Determines if the given event should be accepted.
!          * 
           * @param event Event to test.
           * @return True if event should be given to BusMember, false 
otherwise.
           */
--- 365,384 ----
              
              // Add the file to the list
              _fileList.put(file, dateString);
!             
              // Update the menu and save.
              updateMenu();
              saveList();
              return true;
          }
      }
!     
      /** Class providing filtering for project events. */
      private static class Filter implements BusFilter {
          
!         /**
           * Determines if the given event should be accepted.
!          *
           * @param event Event to test.
           * @return True if event should be given to BusMember, false 
otherwise.
           */

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to