OSDN Git Service

まちBBSで削除レスがあるレス番号とスレの件数がずれる不具合を修正
[gikonavigoeson/gikonavi.git] / InputAssist.pas
index d6da126..fafc3a1 100644 (file)
@@ -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 \90é\8c¾ }
        FSortColumn : Integer;
+       FInsertText : String;
        procedure AddListViewItem(ResWord : TResistWord);
+    procedure SetCategory(combo: TComboBox; selected: String);
+    function ValidateKey(key, category: String): boolean;
   public
-    { Public \90é\8c¾ }
+       { Public \90é\8c¾ }
+       procedure SetUpFromEditor();
+       procedure SetUpFromMain();
+       function GetInsertText(): String;
   end;
 
 var
@@ -54,14 +80,29 @@ var
 
 implementation
 
+uses Setting, MojuUtils;
+
 
 {$R *.dfm}
 //! \83t\83H\81[\83\80\90\90¬\82Ì\83C\83x\83\93\83g
 procedure TInputAssistForm.FormCreate(Sender: TObject);
 var
+       wp: TWindowPlacement;
        i : Integer;
        column: TListColumn;
 begin
+       //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
+       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('\83L\81[\96¼\82ð\90Ý\92è\82µ\82Ä\82­\82¾\82³\82¢\81B');
-       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('\93¯\88ê\82Ì\83L\81[\96¼\81E\83J\83e\83S\83\8a\96¼\82Å\8aù\82É\93o\98^\8dÏ\82Ý\82Å\82·\81B');
+               end;
        end;
 end;
+//! \83L\81[\96¼\81E\83J\83e\83S\83\8a\97L\8cø\83`\83F\83b\83N
+function TInputAssistForm.ValidateKey(key, category: String): boolean;
+begin
+    Result := True;
+    if (Length(key) = 0) then begin
+        ShowMessage('\83L\81[\96¼\82ð\90Ý\92è\82µ\82Ä\82­\82¾\82³\82¢\81B');
+        Result := False;
+    end else begin
+        if (Length(category) = 0) then begin
+            ShowMessage('\83J\83e\83S\83\8a\82ð\90Ý\92è\82µ\82Ä\82­\82¾\82³\82¢\81B');
+            Result := False;
+        end;
+    end;
+end;
+
 //! \8dí\8f\9c\83{\83^\83\93\89\9f\89º\8e\9e\82Ì\83C\83x\83\93\83g
 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('\83L\81[\96¼\82ð\96³\82µ\82É\82Í\82Å\82«\82Ü\82¹\82ñ\81B');
-               end else begin
-                       resWord := TResistWord(GikoListView1.Selected.Data);
-                       resWord.SetKey(KeyNameEdit.Text);
-                       resWord.SetCategory(CategoryNameEdit.Text);
-                       resWord.SetText(TextMemo.Text);
-                       // \88ê\97\97\82Ì\8dX\90V
-                       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);
+            // \95Ï\8dX\91O\82Ì\83L\81[\81^\83J\83e\83S\83\8a\82Æ\93¯\88ê\82à\82µ\82­\82Í\81A\91¼\82Æ\8fd\95¡\96³\82µ
+            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);
+                // \83L\81[\82ª\95Ï\82í\82é\82Æ\82«\82Í\81AChangeKey\82ð\8cÄ\82Ô
+                if (resWord.GetKey <> KeyNameEdit.Text) then begin
+                               resWord.SetKey(KeyNameEdit.Text);
+                    InputAssistDM.ChangeKey(resWord);
+                end;
+                       // \88ê\97\97\82Ì\8dX\90V
+                           GikoListView1.Selected.Caption := resWord.GetKey;
+                       GikoListView1.Selected.SubItems[0] := resWord.GetCategory;
+                SetCategory(CategoryNameComboBox, resWord.GetCategory);
+                       GikoListView1.AlphaSort;
+               end else begin
+                       ShowMessage('\93¯\88ê\82Ì\83L\81[\96¼\81E\83J\83e\83S\83\8a\96¼\82Å\8aù\82É\93o\98^\8dÏ\82Ý\82Å\82·\81B');
+                   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;
        //\83\\81[\83g\8fó\91Ô\82Ì\90Ý\92è
        InputAssistDM.Sorted := True;
 end;
@@ -157,15 +232,19 @@ procedure TInputAssistForm.GikoListView1Compare(Sender: TObject; Item1,
 begin
        if ((FSortColumn and 2) > 0) then begin
                // \83J\83e\83S\83\8a\82Å\83\\81[\83g
-               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
                // \83L\81[\82Å\83\\81[\83g
-               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;
        // \8f¸\8f\87\8d~\8f\87\82Ì\94½\93]
@@ -210,5 +289,181 @@ procedure TInputAssistForm.CloseButtonClick(Sender: TObject);
 begin
        Close();
 end;
+//! \83J\83e\83S\83\8a\8di\8d\9e\82Ý\83R\83\93\83{\83{\83b\83N\83X\82ð\93Ç\8eæ\90ê\97p\82É\82·\82é\82½\82ß\82Ì\83C\83x\83\93\83g\8f\88\97\9d
+procedure TInputAssistForm.CategoryComboBoxKeyPress(Sender: TObject;
+  var Key: Char);
+begin
+       Key := #0;
+end;
+//! \83J\83e\83S\83\8a\8di\8d\9e\82Ý\83R\83\93\83{\83{\83b\83N\83X\82Å\82Ì\83J\83e\83S\83\8a\95Ï\8dX\8f\88\97\9d
+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;
+//! \83J\83e\83S\83\8a\83R\83\93\83{\83{\83b\83N\83X\90Ý\92è
+procedure TInputAssistForm.SetCategory(combo: TComboBox; selected: String);
+var
+       cat : TStringList;
+    i : Integer;
+begin
+       // \8c\9f\8dõ\97p
+       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;
+        // \91I\91ð\8dÏ\82Ý\82Ì\83J\83e\83S\83\8a\82É\83C\83\93\83f\83b\83N\83X\82ð\95Ï\8dX
+        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 := '\93ü\97Í\83A\83V\83X\83g\90Ý\92è';
+       Panel3.Visible := True;
+       Panel5.Visible := True;
+       Panel7.Visible := False;
+       TextMemo.ReadOnly := False;
+       FInsertText := '';
+       CloseAction.ShortCut := TShortCut(0);
+       // \92Ç\89Á\97p\83L\81[\93ü\97ÍOK
+    SetCategory(CategoryNameComboBox, '');
+end;
+procedure TInputAssistForm.SetUpFromEditor();
+begin
+       Self.Caption := '\93ü\97Í\83A\83V\83X\83g';
+       Panel3.Visible := False;
+       Panel5.Visible := False;
+       Panel7.Visible := True;
+       TextMemo.ReadOnly := True;
+       FInsertText := '';
+       CloseAction.ShortCut := ShortCut(VK_ESCAPE, []);
+       // \8c\9f\8dõ\97p
+    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\83t\83@\83C\83\8b\82ª\92è\8b`\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B', '\8d·\95ª\93o\98^', MB_OK or MB_ICONERROR);
+        Exit;
+    end;
+
+    DefPath := GikoSys.GetAppDir + DefPath;
+    if (FileExists(DefPath) = False) then begin
+        Application.MessageBox('default\83t\83@\83C\83\8b\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ\81B', '\8d·\95ª\93o\98^', 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) + '\8c\8f\93o\98^\82µ\82Ü\82µ\82½\81B';
+    Application.MessageBox(PChar(ResMsg), '\8d·\95ª\93o\98^', MB_OK or MB_ICONINFORMATION);
+end;
 
 end.