6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus,
8 Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, StrUtils;
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 tbtnOpenLog: TToolButton;
53 OpenDialog: TOpenDialog;
54 tbtnInsertCue: TToolButton;
55 mnInsertCue: TMenuItem;
56 PopupMenuListPreviewStyle: TPopupMenu;
57 mnListPreviewStyleNormal: TMenuItem;
58 mnListPreviewStyleTagStripped: TMenuItem;
59 tbtnListPreviewStyle: TToolButton;
60 procedure tbtnClearClick(Sender: TObject);
61 procedure FormCreate(Sender: TObject);
62 procedure lvwLogChange(Sender: TObject; Item: TListItem;
64 procedure lvwLogDblClick(Sender: TObject);
65 procedure lvwLogKeyPress(Sender: TObject; var Key: Char);
66 procedure FormDestroy(Sender: TObject);
67 procedure lvwLogClick(Sender: TObject);
68 procedure mnSaveLogClick(Sender: TObject);
69 procedure lvwLogColumnClick(Sender: TObject; Column: TListColumn);
70 procedure mnPopUpCopyScriptClick(Sender: TObject);
71 procedure mnSaveLogChannelClick(Sender: TObject);
72 procedure mnSaveLogScriptClick(Sender: TObject);
73 procedure mnSaveLogXMLClick(Sender: TObject);
74 procedure lvwLogData(Sender: TObject; Item: TListItem);
75 procedure PopupMenuListViewPopup(Sender: TObject);
76 procedure lvwLogCustomDrawItem(Sender: TCustomListView;
77 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
78 procedure PopupMenuPreviewStylePopup(Sender: TObject);
79 procedure mnPreviewStyleClick(Sender: TObject);
80 procedure tbtnPreviewStyleClick(Sender: TObject);
81 procedure tabBottleLogChange(Sender: TObject);
82 procedure tabBottleLogChanging(Sender: TObject;
83 var AllowChange: Boolean);
84 procedure tabBottleLogContextPopup(Sender: TObject; MousePos: TPoint;
85 var Handled: Boolean);
86 procedure mnCloseTabClick(Sender: TObject);
87 procedure tbtnFindBottleClick(Sender: TObject);
88 procedure tbtnOpenLogClick(Sender: TObject);
89 procedure tabBottleLogMouseDown(Sender: TObject; Button: TMouseButton;
90 Shift: TShiftState; X, Y: Integer);
91 procedure tabBottleLogDragOver(Sender, Source: TObject; X, Y: Integer;
92 State: TDragState; var Accept: Boolean);
93 procedure tabBottleLogDragDrop(Sender, Source: TObject; X, Y: Integer);
94 procedure tabBottleLogEndDrag(Sender, Target: TObject; X, Y: Integer);
95 procedure lvwLogDrawItem(Sender: TCustomListView; Item: TListItem;
96 Rect: TRect; State: TOwnerDrawState);
97 procedure mnListPreviewStyleTagStrippedClick(Sender: TObject);
98 procedure tbtnListPreviewStyleClick(Sender: TObject);
99 procedure PopupMenuListPreviewStylePopup(Sender: TObject);
102 FLastScript: String; //
\83X
\83N
\83\8a\83v
\83g
\8dÄ
\95`
\89æ
\97}
\90§
\97p
103 FBottleLogList: TObjectList;
105 FDragTabIndex: integer; //
\83^
\83u
\83h
\83\89\83b
\83O
\83h
\83\8d\83b
\83v
\8aÖ
\98A
106 FDragTabDest: integer; //
\83h
\83\8d\83b
\83v
\82·
\82é
\88Ê
\92u(
\82·
\82®
\89E
\82É
\82
\82é
\83^
\83u
\82Ì
\83C
\83\93\83f
\83b
\83N
\83X)
108 procedure UpdateScript(const Script: String);
109 procedure UpdateScriptConversationColor(const Script: String);
110 procedure UpdateScriptScript(const Script: String);
111 procedure mnURLClick(Sender: TObject);
112 procedure ExtractURLs(Script: String; Result: TStrings);
113 function GetDefaultFileName(const Name: String; const Ext: String): String;
114 function BottleLogTitled(const LogName: String): TBottleLogList;
115 procedure DrawSingleLineScript(const Script: String; const Rect: TRect;
118 procedure CreateParams(var Params: TCreateParams); override;
121 function SelectedBottleLog: TBottleLogList;
122 property BottleLogList: TObjectList read FBottleLogList;
123 procedure AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String);
124 procedure AddCurrentSystemLog(const LogName, MessageString: String);
125 procedure VoteLog(const MID: String; const Vote: integer);
126 procedure AgreeLog(const MID: String; const Agree: integer);
127 procedure SetBottleState(const MID: String; State: TLogState);
128 procedure AllBottleOpened;
129 procedure LogLoaded(Sender: TObject);
130 procedure LogLoadFailure(Sender: TObject; const Message: String);
131 procedure LogLoadWork(Sender: TObject);
133 procedure UpdateWindow;
134 procedure SelAndFocusMessage(const MID: String);
160 procedure TfrmLog.AddCurrentScriptLog(const LogName, Script, Channel, MID, Ghost: String);
163 BottleLogTitled(LogName).AddScriptLog(Script, Channel, MID, Ghost);
164 if SelectedBottleLog <> BottleLogTitled(LogName) then Exit;
165 lvwLog.OnChange := nil; //
\83C
\83x
\83\93\83g
\94
\90¶(
\82¢
\82ë
\82¢
\82ë
\8dÄ
\95`
\89æ
\82ª
\8bN
\82«
\82é)
\82Ì
\97}
\90§
166 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
167 lvwLog.Items.Count := SelectedBottleLog.Count;
169 if Sel >= 0 then begin
170 lvwLog.Selected := lvwLog.Items[Sel + 1];
171 lvwLog.Selected.Focused := true;
173 if not lvwLog.Focused then
174 ListView_Scroll(lvwLog.Handle, 0, High(integer));
175 lvwLog.OnChange := lvwLogChange;
178 procedure TfrmLog.AddCurrentSystemLog(const LogName, MessageString: String);
181 BottleLogTitled(LogName).AddSystemLog(MessageString);
182 if SelectedBottleLog <> BottleLogTitled(LogName) then Exit;
183 lvwLog.OnChange := nil;
184 if lvwLog.Selected <> nil then Sel := lvwLog.Selected.Index else Sel := -1;
185 lvwLog.Items.Count := SelectedBottleLog.Count;
187 if Sel >= 0 then begin
188 lvwLog.Selected := lvwLog.Items[Sel + 1];
189 lvwLog.Selected.Focused := true;
191 if not lvwLog.Focused then
192 ListView_Scroll(lvwLog.Handle, 0, High(integer));
193 lvwLog.OnChange := lvwLogChange;
198 procedure TfrmLog.tbtnClearClick(Sender: TObject);
200 if SelectedBottleLog = nil then Exit;
201 FBottleLogList.Delete(tabBottleLog.TabIndex);
202 tabBottleLog.TabIndex := 0;
205 lvwLogChange(Self, nil, ctState);
208 procedure TfrmLog.FormCreate(Sender: TObject);
211 FBottleLogList := TObjectList.Create;
213 SsParser.TagPattern.Assign(frmSender.SsParser.TagPattern);
214 SsParser.MetaPattern.Assign(frmSender.SsParser.MetaPattern);
216 with Pref.LogWindowPosition do begin
219 Self.Width := Right - Left + 1;
220 Self.Height := Bottom - Top + 1;
222 lvwLog.DoubleBuffered := true;
223 edtScript.Height := Pref.LogWindowDividerPos;
226 while Token(Pref.LogWindowColumnWidth, ',', i) <> '' do begin
227 lvwLog.Columns[i].Width := StrToIntDef(Token(Pref.LogWindowColumnWidth, ',', i), 100);
231 UpdateWindow; // Reset window color and enabled status of some buttons
234 procedure TfrmLog.FormDestroy(Sender: TObject);
239 for i := 0 to lvwLog.Columns.Count-1 do begin
240 if i > 0 then WidthStr := WidthStr + ',';
241 WidthStr := WidthStr + IntToStr(lvwLog.Column[i].Width);
243 Pref.LogWindowColumnWidth := WidthStr;
245 with Pref.LogWindowPosition do begin
248 Right := Self.Left + Self.Width - 1;
249 Bottom := Self.Top + Self.Height - 1;
251 Pref.LogWindowDividerPos := edtScript.Height;
253 FreeAndNil(FBottleLogList);
256 procedure TfrmLog.lvwLogChange(Sender: TObject; Item: TListItem;
257 Change: TItemChange);
261 if SelectedBottleLog <> nil then begin
262 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
263 if Change = ctState then begin
265 if lvwLog.Selected <> nil then begin
266 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
267 if (Log.LogType = ltBottle) and not frmSender.Connecting then begin
268 Script := Log.Script;
269 frmSender.actVoteMessage.Enabled := true;
270 frmSender.actAgreeMessage.Enabled := true;
271 frmSender.actInsertCue.Enabled := true;
272 mnPopUpCopyScript.Enabled := true;
273 StatusBar.Panels[1].Text := Format('%d
\83o
\83C
\83g -
\83_
\83u
\83\8b\83N
\83\8a\83b
\83N
\82Å
\8dÄ
\90¶', [Length(Log.Script)]);
274 UpdateScript(Script);
276 frmSender.actVoteMessage.Enabled := false;
277 frmSender.actAgreeMessage.Enabled := false;
278 frmSender.actInsertCue.Enabled := false;
279 mnPopUpCopyScript.Enabled := false;
280 StatusBar.Panels[1].Text := '';
281 UpdateScript(''); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\82ð
\83N
\83\8a\83A
284 frmSender.actVoteMessage.Enabled := false;
285 frmSender.actAgreeMessage.Enabled := false;
286 frmSender.actInsertCue.Enabled := false;
287 mnPopUpCopyScript.Enabled := false;
288 StatusBar.Panels[1].Text := '';
289 UpdateScript(Script); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\83N
\83\8a\83A
292 tbtnSaveLog.Enabled := lvwLog.Items.Count > 0;
294 frmSender.actVoteMessage.Enabled := false;
295 frmSender.actAgreeMessage.Enabled := false;
296 frmSender.actInsertCue.Enabled := false;
297 mnPopUpCopyScript.Enabled := false;
298 StatusBar.Panels[0].Text := '';
299 UpdateScript(''); //
\83\8d\83O
\83v
\83\8c\83r
\83\85\81[
\95\94\83N
\83\8a\83A
303 procedure TfrmLog.lvwLogDblClick(Sender: TObject);
305 Log, CueItem: TLogItem;
307 if lvwLog.Selected = nil then
309 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
310 if Log = nil then Exit;
311 if Log.LogType <> ltBottle then
313 Script := frmSender.ScriptTransForSSTP(Log.Script);
314 if Script = '' then begin
315 ShowMessage('
\96â
\91è
\82Ì
\82 \82é
\83X
\83N
\83\8a\83v
\83g
\82Å
\82·
\81B
\8dÄ
\90¶
\82Å
\82«
\82Ü
\82¹
\82ñ
\81B'+
316 '
\83N
\83\89\83C
\83A
\83\93\83g
\82ð
\8dÅ
\90V
\94Å
\82É
\82µ
\82Ä
\82Ý
\82Ä
\82
\82¾
\82³
\82¢
\81B');
320 CueItem := TLogItem.Create(Log);
322 CueItem.Script := Script;
323 frmSender.BottleSstp.Unshift(CueItem);
329 procedure TfrmLog.UpdateScriptConversationColor(const Script: String);
332 UnyuTalking, Talked, InSynchronized: boolean;
335 frmSender.DoTrans(scr, [toConvertURL]);
336 SsParser.LeaveEscape := false;
337 SsParser.InputString := scr;
338 SsParser.LeaveEscape := true;
339 UnyuTalking := false;
340 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
341 InSynchronized := false;
342 edtScript.Text := '';
343 edtScript.Color := Pref.BgColor;
344 for i := 0 to SsParser.Count-1 do begin
345 if (SsParser[i] = '\_s') and not InSynchronized then begin
346 InSynchronized := true;
348 edtScript.SelText := #13#10;
351 end else if (SsParser[i] = '\_s') and InSynchronized then begin
352 InSynchronized := false;
354 edtScript.SelText := #13#10;
358 if (SsParser[i] = '\u') and not UnyuTalking then begin
361 edtScript.SelText := #13#10;
365 if (SsParser[i] = '\h') and UnyuTalking then begin
366 UnyuTalking := false;
368 edtScript.SelText := #13#10;
372 if SsParser.MarkUpType[i] = mtStr then begin
373 if InSynchronized then
374 edtScript.SelAttributes.Color := Pref.TalkColorS
375 else if UnyuTalking then
376 edtScript.SelAttributes.Color := Pref.TalkColorU
378 edtScript.SelAttributes.Color := Pref.TalkColorH;
379 edtScript.SelText := SsParser[i];
382 if SsParser.MarkUpType[i] = mtMeta then begin
383 edtScript.SelAttributes.Color := Pref.MetaWordColor;
384 edtScript.SelText := SsParser[i];
390 procedure TfrmLog.lvwLogKeyPress(Sender: TObject; var Key: Char);
392 if Key = #13 then lvwLogDblClick(Sender);
395 procedure TfrmLog.CreateParams(var Params: TCreateParams);
398 Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
401 procedure TfrmLog.lvwLogClick(Sender: TObject);
403 //
\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ô
405 Selected := Selected;
408 procedure TfrmLog.lvwLogColumnClick(Sender: TObject; Column: TListColumn);
409 var SortType: TBottleLogSortType;
413 if lvwLog.Selected <> nil then
414 SelectedMID := SelectedBottleLog.Bottles[lvwLog.Selected.Index].MID;
416 SortColumn := Column.Index;
418 -1: SortType := stLogTime;
419 subChannel: SortType := stChannel;
420 subGhost: SortType := stGhost;
421 subVotes: SortType := stVote;
422 subAgrees: SortType := stAgree;
423 subScript: SortType := stScript;
424 else SortType := stLogTime;
427 SelectedBottleLog.SortBottles(SortType);
429 SelAndFocusMessage(SelectedMID);
433 procedure TfrmLog.mnPopUpCopyScriptClick(Sender: TObject);
438 Log := SelectedBottleLog.Bottles[frmLog.lvwLog.Selected.Index];
439 if Log = nil then Exit;
441 Clip.SetTextBuf(PChar(Log.Script));
444 procedure TfrmLog.SetBottleState(const MID: String; State: TLogState);
448 for i := 0 to FBottleLogList.Count-1 do begin
449 Bottle := (FBottleLogList[i] as TBottleLogList).Bottle(MID);
450 if Bottle <> nil then begin
451 Bottle.State := State;
452 lvwLog.OnChange := nil;
454 lvwLog.OnChange := lvwLogChange;
459 procedure TfrmLog.mnSaveLogClick(Sender: TObject);
461 if SelectedBottleLog = nil then Exit;
462 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
463 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
464 SaveDialog.DefaultExt := 'log';
465 SaveDialog.FilterIndex := 1;
466 if SaveDialog.Execute then
467 SelectedBottleLog.SaveToSstpLog(SaveDialog.FileName, false);
470 procedure TfrmLog.mnSaveLogChannelClick(Sender: TObject);
472 if SelectedBottleLog = nil then Exit;
473 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.log');
474 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
475 SaveDialog.DefaultExt := 'log';
476 SaveDialog.FilterIndex := 1;
477 if SaveDialog.Execute then
478 SelectedBottleLog.SaveToSstpLog(SaveDialog.FileName, true);
481 procedure TfrmLog.mnSaveLogScriptClick(Sender: TObject);
483 if SelectedBottleLog = nil then Exit;
484 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.txt');
485 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
486 SaveDialog.DefaultExt := 'txt';
487 SaveDialog.FilterIndex := 2;
488 if SaveDialog.Execute then
489 SelectedBottleLog.SaveToText(SaveDialog.FileName);
492 procedure TfrmLog.mnSaveLogXMLClick(Sender: TObject);
494 if SelectedBottleLog = nil then Exit;
495 SaveDialog.FileName := GetDefaultFileName(SelectedBottleLog.Title, '.xml');
496 SaveDialog.InitialDir := ExtractFileDir(Application.ExeName);
497 SaveDialog.DefaultExt := 'xml';
498 SaveDialog.FilterIndex := 3;
499 if SaveDialog.Execute then
500 SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName);
503 procedure TfrmLog.lvwLogData(Sender: TObject; Item: TListItem);
507 if Item = nil then Exit;
509 Log := SelectedBottleLog.Bottles[i];
511 Caption := FormatDateTime('yy/mm/dd hh:nn:ss', Log.LogTime);
513 SubItems.Add(Log.Channel);
514 SubItems.Add(Log.Ghost);
515 if Log.LogType = ltBottle then begin
516 if Log.Votes > 0 then
517 SubItems.Add(IntToStr(Log.Votes))
520 if Log.Agrees > 0 then
521 SubItems.Add(IntToStr(Log.Agrees))
525 //
\83V
\83X
\83e
\83\80\83\8d\83O
\82È
\82Ç
\82Í
\93\8a\95[
\81E
\93¯
\88Ó
\82ð
\95\
\8e¦
\82µ
\82È
\82¢
529 SubItems.Add(Log.Script);
531 if Log.LogType = ltBottle then begin
533 lsUnopened: ImageIndex := IconBottle;
534 lsPlaying: ImageIndex := IconPlaying;
535 lsOpened: ImageIndex := IconOpened;
538 ImageIndex := IconSystemLog;
542 procedure TfrmLog.UpdateWindow;
543 var EnabledFlag: boolean;
545 if true then begin // ColorScript
546 if lvwLog.Color <> Pref.BgColor then lvwLog.Color := Pref.BgColor;
547 if lvwLog.Font.Color <> Pref.TalkColorH then lvwLog.Font.Color := Pref.TalkColorH;
549 if lvwLog.Color <> clWindow then lvwLog.Color := clWindow;
550 if lvwLog.Font.Color <> clWindowText then lvwLog.Font.Color := clWindowText;
552 if SelectedBottleLog <> nil then begin
553 Caption := '
\83\8d\83O - ' + SelectedBottleLog.Title;
554 StatusBar.Panels[0].Text := IntToStr(SelectedBottleLog.Count) + '
\8c\8f';
555 lvwLog.Items.Count := SelectedBottleLog.Count;
557 Caption := '
\83\8d\83O';
558 StatusBar.Panels[0].Text := '';
559 StatusBar.Panels[1].Text := '';
560 lvwLog.Items.Count := 0;
563 EnabledFlag := SelectedBottleLog <> nil;
564 tbtnClear.Enabled := EnabledFlag;
565 tbtnSaveLog.Enabled := EnabledFlag;
566 tbtnFindBottle.Enabled := EnabledFlag;
571 procedure TfrmLog.PopupMenuListViewPopup(Sender: TObject);
577 for i := mnJumpURL.Count-1 downto 0 do begin
578 mnJumpURL.Items[i].Free;
580 mnJumpURL.Enabled := false;
581 if lvwLog.Selected = nil then Exit;
582 Log := SelectedBottleLog.Bottles[lvwLog.Selected.Index];
583 if Log = nil then Exit;
584 Urls := TStringList.Create;
586 ExtractURLs(Log.Script, Urls);
587 for i := 0 to Urls.Count-1 do begin
588 Child := TMenuItem.Create(Self);
590 Caption := Format('(&%d) %s', [i+1, StringReplace(Urls[i], '&', '&&', [rfReplaceAll])]);
592 OnClick := mnURLClick;
593 AutoHotkeys := maManual;
594 mnJumpURL.Add(Child);
597 mnJumpURL.Enabled := Urls.Count > 0;
603 procedure TfrmLog.mnURLClick(Sender: TObject);
604 var LogItem: TLogItem;
608 if (lvwLog.Selected = nil) or (SelectedBottleLog = nil) then Exit;
609 LogItem := SelectedBottleLog[lvwLog.Selected.Index] as TLogItem;
610 Urls := TStringList.Create;
612 ExtractURLs(LogItem.Script, Urls);
613 URL := Urls[(Sender as TMenuItem).Tag];
614 ShellExecute(Handle, 'open', PChar(URL), nil, nil, SW_SHOW);
620 procedure TfrmLog.ExtractURLs(Script: String; Result: TStrings);
621 var i, u, j: integer;
625 SsParser.InputString := Script;
626 for i := 0 to SsParser.Count-1 do begin
627 if (SsParser.Match(SsParser[i], '\URL%b') > 0) then begin
628 for u := 7 downto 1 do begin
629 if (SsParser.Match(SsParser[i],
630 '\URL%b'+StringReplace(StringOfChar('-', u*2),
631 '-', '%b', [rfReplaceAll]))) > 0 then begin
632 for j := 1 to u do begin
633 s := SsParser.GetParam(SsParser[i], j*2);
634 if Pos('http://', s) > 0 then Result.Add(s);
639 if SsParser.Match(SsParser[i], '\URL%b%b') = 0 then begin //
\8aÈ
\88Õ
\94ÅURL
\95Ï
\8a·
640 //
\8aÈ
\88Õ
\8c`
\8e®\URL
\83^
\83O
\95Ï
\8a·
641 s := SsParser.GetParam(SsParser[i], 1);
642 if Pos('http://', s) > 0 then Result.Add(s);
648 procedure TfrmLog.SelAndFocusMessage(const MID: String);
652 for i := 0 to SelectedBottleLog.Count-1 do begin
653 Log := SelectedBottleLog.Items[i] as TLogItem;
654 if Log.MID = MID then begin
655 lvwLog.Items[i].Selected := true;
656 lvwLog.Items[i].Focused := true;
661 procedure TfrmLog.lvwLogCustomDrawItem(Sender: TCustomListView;
662 Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
667 procedure TfrmLog.UpdateScript(const Script: String);
669 if Script <> FLastScript then begin
670 if Pref.LogWindowPreviewStyle = psConversation then begin
671 UpdateScriptConversationColor(Script);
673 UpdateScriptScript(Script);
675 SendMessage(edtScript.Handle, EM_LINESCROLL, Low(integer), Low(integer)); //
\83X
\83N
\83\8d\81[
\83\8b\96ß
\82µ
676 FLastScript := Script;
680 procedure TfrmLog.PopupMenuPreviewStylePopup(Sender: TObject);
683 with PopupMenuPreviewStyle do
684 for i := 0 to Items.Count-1 do
685 Items[i].Checked := Items[i].Tag = Ord(Pref.LogWindowPreviewStyle)
688 procedure TfrmLog.mnPreviewStyleClick(Sender: TObject);
691 with PopupMenuPreviewStyle do
692 for i := 0 to Items.Count-1 do
693 Items[i].Checked := (Sender as TMenuItem).Tag = Items[i].Tag;
694 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle((Sender as TMenuItem).Tag);
696 lvwLogChange(self, lvwLog.Selected, ctState);
699 procedure TfrmLog.UpdateScriptScript(const Script: String);
701 UnyuTalking, InSynchronized: boolean;
704 edtScript.Color := Pref.BgColor;
705 SsParser.LeaveEscape := true;
706 SsParser.InputString := Script;
707 edtScript.Text := '';
708 edtScript.SelAttributes.Color := clWindowText;
709 UnyuTalking := false;
710 InSynchronized := false;
711 for i := 0 to SsParser.Count-1 do begin
712 case SsParser.MarkUpType[i] of
714 if InSynchronized then
715 edtScript.SelAttributes.Color := Pref.TalkColorS
716 else if UnyuTalking then
717 edtScript.SelAttributes.Color := Pref.TalkColorU
719 edtScript.SelAttributes.Color := Pref.TalkColorH;
722 edtScript.SelAttributes.Color := Pref.MarkUpColor;
723 if SsParser[i] = '\h' then
725 else if SsParser[i] = '\u' then
727 else if SsParser[i] = '\_s' then
728 InSynchronized := not InSynchronized;
730 mtMeta: edtScript.SelAttributes.Color := Pref.MetaWordColor;
731 mtTagErr: edtScript.SelAttributes.Color := Pref.MarkErrorColor;
733 edtScript.SelText := SsParser[i];
734 if (SsParser[i] = '\n') and (Pref.LogWindowPreviewStyle = psScriptWithLineBreak) then
735 edtScript.SelText := #13#10;
739 procedure TfrmLog.tbtnPreviewStyleClick(Sender: TObject);
742 sel := Ord(Pref.LogWindowPreviewStyle);
744 if sel > Ord(High(TLogWindowPreviewStyle)) then sel := 0;
745 Pref.LogWindowPreviewStyle := TLogWindowPreviewStyle(sel);
747 lvwLogChange(self, lvwLog.Selected, ctState);
750 function TfrmLog.SelectedBottleLog: TBottleLogList;
752 if tabBottleLog.TabIndex >= 0 then
753 Result := FBottleLogList.Items[tabBottleLog.TabIndex] as TBottleLogList
758 procedure TfrmLog.tabBottleLogChange(Sender: TObject);
761 if SelectedBottleLog.SelectedIndex >= 0 then begin
762 lvwLog.Items[SelectedBottleLog.SelectedIndex].Selected := true;
763 if lvwLog.Focused then lvwLog.Selected.Focused := true;
765 lvwLogChange(Self, nil, ctState);
768 procedure TfrmLog.LogLoaded(Sender: TObject);
770 if SelectedBottleLog = Sender then begin
775 procedure TfrmLog.UpdateTab;
778 cur := tabBottleLog.tabIndex;
779 tabBottleLog.Tabs.Clear;
780 for i := 0 to FBottleLogList.Count - 1 do begin
781 tabBottleLog.Tabs.Add((FBottleLogList[i] as TBottleLogList).Title);
783 if FBottleLogList.Count > 0 then begin
784 if cur < FBottleLogList.Count then
785 tabBottleLog.TabIndex := cur
787 tabBottleLog.TabIndex := FBottleLogList.Count-1;
791 procedure TfrmLog.LogLoadFailure(Sender: TObject; const Message: String);
794 ShowMessage(Message);
795 if Sender = SelectedBottleLog then UpdateWindow;
798 procedure TfrmLog.AgreeLog(const MID: String; const Agree: integer);
803 for i := 0 to FBottleLogList.Count - 1 do begin
804 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
805 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Agrees := Agree;
809 if flag then lvwLog.Invalidate;
812 procedure TfrmLog.VoteLog(const MID: String; const Vote: integer);
817 for i := 0 to FBottleLogList.Count - 1 do begin
818 if (FBottleLogList[i] as TBottleLogList).Bottle(MID) <> nil then begin
819 (FBottleLogList[i] as TBottleLogList).Bottle(MID).Votes := Vote;
823 if flag then lvwLog.Invalidate;
826 procedure TfrmLog.tabBottleLogChanging(Sender: TObject;
827 var AllowChange: Boolean);
829 //
\8c»
\8dÝ
\91I
\91ð
\82³
\82ê
\82Ä
\82¢
\82é
\83\8d\83O
\82Ì
\91I
\91ð
\8fó
\91Ô
\82ð
\95Û
\91¶
830 if SelectedBottleLog = nil then Exit;
831 if lvwLog.Selected <> nil then
832 SelectedBottleLog.SelectedIndex := lvwLog.Selected.Index
834 SelectedBottleLog.SelectedIndex := -1;
837 procedure TfrmLog.tabBottleLogContextPopup(Sender: TObject;
838 MousePos: TPoint; var Handled: Boolean);
840 with tabBottleLog do begin
841 Tag := IndexOfTabAt(MousePos.X, MousePos.Y);
842 if Tag < 0 then Handled := true;
846 procedure TfrmLog.mnCloseTabClick(Sender: TObject);
848 FBottleLogList.Delete(tabBottleLog.Tag);
851 lvwLogChange(Self, nil, ctState);
854 procedure TfrmLog.tbtnFindBottleClick(Sender: TObject);
856 ResultLog: TBottleLogList;
857 Item1, Item2: TLogItem;
860 if SelectedBottleLog = nil then Exit;
861 if SelectedBottleLog.Count = 0 then begin
862 ShowMessage('
\8c\9f\8dõ
\91Î
\8fÛ
\82ª
\8bó
\82Å
\82·
\81B');
867 if InputQuery('
\83X
\83N
\83\8a\83v
\83g
\96{
\95¶
\82ð
\8c\9f\8dõ', '
\8c\9f\8dõ
\95¶
\8e\9a\97ñ', Query) then begin
868 if Query = '' then Exit;
869 ResultLog := TBottleLogList.Create('
\8c\9f\8dõ
\8c\8b\89Ê');
870 for i := 0 to SelectedBottleLog.Count-1 do begin
871 Item1 := SelectedBottleLog.Items[i] as TLogItem;
872 if AnsiContainsText(Item1.Script, Query) and (Item1.LogType = ltBottle) then begin
873 matched := matched + 1;
874 Item2 := TLogItem.Create(ltBottle, Item1.MID, Item1.Channel,
875 Item1.Script, Item1.Ghost, Item1.LogTime);
876 Item2.State := lsOpened;
877 Item2.Votes := Item1.Votes;
878 Item2.Agrees := Item1.Agrees;
879 ResultLog.Add(Item2);
883 ResultLog.AddSystemLog('
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
884 BottleLogList.Add(ResultLog);
886 tabBottleLog.TabIndex := BottleLogList.Count-1;
891 procedure TfrmLog.tbtnOpenLogClick(Sender: TObject);
892 var BottleLog: TBottleLogList;
896 if OpenDialog.Execute then begin
897 for i := 0 to OpenDialog.Files.Count-1 do begin
898 BottleLog := TBottleLogList.Create(ExtractFileName(OpenDialog.Files[i]));
900 BottleLog.LoadFromXMLFile(OpenDialog.Files[i]);
902 on E: EXMLFileOpenException do begin
904 ShowMessage(E.Message);
905 FreeAndNil(BottleLog);
908 if BottleLog <> nil then Index := BottleLogList.Add(BottleLog); //
\8dÅ
\8cã
\82É
\8aJ
\82¢
\82½
\83\8d\83O
\82Ì
\88Ê
\92u
\82ð
\8bL
\89¯
911 if Index >= 0 then tabBottleLog.TabIndex := Index;
916 function TfrmLog.GetDefaultFileName(const Name, Ext: String): String;
918 Result := StringReplace(Name, '/', '', [rfReplaceAll]);
919 Result := StringReplace(Result, ' ', '', [rfReplaceAll]);
920 Result := ChangeFileExt(Result, Ext);
923 function TfrmLog.BottleLogTitled(const LogName: String): TBottleLogList;
926 for i := 0 to FBottleLogList.Count-1 do begin
927 if (FBottleLogList[i] as TBottleLogList).Title = LogName then begin
928 Result := (FBottleLogList[i] as TBottleLogList);
932 //
\8c©
\82Â
\82©
\82ç
\82È
\82¢
\8fê
\8d\87
933 Result := TBottleLogList.Create(LogName); //
\90V
\82µ
\82
\8dì
\82é
934 FBottleLogList.Add(Result);
936 if FBottleLogList.Count = 1 then tabBottleLog.TabIndex := 0;
939 procedure TfrmLog.AllBottleOpened;
943 for i := 0 to FBottleLogList.Count-1 do begin
944 Log := FBottleLogList[i] as TBottleLogList;
945 for j := 0 to Log.Count-1 do begin
946 Log.Bottles[j].State := lsOpened;
951 procedure TfrmLog.tabBottleLogMouseDown(Sender: TObject;
952 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
955 with tabBottleLog do begin
956 Index := IndexOfTabAt(X, Y);
957 if Index = -1 then Exit; //
\83^
\83u
\82ª
\82È
\82¢
\82Ì
\82Å
\83h
\83\89\83b
\83O
\82Å
\82«
\82È
\82¢
958 if Button = mbLeft then begin
959 FDragTabIndex := Index; //
\83h
\83\89\83b
\83O
\82·
\82é
\83^
\83u
\82Ì
\83C
\83\93\83f
\83b
\83N
\83X
\82ð
\95Û
\91¶
961 FDragTabDest := -1; //
\83h
\83\89\83b
\83O
\98g
\90ü
\95`
\89æ
\83t
\83\89\83O
\83N
\83\8a\83A
\82Ì
\82½
\82ß
966 procedure TfrmLog.tabBottleLogDragOver(Sender, Source: TObject; X,
967 Y: Integer; State: TDragState; var Accept: Boolean);
968 var TargetRect: TRect;
971 Accept := Source = tabBottleLog;
972 if not Accept then Exit;
973 with tabBottleLog do begin
974 OldDest := FDragTabDest;
975 FDragTabDest := IndexOfTabAt(X, Y);
976 if FDragTabDest = -1 then begin
977 Accept := false; //
\82±
\82Ì
\8fê
\8d\87\82Í
\83h
\83\8d\83b
\83v
\82ð
\94F
\82ß
\82È
\82¢
984 if (OldDest <> FDragTabDest) and (OldDest >= 0) then begin
985 //
\88È
\91O
\82Ì
\98g
\90ü
\8fÁ
\8b\8e
986 TargetRect := TabRect(OldDest);
988 Brush.Style := bsClear;
989 Rectangle(TargetRect.Left, TargetRect.Top,
990 TargetRect.Right, TargetRect.Bottom);
993 if (OldDest <> FDragTabDest) then begin
994 //
\90V
\82µ
\82¢
\98g
\90ü
\95`
\89æ
995 TargetRect := TabRect(FDragTabDest);
997 Brush.Style := bsClear;
998 Rectangle(TargetRect.Left, TargetRect.Top,
999 TargetRect.Right, TargetRect.Bottom);
1005 procedure TfrmLog.tabBottleLogDragDrop(Sender, Source: TObject; X,
1007 var DestIndex: integer;
1009 with tabBottleLog do begin
1010 DestIndex := IndexOfTabAt(X, Y);
1011 Tabs.Move(FDragTabIndex, DestIndex);
1012 FBottleLogList.Move(FDragTabIndex, DestIndex);
1016 procedure TfrmLog.tabBottleLogEndDrag(Sender, Target: TObject; X,
1019 //
\8b
\90§
\93I
\82É
\83^
\83u
\82ð
\8dÄ
\95`
\89æ
\82³
\82¹
\82é
\81B
\98g
\90ü
\8fÁ
\82µ
\91Î
\8dô
1020 tabBottleLog.Tabs.BeginUpdate;
1021 tabBottleLog.Tabs.EndUpdate;
1024 procedure TfrmLog.LogLoadWork(Sender: TObject);
1026 if Sender = SelectedBottleLog then lvwLog.Invalidate;
1029 procedure TfrmLog.lvwLogDrawItem(Sender: TCustomListView; Item: TListItem;
1030 Rect: TRect; State: TOwnerDrawState);
1037 //
\94w
\8ci
\8fÁ
\8b\8e
1038 ListView_GetItemRect(lvwLog.Handle, Item.Index, DestRect, LVIR_BOUNDS);
1040 lvwLog.Canvas.Brush.Style := bsSolid;
1041 if Item.Selected then begin
1042 lvwLog.Canvas.Brush.Color := clHighlight
1044 lvwLog.Canvas.Brush.Color := Pref.BgColor;
1046 lvwLog.Canvas.FillRect(DestRect);
1047 lvwLog.Canvas.Brush.Style := bsClear;
1048 if Item.Focused and lvwLog.Focused then
1049 lvwLog.Canvas.DrawFocusRect(DestRect);
1051 if Item.Selected then
1052 lvwLog.Canvas.Font.Color := clHighlightText
1054 lvwLog.Canvas.Font.Color := Pref.TalkColorH;
1055 lvwLog.Canvas.Refresh;
1058 //
\83L
\83\83\83v
\83V
\83\87\83\93(
\93ú
\95t)
1059 ListView_GetItemRect(lvwLog.Handle, Item.Index, DestRect, LVIR_LABEL);
1060 Inc(DestRect.Left, 2);
1061 Inc(DestRect.Top, 2);
1062 Dec(DestRect.Right, 2);
1063 DrawTextEx(lvwLog.Canvas.Handle, PChar(Item.Caption), -1, DestRect,
1064 DT_SINGLELINE or DT_END_ELLIPSIS, nil);
1065 ListView_GetItemRect(lvwLog.Handle, Item.Index, DestRect, LVIR_ICON);
1066 Ico := TIcon.Create;
1068 lvwLog.SmallImages.GetIcon(Item.ImageIndex, Ico);
1069 lvwLog.Canvas.Draw(DestRect.Left, DestRect.Top, Ico);
1074 //
\83L
\83\83\83v
\83V
\83\87\83\93\88È
\8aO
1075 for sub := 0 to Item.SubItems.Count-1 do
1077 if sub = SubScript then Continue;
1078 ListView_GetSubItemRect(lvwLog.Handle, Item.Index, sub + 1,
1079 LVIR_BOUNDS, @DestRect);
1080 Inc(DestRect.Left, 2);
1081 Inc(DestRect.Top, 2);
1082 Dec(DestRect.Right, 2);
1083 if lvwLog.Columns[sub+1].Alignment = taRightJustify then
1084 Ex := DT_SINGLELINE or DT_END_ELLIPSIS or DT_RIGHT
1086 Ex := DT_SINGLELINE or DT_END_ELLIPSIS;
1087 DrawTextEx(lvwLog.Canvas.Handle, PChar(Item.SubItems[sub]), -1, DestRect,
1091 //
\83X
\83N
\83\8a\83v
\83g
1092 ListView_GetSubItemRect(lvwLog.Handle, Item.Index, SubScript + 1,
1093 LVIR_BOUNDS, @DestRect);
1094 Script := Item.SubItems[SubScript];
1095 DrawSingleLineScript(Script, DestRect, Item);
1098 procedure TfrmLog.DrawSingleLineScript(const Script: String;
1099 const Rect: TRect; Item: TListItem);
1102 UnyuTalking, Synchronized, Spaced: boolean;
1103 Mark: TSsMarkUpType;
1104 procedure ScopeChange;
1106 if (not Spaced) and (Pref.LogListPreviewStyle = psTagStripped) then
1113 SsParser.InputString := Script;
1115 UnyuTalking := false;
1116 Synchronized := false;
1117 Spaced := true; //
\83^
\83O
\8fÈ
\97ª
\95\
\8e¦
\8e\9e\82É
\95s
\95K
\97v
\82É
\83X
\83R
\81[
\83v
\95Ï
\8a·
\8e\9e\82Ì
\83X
\83y
\81[
\83X
\82ð
\8bó
\82¯
\82È
\82¢
1118 //
\82½
\82ß
\82Ì
\83t
\83\89\83O
1119 for i := 0 to SsParser.Count - 1 do begin
1120 if SsParser[i] = '\h' then
1122 UnyuTalking := false;
1124 end else if SsParser[i] = '\u' then
1126 UnyuTalking := true;
1128 end else if SsParser[i] = '\_s' then
1130 Synchronized := not Synchronized;
1133 Mark := SsParser.MarkUpType[i];
1137 lvwLog.Canvas.Font.Color := Pref.MetaWordColor;
1141 if Pref.LogListPreviewStyle = psNormal then
1142 lvwLog.Canvas.Font.Color := Pref.MarkUpColor
1148 lvwLog.Canvas.Font.Color := Pref.MarkErrorColor;
1151 if Synchronized then
1152 lvwLog.Canvas.Font.Color := Pref.TalkColorS
1153 else if UnyuTalking then
1154 lvwLog.Canvas.Font.Color := Pref.TalkColorU
1156 lvwLog.Canvas.Font.Color := Pref.TalkColorH;
1159 if Item.Selected then lvwLog.Canvas.Font.Color := clHighlightText;
1160 lvwLog.Canvas.Refresh;
1161 w := lvwLog.Canvas.TextWidth(SsParser[i]);
1162 lvwLog.Canvas.TextRect(Rect, Rect.Left + x, Rect.Top + 2, SsParser[i]);
1164 if Rect.Right - Rect.Left < x then Break;
1168 procedure TfrmLog.mnListPreviewStyleTagStrippedClick(Sender: TObject);
1171 with PopupMenuListPreviewStyle do
1172 for i := 0 to Items.Count-1 do
1173 Items[i].Checked := (Sender as TMenuItem).Tag = Items[i].Tag;
1174 Pref.LogListPreviewStyle := TLogListPreviewStyle((Sender as TMenuItem).Tag);
1178 procedure TfrmLog.tbtnListPreviewStyleClick(Sender: TObject);
1181 sel := Ord(Pref.LogListPreviewStyle);
1183 if sel > Ord(High(TLogListPreviewStyle)) then sel := 0;
1184 Pref.LogListPreviewStyle := TLogListPreviewStyle(sel);
1188 procedure TfrmLog.PopupMenuListPreviewStylePopup(Sender: TObject);
1191 with PopupMenuListPreviewStyle do
1192 for i := 0 to Items.Count-1 do
1193 Items[i].Checked := Items[i].Tag = Ord(Pref.LogListPreviewStyle)