// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // The MIT License (MIT) // // Copyright (c) 2018 www.open3d.org // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // ---------------------------------------------------------------------------- #if defined(__APPLE__) // see FileDialogNative.cpp #else #include "Open3D/GUI/FileDialog.h" #include #include #include #include "Open3D/GUI/Button.h" #include "Open3D/GUI/Combobox.h" #include "Open3D/GUI/Label.h" #include "Open3D/GUI/Layout.h" #include "Open3D/GUI/ListView.h" #include "Open3D/GUI/TextEdit.h" #include "Open3D/GUI/Theme.h" #include "Open3D/GUI/Util.h" #include "Open3D/Utility/Console.h" #include "Open3D/Utility/FileSystem.h" #include "Open3D/Utility/Helper.h" // macOS sorts directories in with the files // Windows and Linux (GTK) sort directories first. #ifdef __APPLE__ #define INLINE_DIRS 1 #else #define INLINE_DIRS 0 #endif // __APPLE__ namespace open3d { namespace gui { namespace { // The current path of the dialog should persist across runs of the dialog. // This is defined here rather than in the class definition because we don't // need to be exporting internal details of the class. static std::string g_file_dialog_dir; } // namespace class DirEntry { public: enum Type { DIR, FILE }; DirEntry(const std::string &name, Type type) { type_ = type; name_ = name; if (type == DIR) { display_ = std::string("[ ] ") + name_ + "/"; } else { display_ = std::string(" ") + name_; } } Type GetType() const { return type_; } const std::string &GetName() const { return name_; } const std::string &GetDisplayText() const { return display_; } bool operator==(const DirEntry &rhs) const { return (type_ == rhs.type_ && name_ == rhs.name_); } bool operator!=(const DirEntry &rhs) const { return !this->operator==(rhs); } bool operator<(const DirEntry &rhs) const { #if INLINE_DIRS // Sort directories by name; if the OS allows directories and files // to have the same name, put directories first. if (name_ == rhs.name_) { if (type_ == rhs.type_) { return false; } else { return (type_ == DIR); } } else { return (name_ < rhs.name_); } #else // Sort directories first, then files. // Within each category sort by name. if (type_ == rhs.type_) { return (name_ < rhs.name_); } else { return (type_ == DIR); } #endif // INLINE_DIRS } private: Type type_; std::string name_; std::string display_; }; struct FileDialog::Impl { Mode mode_; std::vector entries_; std::shared_ptr filename_; std::shared_ptr dirtree_; std::shared_ptr filelist_; std::shared_ptr filter_; std::unordered_map> filter_idx_2_filter; std::shared_ptr filter_row_; std::shared_ptr