OSDN Git Service

Added insert const functionality
authornaru <bottle@mikage.to>
Sat, 4 Jan 2003 21:07:42 +0000 (21:07 +0000)
committernaru <bottle@mikage.to>
Sat, 4 Jan 2003 21:07:42 +0000 (21:07 +0000)
bottleclient/StrListEditor.dfm
bottleclient/StrListEditor.pas

index a368e41..3d9bdf8 100755 (executable)
@@ -1,10 +1,10 @@
 object frmStrListEditor: TfrmStrListEditor
-  Left = 761
-  Top = 519
+  Left = 717
+  Top = 501
   BorderStyle = bsDialog
   Caption = #25991#23383#21015#12522#12473#12488
-  ClientHeight = 213
-  ClientWidth = 346
+  ClientHeight = 240
+  ClientWidth = 344
   Color = clBtnFace
   Font.Charset = SHIFTJIS_CHARSET
   Font.Color = clWindowText
@@ -13,13 +13,15 @@ object frmStrListEditor: TfrmStrListEditor
   Font.Style = []
   OldCreateOrder = False
   Position = poScreenCenter
+  OnCreate = FormCreate
+  OnDestroy = FormDestroy
   OnShow = memStringsChange
   PixelsPerInch = 96
   TextHeight = 12
   object pnlHeader: TPanel
     Left = 0
     Top = 0
-    Width = 346
+    Width = 344
     Height = 28
     Align = alTop
     AutoSize = True
@@ -36,17 +38,17 @@ object frmStrListEditor: TfrmStrListEditor
   end
   object pnlFooter: TPanel
     Left = 0
-    Top = 172
-    Width = 346
+    Top = 199
+    Width = 344
     Height = 41
     Align = alBottom
     BevelOuter = bvNone
     TabOrder = 2
     DesignSize = (
-      346
+      344
       41)
     object btnCancel: TButton
-      Left = 184
+      Left = 182
       Top = 8
       Width = 81
       Height = 25
@@ -57,7 +59,7 @@ object frmStrListEditor: TfrmStrListEditor
       OnClick = btnCancelClick
     end
     object btnOk: TButton
-      Left = 272
+      Left = 270
       Top = 8
       Width = 67
       Height = 25
@@ -67,16 +69,30 @@ object frmStrListEditor: TfrmStrListEditor
       TabOrder = 0
       OnClick = btnOkClick
     end
+    object btnConst: TButton
+      Left = 8
+      Top = 8
+      Width = 75
+      Height = 25
+      Caption = #25407#20837'(&I)...'
+      PopupMenu = mnConst
+      TabOrder = 2
+      OnMouseDown = btnConstMouseDown
+    end
   end
   object memStrings: TMemo
     Left = 0
     Top = 28
-    Width = 346
-    Height = 144
+    Width = 344
+    Height = 171
     Align = alClient
     ScrollBars = ssVertical
     TabOrder = 0
     WordWrap = False
     OnChange = memStringsChange
   end
+  object mnConst: TPopupMenu
+    Left = 8
+    Top = 160
+  end
 end
index ce7cb72..0f3e3ae 100755 (executable)
@@ -4,7 +4,7 @@ interface
 
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, StdCtrls, ExtCtrls;
+  Dialogs, StdCtrls, ExtCtrls, Menus;
 
 type
   TfrmStrListEditor = class(TForm)
@@ -14,23 +14,35 @@ type
     btnCancel: TButton;
     btnOk: TButton;
     lblCaption: TLabel;
+    mnConst: TPopupMenu;
+    btnConst: TButton;
     procedure memStringsChange(Sender: TObject);
     procedure btnOkClick(Sender: TObject);
     procedure btnCancelClick(Sender: TObject);
+    procedure btnConstMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure FormCreate(Sender: TObject);
+    procedure FormDestroy(Sender: TObject);
   private
     FCanAllowEmpty: boolean;
+    FConsts: TStrings;
     procedure SetCanAllowEmpty(const Value: boolean);
+    procedure SetConsts(const Value: TStrings);
     { Private \90é\8c¾ }
   public
     { Public \90é\8c¾ }
+    procedure InsertConstItem(Sender: TObject);
     property CanAllowEmpty: boolean read FCanAllowEmpty write SetCanAllowEmpty;
+    property Consts: TStrings read FConsts write SetConsts;
   end;
 
 var
   frmStrListEditor: TfrmStrListEditor;
 
 function StrListEdit(const List: TStrings; CaptionStr: String;
-  AllowEmpty: boolean = false): boolean;
+  AllowEmpty: boolean = false): boolean; overload;
+function StrListEdit(const List: TStrings; CaptionStr: String;
+  AllowEmpty: boolean; ConstList: TStrings): boolean; overload;
 
 implementation
 
@@ -38,6 +50,12 @@ implementation
 
 function StrListEdit(const List: TStrings; CaptionStr: String;
   AllowEmpty: boolean = false): boolean;
+begin
+  Result := StrListEdit(List, CaptionStr, AllowEmpty, nil);
+end;
+
+function StrListEdit(const List: TStrings; CaptionStr: String;
+  AllowEmpty: boolean; ConstList: TStrings): boolean;
 var MyfrmStrListEditor: TfrmStrListEditor;
 begin
   Application.CreateForm(TfrmStrListEditor, MyfrmStrListEditor);
@@ -46,6 +64,11 @@ begin
       CanAllowEmpty := AllowEmpty;
       lblCaption.Caption := CaptionStr;
       memStrings.Lines := List; // Using Assign method (of course)
+      if ConstList <> nil then begin
+        Consts := ConstList;
+      end else begin
+        btnConst.Visible := false;
+      end;
       Result := ShowModal = mrOk;
       if Result then List.Assign(memStrings.Lines);
     finally
@@ -75,4 +98,44 @@ begin
   ModalResult := mrCancel;
 end;
 
+procedure TfrmStrListEditor.btnConstMouseDown(Sender: TObject;
+  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+var Pos: TPoint;
+begin
+  Pos := btnConst.ClientToScreen(Point(0, btnConst.Height));
+  mnConst.Popup(Pos.X, Pos.Y);
+end;
+
+procedure TfrmStrListEditor.InsertConstItem(Sender: TObject);
+begin
+  memStrings.Lines.Add(Consts[(Sender as TMenuItem).Tag]);
+end;
+
+procedure TfrmStrListEditor.SetConsts(const Value: TStrings);
+var i: integer;
+    AMenu: TMenuItem;
+begin
+  FConsts.Assign(Value);
+  mnConst.Items.Clear;
+  for i := 0 to Consts.Count-1 do begin
+    AMenu := TMenuItem.Create(self);
+    with AMenu do begin
+      Caption := Consts[i];
+      Tag := i;
+      OnClick := InsertConstItem;
+    end;
+    mnConst.Items.Add(AMenu);
+  end;
+end;
+
+procedure TfrmStrListEditor.FormCreate(Sender: TObject);
+begin
+  FConsts := TStringList.Create;
+end;
+
+procedure TfrmStrListEditor.FormDestroy(Sender: TObject);
+begin
+  FConsts.Free;
+end;
+
 end.