Home Download Buy Blog Forum Support

Better help again :)

Better help again :)

Postby artee on Tue Oct 13, 2009 7:17 pm

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
artee
 
Posts: 32
Joined: Sat May 30, 2009 10:33 pm

Re: Better help again :)

Postby artee on Wed Oct 21, 2009 9:28 am

Because nobody is interested in better help in Sublime ;P 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 :)
[/list]

Regards,
Artur
artee
 
Posts: 32
Joined: Sat May 30, 2009 10:33 pm

Re: Better help again :)

Postby jps on Wed Oct 21, 2009 12:09 pm

I haven't forgotten about it, it's just sitting on the todo list :)

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.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: Better help again :)

Postby artee on Wed Oct 21, 2009 1:28 pm

Hi

Done :)
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: Select all
# -*- 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


and binding key:
Code: Select all
<bindings>
  <binding key="F1" command="customHelp"/>
</bindings>


Regards,
Artur
artee
 
Posts: 32
Joined: Sat May 30, 2009 10:33 pm

Re: Better help again :)

Postby tgkeul on Wed Oct 21, 2009 7:32 pm

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).
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: Better help again :)

Postby artee on Wed Oct 21, 2009 9:10 pm

tgkeul wrote: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).

This is a good question to Jon why Sublime crashed ;)
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 :)

Regards,
Artur
artee
 
Posts: 32
Joined: Sat May 30, 2009 10:33 pm

Re: Better help again :)

Postby tgkeul on Thu Oct 22, 2009 6:24 pm

The only thing I changed was the help file
Code: Select all
        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
;)
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: Google [Bot], karisublime and 18 guests