Commits

Geoffrey French  committed 2046cb7

Change history attached to document now 'connected' to Window via a chain of ChangeHistoryProxy instances.

  • Participants
  • Parent commits d15ad14
  • Tags 0.1.31s-alpha

Comments (0)

Files changed (8)

File java/BritefuryJ/Browser/Browser.java

 import javax.swing.TransferHandler;
 
 import BritefuryJ.AttributeTable.SimpleAttributeTable;
+import BritefuryJ.ChangeHistory.AbstractChangeHistory;
 import BritefuryJ.ChangeHistory.ChangeHistory;
+import BritefuryJ.ChangeHistory.ChangeHistoryProxy;
 import BritefuryJ.Command.AbstractCommandConsole;
 import BritefuryJ.Command.BoundCommandSet;
 import BritefuryJ.Command.Command;
 	private Subject rootSubject, subject;
 	private FragmentInspector inspector;
 	private BrowserListener listener;
+
+	private ChangeHistoryProxy changeHistoryProxy;
 	
 	private ScrolledPane mainPane;
 	private BrowserEdgePane leftEdge, rightEdge, topEdge, bottomEdge;
 		this.subject = subject;
 		this.inspector = inspector;
 		history = new BrowserHistory( subject );
+		this.changeHistoryProxy = new ChangeHistoryProxy(subject.getChangeHistory());
 
 		mainPane = new ScrolledPane();
 		
 	
 	
 	
