Show line breaks other than Windows style as normal line breaks in text editor. See http://www.heidisql.com/forum.php?t=18769

This commit is contained in:
Ansgar Becker
2015-06-21 14:05:21 +00:00
parent 5b990def8f
commit ba63e1477e
3 changed files with 141 additions and 117 deletions

View File

@@ -3,7 +3,7 @@ unit extra_controls;
interface
uses
Classes, SysUtils, Forms, Windows, Messages, System.Types;
Classes, SysUtils, Forms, Windows, Messages, System.Types, StdCtrls, Clipbrd;
type
// Form with a sizegrip in the lower right corner, without the need for a statusbar
@@ -18,6 +18,12 @@ type
procedure Paint; override;
procedure Resize; override;
end;
// Memo replacement which accepts any line break format
TLineNormalizingMemo = class(TMemo)
private
procedure WMSetText(var msg: TWMSettext); message WM_SETTEXT;
procedure WMPaste(var msg: TWMPaste); message WM_PASTE;
end;
implementation
@@ -58,4 +64,28 @@ begin
end;
{ TLineNormalizingMemo }
procedure TLineNormalizingMemo.WMSetText(var msg: TWMSettext);
var
s: string;
begin
s := msg.Text;
s := AdjustLineBreaks(s);
msg.Text := PChar(s);
inherited;
end;
procedure TLineNormalizingMemo.WMPaste(var msg: TWMPaste);
var
s: string;
begin
if Clipboard.HasFormat(cf_Text) then begin
s := Clipboard.AsText;
s := AdjustLineBreaks(s);
SelText := s;
end;
end;
end.

View File

@@ -18,112 +18,112 @@ object frmTextEditor: TfrmTextEditor
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
DesignSize = (
332
104)
PixelsPerInch = 96
TextHeight = 13
object lblTextLength: TLabel
Left = 213
Top = 87
Width = 65
Height = 13
Anchors = [akLeft, akBottom]
BiDiMode = bdLeftToRight
Caption = 'lblTextLength'
ParentBiDiMode = False
end
object memoText: TMemo
Left = 0
Top = 0
Width = 332
Height = 81
Align = alTop
Anchors = [akLeft, akTop, akRight, akBottom]
Lines.Strings = (
'memoText')
ScrollBars = ssBoth
TabOrder = 0
WantTabs = True
OnChange = memoTextChange
OnKeyDown = memoTextKeyDown
end
object tlbStandard: TToolBar
object Panel1: TPanel
AlignWithMargins = True
Left = 0
Top = 82
Width = 207
Width = 322
Height = 22
Align = alNone
Anchors = [akLeft, akBottom]
AutoSize = True
Caption = 'tlbStandard'
Images = MainForm.ImageListMain
ParentShowHint = False
ShowHint = True
TabOrder = 1
Wrapable = False
object btnWrap: TToolButton
Margins.Left = 0
Margins.Top = 0
Margins.Right = 10
Margins.Bottom = 0
Align = alBottom
BevelOuter = bvNone
Caption = 'Panel1'
ShowCaption = False
TabOrder = 0
ExplicitWidth = 332
object lblTextLength: TLabel
AlignWithMargins = True
Left = 210
Top = 3
Width = 65
Height = 13
Align = alLeft
BiDiMode = bdLeftToRight
Caption = 'lblTextLength'
ParentBiDiMode = False
Layout = tlCenter
end
object tlbStandard: TToolBar
Left = 0
Top = 0
Hint = 'Wrap long lines'
Caption = 'Wrap long lines'
ImageIndex = 62
OnClick = btnWrapClick
end
object btnLinebreaks: TToolButton
Left = 23
Top = 0
Caption = 'Linebreaks'
DropdownMenu = popupLinebreaks
ImageIndex = 123
Style = tbsDropDown
end
object btnLoadText: TToolButton
Left = 61
Top = 0
Hint = 'Load textfile'
Caption = 'Load textfile'
ImageIndex = 52
OnClick = btnLoadTextClick
end
object btnCancel: TToolButton
Left = 84
Top = 0
Hint = 'Cancel'
Caption = 'Cancel'
ImageIndex = 26
OnClick = btnCancelClick
end
object btnApply: TToolButton
Left = 107
Top = 0
Hint = 'Apply changes'
Caption = 'Apply changes'
ImageIndex = 55
OnClick = btnApplyClick
end
object btnSeparator1: TToolButton
Left = 130
Top = 0
Width = 8
Caption = 'btnSeparator1'
ImageIndex = 60
Style = tbsSeparator
end
object btnSearchFind: TToolButton
Left = 138
Top = 0
Action = actSearchFind
end
object btnSearchFindNext: TToolButton
Left = 161
Top = 0
Action = actSearchFindNext
end
object btnSearchReplace: TToolButton
Left = 184
Top = 0
Action = actSearchReplace
Width = 207
Height = 22
Align = alLeft
AutoSize = True
Caption = 'tlbStandard'
Images = MainForm.ImageListMain
ParentShowHint = False
ShowHint = True
TabOrder = 0
Wrapable = False
object btnWrap: TToolButton
Left = 0
Top = 0
Hint = 'Wrap long lines'
Caption = 'Wrap long lines'
ImageIndex = 62
OnClick = btnWrapClick
end
object btnLinebreaks: TToolButton
Left = 23
Top = 0
Caption = 'Linebreaks'
DropdownMenu = popupLinebreaks
ImageIndex = 123
Style = tbsDropDown
end
object btnLoadText: TToolButton
Left = 61
Top = 0
Hint = 'Load textfile'
Caption = 'Load textfile'
ImageIndex = 52
OnClick = btnLoadTextClick
end
object btnCancel: TToolButton
Left = 84
Top = 0
Hint = 'Cancel'
Caption = 'Cancel'
ImageIndex = 26
OnClick = btnCancelClick
end
object btnApply: TToolButton
Left = 107
Top = 0
Hint = 'Apply changes'
Caption = 'Apply changes'
ImageIndex = 55
OnClick = btnApplyClick
end
object btnSeparator1: TToolButton
Left = 130
Top = 0
Width = 8
Caption = 'btnSeparator1'
ImageIndex = 60
Style = tbsSeparator
end
object btnSearchFind: TToolButton
Left = 138
Top = 0
Action = actSearchFind
end
object btnSearchFindNext: TToolButton
Left = 161
Top = 0
Action = actSearchFindNext
end
object btnSearchReplace: TToolButton
Left = 184
Top = 0
Action = actSearchReplace
end
end
end
object popupLinebreaks: TPopupMenu

