diff --git a/lime/_backend/native/NativeCFFI.hx b/lime/_backend/native/NativeCFFI.hx index 696019f43..9c18a2ab4 100644 --- a/lime/_backend/native/NativeCFFI.hx +++ b/lime/_backend/native/NativeCFFI.hx @@ -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; diff --git a/lime/system/DirectoryWatcher.hx b/lime/system/FileWatcher.hx similarity index 65% rename from lime/system/DirectoryWatcher.hx rename to lime/system/FileWatcher.hx index df5be0161..4263f876b 100644 --- a/lime/system/DirectoryWatcher.hx +++ b/lime/system/FileWatcher.hx @@ -13,13 +13,12 @@ import lime.app.Event; @:access(lime._backend.native.NativeCFFI) -class DirectoryWatcher { +class FileWatcher { - public var onChange = new EventVoid> (); - public var onFileAdd = new EventVoid> (); - public var onFileModify = new EventVoid> (); - public var onFileRemove = new EventVoid> (); + public var onAdd = new EventVoid> (); + public var onModify = new EventVoid> (); + public var onRemove = new EventVoid> (); 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 } diff --git a/project/Build.xml b/project/Build.xml index 63a9d723b..a64dda0f9 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -219,7 +219,7 @@ - + diff --git a/project/include/system/DirectoryWatcher.h b/project/include/system/DirectoryWatcher.h deleted file mode 100644 index 7cedb01d0..000000000 --- a/project/include/system/DirectoryWatcher.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef LIME_SYSTEM_DIRECTORY_WATCHER_H -#define LIME_SYSTEM_DIRECTORY_WATCHER_H - -#include -#include -#include - - -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 watchListeners; - - - }; - - -} - - -#endif \ No newline at end of file diff --git a/project/include/system/FileWatcher.h b/project/include/system/FileWatcher.h new file mode 100644 index 000000000..554eff11e --- /dev/null +++ b/project/include/system/FileWatcher.h @@ -0,0 +1,42 @@ +#ifndef LIME_SYSTEM_FILE_WATCHER_H +#define LIME_SYSTEM_FILE_WATCHER_H + +#ifdef RemoveDirectory +#undef RemoveDirectory +#endif + +#include +#include +#include + + +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 watchListeners; + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 8118695e5..8fcd25698 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -23,8 +23,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -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); diff --git a/project/src/system/DirectoryWatcher.cpp b/project/src/system/FileWatcher.cpp similarity index 76% rename from project/src/system/DirectoryWatcher.cpp rename to project/src/system/FileWatcher.cpp index 4a6b897f6..8d8b46fd1 100644 --- a/project/src/system/DirectoryWatcher.cpp +++ b/project/src/system/FileWatcher.cpp @@ -1,4 +1,4 @@ -#include +#include #include @@ -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 ();