OSDN Git Service

マウスジェスチャの追加。
[gikonavigoeson/gikonavi.git] / KeySetting.pas
index 1b0e9d5..1c52d85 100644 (file)
@@ -12,9 +12,11 @@ type
        private
                FAction: TAction;
                FShortCut: TShortCut;
+               FGesture        : string;
        public
                property Action: TAction read FAction write FAction;
                property ShortCut: TShortCut read FShortCut write FShortCut;
+               property Gesture : string read FGesture write FGesture;
        end;
 
        TKeySettingForm = class(TForm)
@@ -34,6 +36,9 @@ type
     TabSheet2: TTabSheet;
     ListView: TListView;
     ListView1: TListView;
+    GestureLabel: TLabel;
+    GestureEdit: TEdit;
+    GestureSetButton: TButton;
                procedure FormCreate(Sender: TObject);
                procedure FormDestroy(Sender: TObject);
     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
@@ -46,6 +51,10 @@ type
     procedure OkBottonClick(Sender: TObject);
     procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem;
       Data: Integer; var Compare: Integer);
+    procedure GestureSetButtonClick(Sender: TObject);
+               procedure OnGestureStart(Sender: TObject);
+               procedure OnGestureMove(Sender: TObject);
+               procedure OnGestureEnd(Sender: TObject);
        private
                { Private \90é\8c¾ }
        public
@@ -58,7 +67,7 @@ type
 
 implementation
 
-uses Giko;
+uses Giko, Gesture;
 
 {$R *.dfm}
 
@@ -69,6 +78,10 @@ var
        KeyItem: TKeySettingItem;
 
 begin
+       MouseGesture.OnGestureStart := OnGestureStart;
+       MouseGesture.OnGestureMove := OnGestureMove;
+       MouseGesture.OnGestureEnd := OnGestureEnd;
+       MouseGesture.SetHook( Handle );
        for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
                if GikoForm.ActionList.Actions[i] is TAction then begin
                        if GikoForm.ActionList.Actions[i].Tag <> 0 then
@@ -77,42 +90,50 @@ begin
                        ListItem.Caption := TAction(GikoForm.ActionList.Actions[i]).Hint;
                        ListItem.SubItems.Add(TAction(GikoForm.ActionList.Actions[i]).Category);
                        ListItem.SubItems.Add(ShortCutToText(TAction(GikoForm.ActionList.Actions[i]).ShortCut));
+                       ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
+                               TAction( GikoForm.ActionList.Actions[i] ) ) );
                        ListItem.ImageIndex := TAction(GikoForm.ActionList.Actions[i]).ImageIndex;
                        KeyItem := TKeySettingItem.Create;
                        KeyItem.Action := TAction(GikoForm.ActionList.Actions[i]);
                        KeyItem.ShortCut := TAction(GikoForm.ActionList.Actions[i]).ShortCut;
+                       KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
+                               TAction( GikoForm.ActionList.Actions[i] ) );
                        ListItem.Data := KeyItem;
                end;
        end;
        if ListView.Items.Count > 0 then
                ListView.Selected := ListView.Items[0];
-    EditorForm := TEditorForm.Create(Self);
-    GikoSys.LoadEditorKeySetting(EditorForm.ActionList);
-    try
-        for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
-            if EditorForm.ActionList.Actions[i] is TAction then begin
-                if EditorForm.ActionList.Actions[i].Tag <> 0 then
-                    Continue;
-                ListItem := ListView1.Items.Add;
-                ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
-                ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
-                ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
-                ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
-                KeyItem := TKeySettingItem.Create;
-                KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
-                KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
-                ListItem.Data := KeyItem;
-            end;
-        end;
-        ListView1.SmallImages := EditorForm.HotToobarImageList;
-    finally
-
-    end;
+       EditorForm := TEditorForm.Create(Self);
+       GikoSys.LoadEditorKeySetting(EditorForm.ActionList);
+       try
+               for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
+                       if EditorForm.ActionList.Actions[i] is TAction then begin
+                               if EditorForm.ActionList.Actions[i].Tag <> 0 then
+                                       Continue;
+                               ListItem := ListView1.Items.Add;
+                               ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
+                               ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
+                               ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
+                               ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
+                               ListItem.SubItems.Add( GikoSys.Setting.Gestures.GetActionGesture(
+                                       TAction( GikoForm.ActionList.Actions[i] ) ) );
+                               KeyItem := TKeySettingItem.Create;
+                               KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
+                               KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
+                               KeyItem.Gesture := GikoSys.Setting.Gestures.GetActionGesture(
+                                       TAction( GikoForm.ActionList.Actions[i] ) );
+                               ListItem.Data := KeyItem;
+                       end;
+               end;
+               ListView1.SmallImages := EditorForm.HotToobarImageList;
+       finally
+
+       end;{
 //     ActionListView.SortType := stText;
        StatusBar.Height := 21;
        StatusBar.Width := 21;
-    PageControl1.ActivePageIndex := 0;
-end;
+       PageControl1.ActivePageIndex := 0;
+}end;
 
 procedure TKeySettingForm.FormDestroy(Sender: TObject);
 var
