Fix bug 75271; ensure that we update commands properly for batched transactions. r=akkana, sr=kin

This commit is contained in:
sfraser%netscape.com 2001-04-11 23:11:29 +00:00
Родитель 24c981fc83
Коммит 702a05ff10
4 изменённых файлов: 64 добавлений и 36 удалений

Просмотреть файл

@ -51,6 +51,7 @@ nsInterfaceState::nsInterfaceState()
, mDirtyState(eStateUninitialized) , mDirtyState(eStateUninitialized)
, mSelectionCollapsed(eStateUninitialized) , mSelectionCollapsed(eStateUninitialized)
, mFirstDoOfFirstUndo(PR_TRUE) , mFirstDoOfFirstUndo(PR_TRUE)
, mBatchDepth(0)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
@ -123,16 +124,8 @@ NS_IMETHODIMP nsInterfaceState::WillDo(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidDo(nsITransactionManager *aManager, NS_IMETHODIMP nsInterfaceState::DidDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aDoResult) nsITransaction *aTransaction, nsresult aDoResult)
{ {
// only need to update if the status of the Undo menu item changes. if (mBatchDepth == 0)
PRInt32 undoCount; UpdateUndoCommands(aManager);
aManager->GetNumberOfUndoItems(&undoCount);
if (undoCount == 1)
{
if (mFirstDoOfFirstUndo)
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo"));
mFirstDoOfFirstUndo = PR_FALSE;
}
return NS_OK; return NS_OK;
} }
@ -151,7 +144,7 @@ NS_IMETHODIMP nsInterfaceState::DidUndo(nsITransactionManager *aManager,
if (undoCount == 0) if (undoCount == 0)
mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo")); CallUpdateCommands(NS_LITERAL_STRING("undo"));
return NS_OK; return NS_OK;
} }
@ -165,7 +158,7 @@ NS_IMETHODIMP nsInterfaceState::WillRedo(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidRedo(nsITransactionManager *aManager, NS_IMETHODIMP nsInterfaceState::DidRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aRedoResult) nsITransaction *aTransaction, nsresult aRedoResult)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo")); CallUpdateCommands(NS_LITERAL_STRING("undo"));
return NS_OK; return NS_OK;
} }
@ -177,6 +170,7 @@ NS_IMETHODIMP nsInterfaceState::WillBeginBatch(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult) NS_IMETHODIMP nsInterfaceState::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult)
{ {
++mBatchDepth;
return NS_OK; return NS_OK;
} }
@ -188,6 +182,10 @@ NS_IMETHODIMP nsInterfaceState::WillEndBatch(nsITransactionManager *aManager, PR
NS_IMETHODIMP nsInterfaceState::DidEndBatch(nsITransactionManager *aManager, nsresult aResult) NS_IMETHODIMP nsInterfaceState::DidEndBatch(nsITransactionManager *aManager, nsresult aResult)
{ {
--mBatchDepth;
if (mBatchDepth == 0)
UpdateUndoCommands(aManager);
return NS_OK; return NS_OK;
} }
@ -230,17 +228,32 @@ nsresult nsInterfaceState::PrimeUpdateTimer()
} }
nsresult nsInterfaceState::UpdateUndoCommands(nsITransactionManager *aManager)
{
// only need to update if the status of the Undo menu item changes.
PRInt32 undoCount;
aManager->GetNumberOfUndoItems(&undoCount);
if (undoCount == 1)
{
if (mFirstDoOfFirstUndo)
CallUpdateCommands(NS_LITERAL_STRING("undo"));
mFirstDoOfFirstUndo = PR_FALSE;
}
return NS_OK;
}
void nsInterfaceState::TimerCallback() void nsInterfaceState::TimerCallback()
{ {
// if the selection state has changed, update stuff // if the selection state has changed, update stuff
PRBool isCollapsed = SelectionIsCollapsed(); PRBool isCollapsed = SelectionIsCollapsed();
if (isCollapsed != mSelectionCollapsed) if (isCollapsed != mSelectionCollapsed)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("select")); CallUpdateCommands(NS_LITERAL_STRING("select"));
mSelectionCollapsed = isCollapsed; mSelectionCollapsed = isCollapsed;
} }
CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); CallUpdateCommands(NS_LITERAL_STRING("style"));
} }
nsresult nsresult
@ -248,7 +261,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
{ {
if (mDirtyState != aNowDirty) if (mDirtyState != aNowDirty)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); CallUpdateCommands(NS_LITERAL_STRING("save"));
mDirtyState = aNowDirty; mDirtyState = aNowDirty;
} }
@ -256,7 +269,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
return NS_OK; return NS_OK;
} }
nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) nsresult nsInterfaceState::CallUpdateCommands(const nsAString& aCommand)
{ {
if (!mDOMWindow) if (!mDOMWindow)
{ {

Просмотреть файл

@ -89,8 +89,8 @@ protected:
PRBool SelectionIsCollapsed(); PRBool SelectionIsCollapsed();
nsresult UpdateDirtyState(PRBool aNowDirty); nsresult UpdateDirtyState(PRBool aNowDirty);
nsresult CallUpdateCommands(const nsString& aCommand); nsresult CallUpdateCommands(const nsAString& aCommand);
nsresult UpdateUndoCommands(nsITransactionManager *aManager);
nsresult PrimeUpdateTimer(); nsresult PrimeUpdateTimer();
void TimerCallback(); void TimerCallback();
@ -107,6 +107,7 @@ protected:
PRInt8 mDirtyState; PRInt8 mDirtyState;
PRInt8 mSelectionCollapsed; PRInt8 mSelectionCollapsed;
PRPackedBool mFirstDoOfFirstUndo; PRPackedBool mFirstDoOfFirstUndo;
PRInt32 mBatchDepth;
}; };

Просмотреть файл

@ -51,6 +51,7 @@ nsInterfaceState::nsInterfaceState()
, mDirtyState(eStateUninitialized) , mDirtyState(eStateUninitialized)
, mSelectionCollapsed(eStateUninitialized) , mSelectionCollapsed(eStateUninitialized)
, mFirstDoOfFirstUndo(PR_TRUE) , mFirstDoOfFirstUndo(PR_TRUE)
, mBatchDepth(0)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
@ -123,16 +124,8 @@ NS_IMETHODIMP nsInterfaceState::WillDo(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidDo(nsITransactionManager *aManager, NS_IMETHODIMP nsInterfaceState::DidDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aDoResult) nsITransaction *aTransaction, nsresult aDoResult)
{ {
// only need to update if the status of the Undo menu item changes. if (mBatchDepth == 0)
PRInt32 undoCount; UpdateUndoCommands(aManager);
aManager->GetNumberOfUndoItems(&undoCount);
if (undoCount == 1)
{
if (mFirstDoOfFirstUndo)
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo"));
mFirstDoOfFirstUndo = PR_FALSE;
}
return NS_OK; return NS_OK;
} }
@ -151,7 +144,7 @@ NS_IMETHODIMP nsInterfaceState::DidUndo(nsITransactionManager *aManager,
if (undoCount == 0) if (undoCount == 0)
mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo")); CallUpdateCommands(NS_LITERAL_STRING("undo"));
return NS_OK; return NS_OK;
} }
@ -165,7 +158,7 @@ NS_IMETHODIMP nsInterfaceState::WillRedo(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidRedo(nsITransactionManager *aManager, NS_IMETHODIMP nsInterfaceState::DidRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aRedoResult) nsITransaction *aTransaction, nsresult aRedoResult)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("undo")); CallUpdateCommands(NS_LITERAL_STRING("undo"));
return NS_OK; return NS_OK;
} }
@ -177,6 +170,7 @@ NS_IMETHODIMP nsInterfaceState::WillBeginBatch(nsITransactionManager *aManager,
NS_IMETHODIMP nsInterfaceState::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult) NS_IMETHODIMP nsInterfaceState::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult)
{ {
++mBatchDepth;
return NS_OK; return NS_OK;
} }
@ -188,6 +182,10 @@ NS_IMETHODIMP nsInterfaceState::WillEndBatch(nsITransactionManager *aManager, PR
NS_IMETHODIMP nsInterfaceState::DidEndBatch(nsITransactionManager *aManager, nsresult aResult) NS_IMETHODIMP nsInterfaceState::DidEndBatch(nsITransactionManager *aManager, nsresult aResult)
{ {
--mBatchDepth;
if (mBatchDepth == 0)
UpdateUndoCommands(aManager);
return NS_OK; return NS_OK;
} }
@ -230,17 +228,32 @@ nsresult nsInterfaceState::PrimeUpdateTimer()
} }
nsresult nsInterfaceState::UpdateUndoCommands(nsITransactionManager *aManager)
{
// only need to update if the status of the Undo menu item changes.
PRInt32 undoCount;
aManager->GetNumberOfUndoItems(&undoCount);
if (undoCount == 1)
{
if (mFirstDoOfFirstUndo)
CallUpdateCommands(NS_LITERAL_STRING("undo"));
mFirstDoOfFirstUndo = PR_FALSE;
}
return NS_OK;
}
void nsInterfaceState::TimerCallback() void nsInterfaceState::TimerCallback()
{ {
// if the selection state has changed, update stuff // if the selection state has changed, update stuff
PRBool isCollapsed = SelectionIsCollapsed(); PRBool isCollapsed = SelectionIsCollapsed();
if (isCollapsed != mSelectionCollapsed) if (isCollapsed != mSelectionCollapsed)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("select")); CallUpdateCommands(NS_LITERAL_STRING("select"));
mSelectionCollapsed = isCollapsed; mSelectionCollapsed = isCollapsed;
} }
CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); CallUpdateCommands(NS_LITERAL_STRING("style"));
} }
nsresult nsresult
@ -248,7 +261,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
{ {
if (mDirtyState != aNowDirty) if (mDirtyState != aNowDirty)
{ {
CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); CallUpdateCommands(NS_LITERAL_STRING("save"));
mDirtyState = aNowDirty; mDirtyState = aNowDirty;
} }
@ -256,7 +269,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
return NS_OK; return NS_OK;
} }
nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) nsresult nsInterfaceState::CallUpdateCommands(const nsAString& aCommand)
{ {
if (!mDOMWindow) if (!mDOMWindow)
{ {

Просмотреть файл

@ -89,8 +89,8 @@ protected:
PRBool SelectionIsCollapsed(); PRBool SelectionIsCollapsed();
nsresult UpdateDirtyState(PRBool aNowDirty); nsresult UpdateDirtyState(PRBool aNowDirty);
nsresult CallUpdateCommands(const nsString& aCommand); nsresult CallUpdateCommands(const nsAString& aCommand);
nsresult UpdateUndoCommands(nsITransactionManager *aManager);
nsresult PrimeUpdateTimer(); nsresult PrimeUpdateTimer();
void TimerCallback(); void TimerCallback();
@ -107,6 +107,7 @@ protected:
PRInt8 mDirtyState; PRInt8 mDirtyState;
PRInt8 mSelectionCollapsed; PRInt8 mSelectionCollapsed;
PRPackedBool mFirstDoOfFirstUndo; PRPackedBool mFirstDoOfFirstUndo;
PRInt32 mBatchDepth;
}; };