6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus,
8 Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, xmldom, XMLIntf,
12 TSaveLogType = (stLog, stLogWithChannels, stText, stXML);
14 TfrmLog = class(TForm)
16 tbtnClear: TToolButton;
19 StatusBar: TStatusBar;
20 tbtnSaveLog: TToolButton;
21 PopupMenuPreview: TPopupMenu;
23 tbtnVoteMessage: TToolButton;
24 PopupMenuListView: TPopupMenu;
25 mnPopUpVoteMessage: TMenuItem;
26 SaveDialog: TSaveDialog;
30 mnPopUpCopyScript: TMenuItem;
31 PopupMenuSaveLog: TPopupMenu;
33 mnSaveLogChannel: TMenuItem;
34 mnSaveLogScript: TMenuItem;
35 mnSaveLogXML: TMenuItem;
36 ToolButton1: TToolButton;
38 mnPopUpAgreeMessage: TMenuItem;
39 tbtnAgreeMessage: TToolButton;
40 ToolButton2: TToolButton;
41 tbtnPreviewStyle: TToolButton;
42 PopupMenuPreviewStyle: TPopupMenu;
43 mnPreviewStyleConversation: TMenuItem;
44 mnPreviewStyleScript: TMenuItem;
45 mnPreviewStyleScriptWithLineBreak: TMenuItem;
47 tabBottleLog: TTabControl;
49 tbtnDownloadLog: TToolButton;
50 PopupMenuTab: TPopupMenu;
51 mnCloseTab: TMenuItem;
52 tbtnFindBottle: TToolButton;
53 XMLDocument: TXMLDocument;
54 tbtnOpenLog: TToolButton;
55 OpenDialog: TOpenDialog;
56 procedure tbtnClearClick(Sender: TObject);
57 procedure FormCreate(Sender: TObject);
58 procedure lvwLogChange(Sender: TObject; Item: TListItem;
60 procedure lvwLogDblClick(Sender: TObject);
61 procedure lvwLogKeyPress(Sender: TObject; var Key: Char);
62 procedure FormDestroy(Sender: TObject);
63 procedure lvwLogClick(Sender: TObject);
64 procedure mnSaveLogClick(Sender: TObject);
65 procedure lvwLogColumnClick(Sender: TObject; Column: TListColumn);
66 procedure mnPopUpCopyScriptClick(Sender: TObject);
67 procedure mnSaveLogChannelClick(Sender: TObject);
68 procedure mnSaveLogScriptClick(Sender: TObject);
69 procedure mnSaveLogXMLClick(Sender: TObject);
70 procedure lvwLogData(Sender: TObject; Item: TListItem);
71 procedure PopupMenuListViewPopup(Sender: TObject);
72 procedure lvwLogCustomDrawItem(Sender: TCustomListView;
73 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
74 procedure lvwLogCustomDrawSubItem(Sender: TCustomListView;
75 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
76 var DefaultDraw: Boolean);
77 procedure PopupMenuPreviewStylePopup(Sender: TObject);
78 procedure mnPreviewStyleClick(Sender: TObject);
79 procedure tbtnPreviewStyleClick(Sender: TObject);
80 procedure tabBottleLogChange(Sender: TObject);
81 procedure tabBottleLogChanging(Sender: TObject;
82 var AllowChange: Boolean);
83 procedure tabBottleLogContextPopup(Sender: TObject; MousePos: TPoint;
84 var Handled: Boolean);
85 procedure mnCloseTabClick(Sender: TObject);
86 procedure tbtnFindBottleClick(Sender: TObject);
87 procedure tbtnOpenLogClick(Sender: TObject);
90 FLastScript: String; //
\83X
\83N
\83\8a\83v
\83g
\8dÄ
\95`
\89æ
\97}
\90§
\97p
91 FBottleLogList: TObjectList;
92 procedure UpdateScript(const Script: String);
93 procedure UpdateScriptConversationColor(const Script: String);
94 procedure UpdateScriptConversationNoColor(const Script: String);
95 procedure UpdateScriptScript(const Script: String);
96 procedure mnURLClick(Sender: TObject);
97 procedure ExtractURLs(Script: String; Result: TStrings);
98 function GetCurrentBottleLog: TBottleLogList;
99 function GetDefaultFileName(const Name: String; const Ext: String): String;
101 procedure CreateParams(var Params: TCreateParams); override;
104 function SelectedBottleLog: TBottleLogList;
105 property CurrentBottleLog: TBottleLogList read GetCurrentBottleLog;
106 property BottleLogList: TObjectList read FBottleLogList;
107 procedure AddCurrentScriptLog(const Script, Channel, MID, Ghost: String);
108 procedure AddCurrentSystemLog(const MessageString: String);
109 procedure VoteLog(const MID: String; const Vote: integer);
110 procedure AgreeLog(const MID: String; const Agree: integer);
111 procedure SetBottleStatusToPlaying(const MID: String);
112 procedure SetBottleStatusToOpened(const MID: String);
113 procedure LogLoaded(Sender: TObject);
114 procedure LogLoadFailure(Sender: TObject; const Message: String);
116 procedure UpdateWindow;
117 procedure SelAndFocusMessage(const MID: String);
124 function CurrentBottleLog: TBottleLogList;
138 uses MainForm, StrUtils;
142 function CurrentBottleLog: TBottleLogList;
144 Result := frmLog.CurrentBottleLog;
149 procedure TfrmLog.AddCurrentScriptLog(const Script, Channel, MID, Ghost: String);
152 CurrentBottleLog.AddScriptLog(Script, Channel, MID, Ghost);
153 if SelectedBottleLog <> CurrentBottleLog then Exit;
154 lvwLog.OnChange := nil; //
\83C
\83x
\83\93\83g
\94
\90¶(
\82¢
\82ë
\82¢
\82ë
\8dÄ
\95`
\89æ
\82ª
\8bN
\82«
\82é)
\82Ì
\97}
\90§
155 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
156 lvwLog.Items.Count := CurrentBottleLog.Count;
158 if Sel >= 0 then begin
159 lvwLog.Selected := lvwLog.Items[Sel + 1];
160 lvwLog.Selected.Focused := true;
162 if not lvwLog.Focused then
163 ListView_Scroll(lvwLog.Handle, 0, High(integer));
164 lvwLog.OnChange := lvwLogChange;
167 procedure TfrmLog.AddCurrentSystemLog(const MessageString: String);
170 CurrentBottleLog.AddSystemLog(MessageString);
171 if SelectedBottleLog <> CurrentBottleLog then Exit;
172 lvwLog.OnChange := nil;
173 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
174 lvwLog.Items.Count := CurrentBottleLog.Count;
176 if Sel >= 0 then begin
177 lvwLog.Selected := lvwLog.Items[Sel + 1];
178 lvwLog.Selected.Focused := true;
180 if not lvwLog.Focused then
181 ListView_Scroll(lvwLog.Handle, 0, High(integer));
182 lvwLog.OnChange := lvwLogChange;
187 procedure TfrmLog.tbtnClearClick(Sender: TObject);
189 if SelectedBottleLog = CurrentBottleLog then begin
190 CurrentBottleLog.Clear;
191 lvwLog.Items.Count := 0;
193 lvwLogChange(Self, nil, ctState);
195 FBottleLogList.Delete(tabBottleLog.TabIndex);
196 tabBottleLog.TabIndex := 0;
199 lvwLogChange(Self, nil, ctState);
203 procedure TfrmLog.FormCreate(Sender: TObject);
205 FBottleLogList := TObjectList.Create;
206 FBottleLogList.Add(TBottleLogList.Create('
\83J
\83\8c\83\93\83g')); // CurrentBottleLog
208 SsParser.TagPattern.Assign(frmSender.SsParser.TagPattern);
209 SsParser.MetaPattern.Assign(frmSender.SsParser.MetaPattern);
211 with Pref.LogWindowPosition do begin
214 Self.Width := Right - Left + 1;
215 Self.Height := Bottom - Top + 1;
217 lvwLog.DoubleBuffered := true;
218 edtScript.Height := Pref.LogWindowDividerPos;
219 UpdateWindow; // Reset window color and enabled status of some buttons
222 procedure TfrmLog.FormDestroy(Sender: TObject);
224 with Pref.LogWindowPosition do begin
227 Right := Self.Left + Self.Width - 1;
228 Bottom := Self.Top + Self.Height - 1;
230 Pref.LogWindowDividerPos := edtScript.Height;
232 FreeAndNil(FBottleLogList);
235 procedure TfrmLog.lvwLogChange(Sender: TObject; Item: TListItem;
236 Change: TItemChange);
240 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
241 if Change = ctState then begin
243 if lvwLog.Selected <> nil then begin
244 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
245 if (Log.LogType = ltBottle) and not frmSender.Connecting then begin
246 Script := Log.Script;
247 frmSender.actVoteMessage.Enabled := true;
248 frmSender.actAgreeMessage.Enabled := true;
249 mnPopUpCopyScript.Enabled := true;
250 UpdateScript(Script);
252 frmSender.actVoteMessage.Enabled := false;
253 frmSender.actAgreeMessage.Enabled := false;
254 mnPopUpCopyScript.Enabled := false;
255 UpdateScript(''); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\82ð
\83N
\83\8a\83A
258 frmSender.actVoteMessage.Enabled := false;
259 frmSender.actAgreeMessage.Enabled := false;
260 mnPopUpCopyScript.Enabled := false;
261 UpdateScript(Script); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\83N
\83\8a\83A
264 tbtnSaveLog.Enabled := lvwLog.Items.Count > 0;
267 procedure TfrmLog.lvwLogDblClick(Sender: TObject);
269 Opt: TScriptTransOptions;
270 SOpt: TSstpSendOptions;
274 if lvwLog.Selected = nil then Exit;
275 //Log := TLogItem(lvwLog.Selected.Data);
276 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
277 if Log = nil then Exit;
278 if Log.LogType <> ltBottle then Exit;
279 Script := Log.Script;
280 Opt := [toConvertURL, toWaitScriptEnd];
281 if Pref.NoTransUrl then Opt := Opt + [toNoChoice];
282 if Pref.IgnoreFrequentYenS then Opt := Opt + [toIgnoreFrequentYenS];
283 if Pref.FixMessySurface then Opt := Opt + [toFixMessySurface];
284 frmSender.DoTrans(Script, Opt);
286 Ghost := frmSender.GetChannelPrefs(Log.Channel).TargetGhost;
287 if Ghost = '' then //
\83`
\83\83\83\93\83l
\83\8b\8ew
\92è
\83S
\81[
\83X
\83g
288 if frmSender.ChannelList.Channel[Log.Channel] <> nil then
289 Ghost := frmSender.ChannelList.Channel[Log.Channel].Ghost;
290 //
\96Ú
\95W
\83S
\81[
\83X
\83g
\8c\88\92è
291 if Log.Ghost <> '' then Ghost := Log.Ghost;
292 if frmSender.GetChannelPrefs(Log.Channel).IgnoreIfGhost then
293 Ghost := frmSender.GetChannelPrefs(Log.Channel).TargetGhost;
294 //
\83^
\81[
\83Q
\83b
\83g
\83S
\81[
\83X
\83g
\8am
\92è
295 Ghost := frmSender.SetHWndToFavoriteGhost(Ghost);
296 frmSender.DirectSstp.SstpSender := 'SSTP Bottle -
\81y
\83\8d\83O
\8dÄ
\90¶
\81z';
297 if Pref.NoTranslate then SOpt := [soNoTranslate] else SOpt := [];
298 frmSender.DirectSstp.SstpSEND(Script, SOpt, frmSender.GhostNameToSetName(Ghost));
301 procedure TfrmLog.UpdateScriptConversationColor(const Script: String);
304 UnyuTalking, Talked: boolean;
307 frmSender.DoTrans(scr, [toConvertURL]);
308 SsParser.LeaveEscape := false;
309 SsParser.InputString := scr;
310 SsParser.LeaveEscape := true;
311 UnyuTalking := false;
312 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
313 edtScript.Text := '';
314 edtScript.Color := Pref.BgColor;
315 for i := 0 to SsParser.Count-1 do begin
316 if (SsParser[i] = '\u') and not UnyuTalking then begin
319 edtScript.SelText := #13#10;
323 if (SsParser[i] = '\h') and UnyuTalking then begin
324 UnyuTalking := false;
326 edtScript.SelText := #13#10;
330 if SsParser.MarkUpType[i] = mtStr then begin
332 edtScript.SelAttributes.Color := Pref.TalkColorU
334 edtScript.SelAttributes.Color := Pref.TalkColorH;
335 edtScript.SelText := SsParser[i];
338 if SsParser.MarkUpType[i] = mtMeta then begin
339 edtScript.SelAttributes.Color := Pref.MetaWordColor;
340 edtScript.SelText := SsParser[i];
346 procedure TfrmLog.UpdateScriptConversationNoColor(const Script: String);
349 UnyuTalking, Talked, LastUnyuTalked: boolean;
352 frmSender.DoTrans(Scr, [toConvertURL]);
353 SsParser.LeaveEscape := false;
354 SsParser.InputString := Scr;
355 SsParser.LeaveEscape := true;
356 edtScript.Text := '';
357 edtScript.Color := clWindow;
358 edtScript.DefAttributes.Color := clWindowText;
359 edtScript.SelAttributes.Color := clWindowText;
361 UnyuTalking := false;
362 LastUnyuTalked := false;
363 for i := 0 to SsParser.Count-1 do begin
364 if (SsParser[i] = '\u') and not UnyuTalking then begin
367 if (SsParser[i] = '\h') and UnyuTalking then begin
368 UnyuTalking := false;
370 if SsParser.MarkUpType[i] in [mtStr, mtMeta] then begin
371 if not Talked then begin
372 if UnyuTalking then Scr := '
\82¤:' else Scr := '
\82³:';
374 if Talked and (UnyuTalking <> LastUnyuTalked) then begin
376 if UnyuTalking then Scr := Scr + '
\82¤:' else Scr := Scr + '
\82³:';
378 Scr := Scr + SsParser[i];
380 LastUnyuTalked := UnyuTalking;
383 edtScript.Text := Scr;
386 procedure TfrmLog.lvwLogKeyPress(Sender: TObject; var Key: Char);
388 if Key = #13 then lvwLogDblClick(Sender);
391 procedure TfrmLog.CreateParams(var Params: TCreateParams);
394 Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
397 procedure TfrmLog.lvwLogClick(Sender: TObject);
399 //
\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ô
401 Selected := Selected;
404 procedure TfrmLog.lvwLogColumnClick(Sender: TObject; Column: TListColumn);
405 var SortType: TBottleLogSortType;
409 if lvwLog.Selected <> nil then
410 SelectedMID := SelectedBottleLog.Bottles[lvwLog.Selected.Index].MID;
412 SortColumn := Column.Index;
414 -1: SortType := stLogTime;
415 subChannel: SortType := stChannel;
416 subVotes: SortType := stVote;
417 subAgrees: SortType := stAgree;
418 subScript: SortType := stScript;
419 else SortType := stLogTime;
422 SelectedBottleLog.SortBottles(SortType);
424 SelAndFocusMessage(SelectedMID);
428 procedure TfrmLog.mnPopUpCopyScriptClick(Sender: TObject);
433 Log := SelectedBottleLog.Bottles[frmLog.lvwLog.Selected.Index];
434 if Log = nil then Exit;
436 Clip.SetTextBuf(PChar(Log.Script));
439 procedure TfrmLog.SetBottleStatusToOpened(const MID: String);
441 if CurrentBottleLog.Bottle(MID) <> nil then begin
442 CurrentBottleLog.Bottle(MID).State := lsOpened;
443 lvwLog.OnChange := nil;
445 lvwLog.OnChange := lvwLogChange;
449 procedure TfrmLog.SetBottleStatusToPlaying(const MID: String);
451 if CurrentBottleLog.Bottle(MID) <> nil then begin
452 CurrentBottleLog.Bottle(MID).State := lsPlaying;
453 lvwLog.OnChange := nil;
455 lvwLog.OnChange := lvwLogChange;
459 procedure TfrmLog.mnSaveLogClick(Sender: TObject);
461 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
462 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
463 SaveDialog.DefaultExt := 'log';
464 SaveDialog.FilterIndex := 1;
465 if SaveDialog.Execute then
466 SelectedBottleLog.SaveToSstpLog(SaveDialog.FileName, false);
469 procedure TfrmLog.mnSaveLogChannelClick(Sender: TObject);
471 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
472 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
473 SaveDialog.DefaultExt := 'log';
474 SaveDialog.FilterIndex := 1;
475 if SaveDialog.Execute then
476 SelectedBottleLog.SaveToSstpLog(SaveDialog.FileName, true);
479 procedure TfrmLog.mnSaveLogScriptClick(Sender: TObject);
481 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.txt');
482 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
483 SaveDialog.DefaultExt := 'txt';
484 SaveDialog.FilterIndex := 2;
485 if SaveDialog.Execute then
486 SelectedBottleLog.SaveToText(SaveDialog.FileName);
489 procedure TfrmLog.mnSaveLogXMLClick(Sender: TObject);
491 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.xml');
492 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
493 SaveDialog.DefaultExt := 'xml';
494 SaveDialog.FilterIndex := 3;
495 if SaveDialog.Execute then
496 SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName, XMLDocument);
499 procedure TfrmLog.lvwLogData(Sender: TObject; Item: TListItem);
503 if Item = nil then Exit;
505 Log := SelectedBottleLog.Bottles[i];
507 Caption := FormatDateTime('yy/mm/dd hh:nn:ss', Log.LogTime);
509 if Log.Ghost <> '' then
510 SubItems.Add(Log.Channel + '/' + Log.Ghost)
512 SubItems.Add(Log.Channel);
513 if Log.LogType = ltBottle then begin
514 SubItems.Add(IntToStr(Log.Votes));
515 SubItems.Add(IntToStr(Log.Agrees));
517 //
\83V
\83X
\83e
\83\80\83\8d\83O
\82È
\82Ç
\82Í
\93\8a\95[
\81E
\93¯
\88Ó
\82ð
\95\
\8e¦
\82µ
\82È
\82¢
521 SubItems.Add(Log.Script);
523 if Log.LogType = ltBottle then begin
525 lsUnopened: ImageIndex := IconBottle;
526 lsPlaying: ImageIndex := IconPlaying;
527 lsOpened: ImageIndex := IconOpened;
530 ImageIndex := IconSystemLog;
534 procedure TfrmLog.UpdateWindow;
536 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
537 if Pref.ColorScript then begin
538 if lvwLog.Color <> Pref.BgColor then lvwLog.Color := Pref.BgColor;
539 if lvwLog.Font.Color <> Pref.TalkColorH then lvwLog.Font.Color := Pref.TalkColorH;
541 if lvwLog.Color <> clWindow then lvwLog.Color := clWindow;
542 if lvwLog.Font.Color <> clWindowText then lvwLog.Font.Color := clWindowText;
544 lvwLog.Items.Count := SelectedBottleLog.Count;
546 //lvwLogChange(Self, lvwLog.Selected, ctState);
549 procedure TfrmLog.PopupMenuListViewPopup(Sender: TObject);
555 for i := mnJumpURL.Count-1 downto 0 do begin
556 mnJumpURL.Items[i].Free;
558 mnJumpURL.Enabled := false;
559 if lvwLog.Selected = nil then Exit;
560 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
561 if Log = nil then Exit;
564 Urls := TStringList.Create;
565 ExtractURLs(Log.Script, Urls);
566 for i := 0 to Urls.Count-1 do begin
567 Child := TMenuItem.Create(Self);
569 Caption := Format('(&%d) %s', [i+1, Urls[i]]);
570 OnClick := mnURLClick;
571 AutoHotkeys := maManual;
572 mnJumpURL.Add(Child);
575 mnJumpURL.Enabled := Urls.Count > 0;
581 procedure TfrmLog.mnURLClick(Sender: TObject);
584 URL := (Sender as TMenuItem).Caption;
585 RegExp.Subst('s/^\(&?\d\) //', URL);
586 ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOW);
589 procedure TfrmLog.ExtractURLs(Script: String; Result: TStrings);
590 var i, u, j: integer;
594 SsParser.LeaveEscape := false;
595 SsParser.InputString := Script;
596 SsParser.LeaveEscape := true;
597 for i := 0 to SsParser.Count-1 do begin
598 if (SsParser.Match(SsParser[i], '\URL%b') > 0) then begin
599 for u := 7 downto 1 do begin
600 if (SsParser.Match(SsParser[i],
601 '\URL%b'+StringReplace(StringOfChar('-', u*2),
602 '-', '%b', [rfReplaceAll]))) > 0 then begin
603 for j := 1 to u do begin
604 s := SsParser.GetParam(SsParser[i], j*2);
605 if Pos('http://', s) > 0 then Result.Add(s);
610 if SsParser.Match(SsParser[i], '\URL%b%b') = 0 then begin //
\8aÈ
\88Õ
\94ÅURL
\95Ï
\8a·
611 //
\8aÈ
\88Õ
\8c`
\8e®\URL
\83^
\83O
\95Ï
\8a·
612 s := SsParser.GetParam(SsParser[i], 1);
613 if Pos('http://', s) > 0 then Result.Add(s);
619 procedure TfrmLog.SelAndFocusMessage(const MID: String);
623 for i := 0 to SelectedBottleLog.Count-1 do begin
624 Log := SelectedBottleLog.Items[i] as TLogItem;
625 if Log.MID = MID then begin
626 lvwLog.Items[i].Selected := true;
627 lvwLog.Items[i].Focused := true;
632 procedure TfrmLog.lvwLogCustomDrawItem(Sender: TCustomListView;
633 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
638 procedure TfrmLog.lvwLogCustomDrawSubItem(Sender: TCustomListView;
639 Item: TListItem; SubItem: Integer; State: TCustomDrawState;
640 var DefaultDraw: Boolean);
646 Mark: TSsMarkUpType;}
649 {if (SubItem <> SubScript+1) or (not Pref.ColorScript) then Exit; // DefaultDraw = true
650 // Custom Script Coloring
651 DefaultDraw := false;
652 SavedDC := SaveDC(lvwLog.Canvas.Handle);
654 ListView_GetSubItemRect(lvwLog.Handle, Item.Index, SubScript+1, LVIR_BOUNDS, @DestRect);
656 lvwLog.Canvas.Brush.Style := bsSolid;
657 if cdsSelected in State then begin
658 lvwLog.Canvas.Brush.Color := clHighlight
660 lvwLog.Canvas.Brush.Color := Pref.BgColor;
662 lvwLog.Canvas.FillRect(DestRect);
663 lvwLog.Canvas.Brush.Style := bsClear;
665 Script := Item.SubItems[SubScript];
666 // DrawTextEx(lvwLog.Canvas.Handle, PChar(Script), -1, DestRect, DT_END_ELLIPSIS, nil);
667 SsParser.InputString := Script;
669 for i := 0 to SsParser.Count - 1 do begin
670 Mark := SsParser.MarkUpType[i];
672 mtMeta: lvwLog.Canvas.Font.Color := Pref.MetaWordColor;
673 mtTag: lvwLog.Canvas.Font.Color := Pref.MarkUpColor;
674 mtTagErr: lvwLog.Canvas.Font.Color := Pref.MarkErrorColor;
676 lvwLog.Canvas.Font.Color := Pref.TalkColorH;
679 w := lvwLog.Canvas.TextWidth(SsParser[i]);
680 lvwLog.Canvas.TextRect(DestRect, DestRect.Left + x, DestRect.Top + 2, SsParser[i]);
682 if DestRect.Right - DestRect.Left < x then Break;
685 RestoreDC(lvwLog.Canvas.Handle, SavedDC);
689 procedure TfrmLog.UpdateScript(const Script: String);
691 if Script <> FLastScript then begin
692 if Pref.LogWindowPreviewStyle = psConversation then begin
693 if Pref.ColorScript then begin
694 UpdateScriptConversationColor(Script);
696 UpdateScriptConversationNoColor(Script);
699 UpdateScriptScript(Script);
701 SendMessage(edtScript.Handle, EM_LINESCROLL, Low(integer), Low(integer)); //
\83X
\83N
\83\8d\81[
\83\8b\96ß
\82µ
702 FLastScript := Script;
706 procedure TfrmLog.PopupMenuPreviewStylePopup(Sender: TObject);
709 with PopupMenuPreviewStyle do
710 for i := 0 to Items.Count-1 do
711 Items[i].Checked := Items[i].Tag = Ord(Pref.LogWindowPreviewStyle)
714 procedure TfrmLog.mnPreviewStyleClick(Sender: TObject);
717 with PopupMenuPreviewStyle do
718 for i := 0 to Items.Count-1 do
719 Items[i].Checked := (Sender as TMenuItem).Tag = Items[i].Tag;
720 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle((Sender as TMenuItem).Tag);
722 lvwLogChange(self, lvwLog.Selected, ctState);
725 procedure TfrmLog.UpdateScriptScript(const Script: String);
727 UnyuTalking: boolean;
730 if Pref.ColorScript then begin
731 edtScript.Color := Pref.BgColor;
733 edtScript.Color := clWindow;
734 edtScript.DefAttributes.Color := clWindowText;
735 edtScript.SelAttributes.Color := clWindowText;
737 SsParser.LeaveEscape := true;
738 SsParser.InputString := Script;
739 edtScript.Text := '';
740 edtScript.SelAttributes.Color := clWindowText;
741 UnyuTalking := false;
742 for i := 0 to SsParser.Count-1 do begin
743 if Pref.ColorScript then begin
744 case SsParser.MarkUpType[i] of
747 edtScript.SelAttributes.Color := Pref.TalkColorU
749 edtScript.SelAttributes.Color := Pref.TalkColorH;
752 edtScript.SelAttributes.Color := Pref.MarkUpColor;
753 if SsParser[i] = '\h' then
755 else if SsParser[i] = '\u' then
758 mtMeta: edtScript.SelAttributes.Color := Pref.MetaWordColor;
759 mtTagErr: edtScript.SelAttributes.Color := Pref.MarkErrorColor;
762 edtScript.SelText := SsParser[i];
763 if (SsParser[i] = '\n') and (Pref.LogWindowPreviewStyle = psScriptWithLineBreak) then
764 edtScript.SelText := #13#10;
768 procedure TfrmLog.tbtnPreviewStyleClick(Sender: TObject);
771 sel := Ord(Pref.LogWindowPreviewStyle);
773 if sel > Ord(High(TLogWindowPreviewStyle)) then sel := 0;
774 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle(sel);
776 lvwLogChange(self, lvwLog.Selected, ctState);
779 function TfrmLog.SelectedBottleLog: TBottleLogList;
781 Result := FBottleLogList.Items[tabBottleLog.TabIndex] as TBottleLogList;
784 function TfrmLog.GetCurrentBottleLog: TBottleLogList;
786 Result := FBottleLogList.Items[0] as TBottleLogList;
789 procedure TfrmLog.tabBottleLogChange(Sender: TObject);
792 if SelectedBottleLog.SelectedIndex >= 0 then begin
793 lvwLog.Items[SelectedBottleLog.SelectedIndex].Selected := true;
794 if lvwLog.Focused then lvwLog.Selected.Focused := true;
796 lvwLogChange(Self, nil, ctState);
799 procedure TfrmLog.LogLoaded(Sender: TObject);
801 if SelectedBottleLog = Sender then begin
806 procedure TfrmLog.UpdateTab;
810 cur := SelectedBottleLog;
811 tabBottleLog.Tabs.Clear;
812 for i := 0 to FBottleLogList.Count - 1 do begin
813 tabBottleLog.Tabs.Add((FBottleLogList[i] as TBottleLogList).Title);
815 tabBottleLog.TabIndex := FBottleLogList.IndexOf(cur);
818 procedure TfrmLog.LogLoadFailure(Sender: TObject; const Message: String);
821 ShowMessage(Message);
822 (Sender as TBottleLogList).AddSystemLog(Message);
826 procedure TfrmLog.AgreeLog(const MID: String; const Agree: integer);
831 for i := 0 to FBottleLogList.Count - 1 do begin
832 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
833 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Agrees := Agree;
837 if flag then lvwLog.Invalidate;
840 procedure TfrmLog.VoteLog(const MID: String; const Vote: integer);
845 for i := 0 to FBottleLogList.Count - 1 do begin
846 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
847 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Votes := Vote;
851 if flag then lvwLog.Invalidate;
854 procedure TfrmLog.tabBottleLogChanging(Sender: TObject;
855 var AllowChange: Boolean);
857 if lvwLog.Selected <> nil then
858 SelectedBottleLog.SelectedIndex := lvwLog.Selected.Index
860 SelectedBottleLog.SelectedIndex := -1;
863 procedure TfrmLog.tabBottleLogContextPopup(Sender: TObject;
864 MousePos: TPoint; var Handled: Boolean);
866 with tabBottleLog do begin
867 Tag := IndexOfTabAt(MousePos.X, MousePos.Y);
868 if Tag < 0 then Handled := true;
869 mnCloseTab.Enabled := Tag > 0;
873 procedure TfrmLog.mnCloseTabClick(Sender: TObject);
875 if tabBottleLog.Tag = 0 then Exit;
876 FBottleLogList.Delete(tabBottleLog.Tag);
877 tabBottleLog.TabIndex := 0;
880 lvwLogChange(Self, nil, ctState);
883 procedure TfrmLog.tbtnFindBottleClick(Sender: TObject);
885 ResultLog: TBottleLogList;
886 Item1, Item2: TLogItem;
889 if SelectedBottleLog.Count = 0 then begin
890 ShowMessage('
\8c\9f\8dõ
\91Î
\8fÛ
\82ª
\8bó
\82Å
\82·
\81B');
895 if InputQuery('
\83X
\83N
\83\8a\83v
\83g
\96{
\95¶
\82ð
\8c\9f\8dõ', '
\8c\9f\8dõ
\95¶
\8e\9a\97ñ', Query) then begin
896 if Query = '' then Exit;
897 ResultLog := TBottleLogList.Create('
\8c\9f\8dõ
\8c\8b\89Ê');
898 for i := 0 to SelectedBottleLog.Count-1 do begin
899 Item1 := SelectedBottleLog.Items[i] as TLogItem;
900 if AnsiContainsText(Item1.Script, Query) and (Item1.LogType = ltBottle) then begin
901 matched := matched + 1;
902 Item2 := TLogItem.Create(ltBottle, Item1.MID, Item1.Channel,
903 Item1.Script, Item1.Ghost, Item1.LogTime);
904 Item2.State := lsOpened;
905 Item2.Votes := Item1.Votes;
906 Item2.Agrees := Item1.Agrees;
907 ResultLog.Add(Item2);
911 ResultLog.AddSystemLog('
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
912 BottleLogList.Add(ResultLog);
914 tabBottleLog.TabIndex := BottleLogList.Count-1;
919 procedure TfrmLog.tbtnOpenLogClick(Sender: TObject);
920 var BottleLog: TBottleLogList;
924 if OpenDialog.Execute then begin
926 for i := 0 to OpenDialog.Files.Count-1 do begin
927 BottleLog := TBottleLogList.Create(ExtractFileName(OpenDialog.Files[i]));
928 BottleLog.LoadFromXMLFile(OpenDialog.Files[i], XMLDocument);
929 BottleLogList.Add(BottleLog);
932 on E: EXMLFileOpenException do begin
934 ShowMessage(E.Message);
943 function TfrmLog.GetDefaultFileName(const Name, Ext: String): String;
945 Result := StringReplace(Name, '/', '', [rfReplaceAll]);
946 Result := StringReplace(Result, ' ', '', [rfReplaceAll]);
947 Result := ChangeFileExt(Result, Ext);