]> gitweb.factorcode.org Git - factor.git/commitdiff
ui: add a "system-alert" hook that can raise a system modal dialog without involving...
authorJoe Groff <arcata@gmail.com>
Wed, 24 Feb 2010 03:28:57 +0000 (19:28 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 24 Feb 2010 03:28:57 +0000 (19:28 -0800)
basis/cocoa/cocoa.factor
basis/ui/backend/cocoa/cocoa.factor
basis/ui/backend/windows/windows.factor
basis/ui/backend/x11/x11.factor
basis/ui/ui.factor

index 34bac0a5055229e13b7a738190f577359fd3ab7e..fb21843c0f6f4e396dd6723e19073dc7779eb8dd 100644 (file)
@@ -39,6 +39,7 @@ SYNTAX: IMPORT: scan [ ] import-objc-class ;
 
 [
     {
+        "NSAlert"
         "NSApplication"
         "NSArray"
         "NSAutoreleasePool"
index 8eeca89c2f14903c396d40e4abbd673eee0e17ad..6e64c35e49e5ed73c1496f1989e1258d33e5c15a 100644 (file)
@@ -213,6 +213,16 @@ M: cocoa-ui-backend offscreen-pixels ( world -- alien w h )
 M: cocoa-ui-backend beep ( -- )
     NSBeep ;
 
+M: cocoa-ui-backend system-alert
+    NSAlert -> alloc -> init -> autorelease [
+        {
+            [ swap <NSString> -> setInformativeText: ]
+            [ swap <NSString> -> setMessageText: ]
+            [ "OK" <NSString> -> addButtonWithTitle: drop ]
+            [ -> runModal drop ]
+        } cleave
+    ] [ 2drop ] if* ;
+
 CLASS: {
     { +superclass+ "NSObject" }
     { +name+ "FactorApplicationDelegate" }
index 69b09dcba0911154d8e7d7db57390c517240cf60..5863d3f39d8e1624883b541b78db9792b7b38ec2 100644 (file)
@@ -783,6 +783,9 @@ M: windows-ui-backend (with-ui)
 M: windows-ui-backend beep ( -- )
     0 MessageBeep drop ;
 
+M: windows-ui-backend system-alert
+    [ f ] 2dip swap MB_OK MessageBox drop ;
+
 : fullscreen-RECT ( hwnd -- RECT )
     MONITOR_DEFAULTTONEAREST MonitorFromWindow
     MONITORINFOEX <struct>
index 74d911ef90d365f8f87450cd77745ca2e2d254be..ee6eb813b0a10e36be797277940c9c327b1be4b0 100644 (file)
@@ -8,6 +8,7 @@ strings ui ui.backend ui.clipboards ui.event-loop ui.gadgets
 ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats
 ui.pixel-formats.private ui.private x11 x11.clipboard x11.constants
 x11.events x11.glx x11.io x11.windows x11.xim x11.xlib ;
+FROM: unix.ffi => system ;
 IN: ui.backend.x11
 
 SINGLETON: x11-ui-backend
@@ -326,6 +327,17 @@ M: x11-ui-backend (with-ui) ( quot -- )
 M: x11-ui-backend beep ( -- )
     dpy get 100 XBell drop ;
 
+<PRIVATE
+: escape-' ( string -- string' )
+    [ dup CHAR: ' = [ drop "'\''" ] [ 1string ] if ] { } map-as concat ;
+
+: xmessage ( string -- )
+    escape-' "/usr/X11R6/bin/xmessage '" "'" surround system ;
+PRIVATE>
+
+M: x11-ui-backend system-alert
+    "\n\n" glue xmessage ;
+
 : black ( -- xcolor ) 0 0 0 0 0 0 XColor <struct-boa> ; inline
 
 M:: x11-ui-backend (grab-input) ( handle -- )
index e0fa560935f35b551040fbb2c1cafe3d96a45011..824ffb8351ebffc04589197dbd8d07e515b0860e 100644 (file)
@@ -243,6 +243,8 @@ M: object close-window
 
 HOOK: beep ui-backend ( -- )
 
+HOOK: system-alert ui-backend ( caption text -- )
+
 : parse-main-window-attributes ( class -- attributes )
     "{" expect dup all-slots parse-tuple-literal-slots ;