Skip to content
28 changes: 28 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ namespace Scratch {
visible = false
};

terminal.terminal.focus_in_event.connect (on_terminal_focus_change);
terminal.terminal.focus_out_event.connect (on_terminal_focus_change);

var view_grid = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL
};
Expand Down Expand Up @@ -745,6 +748,27 @@ namespace Scratch {
toolbar.share_menu_button.sensitive = val;
}

private bool on_terminal_focus_change () {
var focused = terminal.terminal.has_focus;
//<Control>r +- shift
Utils.action_from_group (ACTION_SHOW_REPLACE, actions).set_enabled (!focused);
Utils.action_from_group (ACTION_RESTORE_PROJECT_DOCS, actions).set_enabled (!focused);
//<Control>z +- shift
Utils.action_from_group (ACTION_UNDO, actions).set_enabled (!focused);
Utils.action_from_group (ACTION_REDO, actions).set_enabled (!focused);

//<Control>u
Utils.action_from_group (ACTION_TO_UPPER_CASE, actions).set_enabled (!focused);

//<Control>k +- shift
Utils.action_from_group (ACTION_DUPLICATE_TAB, actions).set_enabled (!focused);
Utils.action_from_group (ACTION_CLEAR_LINES, actions).set_enabled (!focused);

//<Control>l
Utils.action_from_group (ACTION_TO_LOWER_CASE, actions).set_enabled (!focused);
return false;
}

// Get current document
public Scratch.Services.Document? get_current_document () {
return document_view.current_document;
Expand Down Expand Up @@ -1292,6 +1316,10 @@ namespace Scratch {
}

private void action_show_replace (SimpleAction action) {
if (terminal.terminal.has_focus) {
return;
}

find ();
// May have to wait for the search bar to be revealed before we can grab focus

Expand Down