From 9ead143427d179a3c3b57ea904641b440f89e8df Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Thu, 29 Sep 2016 07:47:23 +0000 Subject: [PATCH] memo: Changes the LFM writer to store the lines without wordwrap so that this information is not lost, see bug #30659 git-svn-id: trunk@53052 - --- lcl/interfaces/carbon/carbonstrings.pp | 4 +- lcl/interfaces/cocoa/cocoawsstdctrls.pp | 4 +- lcl/interfaces/lcl.lpk | 5 +++ lcl/lclbase.lpk | 5 +++ lcl/textstrings.pas | 55 ++++++++++++++++++++++++- 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/lcl/interfaces/carbon/carbonstrings.pp b/lcl/interfaces/carbon/carbonstrings.pp index d77e7bcbc7..6e38e3c85c 100644 --- a/lcl/interfaces/carbon/carbonstrings.pp +++ b/lcl/interfaces/carbon/carbonstrings.pp @@ -26,7 +26,7 @@ uses // rtl+ftl Classes, SysUtils, // LCL - LCLProc, LCLType, Graphics, Controls, StdCtrls, LazUtf8Classes, + LCLProc, LCLType, Graphics, Controls, StdCtrls, LazUtf8Classes, textstrings, // LCL Carbon CarbonEdits, CarbonListViews; @@ -80,7 +80,7 @@ type { TCarbonMemoStrings } - TCarbonMemoStrings = class(TStrings) + TCarbonMemoStrings = class(TCustomMemoStrings) private FOwner: TCarbonMemo; // Carbon memo control owning strings protected diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pp b/lcl/interfaces/cocoa/cocoawsstdctrls.pp index a99a0e5418..48ab624f3c 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pp +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pp @@ -27,7 +27,7 @@ uses MacOSAll, CocoaAll, Classes, sysutils, // LCL Controls, StdCtrls, Graphics, LCLType, LMessages, LCLProc, LCLMessageGlue, - LazUtf8Classes, + LazUtf8Classes, textstrings, // Widgetset WSStdCtrls, WSLCLClasses, WSControls, WSProc, // LCL Cocoa @@ -134,7 +134,7 @@ type { TCocoaMemoStrings } - TCocoaMemoStrings = class(TStrings) + TCocoaMemoStrings = class(TCustomMemoStrings) private FTextView: NSTextView; public diff --git a/lcl/interfaces/lcl.lpk b/lcl/interfaces/lcl.lpk index c40bb5aca9..2798120afe 100644 --- a/lcl/interfaces/lcl.lpk +++ b/lcl/interfaces/lcl.lpk @@ -113,6 +113,11 @@ end;"/> + + + + + diff --git a/lcl/lclbase.lpk b/lcl/lclbase.lpk index 0244d09074..0bbc3508c3 100644 --- a/lcl/lclbase.lpk +++ b/lcl/lclbase.lpk @@ -13,6 +13,11 @@ + + + + + diff --git a/lcl/textstrings.pas b/lcl/textstrings.pas index 97a1417776..1e87599a81 100644 --- a/lcl/textstrings.pas +++ b/lcl/textstrings.pas @@ -16,6 +16,10 @@ TTextStrings is a TStrings descendent that is optimized for handling the complete text as whole (instead of as line by line as in TStringList). + + TCustomMemoStrings is a TStrings descendent which works around the behavior + of TMemo.Lines, which contains the text with wordwrap line endings, in order + to store the text in the LFM without those wordwrap line endings. See bug 30659 } unit TextStrings; @@ -37,7 +41,14 @@ type end; PTextLineRange = ^TTextLineRange; - TTextStrings = class(TStrings) + TCustomMemoStrings = class(TStrings) + protected + procedure DoReadData(Reader: TReader); virtual; + procedure DoWriteData(Writer: TWriter); virtual; + procedure DefineProperties(Filer: TFiler); override; + end; + + TTextStrings = class(TCustomMemoStrings) private FOnChange: TNotifyEvent; FOnChanging: TNotifyEvent; @@ -90,6 +101,48 @@ type implementation +{ TCustomMemoStrings } + +procedure TCustomMemoStrings.DoReadData(Reader: TReader); +begin + Reader.ReadListBegin; + BeginUpdate; + try + Clear; + while not Reader.EndOfList do + Add(Reader.ReadString); + finally + EndUpdate; + end; + Reader.ReadListEnd; +end; + +procedure TCustomMemoStrings.DoWriteData(Writer: TWriter); +var + i: Integer; + lStringsNoWordWrap: TStringList; +begin + lStringsNoWordWrap := TStringList.Create; + try + lStringsNoWordWrap.Text := Text; + + Writer.WriteListBegin; + for i := 0 to lStringsNoWordWrap.Count - 1 do + Writer.WriteString(lStringsNoWordWrap.Strings[i]); + Writer.WriteListEnd; + finally + lStringsNoWordWrap.Free; + end; +end; + +procedure TCustomMemoStrings.DefineProperties(Filer: TFiler); +var + HasData: Boolean; +begin + HasData := Count > 0; + Filer.DefineProperty('Strings', @DoReadData, @DoWriteData, HasData); +end; + { TTextStrings } function TTextStrings.GetTextStr: string;