Ignore:
Timestamp:
Aug 2, 2018, 3:33:02 PM (6 years ago)
Author:
chronos
Message:
  • Added: Syntax highlighting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormSourceCode.pas

    r88 r97  
    66
    77uses
    8   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   Menus, ActnList, strutils;
     8  Classes, SysUtils, FileUtil, SynEdit, SynHighlighterIni, Forms, Controls,
     9  Graphics, Dialogs, StdCtrls, Menus, ActnList, strutils, SynEditTypes,
     10  SynEditHighlighter, SynHighlighterAny, SynHighlighterJava, UBFHighlighter;
    1011
    1112type
     
    2324    AGenerateNumber: TAction;
    2425    ActionList1: TActionList;
    25     MemoSource: TMemo;
    2626    MenuItem1: TMenuItem;
    2727    MenuItem2: TMenuItem;
     
    3636    MenuItem6: TMenuItem;
    3737    PopupMenuSource: TPopupMenu;
     38    SynEdit1: TSynEdit;
     39    SynJavaSyn1: TSynJavaSyn;
    3840    procedure AClearExecute(Sender: TObject);
    3941    procedure ACopyToClipboardExecute(Sender: TObject);
     
    4446    procedure ASelectAllExecute(Sender: TObject);
    4547    procedure AShrinkSourceExecute(Sender: TObject);
     48    procedure FormCreate(Sender: TObject);
    4649    procedure MemoSourceChange(Sender: TObject);
    4750    procedure MemoSourceKeyDown(Sender: TObject; var Key: Word;
     
    5356      Shift: TShiftState; X, Y: Integer);
    5457  private
     58    BFHighlighter: TSynBrainFuckHl;
    5559  public
    5660    procedure UpdateInterface;
     61    procedure UpdateTheme;
    5762  end;
    5863
     
    6267
    6368implementation
     69
     70{$R *.lfm}
    6471
    6572uses
     
    7077  SEnterNumber = 'Enter number';
    7178
    72 
    73 {$R *.lfm}
    7479
    7580{ TFormSourceCode }
     
    8691    for I := 0 to Number - 1 do
    8792      NumberText := NumberText + '+';
    88     MemoSource.SelText := NumberText;
     93    SynEdit1.SelText := NumberText;
    8994  end;
    9095end;
     
    9297procedure TFormSourceCode.APasteFromClipboardExecute(Sender: TObject);
    9398begin
    94   MemoSource.PasteFromClipboard;
     99  SynEdit1.PasteFromClipboard;
    95100end;
    96101
    97102procedure TFormSourceCode.ASelectAllExecute(Sender: TObject);
    98103begin
    99   MemoSource.SelectAll;
     104  SynEdit1.SelectAll;
    100105end;
    101106
     
    109114  IndentText = '  ';
    110115begin
    111   Source := MemoSource.Text;
     116  Source := SynEdit1.Text;
    112117  NewSource := '';
    113118  Indent := 0;
     
    125130      NewSource := NewSource + Source[I];
    126131  end;
    127   MemoSource.Text := NewSource;
     132  SynEdit1.Text := NewSource;
    128133end;
    129134
    130135procedure TFormSourceCode.ACopyToClipboardExecute(Sender: TObject);
    131136begin
    132   MemoSource.CopyToClipboard;
     137  SynEdit1.CopyToClipboard;
    133138end;
    134139
    135140procedure TFormSourceCode.ACutToClipboardExecute(Sender: TObject);
    136141begin
    137   MemoSource.CutToClipboard;
     142  SynEdit1.CutToClipboard;
    138143end;
    139144
    140145procedure TFormSourceCode.AClearExecute(Sender: TObject);
    141146begin
    142   MemoSource.Clear;
     147  SynEdit1.Clear;
    143148end;
    144149
     
    149154  I: Integer;
    150155begin
    151   Source := MemoSource.Text;
     156  Source := SynEdit1.Text;
    152157  Pos := 1;
    153158  for I := 1 to Length(Source) do begin
     
    158163  end;
    159164  SetLength(Source, Pos - 1);
    160   MemoSource.Text := Source;
     165  SynEdit1.Text := Source;
     166end;
     167
     168procedure TFormSourceCode.FormCreate(Sender: TObject);
     169begin
     170  BFHighlighter := TSynBrainFuckHl.Create(nil);
     171  SynEdit1.Highlighter := BFHighlighter;
    161172end;
    162173
     
    164175begin
    165176
     177end;
     178
     179procedure TFormSourceCode.UpdateTheme;
     180const
     181  clLightBlue = TColor($FF8080);
     182  clLightGreen = TColor($80FF80);
     183  clLightRed = TColor($8080FF);
     184begin
     185  if Core.ThemeManager.Theme.Name = 'Dark' then begin
     186    BFHighlighter.IoAttri.Foreground := clWhite;
     187    BFHighlighter.LoopAttri.Foreground := clLightRed;
     188    BFHighlighter.PointerAttri.Foreground := clLightBlue;
     189    BFHighlighter.MemoryAttri.Foreground := clLightGreen;
     190  end else begin
     191    BFHighlighter.IoAttri.Foreground := clBlack;
     192    BFHighlighter.LoopAttri.Foreground := clRed;
     193    BFHighlighter.PointerAttri.Foreground := clBlue;
     194    BFHighlighter.MemoryAttri.Foreground := clGreen;
     195  end;
    166196end;
    167197
Note: See TracChangeset for help on using the changeset viewer.