I have following simple code:
Red []
view [
text "Value of x:" f1: field "" return
text "Value of y:" f2: field "" return
text "Read Sum:" tt: text "" return
button "Calculate" [
tt/text: to-string ((to-integer f1/text) + (to-integer f2/text)) ]
button "Quit" [quit] ]
How can I add code so that one can move between different fields using TAB key? Apparently, this works in Rebol ( http://www.rebol.com/how-to/fields.html ) but is not working here.
according gitter archive
handle-key: function [e prev-fld next-fld][
k: e/key
if k = tab [
either e/shift? [win/selected: prev-fld][win/selected: next-fld]
]
]
view [
text "Value of x:" f1: field "" on-key [handle-key event tt f2] return
text "Value of y:" f2: field "" on-key [handle-key event f1 tt] return
text "Read Sum:" tt: text "" on-key [handle-key event f2 f1] return
button "Calculate" [
tt/text: to-string ((to-integer f1/text) + (to-integer f2/text))
]
button "Quit" [quit]
do [win: self win/selected: f1]
]
Related
I'm trying to trigger autocomplete to show itself after certain words are entered and finalized with a space which does work but only after double tapping space. It does momentarily show the autocomplete when you press space once but then disappears. Only after tapping space again does it show autocomplete and stays. Putting in print() statements to check if it's triggering on the first space does show it works fine but why it closes straight away, I don't know.
Current code:
class ScriptListener(sublime_plugin.EventListener):
commands = [
'&Command1',
'&Command2'
]
Command1_completions = [
'param1=',
'param2='
]
Command2_completions = [
'param1=',
'param2='
]
last_word = ""
current_row = ""
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "source.script"):
return None
if self.last_word == self.commands[0] or self.commands[0] in self.current_row:
return self._remove_known_arguments(self.Command1_completions)
elif self.last_word == self.commands[1] or self.commands[1] in self.current_row:
return self._remove_known_arguments(self.Command2_completions)
else:
return None
def on_modified(self, view):
for region in view.sel():
if (' ' in view.substr(view.word(region))):
self.current_row = view.substr(view.line(view.sel()[0]))
if any(command in self.current_row for command in self.commands):
view.run_command("auto_complete")
else:
self.last_word = view.substr(view.word(region))
def on_selection_modified(self, view):
#Get current row
self.current_row = view.substr(view.line(view.sel()[0]))
def _remove_known_arguments(self, comp_list):
for arg in comp_list:
if (arg in self.current_row):
comp_list.remove(arg)
return comp_list
What I want to do is if I press the button on my mouse it uses a key like "E" and if I press the button again it uses the key "W" and after 2 seconds it resets, I mean if I don’t press the same button after 2 seconds it uses letter "e " again. Is that possible?
I've tried some codes but no results yet:
function OnEvent(event, arg, family)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
toggle = not toggle
if toggle then
PressKey("e")
ReleaseKey("e")
else
PressKey("w")
ReleaseKey("w")
end
end
end
local prev_tm_btn5 = -math.huge
function OnEvent(event, arg, family)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
local tm = GetRunningTime()
local key = tm - prev_tm_btn5 > 2000 and "e" or "w"
prev_tm_btn5 = tm
PressKey(key)
Sleep(15)
ReleaseKey(key)
end
end
I would like to dynamically add a button to the layout of a view, with the actor causing this addition belonging to a button that is already part of the layout.
I started with this:
REBOL [title: "Dynamic Button Addition"]
tilesize: 60x60
curtile: 1
stylize [
p: button [
facets: [init-size: tilesize max-size: tilesize]
actors: [
on-action: [
++ curtile
append tiles compose [ p (to-string curtile) ]
print ? tiles/options/content
v/redraw
]
]
]
]
v: [
tiles: hgroup [ p "1" ]
]
view v
...which does not appear to have the value of tiles/options/content change with each click.
I can get it to change if make these changes:
append tiledata compose [ p (to-string curtile) ]
and
tiledata: [ p "1" ]
v: [
tiles: hgroup tiledata
However, this does not cause any change on screen. If I replace the last four lines with this:
v: view [
tiles: hgroup tiledata
]
...so that v is now the view rather than the view's layout, I get this error when I click:
** Script error: v has no value
** Where: actor all foreach do-actor unless do-face if actor all foreach do-actor if do-event do-event if do-event either -apply- wake-up loop -apply- wait forever try do-events if view do either either either -apply-
** Near: actor face :data
This makes sense to me, because v is not yet done being defined, until I exit the program, IIUC.
How, then, can I make changes to v before the program ends, but after it's been passed to view?
Not very nice, but working if you replace
v/redraw
with these two lines
unview/all
view v
And there is a real dynamic example on how to update a layout that has already be viewed
I will simplify it
stylize [
tbox: hpanel [
actors: [
on-make: [
append face/options [
content: [
]
]
do-actor/style face 'on-make none 'hpanel
]
]
]
]
view/across [
button "button 1"
on-action [
append-content test compose [
button ( join "button " 2 + length? test/gob)
]
]
test: tbox
]
I'm trying to improve the Sliding Tile Puzzle example by making the starting positions random.
There's a better way to do this--"It is considered bad practice to convert values to strings and join them together to pass to do for evaluation."--but the approach I took was to try to generate Rebol3 source, and then evaluate it. I have it generating correctly, I think:
random/seed now
arr: random collect [ repeat tilenum 9 [ keep tilenum ] ]
hgroup-data: copy {}
repeat pos 9 [
curtile: (pick arr pos)
append hgroup-data either curtile = 9
[ reduce "x: box tilesize gameback " ]
[ rejoin [ { p "} curtile {" } ] ]
if all [(pos // 3) = 0 pos != 9] [ append hgroup-data " return^/" ]
]
print hgroup-data
...outputs something like:
p "4" x: box tilesize gameback p "5" return
p "3" p "7" p "1" return
p "2" p "8" p "6"
...which if I then copy and paste into this part, works correctly:
view/options [
hgroup [
PASTE-HERE
]
] [bg-color: gameback]
However, if I try to do it dynamically:
view/options [
hgroup [
hgroup-data
]
] [bg-color: gameback]
...(also print hgroup-data, do hgroup-data, and load hgroup-data), I get this error:
** GUI ERROR: Cannot parse the GUI dialect at: hgroup-data
...(or at: print hgroup-data, etc., depending on which variation I tried.)
If I try load [ hgroup-data ] I get:
** Script error: extend-face does not allow none! for its face argument
** Where: either if forever -apply- apply init-layout make-layout actor all foreach do-actor unless -apply- apply all build-face -apply- apply init-layout make-layout actor all foreach do-actor if build-face -apply- apply init-layout make-layout actor all foreach do-actor unless make-face -apply- apply case view do either either either -apply-
** Near: either all [
word? act: dial/1
block? body: get dial...
However, if I use the syntax hgroup do [ hgroup-data ], the program runs, but there are no buttons: it appears to be somehow over-evaluated, so that the return values of the functions p and box and so on are put straight into the hgroup as code.
Surely I'm missing an easy syntax error here. What is it?
First, I would say it's better to construct a block directly, instead of constructing a string and converting it to a block. But if you really want to do that, this should do the trick:
view/options compose/only [
hgroup (load hgroup-data)
] [bg-color: gameback]
How do the backspace and delete keys work in CKEditor? If I have an iframe in the editable area, and have my cursor next to it, hitting backspace/delete deletes the iframe/removes its HTML code from there.
What I was unable to get was where is the code for this behavior? Where on hitting backspace the range is shrunken to the iframe and it was removed.
Please point me in the right direction of where this happens in the source code.
There is something about delete
oKeystrokeHandler.SetKeystrokes
But i don't about that behavior
var FCKEnterKey = function( targetWindow, enterMode, shiftEnterMode, tabSpaces )
{
this.Window = targetWindow ;
this.EnterMode = enterMode || 'p' ;
this.ShiftEnterMode = shiftEnterMode || 'br' ;
// Setup the Keystroke Handler.
var oKeystrokeHandler = new FCKKeystrokeHandler( false ) ;
oKeystrokeHandler._EnterKey = this ;
oKeystrokeHandler.OnKeystroke = FCKEnterKey_OnKeystroke ;
oKeystrokeHandler.SetKeystrokes( [
[ 13 , 'Enter' ],
[ SHIFT + 13, 'ShiftEnter' ],
[ 8 , 'Backspace' ],
[ CTRL + 8 , 'CtrlBackspace' ],
[ 46 , 'Delete' ]
] ) ;
this.TabText = '' ;
// Safari by default inserts 4 spaces on TAB, while others make the editor
// loose focus. So, we need to handle it here to not include those spaces.
if ( tabSpaces > 0 || FCKBrowserInfo.IsSafari )
{
while ( tabSpaces-- )
this.TabText += '\xa0' ;
oKeystrokeHandler.SetKeystrokes( [ 9, 'Tab' ] );
}
oKeystrokeHandler.AttachToElement( targetWindow.document ) ;
}
http://code.google.com/p/easyfckeditor/source/browse/trunk/src/main/java/oh/how/easy/fck/js/fckeditor/editor/_source/classes/fckenterkey.js?r=2