-	public ChangeHistory getChangeHistory()
+	public AbstractChangeHistory getChangeHistory()
 	{
-		if ( subject != null )
-		{
-			return subject.getChangeHistory();
-		}
-		else
-		{
-			return null;
-		}
+		return changeHistoryProxy;
 	}
 	
 
 		if ( s != subject )
 		{
 			subject = s;
+			changeHistoryProxy.setChangeHistory(subject.getChangeHistory());
 			
 			if ( listener != null )
 			{

File java/BritefuryJ/Browser/TabbedBrowser.java

 import javax.swing.event.ChangeListener;
 import javax.swing.plaf.basic.BasicButtonUI;
 
+import BritefuryJ.ChangeHistory.AbstractChangeHistory;
 import BritefuryJ.ChangeHistory.ChangeHistory;
+import BritefuryJ.ChangeHistory.ChangeHistoryProxy;
 import BritefuryJ.Command.CommandConsoleFactory;
 import BritefuryJ.IncrementalView.FragmentInspector;
 import BritefuryJ.LSpace.PageController;
 	
 	private ArrayList<Browser> browsers;
 	private Browser currentBrowser;
+
+	private ChangeHistoryProxy changeHistoryProxy;
 	
 	private CommandConsoleFactory commandConsoleFactory;
 	
 
 		tabs = new JTabbedPane();
 		tabs.addChangeListener( this );
+
+		changeHistoryProxy = new ChangeHistoryProxy(null);
 		
 		Browser browser = addNewBrowser( subject );
 		setCurrentBrowser( browser );
 	}
 	
 	
-	public ChangeHistory getChangeHistory()
+	public AbstractChangeHistory getChangeHistory()
 	{
-		return currentBrowser.getChangeHistory();
+		return changeHistoryProxy;
 	}
 	
 
 		if ( browser != currentBrowser )
 		{
 			currentBrowser = browser;
+			changeHistoryProxy.setChangeHistory(currentBrowser.getChangeHistory());
 			
 			if ( listener != null )
 			{

File java/BritefuryJ/ChangeHistory/ChangeHistory.java

 	private ArrayList<Entry> past, future;
 	private boolean changesBlocked, bFrozen;
 	private int freezeCount;
-	private ArrayList<ChangeHistoryListener> listeners;
 	private PresentationStateListenerList presStateListeners = null;
 	
 	
 		changesBlocked = false;
 		bFrozen = false;
 		freezeCount = 0;
-		listeners = new ArrayList<ChangeHistoryListener>();
 	}
 
 
 	}
 
 	
-	public void addChangeHistoryListener(ChangeHistoryListener listener)
-	{
-		listeners.add( listener );
-	}
-	
-	public void removeChangeHistoryListener(ChangeHistoryListener listener)
-	{
-		listeners.remove( listener );
-	}
-	
-	
-	
-	
 	public void addChange(Change change)
 	{
 		if ( !changesBlocked )

File java/BritefuryJ/ChangeHistory/ChangeHistoryProxy.java

 package BritefuryJ.ChangeHistory;
 
 public class ChangeHistoryProxy extends AbstractChangeHistory implements ChangeHistoryListener {
-	private AbstractChangeHistory ch;
+	private AbstractChangeHistory underlyingChangeHistory;
 
 
 	public ChangeHistoryProxy(AbstractChangeHistory ch) {
-		this.ch = null;
+		this.underlyingChangeHistory = null;
 
 		setChangeHistory(ch);
 	}
 
 
 	public void setChangeHistory(AbstractChangeHistory ch) {
-		if (this.ch != null) {
-			this.ch.removeChangeHistoryListener(this);
+		if (this.underlyingChangeHistory != null) {
+			this.underlyingChangeHistory.removeChangeHistoryListener(this);
 		}
-		this.ch = ch;
-		if (this.ch != null) {
-			this.ch.addChangeHistoryListener(this);
+		this.underlyingChangeHistory = ch;
+		if (this.underlyingChangeHistory != null) {
+			this.underlyingChangeHistory.addChangeHistoryListener(this);
 		}
+		onModified();
 	}
 
 
 	public ChangeHistory concreteChangeHistory() {
-		return ch.concreteChangeHistory();
+		return underlyingChangeHistory != null  ?  underlyingChangeHistory.concreteChangeHistory()  :  null;
 	}
 
 	public boolean canUndo() {
-		return ch.canUndo();
+		return underlyingChangeHistory != null && underlyingChangeHistory.canUndo();
 	}
 
 	public boolean canRedo() {
-		return ch.canRedo();
+		return underlyingChangeHistory != null && underlyingChangeHistory.canRedo();
 	}
 
 	public int getNumUndoChanges() {
-		return ch.getNumUndoChanges();
+		return underlyingChangeHistory != null  ?  underlyingChangeHistory.getNumUndoChanges()  :  0;
 	}
 
 	public int getNumRedoChanges() {
-		return ch.getNumRedoChanges();
+		return underlyingChangeHistory != null  ?  underlyingChangeHistory.getNumRedoChanges()  :  0;
 	}
 
 
 	public void onChangeHistoryChanged(AbstractChangeHistory history) {
 		onModified();
 	}
+
+
+	@Override
+	public String toString() {
+		return "ChangeHistoryProxy<" + System.identityHashCode(this) + ">(" + underlyingChangeHistory + ")";
+	}
 }

File java/BritefuryJ/Command/CommandConsole.java

 
 import BritefuryJ.AttributeTable.SimpleAttributeTable;
 import BritefuryJ.Browser.Browser;
-import BritefuryJ.ChangeHistory.ChangeHistory;
+import BritefuryJ.ChangeHistory.AbstractChangeHistory;
 import BritefuryJ.Controls.Hyperlink;
 import BritefuryJ.DefaultPerspective.Presentable;
 import BritefuryJ.Graphics.AbstractBorder;
 			return "Command console";
 		}
 
-		public ChangeHistory getChangeHistory()
+		public AbstractChangeHistory getChangeHistory()
 		{
 			return null;
 		}

File java/BritefuryJ/IncrementalView/IncrementalView.java

 import java.lang.ref.WeakReference;
 import java.util.*;
 
+import BritefuryJ.ChangeHistory.AbstractChangeHistory;
 import BritefuryJ.Util.PresentationErrorHandler;
 import org.python.core.Py;
 
 	
 	private StateStore stateStoreToLoad;
 	
-	private ChangeHistory changeHistory;
+	private AbstractChangeHistory changeHistory;
 
 	private Pres viewPres;
 	private LSElement rootElement;
 	// Contexts, logs, etc
 	//
 	
-	public ChangeHistory getChangeHistory()
+	public AbstractChangeHistory getChangeHistory()
 	{
 		return changeHistory;
 	}

File java/BritefuryJ/Projection/Subject.java

 import java.util.ArrayList;
 import java.util.List;
 
+import BritefuryJ.ChangeHistory.AbstractChangeHistory;
 import org.python.core.*;
 
 import BritefuryJ.ChangeHistory.ChangeHistory;
 	public abstract String getTitle();
 
 	
-	public ChangeHistory getChangeHistory()
+	public AbstractChangeHistory getChangeHistory()
 	{
 		if ( enclosingSubject != null )
 		{

File larch/Britefury/Windows/Window.py

 
 
 
-		def onChangeHistoryChanged(history):
-			self.__refreshChangeHistoryControls( history )
-
-		self.__prevChangeHistory = None
-		self.__changeHistoryListener = onChangeHistoryChanged
-
 
 
 		self.onCloseRequestListener = None
 				self._onOpenNewWindow( subject )
 
 			def onTabbledBrowserChangePage(_self, browser):
-				self._onChangePage( browser )
+				pass
 
 
 		def inspectFragment(fragment, sourceElement, triggeringEvent):
 			return self._windowManager.world.inspectFragment( fragment, sourceElement, triggeringEvent )
 
 
+
+		def onChangeHistoryChanged(history):
+			self.__refreshChangeHistoryControls( history )
+
 		self._browser = TabbedBrowser( self._windowManager.world.rootSubject, subject, inspectFragment, _BrowserListener(), commandConsoleFactory )
 		self._browser.getComponent().setPreferredSize( Dimension( 800, 600 ) )
+		changeHistory = self._browser.getChangeHistory()
+		self._browser.getChangeHistory().addChangeHistoryListener(onChangeHistoryChanged)
 
 
 
 
 
 
-	def _onChangePage(self, browser):
-		changeHistory = browser.getChangeHistory()
-
-		if changeHistory is not self.__prevChangeHistory:
-			if self.__prevChangeHistory is not None:
-				self.__prevChangeHistory.removeChangeHistoryListener( self.__changeHistoryListener )
-
-			if changeHistory is not None:
-				changeHistory.addChangeHistoryListener( self.__changeHistoryListener )
-
-			self.__prevChangeHistory = changeHistory
-
-			self.__refreshChangeHistoryControls( changeHistory )
-
-
 	def __refreshChangeHistoryControls(self, changeHistory):
 		if changeHistory is not None:
 			self.__editUndoItem.setEnabled( changeHistory.canUndo() )
 	def __onUndo(self):
 		changeHistory = self._browser.getChangeHistory()
 		if changeHistory.canUndo():
-			changeHistory.undo()
+			changeHistory.concreteChangeHistory().undo()
 
 	def __onRedo(self):
 		changeHistory = self._browser.getChangeHistory()
 		if changeHistory.canRedo():
-			changeHistory.redo()
+			changeHistory.concreteChangeHistory().redo()
 
 
 		
 
 	def __onShowUndoHistory(self):
-		changeHistory = self._browser.getChangeHistory()
+		changeHistory = self._browser.getChangeHistory().concreteChangeHistory()
 		if changeHistory is not None:
 			subject = DefaultPerspective.instance.objectSubject( changeHistory )
 			self._browser.openSubjectInNewWindow( subject )