< prev index next >

src/jdk.deploy.osx/macosx/native/libosx/CFileManager.m

Print this page


   1 /*
   2  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 196 (JNIEnv *env, jclass clazz)
 197 {
 198         jstring filename = nil;
 199 JNF_COCOA_ENTER(env);
 200 
 201         NSBundle *mainBundle = [NSBundle mainBundle];
 202         filename = JNFNormalizedJavaStringForPath(env, [mainBundle bundlePath]);
 203 
 204 JNF_COCOA_EXIT(env);
 205         return filename;
 206 }
 207 
 208 
 209 /*
 210  * Class:     com_apple_eio_FileManager
 211  * Method:    __moveToTrash
 212  * Signature: (Ljava/lang/String;)V
 213  */
 214 
 215 JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1moveToTrash
 216 (JNIEnv *env, jclass clz, jstring url)
 217 {
 218         __block jboolean returnValue = JNI_FALSE;
 219 JNF_COCOA_ENTER(env);
 220 
 221     NSString *path = JNFNormalizedNSStringForPath(env, url);

 222     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 223         NSInteger res = 0;
 224         [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
 225                                                      source:[path stringByDeletingLastPathComponent]
 226                                                 destination:nil
 227                                                       files:[NSArray arrayWithObject:[path lastPathComponent]]
 228                                                         tag:&res];
 229         returnValue = (res == 0);
 230     }];
 231 
 232 JNF_COCOA_EXIT(env);
 233 
 234         return returnValue;
 235 }
 236 
 237 /*
 238  * Class:     com_apple_eio_FileManager
 239  * Method:    __revealInFinder
 240  * Signature: (Ljava/lang/String;)V
 241  */
 242 
 243 JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1revealInFinder
 244 (JNIEnv *env, jclass clz, jstring url)
 245 {
 246         __block jboolean returnValue = JNI_FALSE;
 247 JNF_COCOA_ENTER(env);
 248 
 249     NSString *path = JNFNormalizedNSStringForPath(env, url);
 250     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 251         returnValue = [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""];
 252     }];
 253 
 254 JNF_COCOA_EXIT(env);
   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 196 (JNIEnv *env, jclass clazz)
 197 {
 198         jstring filename = nil;
 199 JNF_COCOA_ENTER(env);
 200 
 201         NSBundle *mainBundle = [NSBundle mainBundle];
 202         filename = JNFNormalizedJavaStringForPath(env, [mainBundle bundlePath]);
 203 
 204 JNF_COCOA_EXIT(env);
 205         return filename;
 206 }
 207 
 208 
 209 /*
 210  * Class:     com_apple_eio_FileManager
 211  * Method:    __moveToTrash
 212  * Signature: (Ljava/lang/String;)V
 213  */
 214 
 215 JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1moveToTrash
 216 (JNIEnv *env, jclass clz, jstring fileName)
 217 {
 218     __block BOOL returnValue = NO;
 219 JNF_COCOA_ENTER(env);
 220 
 221     NSString * path = JNFNormalizedNSStringForPath(env, fileName);
 222     NSURL *url = [NSURL fileURLWithPath:path];
 223     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 224 
 225         returnValue  = [[NSFileManager defaultManager] trashItemAtURL:url
 226                                                      resultingItemURL:nil
 227                                                                 error:nil];



 228     }];
 229 
 230 JNF_COCOA_EXIT(env);
 231 
 232         return returnValue ? JNI_TRUE: JNI_FALSE;
 233 }
 234 
 235 /*
 236  * Class:     com_apple_eio_FileManager
 237  * Method:    __revealInFinder
 238  * Signature: (Ljava/lang/String;)V
 239  */
 240 
 241 JNIEXPORT jboolean JNICALL Java_com_apple_eio_FileManager__1revealInFinder
 242 (JNIEnv *env, jclass clz, jstring url)
 243 {
 244         __block jboolean returnValue = JNI_FALSE;
 245 JNF_COCOA_ENTER(env);
 246 
 247     NSString *path = JNFNormalizedNSStringForPath(env, url);
 248     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 249         returnValue = [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""];
 250     }];
 251 
 252 JNF_COCOA_EXIT(env);
< prev index next >