Recent

Author Topic: TreeView and PopupMenu: Strange reaction to Enter  (Read 4199 times)

Unvictis

  • New Member
  • *
  • Posts: 15
  • Nihil habeo, nihil timeo
TreeView and PopupMenu: Strange reaction to Enter
« on: September 09, 2016, 07:50:01 am »
Good day guys! I am writing a small database for my workshop. There TreeView which awarded the PopupMenu. In this PopupMenu have items to add and rename the tree branches. By clicking on these items new / TTreeNode highlighted node translates the title editing mode (by TTreeNode.EditText;). If I select these items left mouse button menu, everything works as it should. But if I choose them by pressing Enter, the item is added / editing mode, and then the same again becomes the initial state (Enter once to send and TreeView). How do I change this behavior? (Sorry please for my bad English)

PS: Lazarus 1.4.4 x86/x64, FreePascal 2.6.4, Windows XP/10/Ubuntu Mate 16.04 x64

Animation (gif):
http://gifyu.com/images/ezgif-2554597885.gif
« Last Edit: September 09, 2016, 11:34:26 am by Unvictis »

balazsszekely

  • Guest
Re: TreeView and PopupMenu: Strange reaction to Enter
« Reply #1 on: September 09, 2016, 12:12:23 pm »
Hi Unvictis,

Drop a TTimer to your form, set Interval to 200, Enabled property to false, then on popupmenu close:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PopupMenu1Close(Sender: TObject);
  2. begin
  3.   Timer1.Enabled := True;
  4. end;
  5.  
  6. procedure TForm1.tmWaitTimer(Sender: TObject);
  7. begin
  8.   Timer1.Enabled := False;
  9.   if not TreeView1.IsEditing then
  10.     TreeView1.Selected.EditText;
  11. end;
  12.  

Unvictis

  • New Member
  • *
  • Posts: 15
  • Nihil habeo, nihil timeo
Re: TreeView and PopupMenu: Strange reaction to Enter
« Reply #2 on: September 09, 2016, 12:36:06 pm »
Hi Unvictis,

Drop a TTimer to your form, set Interval to 200, Enabled property to false, then on popupmenu close:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PopupMenu1Close(Sender: TObject);
  2. begin
  3.   Timer1.Enabled := True;
  4. end;
  5.  
  6. procedure TForm1.tmWaitTimer(Sender: TObject);
  7. begin
  8.   Timer1.Enabled := False;
  9.   if not TreeView1.IsEditing then
  10.     TreeView1.Selected.EditText;
  11. end;
  12.  

Thanks, but it seems to me that this solution is not optimal.

rvk

  • Hero Member
  • *****
  • Posts: 6665
Re: TreeView and PopupMenu: Strange reaction to Enter
« Reply #3 on: September 09, 2016, 12:37:02 pm »
Drop a TTimer to your form, set Interval to 200, Enabled property to false, then on popupmenu close:
Of course you shouldn't do this in PopupMenu1Close because then it will switch to edit-mode for every-menu item you choose (which you might not want. For example for the delete menu item).

Only enable the timer in the menu-items where you want to edit the item:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuItemXXXClick(Sender: TObject);
  2. begin
  3.   Timer1.Enabled := true;
  4. end;
  5.  
  6. procedure TForm1.tmWaitTimer(Sender: TObject);
  7. begin
  8.   Timer1.Enabled := False;
  9.   if not TreeView1.IsEditing then
  10.     TreeView1.Selected.EditText;
  11. end;

The problem is that switching to editing mode while in an event of a menu-item doesn't always work (for instance in case of keyboard enter, the enter key is still in the queue and is executed in your EditText).

Another possibility would be to do a PostMessage to your form and switch to editing. But the timer-method works good too.

balazsszekely

  • Guest
Re: TreeView and PopupMenu: Strange reaction to Enter
« Reply #4 on: September 09, 2016, 01:33:54 pm »
Quote
@rvk
Only enable the timer in the menu-items where you want to edit the item
I tested my example with only one menu item,  :D but your argument is perfectly valid. 

Quote
@Unvictis
Thanks, but it seems to me that this solution is not optimal.
Take into account what @rvk suggested. I don't think you gonna find a more optimal solution(at least a solution that's easy to implement)

 

TinyPortal © 2005-2018