Changeset 47 for trunk/Forms/UFormSourceCode.pas
- Timestamp:
- Jul 12, 2012, 8:21:21 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormSourceCode.pas
r46 r47 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 Menus ;9 Menus, ActnList, strutils; 10 10 11 11 type … … 14 14 15 15 TFormSourceCode = class(TForm) 16 ACutToClipboard: TAction; 17 ASelectAll: TAction; 18 APasteFromClipboard: TAction; 19 ACopyToClipboard: TAction; 20 AClear: TAction; 21 AFormatSource: TAction; 22 AShrinkSource: TAction; 23 AGenerateNumber: TAction; 24 ActionList1: TActionList; 16 25 MemoSource: TMemo; 26 MenuItem1: TMenuItem; 27 MenuItem2: TMenuItem; 17 28 MenuItem21: TMenuItem; 18 29 MenuItem23: TMenuItem; 19 30 MenuItem26: TMenuItem; 20 31 MenuItem29: TMenuItem; 32 MenuItem3: TMenuItem; 21 33 MenuItem36: TMenuItem; 34 MenuItem4: TMenuItem; 35 MenuItem5: TMenuItem; 36 MenuItem6: TMenuItem; 22 37 PopupMenuSource: TPopupMenu; 38 procedure AClearExecute(Sender: TObject); 39 procedure ACopyToClipboardExecute(Sender: TObject); 40 procedure ACutToClipboardExecute(Sender: TObject); 41 procedure AFormatSourceExecute(Sender: TObject); 42 procedure AGenerateNumberExecute(Sender: TObject); 43 procedure APasteFromClipboardExecute(Sender: TObject); 44 procedure ASelectAllExecute(Sender: TObject); 45 procedure AShrinkSourceExecute(Sender: TObject); 46 procedure MemoSourceChange(Sender: TObject); 47 procedure MemoSourceKeyDown(Sender: TObject; var Key: Word; 48 Shift: TShiftState); 49 procedure MemoSourceKeyPress(Sender: TObject; var Key: char); 50 procedure MemoSourceKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState 51 ); 52 procedure MemoSourceMouseDown(Sender: TObject; Button: TMouseButton; 53 Shift: TShiftState; X, Y: Integer); 23 54 private 24 { private declarations }25 55 public 26 { public declarations }56 procedure UpdateInterface; 27 57 end; 28 58 … … 30 60 FormSourceCode: TFormSourceCode; 31 61 62 32 63 implementation 64 65 uses 66 UFormMain; 67 68 resourcestring 69 SNumberGeneration = 'Number generation'; 70 SEnterNumber = 'Enter number'; 71 33 72 34 73 {$R *.lfm} 35 74 75 { TFormSourceCode } 76 77 procedure TFormSourceCode.AGenerateNumberExecute(Sender: TObject); 78 var 79 NumberText: string; 80 Number: Integer; 81 I: Integer; 82 begin 83 NumberText := InputBox(SNumberGeneration, SEnterNumber, '1'); 84 if TryStrToInt(NumberText, Number) then begin 85 NumberText := ''; 86 for I := 0 to Number - 1 do 87 NumberText := NumberText + '+'; 88 MemoSource.SelText := NumberText; 89 end; 90 end; 91 92 procedure TFormSourceCode.APasteFromClipboardExecute(Sender: TObject); 93 begin 94 MemoSource.PasteFromClipboard; 95 end; 96 97 procedure TFormSourceCode.ASelectAllExecute(Sender: TObject); 98 begin 99 MemoSource.SelectAll; 100 end; 101 102 procedure TFormSourceCode.AFormatSourceExecute(Sender: TObject); 103 var 104 Source: string; 105 NewSource: string; 106 Indent: Integer; 107 I: Integer; 108 const 109 IndentText = ' '; 110 begin 111 Source := MemoSource.Text; 112 NewSource := ''; 113 Indent := 0; 114 for I := 1 to Length(Source) do begin 115 if Source[I] = '[' then begin 116 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding ; 117 Inc(Indent); 118 NewSource := NewSource + DupeString(IndentText, Indent); 119 end 120 else if Source[I] = ']' then begin 121 Dec(Indent); 122 NewSource := NewSource + LineEnding + DupeString(IndentText, Indent) + Source[I] + LineEnding + DupeString(IndentText, Indent); 123 end 124 else if Ord(Source[I]) > $20 then 125 NewSource := NewSource + Source[I]; 126 end; 127 MemoSource.Text := NewSource; 128 end; 129 130 procedure TFormSourceCode.ACopyToClipboardExecute(Sender: TObject); 131 begin 132 MemoSource.CopyToClipboard; 133 end; 134 135 procedure TFormSourceCode.ACutToClipboardExecute(Sender: TObject); 136 begin 137 MemoSource.CutToClipboard; 138 end; 139 140 procedure TFormSourceCode.AClearExecute(Sender: TObject); 141 begin 142 MemoSource.Clear; 143 end; 144 145 procedure TFormSourceCode.AShrinkSourceExecute(Sender: TObject); 146 var 147 Source: string; 148 Pos: Integer; 149 I: Integer; 150 begin 151 Source := MemoSource.Text; 152 Pos := 1; 153 for I := 1 to Length(Source) do begin 154 if Source[I] > ' ' then begin 155 Source[Pos] := Source[I]; 156 Inc(Pos); 157 end; 158 end; 159 SetLength(Source, Pos - 1); 160 MemoSource.Text := Source; 161 end; 162 163 procedure TFormSourceCode.UpdateInterface; 164 begin 165 166 end; 167 168 procedure TFormSourceCode.MemoSourceChange(Sender: TObject); 169 begin 170 MainForm.Modified := True; 171 MainForm.CurrentTarget.Compiled := False; 172 MainForm.UpdateInterface; 173 end; 174 175 procedure TFormSourceCode.MemoSourceKeyDown(Sender: TObject; var Key: Word; 176 Shift: TShiftState); 177 begin 178 end; 179 180 procedure TFormSourceCode.MemoSourceKeyPress(Sender: TObject; var Key: char); 181 begin 182 end; 183 184 procedure TFormSourceCode.MemoSourceKeyUp(Sender: TObject; var Key: Word; 185 Shift: TShiftState); 186 begin 187 MainForm.UpdateStatusBar; 188 end; 189 190 procedure TFormSourceCode.MemoSourceMouseDown(Sender: TObject; Button: TMouseButton; 191 Shift: TShiftState; X, Y: Integer); 192 begin 193 MainForm.UpdateStatusBar; 194 end; 195 196 36 197 end. 37 198
Note:
See TracChangeset
for help on using the changeset viewer.