tweak hook names

This commit is contained in:
Damien Elmes 2021-03-18 10:54:02 +10:00
parent de668441b5
commit 846e7cd4aa
3 changed files with 25 additions and 25 deletions

View File

@ -514,12 +514,12 @@ class Browser(QMainWindow):
gui_hooks.browser_will_show(self)
self.show()
def on_operations_will_execute(self) -> None:
def on_backend_will_block(self) -> None:
# make sure the card list doesn't try to refresh itself during the operation,
# as that will block the UI
self.model.block_updates = True
def on_operations_did_execute(self) -> None:
def on_backend_did_block(self) -> None:
self.model.block_updates = False
def on_operation_did_execute(self, changes: OpChanges) -> None:
@ -1424,8 +1424,8 @@ where id in %s"""
# fixme: remove these once all items are using `operation_did_execute`
gui_hooks.sidebar_should_refresh_decks.append(self.on_item_added)
gui_hooks.sidebar_should_refresh_notetypes.append(self.on_item_added)
gui_hooks.operations_will_execute.append(self.on_operations_will_execute)
gui_hooks.operations_did_execute.append(self.on_operations_did_execute)
gui_hooks.backend_will_block.append(self.on_backend_will_block)
gui_hooks.backend_did_block.append(self.on_backend_did_block)
gui_hooks.operation_did_execute.append(self.on_operation_did_execute)
gui_hooks.focus_did_change.append(self.on_focus_change)
@ -1433,8 +1433,8 @@ where id in %s"""
gui_hooks.undo_state_did_change.remove(self.onUndoState)
gui_hooks.sidebar_should_refresh_decks.remove(self.on_item_added)
gui_hooks.sidebar_should_refresh_notetypes.remove(self.on_item_added)
gui_hooks.operations_will_execute.remove(self.on_operations_will_execute)
gui_hooks.operations_did_execute.remove(self.on_operations_will_execute)
gui_hooks.backend_will_block.remove(self.on_backend_will_block)
gui_hooks.backend_did_block.remove(self.on_backend_will_block)
gui_hooks.operation_did_execute.remove(self.on_operation_did_execute)
gui_hooks.focus_did_change.remove(self.on_focus_change)

View File

@ -823,13 +823,13 @@ class AnkiQt(QMainWindow):
def _increase_background_ops(self) -> None:
if not self._background_op_count:
gui_hooks.operations_will_execute()
gui_hooks.backend_will_block()
self._background_op_count += 1
def _decrease_background_ops(self) -> None:
self._background_op_count -= 1
if not self._background_op_count:
gui_hooks.operations_did_execute()
gui_hooks.backend_did_block()
assert self._background_op_count >= 0
def _fire_change_hooks_after_op_performed(

View File

@ -399,21 +399,6 @@ hooks = [
New code should use `operation_did_execute` instead.
""",
),
Hook(
name="operations_will_execute",
doc="""Called before one or more operations are executed with mw.perform_op().
Subscribers can use this to set a flag to avoid DB updates until the operation
completes, as doing so will freeze the UI.
""",
),
Hook(
name="operations_did_execute",
doc="""Called after one or more operations are executed with mw.perform_op().
Called regardless of the success of individual operations, and only called when
there are no outstanding ops.
""",
),
Hook(
name="operation_did_execute",
args=[
@ -422,8 +407,7 @@ hooks = [
doc="""Called after an operation completes.
Changes can be inspected to determine whether the UI needs updating.
This will also be called when the legacy mw.reset() is used. When called via
mw.reset(), `operation_will_execute` will not be called.
This will also be called when the legacy mw.reset() is used.
""",
),
Hook(
@ -435,6 +419,22 @@ hooks = [
doc="""Called each time the focus changes. Can be used to defer updates from
`operation_did_execute` until a window is brought to the front.""",
),
Hook(
name="backend_will_block",
doc="""Called before one or more operations are executed with mw.perform_op().
Subscribers can use this to set a flag to avoid DB queries until the operation
completes, as doing so will freeze the UI until the long-running operation
completes.
""",
),
Hook(
name="backend_did_block",
doc="""Called after one or more operations are executed with mw.perform_op().
Called regardless of the success of individual operations, and only called when
there are no outstanding ops.
""",
),
# Webview
###################
Hook(