Skip to content

Commit

Permalink
new integrated terminal - added right click menu and keyboard shortcu…
Browse files Browse the repository at this point in the history
…ts to copy and paste
  • Loading branch information
giuspen committed Oct 7, 2022
1 parent 41169c3 commit 3fff0b2
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 45 deletions.
5 changes: 5 additions & 0 deletions src/ct/ct_actions.h
Expand Up @@ -523,4 +523,9 @@ class CtActions
void online_help();
void folder_cfg_open();
void dialog_about();

public:
void terminal_copy();
void terminal_paste();
void terminal_reset();
};
14 changes: 14 additions & 0 deletions src/ct/ct_actions_edit.cc
Expand Up @@ -554,6 +554,13 @@ void CtActions::cut_as_plain_text()
// Copy as Plain Text
void CtActions::copy_as_plain_text()
{
#if defined(HAVE_VTE)
Gtk::Widget* pVte = _pCtMainWin->get_vte();
if (pVte and pVte->has_focus()) {
terminal_copy();
return;
}
#endif // HAVE_VTE
CtClipboard::force_plain_text();
auto proof = _get_text_view_n_buffer_codebox_proof();
g_signal_emit_by_name(G_OBJECT(proof.text_view->gobj()), "copy-clipboard");
Expand All @@ -562,6 +569,13 @@ void CtActions::copy_as_plain_text()
// Paste as Plain Text
void CtActions::paste_as_plain_text()
{
#if defined(HAVE_VTE)
Gtk::Widget* pVte = _pCtMainWin->get_vte();
if (pVte and pVte->has_focus()) {
terminal_paste();
return;
}
#endif // HAVE_VTE
auto proof = _get_text_view_n_buffer_codebox_proof();
CtClipboard::force_plain_text();
g_signal_emit_by_name(G_OBJECT(proof.text_view->gobj()), "paste-clipboard");
Expand Down
71 changes: 35 additions & 36 deletions src/ct/ct_actions_others.cc
Expand Up @@ -34,8 +34,10 @@
#ifndef _WIN32
#include <sys/wait.h> // WEXITSTATUS __FreeBSD__ (#1550)
#endif // !_WIN32
#if defined(HAVE_VTE)
#include <vte/vte.h>
#endif // HAVE_VTE

// Cut Link
void CtActions::link_cut()
{
if (!_is_curr_node_not_read_only_or_error()) return;
Expand All @@ -44,15 +46,13 @@ void CtActions::link_cut()
}
}

// Copy Link
void CtActions::link_copy()
{
if (!_link_check_around_cursor().empty()) {
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}
}

//Dismiss Link
void CtActions::link_dismiss()
{
if (!_is_curr_node_not_read_only_or_error()) return;
Expand All @@ -61,7 +61,6 @@ void CtActions::link_dismiss()
}
}

// Delete Link
void CtActions::link_delete()
{
if (!_is_curr_node_not_read_only_or_error()) return;
Expand All @@ -71,21 +70,18 @@ void CtActions::link_delete()
}
}

