Ignore:
Timestamp:
Mar 8, 2022, 10:55:43 AM (3 years ago)
Author:
chronos
Message:
  • Added: Action to generate text as brainfuck code.
  • Modified: Used loop in number generation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSourceCode.pas

    r131 r143  
    1515
    1616  TFormSourceCode = class(TForm)
     17    AGenerateText: TAction;
    1718    ACutToClipboard: TAction;
    1819    ASelectAll: TAction;
     
    3536    MenuItem5: TMenuItem;
    3637    MenuItem6: TMenuItem;
     38    MenuItem7: TMenuItem;
     39    Separator1: TMenuItem;
    3740    PopupMenuSource: TPopupMenu;
    3841    SynEditSource: TSynEdit;
     
    4346    procedure AFormatSourceExecute(Sender: TObject);
    4447    procedure AGenerateNumberExecute(Sender: TObject);
     48    procedure AGenerateTextExecute(Sender: TObject);
    4549    procedure APasteFromClipboardExecute(Sender: TObject);
    4650    procedure ASelectAllExecute(Sender: TObject);
     
    7276
    7377uses
    74   UCore, UFormMain;
     78  UCore, UFormMain, UBFCodeTools;
    7579
    7680resourcestring
    7781  SNumberGeneration = 'Number generation';
    7882  SEnterNumber = 'Enter number';
    79 
     83  STextGeneration = 'Text generation';
     84  SEnterText = 'Enter text';
    8085
    8186{ TFormSourceCode }
     
    8388procedure TFormSourceCode.AGenerateNumberExecute(Sender: TObject);
    8489var
     90  Number: Integer;
    8591  NumberText: string;
    86   Number: Integer;
    87   I: Integer;
    8892begin
    8993  NumberText := InputBox(SNumberGeneration, SEnterNumber, '1');
    9094  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);
    9596  end;
    9697end;
    9798
     99procedure TFormSourceCode.AGenerateTextExecute(Sender: TObject);
     100var
     101  Text: string;
     102begin
     103  Text := InputBox(STextGeneration, SEnterText, '');
     104  SynEditSource.SelText := GenerateText(Text);
     105end;
     106
    98107procedure TFormSourceCode.APasteFromClipboardExecute(Sender: TObject);
    99108begin
     
    107116
    108117procedure 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;
     118begin
     119  SynEditSource.Text := FormatCode(SynEditSource.Text);
    134120  MemoSourceChange(nil);
    135121end;
     
    151137
    152138procedure 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;
     139begin
     140  SynEditSource.Text := ShrinkCode(SynEditSource.Text);
    168141  MemoSourceChange(nil);
    169142end;
Note: See TracChangeset for help on using the changeset viewer.