Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-07

ChmHelpPkg: better way to show all CHMs when starting lhelp?

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reinier Olislagers

Hi list,

Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) should open all help files to enable content/index search

I want to open all .chm files in the help database when starting up lhelp, which allows browsing and searching through the entire documentation set.

See modified code below.

Though this seems to work (I get the RTL, FCL, LCL and reference guide CHMs displayed, and the proper help subject is shown), it's clunky:
- using built-in sleep periods seems clunky. Tried removing this, but IIRC the reference guide then fails to load.
- the commented out mime type support detection seems to fail, which causes other help databases to display (e.g. browser-based help)
- lhelp flashes while the dbs are being loaded; I suppose there's nothing we can do about that?

Any suggestions?

Thanks,
Reinier

lazarus\components\chmhelp\packages\idehelp\lazchmhelp.pas

function TChmHelpViewer.ShowNode(Node: THelpNode; var ErrMsg: string):
TShowHelpResult;
var
...
  WasRunning: boolean;
...
  if ExtractFileNameOnly(GetHelpExe) = 'lhelp' then begin
    //start of modifications
    WasRunning:=fHelpConnection.ServerRunning;
    fHelpConnection.StartHelpServer(HelpLabel, GetHelpExe);
    // If the server is not already running, open all chm files after it
has started
    // This will allow cross-chm (LCL, FCL etc) searching and browsing
in lhelp.
    if not(WasRunning) then begin
      for i := 0 to HelpDatabases.Count-1 do begin
        //this doesn't seem to work - no dbs opened:
        //if HelpDatabases[i].SupportsMimeType('application/x-chm') then
begin // Only open chm help files
        HelpDatabases[i].ShowTableOfContents;
        Sleep(200); //give viewer chance to open file. todo: better way
of doing this?
      end;
    end;
    //end of modifications
    Res := fHelpConnection.OpenURL(FileName, Url);

Reply by email

Mark Morgan Lloyd
to Reinier Olislagers
Reinier Olislagers wrote 15 lines
Hi list, Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) should open all help files to enable content/index search I want to open all .chm files in the help database when starting up lhelp, which allows browsing and searching through the entire documentation set. See modified code below. Though this seems to work (I get the RTL, FCL, LCL and reference guide CHMs displayed, and the proper help subject is shown), it's clunky: - using built-in sleep periods seems clunky. Tried removing this, but IIRC the reference guide then fails to load.

Presumably there's no back-channel that allows lhelp to confirm that it's just completed a load. Can something writing via SimpleIPC check whether the last message has been read, and would putting a dummy message between CHM names help?

I've just checked on Linux and if I have two logins the lhelp activity is correctly distinct. It would probably be wise if somebody checked this on a Windows system that allows multiple logins, i.e. "Terminal Server" or whatever the modern equivalent is.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
I've just checked on Linux and if I have two logins the lhelp activity is correctly distinct. It would probably be wise if somebody checked this on a Windows system that allows multiple logins, i.e. "Terminal Server" or whatever the modern equivalent is.

There's a problem which I think will affect all unixes: if two copies of lhelp are fired up with the same parameters, the first one that terminates knocks out the unix-domain socket and the second one will bomb when it tries to do the same.

The solution I've used for this in the past is to append a PID, it does mean though that something has to look for and delete "orphans". I'd add that my preference is to put things like this in the user's home directory if possible, since that implicitly limits the possibility of clashes on a multiuser system.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Reinier Olislagers
to Mark Morgan Lloyd: Presumably there's no back-channel that allows lhelp to confirm that it's just completed…
Mark Morgan Lloyd wrote 21 lines
Reinier Olislagers wrote: > Hi list, > > Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) > should open all help files to enable content/index search > > I want to open all .chm files in the help database when starting up > lhelp, which allows browsing and searching through the entire > documentation set. > > See modified code below. > > Though this seems to work (I get the RTL, FCL, LCL and reference guide > CHMs displayed, and the proper help subject is shown), it's clunky: > - using built-in sleep periods seems clunky. Tried removing this, but > IIRC the reference guide then fails to load. Presumably there's no back-channel that allows lhelp to confirm that it's just completed a load. Can something writing via SimpleIPC check whether the last message has been read, and would putting a dummy message between CHM names help?

Thanks, Mark.

