{*****************************************************************************
 *
 *  FMCats
 *
 *      Category editor
 *
 *  Copyright (c) 2002 Arthur Hoogervorst
 *
 *  Author:     Arthur Hoogervorst
 *  E-mail:     ahooger@istar.ca
 *  Homepage:   http://roundabout.sourceforge.net
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation;
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 *----------------------------------------------------------------------------
 *
 *  Revision history:
 *
 *     DATE     REV                 DESCRIPTION
 *  ----------- --- ----------------------------------------------------------
 *  2002        1.0    Initial Release of Category editor
 *****************************************************************************}

 unit FMCats;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GradForm, pmToDo, StdCtrls;

type
  TCatEditor = class(TdfsGradientForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure dfsGradientFormCreate(Sender: TObject);
    procedure dfsGradientFormDestroy(Sender: TObject);
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    Changed : Byte;
    procedure RefreshListBox;
  published
    { Published declarations }
  end;

var
  CatEditor : TCatEditor;

implementation
uses PXStuff;

{$R *.DFM}

procedure TCatEditor.RefreshListBox;
var t : TStringList;
begin
  t := TStringList.Create;
  t.Text := GetCategories(sToDoFolder);
  ListBox1.Items.Text := t.text;
  t.Free;
end;

procedure TCatEditor.Button1Click(Sender: TObject);
begin
  NewCategory(sToDoFolder);
  RefreshListBox;
  Changed := 1;
end;

procedure TCatEditor.Button2Click(Sender: TObject);
var s : string;
begin
  if ListBox1.ItemIndex <> -1 then
  begin
    s := ListBox1.Items.Strings[ListBox1.ItemIndex];
    if InputQuery(sAppTitle, GetMessageString(158), s) then
    begin
      if s <> '' then
      begin
        RenameFile(sToDoFolder
          + ListBox1.Items.Strings[ListBox1.ItemIndex] + '.ptd',
          sToDoFolder + s + '.ptd'); //RR
        RefreshListBox;
        Changed := 2;
      end;
    end;
  end;
end;


procedure TCatEditor.Button3Click(Sender: TObject);
begin
  if ListBox1.ItemIndex <> -1 then
  begin
    DeleteFile(sToDoFolder
      + ListBox1.Items.Strings[ListBox1.ItemIndex] + '.ptd');
    RefreshListBox;
    Changed := 3;
  end;
end;

procedure TCatEditor.dfsGradientFormCreate(Sender: TObject);
begin
  RefreshListBox;
  Changed := 0;
end;

procedure TCatEditor.dfsGradientFormDestroy(Sender: TObject);
begin
  CatEditor := nil;
end;

initialization
   PMRegistry.AddCustomClass(TCatEditor, 'TCatEditor');
end.
