Fix search view not hiding after hitting ESC

The SearchView did not always hide after hitting ESC while typing
 into the SearchBar.
The problem in general arises because the duty of toggling the search
 view was scattered in multiple files (listed below). Centralizing
 the logic into one appropriate place, makes the switching management
 easier and also fixes the core problem.

The details of the problem can be described using a search scenerio
 as below:

1. The user starts typing into the searchbar.
2. The view switches to the search view upon typing the first searchable
 character.
3. The logic to set the previous view of the search view is not going
 to be kicked until the search engine actually starts the query and
 the search view begins adding found items.
4. The engine has queried the db.At this point, the user hits ESC,
 and the _search.props.search_mode_active becomes false in Window.py.
5. That in turn calls SearchView.search_mode_active.setter which sets
 search_state to None. Again this activates the
 Window._on_search_state_changed handler that makes the switch to the
 previous view.
6. Now, because the search is in progress in the background,
 the search_state and the previous_view are being set constantly which,
 the former keeps triggering the Window._on_search_state_changed handler
 and the latter is now set to the new previous view (search view). So
 the view returns back to the search view.
7. Other than that, SearchBar.py keeps switching to the search view as
 long as the timer is active.

To fix the problem, take the responsibility to switch the search view out
 of those areas and place them into the Window.py which has the knowledge
 of the state of the search and related views and as the main container
 also has the resonsibility to decide what views should be shown and when.

This fix does not deal with the issue of ongoing background search.

The following changes were made as part of the fix:

-Changes in Window.py:

Modifty the private function Window.on_search_state_changed()
 such that it takes the responsibility of switching the views after
 the search state changes.

Add a listener function to Window called _on_search_mode_active_changed
 that takes the responsibility of disabling and enabling
 the search view and switching to the previous view by holding the
 previous view in a new field: view_before_search.

Modify the Window._on_key_press() function such that
 upon entering search characters or pressing ESC, the
 search.props.search_mode_active is toggled.

-Changes in SearchBar.py:

Remove the search view switching logic from
 SearchBar._search_state_changed() so that only the Window object is
 concerned with it.

-Changes in SearchView.py:

Remove the block of code from the SearchView._add_item() function that
 deals with setting the previous_view field. The field is set by the
 Window object instead.
 To prevent a loop that can be caused by setting
 the search_mode_active property, add a check to the same setter to
 prevent unnecessarily setting the search_state property.

Remove prev_view field, because it is no longer needed.

Closes: #141
4 jobs for master in 10 minutes and 53 seconds (queued for 1 second)
latest
Status Job ID Name Coverage
  Check
passed #327111
flake8

00:01:18

 
  Build Flatpak
passed #327112
flatpak

00:09:04

 
  Deploy
passed #327113
review

00:00:30

manual #327114
allowed to fail manual
stop_review