ADD: Custom fields support for tooltips

This commit is contained in:
Alexander Koblov 2011-04-10 08:16:26 +00:00
commit 790c070bfb
3 changed files with 205 additions and 12 deletions

View file

@ -5,40 +5,189 @@ unit uInfoToolTip;
interface
uses
Classes, SysUtils,
Classes, SysUtils, fgl, uXmlConfig,
uFile, uFileSource;
type
{ TMaskItem }
TMaskItem = class
Name: UTF8String;
Mask: UTF8String;
Hint: UTF8String;
end;
{ TMaskItemList }
TMaskItemList = specialize TFPGObjectList<TMaskItem>;
{ TFileInfoToolTip }
TFileInfoToolTip = class
protected
FMaskItemList: TMaskItemList;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function GetFileInfoToolTip(aFileSource: IFileSource; const aFile: TFile): UTF8String;
procedure Load(AConfig: TXmlConfig; ANode: TXmlNode);
procedure Save(AConfig: TXmlConfig; ANode: TXmlNode);
property MaskItemList: TMaskItemList read FMaskItemList;
end;
function GetFileInfoToolTip(aFileSource: IFileSource; const aFile: TFile): UTF8String;
implementation
uses
StrUtils, uFileProperty
LCLProc, StrUtils, uMasks, uDebug, uGlobs, uFileProperty, uFileFunctions,
uFileSourceProperty
{$IF DEFINED(MSWINDOWS)}
, uShlObjAdditional, uFileSourceProperty
, uShlObjAdditional
{$ENDIF}
;
function GetFileInfoToolTip(aFileSource: IFileSource; const aFile: TFile): UTF8String;
begin
Result:= EmptyStr;
{$IF DEFINED(MSWINDOWS)}
if fspDirectAccess in aFileSource.Properties then
Result:= SHGetInfoTip(aFile.Path, aFile.Name)
begin
Result:= StringReplace(gFileInfoToolTip.GetFileInfoToolTip(aFileSource, aFile), '\n', LineEnding, [rfReplaceAll]);
{$IF DEFINED(MSWINDOWS)}
Result:= IfThen(Result = EmptyStr, EmptyStr, Result + LineEnding) + SHGetInfoTip(aFile.Path, aFile.Name)
{$ENDIF}
end
else
{$ENDIF}
begin
if fpModificationTime in aFile.SupportedProperties then
with (aFile.Properties[fpModificationTime] as TFileModificationDateTimeProperty) do
Result:= GetDescription + #58#32 + AsString;
if fpSize in aFile.SupportedProperties then
with (aFile.Properties[fpSize] as TFileSizeProperty) do
Result:= IfThen(Result=EmptyStr, EmptyStr, Result + LineEnding) + GetDescription + #58#32 + AsString;
Result:= IfThen(Result = EmptyStr, EmptyStr, Result + LineEnding) + GetDescription + #58#32 + AsString;
if fpCompressedSize in aFile.SupportedProperties then
with (aFile.Properties[fpCompressedSize] as TFileCompressedSizeProperty) do
Result:= IfThen(Result=EmptyStr, EmptyStr, Result + LineEnding) + GetDescription + #58#32 + AsString;
Result:= IfThen(Result = EmptyStr, EmptyStr, Result + LineEnding) + GetDescription + #58#32 + AsString;
end;
end;
{ TFileInfoToolTip }
constructor TFileInfoToolTip.Create;
begin
FMaskItemList:= TMaskItemList.Create(True);
end;
destructor TFileInfoToolTip.Destroy;
begin
FreeThenNil(FMaskItemList);
inherited Destroy;
end;
procedure TFileInfoToolTip.Clear;
begin
begin
while FMaskItemList.Count > 0 do
begin
FMaskItemList[0].Free;
FMaskItemList.Delete(0);
end;
end;
end;
function TFileInfoToolTip.GetFileInfoToolTip(aFileSource: IFileSource;
const aFile: TFile): UTF8String;
var
I, J: Integer;
MaskItem: TMaskItem;
begin
Result:= EmptyStr;
for I:= 0 to FMaskItemList.Count - 1 do
begin
MaskItem:= FMaskItemList[I];
// Get hint by search template
if MaskItem.Mask[1] = '>' then
for J:= 0 to gSearchTemplateList.Count - 1 do
with gSearchTemplateList do
begin
if (Templates[J].TemplateName = PChar(MaskItem.Mask)+1) and
Templates[J].CheckFile(AFile) then
begin
Result:= FormatFileFunctions(MaskItem.Hint, aFile, aFileSource);
Exit;
end;
end;
// Get hint by file mask
if MatchesMaskList(AFile.Name, MaskItem.Mask) then
begin
Result:= FormatFileFunctions(MaskItem.Hint, aFile, aFileSource);
Exit;
end;
end;
end;
procedure TFileInfoToolTip.Load(AConfig: TXmlConfig; ANode: TXmlNode);
var
sMask,
sName,
sHint: UTF8String;
MaskItem: TMaskItem;
begin
Clear;
ANode := ANode.FindNode('CustomFields');
if Assigned(ANode) then
begin
ANode := ANode.FirstChild;
while Assigned(ANode) do
begin
if ANode.CompareName('CustomField') = 0 then
begin
if AConfig.TryGetValue(ANode, 'Name', sName) and
AConfig.TryGetValue(ANode, 'Mask', sMask) and
AConfig.TryGetValue(ANode, 'Hint', sHint) then
begin
MaskItem:= TMaskItem.Create;
MaskItem.Name := sName;
MaskItem.Mask := sMask;
MaskItem.Hint := sHint;
FMaskItemList.Add(MaskItem);
end
else
begin
DCDebug('Invalid entry in configuration: ' + AConfig.GetPathFromNode(ANode) + '.');
end;
end;
ANode := ANode.NextSibling;
end;
end;
end;
procedure TFileInfoToolTip.Save(AConfig: TXmlConfig; ANode: TXmlNode);
var
I : Integer;
SubNode: TXmlNode;
begin
ANode := AConfig.FindNode(ANode, 'CustomFields', True);
AConfig.ClearNode(ANode);
for I:=0 to FMaskItemList.Count - 1 do
begin
SubNode := AConfig.AddNode(ANode, 'CustomField');
AConfig.AddValue(SubNode, 'Name', FMaskItemList[I].Name);
AConfig.AddValue(SubNode, 'Mask', FMaskItemList[I].Mask);
AConfig.AddValue(SubNode, 'Hint', FMaskItemList[I].Hint);
end;
end;
end.