@@ -174,7 +195,7 @@ var
        KeyItem: TKeySettingItem;
     ActiveListView: TListView;
 begin
-    if PageControl1.ActivePage.TabIndex <> 0 then
+               if PageControl1.ActivePage.TabIndex <> 0 then
        ActiveListView := ListView1
     else
        ActiveListView := ListView;
@@ -214,11 +235,13 @@ var
        Item: TListItem;
        KeyItem: TKeySettingItem;
 begin
+       GikoSys.Setting.Gestures.ClearGesture;
        for i := 0 to ListView.Items.Count - 1 do begin
                Item := ListView.Items[i];
                if TObject(Item.Data) is TKeySettingItem then begin
                        KeyItem := TKeySettingItem(Item.Data);
                        KeyItem.Action.ShortCut := KeyItem.ShortCut;
+                       GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
                end;
        end;
        for i := 0 to ListView1.Items.Count - 1 do begin
@@ -226,6 +249,7 @@ begin
                if TObject(Item.Data) is TKeySettingItem then begin
                        KeyItem := TKeySettingItem(Item.Data);
                        KeyItem.Action.ShortCut := KeyItem.ShortCut;
+                       GikoSys.Setting.Gestures.AddGesture( KeyItem.Gesture, KeyItem.Action );
                end;
        end;
 
@@ -242,4 +266,62 @@ begin
                Compare := 0;
 end;
 
+procedure TKeySettingForm.GestureSetButtonClick(Sender: TObject);
+const
+       ERR_MSG = '\93ü\97Í\82µ\82½\83W\83F\83X\83`\83\83\81[\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
+       ERR_TITLE = '\83G\83\89\81[';
+var
+       i: Integer;
+       Item: TListItem;
+       KeyItem: TKeySettingItem;
+       ActiveListView: TListView;
+begin
+       if PageControl1.ActivePage.TabIndex <> 0 then
+               ActiveListView := ListView1
+       else
+               ActiveListView := ListView;
+
+       if ActiveListView.Selected = nil then Exit;
+       if (GetKeyState( VK_SHIFT ) and $80000000) <> 0 then begin
+               GestureEdit.Text := '';
+               Exit;
+       end;
+
+       // \8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83W\83F\83X\83`\83\83\81[\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
+       for i := 0 to ActiveListView.Items.Count - 1 do begin
+               if ActiveListView.Selected = ActiveListView.Items[i] then
+                       Continue;
+               Item := ActiveListView.Items[i];
+               if TObject(Item.Data) is TKeySettingItem then begin
+                       KeyItem := TKeySettingItem(Item.Data);
+                       if KeyItem.Gesture = GestureEdit.Text then begin
+                               MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
+                               HotKey.SetFocus;
+                               Exit;
+                       end;
+               end;
+       end;
+       // \83W\83F\83X\83`\83\83\81[\90Ý\92è
+       if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
+               KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
+               KeyItem.Gesture := GestureEdit.Text;
+               ActiveListView.Selected.SubItems[2] := GestureEdit.Text;
+       end;
+end;
+
+procedure TKeySettingForm.OnGestureStart(Sender: TObject);
+begin
+       GestureEdit.Text := '';
+end;
+
+procedure TKeySettingForm.OnGestureMove(Sender: TObject);
+begin
+       GestureEdit.Text := MouseGesture.GetGestureStr;
+end;
+
+procedure TKeySettingForm.OnGestureEnd(Sender: TObject);
+begin
+       GestureEdit.Text := MouseGesture.GetGestureStr;
+end;
+
 end.