diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-16 08:24:15 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-16 08:24:15 +0200 |
commit | f0539547ffe1de0d85822f10264a4a110e4344a2 (patch) | |
tree | 5dcfbf58b680d6143a676351d0e882022ac247b1 | |
parent | 686adc5690c8507d25b080612f301c1aef594a19 (diff) |
Matrix: add ctrl+v pasting to upload media file, vim key navigation
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 32 |
2 files changed, 26 insertions, 11 deletions
@@ -49,7 +49,10 @@ Press `Enter` to view image/video attached to matrix message, or to view the url Press `Ctrl + M` to begin writing a message in a matrix room, press `ESC` to cancel.\ Press `Ctrl + R` to reply to a message on matrix, press `ESC` to cancel.\ Press `Ctrl + E` to edit a message on matrix, press `ESC` to cancel. Currently only works for your own messages.\ -Press `Ctrl + D` to delete a message on matrix. Currently deleting a message only deletes the event, so if you delete an edit then the original message wont be deleted. +Press `Ctrl + D` to delete a message on matrix. Currently deleting a message only deletes the event, so if you delete an edit then the original message wont be deleted.\ +Press `Ctrl + V` to upload media to room in matrix, if the clipboard contains a path to an absolute filepath. + +In the matrix client you can also navigate using VIM keys (H, J, K, L). In matrix you can select a message with enter to open the url in the message (or if there are multiple urls then a menu will appear for selecting which to open). ## Matrix commands diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 0139f37..cea2afb 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3199,10 +3199,12 @@ namespace QuickMedia { } else if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) { redraw = true; } else if(event.type == sf::Event::KeyPressed && chat_state == ChatState::NAVIGATING) { - if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home) { + if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home || event.key.code == sf::Keyboard::K) + { bool hit_top = false; switch(event.key.code) { case sf::Keyboard::Up: + case sf::Keyboard::K: hit_top = !tabs[selected_tab].body->select_previous_item(); break; case sf::Keyboard::PageUp: @@ -3227,7 +3229,7 @@ namespace QuickMedia { return result_items; }); } - } else if(event.key.code == sf::Keyboard::Down) { + } else if(event.key.code == sf::Keyboard::Down || event.key.code == sf::Keyboard::J) { tabs[selected_tab].body->select_next_item(); } else if(event.key.code == sf::Keyboard::PageDown) { tabs[selected_tab].body->select_next_page(); @@ -3235,7 +3237,7 @@ namespace QuickMedia { tabs[selected_tab].body->select_last_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = PageType::EXIT; - } else if(event.key.code == sf::Keyboard::Left && synced) { + } else if((event.key.code == sf::Keyboard::Left || event.key.code == sf::Keyboard::H) && synced) { tabs[selected_tab].body->clear_cache(); selected_tab = std::max(0, selected_tab - 1); read_marker_timer.restart(); @@ -3245,7 +3247,7 @@ namespace QuickMedia { typing = false; typing_futures.push_back(std::async(typing_async_func, false, current_room_id)); } - } else if(event.key.code == sf::Keyboard::Right && synced) { + } else if((event.key.code == sf::Keyboard::Right || event.key.code == sf::Keyboard::L) && synced) { tabs[selected_tab].body->clear_cache(); selected_tab = std::min((int)tabs.size() - 1, selected_tab + 1); read_marker_timer.restart(); @@ -3257,6 +3259,21 @@ 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<BodyItem> selected = tabs[selected_tab].body->get_selected_shared(); if(selected) { @@ -3373,11 +3390,6 @@ namespace QuickMedia { } } - if(chat_state == ChatState::NAVIGATING && tabs[selected_tab].type == ChatTabType::MESSAGES && event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::M && event.key.control) { - chat_input.set_editable(true); - chat_state = ChatState::TYPING_MESSAGE; - } - if((chat_state == ChatState::TYPING_MESSAGE || chat_state == ChatState::REPLYING || chat_state == ChatState::EDITING) && tabs[selected_tab].type == ChatTabType::MESSAGES) { if(event.type == sf::Event::TextEntered) { //chat_input.onTextEntered(event.text.unicode); @@ -3454,7 +3466,7 @@ namespace QuickMedia { // TODO: Upload multiple files. std::string err_msg; if(matrix->post_file(current_room_id, selected_files[0], err_msg) != PluginResult::OK) { - std::string desc = "Failed to upload image to room, error: " + err_msg; + std::string desc = "Failed to upload media to room, error: " + err_msg; show_notification("QuickMedia", desc.c_str(), Urgency::CRITICAL); } } |