Rename new API to FileWatcher (resolve #1064)
This commit is contained in:
@@ -49,15 +49,15 @@ class NativeCFFI {
|
||||
@:cffi private static function lime_data_pointer_offset (dataPointer:DataPointer, offset:Int):Float;
|
||||
@:cffi private static function lime_deflate_compress (data:Dynamic, bytes:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_deflate_decompress (data:Dynamic, bytes:Dynamic):Dynamic;
|
||||
@:cffi private static function lime_directory_watcher_create (callback:Dynamic):CFFIPointer;
|
||||
@:cffi private static function lime_directory_watcher_add_watch (handle:CFFIPointer, path:Dynamic, recursive:Bool):Dynamic;
|
||||
@:cffi private static function lime_directory_watcher_remove_watch (handle:CFFIPointer, watchID:Dynamic):Void;
|
||||
@:cffi private static function lime_directory_watcher_update (handle:CFFIPointer):Void;
|
||||
@:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void;
|
||||
@:cffi private static function lime_file_dialog_open_directory (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_file (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_open_files (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_dialog_save_file (title:String, filter:String, defaultPath:String):Dynamic;
|
||||
@:cffi private static function lime_file_watcher_create (callback:Dynamic):CFFIPointer;
|
||||
@:cffi private static function lime_file_watcher_add_directory (handle:CFFIPointer, path:Dynamic, recursive:Bool):Dynamic;
|
||||
@:cffi private static function lime_file_watcher_remove_directory (handle:CFFIPointer, watchID:Dynamic):Void;
|
||||
@:cffi private static function lime_file_watcher_update (handle:CFFIPointer):Void;
|
||||
@:cffi private static function lime_font_get_ascender (handle:Dynamic):Int;
|
||||
@:cffi private static function lime_font_get_descender (handle:Dynamic):Int;
|
||||
@:cffi private static function lime_font_get_family_name (handle:Dynamic):Dynamic;
|
||||
|
||||
@@ -13,13 +13,12 @@ import lime.app.Event;
|
||||
@:access(lime._backend.native.NativeCFFI)
|
||||
|
||||
|
||||
class DirectoryWatcher {
|
||||
class FileWatcher {
|
||||
|
||||
|
||||
public var onChange = new Event<Void->Void> ();
|
||||
public var onFileAdd = new Event<String->Void> ();
|
||||
public var onFileModify = new Event<String->Void> ();
|
||||
public var onFileRemove = new Event<String->Void> ();
|
||||
public var onAdd = new Event<String->Void> ();
|
||||
public var onModify = new Event<String->Void> ();
|
||||
public var onRemove = new Event<String->Void> ();
|
||||
|
||||
private var handle:CFFIPointer;
|
||||
private var hasUpdate:Bool;
|
||||
@@ -29,14 +28,14 @@ class DirectoryWatcher {
|
||||
public function new () {
|
||||
|
||||
#if (lime_cffi && !macro)
|
||||
handle = NativeCFFI.lime_directory_watcher_create (this_onChange);
|
||||
handle = NativeCFFI.lime_file_watcher_create (this_onChange);
|
||||
ids = new Map ();
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function addPath (path:String, recursive:Bool = true):Void {
|
||||
public function addDirectory (path:String, recursive:Bool = true):Void {
|
||||
|
||||
#if (lime_cffi && !macro)
|
||||
if (!hasUpdate) {
|
||||
@@ -46,19 +45,19 @@ class DirectoryWatcher {
|
||||
|
||||
}
|
||||
|
||||
var id:Int = NativeCFFI.lime_directory_watcher_add_watch (handle, path, recursive);
|
||||
var id:Int = NativeCFFI.lime_file_watcher_add_directory (handle, path, recursive);
|
||||
ids[path] = id;
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function removePath (path:String):Void {
|
||||
public function removeDirectory (path:String):Void {
|
||||
|
||||
#if (lime_cffi && !macro)
|
||||
if (ids.exists (path)) {
|
||||
|
||||
NativeCFFI.lime_directory_watcher_remove_watch (handle, ids[path]);
|
||||
NativeCFFI.lime_file_watcher_remove_directory (handle, ids[path]);
|
||||
ids.remove (path);
|
||||
|
||||
if (!ids.keys ().hasNext ()) {
|
||||
@@ -99,18 +98,15 @@ class DirectoryWatcher {
|
||||
|
||||
case 1:
|
||||
|
||||
onFileAdd.dispatch (path);
|
||||
onChange.dispatch ();
|
||||
onAdd.dispatch (path);
|
||||
|
||||
case 2:
|
||||
|
||||
onFileRemove.dispatch (path);
|
||||
onChange.dispatch ();
|
||||
onRemove.dispatch (path);
|
||||
|
||||
case 4:
|
||||
|
||||
onFileModify.dispatch (path);
|
||||
onChange.dispatch ();
|
||||
onModify.dispatch (path);
|
||||
|
||||
}
|
||||
|
||||
@@ -120,7 +116,7 @@ class DirectoryWatcher {
|
||||
private function this_onUpdate (_):Void {
|
||||
|
||||
#if (lime_cffi && !macro)
|
||||
NativeCFFI.lime_directory_watcher_update (handle);
|
||||
NativeCFFI.lime_file_watcher_update (handle);
|
||||
#end
|
||||
|
||||
}
|
||||
@@ -219,7 +219,7 @@
|
||||
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/simplefilewatcher/include/" />
|
||||
<compilerflag value="-DLIME_SIMPLEFILEWATCHER" />
|
||||
|
||||
<file name="src/system/DirectoryWatcher.cpp" />
|
||||
<file name="src/system/FileWatcher.cpp" />
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef LIME_SYSTEM_DIRECTORY_WATCHER_H
|
||||
#define LIME_SYSTEM_DIRECTORY_WATCHER_H
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class DirectoryWatcher {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
DirectoryWatcher (value callback);
|
||||
~DirectoryWatcher ();
|
||||
|
||||
unsigned long AddWatch (const std::string directory, bool recursive);
|
||||
void RemoveWatch (unsigned long watchID);
|
||||
void Update ();
|
||||
|
||||
AutoGCRoot* callback;
|
||||
|
||||
private:
|
||||
|
||||
void* fileWatcher = 0;
|
||||
std::map<unsigned long, void*> watchListeners;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
42
project/include/system/FileWatcher.h
Normal file
42
project/include/system/FileWatcher.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef LIME_SYSTEM_FILE_WATCHER_H
|
||||
#define LIME_SYSTEM_FILE_WATCHER_H
|
||||
|
||||
#ifdef RemoveDirectory
|
||||
#undef RemoveDirectory
|
||||
#endif
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class FileWatcher {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
FileWatcher (value callback);
|
||||
~FileWatcher ();
|
||||
|
||||
unsigned long AddDirectory (const std::string directory, bool recursive);
|
||||
void RemoveDirectory (unsigned long watchID);
|
||||
void Update ();
|
||||
|
||||
AutoGCRoot* callback;
|
||||
|
||||
private:
|
||||
|
||||
void* fileWatcher = 0;
|
||||
std::map<unsigned long, void*> watchListeners;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -23,8 +23,8 @@
|
||||
#include <system/CFFIPointer.h>
|
||||
#include <system/Clipboard.h>
|
||||
#include <system/ClipboardEvent.h>
|
||||
#include <system/DirectoryWatcher.h>
|
||||
#include <system/Endian.h>
|
||||
#include <system/FileWatcher.h>
|
||||
#include <system/JNI.h>
|
||||
#include <system/Locale.h>
|
||||
#include <system/SensorEvent.h>
|
||||
@@ -65,10 +65,10 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void gc_directory_watcher (value handle) {
|
||||
void gc_file_watcher (value handle) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
|
||||
FileWatcher* watcher = (FileWatcher*)val_data (handle);
|
||||
delete watcher;
|
||||
#endif
|
||||
|
||||
@@ -360,50 +360,6 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_directory_watcher_create (value callback) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
DirectoryWatcher* watcher = new DirectoryWatcher (callback);
|
||||
return CFFIPointer (watcher, gc_directory_watcher);
|
||||
#else
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_directory_watcher_add_watch (value handle, value path, bool recursive) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
|
||||
return alloc_int (watcher->AddWatch (val_string (path), recursive));
|
||||
#else
|
||||
return alloc_int (0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_directory_watcher_remove_watch (value handle, value watchID) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
|
||||
watcher->RemoveWatch (val_int (watchID));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_directory_watcher_update (value handle) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
DirectoryWatcher* watcher = (DirectoryWatcher*)val_data (handle);
|
||||
watcher->Update ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_drop_event_manager_register (value callback, value eventObject) {
|
||||
|
||||
DropEvent::callback = new AutoGCRoot (callback);
|
||||
@@ -546,6 +502,51 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_file_watcher_create (value callback) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
FileWatcher* watcher = new FileWatcher (callback);
|
||||
return CFFIPointer (watcher, gc_file_watcher);
|
||||
#else
|
||||
return alloc_null ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_file_watcher_add_directory (value handle, value path, bool recursive) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
FileWatcher* watcher = (FileWatcher*)val_data (handle);
|
||||
return alloc_int (watcher->AddDirectory (val_string (path), recursive));
|
||||
#else
|
||||
return alloc_int (0);
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_file_watcher_remove_directory (value handle, value watchID) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
FileWatcher* watcher = (FileWatcher*)val_data (handle);
|
||||
watcher->RemoveDirectory (val_int (watchID));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_file_watcher_update (value handle) {
|
||||
|
||||
#ifdef LIME_SIMPLEFILEWATCHER
|
||||
FileWatcher* watcher = (FileWatcher*)val_data (handle);
|
||||
watcher->Update ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lime_font_get_ascender (value fontHandle) {
|
||||
|
||||
#ifdef LIME_FREETYPE
|
||||
@@ -1888,15 +1889,15 @@ namespace lime {
|
||||
DEFINE_PRIME2 (lime_data_pointer_offset);
|
||||
DEFINE_PRIME2 (lime_deflate_compress);
|
||||
DEFINE_PRIME2 (lime_deflate_decompress);
|
||||
DEFINE_PRIME1 (lime_directory_watcher_create);
|
||||
DEFINE_PRIME3 (lime_directory_watcher_add_watch);
|
||||
DEFINE_PRIME2v (lime_directory_watcher_remove_watch);
|
||||
DEFINE_PRIME1v (lime_directory_watcher_update);
|
||||
DEFINE_PRIME2v (lime_drop_event_manager_register);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_directory);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_file);
|
||||
DEFINE_PRIME3 (lime_file_dialog_open_files);
|
||||
DEFINE_PRIME3 (lime_file_dialog_save_file);
|
||||
DEFINE_PRIME1 (lime_file_watcher_create);
|
||||
DEFINE_PRIME3 (lime_file_watcher_add_directory);
|
||||
DEFINE_PRIME2v (lime_file_watcher_remove_directory);
|
||||
DEFINE_PRIME1v (lime_file_watcher_update);
|
||||
DEFINE_PRIME1 (lime_font_get_ascender);
|
||||
DEFINE_PRIME1 (lime_font_get_descender);
|
||||
DEFINE_PRIME1 (lime_font_get_family_name);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <system/DirectoryWatcher.h>
|
||||
#include <system/FileWatcher.h>
|
||||
#include <FileWatcher/FileWatcher.h>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace lime {
|
||||
|
||||
public:
|
||||
|
||||
UpdateListener (DirectoryWatcher* _watcher) {
|
||||
UpdateListener (FileWatcher* _watcher) {
|
||||
|
||||
watcher = _watcher;
|
||||
|
||||
@@ -22,13 +22,12 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
DirectoryWatcher* watcher;
|
||||
|
||||
FileWatcher* watcher;
|
||||
|
||||
};
|
||||
|
||||
|
||||
DirectoryWatcher::DirectoryWatcher (value _callback) {
|
||||
FileWatcher::FileWatcher (value _callback) {
|
||||
|
||||
callback = new AutoGCRoot (_callback);
|
||||
fileWatcher = new FW::FileWatcher ();
|
||||
@@ -36,7 +35,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
DirectoryWatcher::~DirectoryWatcher () {
|
||||
FileWatcher::~FileWatcher () {
|
||||
|
||||
delete callback;
|
||||
delete fileWatcher;
|
||||
@@ -52,7 +51,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
unsigned long DirectoryWatcher::AddWatch (std::string directory, bool recursive) {
|
||||
unsigned long FileWatcher::AddDirectory (std::string directory, bool recursive) {
|
||||
|
||||
UpdateListener* listener = new UpdateListener (this);
|
||||
FW::WatchID watchID = ((FW::FileWatcher*)fileWatcher)->addWatch (directory, listener, true);
|
||||
@@ -62,7 +61,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcher::RemoveWatch (unsigned long watchID) {
|
||||
void FileWatcher::RemoveDirectory (unsigned long watchID) {
|
||||
|
||||
((FW::FileWatcher*)fileWatcher)->removeWatch (watchID);
|
||||
|
||||
@@ -76,7 +75,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void DirectoryWatcher::Update () {
|
||||
void FileWatcher::Update () {
|
||||
|
||||
((FW::FileWatcher*)fileWatcher)->update ();
|
||||
|
||||
Reference in New Issue
Block a user