Could very well be, but the code I showed is at a higher abstraction level... and I don't know enough about other similar functions (i.e. what the data structures mean) which one to use unless I do a lot more digging.

Reply by email

Reinier Olislagers
to Reinier Olislagers: Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) should open all…

Let's see if somebody has some good ideas about the problem described below.

Thanks,
Reinier

Reinier Olislagers wrote 15 lines
Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) should open all help files to enable content/index search I want to open all .chm files in the help database when starting up lhelp, which allows browsing and searching through the entire documentation set. See modified code below. Though this seems to work (I get the RTL, FCL, LCL and reference guide CHMs displayed, and the proper help subject is shown), it's clunky: - using built-in sleep periods seems clunky. Tried removing this, but IIRC the reference guide then fails to load. - the commented out mime type support detection seems to fail, which causes other help databases to display (e.g. browser-based help)

====> this is my main problem.

Any hints on how to solve this?
Thanks.

Show quoted text 32 lines
- lhelp flashes while the dbs are being loaded; I suppose there's nothing we can do about that? lazarus\components\chmhelp\packages\idehelp\lazchmhelp.pas function TChmHelpViewer.ShowNode(Node: THelpNode; var ErrMsg: string): TShowHelpResult; var ... WasRunning: boolean; ... if ExtractFileNameOnly(GetHelpExe) = 'lhelp' then begin //start of modifications WasRunning:=fHelpConnection.ServerRunning; fHelpConnection.StartHelpServer(HelpLabel, GetHelpExe); // If the server is not already running, open all chm files after it has started // This will allow cross-chm (LCL, FCL etc) searching and browsing in lhelp. if not(WasRunning) then begin for i := 0 to HelpDatabases.Count-1 do begin //this doesn't seem to work - no dbs opened: //if HelpDatabases[i].SupportsMimeType('application/x-chm') then begin // Only open chm help files HelpDatabases[i].ShowTableOfContents; Sleep(200); //give viewer chance to open file. todo: better way of doing this? end; end; //end of modifications Res := fHelpConnection.OpenURL(FileName, Url);

Reply by email

Reinier Olislagers
to Reinier Olislagers
Show quoted text 9 lines
On 21-7-2012 13:56, Reinier Olislagers wrote: > Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) > should open all help files to enable content/index search > > I want to open all .chm files in the help database when starting up > lhelp, which allows browsing and searching through the entire > documentation set. > > See modified code below.

