Bladeren bron

ADD: Create directory dialog - support extended syntax

Alexander Koblov 3 jaren geleden
bovenliggende
commit
f2213b9e21
4 gewijzigde bestanden met toevoegingen van 134 en 72 verwijderingen
  1. 50 61
      src/fmkdir.lfm
  2. 1 2
      src/fmkdir.lrj
  3. 81 7
      src/fmkdir.pas
  4. 2 2
      src/uglobs.pas

+ 50 - 61
src/fmkdir.lfm

@@ -1,6 +1,6 @@
 object frmMkDir: TfrmMkDir
   Left = 366
-  Height = 77
+  Height = 104
   Top = 429
   Width = 350
   ActiveControl = cbMkDir
@@ -8,17 +8,17 @@ object frmMkDir: TfrmMkDir
   BorderIcons = [biSystemMenu]
   BorderStyle = bsDialog
   Caption = 'Create new directory'
-  ClientHeight = 77
+  ClientHeight = 104
   ClientWidth = 350
   Constraints.MinHeight = 50
   Constraints.MinWidth = 350
   KeyPreview = True
   OnKeyPress = FormKeyPress
   Position = poOwnerFormCenter
-  LCLVersion = '1.1'
+  LCLVersion = '2.2.0.4'
   object lblMakeDir: TLabel
     Left = 6
-    Height = 18
+    Height = 15
     Top = 3
     Width = 338
     Align = alTop
@@ -31,8 +31,8 @@ object frmMkDir: TfrmMkDir
   end
   object cbMkDir: TComboBox
     Left = 6
-    Height = 28
-    Top = 21
+    Height = 23
+    Top = 18
     Width = 338
     Align = alTop
     AutoComplete = True
@@ -41,66 +41,55 @@ object frmMkDir: TfrmMkDir
     BorderSpacing.Right = 6
     BorderSpacing.Bottom = 3
     DropDownCount = 5
-    ItemHeight = 0
+    ItemHeight = 15
+    OnChange = cbMkDirChange
+    OnKeyUp = cbMkDirKeyUp
     TabOrder = 0
   end
-  object pnlBottom: TPanel
+  object cbExtended: TCheckBox
+    AnchorSideLeft.Control = cbMkDir
+    AnchorSideTop.Control = cbMkDir
+    AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 36
-    Top = 55
-    Width = 338
-    Align = alTop
-    AutoSize = True
-    BorderSpacing.Left = 6
-    BorderSpacing.Top = 6
-    BorderSpacing.Right = 6
-    BorderSpacing.Bottom = 3
-    BevelOuter = bvNone
-    ClientHeight = 36
-    ClientWidth = 338
+    Height = 19
+    Top = 44
+    Width = 106
+    Caption = '&Extended syntax'
+    OnChange = cbExtendedChange
     TabOrder = 1
-    object pnlButtons: TPanel
-      Left = 192
-      Height = 36
+  end
+  object ButtonPanel: TButtonPanel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = cbExtended
+    AnchorSideTop.Side = asrBottom
+    AnchorSideRight.Control = Owner
+    AnchorSideRight.Side = asrBottom
+    Left = 6
+    Height = 26
+    Top = 69
+    Width = 338
+    Align = alNone
+    Anchors = [akTop, akLeft, akRight]
+    OKButton.Name = 'OKButton'
+    OKButton.DefaultCaption = True
+    HelpButton.Name = 'HelpButton'
+    HelpButton.DefaultCaption = True
+    CloseButton.Name = 'CloseButton'
+    CloseButton.DefaultCaption = True
+    CancelButton.Name = 'CancelButton'
+    CancelButton.DefaultCaption = True
+    ButtonOrder = boCloseOKCancel
+    TabOrder = 2
+    ShowButtons = [pbOK, pbCancel]
+    ShowBevel = False
+    object lblExample: TLabel
+      AnchorSideLeft.Control = ButtonPanel
+      AnchorSideTop.Side = asrCenter
+      Left = 0
+      Height = 1
       Top = 0
