Recent

Author Topic: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer  (Read 1828 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
« 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??
« Last Edit: December 04, 2019, 02:37:18 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: SynEdit - Detect Undo/Redo Without Using Timer
« Reply #1 on: December 04, 2019, 02:33:57 am »
Have you tried using TSynEdit.CanRedo and TSynEdit.CanUndo?

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit - Detect Undo/Redo Without Using Timer
« Reply #2 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
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit - Detect Undo/Redo Without Using Timer
« Reply #3 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.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
« Reply #4 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;

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
« Reply #5 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
« Reply #6 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
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: [SOLVED] SynEdit - Detect Undo/Redo Without Using Timer
« Reply #7 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
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018