Browse Source

Initial Release on http://luaforge.net

Jean-Francois Goulet 20 years ago
parent
commit
d1d562ae9c
2 changed files with 339 additions and 0 deletions
  1. 147 0
      LuaEdit/SearchPath.dfm
  2. 192 0
      LuaEdit/SearchPath.pas

+ 147 - 0
LuaEdit/SearchPath.dfm

@@ -0,0 +1,147 @@
+object frmSearchPath: TfrmSearchPath
+  Left = 442
+  Top = 344
+  Width = 370
+  Height = 300
+  Caption = 'Search Path'
+  Color = clBtnFace
+  Constraints.MinHeight = 300
+  Constraints.MinWidth = 370
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'MS Sans Serif'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poOwnerFormCenter
+  OnShow = FormShow
+  DesignSize = (
+    362
+    273)
+  PixelsPerInch = 96
+  TextHeight = 13
+  object GroupBox1: TGroupBox
+    Left = 8
+    Top = 8
+    Width = 350
+    Height = 224
+    Anchors = [akLeft, akTop, akRight, akBottom]
+    Constraints.MinWidth = 350
+    TabOrder = 0
+    DesignSize = (
+      350
+      224)
+    object lblMessage: TLabel
+      Left = 11
+      Top = 17
+      Width = 331
+      Height = 28
+      Anchors = [akLeft, akTop, akRight]
+      AutoSize = False
+      WordWrap = True
+    end
+    object Panel1: TPanel
+      Left = 2
+      Top = 191
+      Width = 346
+      Height = 31
+      Align = alBottom
+      BevelOuter = bvNone
+      TabOrder = 2
+      DesignSize = (
+        346
+        31)
+      object btnAdd: TButton
+        Left = 92
+        Top = 1
+        Width = 75
+        Height = 25
+        Anchors = [akRight, akBottom]
+        Caption = '&Add'
+        TabOrder = 1
+        OnClick = btnAddClick
+      end
+      object btnDelete: TButton
+        Left = 172
+        Top = 1
+        Width = 75
+        Height = 25
+        Anchors = [akRight, akBottom]
+        Caption = '&Delete'
+        TabOrder = 2
+        OnClick = btnDeleteClick
+      end
+      object btnDeleteInvalid: TButton
+        Left = 252
+        Top = 1
+        Width = 88
+        Height = 25
+        Anchors = [akRight, akBottom]
+        Caption = 'Delete &Invalid'
+        TabOrder = 3
+        OnClick = btnDeleteInvalidClick
+      end
+      object btnReplace: TButton
+        Left = 12
+        Top = 1
+        Width = 75
+        Height = 25
+        Anchors = [akRight, akBottom]
+        Caption = '&Replace'
+        TabOrder = 0
+        OnClick = btnReplaceClick
+      end
+    end
+    object txtSearchPath: TJvDotNetDirectoryEdit
+      Left = 11
+      Top = 164
+      Width = 331
+      Height = 21
+      AcceptFiles = False
+      OnButtonClick = txtSearchPathButtonClick
+      DialogKind = dkWin32
+      AutoCompleteFileOptions = []
+      DialogOptions = [sdAllowCreate, sdPerformCreate]
+      Anchors = [akLeft, akRight, akBottom]
+      TabOrder = 1
+    end
+    object lstSearchPath: TJvDotNetListBox
+      Left = 11
+      Top = 49
+      Width = 331
+      Height = 112
+      Anchors = [akLeft, akTop, akRight, akBottom]
+      ItemHeight = 13
+      Background.FillMode = bfmTile
+      Background.Visible = False
+      Sorted = True
+      Style = lbOwnerDrawFixed
+      TabOrder = 0
+      OnClick = lstSearchPathClick
+      OnDrawItem = lstSearchPathDrawItem
+    end
+  end
+  object btnCancel: TButton
+    Left = 280
+    Top = 240
+    Width = 75
+    Height = 25
+    Anchors = [akRight, akBottom]
+    Cancel = True
+    Caption = '&Cancel'
+    ModalResult = 2
+    TabOrder = 2
+  end
+  object btnOk: TButton
+    Left = 200
+    Top = 240
+    Width = 75
+    Height = 25
+    Anchors = [akRight, akBottom]
+    Caption = '&OK'
+    Default = True
+    ModalResult = 1
+    TabOrder = 1
+    OnClick = btnOkClick
+  end
+end

