Lazarus

Programming => General => Topic started by: pixelink on December 04, 2019, 01:39:50 am

Title: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
Post by: pixelink on December 04, 2019, 01:39:50 am
I have code in the changeupdate of SynEdit to turn on/off undo/redo  when the editor becomes dirty
However, I only doing enabled both U/R at the same time

How can I check which state the SynEdit actually fired... whether it is undo 1st, then redo 2nd.

So, basically, the 1st edit enables UNDO, but the second edit enables REDO

FYI... I already know SynEdit has built in U/R functionality (that works fine)... but how to capture what state its in so menus and buttons reflect the correct state

Make sense??
Title: Re: SynEdit - Detect Undo/Redo Without Using Timer
Post by: Handoko on December 04, 2019, 02:33:57 am
Have you tried using TSynEdit.CanRedo and TSynEdit.CanUndo?
Title: Re: SynEdit - Detect Undo/Redo Without Using Timer
Post by: pixelink on December 04, 2019, 02:07:28 pm
Have you tried using TSynEdit.CanRedo and TSynEdit.CanUndo?

Didn't know about it.
I will check that out.

Thanks
Title: Re: SynEdit - Detect Undo/Redo Without Using Timer
Post by: pixelink on December 04, 2019, 02:36:07 pm
Works perfect. Thank Handoko

CODE THAT WORKS:

Code: Pascal  [Select]
  1.  
  2.   if SynEdit.CanUndo = True Then
  3.       begin
  4.        btnUndo.Enabled:=True;
  5.        mnuUndo.Enabled:=True;
  6.        popmnuUndo.Enabled:=True;
  7.       end
  8.    else
  9.      begin
  10.        btnUndo.Enabled:=False;
  11.        mnuUndo.Enabled:=False;
  12.        popmnuUndo.Enabled:=False;
  13.       end;
  14.  
  15.  
  16.    if SynEdit.CanRedo = True Then
  17.       begin
  18.        btnRedo.Enabled:=True;
  19.        mnuRedo.Enabled:=True;
  20.        popmnuRedo.Enabled:=True;
  21.       end
  22.    else
  23.      begin
  24.        btnRedo.Enabled:=False;
  25.        mnuRedo.Enabled:=False;
  26.        popmnuRedo.Enabled:=False;
  27.       end;
  28.  
  29.  
Title: Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
Post by: lainz on December 04, 2019, 02:47:01 pm
You can simplify the code like this:
Code: Pascal  [Select]
  1.        btnUndo.Enabled:=SynEdit.CanUndo;
  2.        mnuUndo.Enabled:=SynEdit.CanUndo;
  3.        popmnuUndo.Enabled:=SynEdit.CanUndo;
  4.  
  5.        btnRedo.Enabled:=SynEdit.CanRedo;
  6.        mnuRedo.Enabled:=SynEdit.CanRedo;
  7.        popmnuRedo.Enabled:=SynEdit.CanRedo;
Title: Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
Post by: lucamar on December 04, 2019, 06:24:45 pm
You can simplify it even more if you link the button and the menu items to a TAction. All you would have to do to enable/disable all associated controls is to set the Action's Enabled property instead of en-/disabling them one by one.
Title: Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
Post by: pixelink on December 04, 2019, 10:27:35 pm
You can simplify the code like this:
Code: Pascal  [Select]
  1.        btnUndo.Enabled:=SynEdit.CanUndo;
  2.        mnuUndo.Enabled:=SynEdit.CanUndo;
  3.        popmnuUndo.Enabled:=SynEdit.CanUndo;
  4.  
  5.        btnRedo.Enabled:=SynEdit.CanRedo;
  6.        mnuRedo.Enabled:=SynEdit.CanRedo;
  7.        popmnuRedo.Enabled:=SynEdit.CanRedo;

Cool... Thanks for the tip
Title: Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
Post by: pixelink on December 04, 2019, 10:27:57 pm
You can simplify it even more if you link the button and the menu items to a TAction. All you would have to do to enable/disable all associated controls is to set the Action's Enabled property instead of en-/disabling them one by one.

Cool... Thanks for the tip