unit FMToDo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  PXStuff, GradForm, ClipBrd,
  StdCtrls, ComCtrls, RichEdit2, ActnList, Menus;

type
  TFormToDo = class(TdfsGradientForm)
    RichEdit1: TRichEdit;
    ActionList1: TActionList;
    actEditCut: TAction;
    actEditCopy: TAction;
    actEditPaste: TAction;
    actEditSelectAll: TAction;
    PopupMenuToDo: TPopupMenu;
    Ausschneiden1: TMenuItem;
    Kopieren1: TMenuItem;
    Einfgen1: TMenuItem;
    N1: TMenuItem;
    Allesmarkieren1: TMenuItem;
    actEditUndo: TAction;
    Rckgngig1: TMenuItem;
    N2: TMenuItem;
    actFileExit: TAction;
    procedure FormCreate(Sender: TObject);
    procedure dfsGradientFormHide(Sender: TObject);
    procedure dfsGradientFormResize(Sender: TObject);
    procedure dfsGradientFormPaint(Sender: TObject);
    procedure actEditCutUpdate(Sender: TObject);
    procedure actEditCopyUpdate(Sender: TObject);
    procedure actEditPasteUpdate(Sender: TObject);
    procedure actEditCutExecute(Sender: TObject);
    procedure actEditCopyExecute(Sender: TObject);
    procedure actEditPasteExecute(Sender: TObject);
    procedure actEditSelectAllExecute(Sender: TObject);
    procedure actEditUndoUpdate(Sender: TObject);
    procedure actEditUndoExecute(Sender: TObject);
    procedure actFileExitExecute(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure SetEditRect;
  public
    { Public-Deklarationen }
  end;

var
  FormToDo: TFormToDo;

implementation

uses Main;

{$R *.DFM}

const GutterWid = 10;
var ToDoFileName: string;

procedure TFormToDo.FormCreate(Sender: TObject);
begin
  ToDoFileName := GetAppPath + 'ToDo.txt';
  if fileexists(ToDoFileName) then RichEdit1.Lines.LoadFromFile(ToDoFileName);
  with RichEdit1 do
  begin
    Font := MainForm.DefaultFont;
  end;
end;

procedure TFormToDo.dfsGradientFormHide(Sender: TObject);
begin
  RichEdit1.Lines.SaveToFile(ToDoFileName);
end;

procedure TFormToDo.SetEditRect;
var
  R: TRect;
begin
  with RichEdit1 do
  begin
    R := Rect(GutterWid, 0, ClientWidth - GutterWid, ClientHeight);
    SendMessage(Handle, EM_SETRECT, 0, Longint(@R));
  end;
end;


procedure TFormToDo.dfsGradientFormResize(Sender: TObject);
begin
  SetEditRect;
end;

procedure TFormToDo.dfsGradientFormPaint(Sender: TObject);
begin
  SetEditRect;
end;

procedure TFormToDo.actEditCutUpdate(Sender: TObject);
begin
  (Sender as TAction).Enabled := (RichEdit1.SelLength > 0) and
    (RichEdit1.Enabled);
end;

procedure TFormToDo.actEditCopyUpdate(Sender: TObject);
begin
  (Sender as TAction).Enabled := (RichEdit1.SelLength > 0)
end;

procedure TFormToDo.actEditPasteUpdate(Sender: TObject);
begin
  try
    (Sender as TAction).Enabled := (RichEdit1.Enabled) and
      (ClipBoard.HasFormat(CF_TEXT)) and (ClipBoard.AsText <> '');
  except end;
end;

procedure TFormToDo.actEditCutExecute(Sender: TObject);
begin
  if (RichEdit1.SelLength > 0) then RichEdit1.CutToClipboard;
end;

procedure TFormToDo.actEditCopyExecute(Sender: TObject);
begin
  if (RichEdit1.SelLength > 0) then RichEdit1.CopyToClipboard;
end;

procedure TFormToDo.actEditPasteExecute(Sender: TObject);
begin
  if actEditPaste.Enabled then RichEdit1.SelText := ClipBoard.AsText;
end;

procedure TFormToDo.actEditSelectAllExecute(Sender: TObject);
begin
  if RichEdit1.Focused then RichEdit1.SelectAll;
end;

procedure TFormToDo.actEditUndoUpdate(Sender: TObject);
begin
  (Sender as TAction).Enabled := RichEdit1.CanUndo;
end;

procedure TFormToDo.actEditUndoExecute(Sender: TObject);
begin
  if RichEdit1.CanUndo then RichEdit1.Undo;
end;

procedure TFormToDo.actFileExitExecute(Sender: TObject);
begin
  Hide;
end;

end.

