OSDN Git Service

クリップ時に保存確認しないように修正。
[winbottle/winbottle.git] / bottleclient / LogForm.pas
index 06b1a90..bfcb5e8 100755 (executable)
@@ -6,7 +6,8 @@ uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus,
   Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, StrUtils,
-  TalkShowFrame, SppList, HtmlOutputConfig, HtmlOutputProgress;
+  TalkShowFrame, SppList, HtmlOutputConfig, HtmlOutputProgress,
+  SearchLog, IniFiles, BRegExp, RegexUtils;
 
 type
   // \83\8d\83O\82Ì\95Û\91\95û\96@
@@ -76,6 +77,10 @@ type
     mnDeleteLogItem: TMenuItem;
     mnTabSaveXMLLog: TMenuItem;
     mnSaveHTML: TMenuItem;
+    mnPopupCopyGhost: TMenuItem;
+    PopupMenuAction: TPopupMenu;
+    mnTestAction: TMenuItem;
+    mnSelAction: TMenuItem;
     procedure tbtnClearClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure lvwLogChange(Sender: TObject; Item: TListItem;
@@ -126,6 +131,9 @@ type
     procedure lvwLogEndDrag(Sender, Target: TObject; X, Y: Integer);
     procedure mnTabSaveXMLLogClick(Sender: TObject);
     procedure mnSaveHTMLClick(Sender: TObject);
+    procedure mnPopupCopyGhostClick(Sender: TObject);
+    procedure mnTestActionClick(Sender: TObject);
+    procedure mnSelActionClick(Sender: TObject);
   private
     { Private \90é\8c¾ }
     FLastScript: String; //\83X\83N\83\8a\83v\83g\8dÄ\95`\89æ\97}\90§\97p
@@ -149,15 +157,20 @@ type
       Item: TListItem);
     procedure PreviewStyleChange;
     procedure DrawListViewDragBorder(const Rect: TRect);
-    procedure DoSaveLogXML(Log: TBottleLogList);
+    function DoSaveLogXML(Log: TBottleLogList): integer;
     procedure DoCloseTab(const Index: integer);
+    function DoSearchLog(Condition: TSearchCond): TBottleLogList;
+    procedure SearchLogIndivisual(Condition: TSearchCond;
+      LogList, Result: TBottleLogList; UntilIndex: integer = -1);
+    function CheckLogSave(const Index: integer): integer;
   protected
     procedure CreateParams(var Params: TCreateParams); override;
   public
     { Public \90é\8c¾ }
     function SelectedBottleLog: TBottleLogList;
     property BottleLogList: TObjectList read FBottleLogList;
-    procedure AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String);
+    procedure AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String;
+      const LogTime: TDateTime; const Vote, Agree: integer);
     procedure AddCurrentSystemLog(const LogName, MessageString: String);
     procedure VoteLog(const MID: String; const Vote: integer);
     procedure AgreeLog(const MID: String; const Agree: integer);
@@ -171,6 +184,7 @@ type
     procedure UpdateTab;
     procedure UpdateWindow;
     procedure SelAndFocusMessage(const MID: String);
+    function CheckLog(Sender: TObject): integer;
   end;
 
   TBottleLogDragObject = class(TDragControlObjectEx)
@@ -209,10 +223,12 @@ uses MainForm;
 
 { TfrmLog }
 
-procedure TfrmLog.AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String);
+procedure TfrmLog.AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String;
+  const LogTime: TDateTime; const Vote, Agree: integer);
 var Sel: integer;
 begin
-  BottleLogTitled(LogName).AddScriptLog(Script, Channel, MID, Ghost);
+  BottleLogTitled(LogName).AddScriptLog(Script, Channel, MID, Ghost, LogTime, Vote, Agree);
+  BottleLogTitled(LogName).LogModified := true; // \82±\82Ì\83\8a\83X\83g\82Í\95Ï\8dX\82³\82ê\82½
   if SelectedBottleLog <> BottleLogTitled(LogName) then Exit;
   lvwLog.OnChange := nil; //\83C\83x\83\93\83g\94­\90¶(\82¢\82ë\82¢\82ë\8dÄ\95`\89æ\82ª\8bN\82«\82é)\82Ì\97}\90§
   if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
@@ -286,6 +302,8 @@ begin
   TalkShowFrame.SetPreviewFont(edtScript.Font);
   TalkShowFrame.PrevControl := lvwLog;
 
