Ignore:
Timestamp:
Jul 12, 2012, 8:21:21 AM (12 years ago)
Author:
chronos
Message:
  • Added: Clipboard manipulation support in source code form.
  • Modified: Moved code which belongs to UFormSourceCode from UFormMain.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSourceCode.pas

    r46 r47  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Menus;
     9  Menus, ActnList, strutils;
    1010
    1111type
     
    1414
    1515  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;
    1625    MemoSource: TMemo;
     26    MenuItem1: TMenuItem;
     27    MenuItem2: TMenuItem;
    1728    MenuItem21: TMenuItem;
    1829    MenuItem23: TMenuItem;
    1930    MenuItem26: TMenuItem;
    2031    MenuItem29: TMenuItem;
     32    MenuItem3: TMenuItem;
    2133    MenuItem36: TMenuItem;
     34    MenuItem4: TMenuItem;
     35    MenuItem5: TMenuItem;
     36    MenuItem6: TMenuItem;
    2237    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);
    2354  private
    24     { private declarations }
    2555  public
    26     { public declarations }
     56    procedure UpdateInterface;
    2757  end;
    2858
     
    3060  FormSourceCode: TFormSourceCode;
    3161
     62
    3263implementation
     64
     65uses
     66  UFormMain;
     67
     68resourcestring
     69  SNumberGeneration = 'Number generation';
     70  SEnterNumber = 'Enter number';
     71
    3372
    3473{$R *.lfm}
    3574
     75{ TFormSourceCode }
     76
     77procedure TFormSourceCode.AGenerateNumberExecute(Sender: TObject);
     78var
     79  NumberText: string;
     80  Number: Integer;
     81  I: Integer;
     82begin
     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;
     90end;
     91
     92procedure TFormSourceCode.APasteFromClipboardExecute(Sender: TObject);
     93begin
     94  MemoSource.PasteFromClipboard;
     95end;
     96
     97procedure TFormSourceCode.ASelectAllExecute(Sender: TObject);
     98begin
     99  MemoSource.SelectAll;
     100end;
     101
     102procedure TFormSourceCode.AFormatSourceExecute(Sender: TObject);
     103var
     104  Source: string;
     105  NewSource: string;
     106  Indent: Integer;
     107  I: Integer;
     108const
     109  IndentText = '  ';
     110begin
     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;
     128end;
     129
     130procedure TFormSourceCode.ACopyToClipboardExecute(Sender: TObject);
     131begin
     132  MemoSource.CopyToClipboard;
     133end;
     134
     135procedure TFormSourceCode.ACutToClipboardExecute(Sender: TObject);
     136begin
     137  MemoSource.CutToClipboard;
     138end;
     139
     140procedure TFormSourceCode.AClearExecute(Sender: TObject);
     141begin
     142  MemoSource.Clear;
     143end;
     144
     145procedure TFormSourceCode.AShrinkSourceExecute(Sender: TObject);
     146var
     147  Source: string;
     148  Pos: Integer;
     149  I: Integer;
     150begin
     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;
     161end;
     162
     163procedure TFormSourceCode.UpdateInterface;
     164begin
     165
     166end;
     167
     168procedure TFormSourceCode.MemoSourceChange(Sender: TObject);
     169begin
     170  MainForm.Modified := True;
     171  MainForm.CurrentTarget.Compiled := False;
     172  MainForm.UpdateInterface;
     173end;
     174
     175procedure TFormSourceCode.MemoSourceKeyDown(Sender: TObject; var Key: Word;
     176  Shift: TShiftState);
     177begin
     178end;
     179
     180procedure TFormSourceCode.MemoSourceKeyPress(Sender: TObject; var Key: char);
     181begin
     182end;
     183
     184procedure TFormSourceCode.MemoSourceKeyUp(Sender: TObject; var Key: Word;
     185  Shift: TShiftState);
     186begin
     187  MainForm.UpdateStatusBar;
     188end;
     189
     190procedure TFormSourceCode.MemoSourceMouseDown(Sender: TObject; Button: TMouseButton;
     191  Shift: TShiftState; X, Y: Integer);
     192begin
     193  MainForm.UpdateStatusBar;
     194end;
     195
     196
    36197end.
    37198
Note: See TracChangeset for help on using the changeset viewer.