mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
ADD: Lua Stash functions, GetAsText()/AddAsText()/SetAsText
This commit is contained in:
parent
3831c8a856
commit
c19d7694ee
2 changed files with 87 additions and 1 deletions
|
|
@ -6,7 +6,7 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils, syncobjs,
|
||||
uFile, uFileSystemFileSource;
|
||||
uFile, uFileSystemFileSource, DCOSUtils;
|
||||
|
||||
type
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ type
|
|||
private
|
||||
procedure addPath( const path: String ); inline;
|
||||
procedure removePath( const path: String ); inline;
|
||||
procedure doAddFromString(const pathsStr: String);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
|
@ -29,7 +30,12 @@ type
|
|||
function count: Integer;
|
||||
procedure addPaths( const files: TFiles );
|
||||
procedure removePaths( const files: TFiles );
|
||||
|
||||
function toFiles: TFiles;
|
||||
function toString: String; override;
|
||||
|
||||
procedure addFromString( const pathsStr: String );
|
||||
procedure setFromString( const pathsStr: String );
|
||||
end;
|
||||
|
||||
var
|
||||
|
|
@ -147,6 +153,61 @@ begin
|
|||
Result:= files;
|
||||
end;
|
||||
|
||||
function TStashFilesBackend.toString: String;
|
||||
var
|
||||
stringBuilder: TAnsiStringBuilder;
|
||||
path: String;
|
||||
begin
|
||||
stringBuilder:= TAnsiStringBuilder.Create;
|
||||
|
||||
_lockObject.Acquire;
|
||||
try
|
||||
for path in _paths do begin
|
||||
stringBuilder.Append( path );
|
||||
stringBuilder.Append( #10 );
|
||||
end;
|
||||
finally
|
||||
_lockObject.Release;
|
||||
end;
|
||||
|
||||
Result:= stringBuilder.ToString;
|
||||
end;
|
||||
|
||||
procedure TStashFilesBackend.doAddFromString(const pathsStr: String);
|
||||
var
|
||||
pathsArray: TStringArray;
|
||||
path: String;
|
||||
begin
|
||||
pathsArray:= pathsStr.Split( #10 );
|
||||
for path in pathsArray do begin
|
||||
if path.IsEmpty then
|
||||
continue;
|
||||
if mbFileSystemEntryExists(path) then
|
||||
self.addPath( path );
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TStashFilesBackend.addFromString(const pathsStr: String);
|
||||
begin
|
||||
_lockObject.Acquire;
|
||||
try
|
||||
doAddFromString( pathsStr );
|
||||
finally
|
||||
_lockObject.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TStashFilesBackend.setFromString(const pathsStr: String);
|
||||
begin
|
||||
_lockObject.Acquire;
|
||||
try
|
||||
_paths.Clear;
|
||||
doAddFromString( pathsStr );
|
||||
finally
|
||||
_lockObject.Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
stashFilesBackend:= TStashFilesBackend.Create;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ uses
|
|||
uFilePanelSelect, uMasks, LazFileUtils, Character, UnicodeData,
|
||||
DCBasicTypes, Variants, uFile, uFileProperty, uFileSource,
|
||||
uFileSourceProperty, uFileSourceUtil, uFileSystemFileSource,
|
||||
uStashFilesBackend,
|
||||
uDefaultFilePropertyFormatter, DCDateTimeUtils, uShellExecute;
|
||||
|
||||
procedure luaPushSearchRec(L : Plua_State; Rec: PSearchRecEx);
|
||||
|
|
@ -517,6 +518,24 @@ begin
|
|||
Clipboard.SetAsHtml(luaL_checkstring(L, 1));
|
||||
end;
|
||||
|
||||
function luaStashGetAsText(L : Plua_State) : Integer; cdecl;
|
||||
begin
|
||||
Result:= 1;
|
||||
lua_pushstring(L, stashFilesBackend.ToString);
|
||||
end;
|
||||
|
||||
function luaStashAddAsText(L : Plua_State) : Integer; cdecl;
|
||||
begin
|
||||
Result:= 0;
|
||||
stashFilesBackend.addFromString(luaL_checkstring(L, 1));
|
||||
end;
|
||||
|
||||
function luaStashSetAsText(L : Plua_State) : Integer; cdecl;
|
||||
begin
|
||||
Result:= 0;
|
||||
stashFilesBackend.setFromString(luaL_checkstring(L, 1));
|
||||
end;
|
||||
|
||||
function luaMessageBox(L : Plua_State) : Integer; cdecl;
|
||||
var
|
||||
flags: Integer;
|
||||
|
|
@ -923,6 +942,12 @@ begin
|
|||
luaP_register(L, 'SetAsHtml', @luaClipbrdSetHtml);
|
||||
lua_setglobal(L, 'Clipbrd');
|
||||
|
||||
lua_newtable(L);
|
||||
luaP_register(L, 'GetAsText', @luaStashGetAsText);
|
||||
luaP_register(L, 'AddAsText', @luaStashAddAsText);
|
||||
luaP_register(L, 'SetAsText', @luaStashSetAsText);
|
||||
lua_setglobal(L, 'Stash');
|
||||
|
||||
lua_newtable(L);
|
||||
luaP_register(L, 'MessageBox', @luaMessageBox);
|
||||
luaP_register(L, 'InputQuery', @luaInputQuery);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue