Page 1 of 1

Overwrite Ctrl+Z

Posted: Tue Jul 25, 2006 7:50 am
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

Posted: Tue Jul 25, 2006 7:24 pm
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

Posted: Wed Jul 26, 2006 11:24 am
by JPR
Hello Sergey,

I would like not to disable but overwrite

Thank

JPR

Posted: Wed Jul 26, 2006 2:46 pm
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.

Posted: Wed Jul 26, 2006 3:32 pm
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

Posted: Wed Jul 26, 2006 3:45 pm
by Michel
You could try catching it in Form.OnShortCut and setting Handled to True.
HTH,
Michel

Posted: Wed Jul 26, 2006 8:21 pm
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.

Posted: Thu Jul 27, 2006 7:29 am
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

Posted: Sat Jul 29, 2006 12:49 pm
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;

Posted: Mon Jul 31, 2006 10:48 am
by JPR
Thank Sergey but In what unit ?

JPR

Posted: Wed Aug 02, 2006 7:03 pm
by Sergey Tkachenko
RVEdit.pas