// Cut Anchor
void CtActions::anchor_cut()
{
object_set_selection(curr_anchor_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

// Copy Anchor
void CtActions::anchor_copy()
{
object_set_selection(curr_anchor_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

// Delete Anchor
void CtActions::anchor_delete()
{
object_set_selection(curr_anchor_anchor);
Expand All @@ -94,7 +90,6 @@ void CtActions::anchor_delete()
_pCtMainWin->get_text_view().grab_focus();
}

// Edit an Anchor
void CtActions::anchor_edit()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -109,21 +104,18 @@ void CtActions::anchor_link_to_clipboard()
CtClipboard{_pCtMainWin}.anchor_link_to_clipboard(_pCtMainWin->curr_tree_iter(), curr_anchor_anchor->get_anchor_name());
}

// Cut Embedded File
void CtActions::embfile_cut()
{
object_set_selection(curr_file_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

// Copy Embedded File
void CtActions::embfile_copy()
{
object_set_selection(curr_file_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

// Delete Embedded File
void CtActions::embfile_delete()
{
object_set_selection(curr_file_anchor);
Expand All @@ -132,7 +124,6 @@ void CtActions::embfile_delete()
_pCtMainWin->get_text_view().grab_focus();
}

// Embedded File Save Dialog
void CtActions::embfile_save()
{
CtDialogs::FileSelectArgs args{_pCtMainWin};
Expand All @@ -146,7 +137,6 @@ void CtActions::embfile_save()
g_file_set_contents(filepath.c_str(), curr_file_anchor->get_raw_blob().c_str(), (gssize)curr_file_anchor->get_raw_blob().size(), nullptr);
}

// Embedded File Open
void CtActions::embfile_open()
{
const size_t open_id = curr_file_anchor->get_unique_id();
Expand Down Expand Up @@ -177,7 +167,6 @@ void CtActions::embfile_open()
}
}

// Embedded File Rename
void CtActions::embfile_rename()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -191,7 +180,6 @@ void CtActions::embfile_rename()
_pCtMainWin->update_window_save_needed(CtSaveNeededUpdType::nbuf, true/*new_machine_state*/);
}

// Save to Disk the selected LatexBox Image
void CtActions::latex_save()
{
CtDialogs::FileSelectArgs args{_pCtMainWin};
Expand All @@ -213,7 +201,6 @@ void CtActions::latex_save()
}
}

// Edit the selected LatexBox
void CtActions::latex_edit()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -223,21 +210,18 @@ void CtActions::latex_edit()
_latex_edit_dialog(curr_latex_anchor->get_latex_text(), iter_insert, &iter_bound);
}

// Cut LatexBox
void CtActions::latex_cut()
{
object_set_selection(curr_latex_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

// Copy LatexBox
void CtActions::latex_copy()
{
object_set_selection(curr_latex_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

// Delete LatexBox
void CtActions::latex_delete()
{
object_set_selection(curr_latex_anchor);
Expand All @@ -246,7 +230,6 @@ void CtActions::latex_delete()
_pCtMainWin->get_text_view().grab_focus();
}

// Save to Disk the selected Image
void CtActions::image_save()
{
CtDialogs::FileSelectArgs args{_pCtMainWin};
Expand All @@ -268,7 +251,6 @@ void CtActions::image_save()
}
}

// Edit the selected Image
void CtActions::image_edit()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -278,21 +260,18 @@ void CtActions::image_edit()
_image_edit_dialog(curr_image_anchor->get_pixbuf(), iter_insert, &iter_bound);
}

// Cut Image
void CtActions::image_cut()
{
object_set_selection(curr_image_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

// Copy Image
void CtActions::image_copy()
{
object_set_selection(curr_image_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

// Delete Image
void CtActions::image_delete()
{
object_set_selection(curr_image_anchor);
Expand All @@ -301,7 +280,6 @@ void CtActions::image_delete()
_pCtMainWin->get_text_view().grab_focus();
}

// Edit the Link Associated to the Image
void CtActions::image_link_edit()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -324,7 +302,6 @@ void CtActions::image_link_edit()
}
}

// Dismiss the Link Associated to the Image
void CtActions::image_link_dismiss()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -338,7 +315,6 @@ void CtActions::toggle_show_hide_main_window()
_pCtMainWin->signal_app_show_hide_main_win();
}

// Function Called at Every Link Click
void CtActions::link_clicked(const Glib::ustring& tag_property_value, bool from_wheel)
{
CtLinkEntry link_entry = CtMiscUtil::get_link_entry(tag_property_value);
Expand Down Expand Up @@ -432,21 +408,18 @@ void CtActions::current_node_scroll_to_anchor(Glib::ustring anchor_name)
}
}

// Cut CodeBox
void CtActions::codebox_cut()
{
object_set_selection(curr_codebox_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "cut-clipboard");
}

// Copy CodeBox
void CtActions::codebox_copy()
{
object_set_selection(curr_codebox_anchor);
g_signal_emit_by_name(G_OBJECT(_pCtMainWin->get_text_view().gobj()), "copy-clipboard");
}

// Delete CodeBox
void CtActions::codebox_delete()
{
object_set_selection(curr_codebox_anchor);
Expand All @@ -455,7 +428,6 @@ void CtActions::codebox_delete()
_pCtMainWin->get_text_view().grab_focus();
}

// Delete CodeBox but keep the Text
void CtActions::codebox_delete_keeping_text()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -467,7 +439,6 @@ void CtActions::codebox_delete_keeping_text()
_curr_buffer()->insert_at_cursor(content);
}

// Change CodeBox Properties
void CtActions::codebox_change_properties()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand Down Expand Up @@ -573,7 +544,6 @@ void CtActions::_exec_code(const bool is_all)
}
}

// Load the CodeBox Content From a Text Fil
void CtActions::codebox_load_from_file()
{
if (not _is_curr_node_not_read_only_or_error()) return;
Expand All @@ -588,7 +558,6 @@ void CtActions::codebox_load_from_file()
curr_codebox_anchor->get_buffer()->set_text(buffer);
}

// Save the CodeBox Content To a Text File
void CtActions::codebox_save_to_file()
{
CtDialogs::FileSelectArgs args{_pCtMainWin};
Expand Down Expand Up @@ -830,7 +799,6 @@ void CtActions::table_export()
}
}

// Anchor Edit Dialog
void CtActions::_anchor_edit_dialog(CtImageAnchor* anchor, Gtk::TextIter insert_iter, Gtk::TextIter* iter_bound)
{
Glib::ustring dialog_title = anchor == nullptr ? _("Insert Anchor") : _("Edit Anchor");
Expand All @@ -848,7 +816,6 @@ void CtActions::_anchor_edit_dialog(CtImageAnchor* anchor, Gtk::TextIter insert_
image_insert_anchor(insert_iter, ret_anchor_name, image_justification);
}

// Iteration of the Modification Time Sentinel
bool CtActions::_on_embfiles_sentinel_timeout()
{
for (auto& item : _embfiles_opened) {
Expand Down Expand Up @@ -891,3 +858,35 @@ bool CtActions::_on_embfiles_sentinel_timeout()
}
return true; // this way we keep the timer alive
}

void CtActions::terminal_copy()
{
#if defined(HAVE_VTE)
Gtk::Widget* pVte = _pCtMainWin->get_vte();
if (not pVte) {
return;
}
GtkWidget* pTermWidget = pVte->gobj();
if (not vte_terminal_get_has_selection(VTE_TERMINAL(pTermWidget))) {
vte_terminal_select_all(VTE_TERMINAL(pTermWidget));
}
vte_terminal_copy_clipboard_format(VTE_TERMINAL(pTermWidget), VTE_FORMAT_TEXT);
#endif // HAVE_VTE
}

void CtActions::terminal_paste()
{
#if defined(HAVE_VTE)
Gtk::Widget* pVte = _pCtMainWin->get_vte();
if (not pVte) {
return;
}
GtkWidget* pTermWidget = pVte->gobj();
vte_terminal_paste_clipboard(VTE_TERMINAL(pTermWidget));
#endif // HAVE_VTE
}

void CtActions::terminal_reset()
{
_pCtMainWin->restart_vte();
}
22 changes: 14 additions & 8 deletions src/ct/ct_main_win_vte.cc
Expand Up @@ -22,6 +22,7 @@
*/

#include "ct_main_win.h"
#include "ct_actions.h"
#if defined(HAVE_VTE)
#include <vte/vte.h>
#endif // HAVE_VTE
Expand Down Expand Up @@ -113,19 +114,24 @@ void CtMainWin::restart_vte()
button_reset->set_image(*new_managed_image_from_stock("ct_clear", Gtk::ICON_SIZE_MENU));
button_reset->set_tooltip_text(_("Reset"));

button_copy->signal_clicked().connect([pTermWidget](){
if (not vte_terminal_get_has_selection(VTE_TERMINAL(pTermWidget))) {
vte_terminal_select_all(VTE_TERMINAL(pTermWidget));
}
vte_terminal_copy_clipboard_format(VTE_TERMINAL(pTermWidget), VTE_FORMAT_TEXT);
button_copy->signal_clicked().connect([this](){
get_ct_actions()->terminal_copy();
});
button_paste->signal_clicked().connect([pTermWidget](){
vte_terminal_paste_clipboard(VTE_TERMINAL(pTermWidget));
button_paste->signal_clicked().connect([this](){
get_ct_actions()->terminal_paste();
});
button_reset->signal_clicked().connect([this](){
restart_vte();
get_ct_actions()->terminal_reset();
});

_pVte->signal_button_press_event().connect([this](GdkEventButton* event){
if (3 == event->button) {
get_ct_menu().get_popup_menu(CtMenu::POPUP_MENU_TYPE::Terminal)->popup(event->button, event->time);
return true; // do not propagate the event
}
return false; // propagate the event
}, false);

auto pButtonsBox = Gtk::manage(new Gtk::Box{Gtk::ORIENTATION_VERTICAL, 0/*spacing*/});
pButtonsBox->pack_start(*button_copy, false, false);
pButtonsBox->pack_start(*button_paste, false, false);
Expand Down

0 comments on commit 3fff0b2

Please sign in to comment.