cocoa: changing the way undo manager is allocated. Changing handling of the text assignment to a memo. Patch by Zoë Peterson. bug #36073

git-svn-id: trunk@62438 -
This commit is contained in:
dmitry 2019-12-23 20:07:57 +00:00
parent 16d8971fa2
commit 4404a659e0
3 changed files with 14 additions and 25 deletions

View File

@ -124,7 +124,6 @@ type
procedure dealloc; override;
function acceptsFirstResponder: LCLObjCBoolean; override;
function undoManager: NSUndoManager; override;
function lclGetCallback: ICommonCallback; override;
procedure lclClearCallback; override;
procedure resetCursorRects; override;
@ -153,6 +152,7 @@ type
// delegate methods
procedure textDidChange(notification: NSNotification); message 'textDidChange:';
procedure lclExpectedKeys(var wantTabs, wantArrows, wantReturn, wantAll: Boolean); override;
function undoManagerForTextView(view: NSTextView): NSUndoManager; message 'undoManagerForTextView:';
end;
{ TCococaFieldEditorExt }
@ -1037,18 +1037,6 @@ begin
Result := NSViewCanFocus(Self);
end;
function TCocoaTextView.undoManager: NSUndoManager;
begin
if allowsUndo then
begin
if not Assigned(FUndoManager) then
FUndoManager := NSUndoManager.alloc.init;
Result := FUndoManager;
end
else
Result := nil;
end;
function TCocoaTextView.lclGetCallback: ICommonCallback;
begin
Result := callback;
@ -1187,6 +1175,13 @@ begin
wantAll := true;
end;
function TCocoaTextView.undoManagerForTextView(view: NSTextView): NSUndoManager;
begin
if not Assigned(FUndoManager) then
FUndoManager := NSUndoManager.alloc.init;
Result := FUndoManager;
end;
{ TCocoaSecureTextField }
function TCocoaSecureTextField.acceptsFirstResponder: LCLObjCBoolean;

View File

@ -618,6 +618,7 @@ begin
ns := NSStringUTF8(s);
text.setString(ns);
ns.release;
text.undoManager.removeAllActions;
end;
end;

View File

@ -1173,12 +1173,8 @@ begin
end;
procedure TCocoaMemoStrings.SetTextStr(const Value: string);
var
ns: NSString;
begin
ns := NSStringUtf8(LineBreaksToUnix(Value));
FTextView.setString(ns);
ns.release;
SetNSText(FTextView, LineBreaksToUnix(Value));
FTextView.textDidChange(nil);
end;
@ -1301,6 +1297,8 @@ begin
FTextView.insertText( NSString.stringWithUTF8String( LFSTR ));
if not ro then FTextView.setEditable(ro);
FTextView.undoManager.removeAllActions;
end;
procedure TCocoaMemoStrings.LoadFromFile(const FileName: string);
@ -1471,9 +1469,7 @@ begin
txt.callback := lcl;
txt.setDelegate(txt);
ns := NSStringUtf8(AParams.Caption);
txt.setString(ns);
ns.release;
SetNSText(txt, AParams.Caption);
scr.callback := txt.callback;
@ -1684,13 +1680,10 @@ end;
class procedure TCocoaWSCustomMemo.SetText(const AWinControl:TWinControl;const AText:String);
var
txt: TCocoaTextView;
ns: NSString;
begin
txt := GetTextView(AWinControl);
if not Assigned(txt) then Exit;
ns := NSStringUtf8(LineBreaksToUnix(AText));
txt.setString(ns);
ns.release;
SetNSText(txt, LineBreaksToUnix(AText));
end;
class function TCocoaWSCustomMemo.GetText(const AWinControl: TWinControl; var AText: String): Boolean;