Kaydet (Commit) 4deb9d4e authored tarafından Ivan Timofeev's avatar Ivan Timofeev

SdrModel: make sure undo/redo stacks are not empty

most probably Undo() does not get called if there is no undo actions,
just to be on the safe side.

Change-Id: I3597698dbe8208916be94ebddd7260fbd7eadc74
üst c050300a
...@@ -575,13 +575,9 @@ public: ...@@ -575,13 +575,9 @@ public:
void SetMaxUndoActionCount(sal_uIntPtr nAnz); void SetMaxUndoActionCount(sal_uIntPtr nAnz);
sal_uIntPtr GetMaxUndoActionCount() const { return nMaxUndoCount; } sal_uIntPtr GetMaxUndoActionCount() const { return nMaxUndoCount; }
void ClearUndoBuffer(); void ClearUndoBuffer();
// UndoAction(0) ist die aktuelle (also die zuletzt eingegangene)
sal_uIntPtr GetUndoActionCount() const { return pUndoStack!=NULL ? pUndoStack->size() : 0; }
const SfxUndoAction* GetUndoAction(sal_uIntPtr nNum) const { return (SfxUndoAction*)(pUndoStack!=NULL ? (*pUndoStack)[nNum] : NULL); }
// RedoAction(0) ist die aktuelle (also die des letzten Undo)
sal_uIntPtr GetRedoActionCount() const { return pRedoStack!=NULL ? pRedoStack->size() : 0; }
const SfxUndoAction* GetRedoAction(sal_uIntPtr nNum) const { return (SfxUndoAction*)(pRedoStack!=NULL ? (*pRedoStack)[nNum] : NULL); }
bool HasUndoActions() const;
bool HasRedoActions() const;
bool Undo(); bool Undo();
bool Redo(); bool Redo();
bool Repeat(SfxRepeatTarget&); bool Repeat(SfxRepeatTarget&);
......
...@@ -791,8 +791,8 @@ IMPL_LINK( SvxIMapDlg, StateHdl, IMapWindow*, pWnd ) ...@@ -791,8 +791,8 @@ IMPL_LINK( SvxIMapDlg, StateHdl, IMapWindow*, pWnd )
aTbxIMapDlg1.EnableItem( TBI_POLYDELETE, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() ); aTbxIMapDlg1.EnableItem( TBI_POLYDELETE, !bDrawEnabled && pView->IsDeleteMarkedPointsPossible() );
// Undo/Redo // Undo/Redo
aTbxIMapDlg1.EnableItem( TBI_UNDO, pModel->GetUndoActionCount() > 0 ); aTbxIMapDlg1.EnableItem( TBI_UNDO, pModel->HasUndoActions() );
aTbxIMapDlg1.EnableItem( TBI_REDO, pModel->GetRedoActionCount() > 0 ); aTbxIMapDlg1.EnableItem( TBI_REDO, pModel->HasRedoActions() );
if ( bPolyEdit ) if ( bPolyEdit )
{ {
......
...@@ -431,6 +431,16 @@ void SdrModel::ClearUndoBuffer() ...@@ -431,6 +431,16 @@ void SdrModel::ClearUndoBuffer()
} }
} }
bool SdrModel::HasUndoActions() const
{
return pUndoStack && !pUndoStack->empty();
}
bool SdrModel::HasRedoActions() const
{
return pRedoStack && !pRedoStack->empty();
}
bool SdrModel::Undo() bool SdrModel::Undo()
{ {
bool bRet = false; bool bRet = false;
...@@ -440,7 +450,7 @@ bool SdrModel::Undo() ...@@ -440,7 +450,7 @@ bool SdrModel::Undo()
} }
else else
{ {
SfxUndoAction* pDo=(SfxUndoAction*)GetUndoAction(0); SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
if(pDo!=NULL) if(pDo!=NULL)
{ {
const bool bWasUndoEnabled = mbUndoEnabled; const bool bWasUndoEnabled = mbUndoEnabled;
...@@ -466,7 +476,7 @@ bool SdrModel::Redo() ...@@ -466,7 +476,7 @@ bool SdrModel::Redo()
} }
else else
{ {
SfxUndoAction* pDo=(SfxUndoAction*)GetRedoAction(0); SfxUndoAction* pDo = HasRedoActions() ? pRedoStack->front() : NULL;
if(pDo!=NULL) if(pDo!=NULL)
{ {
const bool bWasUndoEnabled = mbUndoEnabled; const bool bWasUndoEnabled = mbUndoEnabled;
...@@ -492,7 +502,7 @@ bool SdrModel::Repeat(SfxRepeatTarget& rView) ...@@ -492,7 +502,7 @@ bool SdrModel::Repeat(SfxRepeatTarget& rView)
} }
else else
{ {
SfxUndoAction* pDo=(SfxUndoAction*)GetUndoAction(0); SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
if(pDo!=NULL) if(pDo!=NULL)
{ {
if(pDo->CanRepeat(rView)) if(pDo->CanRepeat(rView))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment