Jump to content

Recommended Posts

Posted

Here's my latest version. No major changes, just a bit of cleanup in a couple spots.

MouseHoverCallTips = EventClass:new(Common)

-- If you are experiencing problems with this script then set the following
-- variable to true to enable diagnostic messages.
MouseHoverCallTips.Debug = false

--------------------------------------------------------------------------------
-- OnSwitchFile
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:OnSwitchFile(path)
    self:initialize_mouse_dwell()
    return false
end

--------------------------------------------------------------------------------
-- initialize_mouse_dwell
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:initialize_mouse_dwell()
    --if (self:IsAu3File(path)) then
        local mousehover_calltips_dwelltime = tonumber(props["mousehover.calltips.dwelltime"])
        if (mousehover_calltips_dwelltime == nil) then mousehover_calltips_dwelltime = 700 end -- default
        scite.SendEditor(SCI_SETMOUSEDWELLTIME, mousehover_calltips_dwelltime)
    --end

    return true
end

--------------------------------------------------------------------------------
-- IsAu3File
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:IsAu3File(path)
    if (string.lower(string.sub(path, -4)) == string.lower(string.sub(props["au3"], -4))) then
        return true
    end

    return false
end

--------------------------------------------------------------------------------
-- find_instance
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:find_instance(source, pattern)
    local function find_first_instance(source, pattern, acc)
        if (source == '') then return 0 end

        if (pattern == '') then return 0 end

        if (acc == string.len(source)) then return 0 end

        if (string.sub(source, acc, acc) == pattern) then
            return acc
        else
            acc = acc + 1
            return find_first_instance(source, pattern, acc)
        end
    end

    return find_first_instance(source, pattern, 1)
end

--------------------------------------------------------------------------------
-- get_func_def
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:get_func_def(line, word, style)
    local var = string.gsub(line, " (", '(', 1)

    local position = self:find_instance(var, '(')

    if (position ~= 0) then
        local func_name = string.sub(var, 1, position - 1)

        if (style == 14) then func_name = string.gsub(func_name, "_AutoItObject_", '') end

        func_name = string.lower(func_name)

        word = string.lower(word)

        if (func_name == word) then return string.gsub(line, "%)(.)", "%)n%1") end -- changed: was adding a trailing empty line in some cases.
    end

    return nil
end

--------------------------------------------------------------------------------
-- get_function_calltip
--
--------------------------------------------------------------------------------
function MouseHoverCallTips:get_function_calltip(directory, style, word)
    local function_calltip = nil

    local file = io.open(directory, 'r')
    if file ~= nil then
        for line in file:lines() do
            -- filter out constants
            if (style == 4) then
                local string_end = string.sub(line, -2)

                for i = 1, 4 do
                    if (string_end == '?' .. i) then break end
                end
            end

            function_calltip = self:get_func_def(line, word, style)

            if (function_calltip ~= nil) then break end
        end

        file:close()
    end

    return function_calltip
end

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

    local style = scite.SendEditor(SCI_GETSTYLEAT, position)

    if (style == 4 or style == 14 or style == 15) then
        local directories = props["api.$(au3)"]

        if (directories ~= nil) then
            self:DebugPrint("API files: " .. directories)
            for directory in directories:gmatch("([^;rn]+)") do
                self:DebugPrint("Searching API file: " .. directory)
                local function_calltip = self:get_function_calltip(directory, style, word)
                if (function_calltip ~= nil) then
                    self:DebugPrint("Found calltip in API file: " .. directory)
                    scite.SendEditor(SCI_CALLTIPSHOW, position, function_calltip)
                    break
                end
            end
        else
            self:DebugPrint("The api.$(au3) is missing or empty.")
        end
    else
        self:DebugPrint("Unsupported style detected.")
    end
    return true
end
  • 3 months later...
Posted (edited)

As long as the au3 lexer can keep them separated and assign to them two different styles.

Mmm, so it will be possible to use the same variable name and the same function name and not get them all confused?

Edited by LaCastiglione
Posted (edited)

Good job, a really really really god job.

I know it's not your duty to do what others say, but I have a feature request that may be even impossible, but worth hearing!

For me, I usually keep my functions in a separated file, Functions.au3 for example and include it in the main file of the project, Main.au3 for example.

Would be nice if hovering the mouse cursor on the functions call in the Main.au3, shows its call tips (Functions that has been declared in Functions.au3).

Hope you understand me ^_^

Edited by D4RKON3
Posted (edited)

Good job, a really really really god job.

I know it's not your duty to do what others say, but I have a feature request that may be even impossible, but worth hearing!

For me, I usually keep my functions in a separated file, Functions.au3 for example and include it in the main file of the project, Main.au3 for example.

Would be nice if hovering the mouse cursor on the functions call in the Main.au3, shows its call tips (Functions that has been declared in Functions.au3).

Hope you understand me ^_^

As long as you dont' mind waiting four to six months before I decide to get around to it. =P Kidding. I'm already thinking of a simple method.

@LaCastiglione I like your idea BTW.

Well, thank ye kindly. (It wasn't my idea)

Edited by LaCastiglione
Posted (edited)

I personal would ditch the " -- changed: was adding a trailing empty line in some cases." comment. As the related context is long gone (the org code that was changes). Or/and: It was only intended as temporary additional modification background/reason.

---

czardas:

... Twilight zone ... (can be anything, including real stuff)

;)

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 ...
 

Posted (edited)

czardas:

... Twilight zone ... (can be anything, including real stuff)

;)

I thought the distinction was important in this case, with there being a fine line between something really good and something really crude, otherwise I would have kept it zipped. Anyway, enough digression from me.

I love the original series.

Edited by czardas
  • 2 weeks later...

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
×
×
  • Create New...