[Lazarus] OpenDocument and Linux Mint

silvioprog silvioprog at gmail.com
Fri Apr 25 07:21:12 CEST 2014


2014-04-17 14:50 GMT-03:00 Mattias Gaertner <nc-gaertnma at netcologne.de>:

> On Thu, 17 Apr 2014 14:35:07 -0300
> silvioprog <silvioprog at gmail.com> wrote:
>
> > 2014-04-16 22:07 GMT-03:00 waldo kitty <wkitty42 at windstream.net>:
> > [...]
> >
> > > and you don't get any kind of exception or other error results??
> > >
> >
> > No error occurs, and it doesn't opens file. :/
> >
> > I'm trying to debug LCL in trying to figure out the problem ...
>
> The OpenDocument function does not raise exceptions under Linux. It
> returns false if no application was found.
>
> It should be improved to raise an exception for the errors it can spot.
> Like not finding the application or if the program returns bytes on
> Stderr or if the ExitCode<>0.


I found the error. In a terminal, when I call:

$ xdg-open test.txt

The "test.txt" file is opened into terminal. But when I call:

$ gnome-open test.txt

The "test.txt" file is opened into Pluma Editor (native text editor on
Linux Mint, like GEdit in Ubuntu).

Then seems a problem in Linux Mint (Mate).

To solve my problem, I changed the function from:

[code]
function OpenDocument(APath: String): Boolean;
var
  lApp: string;
begin
  // Android uses this
  if Assigned(OpenDocumentWidgetsetImplementation) then
  begin
    Result := OpenDocumentWidgetsetImplementation(APath);
    Exit;
  end;

  Result := True;
  if not FileExistsUTF8(APath) then exit(false);

  lApp:=FindFilenameOfCmd('xdg-open'); // Portland OSDL/FreeDesktop
standard on Linux
  if lApp='' then
    lApp:=FindFilenameOfCmd('kfmclient'); // KDE command
  if lApp='' then
    lApp:=FindFilenameOfCmd('gnome-open'); // GNOME command
  if lApp='' then
    Exit(False);

  if (APath<>'') and (APath[1]<>'"') then
    APath:=QuotedStr(APath);
  RunCmdFromPath(lApp,APath);
end;
[/code]

To:

[code]
function OpenDocument(const APath: String): Boolean;
var
  lApp: string;
begin
  // Android uses this
  if Assigned(OpenDocumentWidgetsetImplementation) then
  begin
    Result := OpenDocumentWidgetsetImplementation(APath);
    Exit;
  end;

  Result := True;
  if not FileExistsUTF8(APath) then exit(false);

  lApp:=FindFilenameOfCmd('gnome-open'); // GNOME command
  if lApp='' then
    lApp:=FindFilenameOfCmd('kfmclient') // KDE command
  else
  if lApp='' then
    lApp:=FindFilenameOfCmd('xdg-open') // Portland OSDL/FreeDesktop
standard on Linux
  else
  if lApp='' then
    Exit(False);

  if (APath<>'') and (APath[1]<>'"') then
    APath:=QuotedStr(APath);
  RunCmdFromPath(lApp,APath);
end;
[/code]

Quick fix! :p

-- 
Silvio Cl├ęcio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140425/28afc570/attachment-0003.html>


More information about the Lazarus mailing list