diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 0874cbc905..bae8f8aa56 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -136,12 +136,18 @@ public: virtual void controlTextDidChange() wxOVERRIDE; + virtual bool CanUndo() const wxOVERRIDE; + virtual void Undo() wxOVERRIDE; + virtual bool CanRedo() const wxOVERRIDE; + virtual void Redo() wxOVERRIDE; + protected: void DoUpdateTextStyle(); NSScrollView* m_scrollView; NSTextView* m_textView; bool m_useCharWrapping; + NSUndoManager* m_undoManager; }; class wxNSComboBoxControl : public wxNSTextFieldControl, public wxComboWidgetImpl diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index f8cf958591..b52f1da4d7 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -773,6 +773,12 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s [tv setDelegate: tv]; + m_undoManager = nil; + if ( wxPeer && wxPeer->GetParent() && wxPeer->GetParent()->GetPeer() && wxPeer->GetParent()->GetPeer()->GetWXWidget() ) + m_undoManager = [wxPeer->GetParent()->GetPeer()->GetWXWidget() undoManager]; + + [tv setAllowsUndo:YES]; + InstallEventHandler(tv); } @@ -1019,6 +1025,38 @@ void wxNSTextViewControl::controlTextDidChange() DoUpdateTextStyle(); } +bool wxNSTextViewControl::CanUndo() const +{ + if ( !m_undoManager ) + return false; + + return [m_undoManager canUndo]; +} + +void wxNSTextViewControl::Undo() +{ + if ( !m_undoManager ) + return; + + [m_undoManager undo]; +} + +bool wxNSTextViewControl::CanRedo() const +{ + if ( !m_undoManager ) + return false; + + return [m_undoManager canRedo]; +} + +void wxNSTextViewControl::Redo() +{ + if ( !m_undoManager ) + return; + + [m_undoManager redo]; +} + void wxNSTextViewControl::DoUpdateTextStyle() { if ( m_useCharWrapping )