You've already forked lazarus-ccr
Added support to sample apps for shelling on OS X; activated LCL DropFiles in sample apps
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1417 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -139,7 +139,12 @@ type
|
|||||||
HintWindow: THintWindow;
|
HintWindow: THintWindow;
|
||||||
HintVisible: boolean;
|
HintVisible: boolean;
|
||||||
|
|
||||||
|
{$IFNDEF LCL}
|
||||||
procedure wmDropFiles(var Message: TMessage); message wm_DropFiles;
|
procedure wmDropFiles(var Message: TMessage); message wm_DropFiles;
|
||||||
|
{$ELSE}
|
||||||
|
procedure DropFiles( Sender : TObject;
|
||||||
|
const FileNames: array of string);
|
||||||
|
{$ENDIF}
|
||||||
procedure CloseAll;
|
procedure CloseAll;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
@ -206,8 +211,11 @@ for I := 0 to MaxHistories-1 do
|
|||||||
SelectAllItem.ShortCut := ShortCut(VK_A, [ssMeta]);
|
SelectAllItem.ShortCut := ShortCut(VK_A, [ssMeta]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFNDEF LCL}
|
||||||
DragAcceptFiles(Handle, True);
|
DragAcceptFiles(Handle, True);
|
||||||
|
{$ELSE}
|
||||||
|
AllowDropFiles := True;
|
||||||
|
OnDropFiles := DropFiles;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
HintWindow := THintWindow.Create(Self);
|
HintWindow := THintWindow.Create(Self);
|
||||||
HintWindow.Color := $C0FFFF;
|
HintWindow.Color := $C0FFFF;
|
||||||
@ -218,8 +226,8 @@ var
|
|||||||
S: string;
|
S: string;
|
||||||
I: integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
{$IFNDEF DARWIN} //Launched file name not passed via command line with OS X.
|
// With OS X app, ParamStr not meaningful unless launched with --args switch.
|
||||||
if (ParamCount >= 1) then
|
if (ParamCount >= 1) {$IFDEF LCLCarbon} and (Copy(ParamStr(1), 1, 4) <> '-psn') {$ENDIF} then
|
||||||
begin {Parameter is file to load}
|
begin {Parameter is file to load}
|
||||||
{$IFNDEF LCL}
|
{$IFNDEF LCL}
|
||||||
S := CmdLine;
|
S := CmdLine;
|
||||||
@ -238,7 +246,6 @@ if (ParamCount >= 1) then
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Viewer.LoadFromFile(HtmlToDos(Trim(S)));
|
Viewer.LoadFromFile(HtmlToDos(Trim(S)));
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.OpenFileClick(Sender: TObject);
|
procedure TForm1.OpenFileClick(Sender: TObject);
|
||||||
@ -336,8 +343,12 @@ if (I <= 2) or (J > 0) then
|
|||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params),
|
ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params),
|
||||||
nil, SW_SHOWNORMAL);
|
nil, SW_SHOWNORMAL);
|
||||||
|
{$ELSE} //Not sure if this makes any sense since executable won't have .exe.
|
||||||
|
{$IFDEF LCLCarbon}
|
||||||
|
Shell('open -n "' + S + '" --args "' + Params + '"');
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('Open ' + S);
|
Shell('"' + S + '" "' + Params + '"');
|
||||||
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end
|
end
|
||||||
@ -366,7 +377,11 @@ if (I > 0) or (J > 0) then
|
|||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
ShellExecute(0, nil, pchar(URL), nil, nil, SW_SHOWNORMAL);
|
ShellExecute(0, nil, pchar(URL), nil, nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('Open ' + URL);
|
{$IFDEF LCLCarbon}
|
||||||
|
Shell('open "' + URL + '"');
|
||||||
|
{$ELSE}
|
||||||
|
Shell('"' + URL + '"'); //use LCL's OpenURL?
|
||||||
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Handled := True;
|
Handled := True;
|
||||||
Exit;
|
Exit;
|
||||||
@ -620,22 +635,27 @@ if OpenDialog.Execute then
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFNDEF LCL}
|
||||||
procedure TForm1.wmDropFiles(var Message: TMessage);
|
procedure TForm1.wmDropFiles(var Message: TMessage);
|
||||||
var
|
var
|
||||||
S: string[200];
|
S: string[200];
|
||||||
Ext: string;
|
Ext: string;
|
||||||
Count: integer;
|
Count: integer;
|
||||||
begin
|
begin
|
||||||
{$IFDEF MSWINDOWS}
|
|
||||||
Count := DragQueryFile(Message.WParam, 0, @S[1], 200);
|
Count := DragQueryFile(Message.WParam, 0, @S[1], 200);
|
||||||
{$IFNDEF LCL}
|
|
||||||
Length(S) := Count;
|
Length(S) := Count;
|
||||||
{$ELSE}
|
|
||||||
S[0] := Char(Count);
|
|
||||||
{$ENDIF}
|
|
||||||
DragFinish(Message.WParam);
|
DragFinish(Message.WParam);
|
||||||
if Count >0 then
|
if Count >0 then
|
||||||
begin
|
begin
|
||||||
|
{$ELSE}
|
||||||
|
procedure TForm1.DropFiles( Sender : TObject;
|
||||||
|
const FileNames : array of string);
|
||||||
|
var
|
||||||
|
S : string;
|
||||||
|
Ext: string;
|
||||||
|
begin
|
||||||
|
S := FileNames[0];
|
||||||
|
{$ENDIF}
|
||||||
Ext := LowerCase(ExtractFileExt(S));
|
Ext := LowerCase(ExtractFileExt(S));
|
||||||
if (Ext = '.htm') or (Ext = '.html') then
|
if (Ext = '.htm') or (Ext = '.html') then
|
||||||
Viewer.LoadFromFile(S)
|
Viewer.LoadFromFile(S)
|
||||||
@ -644,9 +664,10 @@ if Count >0 then
|
|||||||
else if (Ext = '.bmp') or (Ext = '.gif') or (Ext = '.jpg')
|
else if (Ext = '.bmp') or (Ext = '.gif') or (Ext = '.jpg')
|
||||||
or (Ext = '.jpeg') or (Ext = '.png') then
|
or (Ext = '.jpeg') or (Ext = '.png') then
|
||||||
Viewer.LoadImageFile(S);
|
Viewer.LoadImageFile(S);
|
||||||
|
{$IFNDEF LCL}
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
|
||||||
Message.Result := 0;
|
Message.Result := 0;
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.MediaPlayerNotify(Sender: TObject);
|
procedure TForm1.MediaPlayerNotify(Sender: TObject);
|
||||||
@ -843,7 +864,13 @@ WinExec(StrPCopy(PC, ParamStr(0)+' "'+NewWindowFile+'"'), sw_Show);
|
|||||||
ShellExecute(Handle, nil, StrPCopy(PC, ParamStr(0)),
|
ShellExecute(Handle, nil, StrPCopy(PC, ParamStr(0)),
|
||||||
StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL);
|
StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('Open ' + ParamStr(0));
|
{$IFDEF LCLCarbon}
|
||||||
|
Shell('open -n "' +
|
||||||
|
ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) +
|
||||||
|
'" --args "' + NewWindowFile + '"');
|
||||||
|
{$ELSE}
|
||||||
|
Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"');
|
||||||
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
@ -146,7 +146,12 @@ const
|
|||||||
HintVisible: boolean;
|
HintVisible: boolean;
|
||||||
TitleViewer: ThtmlViewer;
|
TitleViewer: ThtmlViewer;
|
||||||
|
|
||||||
|
{$IFNDEF LCL}
|
||||||
procedure wmDropFiles(var Message: TMessage); message wm_DropFiles;
|
procedure wmDropFiles(var Message: TMessage); message wm_DropFiles;
|
||||||
|
{$ELSE}
|
||||||
|
procedure DropFiles( Sender : TObject;
|
||||||
|
const FileNames: array of string);
|
||||||
|
{$ENDIF}
|
||||||
procedure CloseAll;
|
procedure CloseAll;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
@ -199,8 +204,11 @@ for I := 0 to MaxHistories-1 do
|
|||||||
SelectAll1.ShortCut := ShortCut(VK_A, [ssMeta]);
|
SelectAll1.ShortCut := ShortCut(VK_A, [ssMeta]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFNDEF LCL}
|
||||||
DragAcceptFiles(Handle, True);
|
DragAcceptFiles(Handle, True);
|
||||||
|
{$ELSE}
|
||||||
|
AllowDropFiles := True;
|
||||||
|
OnDropFiles := DropFiles;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
HintWindow := THintWindow.Create(Self);
|
HintWindow := THintWindow.Create(Self);
|
||||||
HintWindow.Color := $CCFFFF;
|
HintWindow.Color := $CCFFFF;
|
||||||
@ -281,9 +289,9 @@ if (I <= 2) or (J > 0) then
|
|||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params),
|
ShellExecute(Handle, nil, StrPCopy(PC, S), StrPCopy(PC2, Params),
|
||||||
nil, SW_SHOWNORMAL);
|
nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE} //Not sure if this makes any sense since executable won't have .exe.
|
||||||
{$IFDEF LCLCarbon}
|
{$IFDEF LCLCarbon}
|
||||||
Shell('Open "' + S + '.app"');
|
Shell('open -n "' + S + '" --args "' + Params + '"');
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('"' + S + '" "' + Params + '"');
|
Shell('"' + S + '" "' + Params + '"');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -316,9 +324,9 @@ if (I > 0) or (J > 0) then
|
|||||||
ShellExecute(Handle, nil, StrPCopy(PC, URL), nil, nil, SW_SHOWNORMAL);
|
ShellExecute(Handle, nil, StrPCopy(PC, URL), nil, nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
{$IFDEF LCLCarbon}
|
{$IFDEF LCLCarbon}
|
||||||
Shell('Open "' + URL + '.app"');
|
Shell('open "' + URL + '"');
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('"' + URL + '"');
|
Shell('"' + URL + '"'); //use LCL's OpenURL?
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Handled := True;
|
Handled := True;
|
||||||
@ -347,7 +355,7 @@ else OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
|
|||||||
{$ELSE} //Don't default to within app bundle.
|
{$ELSE} //Don't default to within app bundle.
|
||||||
else OpenDialog.InitialDir := ExtractFilePath(ParamStr(0)) + '../../../';
|
else OpenDialog.InitialDir := ExtractFilePath(ParamStr(0)) + '../../../';
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
//OpenDialog.FilterIndex := 1; //Form's Filter wasn't right, so set here
|
//OpenDialog.FilterIndex := 1; //Form's Filter isn't right, so set here
|
||||||
OpenDialog.Filter := 'HTML Files (*.htm,*.html)|*.htm;*.html'+
|
OpenDialog.Filter := 'HTML Files (*.htm,*.html)|*.htm;*.html'+
|
||||||
'|All Files (*.*)|*.*';
|
'|All Files (*.*)|*.*';
|
||||||
if OpenDialog.Execute then
|
if OpenDialog.Execute then
|
||||||
@ -372,8 +380,8 @@ var
|
|||||||
S: string;
|
S: string;
|
||||||
I: integer;
|
I: integer;
|
||||||
begin
|
begin
|
||||||
{$IFNDEF LCLCarbon} //Launched file name not passed via command line with app bundle.
|
// With OS X app, ParamStr not meaningful unless launched with --args switch.
|
||||||
if (ParamCount >= 1) then
|
if (ParamCount >= 1) {$IFDEF LCLCarbon} and (Copy(ParamStr(1), 1, 4) <> '-psn') {$ENDIF} then
|
||||||
begin {Parameter is file to load}
|
begin {Parameter is file to load}
|
||||||
{$IFNDEF LCL}
|
{$IFNDEF LCL}
|
||||||
S := CmdLine;
|
S := CmdLine;
|
||||||
@ -392,10 +400,10 @@ if (ParamCount >= 1) then
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
FrameViewer.LoadFromFile(HtmlToDos(Trim(S)));
|
FrameViewer.LoadFromFile(HtmlToDos(Trim(S)));
|
||||||
end
|
end
|
||||||
else {$ENDIF} if FileExists(ExtractFilePath(ParamStr(0))+'demo.htm') then
|
else if FileExists(ExtractFilePath(ParamStr(0))+'demo.htm') then
|
||||||
FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0))+'demo.htm')
|
FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0))+'demo.htm')
|
||||||
{If run from Lazarus IDE, HTML files probably won't be in executable's folder,
|
{If run from Lazarus IDE, HTML files probably won't be in executable's folder,
|
||||||
so look for them one level up (or 4 levels up with Carbon app bundle).}
|
so look for them one level up (or 4 levels up with OS X app bundle).}
|
||||||
else if FileExists(ExtractFilePath(ParamStr(0)) + '..' + PathDelim +
|
else if FileExists(ExtractFilePath(ParamStr(0)) + '..' + PathDelim +
|
||||||
{$IFDEF LCLCarbon} '../../../' + {$ENDIF} 'demo.htm') then
|
{$IFDEF LCLCarbon} '../../../' + {$ENDIF} 'demo.htm') then
|
||||||
FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0)) + '..' + PathDelim +
|
FrameViewer.LoadFromFile(ExtractFilePath(ParamStr(0)) + '..' + PathDelim +
|
||||||
@ -623,7 +631,9 @@ if FileExists(S) then
|
|||||||
StrPCopy(PC2, S+Dest), nil, SW_SHOWNORMAL);
|
StrPCopy(PC2, S+Dest), nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
{$IFDEF LCLCarbon}
|
{$IFDEF LCLCarbon}
|
||||||
Shell('Open "' + ParamStr(0) + '.app"');
|
Shell('open -n "' +
|
||||||
|
ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) +
|
||||||
|
'" --args "' + S+Dest + '"');
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('"' + ParamStr(0) + '" "' + S+Dest + '"');
|
Shell('"' + ParamStr(0) + '" "' + S+Dest + '"');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -631,24 +641,27 @@ if FileExists(S) then
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFNDEF LCL}
|
||||||
procedure TForm1.wmDropFiles(var Message: TMessage);
|
procedure TForm1.wmDropFiles(var Message: TMessage);
|
||||||
var
|
var
|
||||||
S: string[200];
|
S: string[200];
|
||||||
Count: integer;
|
Count: integer;
|
||||||
begin
|
begin
|
||||||
{$IFDEF MSWINDOWS}
|
|
||||||
Count := DragQueryFile(Message.WParam, 0, @S[1], 200);
|
Count := DragQueryFile(Message.WParam, 0, @S[1], 200);
|
||||||
{$IFNDEF LCL}
|
|
||||||
Length(S) := Count;
|
Length(S) := Count;
|
||||||
{$ELSE}
|
|
||||||
S[0] := Char(Count);
|
|
||||||
{$ENDIF}
|
|
||||||
DragFinish(Message.WParam);
|
DragFinish(Message.WParam);
|
||||||
if Count >0 then
|
if Count >0 then
|
||||||
FrameViewer.LoadFromFile(S);
|
FrameViewer.LoadFromFile(S);
|
||||||
{$ENDIF}
|
|
||||||
Message.Result := 0;
|
Message.Result := 0;
|
||||||
end;
|
end;
|
||||||
|
{$ELSE}
|
||||||
|
procedure TForm1.DropFiles( Sender : TObject;
|
||||||
|
const FileNames : array of string);
|
||||||
|
begin
|
||||||
|
if High(FileNames) >= 0 then {At least one file passed?}
|
||||||
|
FrameViewer.LoadFromFile(FileNames[0]);
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
procedure TForm1.CopyImagetoclipboardClick(Sender: TObject);
|
procedure TForm1.CopyImagetoclipboardClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
@ -860,7 +873,9 @@ begin
|
|||||||
StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL);
|
StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
{$IFDEF LCLCarbon}
|
{$IFDEF LCLCarbon}
|
||||||
Shell('Open "' + ParamStr(0) + '.app"');
|
Shell('open -n "' +
|
||||||
|
ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) +
|
||||||
|
'" --args "' + NewWindowFile + '"');
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"');
|
Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
Reference in New Issue
Block a user