diff --git a/src/Services/Document.vala b/src/Services/Document.vala index 7ac1b5100..945dbaf6a 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -256,24 +256,16 @@ namespace Scratch.Services { this.source_view.buffer.create_tag ("highlight_search_all", "background", "yellow", null); - // Focus in event for SourceView - // Check if file changed externally or permissions changed - this.source_view.focus_in_event.connect (() => { - if (!locked && !is_file_temporary) { - check_undoable_actions (); - check_file_status.begin (); - } - - return false; - }); - - // Focus out event for SourceView - this.source_view.focus_out_event.connect (() => { - if (!locked && Scratch.settings.get_boolean ("autosave")) { - save_with_hold.begin (); + this.source_view.notify["is-focus"].connect (() => { + return_if_fail (!locked); + if (source_view.is_focus) { + if (!is_file_temporary) { + check_undoable_actions (); + check_file_status.begin (); + } + } else if (Scratch.settings.get_boolean ("autosave")) { + save_with_hold.begin (); } - - return false; }); source_view.buffer.changed.connect (() => { diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 8fb50588d..22bd89dc2 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -227,7 +227,15 @@ namespace Scratch.Widgets { // Connecting to some signals search_entry.changed.connect (on_search_parameters_changed); search_entry.key_press_event.connect (on_search_entry_key_press); - search_entry.focus_in_event.connect (on_search_entry_focused_in); + search_entry.notify["is-focus"].connect (() => { + if (search_entry.is_focus && text_buffer != null) { + Idle.add (() => { + update_search_widgets (); + search_entry.select_region (0, -1); + return Source.REMOVE; + }); + } + }); search_entry.icon_release.connect ((p0, p1) => { if (p0 == Gtk.EntryIconPosition.PRIMARY) { search_next (); @@ -359,20 +367,6 @@ namespace Scratch.Widgets { update_search_widgets (); } - private bool on_search_entry_focused_in (Gdk.EventFocus event) { - if (text_buffer == null) { - return false; - } - - Idle.add (() => { - update_search_widgets (); - search_entry.select_region (0, -1); - return Source.REMOVE; - }); - - return Gdk.EVENT_PROPAGATE; - } - public bool search () { search_entry.grab_focus (); if (search_context == null) {