+ 192 - 0
LuaEdit/SearchPath.pas

@@ -0,0 +1,192 @@
+unit SearchPath;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, StdCtrls, ExtCtrls, JvComponent, JvBaseDlg, JvBrowseFolder,
+  JvExStdCtrls, JvListBox, JvDotNetControls, Mask, JvExMask, JvToolEdit;
+
+type
+  TfrmSearchPath = class(TForm)
+    GroupBox1: TGroupBox;
+    Panel1: TPanel;
+    btnAdd: TButton;
+    btnDelete: TButton;
+    btnDeleteInvalid: TButton;
+    btnReplace: TButton;
+    txtSearchPath: TJvDotNetDirectoryEdit;
+    lstSearchPath: TJvDotNetListBox;
+    lblMessage: TLabel;
+    btnCancel: TButton;
+    btnOk: TButton;
+    procedure FormShow(Sender: TObject);
+    procedure lstSearchPathDrawItem(Control: TWinControl; Index: Integer;
+      Rect: TRect; State: TOwnerDrawState);
+    procedure txtSearchPathButtonClick(Sender: TObject);
+    procedure btnAddClick(Sender: TObject);
+    procedure btnReplaceClick(Sender: TObject);
+    procedure lstSearchPathClick(Sender: TObject);
+    procedure btnDeleteInvalidClick(Sender: TObject);
+    procedure btnOkClick(Sender: TObject);
+    procedure btnDeleteClick(Sender: TObject);
+  private
+    { Private declarations }
+  public
+    { Public declarations }
+    procedure InitSearchPathForm(SearchPathString, SearchPathFormTitle, SearchPathMessage: String);
+    function GetSearchPathString(): String;
+  end;
+
+var
+  frmSearchPath: TfrmSearchPath;
+
+implementation
+
+{$R *.dfm}
+
+procedure TfrmSearchPath.InitSearchPathForm(SearchPathString, SearchPathFormTitle, SearchPathMessage: String);
+begin
+  // Initialize a few things before filling
+  lstSearchPath.Clear;
+  lstSearchPath.Items.CommaText := SearchPathString;
+  Self.Caption := SearchPathFormTitle;
+  lblMessage.Caption := SearchPathMessage;
+end;
+
+function TfrmSearchPath.GetSearchPathString(): String;
+begin
+  Result := lstSearchPath.Items.CommaText;
+end;
+
+procedure TfrmSearchPath.FormShow(Sender: TObject);
+begin
+  if lstSearchPath.Count > 0 then
+  begin
+    lstSearchPath.Selected[0] := True;
+    txtSearchPath.Text := lstSearchPath.Items[0];
+  end;
+end;
+
+procedure TfrmSearchPath.lstSearchPathDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
+begin
+  // if current item is selected, simply use white
+  if odSelected in State then
+  begin
+    lstSearchPath.Canvas.Font.Color := clWhite;
+  end
+  else
+  begin
+    // Determine color of font to use according existance of the directory
+    if DirectoryExists(lstSearchPath.Items[Index]) then
+      lstSearchPath.Canvas.Font.Color := clBlack
+    else
+      lstSearchPath.Canvas.Font.Color := lstSearchPath.DisabledTextColor;
+  end;
+
+  // Draw the text
+  lstSearchPath.Canvas.TextRect(Rect, Rect.Left, Rect.Top, '  '+lstSearchPath.Items[Index]);
+end;
+
+procedure TfrmSearchPath.txtSearchPathButtonClick(Sender: TObject);
+begin
+  if DirectoryExists(txtSearchPath.Text) then
+    txtSearchPath.InitialDir := txtSearchPath.Text
+  else
+    txtSearchPath.InitialDir := ExtractFilePath(Application.ExeName);
+end;
+
+procedure TfrmSearchPath.btnAddClick(Sender: TObject);
+var
+  ItemInList: Boolean;
+  FormatedPath: String;
+  x: Integer;
+begin
+  if txtSearchPath.Text <> '' then
+  begin
+    // Initialize stuff
+    ItemInList := False;
+
+    // Format search path to add (add '\' character if none)
+    if Copy(txtSearchPath.Text, Length(txtSearchPath.Text), 1) <> '\' then
+      FormatedPath := txtSearchPath.Text + '\'
+    else
+      FormatedPath := txtSearchPath.Text;
+
+    // Search for new path in list
+    for x := 0 to lstSearchPath.Count - 1 do
+    begin
+      if lstSearchPath.Items[x] = FormatedPath then
+        ItemInList := True;
+    end;
+
+    // Add path to list only if not already in the list
+    if not ItemInList then
+      lstSearchPath.Items.Add(FormatedPath);
+
+    btnReplace.Enabled := (lstSearchPath.ItemIndex <> -1);
+    btnDelete.Enabled := (lstSearchPath.ItemIndex <> -1);
+    btnDeleteInvalid.Enabled := (lstSearchPath.Count > 0);
+  end;
+end;
+
+procedure TfrmSearchPath.btnReplaceClick(Sender: TObject);
+begin
+  // Replace selected item by new path if any item is selected
+  if lstSearchPath.ItemIndex <> -1 then
+    lstSearchPath.Items[lstSearchPath.ItemIndex] := txtSearchPath.Text;
+end;
+
+procedure TfrmSearchPath.lstSearchPathClick(Sender: TObject);
+begin
+  btnReplace.Enabled := (lstSearchPath.ItemIndex <> -1);
+  btnDelete.Enabled := (lstSearchPath.ItemIndex <> -1);
+
+  if lstSearchPath.ItemIndex <> -1 then
+    txtSearchPath.Text := lstSearchPath.Items[lstSearchPath.ItemIndex]
+  else
+    txtSearchPath.Text := '';
+end;
+
+procedure TfrmSearchPath.btnDeleteClick(Sender: TObject);
+var
+  DeletedIndex: Integer;
+begin
+  DeletedIndex := lstSearchPath.ItemIndex;
+  
+  // Delete currently selected item if any
+  if lstSearchPath.ItemIndex <> -1 then
+    lstSearchPath.Items.Delete(lstSearchPath.ItemIndex);
+
+  // Select next or previous in the list if any
+  if ((lstSearchPath.Count > 0) and (DeletedIndex <> -1)) then
+  begin
+    if lstSearchPath.Count >= DeletedIndex + 1 then
+      lstSearchPath.Selected[DeletedIndex] := True
+    else
+      lstSearchPath.Selected[DeletedIndex - 1] := True;
+  end;
+
+  btnReplace.Enabled := (lstSearchPath.ItemIndex <> -1);
+  btnDelete.Enabled := (lstSearchPath.ItemIndex <> -1);
+  btnDeleteInvalid.Enabled := (lstSearchPath.Count > 0);
+end;
+
+procedure TfrmSearchPath.btnDeleteInvalidClick(Sender: TObject);
+var
+  x: Integer;
+begin
+  for x := lstSearchPath.Items.Count - 1 downto 0 do
+  begin
+    if not DirectoryExists(lstSearchPath.Items[x]) then
+      lstSearchPath.Items.Delete(x);
+  end;
+end;
+
+procedure TfrmSearchPath.btnOkClick(Sender: TObject);
+begin
+  btnAdd.Click;
+  ModalResult := mrOk;
+end;
+
+end.