From 0f6813a68d7f54c811b5040bdea37ca7b7e1b86e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 16 Oct 2020 19:44:18 +0200 Subject: Matrix: Change keybindings to not use ctrl, and add U to upload media --- src/QuickMedia.cpp | 135 ++++++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index cea2afb..cec81c6 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -2979,7 +2979,7 @@ namespace QuickMedia { sf::Sprite logo_sprite(plugin_logo); - Entry chat_input("Press ctrl+m to begin writing a message...", font.get(), cjk_font.get()); + Entry chat_input("Press m or i to begin writing a message...", font.get(), cjk_font.get()); chat_input.draw_background = false; chat_input.set_editable(false); @@ -3259,68 +3259,6 @@ namespace QuickMedia { } } - if(tabs[selected_tab].type == ChatTabType::MESSAGES && ((event.key.control && event.key.code == sf::Keyboard::M) || event.key.code == sf::Keyboard::I)) { - chat_input.set_editable(true); - chat_state = ChatState::TYPING_MESSAGE; - } - - if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::V) { - // TODO: Make asynchronous. - // TODO: Upload multiple files. - std::string err_msg; - if(matrix->post_file(current_room_id, sf::Clipboard::getString(), err_msg) != PluginResult::OK) { - std::string desc = "Failed to upload media to room, error: " + err_msg; - show_notification("QuickMedia", desc.c_str(), Urgency::CRITICAL); - } - } - - if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::R) { - std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); - if(selected) { - chat_state = ChatState::REPLYING; - currently_operating_on_item = selected; - chat_input.set_editable(true); - replying_to_text.setString("Replying to:"); - } else { - // TODO: Show inline notification - show_notification("QuickMedia", "No message selected for replying"); - } - } else if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::E) { - std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); - if(selected) { - if(!selected->url.empty()) { // cant edit messages that are image/video posts - // TODO: Show inline notification - show_notification("QuickMedia", "You can only edit messages with no file attached to it"); - } else if(!matrix->was_message_posted_by_me(selected->userdata)) { - // TODO: Show inline notification - show_notification("QuickMedia", "You can't edit a message that was posted by somebody else"); - } else { - chat_state = ChatState::EDITING; - currently_operating_on_item = selected; - chat_input.set_editable(true); - chat_input.set_text(selected->get_description()); // TODO: Description? it may change in the future, in which case this should be edited - chat_input.move_caret_to_end(); - replying_to_text.setString("Editing message:"); - } - } else { - // TODO: Show inline notification - show_notification("QuickMedia", "No message selected for editing"); - } - } else if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.control && event.key.code == sf::Keyboard::D) { - BodyItem *selected = tabs[selected_tab].body->get_selected(); - if(selected) { - // TODO: Make asynchronous - std::string err_msg; - if(matrix->delete_message(current_room_id, selected->userdata, err_msg) != PluginResult::OK) { - // TODO: Show inline notification - show_notification("QuickMedia", "Failed to delete message, reason: " + err_msg, Urgency::CRITICAL); - } - } else { - // TODO: Show inline notification - show_notification("QuickMedia", "No message selected for deletion"); - } - } - if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.code == sf::Keyboard::Enter) { BodyItem *selected = tabs[selected_tab].body->get_selected(); if(selected) { @@ -3388,6 +3326,77 @@ namespace QuickMedia { continue; launch_url(selected_item->get_title()); } + } else if(event.type == sf::Event::KeyReleased && chat_state == ChatState::NAVIGATING && tabs[selected_tab].type == ChatTabType::MESSAGES) { + if(event.key.code == sf::Keyboard::U) { + new_page = PageType::FILE_MANAGER; + chat_input.set_editable(false); + } + + if(event.key.code == sf::Keyboard::M || event.key.code == sf::Keyboard::I) { + chat_input.set_editable(true); + chat_state = ChatState::TYPING_MESSAGE; + } + + if(event.key.control && event.key.code == sf::Keyboard::V) { + // TODO: Make asynchronous. + // TODO: Upload multiple files. + std::string err_msg; + if(matrix->post_file(current_room_id, sf::Clipboard::getString(), err_msg) != PluginResult::OK) { + std::string desc = "Failed to upload media to room, error: " + err_msg; + show_notification("QuickMedia", desc.c_str(), Urgency::CRITICAL); + } + } + + if(event.key.code == sf::Keyboard::R) { + std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); + if(selected) { + chat_state = ChatState::REPLYING; + currently_operating_on_item = selected; + chat_input.set_editable(true); + replying_to_text.setString("Replying to:"); + } else { + // TODO: Show inline notification + show_notification("QuickMedia", "No message selected for replying"); + } + } + + if(event.key.code == sf::Keyboard::E) { + std::shared_ptr selected = tabs[selected_tab].body->get_selected_shared(); + if(selected) { + if(!selected->url.empty()) { // cant edit messages that are image/video posts + // TODO: Show inline notification + show_notification("QuickMedia", "You can only edit messages with no file attached to it"); + } else if(!matrix->was_message_posted_by_me(selected->userdata)) { + // TODO: Show inline notification + show_notification("QuickMedia", "You can't edit a message that was posted by somebody else"); + } else { + chat_state = ChatState::EDITING; + currently_operating_on_item = selected; + chat_input.set_editable(true); + chat_input.set_text(selected->get_description()); // TODO: Description? it may change in the future, in which case this should be edited + chat_input.move_caret_to_end(); + replying_to_text.setString("Editing message:"); + } + } else { + // TODO: Show inline notification + show_notification("QuickMedia", "No message selected for editing"); + } + } + + if(event.key.code == sf::Keyboard::D) { + BodyItem *selected = tabs[selected_tab].body->get_selected(); + if(selected) { + // TODO: Make asynchronous + std::string err_msg; + if(matrix->delete_message(current_room_id, selected->userdata, err_msg) != PluginResult::OK) { + // TODO: Show inline notification + show_notification("QuickMedia", "Failed to delete message, reason: " + err_msg, Urgency::CRITICAL); + } + } else { + // TODO: Show inline notification + show_notification("QuickMedia", "No message selected for deletion"); + } + } } if((chat_state == ChatState::TYPING_MESSAGE || chat_state == ChatState::REPLYING || chat_state == ChatState::EDITING) && tabs[selected_tab].type == ChatTabType::MESSAGES) { -- cgit v1.2.3