6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, Grids, ExtCtrls, StdCtrls, Menus, ActnList, AbonInfo;
10 TNgEdit = class(TForm)
13 NgWordGrid: TStringGrid;
15 ButtonReload: TButton;
16 ButtonCancel: TButton;
31 SetInfButton: TButton;
32 InsRowButton: TButton;
33 AddRowButton: TButton;
34 DelRowButton: TButton;
35 AddColButton: TButton;
36 DelColButton: TButton;
37 RegExpButton: TButton;
38 ActionList: TActionList;
39 AddRowAction: TAction;
40 AddColAction: TAction;
41 InsRowAction: TAction;
42 DelColAction: TAction;
43 DelRowAction: TAction;
44 RegExpAction: TAction;
45 SetInfAction: TAction;
50 MnRegExpTest: TMenuItem;
51 procedure FormCreate(Sender: TObject);
52 procedure NgWordGridMouseUp(Sender: TObject; Button: TMouseButton;
53 Shift: TShiftState; X, Y: Integer);
54 procedure FormDestroy(Sender: TObject);
55 procedure ButtonOkClick(Sender: TObject);
56 procedure ButtonReloadClick(Sender: TObject);
57 procedure FormShow(Sender: TObject);
58 procedure AddRowActionExecute(Sender: TObject);
59 procedure AddColActionExecute(Sender: TObject);
60 procedure InsRowActionExecute(Sender: TObject);
61 procedure DelColActionExecute(Sender: TObject);
62 procedure DelRowActionExecute(Sender: TObject);
63 procedure RegExpActionExecute(Sender: TObject);
64 procedure SetInfActionExecute(Sender: TObject);
65 procedure MnStdAbnClick(Sender: TObject);
66 procedure MnTrnAbnClick(Sender: TObject);
67 procedure MnStdCmpClick(Sender: TObject);
68 procedure MnRegexpClick(Sender: TObject);
69 procedure MnAllThrClick(Sender: TObject);
70 procedure MnSpcThrClick(Sender: TObject);
71 procedure MnSpcBrdClick(Sender: TObject);
81 procedure DeleteInfo(Index: Integer);
82 function ParseLine(const Line: String; var NgList: TStringList): TLineInfo;
83 procedure DspLineNo(Row: Integer);
86 procedure SetFilePath(FilePath: String);
87 function GetReload: Boolean;
95 uses RegExpTester, AbonInfoSet, GikoSystem, MojuUtils;
100 procedure TNgEdit.FormCreate(Sender: TObject);
102 FInfoList := TList.Create;
105 Left := GikoSys.Setting.NGWindowLeft;
106 Top := GikoSys.Setting.NGWindowTop;
107 Width := GikoSys.Setting.NGWindowWidth;
108 Height := GikoSys.Setting.NGWindowHeight;
109 if (GikoSys.Setting.NGWindowMax = False) then
110 WindowState := wsNormal
112 WindowState := wsMaximized;
115 procedure TNgEdit.FormDestroy(Sender: TObject);
120 GikoSys.Setting.NGWindowLeft := Left;
121 GikoSys.Setting.NGWindowTop := Top;
122 GikoSys.Setting.NGWindowWidth := Width;
123 GikoSys.Setting.NGWindowHeight := Height;
124 if (WindowState = wsMaximized) then
125 GikoSys.Setting.NGWindowMax := True
127 GikoSys.Setting.NGWindowMax := False;
130 procedure TNgEdit.SetFilePath(FilePath: String);
132 FFilePath := FilePath;
135 procedure TNgEdit.FormShow(Sender: TObject);
142 NgWordGrid.RowCount := 2;
143 NgWordGrid.ColCount := 3;
144 NgWordGrid.ColWidths[0] := 27;
145 NgWordGrid.ColWidths[1] := 200;
146 NgWordGrid.Cells[0, 0] := 'No.';
147 NgWordGrid.Cells[1, 0] := '
\90Ý
\92è';
148 NgWordGrid.Cells[0, 1] := ' 1';
149 NgWordGrid.Cells[1, 1] := '';
150 NgWordGrid.Cells[2, 1] := '';
154 for Col := 2 to NgWordGrid.ColCount - 1 do
155 NgWordGrid.Cells[Col, 0] := 'NG
\83\8f\81[
\83h' + IntToStr(Col - 1);
157 if (FInfoList.Count = 0) then begin
158 inf := TLineInfo.Create;
160 NgWordGrid.Cells[1, 1] := inf.ToString;
164 function TNgEdit.GetReload: Boolean;
169 procedure TNgEdit.Load;
181 if (FFilePath = '') or (FileExists(FFilePath) = False) then
184 text := TStringList.Create;
185 line := TStringList.Create;
190 text.LoadFromFile(FFilePath);
192 max_line := text.Count - 1;
195 for idx := 0 to max_line do begin
196 inf := ParseLine(text.Strings[idx], line);
197 if (inf <> nil) then begin
200 ColCnt := line.Count + 2;
201 if (NgWordGrid.ColCount < ColCnt) then
202 NgWordGrid.ColCount := ColCnt;
204 if (NgWordGrid.RowCount <= Row) then
205 NgWordGrid.RowCount := Row + 1;
208 NgWordGrid.Cells[1, Row] := inf.ToString;
209 for Col := 2 to (ColCnt - 1) do begin
210 NgWordGrid.Cells[Col, Row] := line.Strings[Col - 2];
218 on e: Exception do begin
219 msg := 'NG
\83\8f\81[
\83h
\83t
\83@
\83C
\83\8b\82Ì
\93Ç
\82Ý
\8d\9e\82Ý
\82Å
\83G
\83\89\81[
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½
\81B' + #10 + e.Message;
220 Application.MessageBox(PChar(msg), 'NG
\83\8f\81[
\83h
\95Ò
\8fW', MB_OK or MB_ICONERROR);
228 procedure TNgEdit.DspLineNo(Row: Integer);
232 CellStr := ' ' + IntToStr(Row);
233 NgWordGrid.Cells[0, Row] := Copy(CellStr, Length(CellStr) - 3, 4);
236 procedure TNgEdit.Save;
247 if (FFilePath = '') then
250 text := TStringList.Create;
251 RowMax := NgWordGrid.RowCount - 1;
252 ColMax := NgWordGrid.ColCount - 1;
254 for Row := 1 to RowMax do begin
256 for Col := 2 to ColMax do begin
257 if (NgWordGrid.Cells[Col, Row] <> '') then begin
260 Line := Line + CustomStringReplace(NgWordGrid.Cells[Col, Row], #13#10, '');
263 if (Line <> '') then begin
264 if (FInfoList.Count >= Row) then begin
265 inf := TLineInfo(FInfoList.Items[Row - 1]);
267 if (inf.CompType = ctRegexp) then
268 Line := DEF_REGEXP + #9 + Line;
270 case inf.TargetType of
271 ttThread: Line := DEF_THREAD + inf.TargetThread + DEF_END + #9 + Line;
272 ttBoard: Line := DEF_BOARD + inf.TargetBoard + DEF_END + #9 + Line;
275 if (inf.AbonType = stTransparent) then
284 text.SaveToFile(FFilePath);
286 on e: Exception do begin
287 msg := 'NG
\83\8f\81[
\83h
\83t
\83@
\83C
\83\8b\82Ö
\82Ì
\95Û
\91¶
\82Å
\83G
\83\89\81[
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½
\81B' + #10 + e.Message;
288 Application.MessageBox(PChar(msg), 'NG
\83\8f\81[
\83h
\95Ò
\8fW', MB_OK or MB_ICONERROR);
295 function TNgEdit.ParseLine(const Line: String; var NgList: TStringList): TLineInfo;
306 if (src = '') then begin
311 inf := TLineInfo.Create;
313 if (src[1] = #9) then begin
314 inf.AbonType := stTransparent;
318 while (src <> '') do begin
320 if (idx > 0) then begin
321 NgWd := Copy(src, 1, idx - 1);
328 if (NgWd = DEF_REGEXP) then begin
329 inf.CompType := ctRegexp;
330 end else if (Pos(DEF_THREAD, NgWd) = 1) then begin
331 idx := Pos(DEF_END, NgWd);
332 if (idx > 1) then begin
333 len := idx - Length(DEF_THREAD) - 1;
334 inf.TargetThread := Copy(NgWd, Length(DEF_THREAD) + 1, len);
335 inf.TargetType := ttThread;
339 end else if (Pos(DEF_BOARD, NgWd) = 1) then begin
340 idx := Pos(DEF_END, NgWd);
341 if (idx > 1) then begin
342 len := idx - Length(DEF_BOARD) - 1;
343 inf.TargetBoard := Copy(NgWd, Length(DEF_BOARD) + 1, len);
344 inf.TargetType := ttBoard;
348 end else if (NgWd <> '') then begin
356 procedure TNgEdit.ClearInfo;
358 while (FInfoList.Count > 0) do begin
359 TLineInfo(FInfoList.Items[0]).Free;
364 procedure TNgEdit.DeleteInfo(Index: Integer);
366 if (Index >= 0) and (Index < FInfoList.Count) then begin
367 TLineInfo(FInfoList.Items[Index]).Free;
368 FInfoList.Delete(Index);
372 procedure TNgEdit.ButtonOkClick(Sender: TObject);
379 procedure TNgEdit.ButtonReloadClick(Sender: TObject);
386 procedure TNgEdit.AddRowActionExecute(Sender: TObject);
392 Row := NgWordGrid.RowCount;
393 NgWordGrid.RowCount := NgWordGrid.RowCount + 1;
397 inf := TLineInfo.Create;
399 NgWordGrid.Cells[1, Row] := inf.ToString;
401 for Col := 2 to NgWordGrid.ColCount - 1 do begin
402 NgWordGrid.Cells[Col, Row] := '';
405 NgWordGrid.Row := Row;
408 procedure TNgEdit.AddColActionExecute(Sender: TObject);
413 Col := NgWordGrid.ColCount;
414 NgWordGrid.ColCount := NgWordGrid.ColCount + 1;
416 NgWordGrid.Cells[Col, 0] := 'NG
\83\8f\81[
\83h' + IntToStr(Col - 1);
417 for Row := 1 to NgWordGrid.RowCount - 1 do begin
418 NgWordGrid.Cells[Col, Row] := '';
421 NgWordGrid.Col := Col;
424 procedure TNgEdit.InsRowActionExecute(Sender: TObject);
433 if (NgWordGrid.Row <= 0) or (NgWordGrid.Row >= NgWordGrid.RowCount) then
436 RowIns := NgWordGrid.Row;
437 RowMin := NgWordGrid.Row + 1;
438 RowMax := NgWordGrid.RowCount;
439 NgWordGrid.RowCount := NgWordGrid.RowCount + 1;
440 DspLineNo(NgWordGrid.RowCount - 1);
442 for Row := RowMax downto RowMin do begin
443 for Col := 1 to NgWordGrid.ColCount - 1 do begin
444 NgWordGrid.Cells[Col, Row] := NgWordGrid.Cells[Col, (Row - 1)];
448 inf := TLineInfo.Create;
449 FInfoList.Insert(RowIns - 1, inf);
450 NgWordGrid.Cells[1, RowIns] := inf.ToString;
452 for Col := 2 to NgWordGrid.ColCount - 1 do begin
453 NgWordGrid.Cells[Col, RowIns] := '';
458 procedure TNgEdit.DelColActionExecute(Sender: TObject);
466 if (NgWordGrid.ColCount <= 3) then
468 if (NgWordGrid.Col <= 1) or (NgWordGrid.Col >= NgWordGrid.ColCount) then
471 ColDel := NgWordGrid.Col;
472 for Row := 1 to NgWordGrid.RowCount - 1 do begin
473 if (NgWordGrid.Cells[ColDel, Row] <> '') then begin
474 if (Application.MessageBox('
\91I
\91ð
\82³
\82ê
\82½
\97ñ
\82É
\82ÍNG
\83\8f\81[
\83h
\82ª
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82Ü
\82·
\82ª
\8dí
\8f\9c\82µ
\82Ä
\82à
\82æ
\82ë
\82µ
\82¢
\82Å
\82·
\82©
\81H',
475 '
\91I
\91ð
\97ñ
\8dí
\8f\9c', MB_YESNO or MB_ICONQUESTION) = IDYES) then
483 ColMax := NgWordGrid.ColCount - 2;
485 for Row := 1 to NgWordGrid.RowCount - 1 do begin
486 for Col := ColMin to ColMax do begin
487 NgWordGrid.Cells[Col, Row] := NgWordGrid.Cells[Col + 1, Row];
491 NgWordGrid.ColCount := NgWordGrid.ColCount - 1;
495 procedure TNgEdit.DelRowActionExecute(Sender: TObject);
504 if (NgWordGrid.Row <= 0) or (NgWordGrid.Row >= NgWordGrid.RowCount) then
507 RowDel := NgWordGrid.Row;
509 for Col := 2 to NgWordGrid.ColCount - 1 do begin
510 if (NgWordGrid.Cells[Col, RowDel] <> '') then begin
511 if (Application.MessageBox('
\91I
\91ð
\82³
\82ê
\82½
\8ds
\82É
\82ÍNG
\83\8f\81[
\83h
\82ª
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82Ü
\82·
\82ª
\8dí
\8f\9c\82µ
\82Ä
\82à
\82æ
\82ë
\82µ
\82¢
\82Å
\82·
\82©
\81H',
512 '
\91I
\91ð
\8ds
\8dí
\8f\9c', MB_YESNO or MB_ICONQUESTION) = IDYES) then
519 if (FInfoList.Count = 1) then begin
520 for Col := 1 to NgWordGrid.ColCount - 1 do begin
521 NgWordGrid.Cells[Col, 1] := '';
523 DeleteInfo(RowDel - 1);
524 inf := TLineInfo.Create;
526 NgWordGrid.Cells[1, 1] := inf.ToString;
529 RowMax := NgWordGrid.RowCount - 2;
531 for Row := RowMin to RowMax do begin
532 for Col := 1 to NgWordGrid.ColCount - 1 do begin
533 NgWordGrid.Cells[Col, Row] := NgWordGrid.Cells[Col, Row + 1];
537 NgWordGrid.RowCount := NgWordGrid.RowCount - 1;
538 DeleteInfo(RowDel - 1);
542 procedure TNgEdit.RegExpActionExecute(Sender: TObject);
547 Dlg := TRegExpTest.Create(Self);
549 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) and
550 (NgWordGrid.Col > 1) and (NgWordGrid.Col < NgWordGrid.ColCount) then begin
551 if (NgWordGrid.Cells[NgWordGrid.Col, NgWordGrid.Row] <> '') then begin
552 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
553 if (inf.CompType = ctRegexp) then
554 Dlg.SetRegExp(NgWordGrid.Cells[NgWordGrid.Col, NgWordGrid.Row]);
563 procedure TNgEdit.SetInfActionExecute(Sender: TObject);
568 if (NgWordGrid.Row <= 0) or (NgWordGrid.Row >= NgWordGrid.RowCount) then
571 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
573 Dlg := TAbonInfoEdit.Create(Self);
576 if (Dlg.ShowModal = mrOk) then begin
578 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
584 procedure TNgEdit.NgWordGridMouseUp(Sender: TObject; Button: TMouseButton;
585 Shift: TShiftState; X, Y: Integer);
593 if (Button = mbRight) then begin
594 NgWordGrid.MouseToCell(X, Y, Col, Row);
595 if (Col >= 0) and (Row > 0) then begin
596 inf := TLineInfo(FInfoList.Items[Row - 1]);
597 if (inf.AbonType = stTransparent) then begin
598 MnStdAbn.Checked := False;
599 MnTrnAbn.Checked := True;
601 MnStdAbn.Checked := True;
602 MnTrnAbn.Checked := False;
604 case inf.TargetType of
606 MnAllThr.Checked := False;
607 MnSpcThr.Checked := True;
608 MnSpcBrd.Checked := False;
611 MnAllThr.Checked := False;
612 MnSpcThr.Checked := False;
613 MnSpcBrd.Checked := True;
616 MnAllThr.Checked := True;
617 MnSpcThr.Checked := False;
618 MnSpcBrd.Checked := False;
621 if (inf.CompType = ctRegexp) then begin
622 MnStdCmp.Checked := False;
623 MnRegexp.Checked := True;
625 MnRegExpTest.Enabled := True
627 MnRegExpTest.Enabled := False;
629 MnStdCmp.Checked := True;
630 MnRegexp.Checked := False;
631 MnRegExpTest.Enabled := False;
634 MnDelCol.Enabled := True
636 MnDelCol.Enabled := False;
638 NgWordGrid.Row := Row;
640 NgWordGrid.Col := Col;
641 MousePos.X := X + NgWordGrid.Left;
642 MousePos.Y := Y + NgWordGrid.Top;
643 MenuPos := Self.ClientToScreen(MousePos);
644 GridMenu.Popup(MenuPos.X, MenuPos.Y);
649 procedure TNgEdit.MnStdAbnClick(Sender: TObject);
653 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
654 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
655 inf.AbonType := atStandard;
656 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
660 procedure TNgEdit.MnTrnAbnClick(Sender: TObject);
664 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
665 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
666 inf.AbonType := stTransparent;
667 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
671 procedure TNgEdit.MnStdCmpClick(Sender: TObject);
675 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
676 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
677 inf.CompType := ctStandard;
678 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
682 procedure TNgEdit.MnRegexpClick(Sender: TObject);
686 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
687 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
688 inf.CompType := ctRegexp;
689 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
693 procedure TNgEdit.MnAllThrClick(Sender: TObject);
697 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
698 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
699 inf.TargetType := ttAll;
700 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
704 procedure TNgEdit.MnSpcThrClick(Sender: TObject);
708 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
709 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
710 inf.TargetType := ttThread;
711 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
712 SetInfActionExecute(nil);
716 procedure TNgEdit.MnSpcBrdClick(Sender: TObject);
720 if (NgWordGrid.Row > 0) and (NgWordGrid.Row < NgWordGrid.RowCount) then begin
721 inf := TLineInfo(FInfoList.Items[NgWordGrid.Row - 1]);
722 inf.TargetType := ttBoard;
723 NgWordGrid.Cells[1, NgWordGrid.Row] := inf.ToString;
724 SetInfActionExecute(nil);