+  mnSelAction.Checked := Pref.LogAction; // \8f\89\8aú\89»
+
   PreviewStyleChange;
   UpdateWindow; // Reset window color and enabled status of some buttons
 end;
@@ -321,13 +339,15 @@ begin
   Selected := false;
   IsNormalBottle := false;
   if SelectedBottleLog <> nil then begin
-    StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '\8c\8f';
     if Change = ctState then begin
       Script := '';
       if lvwLog.Selected <> nil then begin
         Selected := true;
+        StatusBar.Panels[0].Text := Format('%d/%d\8c\8f', [lvwLog.Selected.Index+1,
+          SelectedBottleLog.Count]);
         Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
-        if (Log.LogType = ltBottle) and not frmSender.Connecting then begin
+//        if (Log.LogType = ltBottle) and not frmSender.Connecting then begin
+        if Log.LogType = ltBottle then begin
           IsNormalBottle := true;
           Script := Log.Script;
           Text := Format('%d\83o\83C\83g/%d\95b - \83_\83u\83\8b\83N\83\8a\83b\83N\82Å\8dÄ\90¶',
@@ -342,6 +362,7 @@ begin
           UpdateScript(''); // \83\8d\83O\83v\83\8c\83r\83\85\81[\95\94\82ð\83N\83\8a\83A
         end;
       end else begin
+        StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '\8c\8f';
         StatusBar.Panels[1].Text := '';
         UpdateScript(Script); // \83\8d\83O\83v\83\8c\83r\83\85\81[\95\94\83N\83\8a\83A
       end;
@@ -357,6 +378,7 @@ begin
   frmSender.actInsertCue.Enabled := Selected;
   frmSender.actDeleteLogItem.Enabled := Selected;
   mnPopUpCopyScript.Enabled := Selected and IsNormalBottle;
+  mnPopupCopyGhost.Enabled := Selected and IsNormalBottle;
 end;
 
 procedure TfrmLog.lvwLogDblClick(Sender: TObject);
@@ -370,7 +392,14 @@ begin
   if Log = nil then Exit;
   if Log.LogType <> ltBottle then
     Exit;
-  Script := frmSender.ScriptTransForSSTP(Log.Script, ErrorMes);
+  //\92P\91Ì\83A\83N\83V\83\87\83\93\82ª\97L\8cø\82Å\82 \82ê\82Î\83X\83N\83\8a\83v\83g\82Ì\95Ï\8a·\82µ\82È\82¢
+  if Pref.LogAction then
+  begin
+    Script :=  Log.Script;
+    ErrorMes := '';
+  end else
+    Script := frmSender.ScriptTransForSSTP(Log.Script, ErrorMes);
+
   if ErrorMes <> '' then
   begin
     Res := MessageDlg('\96â\91è\82Ì\82 \82é\83X\83N\83\8a\83v\83g\82Å\82·\81B\8dÄ\90\82Å\82«\82Ü\82¹\82ñ\81B'#13#10+
@@ -384,8 +413,19 @@ begin
 
   CueItem := TLogItem.Create(Log);
   try
-    CueItem.Script := Script;
-    frmSender.BottleSstp.Unshift(CueItem);
+    //\83A\83N\83V\83\87\83\93\82ª\97L\8cø\82Å\82 \82ê\82Î\92Ê\8fí\8f\88\97\9d\8fÈ\97ª
+    if Pref.LogAction then
+      //\8c^\95Ï\8a·\82Æ\8eó\90M
+      frmSender.BottleCnv(CueItem)
+    else
+    begin
+      //\83`\83\83\83\93\83l\83\8b\83S\81[\83X\83g\91Î\8dô
+      if CueItem.Ghost = '' then
+        if ChannelList.Channel[CueItem.Channel] <> nil then
+          CueItem.Ghost := ChannelList.Channel[CueItem.Channel].Ghost;
+      CueItem.Script := Script;
+      frmSender.BottleSstp.Unshift(CueItem);
+    end;
   except
     CueItem.Free;
   end;
@@ -530,7 +570,7 @@ procedure TfrmLog.mnSaveLogClick(Sender: TObject);
 begin
   if SelectedBottleLog = nil then Exit;
   SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
-  SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
+  SaveDialog.InitialDir := Pref.LogDir;
   SaveDialog.DefaultExt := 'log';
   SaveDialog.FilterIndex := 1;
   if SaveDialog.Execute then
@@ -541,7 +581,7 @@ procedure TfrmLog.mnSaveLogChannelClick(Sender: TObject);
 begin
   if SelectedBottleLog = nil then Exit;
   SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
-  SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
+  SaveDialog.InitialDir := Pref.LogDir;
   SaveDialog.DefaultExt := 'log';
   SaveDialog.FilterIndex := 1;
   if SaveDialog.Execute then
@@ -552,7 +592,7 @@ procedure TfrmLog.mnSaveLogScriptClick(Sender: TObject);
 begin
   if SelectedBottleLog = nil then Exit;
   SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.txt');
-  SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
+  SaveDialog.InitialDir := Pref.LogDir;
   SaveDialog.DefaultExt := 'txt';
   SaveDialog.FilterIndex := 2;
   if SaveDialog.Execute then
@@ -608,7 +648,7 @@ procedure TfrmLog.UpdateWindow;
 var EnabledFlag: boolean;
 begin
   lvwLog.Color := Pref.BgColor;
-  lvwLog.Font.Color := Pref.TalkColorH;
+  lvwLog.Font.Color := Pref.TextColor;
   if SelectedBottleLog <> nil then begin
     Caption := '\83\8d\83O - ' + SelectedBottleLog.Title;
     StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '\8c\8f';
@@ -662,7 +702,7 @@ end;
 
 procedure TfrmLog.mnURLClick(Sender: TObject);
 var LogItem: TLogItem;
-    URL: String;
+    URL: string;
     Urls: TStringList;
 begin
   if (lvwLog.Selected = nil) or (SelectedBottleLog = nil) then Exit;
@@ -671,7 +711,7 @@ begin
   try
     ExtractURLs(LogItem.Script, Urls);
     URL := Urls[(Sender as TMenuItem).Tag];
-    ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOW);
+    frmSender.OpenBrowser(URL);
   finally
     Urls.Free;
   end;
@@ -683,8 +723,11 @@ var i, u, j: integer;
 begin
   Result.Clear;
   SsParser.InputString := Script;
+  SsParser.LeaveEscape := true;
   for i := 0 to SsParser.Count-1 do begin
-    if (SsParser.Match(SsParser[i], '\URL%b') > 0) then begin
+    if (SsParser.Match(SsParser[i], '\URL%b') > 0)
+    and (SsParser.MarkUpType[i] = mtTag) then
+    begin
       for u := 7 downto 1 do begin
         if (SsParser.Match(SsParser[i],
             '\URL%b'+StringReplace(StringOfChar('-', u*2),
@@ -915,39 +958,55 @@ begin
 end;
 
 procedure TfrmLog.tbtnFindBottleClick(Sender: TObject);
-var Query: String;
-    ResultLog: TBottleLogList;
-    Item1, Item2: TLogItem;
-    i, matched: integer;
+var ResultLog: TBottleLogList;
+    Cond: TSearchCond;
+    i: integer;
+    CList, GList: THashedStringList;
 begin
-  if SelectedBottleLog = nil then Exit;
-  if SelectedBottleLog.Count = 0 then begin
-    ShowMessage('\8c\9f\8dõ\91Î\8fÛ\82ª\8bó\82Å\82·\81B');
-    Exit;
-  end;
-  Query := '';
-  matched := 0;
-  if InputQuery('\83X\83N\83\8a\83v\83g\96{\95\82ð\8c\9f\8dõ', '\8c\9f\8dõ\95\8e\9a\97ñ', Query) then begin
-    if Query = '' then Exit;
-    ResultLog := TBottleLogList.Create('\8c\9f\8dõ\8c\8b\89Ê');
-    for i := 0 to SelectedBottleLog.Count-1 do begin
-      Item1 := SelectedBottleLog.Items[i] as TLogItem;
-      if AnsiContainsText(Item1.Script, Query) and (Item1.LogType = ltBottle) then begin
-        matched := matched + 1;
-        Item2 := TLogItem.Create(ltBottle, Item1.MID, Item1.Channel,
-          Item1.Script, Item1.Ghost, Item1.LogTime);
-        Item2.State := lsOpened;
-        Item2.Votes := Item1.Votes;
-        Item2.Agrees := Item1.Agrees;
-        ResultLog.Add(Item2);
+  Application.CreateForm(TfrmSearchLog, frmSearchLog);
+  Cond := TSearchCond.Create(nil);
+  try
+    try
+      with frmSearchLog do
+      begin
+        // \8c»\8dÝ\83\8d\83O\82É\82 \82é\83S\81[\83X\83g\82Æ\83`\83\83\83\93\83l\83\8b\82Ì\83\8a\83X\83g\82ð\8eæ\93¾
+        // \8fd\82½\82¢\82©\82à??
+        CList := THashedStringList.Create;
+        GList := THashedStringList.Create;
+        try
+          for i := 0 to BottleLogList.Count-1 do
+          begin
+            with BottleLogList[i] as TBottleLogList do
+            begin
+              ExtractUniqueChannels(CList);
+              ExtractUniqueGhosts(GList);
+            end;
+          end;
+          CList.Sort;
+          GList.Sort;
+          ChannelList := CList;
+          GhostList   := GList;
+        finally
+          CList.Free;
+          GList.Free;
+        end;
+        if not Execute then
+          Exit
+        else
+          Cond.Assign(Condition);
       end;
+    finally
+      frmSearchLog.Release;
     end;
-    if matched = 0 then
-      ResultLog.AddSystemLog('\8c©\82Â\82©\82è\82Ü\82¹\82ñ\82Å\82µ\82½');
+    // \8c\9f\8dõ\8eÀ\8ds
+    ResultLog := DoSearchLog(Cond);
+    // \90V\83^\83u\82ð\8dì\90¬\82µ\82Ä\89æ\96Ê\8dX\90V
     BottleLogList.Add(ResultLog);
     UpdateTab;
     tabBottleLog.TabIndex := BottleLogList.Count-1;
     UpdateWindow;
+  finally
+    Cond.Free;
   end;
 end;
 
@@ -956,6 +1015,7 @@ var BottleLog: TBottleLogList;
     i, Index: integer;
 begin
   Index := -1;
+  OpenDialog.InitialDir := Pref.LogDir;
   if OpenDialog.Execute then begin
     for i := 0 to OpenDialog.Files.Count-1 do begin
       BottleLog := TBottleLogList.Create(ExtractFileName(OpenDialog.Files[i]));
@@ -1018,13 +1078,20 @@ procedure TfrmLog.tabBottleLogMouseDown(Sender: TObject;
   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 var Index: integer;
 begin
-  with tabBottleLog do begin
-    Index := IndexOfTabAt(X, Y);
-    if Index = -1 then Exit; //\83^\83u\82ª\82È\82¢\82Ì\82Å\83h\83\89\83b\83O\82Å\82«\82È\82¢
-    if Button = mbLeft then begin
-      FDragTabIndex := Index; //\83h\83\89\83b\83O\82·\82é\83^\83u\82Ì\83C\83\93\83f\83b\83N\83X\82ð\95Û\91
-      BeginDrag(False);
-      FDragTabDest := -1;     //\83h\83\89\83b\83O\98g\90ü\95`\89æ\83t\83\89\83O\83N\83\8a\83A\82Ì\82½\82ß
+  if Button = mbMiddle then
+  begin
+    //\92\86\83{\83^\83\93\83N\83\8a\83b\83N\82Å\83^\83u\8dí\8f\9c
+    DoCloseTab(tabBottleLog.IndexOfTabAt(X, Y));
+  end else
+  begin
+    with tabBottleLog do begin
+      Index := IndexOfTabAt(X, Y);
+      if Index = -1 then Exit; //\83^\83u\82ª\82È\82¢\82Ì\82Å\83h\83\89\83b\83O\82Å\82«\82È\82¢
+      if Button = mbLeft then begin
+        FDragTabIndex := Index; //\83h\83\89\83b\83O\82·\82é\83^\83u\82Ì\83C\83\93\83f\83b\83N\83X\82ð\95Û\91
+        BeginDrag(False);
+        FDragTabDest := -1;     //\83h\83\89\83b\83O\98g\90ü\95`\89æ\83t\83\89\83O\83N\83\8a\83A\82Ì\82½\82ß
+      end;
     end;
   end;
 end;
@@ -1109,7 +1176,11 @@ end;
 
 procedure TfrmLog.LogLoadWork(Sender: TObject);
 begin
-  if Sender = SelectedBottleLog then lvwLog.Invalidate;
+  if Sender = SelectedBottleLog then
+  begin
+    lvwLog.Invalidate;
+    lvwLog.Items.Count := SelectedBottleLog.Count;
+  end;
 end;
 
 procedure TfrmLog.lvwLogDrawItem(Sender: TCustomListView; Item: TListItem;
@@ -1170,7 +1241,7 @@ begin
     else
       lvwLog.Canvas.Font.Color := clWindowText;
   end else
-    lvwLog.Canvas.Font.Color := Pref.TalkColorH;
+  lvwLog.Canvas.Font.Color := Pref.TextColor;
   lvwLog.Canvas.Refresh;
 
   // \83L\83\83\83v\83V\83\87\83\93(\93ú\95t)
@@ -1179,7 +1250,7 @@ begin
   Inc(DestRect.Top, 2);
   Dec(DestRect.Right, 2);
   DrawTextEx(lvwLog.Canvas.Handle, PChar(Item.Caption), -1, DestRect,
-    DT_SINGLELINE or DT_END_ELLIPSIS, nil);
+    DT_SINGLELINE or DT_RIGHT, nil);
   ListView_GetItemRect(lvwLog.Handle, Item.Index, DestRect, LVIR_ICON);
   Ico := TIcon.Create;
   try
@@ -1194,6 +1265,13 @@ begin
     if sub = SubScript then Continue;
     ListView_GetSubItemRect(lvwLog.Handle, Item.Index, sub + 1,
       LVIR_BOUNDS, @DestRect);
+    if DestRect.Right - DestRect.Left <= 16 then
+    begin
+      // \8b·\82·\82¬\82é\8fê\8d\87\82Í\95\8e\9a\97ñ\82ð\95`\89æ\82µ\82È\82¢\81B
+      // 16\82Æ\82¢\82¤\90\94\8e\9a\82Í\8eÀ\91ª\92l\81B\89½\82©\82Ì\83o\83O\82Á\82Û
+      lvwLog.Canvas.FillRect(DestRect);
+      Continue;
+    end;
     Inc(DestRect.Left, 2);
     Inc(DestRect.Top, 2);
     Dec(DestRect.Right, 2);
@@ -1442,7 +1520,20 @@ begin
   lvwLog.Items.BeginUpdate; // \83h\83\8d\83b\83v\92\86\82Í\95\\8e¦\82ð\97}\8e~\82·\82é\81@\8fd\97v\81I
   try
     // \83h\83\8d\83b\83v\88Ê\92u\82É Item \82ð\88Ú\93®\82·\82é
-    SrcLog := Src.BottleLogList.Extract(Src.LogItem);
+    if (GetAsyncKeyState(VK_CONTROL) and $8000) > 0 then
+    begin // \83R\83s\81[\88Ú\93®\82Ì\8fê\8d\87
+      SrcLog := TLogItem.Create(Src.LogItem);
+      SelectedBottleLog.LogModified := true; // \95Ï\8dX\88µ\82¢\82É\82·\82é
+    end else // \88Ú\93®\82¾\82¯\82·\82é\8fê\8d\87
+    begin
+      SrcLog := Src.BottleLogList.Extract(Src.LogItem);
+      // \88Ú\93®\8c³\82Æ\88Ú\93®\90æ\82ª\88á\82Á\82Ä\82¢\82ê\82Î\97¼\95û\82Ì\83t\83\89\83O\82ð\97§\82Ä\82é
+      if SelectedBottleLog.SelectedIndex <> Src.BottleLogList.SelectedIndex then
+      begin
+        Src.BottleLogList.LogModified := true; // \88Ú\93®\8c³
+        SelectedBottleLog.LogModified := true; // \88Ú\93®\90æ
+      end;
+    end;
     if TargetItem >= 0 then
     begin
       // \82·\82Å\82É\91\8dÝ\82·\82é\83A\83C\83e\83\80\82Ì\8fã\82É\83h\83\8d\83b\83v\82µ\82½\8fê\8d\87
@@ -1525,14 +1616,20 @@ begin
   end;
 end;
 
-procedure TfrmLog.DoSaveLogXML(Log: TBottleLogList);
+function TfrmLog.DoSaveLogXML(Log: TBottleLogList): integer;
+var
+  Res: integer;
 begin
+  Res := idYes;
   SaveDialog.FileName := GetDefaultFileName(Log.Title, '.xml');
-  SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
+  SaveDialog.InitialDir := Pref.LogDir;
   SaveDialog.DefaultExt := 'xml';
   SaveDialog.FilterIndex := 3;
   if SaveDialog.Execute then
-    Log.SaveToXmlFile(SaveDialog.FileName);
+    Log.SaveToXmlFile(SaveDialog.FileName)
+  else
+    Res := idCancel;
+  Result := Res;
 end;
 
 procedure TfrmLog.DoCloseTab(const Index: integer);
@@ -1541,6 +1638,7 @@ var
   PrevSelection: TBottleLogList; // \95Â\82\82½\82Æ\82«\83^\83u\82ª\82¸\82ê\82È\82¢\82æ\82¤\82É\82·\82é\8f\88\97\9d\97p
   i: integer;
 begin
+  if CheckLogSave(Index) = idCancel then exit; // \83\8d\83O\82Ì\95Û\91\8am\94F
   if Pref.ConfirmOnTabClose then
   begin
     Confirm := Format('\83^\83u"%s"\82ð\95Â\82\82Ü\82·\82©?', [(FBottleLogList[Index] as TBottleLogList).Title]);
@@ -1567,6 +1665,99 @@ begin
     Canceled := true;
 end;
 
+function TfrmLog.DoSearchLog(Condition: TSearchCond): TBottleLogList;
+var i, UntilIndex: integer;
+begin
+  Result := TBottleLogList.Create('\8c\9f\8dõ\8c\8b\89Ê');
+  if Condition.SearchLogRange in [srSelectedLogList, srAboveSelectedLog] then
+  begin
+    if SelectedBottleLog = nil then
+    begin
+      ShowMessage('\8c\9f\8dõ\91Î\8fÛ\82ª\82 \82è\82Ü\82¹\82ñ');
+      Result.Free;
+      Result := nil;
+      Exit;
+    end else
+    begin
+      if Condition.SearchLogRange = srSelectedLogList then
+        UntilIndex := -1
+      else if lvwLog.Selected = nil then
+        UntilIndex := -1
+      else
+        UntilIndex := lvwLog.Selected.Index;
+      SearchLogIndivisual(Condition, SelectedBottleLog, Result, UntilIndex);
+    end;
+  end else if Condition.SearchLogRange = srAllLogLists then
+  begin
+    for i := 0 to BottleLogList.Count-1 do
+    begin
+      SearchLogIndivisual(Condition, BottleLogList[i] as TBottleLogList,
+        Result);
+    end;
+  end;
+
+  if Result.Count = 0 then
+    Result.AddSystemLog('\8c©\82Â\82©\82è\82Ü\82¹\82ñ\82Å\82µ\82½\81B');
+end;
+
+procedure TfrmLog.SearchLogIndivisual(Condition: TSearchCond; LogList,
+  Result: TBottleLogList; UntilIndex: integer = -1);
+var
+  i, Max: integer;
+  Bottle, New: TLogItem;
+  Ok: boolean;
+begin
+  // 1\8cÂ\82Ì\83\8d\83O\83^\83u\82É\91Î\82µ\82Ä\8c\9f\8dõ\82ð\82©\82¯\82é\81BUntilIndex\82Å\94Í\88Í\8ew\92è(\8fÈ\97ª\8e\9e\82»\82Ì\83^\83u\91S\91Ì)
+  if UntilIndex >= 0 then
+    Max := UntilIndex
+  else
+    Max := LogList.Count-1;
+  for i := 0 to Max do
+  begin
+    // \8fð\8c\8f\94»\92è
+    Bottle := LogList.Bottles[i];
+    if Bottle.LogType <> ltBottle then
+      Continue;
+    Ok := true;
+    // \83X\83N\83\8a\83v\83g\83p\83^\81[\83\93\82Å\89ð\90Í
+    if Condition.ScriptPattern <> '' then
+    begin
+      if Condition.ScriptRegExp then
+      begin
+        try
+          if not RegExp.Match(Condition.ScriptPattern, Bottle.Script) then
+            Ok := false;
+        except
+          on EBRegExpError do
+            Ok := false; //\96­\82È\90³\8bK\95\\8c»\82ð\8fR\82é
+        end;
+      end else
+      begin
+        if not AnsiContainsText(Bottle.Script, Condition.ScriptPattern) then
+          Ok := false;
+      end;
+    end;
+    // \83`\83\83\83\93\83l\83\8b\96¼\81A\83S\81[\83X\83g\96¼\81A\93\8a\95[\93¯\88Ó
+    if Condition.Channel <> '' then
+      if not AnsiContainsText(Bottle.Channel, Condition.Channel) then
+        Ok := false;
+    if Condition.Ghost <> '' then
+      if not AnsiContainsText(Bottle.Ghost, Condition.Ghost) then
+        Ok := false;
+    if Condition.MinVote > Bottle.Votes then
+      Ok := false;
+    if Condition.MinAgree > Bottle.Agrees then
+      Ok := false;
+    // \8fð\8c\8f\82É\88ê\92v\82µ\82½\82à\82Ì\82ð\8c\8b\89Ê\83\8a\83X\83g\82É\92Ç\89Á
+    if Ok then
+    begin
+      New := TLogItem.Create(Bottle); // \83R\83s\81[\83R\83\93\83X\83g\83\89\83N\83^
+      New.State := lsOpened;
+      Result.Add(New);
+    end;
+  end;
+end;
+
 { TBottleLogDragObject }
 
 function TBottleLogDragObject.GetDragImages: TDragImageList;
@@ -1644,4 +1835,65 @@ begin
     end;
 end;
 
+procedure TfrmLog.mnPopupCopyGhostClick(Sender: TObject);
+var
+  Log: TLogItem;
+  Clip: TClipBoard;
+begin
+  Log := SelectedBottleLog.Bottles[frmLog.lvwLog.Selected.Index];
+  if Log = nil then Exit;
+  Clip := ClipBoard();
+  Clip.SetTextBuf(PChar(Log.Ghost));
+end;
+
+function TfrmLog.CheckLog(Sender: TObject): integer;
+var
+  i, Res: integer;
+begin
+  // \91S\82Ä\82Ì\83\8a\83X\83g\81i\83^\83u\81j\83`\83F\83b\83N\82·\82é
+  // frmSender\82©\82ç\8fI\97¹\8e\9e\82É\8cÄ\82Ñ\8fo\82³\82ê\82é
+  Res := idNo;
+  for i := 0 to BottleLogList.Count-1 do
+  begin
+    Res := CheckLogSave(i);
+    if Res = idCancel then break;
+  end;
+  Result := Res;
+end;
+
+function TfrmLog.CheckLogSave(const Index: integer): integer;
+var
+  Res: integer;
+  Confirm: string;
+begin
+  // \83\8a\83X\83g\82ð\83`\83F\83b\83N\82µ\81A\95Û\91\8f\88\97\9d\82ð\8cÄ\82Ñ\8fo\82·
+  Res := idNo;
+  if (BottleLogList[Index] as TBottleLogList).LogModified then
+  begin
+    Confirm := Format('\83^\83u %s \82Ì\93à\97e\82Í\95Ï\8dX\82³\82ê\82Ä\82¢\82Ü\82·\81B'#13#10#13#10 +
+      '\95Û\91\82µ\82Ü\82·\82©\81H', [(FBottleLogList[Index] as TBottleLogList).Title]);
+    Res := MessageDlg(Confirm, mtConfirmation, mbYesNoCancel, 0);
+    if Res = idYes then
+      Res := DoSaveLogXML(FBottleLogList[Index] as TBottleLogList);
+  end;
+  Result := Res;
+end;
+
+procedure TfrmLog.mnTestActionClick(Sender: TObject);
+begin
+  Screen.Cursor := crHourGlass;
+  frmSender.LogInsertCue(true); // \83A\83N\83V\83\87\83\93\83e\83X\83g\81i\98A\91±\8dÄ\90\81j\97L\8cø
+  Screen.Cursor := crDefault;
+end;
+
+procedure TfrmLog.mnSelActionClick(Sender: TObject);
+begin
+  // \92P\91Ì\83A\83N\83V\83\87\83\93\82Ì\97L\96³\82ð\90Ý\92è
+  if mnSelAction.Checked then
+    mnSelAction.Checked := false
+  else
+    mnSelAction.Checked := true;
+  Pref.LogAction := mnSelAction.Checked;
+end;
+
 end.