improved hint and call tip windows

This commit is contained in:
Basile Burg 2015-03-13 22:20:30 +01:00
parent d4da82f505
commit c849f563d6
1 changed files with 25 additions and 24 deletions

View File

@ -91,7 +91,7 @@ type
fMousePos: TPoint; fMousePos: TPoint;
fCallTipWin: TCEEditorHintWindow; fCallTipWin: TCEEditorHintWindow;
fDDocWin: TCEEditorHintWindow; fDDocWin: TCEEditorHintWindow;
fIdleTimer: TIdleTimer; fHintTimer: TIdleTimer;
fCanShowHint: boolean; fCanShowHint: boolean;
fOldMousePos: TPoint; fOldMousePos: TPoint;
function getMouseStart: Integer; function getMouseStart: Integer;
@ -100,8 +100,7 @@ type
procedure saveCache; procedure saveCache;
procedure loadCache; procedure loadCache;
procedure setDefaultFontSize(aValue: Integer); procedure setDefaultFontSize(aValue: Integer);
procedure hintWinClick(sender: TObject); procedure HintTimerEvent(sender: TObject);
procedure EditorIdle(sender: TObject);
procedure InitHintWins; procedure InitHintWins;
protected protected
procedure SetVisible(Value: Boolean); override; procedure SetVisible(Value: Boolean); override;
@ -326,12 +325,15 @@ end;
constructor TCESynMemo.Create(aOwner: TComponent); constructor TCESynMemo.Create(aOwner: TComponent);
begin begin
inherited; inherited;
InitHintWins; //
self.ShowHint:=false;
SetDefaultKeystrokes; // not called in inherited if owner = nil !
fDefaultFontSize := 10; fDefaultFontSize := 10;
fIdleTimer := TIdleTimer.Create(self); SetDefaultKeystrokes; // not called in inherited if owner = nil !
fIdleTimer.OnTimer := @EditorIdle; //
ShowHint :=false;
InitHintWins;
fHintTimer := TIdleTimer.Create(self);
fHintTimer.OnTimer := @HintTimerEvent;
//
Gutter.LineNumberPart.ShowOnlyLineNumbersMultiplesOf := 5; Gutter.LineNumberPart.ShowOnlyLineNumbersMultiplesOf := 5;
Gutter.LineNumberPart.MarkupInfo.Foreground := clGray; Gutter.LineNumberPart.MarkupInfo.Foreground := clGray;
Gutter.SeparatorPart.LineOffset := 1; Gutter.SeparatorPart.LineOffset := 1;
@ -352,11 +354,11 @@ begin
fTempFileName := GetTempDir(false) + 'temp_' + uniqueObjStr(self) + '.d'; fTempFileName := GetTempDir(false) + 'temp_' + uniqueObjStr(self) + '.d';
fFilename := '<new document>'; fFilename := '<new document>';
fModified := false; fModified := false;
//ShowHint := true;
TextBuffer.AddNotifyHandler(senrUndoRedoAdded, @changeNotify); TextBuffer.AddNotifyHandler(senrUndoRedoAdded, @changeNotify);
// //
fPositions := TCESynMemoPositions.create(self); fPositions := TCESynMemoPositions.create(self);
fMultiDocSubject := TCEMultiDocSubject.create; fMultiDocSubject := TCEMultiDocSubject.create;
//
subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self); subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self);
end; end;
@ -370,6 +372,7 @@ begin
// //
if fileExists(fTempFileName) then if fileExists(fTempFileName) then
sysutils.DeleteFile(fTempFileName); sysutils.DeleteFile(fTempFileName);
//
inherited; inherited;
end; end;
@ -398,28 +401,21 @@ begin
if Value then setFocus; if Value then setFocus;
end; end;
procedure TCESynMemo.hintWinClick(sender: TObject);
begin
with THintWindow(sender) do Hide;
end;
procedure TCESynMemo.InitHintWins; procedure TCESynMemo.InitHintWins;
begin begin
if fCallTipWin = nil then begin if fCallTipWin = nil then begin
fCallTipWin := TCEEditorHintWindow.Create(self); fCallTipWin := TCEEditorHintWindow.Create(self);
fCallTipWin.Color := clInfoBk + $01010100; fCallTipWin.Color := clInfoBk + $01010100;
fCallTipWin.Font.Color:= clInfoText; fCallTipWin.Font.Color:= clInfoText;
fCallTipWin.OnClick:= @hintWinClick;
end; end;
if fDDocWin = nil then begin if fDDocWin = nil then begin
fDDocWin := TCEEditorHintWindow.Create(self); fDDocWin := TCEEditorHintWindow.Create(self);
fDDocWin.Color := clInfoBk + $01010100; fDDocWin.Color := clInfoBk + $01010100;
fDDocWin.Font.Color:= clInfoText; fDDocWin.Font.Color:= clInfoText;
fDDocWin.OnClick:= @hintWinClick;
end; end;
end; end;
procedure TCESynMemo.EditorIdle(sender: TObject); procedure TCESynMemo.HintTimerEvent(sender: TObject);
var var
str: string; str: string;
begin begin
@ -427,7 +423,7 @@ begin
if not isDSource then exit; if not isDSource then exit;
// //
if not fCanShowHint then exit; if not fCanShowHint then exit;
if Identifier = '' then exit; fCanShowHint := false;
DcdWrapper.getDdocFromCursor(str); DcdWrapper.getDdocFromCursor(str);
// //
if (length(str) > 0) then if (length(str) > 0) then
@ -440,8 +436,7 @@ begin
if str <> '' then if str <> '' then
begin begin
fDDocWin.FontSize := Font.Size; fDDocWin.FontSize := Font.Size;
fDDocWin.Font.Size:=Font.Size; fDDocWin.HintRect := fDDocWin.CalcHintRect(0, str, nil);
fDDocWin.HintRect := fCallTipWin.CalcHintRect(0, str, nil);
fDDocWin.OffsetHintRect(mouse.CursorPos, Font.Size); fDDocWin.OffsetHintRect(mouse.CursorPos, Font.Size);
fDDocWin.ActivateHint(fDDocWin.HintRect, str); fDDocWin.ActivateHint(fDDocWin.HintRect, str);
end; end;
@ -610,7 +605,7 @@ begin
begin begin
fCallTipWin.FontSize := Font.Size; fCallTipWin.FontSize := Font.Size;
fCallTipWin.HintRect := fCallTipWin.CalcHintRect(0, str, nil); fCallTipWin.HintRect := fCallTipWin.CalcHintRect(0, str, nil);
fCallTipWin.OffsetHintRect(point(CaretXPix, CaretYPix), Font.Size); fCallTipWin.OffsetHintRect(ClientToScreen(point(CaretXPix, CaretYPix)), - (Font.Size * 2 + 5));
fCallTipWin.ActivateHint(str); fCallTipWin.ActivateHint(str);
end; end;
end else fCallTipWin.Hide; end else fCallTipWin.Hide;
@ -628,13 +623,19 @@ begin
end; end;
procedure TCESynMemo.MouseMove(Shift: TShiftState; X, Y: Integer); procedure TCESynMemo.MouseMove(Shift: TShiftState; X, Y: Integer);
var
dX, dY: Integer;
begin begin
fDDocWin.Hide; fDDocWin.Hide;
fCallTipWin.Hide; fCallTipWin.Hide;
inherited; inherited;
fCanShowHint := (shift = []) and dx := X - fOldMousePos.x;
(Y - fOldMousePos.y < 2) and (Y - fOldMousePos.y > -2) and dy := Y - fOldMousePos.y;
(X - fOldMousePos.x < 2) and (X - fOldMousePos.x > -2); fCanShowHint:=false;
if (shift = []) then if
((dx < 0) and (dx > -5) or (dx > 0) and (dx < 5)) or
((dy < 0) and (dy > -5) or (dy > 0) and (dy < 5)) then
fCanShowHint:=true;
fOldMousePos := Point(X, Y); fOldMousePos := Point(X, Y);
fMousePos := PixelsToRowColumn(fOldMousePos); fMousePos := PixelsToRowColumn(fOldMousePos);
if ssLeft in Shift then if ssLeft in Shift then