Still getting the error. Can someone take a look? Thanks!
–SonicX278
Still getting the error. Can someone take a look? Thanks!
–SonicX278
Okay i got the whole thing working. I added this in.
view.\_onEvent( event, M.\_options.defaultFile )
Now how do i print the defualtFile when i press a button?
–SonicX278
Never mind. I got it. Thanks for the help!
–SonicX278
Hi Sonic.
Sorry, I was out today. Glad that you make it work.
It just came out to me a simpler solution. Instead of modifier the widget button source, you could just wrap it in a function like:
local function myNewButton(options) local onEvent = function(e) options.onEvent(e, options.defaultFile) end options.onEvent = onEvent return require("widget").newButton(options) end
and you use that function instead of the widget.newButton.
Well I think I can just stick with the modified code. Can you check out my other question by any chance?
–SonicX278
Ok. Saw it. So, if you just use my simpler solution will solve that issue as well.
To fix the problem that you reported, you would need change some more code. Go with the simpler solution, it is better.
Oh ok. I’ll be home soon so I can try then.
–SonicX278
Where would i add this function? And how would i use it?
–SonicX278
you add that function on the same file that you need to use it.
If you will use the function in several different files, you can add it as a external module.
But to make things easier to you, just write this down in your main.lua:
local widget = require "widget" local newButton = widget.newButton widget.newButton = function(options) local onEvent = options.onEvent local onEventWrap = function(e) if onEvent then onEvent(e, options.defaultFile) end end options.onEvent = onEventWrap return newButton(options) end
now you can just use the widget.newButton as you were using before and your onEvent listener will receive a 2nd parameter that will be the defaultFile being used.
This gives me a error on
options.onEvent(e, options.defaultFile)
Just says
18:43:46.363 C:\Users\USER\Desktop\AppRebuilt - Copy\module\shortCuts.lua:10: in function '\_onEvent'
–SonicX278
Sorry. I fixed the error. I updated the code above.
I’m not home to test it right now. When are you up until?
–SonicX278
Well thanks a ton! Works like a charm! Now my lines of code in each file went from 700 to just over 100! Awesome!
–SonicX278