Close modals when using back/forward buttons in browser

This commit is contained in:
Kovid Goyal 2017-05-09 14:28:30 +05:30
parent 96f9365ca1
commit e61c047395
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 15 additions and 3 deletions

View File

@ -1,11 +1,12 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import hash_literals, bound_methods from __python__ import bound_methods, hash_literals
from book_list.constants import read_book_container_id, book_list_container_id from book_list.constants import book_list_container_id, read_book_container_id
from book_list.globals import get_current_query from book_list.globals import get_current_query
from book_list.library_data import current_library_id from book_list.library_data import current_library_id
from utils import parse_url_params, encode_query_with_path from modals import close_all_modals
from utils import encode_query_with_path, parse_url_params
mode_handlers = {} mode_handlers = {}
default_mode_handler = None default_mode_handler = None
@ -38,6 +39,7 @@ def apply_mode(mode):
def apply_url(ignore_handler): def apply_url(ignore_handler):
close_all_modals() # needed to close any error dialogs, etc when clicking back or forward in the browser or using push_state() to go to a new page
data = parse_url_params() data = parse_url_params()
data.mode = data.mode or 'book_list' data.mode = data.mode or 'book_list'
get_current_query(data) get_current_query(data)

View File

@ -125,6 +125,11 @@ class ModalContainer:
return return
self.clear_current_modal() self.clear_current_modal()
def close_all_modals(self):
while self.current_modal is not None:
self.close_current_modal()
def create_simple_dialog(title, msg, details, icon, prefix): def create_simple_dialog(title, msg, details, icon, prefix):
details = details or '' details = details or ''
def create_func(parent): def create_func(parent):
@ -223,6 +228,11 @@ def create_modal_container():
def show_modal(create_func, on_close=None, show_close=True): def show_modal(create_func, on_close=None, show_close=True):
return modal_container.show_modal(create_func, on_close, show_close) return modal_container.show_modal(create_func, on_close, show_close)
def close_all_modals():
return modal_container.close_all_modals()
def error_dialog(title, msg, details=None): def error_dialog(title, msg, details=None):
create_simple_dialog(title, msg, details, 'bug', _('Error:')) create_simple_dialog(title, msg, details, 'bug', _('Error:'))