-      Width = 146
-      Align = alRight
-      AutoSize = True
-      BevelOuter = bvNone
-      ClientHeight = 36
-      ClientWidth = 146
-      TabOrder = 0
-      object btnOK: TBitBtn
-        Left = 0
-        Height = 36
-        Top = 0
-        Width = 59
-        Align = alRight
-        AutoSize = True
-        BorderSpacing.Right = 3
-        BorderSpacing.InnerBorder = 2
-        Caption = '&OK'
-        Constraints.MinWidth = 50
-        Default = True
-        Kind = bkOK
-        ModalResult = 1
-        TabOrder = 0
-      end
-      object btnCancel: TBitBtn
-        Left = 62
-        Height = 36
-        Top = 0
-        Width = 84
-        Align = alRight
-        AutoSize = True
-        BorderSpacing.InnerBorder = 2
-        Cancel = True
-        Caption = '&Cancel'
-        Constraints.MinWidth = 50
-        Kind = bkCancel
-        ModalResult = 2
-        TabOrder = 1
-      end
+      Width = 1
+      ParentColor = False
     end
   end
 end

+ 1 - 2
src/fmkdir.lrj

@@ -1,6 +1,5 @@
 {"version":1,"strings":[
 {"hash":80444489,"name":"tfrmmkdir.caption","sourcebytes":[67,114,101,97,116,101,32,110,101,119,32,100,105,114,101,99,116,111,114,121],"value":"Create new directory"},
 {"hash":122714874,"name":"tfrmmkdir.lblmakedir.caption","sourcebytes":[38,73,110,112,117,116,32,110,101,119,32,100,105,114,101,99,116,111,114,121,32,110,97,109,101,58],"value":"&Input new directory name:"},
-{"hash":11067,"name":"tfrmmkdir.btnok.caption","sourcebytes":[38,79,75],"value":"&OK"},
-{"hash":177752476,"name":"tfrmmkdir.btncancel.caption","sourcebytes":[38,67,97,110,99,101,108],"value":"&Cancel"}
+{"hash":225074456,"name":"tfrmmkdir.cbextended.caption","sourcebytes":[38,69,120,116,101,110,100,101,100,32,115,121,110,116,97,120],"value":"&Extended syntax"}
 ]}

+ 81 - 7
src/fmkdir.pas

@@ -5,20 +5,23 @@ unit fMkDir;
 interface
 
 uses
-  SysUtils, Classes, Controls, Forms, StdCtrls, Buttons, ExtCtrls;
+  SysUtils, Classes, Controls, Forms, StdCtrls, Buttons, ExtCtrls, ButtonPanel;
 
 type
 
   { TfrmMkDir }
 
   TfrmMkDir = class(TForm)
-    btnCancel: TBitBtn;
-    btnOK: TBitBtn;
+    ButtonPanel: TButtonPanel;
+    cbExtended: TCheckBox;
     cbMkDir: TComboBox;
+    lblExample: TLabel;
     lblMakeDir: TLabel;
-    pnlButtons: TPanel;
-    pnlBottom: TPanel;
+    procedure cbExtendedChange(Sender: TObject);
+    procedure cbMkDirChange(Sender: TObject);
+    procedure cbMkDirKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure FormKeyPress(Sender: TObject; var Key: Char);
+    procedure RefreshExample;
   public
 
   end;
@@ -32,6 +35,32 @@ implementation
 uses
   DCStrUtils, uGlobs;
 
+function sReplace(sMask: string): string;
+var
+  iStart, iEnd: integer;
+begin
+  Result := '';
+  while Length(sMask) > 0 do
+  begin
+    iStart := Pos('[', sMask);
+    if iStart > 0 then
+    begin
+      iEnd := Pos(']', sMask);
+      if iEnd > iStart then
+      begin
+        Result := Result + Copy(sMask, 1, iStart - 1) +
+                  FormatDateTime(Copy(sMask, iStart + 1, iEnd - iStart - 1), Now);
+        Delete(sMask, 1, iEnd);
+      end
+      else
+        Break;
+    end
+    else
+      Break;
+  end;
+  Result := Result + sMask;
+end;
+
 procedure TfrmMkDir.FormKeyPress(Sender: TObject; var Key: Char);
 begin
   if Key = #27 then
