diff --git a/include/utility/image.h b/include/utility/image.h index e6925b3..adb75d5 100644 --- a/include/utility/image.h +++ b/include/utility/image.h @@ -365,7 +365,7 @@ struct skiv_image_directory_s { struct fl_s { fd_s* getActiveFile (void) { - return (_ptr != nullptr) ? _ptr : nullptr; + return _it._Ptr; } std::vector getList (void) @@ -376,15 +376,20 @@ struct skiv_image_directory_s { void setList (std::vector list) { _list = std::move(list); - _it = _list.begin(); - _ptr = _it._Ptr; + + if (_list.empty()) + _list.push_back({ L"", L"", WIN32_FIND_DATA { } }); + + _it = _list.begin(); } void clear (void) { _list.clear(); - _it = _list.begin(); - _ptr = nullptr; + + _list.push_back({ L"", L"", WIN32_FIND_DATA { } }); + + _it = _list.begin(); } bool empty (void) @@ -403,7 +408,6 @@ struct skiv_image_directory_s { private: std::vector _list; std::vector::iterator _it; - fd_s* _ptr; } fileList; //std::wstring orig_path; // Holds a cached copy of cover.path diff --git a/src/tabs/viewer.cpp b/src/tabs/viewer.cpp index 1db02e2..cad010e 100644 --- a/src/tabs/viewer.cpp +++ b/src/tabs/viewer.cpp @@ -2965,11 +2965,11 @@ SKIF_UI_Tab_DrawViewer (void) } // Identify when the folder was changed outside of the app - //PLOG_VERBOSE << "_current_folder.watch was signaled! Delay checking the folder for another 5000 ms..."; + //PLOG_VERBOSE << "_current_folder.watch was signaled! Delay checking the folder for another 500 ms..."; if (_current_folder.watch.isSignaled (_current_folder.folder_path)) dwLastSignaled = SKIF_Util_timeGetTime(); - if (dwLastSignaled != 0 && dwLastSignaled + 5000 < SKIF_Util_timeGetTime()) + if (dwLastSignaled != 0 && dwLastSignaled + 500 < SKIF_Util_timeGetTime()) { if (! _current_folder.fileList.fileDeleted) _current_folder.workerThread (true); @@ -2988,7 +2988,7 @@ SKIF_UI_Tab_DrawViewer (void) PLOG_VERBOSE << "_current_folder.fileList.getActiveFile(): " << _current_folder.fileList.getActiveFile()->path; // If the selected file was changed from within _current_folder, also update dragDroppedFilePath - if (_current_folder.fileList.getActiveFile() != nullptr && + if (! _current_folder.fileList.getActiveFile()->path.empty() && cover.file_info.filename != _current_folder.fileList.getActiveFile()->filename) dragDroppedFilePath = _current_folder.fileList.getActiveFile()->path; @@ -3000,7 +3000,7 @@ SKIF_UI_Tab_DrawViewer (void) // Only apply changes to the scaling method if we actually have an image loaded if (cover.pRawTexSRV.p != nullptr) { - if (_current_folder.fileList.getActiveFile() != nullptr && ! _current_folder.fileList.getActiveFile()->path.empty() && + if (! _current_folder.fileList.getActiveFile()->path.empty() && ImGui::GetKeyData (ImGuiKey_Delete)->DownDuration == 0.0f) // Delete - Delete the opened image _DeleteImage (); diff --git a/src/utility/image.cpp b/src/utility/image.cpp index 4a18e20..fca1842 100644 --- a/src/utility/image.cpp +++ b/src/utility/image.cpp @@ -4048,11 +4048,12 @@ skiv_image_directory_s::reset (void) void skiv_image_directory_s::fl_s::setImage (const std::wstring& path) { + _it = _list.begin(); + if (_list.empty()) return; - _it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; }); - _ptr = _it._Ptr; + _it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; }); } std::wstring @@ -4074,7 +4075,6 @@ skiv_image_directory_s::fl_s::nextImage (void) else std::advance (_it, 1); - _ptr = _it._Ptr; return _it->path; } @@ -4097,7 +4097,6 @@ skiv_image_directory_s::fl_s::prevImage (void) else std::advance (_it, -1); - _ptr = _it._Ptr; return _it->path; } @@ -4115,8 +4114,6 @@ skiv_image_directory_s::fl_s::deleteImage (void) if (_it->path.empty() && ! _list.empty()) prevImage(); - _ptr = _it._Ptr; - return _it->path; } @@ -4124,14 +4121,12 @@ skiv_image_directory_s::fl_s::deleteImage (void) void skiv_image_directory_s::fl_s::updateFileIterator (const std::wstring& path) { - _it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; }); - // If the file was removed from File Explorer, reset to first item // TODO: Fix proper file tracking so we can detect removed files and just go to one of the nearby ones - if (_it->path.empty() && ! _list.empty()) - _it = _list.begin(); + _it = std::find_if (_list.begin(), _list.end(), [&](const fd_s& file) { return file.path == path; }); - _ptr = _it._Ptr; + if (_it == _list.end()) + _it = _list.begin(); } int