Skip to content
Browse files

Fixed a typo in CTButton (addResponder). Added a permanent default in…

…put responder for CTDropDown, and fixed setOptions to a correct behavior.
  • Loading branch information...
1 parent 9a7fcdc commit 995fad60a5bb1ecf040ec922d813fa76700da3f8 @danielohrlund committed Nov 12, 2011
Showing with 54 additions and 22 deletions.
  1. +1 −1 CTButton.t
  2. +10 −0 CTDropDown.extern.c
  3. +1 −0 CTDropDown.extern.h
  4. +35 −19 CTDropDown.t
  5. +7 −2 TestDropDown.t
View
2 CTButton.t
@@ -44,7 +44,7 @@ mkCocoaButton w = class
if not derAdded then
addResponderImpl der
derAdded := True
- addResponderImpl der
+ addResponderImpl r
setResponders rs = request
setRespondersImpl (der:rs)
View
10 CTDropDown.extern.c
@@ -33,6 +33,16 @@ TUP0 dropDownAddOption_CTDropDown(Int cocoaRef, LIST str, Int dummy) {
});
}
+TUP0 dropDownRemoveOptions_CTDropDown(Int cocoaRef, Int dummy) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSPopUpButton *thisDropDown = (NSPopUpButton*) cocoaRef;
+ [thisDropDown removeAllItems];
+ [pool drain];
+ });
+
+}
+
LIST dropDownGetSelectedOption_CTDropDown(Int cocoaRef, Int dummy) {
__block LIST s;
dispatch_sync(dispatch_get_main_queue(), ^{
View
1 CTDropDown.extern.h
@@ -7,6 +7,7 @@
Int initDropDown_CTDropDown(World,Int);
TUP0 dropDownAddOption_CTDropDown(Int,LIST,Int);
+TUP0 dropDownRemoveOptions_CTDropDown(Int,Int);
TUP0 dropDownSetPosition_CTDropDown(Int,Position_CocoaDef,Int);
Size_CocoaDef dropDownSetSize_CTDropDown(Int,Size_CocoaDef,Int);
LIST dropDownGetSelectedOption_CTDropDown(Int,Int);
View
54 CTDropDown.t
@@ -18,24 +18,36 @@ mkCocoaDropDown w = class
size := {width=108; height=17}
title := "DropDown"
- BaseComponent {setPosition=setPositionImpl;setSize=dummy1;getSize=dummy2;..} =
+ der = new defaultDropdownInputResponder refreshMyOptionAndPerformCallback
+ derAdded := False
+
+ BaseComponent {setPosition=setPositionImpl;setSize=dummy1;getSize=dummy2;setResponders=setRespondersImpl;
+ addResponder=addResponderImpl;..} =
new basicComponent True Nothing "DropDown"
setPosition p = request
if isActive state then
Active ref = state
dropDownSetPosition ref p
setPositionImpl p
-
+
+ getSize = request
+ result size
setSize s = request
if isActive state then
Active ref = state
size := (<- dropDownSetSize ref s)
else
size := s
-
- getSize = request
- result size
+
+ addResponder r = request
+ if not derAdded then
+ addResponderImpl der
+ derAdded := True
+ addResponderImpl r
+
+ setResponders rs = request
+ setRespondersImpl (der:rs)
dsh := new defaultSelectionResponder
selectionChanged str = action
@@ -47,8 +59,11 @@ mkCocoaDropDown w = class
addOption o = request
insertOption o
setOptions opts = action
- options := []
- forall o <- (reverse opts) do
+ options := []
+ if isActive state then
+ Active ref = state
+ dropDownRemoveOptions ref
+ forall o <- opts do
insertOption o
insertOption o = do
options := o : options
@@ -75,29 +90,29 @@ mkCocoaDropDown w = class
result state
initComp app = request
- ref <- initDropDown w
- state := Active ref
- forall o <- options do
- dropDownAddOption ref o
- dropDownSetPosition ref (<- getPosition)
- size := (<- dropDownSetSize ref size)
- currentOption := (<- dropDownGetSelectedOption ref)
- sh = new defaultHandler refreshMyOptionAndPerformCallback
- addResponder sh
- result ref
+ ref <- initDropDown w
+ state := Active ref
+ forall o <- (reverse options) do
+ dropDownAddOption ref o
+ dropDownSetPosition ref (<- getPosition)
+ size := (<- dropDownSetSize ref size)
+ currentOption := (<- dropDownGetSelectedOption ref)
+ if not derAdded then
+ addResponderImpl der
+ derAdded := True
+ result ref
this = DropDown{id=self;..}
result this
defaultSelectionResponder = class
selectionChanged str = action
- setSelectionResponder _ = request
result RespondsToSelectionEvents {..}
data SizeState = Small | Expanded
-defaultHandler dropdownUpdateMethod = class
+defaultDropdownInputResponder dropdownUpdateMethod = class
sizeState := Small
respondToInputEvent (KeyEvent t) modifiers = request
result NotConsumed
@@ -123,6 +138,7 @@ private
extern initDropDown :: World -> Request CocoaRef
extern dropDownAddOption :: CocoaRef -> String -> Request ()
+extern dropDownRemoveOptions :: CocoaRef -> Request ()
extern dropDownSetPosition :: CocoaRef -> Position -> Request ()
extern dropDownSetSize :: CocoaRef -> Size -> Request Size
extern dropDownGetSelectedOption :: CocoaRef -> Request String
View
9 TestDropDown.t
@@ -6,6 +6,7 @@ import CTDropDown
root :: RootType
root w = class
+ env = new posix w
osx = new cocoa w
w1 = new mkCocoaWindow w
dropD = new mkCocoaDropDown w
@@ -18,14 +19,18 @@ root w = class
dropD.setOptions ["first", "second", "third"]
dropD.setPosition ({x=100;y=100})
- dropD.setSelectionResponder (new defaultSelectionResponder)
+ dropD.setSelectionResponder (new defaultSelectionResponder env.stdout.write)
w1.addComponent dropD
app.addWindow w1
+
+ after (sec 5) send action
+ dropD.setOptions ["some", "new", "options"]
result action
osx.startApplication start
-defaultSelectionResponder = class
+defaultSelectionResponder writer = class
selectionChanged str = action
+ writer $ str ++ " selected\n"
result RespondsToSelectionEvents {..}

0 comments on commit 995fad6

Please sign in to comment.
Something went wrong with that request. Please try again.