Overwrite Ctrl+Z

General TRichView support forum. Please post your questions here
Post Reply
JPR
Posts: 35
Joined: Fri Apr 14, 2006 7:27 am

Overwrite Ctrl+Z

Post by JPR »

Hi,

I would like to overwrite Ctrl+Z in TRichViewEdit but If I use KeyDown in delphi my code doesn't work correctly.

Code: Select all

procedure TForm1.xre1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = 90) and (ssCtrl in Shift) then
  begin
    if MyUndoIdt < 1 then
      MyUndoIdt:= MyDim;
    if MyUndo[MyUndoIdt] <> nil then
    begin
      SendMessage(xre1.Handle, WM_SETREDRAW, 0, 0);
      xre1.LoadFromStream(MyUndo[MyUndoIdt], rvynaAuto);
      xre1.Format;
      FreeAndNil(MyUndo[MyUndoIdt]);
      xre1.SelStart:= MyUndoPos[MyUndoIdt];
      MyUndoPos[MyUndoIdt]:= 0;
      SendMessage(xre1.Handle, WM_SETREDRAW, 1, 0);
      xre1.Invalidate;
      Dec(MyUndoIdt);
    end
  end;
end;
I need to do that to do a my proper undo because I use MarkString function. With this function Undo (RichView) doesn't work correctly.


Thank to help me.

JP
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) To disable the standard Ctrl+Z processing, assign Key:=0 in OnKeyDown
2) This code will crash TRichViewEdit if the caret is in table cell inplace editor. Use PostMessage to avoid this problem. Examples:
http://www.trichview.com/support/trichv ... tion_4.htm
http://www.trichview.com/support/trichv ... ream_4.htm
http://www.trichview.com/support/trichv ... brve_6.htm
JPR
Posts: 35
Joined: Fri Apr 14, 2006 7:27 am

Post by JPR »

Hello Sergey,

I would like not to disable but overwrite

Thank

JPR
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

May be it would be better to use undoable version of sting marking procedure? (SearchText + ApplyStyleConversion)
It's slower, but can be undone without tricks.
JPR
Posts: 35
Joined: Fri Apr 14, 2006 7:27 am

Post by JPR »

I have already try this method but I need a fastly Highligthing SQL script.
with MarkString function, I reduce by 3, time of process.

Have you a solution to overwrite Ctrl+Z, please Sergey ?

Because I try a lot of thing, but I don't find solution.

Thank
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post by Michel »

You could try catching it in Form.OnShortCut and setting Handled to True.
HTH,
Michel
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

And your code in OnKeyDown is not working? What's wrong with it?
Yes, it does not block the default processing of Ctrl+Z, but the default undo code will be executed after your code. After loading a file, an undo buffer is empty, so the default procedure should do nothing.
There will be a problem inside tables, as I mentioned before, but without tables it should work.
JPR
Posts: 35
Joined: Fri Apr 14, 2006 7:27 am

Post by JPR »

Hi sergey,

No this code doesn't work correctly. I have put a breakpoint on this procedure and Delphi can't execute this part of code.
Key = 90 not work.

I have put UndoLimit = 0

Thank

JP
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Well, you are right, undo and redo keys are processed without calling OnKeyDown. I agree, it's not good.
The beginning of TCustomRichViewEdit.KeyDown must be changed from

Code: Select all

  TRVEditRVData(RVData).PrepareForEdit;
  if (Key=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then
    Key := 0;
  if IsUndoShortcut(Shift, Key) then begin
    Undo;
    Key := 0;
    end
  else if IsRedoShortcut(Shift, Key) then begin
    Redo;
    Key := 0;
  end;
  if Key = 0 then
    exit;
  inherited KeyDown(Key, Shift);
to

Code: Select all

  if (Key=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then begin
    Key := 0;
    exit;
  end;
  inherited KeyDown(Key, Shift);
  if Key = 0 then
    exit;
  if IsUndoShortcut(Shift, Key) then begin
    Undo;
    Key := 0;
    end
  else if IsRedoShortcut(Shift, Key) then begin
    Redo;
    Key := 0;
  end;
JPR
Posts: 35
Joined: Fri Apr 14, 2006 7:27 am

Post by JPR »

Thank Sergey but In what unit ?

JPR
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RVEdit.pas
Post Reply