View file

@ -85,6 +85,7 @@ type
[] { invalid });
function FormatFileFunction(FuncS: string; AFile: TFile; const AFileSource: IFileSource): string;
function FormatFileFunctions(FuncS: String; AFile: TFile; const AFileSource: IFileSource): String;
function GetFileFunctionByName(FuncS: string): TFileFunction;
procedure FillContentFieldMenu(MenuItem: TMenuItem; OnMenuItemClick: TNotifyEvent);
@ -274,6 +275,33 @@ begin
//------------------------------------------------------
end;
function FormatFileFunctions(FuncS: String; AFile: TFile; const AFileSource: IFileSource): String;
var
p: Integer;
begin
Result:= EmptyStr;
while True do
begin
p := pos('[', FuncS);
if p = 0 then
Break
else if p > 1 then
Result:= Result + Copy(FuncS, 1, p - 1);
Delete(FuncS, 1, p);
p := pos(']', FuncS);
if p = 0 then
Break
else if p > 1 then
Result:= Result + FormatFileFunction(Copy(FuncS, 1, p - 1), AFile, AFileSource);
Delete(FuncS, 1, p);
end;
if Length(FuncS) <> 0 then
Result:= Result + FuncS;
end;
function GetFileFunctionByName(FuncS: String): TFileFunction;
var
AType, AFunc: String;

View file

@ -27,7 +27,8 @@ interface
uses
Classes, Controls, Forms, uExts, uColorExt, Graphics, uClassesEx, uMultiArc,
uColumns, uhotkeymanger, uActs, uSearchTemplate, uFileSourceOperationOptions,
uWFXModule, uWCXModule, uWDXModule, uwlxmodule, udsxmodule, uXmlConfig;
uWFXModule, uWCXModule, uWDXModule, uwlxmodule, udsxmodule, uXmlConfig,
uInfoToolTip;
type
{ Log options }
@ -164,6 +165,7 @@ var
gLuaLib:String;
gExts:TExts;
gColorExt:TColorExt;
gFileInfoToolTip: TFileInfoToolTip;
{ Fonts page }
gFonts: TDCFontsOptions;
@ -535,6 +537,7 @@ procedure CreateGlobs;
begin
gExts := TExts.Create;
gColorExt := TColorExt.Create;
gFileInfoToolTip := TFileInfoToolTip.Create;
glsHotDir := TStringListEx.Create;
glsDirHistory := TStringListEx.Create;
glsMaskHistory := TStringListEx.Create;
@ -556,6 +559,7 @@ end;
procedure DestroyGlobs;
begin
FreeThenNil(gColorExt);
FreeThenNil(gFileInfoToolTip);
FreeThenNil(glsDirHistory);
FreeThenNil(glsHotDir);
FreeThenNil(glsMaskHistory);
@ -774,6 +778,7 @@ begin
gExts.Clear;
gColorExt.Clear;
gFileInfoToolTip.Clear;
glsHotDir.Clear;
glsDirHistory.Clear;
glsMaskHistory.Clear;
@ -1438,6 +1443,14 @@ begin
gColorExt.Load(gConfig, Node);
end;
{ ToolTips page }
Node := Root.FindNode('ToolTips');
if Assigned(Node) then
begin
gShowToolTipMode := TShowToolTipMode(GetValue(Node, 'ShowToolTipMode', Integer(gShowToolTipMode)));
gFileInfoToolTip.Load(gConfig, Node);
end;
{ Layout page }
Node := Root.FindNode('Layout');
if Assigned(Node) then
@ -1550,7 +1563,6 @@ begin
gShowWarningMessages := GetValue(Node, 'ShowWarningMessages', gShowWarningMessages);
gSpaceMovesDown := GetValue(Node, 'SpaceMovesDown', gSpaceMovesDown);
gDirBrackets := GetValue(Node, 'DirBrackets', gDirBrackets);
gShowToolTipMode := TShowToolTipMode(GetValue(Node, 'ShowToolTipMode', Integer(gShowToolTipMode)));
end;
{ Auto refresh page }
@ -1712,6 +1724,11 @@ begin
SetValue(Node, 'UseFrameCursor', gUseFrameCursor);
gColorExt.Save(gConfig, Node);
{ ToolTips page }
Node := FindNode(Root, 'ToolTips', True);
SetValue(Node, 'ShowToolTipMode', Integer(gShowToolTipMode));
gFileInfoToolTip.Save(gConfig, Node);
{ Layout page }
Node := FindNode(Root, 'Layout', True);
SetValue(Node, 'MainMenu', gMainMenu);
@ -1798,7 +1815,6 @@ begin
SetValue(Node, 'ShowWarningMessages', gShowWarningMessages);
SetValue(Node, 'SpaceMovesDown', gSpaceMovesDown);
SetValue(Node, 'DirBrackets', gDirBrackets);
SetValue(Node, 'ShowToolTipMode', Integer(gShowToolTipMode));
{ Auto refresh page }
Node := FindNode(Root, 'AutoRefresh', True);