OSDN Git Service

Moved BuildMenu method to MainForm.pas etc.
authornaru <bottle@mikage.to>
Sat, 21 Dec 2002 13:10:37 +0000 (13:10 +0000)
committernaru <bottle@mikage.to>
Sat, 21 Dec 2002 13:10:37 +0000 (13:10 +0000)
bottleclient/MainForm.dfm
bottleclient/MainForm.pas
bottleclient/ScriptConsts.pas

index fd3d6a6..5022b5c 100755 (executable)
@@ -1,6 +1,6 @@
 object frmSender: TfrmSender
-  Left = 245
-  Top = 361
+  Left = 236
+  Top = 670
   Width = 524
   Height = 308
   Caption = 'SSTP Bottle Client'
index 664f9f3..a3e3df3 100755 (executable)
@@ -10,7 +10,8 @@ uses
   RichEdit, Clipbrd, SsParser, MPlayer, SakuraSeeker,
   HeadValue, Logs,
   IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdSLPP20,
-  IdException, HttpThread, IdHTTP, IdURI, DirectSstp, XPMan, LogDownload;
+  IdException, HttpThread, IdHTTP, IdURI, DirectSstp, XPMan, LogDownload,
+  ScriptConsts;
 
 type
   TfrmSender = class(TForm)
@@ -278,6 +279,7 @@ type
     procedure UpdateJoinChannelList(Dat: THeadValue);
     procedure NoLuidError;
     procedure UpdateIfGhostBox;
