6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus,
8 Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs;
11 TSaveLogType = (stLog, stLogWithChannels, stText, stXML);
13 TfrmLog = class(TForm)
15 tbtnClear: TToolButton;
18 StatusBar: TStatusBar;
19 tbtnSaveLog: TToolButton;
20 PopupMenuPreview: TPopupMenu;
22 tbtnVoteMessage: TToolButton;
23 PopupMenuListView: TPopupMenu;
24 mnPopUpVoteMessage: TMenuItem;
25 SaveDialog: TSaveDialog;
29 mnPopUpCopyScript: TMenuItem;
30 PopupMenuSaveLog: TPopupMenu;
32 mnSaveLogChannel: TMenuItem;
33 mnSaveLogScript: TMenuItem;
34 mnSaveLogXML: TMenuItem;
35 ToolButton1: TToolButton;
37 mnPopUpAgreeMessage: TMenuItem;
38 tbtnAgreeMessage: TToolButton;
39 ToolButton2: TToolButton;
40 tbtnPreviewStyle: TToolButton;
41 PopupMenuPreviewStyle: TPopupMenu;
42 mnPreviewStyleConversation: TMenuItem;
43 mnPreviewStyleScript: TMenuItem;
44 mnPreviewStyleScriptWithLineBreak: TMenuItem;
46 tabBottleLog: TTabControl;
48 tbtnDownloadLog: TToolButton;
49 PopupMenuTab: TPopupMenu;
50 mnCloseTab: TMenuItem;
51 tbtnFindBottle: TToolButton;
52 procedure tbtnClearClick(Sender: TObject);
53 procedure FormCreate(Sender: TObject);
54 procedure lvwLogChange(Sender: TObject; Item: TListItem;
56 procedure lvwLogDblClick(Sender: TObject);
57 procedure lvwLogKeyPress(Sender: TObject; var Key: Char);
58 procedure FormDestroy(Sender: TObject);
59 procedure lvwLogClick(Sender: TObject);
60 procedure mnSaveLogClick(Sender: TObject);
61 procedure lvwLogColumnClick(Sender: TObject; Column: TListColumn);
62 procedure mnPopUpCopyScriptClick(Sender: TObject);
63 procedure mnSaveLogChannelClick(Sender: TObject);
64 procedure mnSaveLogScriptClick(Sender: TObject);
65 procedure mnSaveLogXMLClick(Sender: TObject);
66 procedure lvwLogData(Sender: TObject; Item: TListItem);
67 procedure PopupMenuListViewPopup(Sender: TObject);
68 procedure lvwLogCustomDrawItem(Sender: TCustomListView;
69 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
70 procedure lvwLogCustomDrawSubItem(Sender: TCustomListView;
71 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
72 var DefaultDraw: Boolean);
73 procedure PopupMenuPreviewStylePopup(Sender: TObject);
74 procedure mnPreviewStyleClick(Sender: TObject);
75 procedure tbtnPreviewStyleClick(Sender: TObject);
76 procedure tabBottleLogChange(Sender: TObject);
77 procedure tabBottleLogChanging(Sender: TObject;
78 var AllowChange: Boolean);
79 procedure tabBottleLogContextPopup(Sender: TObject; MousePos: TPoint;
80 var Handled: Boolean);
81 procedure mnCloseTabClick(Sender: TObject);
82 procedure tbtnFindBottleClick(Sender: TObject);
85 FLastScript: String; //
\83X
\83N
\83\8a\83v
\83g
\8dÄ
\95`
\89æ
\97}
\90§
\97p
86 FBottleLogList: TObjectList;
87 procedure UpdateScript(const Script: String);
88 procedure UpdateScriptConversationColor(const Script: String);
89 procedure UpdateScriptConversationNoColor(const Script: String);
90 procedure UpdateScriptScript(const Script: String);
91 procedure DoSaveLog(SaveType: TSaveLogType; Ext: String;
93 procedure mnURLClick(Sender: TObject);
94 procedure ExtractURLs(Script: String; Result: TStrings);
95 function XmlEntity(S: String): String;
96 function GetCurrentBottleLog: TBottleLogList;
98 procedure CreateParams(var Params: TCreateParams); override;
101 function SelectedBottleLog: TBottleLogList;
102 property CurrentBottleLog: TBottleLogList read GetCurrentBottleLog;
103 property BottleLogList: TObjectList read FBottleLogList;
104 procedure AddCurrentScriptLog(const Script, Channel, MID, Ghost: String);
105 procedure AddCurrentSystemLog(const MessageString: String);
106 procedure VoteLog(const MID: String; const Vote: integer);
107 procedure AgreeLog(const MID: String; const Agree: integer);
108 procedure SetBottleStatusToPlaying(const MID: String);
109 procedure SetBottleStatusToOpened(const MID: String);
110 procedure LogLoaded(Sender: TObject);
111 procedure LogLoadFailure(Sender: TObject; const Message: String);
113 procedure UpdateWindow;
114 procedure SelAndFocusMessage(const MID: String);
121 function CurrentBottleLog: TBottleLogList;
135 uses MainForm, StrUtils;
139 function CurrentBottleLog: TBottleLogList;
141 Result := frmLog.CurrentBottleLog;
146 procedure TfrmLog.AddCurrentScriptLog(const Script, Channel, MID, Ghost: String);
149 CurrentBottleLog.AddScriptLog(Script, Channel, MID, Ghost);
150 if SelectedBottleLog <> CurrentBottleLog then Exit;
151 lvwLog.OnChange := nil; //
\83C
\83x
\83\93\83g
\94
\90¶(
\82¢
\82ë
\82¢
\82ë
\8dÄ
\95`
\89æ
\82ª
\8bN
\82«
\82é)
\82Ì
\97}
\90§
152 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
153 lvwLog.Items.Count := CurrentBottleLog.Count;
155 if Sel >= 0 then begin
156 lvwLog.Selected := lvwLog.Items[Sel + 1];
157 lvwLog.Selected.Focused := true;
159 if not lvwLog.Focused then
160 ListView_Scroll(lvwLog.Handle, 0, High(integer));
161 lvwLog.OnChange := lvwLogChange;
164 procedure TfrmLog.AddCurrentSystemLog(const MessageString: String);
167 CurrentBottleLog.AddSystemLog(MessageString);
168 if SelectedBottleLog <> CurrentBottleLog then Exit;
169 lvwLog.OnChange := nil;
170 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
171 lvwLog.Items.Count := CurrentBottleLog.Count;
173 if Sel >= 0 then begin
174 lvwLog.Selected := lvwLog.Items[Sel + 1];
175 lvwLog.Selected.Focused := true;
177 if not lvwLog.Focused then
178 ListView_Scroll(lvwLog.Handle, 0, High(integer));
179 lvwLog.OnChange := lvwLogChange;
184 procedure TfrmLog.tbtnClearClick(Sender: TObject);
186 if SelectedBottleLog = CurrentBottleLog then begin
187 CurrentBottleLog.Clear;
188 lvwLog.Items.Count := 0;
190 lvwLogChange(Self, nil, ctState);
192 FBottleLogList.Delete(tabBottleLog.TabIndex);
193 tabBottleLog.TabIndex := 0;
196 lvwLogChange(Self, nil, ctState);
200 procedure TfrmLog.FormCreate(Sender: TObject);
202 FBottleLogList := TObjectList.Create;
203 FBottleLogList.Add(TBottleLogList.Create('
\83J
\83\8c\83\93\83g')); // CurrentBottleLog
205 SsParser.TagPattern.Assign(frmSender.SsParser.TagPattern);
206 SsParser.MetaPattern.Assign(frmSender.SsParser.MetaPattern);
208 with Pref.LogWindowPosition do begin
211 Self.Width := Right - Left + 1;
212 Self.Height := Bottom - Top + 1;
214 lvwLog.DoubleBuffered := true;
215 edtScript.Height := Pref.LogWindowDividerPos;
216 UpdateWindow; // Reset window color and enabled status of some buttons
219 procedure TfrmLog.FormDestroy(Sender: TObject);
221 with Pref.LogWindowPosition do begin
224 Right := Self.Left + Self.Width - 1;
225 Bottom := Self.Top + Self.Height - 1;
227 Pref.LogWindowDividerPos := edtScript.Height;
229 FreeAndNil(FBottleLogList);
232 procedure TfrmLog.lvwLogChange(Sender: TObject; Item: TListItem;
233 Change: TItemChange);
237 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
238 if Change = ctState then begin
240 if lvwLog.Selected <> nil then begin
241 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
242 if (Log.LogType = ltBottle) and not frmSender.Connecting then begin
243 Script := Log.Script;
244 frmSender.actVoteMessage.Enabled := true;
245 frmSender.actAgreeMessage.Enabled := true;
246 mnPopUpCopyScript.Enabled := true;
247 UpdateScript(Script);
249 frmSender.actVoteMessage.Enabled := false;
250 frmSender.actAgreeMessage.Enabled := false;
251 mnPopUpCopyScript.Enabled := false;
252 UpdateScript(''); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\82ð
\83N
\83\8a\83A
255 frmSender.actVoteMessage.Enabled := false;
256 frmSender.actAgreeMessage.Enabled := false;
257 mnPopUpCopyScript.Enabled := false;
258 UpdateScript(Script); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\83N
\83\8a\83A
261 tbtnSaveLog.Enabled := lvwLog.Items.Count > 0;
264 procedure TfrmLog.lvwLogDblClick(Sender: TObject);
266 Opt: TScriptTransOptions;
267 SOpt: TSstpSendOptions;
271 if lvwLog.Selected = nil then Exit;
272 //Log := TLogItem(lvwLog.Selected.Data);
273 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
274 if Log = nil then Exit;
275 if Log.LogType <> ltBottle then Exit;
276 Script := Log.Script;
277 Opt := [toConvertURL, toWaitScriptEnd];
278 if Pref.NoTransUrl then Opt := Opt + [toNoChoice];
279 if Pref.IgnoreFrequentYenS then Opt := Opt + [toIgnoreFrequentYenS];
280 if Pref.FixMessySurface then Opt := Opt + [toFixMessySurface];
281 frmSender.DoTrans(Script, Opt);
283 Ghost := frmSender.GetChannelPrefs(Log.Channel).TargetGhost;
284 if Ghost = '' then //
\83`
\83\83\83\93\83l
\83\8b\8ew
\92è
\83S
\81[
\83X
\83g
285 if frmSender.ChannelList.Channel[Log.Channel] <> nil then
286 Ghost := frmSender.ChannelList.Channel[Log.Channel].Ghost;
287 //
\96Ú
\95W
\83S
\81[
\83X
\83g
\8c\88\92è
288 if Log.Ghost <> '' then Ghost := Log.Ghost;
289 if frmSender.GetChannelPrefs(Log.Channel).IgnoreIfGhost then
290 Ghost := frmSender.GetChannelPrefs(Log.Channel).TargetGhost;
291 //
\83^
\81[
\83Q
\83b
\83g
\83S
\81[
\83X
\83g
\8am
\92è
292 Ghost := frmSender.SetHWndToFavoriteGhost(Ghost);
293 frmSender.DirectSstp.SstpSender := 'SSTP Bottle -
\81y
\83\8d\83O
\8dÄ
\90¶
\81z';
294 if Pref.NoTranslate then SOpt := [soNoTranslate] else SOpt := [];
295 frmSender.DirectSstp.SstpSEND(Script, SOpt, frmSender.GhostNameToSetName(Ghost));
298 procedure TfrmLog.UpdateScriptConversationColor(const Script: String);
301 UnyuTalking, Talked: boolean;
304 frmSender.DoTrans(scr, [toConvertURL]);
305 SsParser.LeaveEscape := false;
306 SsParser.InputString := scr;
307 SsParser.LeaveEscape := true;
308 UnyuTalking := false;
309 Talked := false; //'\h\u\h\u'
\82Ì
\82æ
\82¤
\82È
\83X
\83N
\83\8a\83v
\83g
\82Å
\8bó
\82«
\8ds
\82ð
\8dì
\82ç
\82È
\82¢
\82½
\82ß
\82Ì
\91[
\92u
310 edtScript.Text := '';
311 edtScript.Color := Pref.BgColor;
312 for i := 0 to SsParser.Count-1 do begin
313 if (SsParser[i] = '\u') and not UnyuTalking then begin
316 edtScript.SelText := #13#10;
320 if (SsParser[i] = '\h') and UnyuTalking then begin
321 UnyuTalking := false;
323 edtScript.SelText := #13#10;
327 if SsParser.MarkUpType[i] = mtStr then begin
329 edtScript.SelAttributes.Color := Pref.TalkColorU
331 edtScript.SelAttributes.Color := Pref.TalkColorH;
332 edtScript.SelText := SsParser[i];
335 if SsParser.MarkUpType[i] = mtMeta then begin
336 edtScript.SelAttributes.Color := Pref.MetaWordColor;
337 edtScript.SelText := SsParser[i];
343 procedure TfrmLog.UpdateScriptConversationNoColor(const Script: String);
346 UnyuTalking, Talked, LastUnyuTalked: boolean;
349 frmSender.DoTrans(Scr, [toConvertURL]);
350 SsParser.LeaveEscape := false;
351 SsParser.InputString := Scr;
352 SsParser.LeaveEscape := true;
353 edtScript.Text := '';
354 edtScript.Color := clWindow;
355 edtScript.DefAttributes.Color := clWindowText;
356 edtScript.SelAttributes.Color := clWindowText;
358 UnyuTalking := false;
359 LastUnyuTalked := false;
360 for i := 0 to SsParser.Count-1 do begin
361 if (SsParser[i] = '\u') and not UnyuTalking then begin
364 if (SsParser[i] = '\h') and UnyuTalking then begin
365 UnyuTalking := false;
367 if SsParser.MarkUpType[i] in [mtStr, mtMeta] then begin
368 if not Talked then begin
369 if UnyuTalking then Scr := '
\82¤:' else Scr := '
\82³:';
371 if Talked and (UnyuTalking <> LastUnyuTalked) then begin
373 if UnyuTalking then Scr := Scr + '
\82¤:' else Scr := Scr + '
\82³:';
375 Scr := Scr + SsParser[i];
377 LastUnyuTalked := UnyuTalking;
380 edtScript.Text := Scr;
383 procedure TfrmLog.lvwLogKeyPress(Sender: TObject; var Key: Char);
385 if Key = #13 then lvwLogDblClick(Sender);
388 procedure TfrmLog.CreateParams(var Params: TCreateParams);
391 Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
394 procedure TfrmLog.lvwLogClick(Sender: TObject);
396 //
\89E
\83N
\83\8a\83b
\83N
\82Å
\83\81\83j
\83\85\81[
\8fo
\82·
\82Æ
\82«
\82É
\94
\90¶
\82·
\82é
\95s
\8bï
\8d\87\91Î
\8dô
398 Selected := Selected;
401 procedure TfrmLog.mnSaveLogClick(Sender: TObject);
403 DoSaveLog(stLog, 'log', 1);
406 procedure TfrmLog.lvwLogColumnClick(Sender: TObject; Column: TListColumn);
407 var SortType: TBottleLogSortType;
411 if lvwLog.Selected <> nil then
412 SelectedMID := SelectedBottleLog.Bottles[lvwLog.Selected.Index].MID;
414 SortColumn := Column.Index;
416 -1: SortType := stLogTime;
417 subChannel: SortType := stChannel;
418 subVotes: SortType := stVote;
419 subAgrees: SortType := stAgree;
420 subScript: SortType := stScript;
421 else SortType := stLogTime;
424 SelectedBottleLog.SortBottles(SortType);
426 SelAndFocusMessage(SelectedMID);
430 procedure TfrmLog.mnPopUpCopyScriptClick(Sender: TObject);
435 Log := SelectedBottleLog.Bottles[frmLog.lvwLog.Selected.Index];
436 if Log = nil then Exit;
438 Clip.SetTextBuf(PChar(Log.Script));
441 procedure TfrmLog.SetBottleStatusToOpened(const MID: String);
443 if CurrentBottleLog.Bottle(MID) <> nil then begin
444 CurrentBottleLog.Bottle(MID).State := lsOpened;
445 lvwLog.OnChange := nil;
447 lvwLog.OnChange := lvwLogChange;
451 procedure TfrmLog.SetBottleStatusToPlaying(const MID: String);
453 if CurrentBottleLog.Bottle(MID) <> nil then begin
454 CurrentBottleLog.Bottle(MID).State := lsPlaying;
455 lvwLog.OnChange := nil;
457 lvwLog.OnChange := lvwLogChange;
461 procedure TfrmLog.DoSaveLog(SaveType: TSaveLogType; Ext: String; Filter: integer);
467 DayStr: array[1..7] of String = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
469 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
470 SaveDialog.DefaultExt := Ext;
471 SaveDialog.FilterIndex := Filter;
472 if SaveDialog.Execute then begin
475 Log := TStringList.Create;
477 stLog, stLogWithChannels: begin
478 for i := 0 to SelectedBottleLog.Count -1 do begin
479 LogItem := SelectedBottleLog.Bottles[i];
480 if LogItem = nil then Continue;
481 if LogItem.LogType <> ltBottle then Continue;
482 Date := FormatDateTime('yyyy/mm/dd hh:nn:ss ', LogItem.LogTime);
483 Date := Date + '(' + DayStr[DayOfWeek(LogItem.LogTime)] + ')';
484 if SaveType = stLogWithChannels then
485 Date := Date + ',' + LogItem.Channel +',SEND,' + LogItem.Script
487 Date := Date + ',0.0.0.0,SEND,' + LogItem.Script;
492 for i := 0 to SelectedBottleLog.Count -1 do begin
493 LogItem := SelectedBottleLog.Bottles[i];
494 if LogItem = nil then Continue;
495 if LogItem.LogType <> ltBottle then Continue;
496 Log.Add(LogItem.Script);
500 Log.Add('<?xml version=''1.0'' encoding=''Shift_JIS''?>');
501 Log.Add('<bottlelog saved=''' + FormatDateTime('yyyy/mm/dd hh:nn:ss', Now) + '''>');
502 for i := 0 to SelectedBottleLog.Count -1 do begin
503 LogItem := SelectedBottleLog.Bottles[i];
504 if LogItem = nil then Continue;
505 if LogItem.LogType <> ltBottle then Continue;
506 Date := FormatDateTime('yyyy/mm/dd hh:nn:ss', LogItem.LogTime);
507 Log.Add(Format('<message mid=''%s''>', [LogItem.MID]));
508 Log.Add('<date>' + Date + '</date>');
509 Log.Add('<channel>' + XmlEntity(LogItem.Channel) + '</channel>');
511 Log.Add('<script>' + XmlEntity(LogItem.Script) + '</script>');
512 Log.Add('<votes>' + IntToStr(LogItem.Votes) + '</votes>');
513 Log.Add('<agrees>' + IntToStr(LogItem.Agrees) + '</agrees>');
515 if LogItem.Ghost = '' then
518 Log.Add(Format('<ghost>%s</ghost>', [XmlEntity(LogItem.Ghost)]));
520 Log.Add('</message>');
522 Log.Add('</bottlelog>');
525 Log.SaveToFile(SaveDialog.FileName);
532 procedure TfrmLog.mnSaveLogChannelClick(Sender: TObject);
534 DoSaveLog(stLogWithChannels, 'log', 1);
537 procedure TfrmLog.mnSaveLogScriptClick(Sender: TObject);
539 DoSaveLog(stText, 'txt', 2);
542 procedure TfrmLog.mnSaveLogXMLClick(Sender: TObject);
544 DoSaveLog(stXML, 'xml', 3);
547 procedure TfrmLog.lvwLogData(Sender: TObject; Item: TListItem);
551 if Item = nil then Exit;
553 Log := SelectedBottleLog.Bottles[i];
555 Caption := FormatDateTime('yy/mm/dd hh:nn:ss', Log.LogTime);
557 if Log.Ghost <> '' then
558 SubItems.Add(Log.Channel + '/' + Log.Ghost)
560 SubItems.Add(Log.Channel);
561 if Log.LogType = ltBottle then begin
562 SubItems.Add(IntToStr(Log.Votes));
563 SubItems.Add(IntToStr(Log.Agrees));
565 //
\83V
\83X
\83e
\83\80\83\8d\83O
\82È
\82Ç
\82Í
\93\8a\95[
\81E
\93¯
\88Ó
\82ð
\95\
\8e¦
\82µ
\82È
\82¢
569 SubItems.Add(Log.Script);
571 if Log.LogType = ltBottle then begin
573 lsUnopened: ImageIndex := IconBottle;
574 lsPlaying: ImageIndex := IconPlaying;
575 lsOpened: ImageIndex := IconOpened;
578 ImageIndex := IconSystemLog;
582 procedure TfrmLog.UpdateWindow;
584 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
585 if Pref.ColorScript then begin
586 if lvwLog.Color <> Pref.BgColor then lvwLog.Color := Pref.BgColor;
587 if lvwLog.Font.Color <> Pref.TalkColorH then lvwLog.Font.Color := Pref.TalkColorH;
589 if lvwLog.Color <> clWindow then lvwLog.Color := clWindow;
590 if lvwLog.Font.Color <> clWindowText then lvwLog.Font.Color := clWindowText;
592 lvwLog.Items.Count := SelectedBottleLog.Count;
594 //lvwLogChange(Self, lvwLog.Selected, ctState);
597 procedure TfrmLog.PopupMenuListViewPopup(Sender: TObject);
603 for i := mnJumpURL.Count-1 downto 0 do begin
604 mnJumpURL.Items[i].Free;
606 mnJumpURL.Enabled := false;
607 if lvwLog.Selected = nil then Exit;
608 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
609 if Log = nil then Exit;
612 Urls := TStringList.Create;
613 ExtractURLs(Log.Script, Urls);
614 for i := 0 to Urls.Count-1 do begin
615 Child := TMenuItem.Create(Self);
617 Caption := Format('(&%d) %s', [i+1, Urls[i]]);
618 OnClick := mnURLClick;
619 AutoHotkeys := maManual;
620 mnJumpURL.Add(Child);
623 mnJumpURL.Enabled := Urls.Count > 0;
629 procedure TfrmLog.mnURLClick(Sender: TObject);
632 URL := (Sender as TMenuItem).Caption;
633 RegExp.Subst('s/^\(&?\d\) //', URL);
634 ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOW);
637 procedure TfrmLog.ExtractURLs(Script: String; Result: TStrings);
638 var i, u, j: integer;
642 SsParser.LeaveEscape := false;
643 SsParser.InputString := Script;
644 SsParser.LeaveEscape := true;
645 for i := 0 to SsParser.Count-1 do begin
646 if (SsParser.Match(SsParser[i], '\URL%b') > 0) then begin
647 for u := 7 downto 1 do begin
648 if (SsParser.Match(SsParser[i],
649 '\URL%b'+StringReplace(StringOfChar('-', u*2),
650 '-', '%b', [rfReplaceAll]))) > 0 then begin
651 for j := 1 to u do begin
652 s := SsParser.GetParam(SsParser[i], j*2);
653 if Pos('http://', s) > 0 then Result.Add(s);
658 if SsParser.Match(SsParser[i], '\URL%b%b') = 0 then begin //
\8aÈ
\88Õ
\94ÅURL
\95Ï
\8a·
659 //
\8aÈ
\88Õ
\8c`
\8e®\URL
\83^
\83O
\95Ï
\8a·
660 s := SsParser.GetParam(SsParser[i], 1);
661 if Pos('http://', s) > 0 then Result.Add(s);
667 procedure TfrmLog.SelAndFocusMessage(const MID: String);
671 for i := 0 to SelectedBottleLog.Count-1 do begin
672 Log := SelectedBottleLog.Items[i] as TLogItem;
673 if Log.MID = MID then begin
674 lvwLog.Items[i].Selected := true;
675 lvwLog.Items[i].Focused := true;
680 procedure TfrmLog.lvwLogCustomDrawItem(Sender: TCustomListView;
681 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
686 procedure TfrmLog.lvwLogCustomDrawSubItem(Sender: TCustomListView;
687 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
688 var DefaultDraw: Boolean);
694 Mark: TSsMarkUpType;}
697 {if (SubItem <> SubScript+1) or (not Pref.ColorScript) then Exit; // DefaultDraw = true
698 // Custom Script Coloring
699 DefaultDraw := false;
700 SavedDC := SaveDC(lvwLog.Canvas.Handle);
702 ListView_GetSubItemRect(lvwLog.Handle, Item.Index, SubScript+1, LVIR_BOUNDS, @DestRect);
704 lvwLog.Canvas.Brush.Style := bsSolid;
705 if cdsSelected in State then begin
706 lvwLog.Canvas.Brush.Color := clHighlight
708 lvwLog.Canvas.Brush.Color := Pref.BgColor;
710 lvwLog.Canvas.FillRect(DestRect);
711 lvwLog.Canvas.Brush.Style := bsClear;
713 Script := Item.SubItems[SubScript];
714 // DrawTextEx(lvwLog.Canvas.Handle, PChar(Script), -1, DestRect, DT_END_ELLIPSIS, nil);
715 SsParser.InputString := Script;
717 for i := 0 to SsParser.Count - 1 do begin
718 Mark := SsParser.MarkUpType[i];
720 mtMeta: lvwLog.Canvas.Font.Color := Pref.MetaWordColor;
721 mtTag: lvwLog.Canvas.Font.Color := Pref.MarkUpColor;
722 mtTagErr: lvwLog.Canvas.Font.Color := Pref.MarkErrorColor;
724 lvwLog.Canvas.Font.Color := Pref.TalkColorH;
727 w := lvwLog.Canvas.TextWidth(SsParser[i]);
728 lvwLog.Canvas.TextRect(DestRect, DestRect.Left + x, DestRect.Top + 2, SsParser[i]);
730 if DestRect.Right - DestRect.Left < x then Break;
733 RestoreDC(lvwLog.Canvas.Handle, SavedDC);
737 procedure TfrmLog.UpdateScript(const Script: String);
739 if Script <> FLastScript then begin
740 if Pref.LogWindowPreviewStyle = psConversation then begin
741 if Pref.ColorScript then begin
742 UpdateScriptConversationColor(Script);
744 UpdateScriptConversationNoColor(Script);
747 UpdateScriptScript(Script);
749 SendMessage(edtScript.Handle, EM_LINESCROLL, Low(integer), Low(integer)); //
\83X
\83N
\83\8d\81[
\83\8b\96ß
\82µ
750 FLastScript := Script;
754 procedure TfrmLog.PopupMenuPreviewStylePopup(Sender: TObject);
757 with PopupMenuPreviewStyle do
758 for i := 0 to Items.Count-1 do
759 Items[i].Checked := Items[i].Tag = Ord(Pref.LogWindowPreviewStyle)
762 procedure TfrmLog.mnPreviewStyleClick(Sender: TObject);
765 with PopupMenuPreviewStyle do
766 for i := 0 to Items.Count-1 do
767 Items[i].Checked := (Sender as TMenuItem).Tag = Items[i].Tag;
768 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle((Sender as TMenuItem).Tag);
770 lvwLogChange(self, lvwLog.Selected, ctState);
773 procedure TfrmLog.UpdateScriptScript(const Script: String);
775 UnyuTalking: boolean;
778 if Pref.ColorScript then begin
779 edtScript.Color := Pref.BgColor;
781 edtScript.Color := clWindow;
782 edtScript.DefAttributes.Color := clWindowText;
783 edtScript.SelAttributes.Color := clWindowText;
785 SsParser.LeaveEscape := true;
786 SsParser.InputString := Script;
787 edtScript.Text := '';
788 edtScript.SelAttributes.Color := clWindowText;
789 UnyuTalking := false;
790 for i := 0 to SsParser.Count-1 do begin
791 if Pref.ColorScript then begin
792 case SsParser.MarkUpType[i] of
795 edtScript.SelAttributes.Color := Pref.TalkColorU
797 edtScript.SelAttributes.Color := Pref.TalkColorH;
800 edtScript.SelAttributes.Color := Pref.MarkUpColor;
801 if SsParser[i] = '\h' then
803 else if SsParser[i] = '\u' then
806 mtMeta: edtScript.SelAttributes.Color := Pref.MetaWordColor;
807 mtTagErr: edtScript.SelAttributes.Color := Pref.MarkErrorColor;
810 edtScript.SelText := SsParser[i];
811 if (SsParser[i] = '\n') and (Pref.LogWindowPreviewStyle = psScriptWithLineBreak) then
812 edtScript.SelText := #13#10;
816 procedure TfrmLog.tbtnPreviewStyleClick(Sender: TObject);
819 sel := Ord(Pref.LogWindowPreviewStyle);
821 if sel > Ord(High(TLogWindowPreviewStyle)) then sel := 0;
822 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle(sel);
824 lvwLogChange(self, lvwLog.Selected, ctState);
827 function TfrmLog.XmlEntity(S: String): String;
829 S := StringReplace(S, '&', '&', [rfReplaceAll]);
830 S := StringReplace(S, '<', '<', [rfReplaceAll]);
831 S := StringReplace(S, '>', '>', [rfReplaceAll]);
835 function TfrmLog.SelectedBottleLog: TBottleLogList;
837 Result := FBottleLogList.Items[tabBottleLog.TabIndex] as TBottleLogList;
840 function TfrmLog.GetCurrentBottleLog: TBottleLogList;
842 Result := FBottleLogList.Items[0] as TBottleLogList;
845 procedure TfrmLog.tabBottleLogChange(Sender: TObject);
848 if SelectedBottleLog.SelectedIndex >= 0 then begin
849 lvwLog.Items[SelectedBottleLog.SelectedIndex].Selected := true;
850 if lvwLog.Focused then lvwLog.Selected.Focused := true;
852 lvwLogChange(Self, nil, ctState);
855 procedure TfrmLog.LogLoaded(Sender: TObject);
857 if SelectedBottleLog = Sender then begin
862 procedure TfrmLog.UpdateTab;
866 cur := SelectedBottleLog;
867 tabBottleLog.Tabs.Clear;
868 for i := 0 to FBottleLogList.Count - 1 do begin
869 tabBottleLog.Tabs.Add((FBottleLogList[i] as TBottleLogList).Title);
871 tabBottleLog.TabIndex := FBottleLogList.IndexOf(cur);
874 procedure TfrmLog.LogLoadFailure(Sender: TObject; const Message: String);
877 ShowMessage(Message);
878 (Sender as TBottleLogList).AddSystemLog(Message);
882 procedure TfrmLog.AgreeLog(const MID: String; const Agree: integer);
887 for i := 0 to FBottleLogList.Count - 1 do begin
888 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
889 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Agrees := Agree;
893 if flag then lvwLog.Invalidate;
896 procedure TfrmLog.VoteLog(const MID: String; const Vote: integer);
901 for i := 0 to FBottleLogList.Count - 1 do begin
902 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
903 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Votes := Vote;
907 if flag then lvwLog.Invalidate;
910 procedure TfrmLog.tabBottleLogChanging(Sender: TObject;
911 var AllowChange: Boolean);
913 if lvwLog.Selected <> nil then
914 SelectedBottleLog.SelectedIndex := lvwLog.Selected.Index
916 SelectedBottleLog.SelectedIndex := -1;
919 procedure TfrmLog.tabBottleLogContextPopup(Sender: TObject;
920 MousePos: TPoint; var Handled: Boolean);
922 with tabBottleLog do begin
923 Tag := IndexOfTabAt(MousePos.X, MousePos.Y);
924 if Tag < 0 then Handled := true;
925 mnCloseTab.Enabled := Tag > 0;
929 procedure TfrmLog.mnCloseTabClick(Sender: TObject);
931 if tabBottleLog.Tag = 0 then Exit;
932 FBottleLogList.Delete(tabBottleLog.Tag);
933 tabBottleLog.TabIndex := 0;
936 lvwLogChange(Self, nil, ctState);
939 procedure TfrmLog.tbtnFindBottleClick(Sender: TObject);
941 ResultLog: TBottleLogList;
942 Item1, Item2: TLogItem;
945 if SelectedBottleLog.Count = 0 then begin
946 ShowMessage('
\8c\9f\8dõ
\91Î
\8fÛ
\82ª
\8bó
\82Å
\82·
\81B');
951 ResultLog := TBottleLogList.Create('
\8c\9f\8dõ
\8c\8b\89Ê');
952 if InputQuery('
\83X
\83N
\83\8a\83v
\83g
\96{
\95¶
\82ð
\8c\9f\8dõ', '
\8c\9f\8dõ
\95¶
\8e\9a\97ñ', Query) then begin
953 if Query = '' then Exit;
954 for i := 0 to SelectedBottleLog.Count-1 do begin
955 Item1 := SelectedBottleLog.Items[i] as TLogItem;
956 if AnsiContainsText(Item1.Script, Query) and (Item1.LogType = ltBottle) then begin
957 matched := matched + 1;
958 Item2 := TLogItem.Create(ltBottle, Item1.MID, Item1.Channel,
959 Item1.Script, Item1.Ghost, Item1.LogTime);
960 Item2.State := lsOpened;
961 Item2.Votes := Item1.Votes;
962 Item2.Agrees := Item1.Agrees;
963 ResultLog.Add(Item2);
968 ResultLog.AddSystemLog('
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
969 BottleLogList.Add(ResultLog);
970 tabBottleLog.TabIndex := BottleLogList.Count-1;
973 lvwLogChange(Self, nil, ctState);