Jump to content

MouseHoverCallTips [11/24/2023]


Recommended Posts

Can you add a timer or something to make the tip go away after some time if mouse isn't over a function?

I think that's what the OnDwellEnd function is for.

Another thing I thought of though, I think there's a way to use the lexer to tell what kind of word you are hovering. You should restrict the calltips to words the lexer identifies as functions so you don't get random calltips from comments or strings, etc.

Link to comment
Share on other sites

That is what onDwellEnd is for but it's either messed up or I am using it wrong (most likely). I'll look into the timer as an alternative.

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

Edited by LaCastiglione
Link to comment
Share on other sites

Here's where the strangeness comes in: you have to switch buffers before it will work on first load.

That's the opposite of the initial behavior. (working on a file/buffer after a file open, but not after switching buffers).

Maybe you need to use both OnOpen() and OnSwitchFile().

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

I tried this but nothing doing:

MouseHoverCallTips = EventClass:new(Common)



function MouseHoverCallTips:OnOpen(path)

    MouseHoverCallTips:initialize_mouse_dwell()

    return true

end



function MouseHoverCallTips:OnSwitchFile(path)

    MouseHoverCallTips:initialize_mouse_dwell()

    return true

end



function MouseHoverCallTips:initialize_mouse_dwell()

    local mousehover_calltips_dwelltime = tonumber(props["mousehover.calltips.dwelltime"])



    if (mousehover_calltips_dwelltime == nil) then

        mousehover_calltips_dwelltime = 700 -- default

    end



    scite.SendEditor(SCI_SETMOUSEDWELLTIME, mousehover_calltips_dwelltime)



    return true

end



function MouseHoverCallTips:OnDwellStart(position, word)

    if (word == "") then

        return nil

    end



    local directory = props["SciteDefaultHome"] .. "apiau3.api"



    local file = io.open(directory, "r")



    local parens_start

    local parens_end

    local char_start

    local char_end



    for line in file:lines() do

        if (string.find(line, word)) then

            -- filter out entries ending with ?4, ?3, ?2, & ?1

            for var = 1, 4 do

                char_start, char_end = string.find(line, '?' .. var)



                if (char_start ~= nil) then

                    file:close()

                    return nil

                end

            end



            parens_start, parens_end = string.find(line, "%)")

            if (parens_start ~= nil) then

                line = string.gsub(line, "%)", "%)n", 1)

            end



            file:close()



            scite.SendEditor(SCI_CALLTIPSHOW, position, line)



            return true

        end

    end



    file:close()



    return true

end



function MouseHoverCallTips:OnDwellEnd()

    scite.SendEditor(SCI_CALLTIPCANCEL)

    return true

end

Edited by LaCastiglione
Link to comment
Share on other sites

I looked into that lexer and I can't make heads or tails of it. I kinda have an idea of what's going on. You find out what kind of word you're at in the file (variable, function, comment, etc) and then you give that information to the styler along with a start position which takes over from there.

You don't have to understand the lexer I think. Just read the style of the first character of your word with SCI_GETSTYLEAT

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Just read the style of the first character of your word with SCI_GETSTYLEAT

Doh! I understand now. I do that from lua. Excellent. Thank you!

Edit: Ok, I did it and it works great! OP updated.

Edited by LaCastiglione
Link to comment
Share on other sites

I tried this but nothing doing: ...

It should. (CQ: working for me.)

- OnOpen(): run's on every file that's loaded while scite is starting. And on files that are user loaded after the scite startup.

But note that OnSwitchFile() is also run on the active file/buffer if its not the last loaded file at scite startup. (and not on user loaded files/buffers ... until you switch buffers of course.)

PS: is OnDwellEnd() active? ... or not yet, as its never executed.on this side.

---

(I'm not sure what behavior's are scite4autoit related or native scites related.)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

AFAIK there is no OnDwellEnd(). OnDwellStart() is called with an empty string to signify that event according to the old documentation I read. If there is an event in later SciTE then the Events class isn't invoking it on inherited classes unless Jos caught it and added it.

Link to comment
Share on other sites

Heh. You know something. I'm looking at the documentation again. I have no idea where I got onDwellEnd. Maybe my brain wished for something like that and tried to make it so.

Doh.

"OnDwellStart will receive the position of the mouse and the word under the mouse as arguments and the word will be empty when the mouse starts moving." So I updated the lua in the op.

Edited by LaCastiglione
Link to comment
Share on other sites

Optional code suggestion:

-- 'if MouseHoverCallTips:IsAu3File(path) then', or 'if self:IsAu3File(path) then'.
-- Although I'm not sure if there is a significant/important differance between the two. (just to be clear)
function MouseHoverCallTips:IsAu3File(path)
    -- working, but I'm not sure if there is a better way.
    -- note: string.sub(props["au3"]), -4) ... assuming extention is 3 characters. (alt: ditch leading '*' character.)
    if (string.lower(string.sub(path, -4)) == string.lower(string.sub(props["au3"], -4))) then
        return true
    end
    return false
end

PS: Not sure if it matters. But just in case. There is no 'file:close()' after the "for line .." loop in OnDwellStart(). (for all I know the open file might be auto-closed on hitting EOF, or on exiting the function.)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Roger ... Looks a little odd with those comments. ;)

Tried to see if there was a alternative way to get a hold of 'all' the API function definitions that are actively used by the current (local user) scite4autoit setup ... but no luck so far.

Anyone know if there is a other way than doing it the file:open way ?

Anyway ... extended the definition finder a bit to do it anyway. (added+changed functions only) (LC: use as you see fit.)

function MouseHoverCallTips:GetFuncDef(word, filespecList, delim)
    for filespec in string.gmatch(filespecList, "[^;]+") do
        local file = io.open(filespec, "r")
        if file ~= nil then
            local parens_start
            for line in file:lines() do
                if (string.find(line, word)) then
                    parens_start = string.find(line, "%)")
                    if (parens_start ~= nil) then
                        line = string.gsub(line, "%)(.)", "%)n%1") -- changed: was adding a trailing empty line in some cases.
                    end
                    file:close()
                    return line
                end
            end
            file:close()
        end
    end
end

function MouseHoverCallTips:OnDwellStart(position, word)
    if (word == "") then
        if (scite.SendEditor(SCI_CALLTIPACTIVE)) then
            scite.SendEditor(SCI_CALLTIPCANCEL)
        end
    end

    if (scite.SendEditor(SCI_GETSTYLEAT, position) == 4 or scite.SendEditor(SCI_GETSTYLEAT, position) == 15) then
        local funcdef = self:GetFuncDef(word, props["api.$(au3)"], ";")
        if funcdef ~= nil then
            scite.SendEditor(SCI_CALLTIPSHOW, position, funcdef)
        end
    end

    return true
end

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

What's weird is that OnOpen is called when SciTE is opened and when I switch between buffers. So, I removed OnSwitchFile and restarted SciTE but calltips are still not displayed when I hover over a function even after switching buffers.

Edited by LaCastiglione
Link to comment
Share on other sites

  • jaberwacky changed the title to MouseHoverCallTips [11/24/2023]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...