+    procedure BuildMenu(Root: TMenuItem; Event: TNotifyEvent);
   public
     function GetChannelPrefs(const ChannelName: String): TChannelPrefs;
     function DoTrans(var Script: String;
@@ -354,6 +356,9 @@ end;
 
 procedure TfrmSender.FormCreate(Sender: TObject);
 begin
+  ScriptConstList.LoadFromDir(ExtractFileDir(Application.ExeName)+'\consts');
+  Notified;
+
   FOriginalCaption := Self.Caption;
 
   FMutex := OpenMutex(MUTEX_ALL_ACCESS, false, 'SSTPBottleClient2');
@@ -384,7 +389,6 @@ begin
   mnGotoVote.Hint := Pref.VotePage;
   mnGotoHelp.Hint := Pref.HelpPage;
 
-
   mnGetNewId.Enabled := (Pref.LUID = '');
 
   try
@@ -422,8 +426,6 @@ begin
     Bottom := Self.Top + Self.Height - 1;
   end;
 
-  ReleaseMutex(FMutex);
-
   if FChannelList <> nil then begin
     FChannelList.Clear;
     FChannelList.Free;
@@ -431,6 +433,10 @@ begin
   if FJoinChannels <> nil then FJoinChannels.Free;
   if FJoinChannelsBackup <> nil then FJoinChannelsBackup.Free;
   if FCueGhost <> nil then FCueGhost.Free;
+
+  ScriptConstList.Save;
+
+  ReleaseMutex(FMutex);
 end;
 
 
@@ -805,7 +811,6 @@ end;
 procedure TfrmSender.FormClose(Sender: TObject; var Action: TCloseAction);
 begin
   EndConnect;
-  frmConstEditor.SaveToFile(ExtractFilePath(Application.ExeName) + 'constlist.txt');
 end;
 
 procedure TfrmSender.ApplicationEventsMinimize(Sender: TObject);
@@ -885,9 +890,9 @@ end;
 
 procedure TfrmSender.Notified;
 begin
-  frmConstEditor.BuildMenu(mnPopConst, mnConstClick);
-  frmConstEditor.BuildMenu(mnPopUpConst.Items, mnConstClick);
-  frmConstEditor.BuildMenu(ConstBarMenu.Items, mnConstClick);
+  BuildMenu(mnPopConst, mnConstClick);
+  BuildMenu(mnPopUpConst.Items, mnConstClick);
+  BuildMenu(ConstBarMenu.Items, mnConstClick);
   ConstMenuBar.Menu := nil;
   ConstMenuBar.AutoSize := false;
   ConstMenuBar.Width := 1000;
@@ -2146,4 +2151,40 @@ begin
   end;
 end;
 
+procedure TfrmSender.BuildMenu(Root: TMenuItem; Event: TNotifyEvent);
+var i, j, k: integer;
+    ConstData: TScriptConst;
+    Menu1, Menu2: TMenuItem;
+begin
+  for i := Root.Count-1 downto 0 do begin
+    if Root.Items[i].Tag >= 0 then begin
+      Root.Items[i].Free;
+    end;
+  end;
+  for i := 0 to ScriptConstList.Count-1 do begin
+    for j := 0 to ScriptConstList[i].Count-1 do begin
+      Menu1 := TMenuItem.Create(Root);
+      Menu1.Caption := ScriptConstList[i][j].Caption;
+      Menu1.Hint    := ScriptConstList[i][j].Caption;
+      Menu1.AutoHotkeys := maManual;
+      Menu1.Tag := ScriptConstList[i][j].ID;
+      Root.Add(Menu1);
+      Menu1.Enabled := ScriptConstList[i][j].Count > 0;
+      for k := 0 to ScriptConstList[i][j].Count-1 do begin
+        ConstData := ScriptConstList[i][j][k];
+        Menu2 := TMenuItem.Create(Root);
+        Menu2.Caption := ConstData.Caption;
+        Menu2.Hint := ConstData.ConstText;
+        if ConstData.ShortCut <> 0 then Menu2.Hint := Menu2.Hint
+          + ' (' + ShortCutToText(ConstData.ShortCut) + ')';
+        Menu2.ShortCut := ConstData.ShortCut;
+        Menu2.OnClick := Event;
+        Menu2.AutoHotkeys := maManual;
+        Menu2.Tag := ConstData.ID;
+        Menu1.Add(Menu2);
+      end;
+    end;
+  end;
+end;
+
 end.
index de38aa5..a9d638e 100755 (executable)
@@ -16,13 +16,16 @@ type
     FConstText: String;
     FShortCut: TShortCut;
     FCaption: String;
+    FID: integer;
     procedure SetCaption(const Value: String);
     procedure SetConstText(const Value: String);
     procedure SetShortCut(const Value: TShortCut);
   public
+    constructor Create;
     property Caption: String read FCaption write SetCaption;
     property ShortCut: TShortCut read FShortCut write SetShortCut;
     property ConstText: String read FConstText write SetConstText;
+    property ID: integer read FID;
     function ToString: String;               // \95\8e\9a\97ñ\95\\8c»\82É\95Ï\8a·
     procedure FromString(const Str: String); // \93Ç\82Ý\8fo\82µ
     procedure Assign(Source: TPersistent); override;
@@ -33,6 +36,7 @@ type
     FConsts: TObjectList;
     FCaption: String;
     FIfGhost: String;
+    FID: integer;
     function GetCount: integer;
     function GetConsts(Index: integer): TScriptConst;
     procedure SetCaption(const Value: String);
@@ -40,12 +44,14 @@ type
   public
     constructor Create;
     destructor Destroy; override;
+    property ID: integer read FID;
     property Count: integer read GetCount;
     property Consts[Index: integer]: TScriptConst read GetConsts; default;
     property Caption: String read FCaption write SetCaption;
     property IfGhost: String read FIfGhost write SetIfGhost;
     procedure Load(Lines: TStrings);
     procedure Save(Lines: TStrings);
+    procedure Delete(const ID: integer);
   end;
 
   TScriptConstFile = class(TObject) // \8eq\81BTScriptConstMenu\82Ì\83\8a\83X\83g\81B
@@ -63,6 +69,7 @@ type
     property Menus[Index: integer]: TScriptConstMenu read GetMenus; default;
     procedure LoadFromFile(LoadFileName: String);
     procedure SaveToFile;
+    procedure Delete(const ID: integer);
   end;
 
   TScriptConstList = class(TObject) // \90e\81BScriptConstFile\82Ì\83\8a\83X\83g\81B
@@ -77,10 +84,21 @@ type
     procedure Save;
     property Files[Index: integer]: TScriptConstFile read GetFiles; default;
     property Count: integer read GetCount;
+    function GetConstByID(const ID: integer): TScriptConst;
+    function GetMenuByID(const ID: integer): TScriptConstMenu;
+    //procedure MoveUp(const ID: integer);
+    //procedure MoveDown(const ID: integer);
+    procedure Delete(const ID: integer);
   end;
 
+var
+  ScriptConstList: TScriptConstList;
+
 implementation
 
+var OldID: integer; // \92è\8c^\8bå\82Ì\93à\95\94ID\81BTag\82É\93ü\82ê\82é\97p
+
+
 // \92P\8f\83\82É\83o\83C\83g\92P\88Ê\82Å\95\8e\9a\97ñ\82ð\8c©\82Ä\82¢\82«\95ª\89ð\82·\82é\83\86\81[\83e\83B\83\8a\83e\83B\8aÖ\90\94
 function Token(const Str: String; const Delimiter: char;
   const Index: integer): String;
@@ -106,12 +124,36 @@ begin
   FFiles := TObjectList.Create(true);
 end;
 
+procedure TScriptConstList.Delete(const ID: integer);
+var i: integer;
+begin
+  for i := Count-1 downto 0 do begin
+    Files[i].Delete(ID);
+  end;
+end;
+
 destructor TScriptConstList.Destroy;
 begin
   FreeAndNil(FFiles);
   inherited;
 end;
 
+function TScriptConstList.GetConstByID(const ID: integer): TScriptConst;
+var i, j, k: integer;
+begin
+  Result := nil;
+  for i := 0 to Count-1 do begin
+    for j := 0 to Files[i].Count-1 do begin
+      for k := 0 to Files[i][j].Count-1 do begin
+        if Files[i][j][k].ID = ID then begin
+          Result := Files[i][j][k];
+          Exit;
+        end;
+      end;
+    end;
+  end;
+end;
+
 function TScriptConstList.GetCount: integer;
 begin
   Result := FFiles.Count;
@@ -122,6 +164,20 @@ begin
   Result := FFiles[Index] as TScriptConstFile;
 end;
 
+function TScriptConstList.GetMenuByID(const ID: integer): TScriptConstMenu;
+var i, j: integer;
+begin
+  Result := nil;
+  for i := 0 to Count-1 do begin
+    for j := 0 to Files[i].Count-1 do begin
+      if Files[i][j].ID = ID then begin
+        Result := Files[i][j];
+        Exit;
+      end;
+    end;
+  end;
+end;
+
 procedure TScriptConstList.LoadFromDir(const Dir: String);
 var F: TSearchRec;
     i: integer;
@@ -165,6 +221,15 @@ begin
   end;
 end;
 
+constructor TScriptConst.Create;
+begin
+  // \92è\8c^\8bå\82ÌID\82ð\90\90¬\82·\82é
+  // TMenuItem\82ÌTag\82É\93ü\82ê\82é\82±\82Æ\82Å\83\81\83j\83\85\81[\8d\80\96Ú\82ª\8e©\95ª\82É\91Î\89\9e\82·\82éTScriptConst\82ð
+  // \92m\82é\82±\82Æ\82ª\82Å\82«\82é
+  FID := OldID+1;
+  OldID := OldID+1;
+end;
+
 procedure TScriptConst.FromString(const Str: String);
 begin
   if Str[1] <> #9 then
@@ -203,6 +268,18 @@ begin
   FMenus := TObjectList.Create(true);
 end;
 
+procedure TScriptConstFile.Delete(const ID: integer);
+var i: integer;
+begin
+  for i := FMenus.Count-1 downto 0 do begin
+    Menus[i].Delete(ID); // Item\82ð\8dí\8f\9c(\82µ\82æ\82¤\82Æ\82·\82é)
+    if Menus[i].ID = ID then begin
+      FMenus.Delete(i);  // Menu\82ð\8dí\8f\9c
+      Exit;
+    end;
+  end;
+end;
+
 destructor TScriptConstFile.Destroy;
 begin
   FreeAndNil(FMenus);
@@ -264,9 +341,19 @@ end;
 
 constructor TScriptConstMenu.Create;
 begin
+  FID := OldID + 1;
+  OldID := OldID + 1;
   FConsts := TObjectList.Create(true);
 end;
 
+procedure TScriptConstMenu.Delete(const ID: integer);
+var i: integer;
+begin
+  for i := Count-1 downto 0 do begin
+    if Consts[i].ID = ID then FConsts.Delete(i);
+  end;
+end;
+
 destructor TScriptConstMenu.Destroy;
 begin
   FreeAndNil(FConsts);
@@ -326,4 +413,13 @@ begin
   FIfGhost := Value;
 end;
 
+initialization
+
+ScriptConstList := TScriptConstList.Create;
+OldID := 0;
+
+finalization
+
+ScriptConstList.Free;
+
 end.