Recent

Author Topic: html help on Mac  (Read 7585 times)

RxRick

  • New Member
  • *
  • Posts: 23
html help on Mac
« on: July 14, 2010, 04:07:51 pm »
i'm trying to understand how to configure html help to work on the mac version of my app (it works fine on windows).

i'm still trying to wrap my head around how things work on the mac.

i'm using the htmlhelp1 example, calling help from the button click:
  ShowHelpOrErrorForKeyword('','HTML/index.html'); 

if i run the example via the lazarus IDE, no problem.

if i compile it, then run the app from Finder (or drag it to the dock), it throws up a dialog "Help context not found... was unable to find file /html/index.html".

if i run it from terminal it throws up a similar dialog: "... unable to find file /Developer/lazarus/examples/helphtml/htmlhelp1.app/Contents/MacOS/html/index.html"

if i add the html folder (and its contents) to the Contents/MacOS directory, it then runs fine from Terminal.

however, it will still does not find the help file if i run the app from Finder (or the dock).

i'd like to package the application for end users, but i can't figure out where to put the help file so the app can find it.

the wiki says 'On Unix there is no "application directory"' - so, where should i put the html help folder, and how do i tell the app where to find it?

RxRick

  • New Member
  • *
  • Posts: 23
Re: html help on Mac
« Reply #1 on: July 21, 2010, 07:18:48 pm »
Is anyone using help on the Mac?  If not, how do you link to your application help file?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: html help on Mac
« Reply #2 on: July 21, 2010, 07:36:59 pm »
Is anyone using help on the Mac?  If not, how do you link to your application help file?
actually i go directly to developer.apple.com using Safari

but let me look at your problem.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

RxRick

  • New Member
  • *
  • Posts: 23
Re: html help on Mac
« Reply #3 on: July 21, 2010, 09:56:23 pm »
thanks.

I tried putting the html folder in the same directory as the app bundle, in the app's bundle root, under Contents, under Contents/MacOS, under Contents/Resources, under my Users folder.

I was finally able to get it to "work" by placing the html folder in the Macintosh HD folder, but that seems extreme. would make more sense to have the help file for my app packaged in with the app bundle itself.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: html help on Mac
« Reply #4 on: July 21, 2010, 09:57:21 pm »
The problem is that LazHelpHTML component DEPENDS upon proper current directory set by the application.

Let's assume the application bundle path is: /Users/user/helphtml/helphtml.app

* When you start the application from the Lazarus. It's current directory is set to the directory of the bundle. (i.e. '/Users/user/helphtml'). So LazHelpHTML is able to resolve the correct path of html files: /Users/user/helphtml/HTML

* When you start the application by Finder (or from the Dock), it's current path is set to "/". What results in incorrect help file selected.

* When you start the application manually from terminal, it's current path is set to "/Users/user/helphtml/helphtml.app/Contents/MacOS" (the directory where the executable is located). It would work correct, but only if you copy the HTML dir into the bundle path. (which is wrong).

To correct things you need to adjust the current path (to the required one) whenever the application is started. For example (htmlhelp1.lpr):
Code: [Select]
program HTMLHelp1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms
  { add your units here }, Unit1, SysUtils, FileUtil;

procedure AdjustCurrentPath;
{$ifdef DARWIN}
var
  i : integer;
  path  : Ansistring;
begin
  path:=ExtractFileDir(Application.ExeName);
  for i:=1 to 3 do // remove: watnedpath/Bundle.app/Contents/MacOS/exe - 3 dirs
    path:=ExtractFileDir(path);
  SetCurrentDirUTF8( path );
end;
{$else}
begin
  // do nothing if not OSX
end;
{$endif}

begin
  Application.Initialize;
  AdjustCurrentPath;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.


I'm not HTML help specialist, but I guess, it's possible to avoid "relative" path usage in the component.

MacOSX NOTE:Application resources should NOT be stored out-side of the bundle. Help files should be kept at: bundle.app/Contents/Resources directory.
i.e.
Code: [Select]
bundle.app/Contents/Resources/HTML/index.html
bundle.app/Contents/Resources/HTML/edit1.html
bundle.app/Contents/Resources/HTML/edit2.html
And so current directory should be set to the bundle's resources instead.
However, the current example doesn't allow to keep HTML inside the bundle, so it's fine to change current directory to the bundle's directory, in this particular case.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

RxRick

  • New Member
  • *
  • Posts: 23
Re: html help on Mac
« Reply #5 on: July 21, 2010, 10:17:57 pm »
thank you very much, that is exactly what I needed, it works perfectly now.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: html help on Mac
« Reply #6 on: July 21, 2010, 10:18:35 pm »
thank you very much, that is exactly what I needed, it works perfectly now.
don't forget to remove all copies of HELP dir you've created ;)
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: html help on Mac
« Reply #7 on: July 21, 2010, 10:29:59 pm »
Yet another thing. F1 hotkey isn't working on Mac OS X.
Instead Command-? combination (Command-Shift-/) should be used.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz