diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index bcc2c93..768b1ea 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -80,19 +80,28 @@ static os::WindowRef create_window(os::DragTarget& dragTarget) { bool processEvent(const os::Event& ev) { switch (ev.type()) { - case os::Event::KeyDown: + case os::Event::KeyDown: { if (ev.scancode() == os::kKeyEsc) return false; break; + } case os::Event::CloseApp: - case os::Event::CloseWindow: + case os::Event::CloseWindow: { closing = true; return false; + } case os::Event::ResizeWindow: break; + case os::Event::MouseDown: { + base::paths paths; + utils::show_file_selector("Blur input", ".", { "mp4", "mkv" }, os::FileDialog::Type::OpenFiles, paths); + tasks::add_files(paths); + break; + } + default: break; } diff --git a/src/gui/ui/utils.cpp b/src/gui/ui/utils.cpp index 0661106..dd394f8 100644 --- a/src/gui/ui/utils.cpp +++ b/src/gui/ui/utils.cpp @@ -105,3 +105,75 @@ double utils::get_display_refresh_rate(int screenNumber) return static_cast(rate); #endif } + +bool utils::show_file_selector( // aseprite + const std::string& title, + const std::string& initialPath, + const base::paths& extensions, + os::FileDialog::Type type, + base::paths& output +) { + const std::string defExtension = ""; // + + if (os::instance()->nativeDialogs()) { + os::FileDialogRef dlg = + os::instance()->nativeDialogs()->makeFileDialog(); + + if (dlg) { + dlg->setTitle(title); + + // Must be set before setFileName() as the Linux impl might + // require the default extension to fix the initial file name + // with the default extension. + if (!defExtension.empty()) { + dlg->setDefaultExtension(defExtension); + } + +#if LAF_LINUX // As the X11 version doesn't store the default path to + // start navigating, we use our own + // get_initial_path_to_select_filename() + dlg->setFileName(get_initial_path_to_select_filename(initialPath)); +#else // !LAF_LINUX + dlg->setFileName(initialPath); +#endif + + dlg->setType(type); + + for (const auto& ext : extensions) + dlg->addFilter(ext, ext + " files (*." + ext + ")"); + + auto res = dlg->show(os::instance()->defaultWindow()); + if (res != os::FileDialog::Result::Error) { + if (res == os::FileDialog::Result::OK) { + if (type == os::FileDialog::Type::OpenFiles) + dlg->getMultipleFileNames(output); + else + output.push_back(dlg->fileName()); + +#if LAF_LINUX // Save the path in the configuration file + if (!output.empty()) { + set_current_dir_for_file_selector(base::get_file_path(output[0])); + } +#endif + + return true; + } + else { + return false; + } + } + else { + // Fallback to default file selector if we weren't able to + // open the native dialog... + } + } + } + + // FileSelector fileSelector(type); + + // if (!defExtension.empty()) + // fileSelector.setDefaultExtension(defExtension); + + // return fileSelector.show(title, initialPath, extensions, output); + return false; +} diff --git a/src/gui/ui/utils.h b/src/gui/ui/utils.h index d292a5b..36c2148 100644 --- a/src/gui/ui/utils.h +++ b/src/gui/ui/utils.h @@ -10,4 +10,12 @@ namespace utils { #else double get_display_refresh_rate(int screenNumber); #endif + + bool show_file_selector( + const std::string& title, + const std::string& initialPath, + const base::paths& extensions, + os::FileDialog::Type type, + base::paths& output + ); }