By explicitly adding an 'application/x-chm' mime type to some CHM help database classes, I now got the LCL.CHM help to open in addition to whatever lhelp will search for (and I'm avoiding opening online help). However, I still don't get e.g. rtl.chm open... what code would I need to edit there?

Wondering if this is the right way to go?
Isn't there some way to recurse through all *.chm files in the chmd files dir and open the corresponding table of contents URL/node?

Thanks,
Reinier
-------------- next part --------------
Index: components/chmhelp/packages/idehelp/lazchmhelp.pas
===================================================================
--- components/chmhelp/packages/idehelp/lazchmhelp.pas	(revision 39547)
+++ components/chmhelp/packages/idehelp/lazchmhelp.pas	(working copy)
@@ -340,6 +340,7 @@
 function TChmHelpViewer.ShowNode(Node: THelpNode; var ErrMsg: string
   ): TShowHelpResult;
 var
+  i: integer;
   FileName: String;
   Url: String;
   Res: TLHelpResponse;
@@ -347,6 +348,7 @@
   Proc: TProcessUTF8;
   FoundFileName: String;
   LHelpPath: String;
+  WasRunning: boolean;
 begin
   if Pos('file://', Node.URL) = 1 then
   begin
@@ -382,7 +384,25 @@
   FileName := CleanAndExpandFilename(FoundFileName);
   if ExtractFileNameOnly(GetHelpExe) = 'lhelp' then begin
+    WasRunning := fHelpConnection.ServerRunning;
     fHelpConnection.StartHelpServer(HelpLabel, GetHelpExe);
+    // If the server is not already running, open all chm files after it has started
+    // This will allow cross-chm (LCL, FCL etc) searching and browsing in lhelp.
+    if not(WasRunning) then begin
+      for i := 0 to HelpDatabases.Count-1 do begin
+        // Only open chm help files (no online html help etc)
+        // Using SupportsMimetype would seem to be the solution here.
+        // This does mean that all classes providing chm file support add
+        // AddSupportedMimeType('application/x-chm');
+        // in their constructors as they normally inherit
+        // text/html from their HTML help parents.
+        // this still does not open all help files such as rtl.chm
+        if HelpDatabases[i].SupportsMimeType('application/x-chm') then begin
+          HelpDatabases[i].ShowTableOfContents;
+          Sleep(200); //give viewer chance to open file. todo: better way of doing this?
+        end;
+      end;
+    end;
     Res := fHelpConnection.OpenURL(FileName, Url);
   end else begin
     if Trim(fHelpExeParams) = '' then
Index: components/chmhelp/packages/idehelp/chmprog.pas
===================================================================
--- components/chmhelp/packages/idehelp/chmprog.pas	(revision 39547)
+++ components/chmhelp/packages/idehelp/chmprog.pas	(working copy)
@@ -124,6 +124,8 @@
 constructor TFPCDirectivesHelpDatabase.Create(TheOwner: TComponent);
 begin
   inherited Create(TheOwner);
+  // Needed for getting lhelp to auto-open this db on start:
+  AddSupportedMimeType('application/x-chm');
   FDirectiveNodes := TFPList.Create;
 end;
Index: components/chmhelp/packages/idehelp/chmlcl.pas
===================================================================
--- components/chmhelp/packages/idehelp/chmlcl.pas	(revision 39547)
+++ components/chmhelp/packages/idehelp/chmlcl.pas	(working copy)
@@ -53,6 +53,8 @@
 constructor TLclChmHelpDatabase.Create(TheOwner: TComponent);
 begin
   inherited Create(TheOwner);
+  // Needed for getting lhelp to auto-open this db on start:
+  AddSupportedMimeType('application/x-chm');
   FBaseURL := THelpBaseURLObject.Create;
   FBaseURL.BaseURL := 'lcl.chm://';
   BasePathObject := FBaseURL;
Index: components/chmhelp/packages/idehelp/chmlangref.pas
===================================================================
--- components/chmhelp/packages/idehelp/chmlangref.pas	(revision 39547)
+++ components/chmhelp/packages/idehelp/chmlangref.pas	(working copy)
@@ -68,6 +68,8 @@
 constructor TLangRefHelpDatabase.Create(TheOwner: TComponent);
 begin
   inherited Create(TheOwner);
+  // Needed for getting lhelp to auto-open this db on start:
+  AddSupportedMimeType('application/x-chm');
   FKeywordNodes := TList.Create;
   FKeyWordsList := TStringList.Create;
   FKeyWordsList.CaseSensitive := False;

Reply by email

Reinier Olislagers
to Reinier Olislagers
Reinier Olislagers wrote 18 lines
> On 21-7-2012 13:56, Reinier Olislagers wrote: >> Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) >> should open all help files to enable content/index search >> >> I want to open all .chm files in the help database when starting up >> lhelp, which allows browsing and searching through the entire >> documentation set. >> >> See modified code below. By explicitly adding an 'application/x-chm' mime type to some CHM help database classes, I now got the LCL.CHM help to open in addition to whatever lhelp will search for (and I'm avoiding opening online help). However, I still don't get e.g. rtl.chm open... what code would I need to edit there? Wondering if this is the right way to go? Isn't there some way to recurse through all *.chm files in the chmd files dir and open the corresponding table of contents URL/node?

Thanks for the overwhelming responses ;)

Ok, I got all chms to open now, please see patch at http://bugs.freepascal.org/view.php?id=22110

Thanks,
Reinier

Reply by email

Reinier Olislagers
to Reinier Olislagers
Reinier Olislagers wrote 10 lines
On 15-12-2012 12:43, Reinier Olislagers wrote: >> On 21-7-2012 13:56, Reinier Olislagers wrote: >>> Editing ChmHelpPkg to try and solve bug 22110 Help (at least CHM help) >>> should open all help files to enable content/index search >>> >>> I want to open all .chm files in the help database when starting up >>> lhelp, which allows browsing and searching through the entire >>> documentation set. Ok, I got all chms to open now, please see patch at http://bugs.freepascal.org/view.php?id=22110

Thanks for the commit in r39551, Mattias!

Reply by email