mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
UPD: refactoring to eliminate duplicate code in FileView
This commit is contained in:
parent
cfb5e4862c
commit
5cfe18488d
5 changed files with 55 additions and 102 deletions
|
|
@ -354,42 +354,8 @@ begin
|
|||
end;
|
||||
|
||||
procedure TBriefDrawGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
|
||||
function handleMBLeft: Boolean;
|
||||
var
|
||||
handler: TFileSourceUIHandler;
|
||||
params: TFileSourceUIParams;
|
||||
index: Integer;
|
||||
begin
|
||||
Result:= False;
|
||||
|
||||
params:= Default( TFileSourceUIParams );
|
||||
params.sender:= FBriefView;
|
||||
params.fs:= FBriefView.FileSource;
|
||||
params.multiColumns:= False;
|
||||
|
||||
handler:= params.fs.GetUIHandler;
|
||||
if handler = nil then
|
||||
Exit;
|
||||
|
||||
params.shift:= Shift;
|
||||
params.x:= X;
|
||||
params.y:= Y;
|
||||
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
|
||||
index:= CellToIndex( params.col, params.row );
|
||||
if index < 0 then
|
||||
Exit;
|
||||
|
||||
ColRowToOffset(True, True, params.col, params.drawingRect.Left, params.drawingRect.Right );
|
||||
ColRowToOffset(False, True, params.row, params.drawingRect.Top, params.drawingRect.Bottom );
|
||||
params.decorationRect:= self.ConvertToDecorationRect( params.drawingRect );
|
||||
|
||||
params.displayFile:= FBriefView.FFiles[index];
|
||||
Result:= handler.click( params );
|
||||
end;
|
||||
|
||||
begin
|
||||
if (Button = mbLeft) and handleMBLeft then
|
||||
if (Button = mbLeft) and self.doCellClick( Shift, X, Y ) then
|
||||
begin
|
||||
FBriefView.tmRenameFile.Enabled := False;
|
||||
FBriefView.FRenameFileIndex := -1;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ type
|
|||
procedure SetGridVertLine(const AValue: Boolean);
|
||||
|
||||
protected
|
||||
function getFileView: TFileView; override;
|
||||
|
||||
procedure DragCanceled; override;
|
||||
procedure DoMouseMoveScroll(X, Y: Integer);
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
|
|
@ -2041,37 +2043,6 @@ var
|
|||
FileSystem: String;
|
||||
Background: Boolean;
|
||||
|
||||
procedure handleMBLeft;
|
||||
var
|
||||
handler: TFileSourceUIHandler;
|
||||
params: TFileSourceUIParams;
|
||||
index: Integer;
|
||||
begin
|
||||
params:= Default( TFileSourceUIParams );
|
||||
params.sender:= self.ColumnsView;
|
||||
params.fs:= self.ColumnsView.FileSource;
|
||||
params.multiColumns:= True;
|
||||
|
||||
handler:= params.fs.GetUIHandler;
|
||||
if handler = nil then
|
||||
Exit;
|
||||
|
||||
params.shift:= Shift;
|
||||
params.x:= X;
|
||||
params.y:= Y;
|
||||
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
|
||||
index:= CellToIndex( params.col, params.row );
|
||||
if index < 0 then
|
||||
Exit;
|
||||
|
||||
ColRowToOffset(True, True, params.col, params.drawingRect.Left, params.drawingRect.Right );
|
||||
ColRowToOffset(False, True, params.row, params.drawingRect.Top, params.drawingRect.Bottom );
|
||||
params.decorationRect:= self.ConvertToDecorationRect( params.drawingRect );
|
||||
|
||||
params.displayFile:= ColumnsView.FFiles[index];
|
||||
handler.click( params );
|
||||
end;
|
||||
|
||||
begin
|
||||
if ColumnsView.IsLoadingFileList then Exit;
|
||||
{$IFDEF LCLGTK2}
|
||||
|
|
@ -2093,7 +2064,7 @@ begin
|
|||
|
||||
if Button = mbLeft then
|
||||
begin
|
||||
handleMBLeft;
|
||||
self.doCellClick( Shift, X, Y );
|
||||
end else if Button = mbRight then
|
||||
begin
|
||||
{ If right click on header }
|
||||
|
|
@ -2262,6 +2233,11 @@ begin
|
|||
Options := Options - [goVertLine];
|
||||
end;
|
||||
|
||||
function TDrawGridEx.getFileView: TFileView;
|
||||
begin
|
||||
Result:= self.ColumnsView;
|
||||
end;
|
||||
|
||||
function TDrawGridEx.GetVisibleRows: TRange;
|
||||
var
|
||||
w: Integer;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
uFileSource, uFileView,
|
||||
uSmoothScrollingGrid;
|
||||
|
||||
type
|
||||
|
|
@ -13,6 +14,9 @@ type
|
|||
{ TFileViewBaseGrid }
|
||||
|
||||
TFileViewBaseGrid = class( TSmoothScrollingGrid )
|
||||
protected
|
||||
function doCellClick( const Shift: TShiftState; const X, Y: Integer ): Boolean;
|
||||
function getFileView: TFileView; virtual; abstract;
|
||||
public
|
||||
function MouseOnGrid(X, Y: LongInt): Boolean;
|
||||
procedure MouseToCellWithoutOutbound(X, Y: Integer; out ACol, ARow: Longint);
|
||||
|
|
@ -24,6 +28,41 @@ implementation
|
|||
|
||||
{ TFileViewBaseGrid }
|
||||
|
||||
function TFileViewBaseGrid.doCellClick( const Shift: TShiftState; const X, Y: Integer ): Boolean;
|
||||
var
|
||||
fileView: TFileView;
|
||||
handler: TFileSourceUIHandler;
|
||||
params: TFileSourceUIParams;
|
||||
index: Integer;
|
||||
begin
|
||||
Result:= False;
|
||||
fileView:= self.getFileView;
|
||||
|
||||
params:= Default( TFileSourceUIParams );
|
||||
params.sender:= fileView;
|
||||
params.fs:= fileView.FileSource;
|
||||
params.multiColumns:= False;
|
||||
|
||||
handler:= params.fs.GetUIHandler;
|
||||
if handler = nil then
|
||||
Exit;
|
||||
|
||||
params.shift:= Shift;
|
||||
params.x:= X;
|
||||
params.y:= Y;
|
||||
self.MouseToCellWithoutOutbound( X, Y, params.col, params.row );
|
||||
index:= self.CellToIndex( params.col, params.row );
|
||||
if index < 0 then
|
||||
Exit;
|
||||
|
||||
self.ColRowToOffset(True, True, params.col, params.drawingRect.Left, params.drawingRect.Right );
|
||||
self.ColRowToOffset(False, True, params.row, params.drawingRect.Top, params.drawingRect.Bottom );
|
||||
params.decorationRect:= self.ConvertToDecorationRect( params.drawingRect );
|
||||
|
||||
params.displayFile:= fileView.DisplayFiles[index];
|
||||
Result:= handler.click( params );
|
||||
end;
|
||||
|
||||
function TFileViewBaseGrid.MouseOnGrid(X, Y: LongInt): Boolean;
|
||||
var
|
||||
bTemp: Boolean;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ type
|
|||
FLastMouseScrollTime: QWord;
|
||||
FFileView: TFileViewWithGrid;
|
||||
protected
|
||||
function getFileView: TFileView; override;
|
||||
procedure Scroll(Message: Cardinal; ScrollCode: SmallInt);
|
||||
{$IF lcl_fullversion < 1080003}
|
||||
function SelectCell(aCol, aRow: Integer): Boolean; override;
|
||||
|
|
@ -207,6 +208,11 @@ begin
|
|||
inherited KeyDown(Key, Shift);
|
||||
end;
|
||||
|
||||
function TFileViewGrid.getFileView: TFileView;
|
||||
begin
|
||||
Result:= self.FFileView;
|
||||
end;
|
||||
|
||||
procedure TFileViewGrid.Scroll(Message: Cardinal; ScrollCode: SmallInt);
|
||||
var
|
||||
Msg: TLMScroll;
|
||||
|
|
|
|||
|
|
@ -266,43 +266,9 @@ end;
|
|||
|
||||
procedure TThumbDrawGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
|
||||
Y: Integer);
|
||||
|
||||
function handleMBLeft: Boolean;
|
||||
var
|
||||
handler: TFileSourceUIHandler;
|
||||
params: TFileSourceUIParams;
|
||||
index: Integer;
|
||||
begin
|
||||
Result:= False;
|
||||
|
||||
params:= Default( TFileSourceUIParams );
|
||||
params.sender:= FThumbView;
|
||||
params.fs:= FThumbView.FileSource;
|
||||
params.multiColumns:= False;
|
||||
|
||||
handler:= params.fs.GetUIHandler;
|
||||
if handler = nil then
|
||||
Exit;
|
||||
|
||||
params.shift:= Shift;
|
||||
params.x:= X;
|
||||
params.y:= Y;
|
||||
MouseToCellWithoutOutbound( X, Y, params.col, params.row );
|
||||
index:= CellToIndex( params.col, params.row );
|
||||
if index < 0 then
|
||||
Exit;
|
||||
|
||||
ColRowToOffset(True, True, params.col, params.drawingRect.Left, params.drawingRect.Right );
|
||||
ColRowToOffset(False, True, params.row, params.drawingRect.Top, params.drawingRect.Bottom );
|
||||
params.decorationRect:= self.ConvertToDecorationRect( params.drawingRect );
|
||||
|
||||
params.displayFile:= FThumbView.FFiles[index];
|
||||
Result:= handler.click( params );
|
||||
end;
|
||||
|
||||
begin
|
||||
if Button = mbLeft then
|
||||
handleMBLeft;
|
||||
self.doCellClick( Shift, X, Y );
|
||||
inherited MouseUp(Button, Shift, X, Y);
|
||||
end;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue