Changeset 143 for trunk/Forms/UFormSourceCode.pas
- Timestamp:
- Mar 8, 2022, 10:55:43 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormSourceCode.pas
r131 r143 15 15 16 16 TFormSourceCode = class(TForm) 17 AGenerateText: TAction; 17 18 ACutToClipboard: TAction; 18 19 ASelectAll: TAction; … … 35 36 MenuItem5: TMenuItem; 36 37 MenuItem6: TMenuItem; 38 MenuItem7: TMenuItem; 39 Separator1: TMenuItem; 37 40 PopupMenuSource: TPopupMenu; 38 41 SynEditSource: TSynEdit; … … 43 46 procedure AFormatSourceExecute(Sender: TObject); 44 47 procedure AGenerateNumberExecute(Sender: TObject); 48 procedure AGenerateTextExecute(Sender: TObject); 45 49 procedure APasteFromClipboardExecute(Sender: TObject); 46 50 procedure ASelectAllExecute(Sender: TObject); … … 72 76 73 77 uses 74 UCore, UFormMain ;78 UCore, UFormMain, UBFCodeTools; 75 79 76 80 resourcestring 77 81 SNumberGeneration = 'Number generation'; 78 82 SEnterNumber = 'Enter number'; 79 83 STextGeneration = 'Text generation'; 84 SEnterText = 'Enter text'; 80 85 81 86 { TFormSourceCode } … … 83 88 procedure TFormSourceCode.AGenerateNumberExecute(Sender: TObject); 84 89 var 90 Number: Integer; 85 91 NumberText: string; 86 Number: Integer;87 I: Integer;88 92 begin 89 93 NumberText := InputBox(SNumberGeneration, SEnterNumber, '1'); 90 94 if TryStrToInt(NumberText, Number) then begin 91 NumberText := ''; 92 for I := 0 to Number - 1 do 93 NumberText := NumberText + '+'; 94 SynEditSource.SelText := NumberText; 95 SynEditSource.SelText := GenerateNumber(Number); 95 96 end; 96 97 end; 97 98 99 procedure TFormSourceCode.AGenerateTextExecute(Sender: TObject); 100 var 101 Text: string; 102 begin 103 Text := InputBox(STextGeneration, SEnterText, ''); 104 SynEditSource.SelText := GenerateText(Text); 105 end; 106 98 107 procedure TFormSourceCode.APasteFromClipboardExecute(Sender: TObject); 99 108 begin … … 107 116 108 117 procedure TFormSourceCode.AFormatSourceExecute(Sender: TObject); 109 var 110 Source: string; 111 NewSource: string; 112 Indent: Integer; 113 I: Integer; 114 const 115 IndentText = ' '; 116 begin 117 Source := SynEditSource.Text; 118 NewSource := ''; 119 Indent := 0; 120 for I := 1 to Length(Source) do begin 121 if Source[I] = '[' then begin 122 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding ; 123 Inc(Indent); 124 NewSource := NewSource + DupeString(IndentText, Indent); 125 end 126 else if Source[I] = ']' then begin 127 Dec(Indent); 128 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding + DupeString(IndentText, Indent); 129 end 130 else if Ord(Source[I]) > $20 then 131 NewSource := NewSource + Source[I]; 132 end; 133 SynEditSource.Text := NewSource; 118 begin 119 SynEditSource.Text := FormatCode(SynEditSource.Text); 134 120 MemoSourceChange(nil); 135 121 end; … … 151 137 152 138 procedure TFormSourceCode.AShrinkSourceExecute(Sender: TObject); 153 var 154 Source: string; 155 Pos: Integer; 156 I: Integer; 157 begin 158 Source := SynEditSource.Text; 159 Pos := 1; 160 for I := 1 to Length(Source) do begin 161 if Source[I] > ' ' then begin 162 Source[Pos] := Source[I]; 163 Inc(Pos); 164 end; 165 end; 166 SetLength(Source, Pos - 1); 167 SynEditSource.Text := Source; 139 begin 140 SynEditSource.Text := ShrinkCode(SynEditSource.Text); 168 141 MemoSourceChange(nil); 169 142 end;
Note:
See TracChangeset
for help on using the changeset viewer.