Implement undo and redo for wxTextCtrl under Mac
Use the parent undo manager to implement these functions.
This commit is contained in:
@@ -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
|
||||
|
@@ -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 )
|
||||
|
Reference in New Issue
Block a user