Browse Source

UPD: COCOA: more proper showing and hiding of AutoComplete ListBox in KASPathEdit (#598)

rich2014 3 năm trước cách đây
mục cha
commit
75b707fae5
1 tập tin đã thay đổi với 27 bổ sung13 xóa
  1. 27 13
      components/KASToolBar/kaspathedit.pas

+ 27 - 13
components/KASToolBar/kaspathedit.pas

@@ -54,16 +54,17 @@ type
     originalText: String;
     originalText: String;
     keyDownText: String;
     keyDownText: String;
 {$ENDIF}
 {$ENDIF}
-    procedure handleSpecialKeys( Key: Word );
+  private
+    procedure handleSpecialKeys( var Key: Word );
     procedure handleUpKey;
     procedure handleUpKey;
     procedure handleDownKey;
     procedure handleDownKey;
-  private
     procedure AutoComplete(const Path: String);
     procedure AutoComplete(const Path: String);
     procedure SetObjectTypes(const AValue: TObjectTypes);
     procedure SetObjectTypes(const AValue: TObjectTypes);
     procedure FormChangeBoundsEvent(Sender: TObject);
     procedure FormChangeBoundsEvent(Sender: TObject);
     procedure ListBoxClick(Sender: TObject);
     procedure ListBoxClick(Sender: TObject);
     procedure ListBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
     procedure ListBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
   private
   private
+    function isShowingListBox(): Boolean; inline;
     procedure ShowListBox;
     procedure ShowListBox;
     procedure HideListBox;
     procedure HideListBox;
   protected
   protected
@@ -207,6 +208,11 @@ end;
 
 
 { TKASPathEdit }
 { TKASPathEdit }
 
 
+function TKASPathEdit.isShowingListBox(): Boolean;
+begin
+  Result:= FPanel<>nil;
+end;
+
 procedure TKASPathEdit.AutoComplete(const Path: String);
 procedure TKASPathEdit.AutoComplete(const Path: String);
 {$IF LCL_FULLVERSION >= 2020000}
 {$IF LCL_FULLVERSION >= 2020000}
 const
 const
@@ -251,6 +257,7 @@ begin
       finally
       finally
         FListBox.Items.EndUpdate;
         FListBox.Items.EndUpdate;
       end;
       end;
+      if FListBox.Items.Count = 0 then HideListBox;
       if FListBox.Items.Count > 0 then
       if FListBox.Items.Count > 0 then
       begin
       begin
         ShowListBox;
         ShowListBox;
@@ -317,7 +324,7 @@ end;
 
 
 procedure TKASPathEdit.ShowListBox;
 procedure TKASPathEdit.ShowListBox;
 begin
 begin
-  if (FPanel = nil) then
+  if not isShowingListBox() then
   begin
   begin
     FPanel:= THintWindow.Create(Self);
     FPanel:= THintWindow.Create(Self);
 {$IF DEFINED(LCLCOCOA)}
 {$IF DEFINED(LCLCOCOA)}
@@ -342,7 +349,7 @@ end;
 
 
 procedure TKASPathEdit.HideListBox;
 procedure TKASPathEdit.HideListBox;
 begin
 begin
-  if (FPanel <> nil) then
+  if isShowingListBox() then
   begin
   begin
     FPanel.Visible:= False;
     FPanel.Visible:= False;
     FListBox.Parent:= nil;
     FListBox.Parent:= nil;
@@ -405,24 +412,31 @@ begin
     VK_ESCAPE,
     VK_ESCAPE,
     VK_RETURN,
     VK_RETURN,
     VK_SELECT:
     VK_SELECT:
-      if self.text=self.keyDownText then
+      if self.text=self.keyDownText then begin
         // from the text has not been changed,
         // from the text has not been changed,
         // the TKASPathEdit is not in the IME state
         // the TKASPathEdit is not in the IME state
         handleSpecialKeys( Key )
         handleSpecialKeys( Key )
-      else
+      end else begin
+        // in the IME state
+        AutoComplete(self.text);
         Key:= 0;
         Key:= 0;
+      end;
   end;
   end;
   inherited KeyUp( Key, Shift );
   inherited KeyUp( Key, Shift );
 end;
 end;
 {$ENDIF}
 {$ENDIF}
 
 
-procedure TKASPathEdit.handleSpecialKeys( Key: Word );
+procedure TKASPathEdit.handleSpecialKeys( var Key: Word );
 begin
 begin
-  HideListBox;
-  if Key=VK_ESCAPE then begin
-    if Assigned(onKeyESCAPE) then onKeyESCAPE( self );
+  if isShowingListBox() then begin
+    HideListBox;
+    Key:= 0;
   end else begin
   end else begin
-    if Assigned(onKeyRETURN) then onKeyRETURN( self );
+    if Key=VK_ESCAPE then begin
+      if Assigned(onKeyESCAPE) then onKeyESCAPE( self );
+    end else begin
+      if Assigned(onKeyRETURN) then onKeyRETURN( self );
+    end;
   end;
   end;
 end;
 end;
 
 
@@ -474,13 +488,13 @@ begin
       handleSpecialKeys( Key );
       handleSpecialKeys( Key );
     {$ENDIF}
     {$ENDIF}
     VK_UP:
     VK_UP:
-      if Assigned(FPanel) then
+      if isShowingListBox() then
       begin
       begin
         Key:= 0;
         Key:= 0;
         handleUpKey();
         handleUpKey();
       end;
       end;
     VK_DOWN:
     VK_DOWN:
-      if Assigned(FPanel) then
+      if isShowingListBox() then
       begin
       begin
         Key:= 0;
         Key:= 0;
         handleDownKey();
         handleDownKey();