DirectoryView.cpp 20 KB

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