mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
UPD: refactoring FileView from uMyDarwin to uDarwinFileView
(cherry picked from commit 116e7cebe7)
This commit is contained in:
parent
2eac8cbd4e
commit
74ba54f044
5 changed files with 84 additions and 81 deletions
|
|
@ -59,6 +59,7 @@ uses
|
|||
, CocoaConfig
|
||||
, uMyDarwin
|
||||
, uDarwinApplication
|
||||
, uDarwinFileView
|
||||
{$ENDIF}
|
||||
, Types, LMessages;
|
||||
|
||||
|
|
@ -5151,12 +5152,12 @@ begin
|
|||
if sType = 'columns' then begin
|
||||
Result := TColumnsFileView.Create(Page, AConfig, ANode, FileViewFlags);
|
||||
{$IFDEF DARWIN}
|
||||
TColumnsFileView(Result).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TColumnsFileView(Result).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
end else if sType = 'brief' then begin
|
||||
Result := TBriefFileView.Create(Page, AConfig, ANode, FileViewFlags);
|
||||
{$IFDEF DARWIN}
|
||||
TBriefFileView(Result).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TBriefFileView(Result).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
end else if sType = 'thumbnails' then
|
||||
Result := TThumbFileView.Create(Page, AConfig, ANode, FileViewFlags)
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ end;
|
|||
|
||||
procedure iCloudAction( const Sender: id );
|
||||
begin
|
||||
uDarwinFileViewUtil.addiCloudDrivePage;
|
||||
TDarwinFileViewUtil.addiCloudDrivePage;
|
||||
end;
|
||||
|
||||
procedure networkAction( const Sender: id );
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
unit uDarwinFileView;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
{$modeswitch objectivec2}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes,
|
||||
uiCloudDrive, uSearchResultFileSource, uFile, uFileSystemFileSource, uFileSource,
|
||||
fMain, uFileViewNotebook, ulng;
|
||||
uiCloudDrive, uSearchResultFileSource, uFileSystemFileSource, uFileSource,
|
||||
uFile, uDisplayFile, uFileProperty,
|
||||
uFileView, uColumnsFileView, uFileViewNotebook,
|
||||
uDarwinFinderModel,
|
||||
ulng,
|
||||
MacOSAll, CocoaAll;
|
||||
|
||||
type
|
||||
uDarwinFileViewUtil = class
|
||||
TDarwinFileViewUtil = class
|
||||
class procedure addFinderSearchResultPage( const searchName: String; const files: TStringArray );
|
||||
class procedure addiCloudDrivePage;
|
||||
end;
|
||||
|
|
@ -19,11 +24,22 @@ type
|
|||
procedure onSearchFinderTagComplete( const searchName: String; const files: TStringArray );
|
||||
end;
|
||||
|
||||
TDarwinFileViewDrawHandler = class
|
||||
procedure onDrawCell(Sender: TFileView; aCol, aRow: Integer;
|
||||
aRect: TRect; focused: Boolean; aFile: TDisplayFile);
|
||||
procedure drawTagsAsDecoration(
|
||||
const colors: TFileFinderTagPrimaryColors; const drawRect: TRect; const focused: Boolean );
|
||||
end;
|
||||
|
||||
var
|
||||
darwinSearchResultHandler: TDarwinSearchResultHandler;
|
||||
darwinFileViewDrawHandler: TDarwinFileViewDrawHandler;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
fMain;
|
||||
|
||||
type
|
||||
|
||||
{ TFinderSearchResultFileSource }
|
||||
|
|
@ -54,12 +70,61 @@ end;
|
|||
procedure TDarwinSearchResultHandler.onSearchFinderTagComplete(const searchName: String;
|
||||
const files: TStringArray);
|
||||
begin
|
||||
uDarwinFileViewUtil.addFinderSearchResultPage( searchName, files );
|
||||
TDarwinFileViewUtil.addFinderSearchResultPage( searchName, files );
|
||||
end;
|
||||
|
||||
{ uDarwinFileViewUtil }
|
||||
{ TDarwinFileViewDrawHandler }
|
||||
|
||||
class procedure uDarwinFileViewUtil.addFinderSearchResultPage( const searchName: String; const files: TStringArray);
|
||||
procedure TDarwinFileViewDrawHandler.onDrawCell(Sender: TFileView; aCol, aRow: Integer;
|
||||
aRect: TRect; focused: Boolean; aFile: TDisplayFile);
|
||||
var
|
||||
macOSProperty: TFileMacOSSpecificProperty;
|
||||
begin
|
||||
if (Sender is TColumnsFileView) and (aCol<>0) then
|
||||
Exit;
|
||||
|
||||
macOSProperty:= aFile.FSFile.MacOSSpecificProperty;
|
||||
if macOSProperty = nil then
|
||||
Exit;
|
||||
|
||||
drawTagsAsDecoration( macOSProperty.FinderTagPrimaryColors, aRect, focused );
|
||||
end;
|
||||
|
||||
procedure TDarwinFileViewDrawHandler.drawTagsAsDecoration(
|
||||
const colors: TFileFinderTagPrimaryColors; const drawRect: TRect;
|
||||
const focused: Boolean);
|
||||
var
|
||||
i: Integer;
|
||||
colorIndex: Integer;
|
||||
color: NSColor;
|
||||
tagRect: NSRect;
|
||||
path: NSBezierPath;
|
||||
begin
|
||||
tagRect.size.width:= 11;
|
||||
tagRect.size.height:= 11;
|
||||
tagRect.origin.x:= drawRect.Right - 17;
|
||||
tagRect.origin.y:= drawRect.Top + (drawRect.Height-tagRect.size.height)/2;
|
||||
|
||||
for i:=0 to 2 do begin
|
||||
colorIndex:= colors.indexes[i];
|
||||
if colorIndex < 0 then
|
||||
break;
|
||||
color:= uDarwinFinderModelUtil.decorationFinderTagNSColors[colorIndex];
|
||||
color.set_;
|
||||
path:= NSBezierPath.bezierPathWithOvalInRect( tagRect );
|
||||
path.fill;
|
||||
if focused then
|
||||
NSColor.alternateSelectedControlTextColor.set_
|
||||
else
|
||||
NSColor.textBackgroundColor.set_;
|
||||
path.stroke;
|
||||
tagRect.origin.x:= tagRect.origin.x - 5;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TDarwinFileViewUtil }
|
||||
|
||||
class procedure TDarwinFileViewUtil.addFinderSearchResultPage( const searchName: String; const files: TStringArray);
|
||||
var
|
||||
i: integer;
|
||||
count: Integer;
|
||||
|
|
@ -92,7 +157,7 @@ begin
|
|||
NewPage.MakeActive;
|
||||
end;
|
||||
|
||||
class procedure uDarwinFileViewUtil.addiCloudDrivePage;
|
||||
class procedure TDarwinFileViewUtil.addiCloudDrivePage;
|
||||
var
|
||||
iCloudFS: TiCloudDriveFileSource;
|
||||
begin
|
||||
|
|
@ -103,6 +168,7 @@ end;
|
|||
|
||||
initialization
|
||||
darwinSearchResultHandler:= TDarwinSearchResultHandler.Create;
|
||||
darwinFileViewDrawHandler:= TDarwinFileViewDrawHandler.Create;
|
||||
|
||||
finalization
|
||||
FreeAndNil( darwinSearchResultHandler );
|
||||
|
|
|
|||
|
|
@ -66,20 +66,6 @@ type
|
|||
var
|
||||
MacosServiceMenuHelper: TMacosServiceMenuHelper;
|
||||
|
||||
type
|
||||
|
||||
{ TDarwinFileViewDrawHelper }
|
||||
|
||||
TDarwinFileViewDrawHelper = class
|
||||
procedure onDrawCell(Sender: TFileView; aCol, aRow: Integer;
|
||||
aRect: TRect; focused: Boolean; aFile: TDisplayFile);
|
||||
procedure drawTagsAsDecoration(
|
||||
const colors: TFileFinderTagPrimaryColors; const drawRect: TRect; const focused: Boolean );
|
||||
end;
|
||||
|
||||
var
|
||||
DarwinFileViewDrawHelper: TDarwinFileViewDrawHelper;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
|
|
@ -163,59 +149,9 @@ begin
|
|||
menu.PopUp();
|
||||
end;
|
||||
|
||||
{ TDarwinFileViewDrawHelper }
|
||||
|
||||
procedure TDarwinFileViewDrawHelper.onDrawCell(Sender: TFileView; aCol, aRow: Integer;
|
||||
aRect: TRect; focused: Boolean; aFile: TDisplayFile);
|
||||
var
|
||||
macOSProperty: TFileMacOSSpecificProperty;
|
||||
begin
|
||||
if (Sender is TColumnsFileView) and (aCol<>0) then
|
||||
Exit;
|
||||
|
||||
macOSProperty:= aFile.FSFile.MacOSSpecificProperty;
|
||||
if macOSProperty = nil then
|
||||
Exit;
|
||||
|
||||
drawTagsAsDecoration( macOSProperty.FinderTagPrimaryColors, aRect, focused );
|
||||
end;
|
||||
|
||||
procedure TDarwinFileViewDrawHelper.drawTagsAsDecoration(
|
||||
const colors: TFileFinderTagPrimaryColors; const drawRect: TRect;
|
||||
const focused: Boolean);
|
||||
var
|
||||
i: Integer;
|
||||
colorIndex: Integer;
|
||||
color: NSColor;
|
||||
tagRect: NSRect;
|
||||
path: NSBezierPath;
|
||||
begin
|
||||
tagRect.size.width:= 11;
|
||||
tagRect.size.height:= 11;
|
||||
tagRect.origin.x:= drawRect.Right - 17;
|
||||
tagRect.origin.y:= drawRect.Top + (drawRect.Height-tagRect.size.height)/2;
|
||||
|
||||
for i:=0 to 2 do begin
|
||||
colorIndex:= colors.indexes[i];
|
||||
if colorIndex < 0 then
|
||||
break;
|
||||
color:= uDarwinFinderModelUtil.decorationFinderTagNSColors[colorIndex];
|
||||
color.set_;
|
||||
path:= NSBezierPath.bezierPathWithOvalInRect( tagRect );
|
||||
path.fill;
|
||||
if focused then
|
||||
NSColor.alternateSelectedControlTextColor.set_
|
||||
else
|
||||
NSColor.textBackgroundColor.set_;
|
||||
path.stroke;
|
||||
tagRect.origin.x:= tagRect.origin.x - 5;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Initialize;
|
||||
begin
|
||||
MacosServiceMenuHelper:= TMacosServiceMenuHelper.Create;
|
||||
DarwinFileViewDrawHelper:= TDarwinFileViewDrawHelper.Create;
|
||||
end;
|
||||
|
||||
procedure Finalize;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ uses
|
|||
Classes, SysUtils, ActnList, uFileView, uFileViewNotebook, uFileSourceOperation,
|
||||
uGlobs, uFileFunctions, uFormCommands, uFileSorting, uShellContextMenu, Menus, ufavoritetabs,ufile
|
||||
{$IFDEF DARWIN}
|
||||
, uMyDarwin
|
||||
, uMyDarwin, uDarwinFileView
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
|
|
@ -2229,7 +2229,7 @@ begin
|
|||
begin
|
||||
aFileView:= TBriefFileView.Create(ActiveNotebook.ActivePage, ActiveFrame);
|
||||
{$IFDEF DARWIN}
|
||||
TBriefFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TBriefFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
ActiveNotebook.ActivePage.FileView:= aFileView;
|
||||
ActiveFrame.SetFocus;
|
||||
|
|
@ -2244,7 +2244,7 @@ begin
|
|||
begin
|
||||
aFileView:= TBriefFileView.Create(LeftTabs.ActivePage, FrameLeft);
|
||||
{$IFDEF DARWIN}
|
||||
TBriefFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TBriefFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
LeftTabs.ActivePage.FileView:= aFileView;
|
||||
end;
|
||||
|
|
@ -2258,7 +2258,7 @@ begin
|
|||
begin
|
||||
aFileView:= TBriefFileView.Create(RightTabs.ActivePage, FrameRight);
|
||||
{$IFDEF DARWIN}
|
||||
TBriefFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TBriefFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
RightTabs.ActivePage.FileView:= aFileView;
|
||||
end;
|
||||
|
|
@ -2277,7 +2277,7 @@ begin
|
|||
else begin
|
||||
aFileView:= TColumnsFileView.Create(ActiveNotebook.ActivePage, ActiveFrame, AParam);
|
||||
{$IFDEF DARWIN}
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
ActiveNotebook.ActivePage.FileView:= aFileView;
|
||||
ActiveFrame.SetFocus;
|
||||
|
|
@ -2298,7 +2298,7 @@ begin
|
|||
else begin
|
||||
aFileView:= TColumnsFileView.Create(LeftTabs.ActivePage, FrameLeft, AParam);
|
||||
{$IFDEF DARWIN}
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
LeftTabs.ActivePage.FileView:= aFileView;
|
||||
end;
|
||||
|
|
@ -2318,7 +2318,7 @@ begin
|
|||
else begin
|
||||
aFileView:= TColumnsFileView.Create(RightTabs.ActivePage, FrameRight, AParam);
|
||||
{$IFDEF DARWIN}
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @DarwinFileViewDrawHelper.OnDrawCell;
|
||||
TColumnsFileView(aFileView).OnDrawCell:= @darwinFileViewDrawHandler.OnDrawCell;
|
||||
{$ENDIF}
|
||||
RightTabs.ActivePage.FileView:= aFileView;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue