mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Polished the BCL; started FileSystem.ios
This commit is contained in:
@@ -130,6 +130,7 @@ export module tk {
|
||||
public init() {
|
||||
this._eventsToken = initEvents();
|
||||
this.nativeApp.registerActivityLifecycleCallbacks(this._eventsToken);
|
||||
this.context = this.nativeApp.getApplicationContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
FileSystem/file_system.d.ts
vendored
2
FileSystem/file_system.d.ts
vendored
@@ -12,7 +12,7 @@
|
||||
/**
|
||||
* Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary.
|
||||
*/
|
||||
public getParent(onSuccess: (folder: Folder) => any, onError?: (error: any) => any);
|
||||
public getParent(onError?: (error: any) => any): Folder;
|
||||
/**
|
||||
* Deletes the current Entity from the file system.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import file_access_module = require("FileSystem/file_system_access");
|
||||
|
||||
|
||||
// The FileSystemAccess implementation, used through all the APIs.
|
||||
var fileAccess;
|
||||
var getFileAccess = function (): file_access_module.FileSystemAccess {
|
||||
@@ -27,16 +28,13 @@ export class FileSystemEntity {
|
||||
/**
|
||||
* Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary.
|
||||
*/
|
||||
public getParent(onSuccess: (parent: Folder) => any, onError?: (error: any) => any) {
|
||||
var localSuccess = function (path: string) {
|
||||
public getParent(onError?: (error: any) => any): Folder {
|
||||
var path = getFileAccess().getParent(this.path, onError);
|
||||
|
||||
var folder = new Folder();
|
||||
folder[pathProperty] = path;
|
||||
|
||||
if (onSuccess) {
|
||||
onSuccess(folder);
|
||||
}
|
||||
}
|
||||
getFileAccess().getParent(this.path, localSuccess, onError);
|
||||
return folder;
|
||||
}
|
||||
/**
|
||||
* Deletes the current entity from the file system.
|
||||
@@ -191,6 +189,15 @@ export class Folder extends FileSystemEntity {
|
||||
return fileAccess.fileExists(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this Folder contains a Folder with the specified name.
|
||||
*/
|
||||
public containsFolder(name: string): boolean {
|
||||
var fileAccess = getFileAccess();
|
||||
var path = fileAccess.concatPath(this.path, name);
|
||||
return fileAccess.folderExists(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the current Folder (recursively) from the file system.
|
||||
*/
|
||||
@@ -285,7 +292,7 @@ export class KnownFolders {
|
||||
/**
|
||||
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static Documents(): Folder {
|
||||
public static documents(): Folder {
|
||||
if (!KnownFolders._documents) {
|
||||
var path = getFileAccess().getDocumentsFolderPath();
|
||||
KnownFolders._documents = new Folder();
|
||||
@@ -299,7 +306,7 @@ export class KnownFolders {
|
||||
/**
|
||||
* Gets the Temporary (Caches) folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
|
||||
*/
|
||||
public static Temporary(): Folder {
|
||||
public static temporary(): Folder {
|
||||
if (!KnownFolders._temp) {
|
||||
var path = getFileAccess().getTempFolderPath();
|
||||
KnownFolders._temp = new Folder();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import app_module = require("Application/application");
|
||||
|
||||
|
||||
export class FileSystemAccess {
|
||||
private _encoding = "UTF-8";
|
||||
private _pathSeparator = "/";
|
||||
@@ -14,18 +15,18 @@ export class FileSystemAccess {
|
||||
return new Date(javaFile.lastModified());
|
||||
}
|
||||
|
||||
public getParent(path: string, onSuccess: (path: string) => any, onError?: (error: any) => any) {
|
||||
public getParent(path: string, onError?: (error: any) => any): string {
|
||||
try {
|
||||
var javaFile = new java.io.File(path);
|
||||
if (onSuccess) {
|
||||
var parent = javaFile.getParentFile();
|
||||
onSuccess(parent.getPath());
|
||||
}
|
||||
return parent.getPath();
|
||||
} catch (exception) {
|
||||
// TODO: unified approach for error messages
|
||||
if (onError) {
|
||||
onError(exception);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
4
FileSystem/file_system_access.d.ts
vendored
4
FileSystem/file_system_access.d.ts
vendored
@@ -1,10 +1,11 @@
|
||||
// TODO: Implement "hidden" notation so that such declarations are not included in the d.ts file we will provide for the users.
|
||||
//@hidden
|
||||
|
||||
export declare class FileSystemAccess {
|
||||
getReadonly(path: string): boolean;
|
||||
getLastModified(path: string): Date;
|
||||
|
||||
getParent(path: string, onSuccess: (path: string) => any, onError?: (error: any) => any);
|
||||
getParent(path: string, onError?: (error: any) => any): string;
|
||||
getFile(path: string, onSuccess: (path: string) => any, onError?: (error: any) => any);
|
||||
getFolder(path: string, onSuccess: (path: string) => any, onError?: (error: any) => any);
|
||||
enumFiles(path: string, onSuccess: (files: Array<string>) => any, onError?: (error: any) => any);
|
||||
@@ -20,3 +21,4 @@ export declare class FileSystemAccess {
|
||||
readText(path: string, onSuccess: (content: string) => any, onError?: (error: any) => any);
|
||||
writeText(path: string, content: string, onSuccess?: () => any, onError?: (error: any) => any);
|
||||
}
|
||||
|
||||
10
declarations.ios.d.ts
vendored
10
declarations.ios.d.ts
vendored
@@ -60,8 +60,9 @@ declare module Foundation {
|
||||
}
|
||||
|
||||
export class NSString {
|
||||
static initWithString(s: string): NSString;
|
||||
static initWithDataEncoding(data: any, encoding: any): any;
|
||||
static initWithString(source: string): any;
|
||||
stringByDeletingLastPathComponent(): string;
|
||||
}
|
||||
|
||||
export class NSURLSessionConfiguration {
|
||||
@@ -78,6 +79,13 @@ declare module Foundation {
|
||||
|
||||
export class NSURL {
|
||||
static URLWithString(url: string): any;
|
||||
path(): string;
|
||||
relativePath(): string;
|
||||
relativeString(): string;
|
||||
}
|
||||
|
||||
export class NSDate {
|
||||
timeIntervalSince1970(): number;
|
||||
}
|
||||
|
||||
export class NSMutableURLRequest {
|
||||
|
||||
Reference in New Issue
Block a user