X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=InputAssist.pas;h=fafc3a1f36ff0a58c4cced0c58bd73714bee1208;hb=99f2be3a17dfec20c0edcaaa09e20c39a74d3af9;hp=d6da126925ae4c9741ab2c1ecdc8cccd7b4d9b0f;hpb=4a63acc572e185dc893439c46a1dbe1ed6c38928;p=gikonavigoeson%2Fgikonavi.git diff --git a/InputAssist.pas b/InputAssist.pas index d6da126..fafc3a1 100644 --- a/InputAssist.pas +++ b/InputAssist.pas @@ -5,23 +5,17 @@ interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, GikoListView, Menus, ExtCtrls, ImgList, - InputAssistDataModule, StdActns, ActnList; + InputAssistDataModule, StdActns, ActnList, GikoSystem, IniFiles; type TInputAssistForm = class(TForm) Panel1: TPanel; Panel2: TPanel; GikoListView1: TGikoListView; - DeleteButton: TButton; - AddButton: TButton; - ApplyButton: TButton; Panel3: TPanel; - KeyNameEdit: TLabeledEdit; - CategoryNameEdit: TLabeledEdit; - Panel4: TPanel; - TextMemo: TMemo; + Panel4: TPanel; + TextMemo: TMemo; ColumnImageList: TImageList; - CloseButton: TButton; InputAssistFormActionList: TActionList; EditCut1: TEditCut; EditCopy1: TEditCopy; @@ -29,6 +23,26 @@ type EditSelectAll1: TEditSelectAll; EditUndo1: TEditUndo; EditDelete1: TEditDelete; + GroupBox1: TGroupBox; + Panel5: TPanel; + CloseButton: TButton; + ApplyButton: TButton; + DeleteButton: TButton; + AddButton: TButton; + Panel6: TPanel; + Panel7: TPanel; + CategoryComboBox: TComboBox; + CategoryComboLabel: TLabel; + InsertButton: TButton; + InsertButtonAction: TAction; + CloseAction: TAction; + KeyPanel: TPanel; + KeyNameEdit: TLabeledEdit; + Splitter: TSplitter; + CategoryPanel: TPanel; + CategoryNameComboBox: TComboBox; + CategoryNameLabel: TLabel; + DiffButton: TButton; procedure FormCreate(Sender: TObject); procedure GikoListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); @@ -41,12 +55,24 @@ type procedure GikoListView1ColumnClick(Sender: TObject; Column: TListColumn); procedure CloseButtonClick(Sender: TObject); + procedure CategoryComboBoxKeyPress(Sender: TObject; var Key: Char); + procedure CategoryComboBoxChange(Sender: TObject); + procedure InsertButtonActionUpdate(Sender: TObject); + procedure InsertButtonActionExecute(Sender: TObject); + procedure CloseActionExecute(Sender: TObject); + procedure DiffButtonClick(Sender: TObject); private { Private éŒ¾ } FSortColumn : Integer; + FInsertText : String; procedure AddListViewItem(ResWord : TResistWord); + procedure SetCategory(combo: TComboBox; selected: String); + function ValidateKey(key, category: String): boolean; public - { Public éŒ¾ } + { Public éŒ¾ } + procedure SetUpFromEditor(); + procedure SetUpFromMain(); + function GetInsertText(): String; end; var @@ -54,14 +80,29 @@ var implementation +uses Setting, MojuUtils; + {$R *.dfm} //! ƒtƒH[ƒ€¶¬‚̃Cƒxƒ“ƒg procedure TInputAssistForm.FormCreate(Sender: TObject); var + wp: TWindowPlacement; i : Integer; column: TListColumn; begin + //ƒEƒBƒ“ƒhƒE‚̈ʒuÝ’è + wp.length := sizeof(wp); + wp.rcNormalPosition.Top := GikoSys.Setting.InputAssistFormTop; + wp.rcNormalPosition.Left := GikoSys.Setting.InputAssistFormLeft; + + wp.rcNormalPosition.Bottom := GikoSys.Setting.InputAssistFormTop + + GikoSys.Setting.InputAssistFormHeight; + wp.rcNormalPosition.Right := GikoSys.Setting.InputAssistFormLeft + + GikoSys.Setting.InputAssistFormWidth; + wp.showCmd := SW_HIDE; + SetWindowPlacement(Handle, @wp); + FSortColumn := 0; GikoListView1.Columns.Clear; column := GikoListView1.Columns.Add; @@ -94,7 +135,7 @@ procedure TInputAssistForm.GikoListView1SelectItem(Sender: TObject; begin if (Item <> nil) and (Item.Data <> nil) then begin KeyNameEdit.Text := TResistWord(Item.Data).GetKey; - CategoryNameEdit.Text := TResistWord(Item.Data).GetCategory; + CategoryNameComboBox.Text := TResistWord(Item.Data).GetCategory; TextMemo.Lines.Text := TResistWord(Item.Data).GetText; end else begin TextMemo.Lines.Text := ''; @@ -105,16 +146,35 @@ procedure TInputAssistForm.AddButtonClick(Sender: TObject); var resWord : TResistWord; begin - if (Length(KeyNameEdit.Text) = 0) then begin - ShowMessage('ƒL[–¼‚ðÝ’肵‚Ä‚­‚¾‚³‚¢B'); - end else begin - resWord := InputAssistDM.Add(KeyNameEdit.Text); - resWord.SetCategory(CategoryNameEdit.Text); - resWord.SetText(TextMemo.Text); - AddListViewItem(resWord); - GikoListView1.AlphaSort; + if (ValidateKey(KeyNameEdit.Text, CategoryNameComboBox.Text)) then begin + if (not InputAssistDM.IsDupulicate( + KeyNameEdit.Text, CategoryNameComboBox.Text) ) then begin + resWord := InputAssistDM.Add(KeyNameEdit.Text); + resWord.SetCategory(CategoryNameComboBox.Text); + resWord.SetText(TextMemo.Text); + AddListViewItem(resWord); + SetCategory(CategoryNameComboBox, resWord.GetCategory); + GikoListView1.AlphaSort; + end else begin + ShowMessage('“¯ˆê‚̃L[–¼EƒJƒeƒSƒŠ–¼‚ÅŠù‚É“o˜^Ï‚Ý‚Å‚·B'); + end; end; end; +//! ƒL[–¼EƒJƒeƒSƒŠ—LŒøƒ`ƒFƒbƒN +function TInputAssistForm.ValidateKey(key, category: String): boolean; +begin + Result := True; + if (Length(key) = 0) then begin + ShowMessage('ƒL[–¼‚ðÝ’肵‚Ä‚­‚¾‚³‚¢B'); + Result := False; + end else begin + if (Length(category) = 0) then begin + ShowMessage('ƒJƒeƒSƒŠ‚ðÝ’肵‚Ä‚­‚¾‚³‚¢B'); + Result := False; + end; + end; +end; + //! íœƒ{ƒ^ƒ“‰Ÿ‰ºŽž‚̃Cƒxƒ“ƒg procedure TInputAssistForm.DeleteButtonClick(Sender: TObject); begin @@ -130,17 +190,28 @@ var resWord : TResistWord; begin if GikoListView1.Selected <> nil then begin - if (Length(KeyNameEdit.Text) = 0) then begin - ShowMessage('ƒL[–¼‚𖳂µ‚É‚Í‚Å‚«‚Ü‚¹‚ñB'); - end else begin - resWord := TResistWord(GikoListView1.Selected.Data); - resWord.SetKey(KeyNameEdit.Text); - resWord.SetCategory(CategoryNameEdit.Text); - resWord.SetText(TextMemo.Text); - // ˆê——‚̍XV - GikoListView1.Selected.Caption := resWord.GetKey; - GikoListView1.Selected.SubItems[0] := resWord.GetCategory; - GikoListView1.AlphaSort; + if (ValidateKey(KeyNameEdit.Text, CategoryNameComboBox.Text)) then begin + resWord := TResistWord(GikoListView1.Selected.Data); + // •ÏX‘O‚̃L[^ƒJƒeƒSƒŠ‚Æ“¯ˆê‚à‚µ‚­‚́A‘¼‚Əd•¡–³‚µ + if ((resWord.GetKey = KeyNameEdit.Text) + and (resWord.GetCategory = CategoryNameComboBox.Text)) or + (not InputAssistDM.IsDupulicate( + KeyNameEdit.Text, CategoryNameComboBox.Text) ) then begin + resWord.SetCategory(CategoryNameComboBox.Text); + resWord.SetText(TextMemo.Text); + // ƒL[‚ª•Ï‚í‚é‚Æ‚«‚́AChangeKey‚ðŒÄ‚Ô + if (resWord.GetKey <> KeyNameEdit.Text) then begin + resWord.SetKey(KeyNameEdit.Text); + InputAssistDM.ChangeKey(resWord); + end; + // ˆê——‚̍XV + GikoListView1.Selected.Caption := resWord.GetKey; + GikoListView1.Selected.SubItems[0] := resWord.GetCategory; + SetCategory(CategoryNameComboBox, resWord.GetCategory); + GikoListView1.AlphaSort; + end else begin + ShowMessage('“¯ˆê‚̃L[–¼EƒJƒeƒSƒŠ–¼‚ÅŠù‚É“o˜^Ï‚Ý‚Å‚·B'); + end; end; end; end; @@ -148,6 +219,10 @@ end; procedure TInputAssistForm.FormClose(Sender: TObject; var Action: TCloseAction); begin + GikoSys.Setting.InputAssistFormTop := Self.Top; + GikoSys.Setting.InputAssistFormLeft := Self.Left; + GikoSys.Setting.InputAssistFormHeight := Self.Height; + GikoSys.Setting.InputAssistFormWidth := Self.Width; //ƒ\[ƒgó‘Ԃ̐ݒè InputAssistDM.Sorted := True; end; @@ -157,15 +232,19 @@ procedure TInputAssistForm.GikoListView1Compare(Sender: TObject; Item1, begin if ((FSortColumn and 2) > 0) then begin // ƒJƒeƒSƒŠ‚Ń\[ƒg - Compare := AnsiCompareStr(Item1.SubItems[0], Item2.SubItems[0]); + Compare := CompareStr( + ZenToHan(Item1.SubItems[0]), ZenToHan(Item2.SubItems[0])); if (Compare = 0) then begin - Compare := AnsiCompareStr(Item1.Caption, Item2.Caption); + Compare := CompareStr( + ZenToHan(Item1.Caption), ZenToHan(Item2.Caption)); end; end else begin // ƒL[‚Ń\[ƒg - Compare := AnsiCompareStr(Item1.Caption, Item2.Caption); + Compare := CompareStr( + ZenToHan(Item1.Caption), ZenToHan(Item2.Caption)); if (Compare = 0) then begin - Compare := AnsiCompareStr(Item1.SubItems[0], Item2.SubItems[0]); + Compare := CompareStr( + ZenToHan(Item1.SubItems[0]), ZenToHan(Item2.SubItems[0])); end; end; // ¸‡~‡‚Ì”½“] @@ -210,5 +289,181 @@ procedure TInputAssistForm.CloseButtonClick(Sender: TObject); begin Close(); end; +//! ƒJƒeƒSƒŠiž‚݃Rƒ“ƒ{ƒ{ƒbƒNƒX‚ð“ÇŽæê—p‚É‚·‚邽‚߂̃Cƒxƒ“ƒgˆ— +procedure TInputAssistForm.CategoryComboBoxKeyPress(Sender: TObject; + var Key: Char); +begin + Key := #0; +end; +//! ƒJƒeƒSƒŠiž‚݃Rƒ“ƒ{ƒ{ƒbƒNƒX‚ł̃JƒeƒSƒŠ•ÏXˆ— +procedure TInputAssistForm.CategoryComboBoxChange(Sender: TObject); +var + i : Integer; + key : String; +begin + LockWindowUpdate(GikoListView1.Handle); + GikoListView1.Clear; + if (CategoryComboBox.ItemIndex <= 0) then begin + for i := 0 to InputAssistDM.ResistWordCount - 1 do begin + AddListViewItem(InputAssistDM.GetResistWord(i)); + end; + end else begin + key := CategoryComboBox.Items[CategoryComboBox.ItemIndex]; + for i := 0 to InputAssistDM.ResistWordCount - 1 do begin + if (key = InputAssistDM.GetResistWord(i).GetCategory) then begin + AddListViewItem(InputAssistDM.GetResistWord(i)); + end; + end; + end; + LockWindowUpdate(0); +end; +//! ƒJƒeƒSƒŠƒRƒ“ƒ{ƒ{ƒbƒNƒXÝ’è +procedure TInputAssistForm.SetCategory(combo: TComboBox; selected: String); +var + cat : TStringList; + i : Integer; +begin + // ŒŸõ—p + cat := TStringList.Create; + try + InputAssistDM.GetCategoryList(cat); + combo.Items.BeginUpdate; + combo.Items.Clear; + combo.Items.Add(''); + combo.Items.AddStrings(cat); + combo.ItemIndex := 0; + combo.Items.EndUpdate; + // ‘I‘ðÏ‚݂̃JƒeƒSƒŠ‚ɃCƒ“ƒfƒbƒNƒX‚ð•ÏX + i := combo.Items.IndexOf(selected); + if (i <> -1) then begin + combo.ItemIndex := i; + end; + finally + cat.Free; + end; +end; + +procedure TInputAssistForm.SetUpFromMain(); +begin + Self.Caption := '“ü—̓AƒVƒXƒgÝ’è'; + Panel3.Visible := True; + Panel5.Visible := True; + Panel7.Visible := False; + TextMemo.ReadOnly := False; + FInsertText := ''; + CloseAction.ShortCut := TShortCut(0); + // ’ljÁ—pƒL[“ü—ÍOK + SetCategory(CategoryNameComboBox, ''); +end; +procedure TInputAssistForm.SetUpFromEditor(); +begin + Self.Caption := '“ü—̓AƒVƒXƒg'; + Panel3.Visible := False; + Panel5.Visible := False; + Panel7.Visible := True; + TextMemo.ReadOnly := True; + FInsertText := ''; + CloseAction.ShortCut := ShortCut(VK_ESCAPE, []); + // ŒŸõ—p + SetCategory(CategoryComboBox, ''); +end; +function TInputAssistForm.GetInsertText(): String; +begin + Result := FInsertText; +end; + +procedure TInputAssistForm.InsertButtonActionUpdate(Sender: TObject); +begin + InsertButtonAction.Enabled := (GikoListView1.Selected <> nil); +end; + +procedure TInputAssistForm.InsertButtonActionExecute(Sender: TObject); +begin + if (GikoListView1.Selected = nil) then begin + FInsertText := ''; + Self.ModalResult := mrNone; + end else begin + FInsertText := TResistWord(GikoListView1.Selected.Data).GetText; + Self.ModalResult := mrOk; + end; +end; + +procedure TInputAssistForm.CloseActionExecute(Sender: TObject); +begin + Self.ModalResult := mrCancel; +end; + +procedure TInputAssistForm.DiffButtonClick(Sender: TObject); +var + ini: TIniFile; + DefPath: String; + SecList: TStringList; + KeyList: TStringList; + Cnt: Integer; + Cnt2: Integer; + MaxCnt: Integer; + MaxCnt2: Integer; + RegCnt: Integer; + DatString: String; + resWord : TResistWord; + ResMsg: String; +begin + ini := TIniFile.Create(GikoSys.Setting.GetDefaultFilesFileName); + DefPath := ini.ReadString('InputAssist', 'FROM', ''); + ini.Free; + if (DefPath = '') then begin + Application.MessageBox('defaultƒtƒ@ƒCƒ‹‚ª’è‹`‚³‚ê‚Ä‚¢‚Ü‚¹‚ñB', '·•ª“o˜^', MB_OK or MB_ICONERROR); + Exit; + end; + + DefPath := GikoSys.GetAppDir + DefPath; + if (FileExists(DefPath) = False) then begin + Application.MessageBox('defaultƒtƒ@ƒCƒ‹‚ªŒ©‚‚©‚è‚Ü‚¹‚ñB', '·•ª“o˜^', MB_OK or MB_ICONERROR); + Exit; + end; + + RegCnt := 0; + SecList := TStringList.Create; + ini := TIniFile.Create(DefPath); + + ini.ReadSections(SecList); + if (SecList.Count > 0) then begin + KeyList := TStringList.Create; + MaxCnt := SecList.Count - 1; + for Cnt := 0 to MaxCnt do begin; + KeyList.Clear; + ini.ReadSection(SecList.Strings[Cnt], KeyList); + if (KeyList.Count > 0) then begin; + MaxCnt2 := KeyList.Count - 1; + for Cnt2 := 0 to MaxCnt2 do begin + DatString := ini.ReadString(SecList.Strings[Cnt], KeyList.Strings[Cnt2], ''); + if (DatString = '') then + Continue; + + if (not InputAssistDM.IsDupulicate( + KeyList.Strings[Cnt2], SecList.Strings[Cnt]) ) then begin + resWord := InputAssistDM.Add(KeyList.Strings[Cnt2]); + resWord.SetCategory(SecList.Strings[Cnt]); + resWord.SetText(DatString); + AddListViewItem(resWord); + RegCnt := RegCnt + 1; + end; + end; + end; + end; + KeyList.Free; + end; + + ini.Free; + SecList.Free; + + if (RegCnt > 0) then begin + SetCategory(CategoryNameComboBox, ''); + GikoListView1.AlphaSort; + end; + + ResMsg := IntToStr(RegCnt) + 'Œ“o˜^‚µ‚Ü‚µ‚½B'; + Application.MessageBox(PChar(ResMsg), '·•ª“o˜^', MB_OK or MB_ICONINFORMATION); +end; end.