Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2461)
+++ ChangeLog	(working copy)
@@ -1,16 +1,24 @@
+2007-06-06  Willie Walker <william.walker@sun.com>
+
+        * src/orca/script.py, src/orca/focus_tracking_presenter.py,
+        src/orca/Gecko.py, src/orca/scripts/gaim.py,
+        src/orca/scripts/StarOffice.py: fix for bug 433951 - making
+        changes in the Orca Preferences dialog causes loss of script
+        state.
+
 2007-06-05  Rich Burridge <rich.burridge@sun.com>
 
         * src/orca/focus_tracking_presenter.py:
-          Work on bug #435199 - Orca is bloating the swap partition, so 
+          Work on bug #435199 - Orca is bloating the swap partition, so
           the system is no more usable after a short time. Added in a
-          _cleanupCache() routine that gets called in _processObjectEvent() 
-          if we've just received a "object:children-changed:remove" event 
+          _cleanupCache() routine that gets called in _processObjectEvent()
+          if we've just received a "object:children-changed:remove" event
           for the desktop.
 
 2007-06-04  Joanmarie Diggs <j-diggs@comcast.net>
 
-        * src/orca/Gecko.py: Fix for bug 444148 - Orca doesn't speak form 
-        fields at landsend.com 
+        * src/orca/Gecko.py: Fix for bug 444148 - Orca doesn't speak form
+        fields at landsend.com
 
 2007-06-04  Joanmarie Diggs <j-diggs@comcast.net>
 
@@ -20,7 +28,7 @@
 
 2007-06-04  Joanmarie Diggs <j-diggs@comcast.net>
 
-        * src/orca/Gecko.py: Adjustment to the fix for Bug 443337 - Orca 
+        * src/orca/Gecko.py: Adjustment to the fix for Bug 443337 - Orca
         should not use the alt text if it is empty to infer a link name.
 
 2007-06-04  Willie Walker <william.walker@sun.com>
Index: src/orca/scripts/gaim.py
===================================================================
--- src/orca/scripts/gaim.py	(revision 2461)
+++ src/orca/scripts/gaim.py	(working copy)
@@ -194,14 +194,14 @@
         vbox = gtk.VBox(False, 0)
         vbox.set_border_width(12)
         gtk.Widget.show(vbox)
-        # Translators: If this checkbox is checked, then Orca will speak 
+        # Translators: If this checkbox is checked, then Orca will speak
         # the name of the chat room.
         #
         label = _("Speak Chat Room name")
         self.speakNameCheckButton = gtk.CheckButton(label)
         gtk.Widget.show(self.speakNameCheckButton)
         gtk.Box.pack_start(vbox, self.speakNameCheckButton, False, False, 0)
