/* Restores current item from the trash. */ static KHandlerResponse restore_current(menu_data_t *m) { char *trash_path; int err; cmd_group_begin("restore: "); cmd_group_end(); /* The string is freed in restore_from_trash(), thus must be cloned. */ trash_path = strdup(trash_list[m->pos].trash_name); err = restore_from_trash(trash_path); free(trash_path); if(err != 0) { const char *const orig_path = m->items[m->pos]; status_bar_errorf("Failed to restore %s", orig_path); curr_stats.save_msg = 1; return KHR_UNHANDLED; } remove_current_item(m->state); return KHR_REFRESH_WINDOW; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse trashes_khandler(FileView *view, menu_data_t *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) { const char *const item = m->items[m->pos]; const char *trash_dir = m->extra_data ? strchr(item, ']') + 2 : item; trash_empty(trash_dir); remove_current_item(m->state); return KHR_REFRESH_WINDOW; } return KHR_UNHANDLED; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse commands_khandler(menu_info *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) /* remove element */ { char cmd_buf[512]; break_at(m->items[m->pos], ' '); snprintf(cmd_buf, sizeof(cmd_buf), "delcommand %s", m->items[m->pos]); execute_cmdline_command(cmd_buf); remove_current_item(m); return KHR_REFRESH_WINDOW; } return KHR_UNHANDLED; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse commands_khandler(FileView *view, menu_data_t *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) /* Remove element. */ { char cmd_buf[512]; break_at(m->items[m->pos], ' '); snprintf(cmd_buf, sizeof(cmd_buf), "cunabbrev %s", m->items[m->pos]); execute_cmdline_command(cmd_buf); remove_current_item(m->state); return KHR_REFRESH_WINDOW; } return KHR_UNHANDLED; }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse commands_khandler(menu_info *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) { /* Remove element. */ char cmd_buf[512]; break_at(m->items[m->pos], ' '); snprintf(cmd_buf, sizeof(cmd_buf), "delcommand %s", m->items[m->pos]); execute_cmdline_command(cmd_buf); remove_current_item(m); return KHR_REFRESH_WINDOW; } else if(wcscmp(keys, L"c") == 0) { const char *const rhs = skip_whitespace(after_first(m->items[m->pos], ' ')); /* Insert command RHS. */ if(rhs[0] == ':') { menu_morph_into_cmdline(CLS_COMMAND, skip_whitespace(rhs + 1), 0); } else if(rhs[0] == '/') { menu_morph_into_cmdline(CLS_FSEARCH, rhs + 1, 0); } else if(rhs[0] == '=') { menu_morph_into_cmdline(CLS_FILTER, rhs + 1, 0); } else { /* filter commands go here. */ menu_morph_into_cmdline(CLS_COMMAND, rhs, (rhs[0] != '!')); } return KHR_MORPHED_MENU; } return KHR_UNHANDLED; }
/* Deletes current item from the trash. */ static KHandlerResponse delete_current(menu_data_t *m) { int ret; io_args_t args = { .arg1.path = trash_list[m->pos].trash_name, .cancellation.hook = &ui_cancellation_hook, }; ioe_errlst_init(&args.result.errors); ui_cancellation_enable(); ret = ior_rm(&args); ui_cancellation_disable(); if(ret != 0) { char *const errors = ioe_errlst_to_str(&args.result.errors); ioe_errlst_free(&args.result.errors); show_error_msg("File deletion error", errors); free(errors); return KHR_UNHANDLED; } ioe_errlst_free(&args.result.errors); remove_current_item(m->state); return KHR_REFRESH_WINDOW; } /* Implementation of cancellation hook for I/O unit. */ static int ui_cancellation_hook(void *arg) { return ui_cancellation_requested(); }
/* Menu-specific shortcut handler. Returns code that specifies both taken * actions and what should be done next. */ static KHandlerResponse bmarks_khandler(menu_info *m, const wchar_t keys[]) { if(wcscmp(keys, L"dd") == 0) { bmarks_remove(m->data[m->pos]); remove_current_item(m); return KHR_REFRESH_WINDOW; } else if(wcscmp(keys, L"gf") == 0) { goto_selected_file(curr_view, m->data[m->pos], 0); return KHR_CLOSE_MENU; } else if(wcscmp(keys, L"e") == 0) { goto_selected_file(curr_view, m->data[m->pos], 1); return KHR_REFRESH_WINDOW; } /* Can't reuse filelist_khandler() here as it works with m->items, not with * m->data. */ return KHR_UNHANDLED; }