Sublime Forum

Better help again :)

#1

Hi

Do you remember my post about better help integration with existing help files, etc… ?
See: viewtopic.php?f=4&t=517#p1739

Is there any progress in implementation of this functionality?
Jon, if you want I can provide full source code for this functionality.
It should be pretty easy to implement and it will be very useful.

Thanks,
Artur

0 Likes

Python help (simple)
#2

Because nobody is interested in better help in Sublime :stuck_out_tongue_winking_eye: so may I have a request for additional information available on API level:
[list=]
*] HWND - Sublime main window handle. This param is required to be passed to HtmlHelp function.
*] ProcessId - Sublime process handle. Can be useful in the future :smile:
[/list]

Regards,
Artur

0 Likes

#3

I haven’t forgotten about it, it’s just sitting on the todo list :slight_smile:

I’m not too keen on wrapping the HTML help calls as part of the API, but if it is too painful to call via Python, there’s no reason a standalone DLL can’t be made and distributed with a package.

I’ll look at exposing the window handle from the API, I’m sure it’d be handy in a bunch of circumstances.

0 Likes

#4

Hi

Done :smile:
Desktop handle was used instead of Sublime foreground window because of problems when WinHelp popup window is displayed.
This is only a draft whole functionality, however it is quite useful.
Example for Python help:

[code]# -- coding: utf-8 --

Some code based on http://d.hatena.ne.jp/pipehead/20071121/1195597559

import ctypes
from ctypes.wintypes import BOOL

import os
import sublime, sublimeplugin

def _T(string):
if isinstance(string, str):
string = unicode(string, ‘utf-8’)
return string

HH_KEYWORD_LOOKUP = 0x000D

class c_tchar_p(ctypes._SimpleCData):
type = ‘Z’ # c_wchar_p

class HH_AKLINK(ctypes.Structure):
fields = (
(‘cbStruct’, ctypes.c_int), # sizeof this structure
(‘fReserved’, BOOL), # must be FALSE (really!)
(‘pszKeywords’, c_tchar_p), # semi-colon separated keywords
(‘pszUrl’, c_tchar_p), # URL to jump to if no keywords found (may be NULL)
(‘pszMsgText’, c_tchar_p), # Message text to display in MessageBox if pszUrl is NULL and no keyword match
(‘pszMsgTitle’, c_tchar_p), # Message text to display in MessageBox if pszUrl is NULL and no keyword match
(‘pszWindow’, c_tchar_p), # Window to display URL in
(‘fIndexOnFail’, BOOL) # Displays index if keyword lookup fails.
)

class CustomHelpCommand(sublimeplugin.TextCommand):
def run(self, view, args):
selected = ]
for region in view.sel():
selected.append(view.substr(view.word(region)) if region.empty() else view.substr(region))
selected = ‘;’.join(selected)
print ‘Displaying help topics for:’, selected

    ak = HH_AKLINK(ctypes.sizeof(HH_AKLINK), False, _T(selected), None, None, None, None, True)
    HtmlHelp = ctypes.windll.LoadLibrary('hhctrl.ocx').HtmlHelpW
    HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), _T('C:\\Python25\\Doc\\Python25.chm'), HH_KEYWORD_LOOKUP, ctypes.byref(ak))

def isEnabled(self, view, args):
  return True[/code]

and binding key:

<bindings> <binding key="F1" command="customHelp"/> </bindings>

Regards,
Artur

0 Likes

#5

artee, I tried your code and it works file - almost. When I close the help window sublime 20091017 aborts with a memory error ( could not read at 00000x0 or so).

0 Likes

#6

This is a good question to Jon why Sublime crashed :wink:
Do you changed above code? Maybe path is passed in invalid format to HTML control? In Windows we have two situations when we wanted to using strings: MBCS or Unicode coding. Depending on that type wa have to call different methods - with ‘W’ or ‘A’ appendix, in this case HTMLHelpW or HTMLHelpA respectively.
I’ve tested it on XP and Vista Pro and Bussines (with 20091010 and 20091017) and works fine but…
HTMLHelp control is half-baked and I’ve noticed several problems when improper window handle is used, e.g. instead of GetDesktopWindow -
GetForegroundWindow will be used it causes deadlock when HTMLHelp topic search modal dialog is displayed.
This is why I wanted to HTMLHelp related functionality should be implemented inside Sublime…
There are no problems with types marshaling or calling additional functionality using ctypes.
Only simple API call with typical return code :smile:

Regards,
Artur

0 Likes

#7

The only thing I changed was the help file

HtmlHelp(ctypes.windll.user32.GetDesktopWindow(), _T('C:\\Python26\\Doc\\Python263.chm'), HH_KEYWORD_LOOKUP, ctypes.byref(ak))
But I identified two workarounds I can live with

  • never close the help file
  • launch the helpfile from Windows toolbar

:wink:

0 Likes