-        gtk.ToggleButton.set_active(self.speakNameCheckButton, 
+        gtk.ToggleButton.set_active(self.speakNameCheckButton,
                                     prefixChatMessage)
 
         return vbox
@@ -221,6 +221,31 @@
         prefs.writelines("orca.scripts.gaim.prefixChatMessage = %s\n" % \
                          prefixChatMessage)
 
+    def getAppState(self):
+        """Returns an object that can be passed to setAppState.  This
+        object will be use by setAppState to restore any state information
+        that was being maintained by the script."""
+        return [default.Script.getAppState(self),
+                self.previousMessages,
+                self.previousChatRoomNames,
+                self.chatAreas]
+
+    def setAppState(self, appState):
+        """Sets the application state using the given appState object.
+
+        Arguments:
+        - appState: an object obtained from getAppState
+        """
+        try:
+            [defaultAppState,
+             self.previousMessages,
+             self.previousChatRoomNames,
+             self.chatAreas] = appState
+            default.Script.setAppState(self, defaultAppState)
+        except:
+            debug.printException(debug.LEVEL_WARNING)
+            pass
+
     def togglePrefix(self, inputEvent):
         """ Toggle whether we prefix chat room messages with the name of
         the chat room.
Index: src/orca/scripts/StarOffice.py
===================================================================
--- src/orca/scripts/StarOffice.py	(revision 2461)
+++ src/orca/scripts/StarOffice.py	(working copy)
@@ -478,7 +478,7 @@
         # If this is a table with no children, then let the user know.
         #
         if not obj.childCount:
-            # Translators: this indicates that there are zero items in 
+            # Translators: this indicates that there are zero items in
             # a layered pane or table.
             #
             utterances.append(_("0 items"))
@@ -879,7 +879,7 @@
         # attributes associated with it (such as font type, size, style...)
         # This label denotes those attributes that you user would like
         # spoken when you ask to hear the text attributes associated with
-        # the current text (typically when the Insert-f key combination is 
+        # the current text (typically when the Insert-f key combination is
         # pressed).
         #
         self.textAttributesLabel = gtk.Label(_("Enabled Text Attributes:"))
@@ -911,7 +911,7 @@
         label = _("Speak spread sheet cell coordinates")
         self.speakCellCoordinatesCheckButton = gtk.CheckButton(label)
         gtk.Widget.show(self.speakCellCoordinatesCheckButton)
-        gtk.Box.pack_start(vbox, self.speakCellCoordinatesCheckButton, 
+        gtk.Box.pack_start(vbox, self.speakCellCoordinatesCheckButton,
                            False, False, 0)
         gtk.ToggleButton.set_active(self.speakCellCoordinatesCheckButton,
                                     speakCellCoordinates)
@@ -939,6 +939,29 @@
                  "orca.scripts.StarOffice.speakCellCoordinates = %s\n" % \
                  speakCellCoordinates)
 
+    def getAppState(self):
+        """Returns an object that can be passed to setAppState.  This
+        object will be use by setAppState to restore any state information
+        that was being maintained by the script."""
+        return [default.Script.getAppState(self),
+                self.dynamicColumnHeaders,
+                self.dynamicRowHeaders]
+
+    def setAppState(self, appState):
+        """Sets the application state using the given appState object.
+
+        Arguments:
+        - appState: an object obtained from getAppState
+        """
+        try:
+            [defaultAppState,
+             self.dynamicColumnHeaders,
+             self.dynamicRowHeaders] = appState
+            default.Script.setAppState(self, defaultAppState)
+        except:
+            debug.printException(debug.LEVEL_WARNING)
+            pass
+
     def adjustForWriterTable(self, obj):
         """Check to see if we are in Writer, where the object with focus
         is a paragraph, and the parent is the table cell. If it is, then,
@@ -1048,7 +1071,7 @@
         return inputLine
 
     def getSpreadSheetRowRange(self, obj):
-        """If this is spread sheet cell, return the start and end indices 
+        """If this is spread sheet cell, return the start and end indices
         of the spread sheet cells for the table that obj is in. Otherwise
         return the complete range (0, parent.table.nColumns).
 
Index: src/orca/focus_tracking_presenter.py
===================================================================
--- src/orca/focus_tracking_presenter.py	(revision 2461)
+++ src/orca/focus_tracking_presenter.py	(working copy)
@@ -292,7 +292,7 @@
         try:
             orca_state.activeScript.activate()
         except:
-            pass 
+            pass
 
     def _cleanupCache(self):
         """Looks for defunct accessible objects in the cache and removes them.
@@ -377,8 +377,8 @@
 
                     # Setup the user's application specific key bindings.
                     # (if any).
-                    # 
-                    if hasattr(self._knownAppSettings[name], 
+                    #
+                    if hasattr(self._knownAppSettings[name],
                                "overrideAppKeyBindings"):
                         script.overrideAppKeyBindings = \
                             self._knownAppSettings[name].overrideAppKeyBindings
@@ -445,7 +445,7 @@
         #
         try:
             if event.source.role == rolenames.ROLE_TOOL_TIP:
-                # Check that it's okay to present tool tips. Always present 
+                # Check that it's okay to present tool tips. Always present
                 # tooltips initiated by the user pressing Control-F1 on the
                 # keyboard.
                 #
@@ -457,7 +457,7 @@
                     # Mouse move events don't update orca_state.lastInputEvent
                     # so it's possible the user accidentally nudged the
                     # mouse and generated another tooltip event. If the
-                    # current time minus the last keyboard event time is 
+                    # current time minus the last keyboard event time is
                     # greater than 0.2 seconds, than just ignore this tooltip
                     # event.
                     #
@@ -915,6 +915,23 @@
         if orca_state.activeScript:
             orca_state.activeScript.visualAppearanceChanged(event, obj)
 
+    def _saveAppStates(self):
+        """Saves script and application state information."""
+        self._appStateInfo = []
+        for script in self._knownScripts.values():
+            self._appStateInfo.append([script.app, script.getAppState()])
+
+    def _restoreAppStates(self):
+        """Restores script and application state information."""
+        try:
+            for [app, appState] in self._appStateInfo:
+                script = self._getScript(app)
+                script.setAppState(appState)
+        except:
+            pass
+
+        self._appStateInfo = None
+
     def activate(self):
         """Called when this presentation manager is activated."""
 
@@ -924,6 +941,8 @@
         self._oldAppSettings = None
         self._defaultScript  = None
 
+        self._restoreAppStates()
+        
         self.setActiveScript(self._getScript(None))
 
         # Tell BrlTTY which commands we care about.
@@ -950,6 +969,8 @@
     def deactivate(self):
         """Called when this presentation manager is deactivated."""
 
+        self._saveAppStates()
+        
         for eventType in self._listenerCounts.keys():
             self.registry.deregisterEventListener(self._enqueueEvent,
                                                   eventType)
Index: src/orca/Gecko.py
===================================================================
--- src/orca/Gecko.py	(revision 2461)
+++ src/orca/Gecko.py	(working copy)
@@ -2277,6 +2277,29 @@
         prefs.writelines("orca.Gecko.minimumFindLength = %s\n" % value)
         minimumFindLength = value
 
+    def getAppState(self):
+        """Returns an object that can be passed to setAppState.  This
+        object will be use by setAppState to restore any state information
+        that was being maintained by the script."""
+        return [default.Script.getAppState(self),
+                self._documentFrameCaretContext,
+                self.lastTableCell]
+
+    def setAppState(self, appState):
+        """Sets the application state using the given appState object.
+
+        Arguments:
+        - appState: an object obtained from getAppState
+        """
+        try:
+            [defaultAppState,
+             self._documentFrameCaretContext,
+             self.lastTableCell] = appState
+            default.Script.setAppState(self, defaultAppState)
+        except:
+            debug.printException(debug.LEVEL_WARNING)
+            pass
+
     def consumesKeyboardEvent(self, keyboardEvent):
         """Called when a key is pressed on the keyboard.
 
Index: src/orca/script.py
===================================================================
--- src/orca/script.py	(revision 2461)
+++ src/orca/script.py	(working copy)
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright 2004-2006 Sun Microsystems Inc.
+# Copyright 2004-2007 Sun Microsystems Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -36,7 +36,7 @@
 __id__        = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2007 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import braillegenerator
@@ -202,6 +202,20 @@
 
         return keyBindings
 
+    def getAppState(self):
+        """Returns an object that can be passed to setAppState.  This
+        object will be used by setAppState to restore any state
+        information that was being maintained by the script."""
+        return None
+
+    def setAppState(self, appState):
+        """Sets the application state using the given appState object.
+
+        Arguments:
+        - appState: an object obtained from getAppState
+        """
+        return
+        
     # [[[WDW - There is a circular reference going on somewhere (see
     # bug 333168).  In the presence of this reference, the existence
     # of a __del__ method prevents the garbage collector from
