DirectoryView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "DirectoryView.h"
  27. #include "FileUtils.h"
  28. #include <AK/LexicalPath.h>
  29. #include <AK/NumberFormat.h>
  30. #include <AK/StringBuilder.h>
  31. #include <LibCore/File.h>
  32. #include <LibCore/MimeData.h>
  33. #include <LibCore/StandardPaths.h>
  34. #include <LibGUI/FileIconProvider.h>
  35. #include <LibGUI/InputBox.h>
  36. #include <LibGUI/Label.h>
  37. #include <LibGUI/MessageBox.h>
  38. #include <LibGUI/ModelEditingDelegate.h>
  39. #include <LibGUI/SortingProxyModel.h>
  40. #include <serenity.h>
  41. #include <spawn.h>
  42. #include <stdio.h>
  43. #include <unistd.h>
  44. namespace FileManager {
  45. NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(const LauncherHandler&)> launch_handler)
  46. {
  47. auto icon = GUI::FileIconProvider::icon_for_executable(details().executable).bitmap_for_size(16);
  48. return GUI::Action::create(details().name, move(icon), [this, launch_handler = move(launch_handler)](auto&) {
  49. launch_handler(*this);
  50. });
  51. }
  52. RefPtr<LauncherHandler> DirectoryView::get_default_launch_handler(const NonnullRefPtrVector<LauncherHandler>& handlers)
  53. {
  54. // If this is an application, pick it first
  55. for (size_t i = 0; i < handlers.size(); i++) {
  56. if (handlers[i].details().launcher_type == Desktop::Launcher::LauncherType::Application)
  57. return handlers[i];
  58. }
  59. // If there's a handler preferred by the user, pick this first
  60. for (size_t i = 0; i < handlers.size(); i++) {
  61. if (handlers[i].details().launcher_type == Desktop::Launcher::LauncherType::UserPreferred)
  62. return handlers[i];
  63. }
  64. // Otherwise, use the user's default, if available
  65. for (size_t i = 0; i < handlers.size(); i++) {
  66. if (handlers[i].details().launcher_type == Desktop::Launcher::LauncherType::UserDefault)
  67. return handlers[i];
  68. }
  69. // If still no match, use the first one we find
  70. if (!handlers.is_empty()) {
  71. return handlers[0];
  72. }
  73. return {};
  74. }
  75. NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const URL& url)
  76. {
  77. NonnullRefPtrVector<LauncherHandler> handlers;
  78. for (auto& h : Desktop::Launcher::get_handlers_with_details_for_url(url)) {
  79. handlers.append(adopt(*new LauncherHandler(h)));
  80. }
  81. return handlers;
  82. }
  83. NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const String& path)
  84. {
  85. return get_launch_handlers(URL::create_with_file_protocol(path));
  86. }
  87. void DirectoryView::handle_activation(const GUI::ModelIndex& index)
  88. {
  89. if (!index.is_valid())
  90. return;
  91. dbgln("on activation: {},{}, this={:p}, m_model={:p}", index.row(), index.column(), this, m_model.ptr());
  92. auto& node = this->node(index);
  93. auto path = node.full_path();
  94. struct stat st;
  95. if (stat(path.characters(), &st) < 0) {
  96. perror("stat");
  97. return;
  98. }
  99. if (S_ISDIR(st.st_mode)) {
  100. if (is_desktop()) {
  101. Desktop::Launcher::open(URL::create_with_file_protocol(path));
  102. return;
  103. }
  104. open(path);
  105. return;
  106. }
  107. auto url = URL::create_with_file_protocol(path);
  108. auto launcher_handlers = get_launch_handlers(url);
  109. auto default_launcher = get_default_launch_handler(launcher_handlers);
  110. if (default_launcher) {
  111. launch(url, *default_launcher);
  112. } else {
  113. auto error_message = String::formatted("Could not open {}", path);
  114. GUI::MessageBox::show(window(), error_message, "File Manager", GUI::MessageBox::Type::Error);
  115. }
  116. }
  117. DirectoryView::DirectoryView(Mode mode)
  118. : m_mode(mode)
  119. , m_model(GUI::FileSystemModel::create({}))
  120. , m_sorting_model(GUI::SortingProxyModel::create(m_model))
  121. {
  122. set_active_widget(nullptr);
  123. set_content_margins({ 2, 2, 2, 2 });
  124. setup_actions();
  125. m_error_label = add<GUI::Label>();
  126. m_error_label->set_font(m_error_label->font().bold_variant());
  127. setup_model();
  128. setup_icon_view();
  129. if (mode != Mode::Desktop) {
  130. setup_columns_view();
  131. setup_table_view();
  132. }
  133. set_view_mode(ViewMode::Icon);
  134. }
  135. const GUI::FileSystemModel::Node& DirectoryView::node(const GUI::ModelIndex& index) const
  136. {
  137. return model().node(m_sorting_model->map_to_source(index));
  138. }
  139. void DirectoryView::setup_model()
  140. {
  141. m_model->on_error = [this](int, const char* error_string) {
  142. auto failed_path = m_model->root_path();
  143. auto error_message = String::formatted("Could not read {}:\n{}", failed_path, error_string);
  144. m_error_label->set_text(error_message);
  145. set_active_widget(m_error_label);
  146. m_mkdir_action->set_enabled(false);
  147. m_touch_action->set_enabled(false);
  148. add_path_to_history(model().root_path());
  149. if (on_path_change)
  150. on_path_change(failed_path, false, false);
  151. };
  152. m_model->on_complete = [this] {
  153. if (m_table_view)
  154. m_table_view->selection().clear();
  155. if (m_icon_view)
  156. m_icon_view->selection().clear();
  157. add_path_to_history(model().root_path());
  158. bool can_write_in_path = access(model().root_path().characters(), W_OK) == 0;
  159. m_mkdir_action->set_enabled(can_write_in_path);
  160. m_touch_action->set_enabled(can_write_in_path);
  161. if (on_path_change)
  162. on_path_change(model().root_path(), true, can_write_in_path);
  163. };
  164. m_model->register_client(*this);
  165. m_model->on_thumbnail_progress = [this](int done, int total) {
  166. if (on_thumbnail_progress)
  167. on_thumbnail_progress(done, total);
  168. };
  169. if (is_desktop())
  170. m_model->set_root_path(Core::StandardPaths::desktop_directory());
  171. }
  172. void DirectoryView::setup_icon_view()
  173. {
  174. m_icon_view = add<GUI::IconView>();
  175. m_icon_view->set_should_hide_unnecessary_scrollbars(true);
  176. m_icon_view->set_selection_mode(GUI::AbstractView::SelectionMode::MultiSelection);
  177. m_icon_view->set_editable(true);
  178. m_icon_view->set_edit_triggers(GUI::AbstractView::EditTrigger::EditKeyPressed);
  179. m_icon_view->aid_create_editing_delegate = [](auto&) {
  180. return make<GUI::StringModelEditingDelegate>();
  181. };
  182. if (is_desktop()) {
  183. m_icon_view->set_frame_shape(Gfx::FrameShape::NoFrame);
  184. m_icon_view->set_scrollbars_enabled(false);
  185. m_icon_view->set_fill_with_background_color(false);
  186. m_icon_view->set_draw_item_text_with_shadow(true);
  187. m_icon_view->set_flow_direction(GUI::IconView::FlowDirection::TopToBottom);
  188. }
  189. m_icon_view->set_model(m_sorting_model);
  190. m_icon_view->set_model_column(GUI::FileSystemModel::Column::Name);
  191. m_icon_view->on_activation = [&](auto& index) {
  192. handle_activation(index);
  193. };
  194. m_icon_view->on_selection_change = [this] {
  195. handle_selection_change();
  196. };
  197. m_icon_view->on_context_menu_request = [this](auto& index, auto& event) {
  198. if (on_context_menu_request)
  199. on_context_menu_request(index, event);
  200. };
  201. m_icon_view->on_drop = [this](auto& index, auto& event) {
  202. handle_drop(index, event);
  203. };
  204. }
  205. void DirectoryView::setup_columns_view()
  206. {
  207. m_columns_view = add<GUI::ColumnsView>();
  208. m_columns_view->set_should_hide_unnecessary_scrollbars(true);
  209. m_columns_view->set_selection_mode(GUI::AbstractView::SelectionMode::MultiSelection);
  210. m_columns_view->set_editable(true);
  211. m_columns_view->set_edit_triggers(GUI::AbstractView::EditTrigger::EditKeyPressed);
  212. m_columns_view->aid_create_editing_delegate = [](auto&) {
  213. return make<GUI::StringModelEditingDelegate>();
  214. };
  215. m_columns_view->set_model(m_sorting_model);
  216. m_columns_view->set_model_column(GUI::FileSystemModel::Column::Name);
  217. m_columns_view->on_activation = [&](auto& index) {
  218. handle_activation(index);
  219. };
  220. m_columns_view->on_selection_change = [this] {
  221. handle_selection_change();
  222. };
  223. m_columns_view->on_context_menu_request = [this](auto& index, auto& event) {
  224. if (on_context_menu_request)
  225. on_context_menu_request(index, event);
  226. };
  227. m_columns_view->on_drop = [this](auto& index, auto& event) {
  228. handle_drop(index, event);
  229. };
  230. }
  231. void DirectoryView::setup_table_view()
  232. {
  233. m_table_view = add<GUI::TableView>();
  234. m_table_view->set_should_hide_unnecessary_scrollbars(true);
  235. m_table_view->set_selection_mode(GUI::AbstractView::SelectionMode::MultiSelection);
  236. m_table_view->set_editable(true);
  237. m_table_view->set_edit_triggers(GUI::AbstractView::EditTrigger::EditKeyPressed);
  238. m_table_view->aid_create_editing_delegate = [](auto&) {
  239. return make<GUI::StringModelEditingDelegate>();
  240. };
  241. m_table_view->set_model(m_sorting_model);
  242. m_table_view->set_key_column_and_sort_order(GUI::FileSystemModel::Column::Name, GUI::SortOrder::Ascending);
  243. m_table_view->on_activation = [&](auto& index) {
  244. handle_activation(index);
  245. };
  246. m_table_view->on_selection_change = [this] {
  247. handle_selection_change();
  248. };
  249. m_table_view->on_context_menu_request = [this](auto& index, auto& event) {
  250. if (on_context_menu_request)
  251. on_context_menu_request(index, event);
  252. };
  253. m_table_view->on_drop = [this](auto& index, auto& event) {
  254. handle_drop(index, event);
  255. };
  256. }
  257. DirectoryView::~DirectoryView()
  258. {
  259. m_model->unregister_client(*this);
  260. }
  261. void DirectoryView::model_did_update(unsigned flags)
  262. {
  263. if (flags & GUI::Model::UpdateFlag::InvalidateAllIndexes) {
  264. for_each_view_implementation([](auto& view) {
  265. view.selection().clear();
  266. });
  267. }
  268. update_statusbar();
  269. }
  270. void DirectoryView::set_view_mode(ViewMode mode)
  271. {
  272. if (m_view_mode == mode)
  273. return;
  274. m_view_mode = mode;
  275. update();
  276. if (mode == ViewMode::Table) {
  277. set_active_widget(m_table_view);
  278. return;
  279. }
  280. if (mode == ViewMode::Columns) {
  281. set_active_widget(m_columns_view);
  282. return;
  283. }
  284. if (mode == ViewMode::Icon) {
  285. set_active_widget(m_icon_view);
  286. return;
  287. }
  288. VERIFY_NOT_REACHED();
  289. }
  290. void DirectoryView::add_path_to_history(const StringView& path)
  291. {
  292. if (m_path_history.size() && m_path_history.at(m_path_history_position) == path)
  293. return;
  294. if (m_path_history_position < m_path_history.size())
  295. m_path_history.resize(m_path_history_position + 1);
  296. m_path_history.append(path);
  297. m_path_history_position = m_path_history.size() - 1;
  298. }
  299. void DirectoryView::open(const StringView& path)
  300. {
  301. auto real_path = Core::File::real_path_for(path);
  302. if (model().root_path() == real_path) {
  303. model().update();
  304. return;
  305. }
  306. set_active_widget(&current_view());
  307. model().set_root_path(real_path);
  308. }
  309. void DirectoryView::set_status_message(const StringView& message)
  310. {
  311. if (on_status_message)
  312. on_status_message(message);
  313. }
  314. void DirectoryView::open_parent_directory()
  315. {
  316. auto path = String::formatted("{}/..", model().root_path());
  317. model().set_root_path(path);
  318. }
  319. void DirectoryView::refresh()
  320. {
  321. model().update();
  322. }
  323. void DirectoryView::open_previous_directory()
  324. {
  325. if (m_path_history_position > 0) {
  326. set_active_widget(&current_view());
  327. m_path_history_position--;
  328. model().set_root_path(m_path_history[m_path_history_position]);
  329. }
  330. }
  331. void DirectoryView::open_next_directory()
  332. {
  333. if (m_path_history_position < m_path_history.size() - 1) {
  334. set_active_widget(&current_view());
  335. m_path_history_position++;
  336. model().set_root_path(m_path_history[m_path_history_position]);
  337. }
  338. }
  339. void DirectoryView::update_statusbar()
  340. {
  341. // If we're triggered during widget construction, just ignore it.
  342. if (m_view_mode == ViewMode::Invalid)
  343. return;
  344. size_t total_size = model().node({}).total_size;
  345. if (current_view().selection().is_empty()) {
  346. set_status_message(String::formatted("{} item(s) ({})",
  347. model().row_count(),
  348. human_readable_size(total_size)));
  349. return;
  350. }
  351. int selected_item_count = current_view().selection().size();
  352. size_t selected_byte_count = 0;
  353. current_view().selection().for_each_index([&](auto& index) {
  354. const auto& node = this->node(index);
  355. selected_byte_count += node.size;
  356. });
  357. StringBuilder builder;
  358. builder.append(String::number(selected_item_count));
  359. builder.append(" item");
  360. if (selected_item_count != 1)
  361. builder.append('s');
  362. builder.append(" selected (");
  363. builder.append(human_readable_size(selected_byte_count).characters());
  364. builder.append(')');
  365. if (selected_item_count == 1) {
  366. auto& node = this->node(current_view().selection().first());
  367. if (!node.symlink_target.is_empty()) {
  368. builder.append(" -> ");
  369. builder.append(node.symlink_target);
  370. }
  371. }
  372. set_status_message(builder.to_string());
  373. }
  374. void DirectoryView::set_should_show_dotfiles(bool show_dotfiles)
  375. {
  376. m_model->set_should_show_dotfiles(show_dotfiles);
  377. }
  378. void DirectoryView::launch(const URL&, const LauncherHandler& launcher_handler) const
  379. {
  380. pid_t child;
  381. if (launcher_handler.details().launcher_type == Desktop::Launcher::LauncherType::Application) {
  382. const char* argv[] = { launcher_handler.details().name.characters(), nullptr };
  383. posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ);
  384. if (disown(child) < 0)
  385. perror("disown");
  386. } else {
  387. for (auto& path : selected_file_paths()) {
  388. const char* argv[] = { launcher_handler.details().name.characters(), path.characters(), nullptr };
  389. posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ);
  390. if (disown(child) < 0)
  391. perror("disown");
  392. }
  393. }
  394. }
  395. Vector<String> DirectoryView::selected_file_paths() const
  396. {
  397. Vector<String> paths;
  398. auto& view = current_view();
  399. auto& model = *view.model();
  400. view.selection().for_each_index([&](const GUI::ModelIndex& index) {
  401. auto parent_index = model.parent_index(index);
  402. auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index);
  403. auto path = name_index.data(GUI::ModelRole::Custom).to_string();
  404. paths.append(path);
  405. });
  406. return paths;
  407. }
  408. void DirectoryView::do_delete(bool should_confirm)
  409. {
  410. auto paths = selected_file_paths();
  411. VERIFY(!paths.is_empty());
  412. FileUtils::delete_paths(paths, should_confirm, window());
  413. }
  414. void DirectoryView::handle_selection_change()
  415. {
  416. update_statusbar();
  417. bool can_delete = !current_view().selection().is_empty() && access(path().characters(), W_OK) == 0;
  418. m_delete_action->set_enabled(can_delete);
  419. m_force_delete_action->set_enabled(can_delete);
  420. if (on_selection_change)
  421. on_selection_change(current_view());
  422. }
  423. void DirectoryView::setup_actions()
  424. {
  425. m_mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) {
  426. String value;
  427. if (GUI::InputBox::show(window(), value, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) {
  428. auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
  429. int rc = mkdir(new_dir_path.characters(), 0777);
  430. if (rc < 0) {
  431. auto saved_errno = errno;
  432. GUI::MessageBox::show(window(), String::formatted("mkdir(\"{}\") failed: {}", new_dir_path, strerror(saved_errno)), "Error", GUI::MessageBox::Type::Error);
  433. }
  434. }
  435. });
  436. m_touch_action = GUI::Action::create("New file...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) {
  437. String value;
  438. if (GUI::InputBox::show(window(), value, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) {
  439. auto new_file_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
  440. struct stat st;
  441. int rc = stat(new_file_path.characters(), &st);
  442. if ((rc < 0 && errno != ENOENT)) {
  443. auto saved_errno = errno;
  444. GUI::MessageBox::show(window(), String::formatted("stat(\"{}\") failed: {}", new_file_path, strerror(saved_errno)), "Error", GUI::MessageBox::Type::Error);
  445. return;
  446. }
  447. if (rc == 0) {
  448. GUI::MessageBox::show(window(), String::formatted("{}: Already exists", new_file_path), "Error", GUI::MessageBox::Type::Error);
  449. return;
  450. }
  451. int fd = creat(new_file_path.characters(), 0666);
  452. if (fd < 0) {
  453. auto saved_errno = errno;
  454. GUI::MessageBox::show(window(), String::formatted("creat(\"{}\") failed: {}", new_file_path, strerror(saved_errno)), "Error", GUI::MessageBox::Type::Error);
  455. return;
  456. }
  457. rc = close(fd);
  458. VERIFY(rc >= 0);
  459. }
  460. });
  461. m_open_terminal_action = GUI::Action::create("Open Terminal here", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) {
  462. posix_spawn_file_actions_t spawn_actions;
  463. posix_spawn_file_actions_init(&spawn_actions);
  464. posix_spawn_file_actions_addchdir(&spawn_actions, path().characters());
  465. pid_t pid;
  466. const char* argv[] = { "Terminal", nullptr };
  467. if ((errno = posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ))) {
  468. perror("posix_spawn");
  469. } else {
  470. if (disown(pid) < 0)
  471. perror("disown");
  472. }
  473. posix_spawn_file_actions_destroy(&spawn_actions);
  474. });
  475. m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { do_delete(true); }, window());
  476. m_force_delete_action = GUI::Action::create(
  477. "Delete without confirmation", { Mod_Shift, Key_Delete },
  478. [this](auto&) { do_delete(false); },
  479. window());
  480. }
  481. void DirectoryView::handle_drop(const GUI::ModelIndex& index, const GUI::DropEvent& event)
  482. {
  483. if (!event.mime_data().has_urls())
  484. return;
  485. auto urls = event.mime_data().urls();
  486. if (urls.is_empty()) {
  487. dbgln("No files to drop");
  488. return;
  489. }
  490. auto& target_node = node(index);
  491. if (!target_node.is_directory())
  492. return;
  493. bool had_accepted_drop = false;
  494. for (auto& url_to_copy : urls) {
  495. if (!url_to_copy.is_valid() || url_to_copy.path() == target_node.full_path())
  496. continue;
  497. auto new_path = String::formatted("{}/{}", target_node.full_path(), LexicalPath(url_to_copy.path()).basename());
  498. if (url_to_copy.path() == new_path)
  499. continue;
  500. if (auto result = Core::File::copy_file_or_directory(new_path, url_to_copy.path()); result.is_error()) {
  501. auto error_message = String::formatted("Could not copy {} into {}: {}", url_to_copy.to_string(), new_path, result.error().error_code);
  502. GUI::MessageBox::show(window(), error_message, "File Manager", GUI::MessageBox::Type::Error);
  503. } else {
  504. had_accepted_drop = true;
  505. }
  506. }
  507. if (had_accepted_drop && on_accepted_drop)
  508. on_accepted_drop();
  509. }
  510. }