View File

@@ -5,13 +5,14 @@ interface
uses
Windows, Classes, Graphics, Forms, Controls, StdCtrls, VirtualTrees,
ComCtrls, ToolWin, Dialogs, SysUtils, Menus, ExtDlgs,
helpers, gnugettext, ActnList, StdActns, extra_controls, System.Actions;
helpers, gnugettext, ActnList, StdActns, extra_controls, System.Actions,
Vcl.ExtCtrls;
{$I const.inc}
type
TfrmTextEditor = class(TFormWithSizeGrip)
memoText: TMemo;
Panel1: TPanel;
tlbStandard: TToolBar;
btnWrap: TToolButton;
btnLoadText: TToolButton;
@@ -50,6 +51,7 @@ type
FStopping: Boolean;
DetectedLineBreaks,
SelectedLineBreaks: TLineBreaks;
memoText: TLineNormalizingMemo;
procedure SetModified(NewVal: Boolean);
public
function GetText: String;
@@ -86,7 +88,6 @@ end;
procedure TfrmTextEditor.SetText(text: String);
var
LB: String;
Detected: TMenuItem;
begin
DetectedLineBreaks := ScanLineBreaks(text);
@@ -102,21 +103,7 @@ begin
end;
if Assigned(Detected) then
SelectLineBreaks(Detected);
// Replace consistent linebreaks with CRLF so they're displayed properly
LB := '';
case DetectedLineBreaks of
lbsUnix: LB := LB_UNIX;
lbsMac: LB := LB_MAC;
lbsWide: LB := LB_WIDE;
end;
if LB <> '' then
text := StringReplace(text, LB, CRLF, [rfReplaceAll]);
// TODO: Find out why the Delphi IDE insists hinting that this
// property is ANSI when it is in fact a WideString.
memoText.Text := text;
memoText.SelectAll;
Modified := False;
end;
@@ -167,6 +154,13 @@ end;
procedure TfrmTextEditor.FormCreate(Sender: TObject);
begin
memoText := TLineNormalizingMemo.Create(Self);
memoText.Parent := Self;
memoText.Align := alClient;
memoText.ScrollBars := ssBoth;
memoText.WantTabs := True;
memoText.OnChange := memoTextChange;
memoText.OnKeyDown := memoTextKeyDown;
InheritFont(Font);
// Use same text properties as in query/find/replace actions
actSearchFind.Caption := MainForm.actQueryFind.Caption;