@@ -46,11 +75,47 @@ begin
   end;
 end;
 
+procedure TfrmMkDir.RefreshExample;
+var
+  sPath: String;
+begin
+  if not cbExtended.Checked then
+    lblExample.Caption:= EmptyStr
+  else begin
+    sPath:= TrimPath(cbMkDir.Text);
+    if StrBegins(sPath, '<') then
+      lblExample.Caption:= sReplace(Copy(sPath, 2, MaxInt))
+    else
+      lblExample.Caption:= EmptyStr
+  end;
+end;
+
+procedure TfrmMkDir.cbMkDirKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+begin
+  RefreshExample;
+end;
+
+procedure TfrmMkDir.cbExtendedChange(Sender: TObject);
+begin
+  RefreshExample;
+end;
+
+procedure TfrmMkDir.cbMkDirChange(Sender: TObject);
+var
+  Index: Integer;
+begin
+  Index:= cbMkDir.ItemIndex;
+  if (Index >= 0) then begin
+    cbExtended.Checked:= Boolean(UIntPtr(cbMkDir.Items.Objects[Index]));
+  end;
+end;
+
 function ShowMkDir(TheOwner: TComponent; var sPath: String): Boolean;
 const
   MAX_LINES = 20;
 var
   Index: Integer;
+  Syntax: TObject;
 begin
   with TfrmMkDir.Create(TheOwner) do
   try
@@ -66,16 +131,25 @@ begin
     if Result then
     begin
       sPath := TrimPath(cbMkDir.Text);
+      Syntax := TObject(UIntPtr(cbExtended.Checked));
+
       glsCreateDirectoriesHistory.CaseSensitive := FileNameCaseSensitive;
       Index := glsCreateDirectoriesHistory.IndexOf(sPath);
 
       if (Index = -1) then
-        glsCreateDirectoriesHistory.Insert(0, sPath)
-      else
+        glsCreateDirectoriesHistory.InsertObject(0, sPath, Syntax)
+      else begin
         glsCreateDirectoriesHistory.Move(Index, 0);
+        glsCreateDirectoriesHistory.Objects[0]:= Syntax;
+      end;
 
       if (glsCreateDirectoriesHistory.Count > MAX_LINES) then
         glsCreateDirectoriesHistory.Delete(glsCreateDirectoriesHistory.Count - 1);
+
+      if cbExtended.Checked and StrBegins(sPath, '<') then
+      begin
+        sPath := lblExample.Caption;
+      end;
     end;
   finally
     Free;

+ 2 - 2
src/uglobs.pas

@@ -911,7 +911,7 @@ begin
       LoadHistory('SearchTextPath', glsSearchPathHistory);
       LoadHistory('ReplaceText', glsReplaceHistory);
       LoadHistory('ReplaceTextPath', glsReplacePathHistory);
-      LoadHistory('CreateDirectories', glsCreateDirectoriesHistory);
+      LoadHistory('CreateDirectories', glsCreateDirectoriesHistory, True);
       LoadHistory('RenameNameMask', glsRenameNameMaskHistory);
       LoadHistory('RenameExtMask', glsRenameExtMaskHistory);
       LoadHistory('SearchDirectories', glsSearchDirectories);
@@ -960,7 +960,7 @@ begin
       SaveHistory('SearchTextPath', glsSearchPathHistory);
       SaveHistory('ReplaceText', glsReplaceHistory);
       SaveHistory('ReplaceTextPath', glsReplacePathHistory);
-      SaveHistory('CreateDirectories', glsCreateDirectoriesHistory);
+      SaveHistory('CreateDirectories', glsCreateDirectoriesHistory, True);
       SaveHistory('RenameNameMask', glsRenameNameMaskHistory);
       SaveHistory('RenameExtMask', glsRenameExtMaskHistory);
       SaveHistory('SearchDirectories', glsSearchDirectories);