]> gitweb.factorcode.org Git - factor.git/commitdiff
Got 'Save Image' and 'Save Image As' menu items working again
authorslava <slava@factorcode.org>
Sat, 14 Oct 2006 03:06:33 +0000 (03:06 +0000)
committerslava <slava@factorcode.org>
Sat, 14 Oct 2006 03:06:33 +0000 (03:06 +0000)
library/ui/cocoa/dialogs.factor
library/ui/cocoa/ui.factor

index 5ebc39a7e58d2719c858e589ade1c7eefbf53533..e14212df93f46074bc3cc3bacc0368e69026f7b0 100644 (file)
@@ -10,9 +10,26 @@ USING: kernel objc objc-classes sequences ;
     dup 1 -> setResolvesAliases:
     dup 1 -> setAllowsMultipleSelection: ;
 
+: <NSSavePanel> ( -- panel )
+    NSSavePanel -> savePanel
+    dup 1 -> setCanChooseFiles:
+    dup 0 -> setCanChooseDirectories:
+    dup 0 -> setAllowsMultipleSelection: ;
+
 : NSOKButton 1 ;
 : NSCancelButton 0 ;
 
+: run-panel ( panel -- paths ) ;
+
 : open-panel ( -- paths )
-    <NSOpenPanel> dup f -> runModalForTypes: NSOKButton =
+    <NSOpenPanel>
+    dup -> runModal NSOKButton =
     [ -> filenames CF>string-array ] [ drop f ] if ;
+
+: split-path ( path -- dir file )
+    <reversed> "/" split1 [ reverse <NSString> ] 2apply swap ;
+
+: save-panel ( path -- paths )
+    <NSSavePanel> dup
+    rot split-path -> runModalForDirectory:file: NSOKButton =
+    [ -> filename CF>string ] [ drop f ] if ;
index 626006a41936e519434931a7460080dc600f1354..43d0d3d3f8295c7879263757d49b62295618516c 100644 (file)
@@ -18,18 +18,29 @@ sequences errors freetype help ;
 : menu-run-files ( -- )
     open-panel [ listener-run-files ] when* ;
 
+: menu-save-image ( -- )
+    image save-panel [ save-image ] when* ;
+
 ! Handle Open events from the Finder
 "NSObject" "FactorApplicationDelegate" {
     { "application:openFiles:" "void" { "id" "SEL" "id" "id" }
         [ >r 3drop r> finder-run-files ]
     }
 
+    { "newFactorWorkspace:" "id" { "id" "SEL" "id" }
+        [ 3drop workspace-window f ]
+    }
+
     { "runFactorFile:" "id" { "id" "SEL" "id" }
         [ 3drop menu-run-files f ]
     }
 
-    { "newFactorWorkspace:" "id" { "id" "SEL" "id" }
-        [ 3drop workspace-window f ]
+    { "saveFactorImage:" "id" { "id" "SEL" "id" }
+        [ 3drop save f ]
+    }
+
+    { "saveFactorImageAs:" "id" { "id" "SEL" "id" }
+        [ 3drop menu-save-image f ]
     }
 
     { "showFactorHelp:" "id" { "id" "SEL" "id" }