Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sidebar modes for different click behaviour #1044

Merged
merged 59 commits into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9d3da3b
Add icons for sidebar tools
RumovZ Feb 25, 2021
17afcb0
Add toolbar to sidebar
RumovZ Feb 25, 2021
fd784ad
Add select and search modes to sidebar
RumovZ Feb 25, 2021
0889972
Save last sidebar tool
RumovZ Feb 25, 2021
4a1e995
Add edit mode in sidebar
RumovZ Feb 25, 2021
47e1e62
Make search first (default) mode
RumovZ Feb 25, 2021
1721332
Handle search on event level
RumovZ Feb 25, 2021
f5981e9
Add group search context action
RumovZ Feb 25, 2021
2c25645
Place sidebar tools right of search bar
RumovZ Feb 26, 2021
f7c20e4
Make backend deck deletion take vec of ids
RumovZ Feb 26, 2021
88c6966
Add support for multi deck deletion in python
RumovZ Feb 26, 2021
0b83828
Enable in-place editing of sidebar deck items
RumovZ Feb 28, 2021
d0b916a
Enable in-place editing of saved searches
RumovZ Feb 28, 2021
1b8cebb
Enable in-place editing of sidebar tags
RumovZ Feb 28, 2021
dc1711b
Always return False from rename_node
RumovZ Feb 28, 2021
e83f0fe
Fix Qt types
RumovZ Feb 28, 2021
30e7d70
Enable extended selection in edit mode
RumovZ Mar 1, 2021
e199bf0
Fix repainting when renaming tag via dialogue
RumovZ Mar 1, 2021
f4aeb0c
Enable deleting multiple saved searches
RumovZ Mar 1, 2021
25d5757
Enable removal of multiple tags from the sidebar
RumovZ Mar 2, 2021
adaea72
Select and scroll to renamed/added sidebar item
RumovZ Mar 2, 2021
c0d7789
Add DECK_CURRENT as a SidebarItemType
RumovZ Mar 3, 2021
e2940de
Escape backslashes in re.sub()'s repl
RumovZ Mar 3, 2021
61e6137
Make SidebarItem._is_extended a property
RumovZ Mar 3, 2021
65a2796
Enable group expanding/collapsing
RumovZ Mar 3, 2021
aa4576d
Enable renaming notetypes
RumovZ Mar 3, 2021
bcc8a5a
Enable renaming templates from the sidebar
RumovZ Mar 3, 2021
7d3d6ed
Remove renaming dialogues from sidebar ...
RumovZ Mar 3, 2021
5c6eea0
Make renamed item current (don't just select)
RumovZ Mar 3, 2021
6930ea2
Adjust sidebar tool icons to smaller size
RumovZ Mar 4, 2021
4ab9e6c
Ask for confirmation when overwriting saved search
RumovZ Mar 4, 2021
1f500c1
Enable Enter/Return search in all modes ...
RumovZ Mar 4, 2021
513e7bd
Enable deleting via delete key
RumovZ Mar 4, 2021
39dad04
Fix children check in context tree actions
RumovZ Mar 5, 2021
cce1b1f
Remove context action dict
RumovZ Mar 5, 2021
23777ee
Fix repainting in case of tree building exception
RumovZ Mar 7, 2021
f72daac
Only show edit actions with conform selection
RumovZ Mar 7, 2021
6c4d645
Simplify multi deletion confirmation strings
RumovZ Mar 7, 2021
f07890c
Ask before removing tags from collection
RumovZ Mar 7, 2021
8d90721
Enable drag for all sidebar items ...
RumovZ Mar 8, 2021
08c09bc
Remove edit mode
RumovZ Mar 8, 2021
28402c7
Improve toolbar styling for macOS
RumovZ Mar 9, 2021
3f772ce
Add shortcuts for sidebar tools
RumovZ Mar 9, 2021
a9ea7e3
Disable expand on double click in search mode
RumovZ Mar 9, 2021
9a84459
Ensure mouse is at current index before searching
RumovZ Mar 9, 2021
ffbb0b7
Disable renaming models and templates ...
RumovZ Mar 10, 2021
0c2ac4b
Merge branch 'master' into sidebar-tools
RumovZ Mar 10, 2021
602ffa6
Update about screen
RumovZ Mar 10, 2021
e1db8e1
Borrow dids in remove_decks_and_child_decks
RumovZ Mar 10, 2021
bc7043c
Store name prefix of sidebar items
RumovZ Mar 10, 2021
8e9331e
Fix repainting in case of tag renaming exception
RumovZ Mar 10, 2021
186a020
Show tooltip instead of prompt for removing tags
RumovZ Mar 11, 2021
337ef0a
Show count of affected notes after tag renaming
RumovZ Mar 11, 2021
3219bb2
Remove prompt when deleting saved searches
RumovZ Mar 11, 2021
f1dd010
Remove deck remove prompt but show card count
RumovZ Mar 11, 2021
5d93832
Run background tasks with progress
RumovZ Mar 11, 2021
c11a394
Remove prompt when deleting from deckbrowser
RumovZ Mar 11, 2021
dad92e1
Annotate decks.rem as deprecated
RumovZ Mar 11, 2021
f4c2fe6
Merge branch 'master' into sidebar-tools
RumovZ Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions ftl/core/actions.ftl
@@ -1,4 +1,6 @@
actions-add = Add
actions-all-selected = All selected
actions-any-selected = Any selected
actions-blue-flag = Blue Flag
actions-cancel = Cancel
actions-choose = Choose
Expand Down Expand Up @@ -30,6 +32,7 @@ actions-replay-audio = Replay Audio
actions-reposition = Reposition
actions-save = Save
actions-search = Search
actions-select = Select
actions-shortcut-key = Shortcut key: { $val }
actions-suspend-card = Suspend Card
actions-set-due-date = Set Due Date
Expand Down
16 changes: 13 additions & 3 deletions ftl/core/browsing.ftl
Expand Up @@ -14,13 +14,19 @@ browsing-card = Card
browsing-card-list = Card List
browsing-card-state = Card State
browsing-cards-cant-be-manually-moved-into = Cards can't be manually moved into a filtered deck.
browsing-cards-deleted =
{ $count ->
[one] { $count } card deleted.
*[other] { $count } cards deleted.
}
browsing-change-deck = Change Deck
browsing-change-deck2 = Change Deck...
browsing-change-note-type = Change Note Type
browsing-change-note-type2 = Change Note Type...
browsing-change-to = Change { $val } to:
browsing-clear-unused = Clear Unused
browsing-clear-unused-tags = Clear Unused Tags
browsing-confirm-saved-search-overwrite = A saved search with the name { $name } already exists. Do you want to overwrite it?
browsing-created = Created
browsing-ctrlandshiftande = Ctrl+Shift+E
browsing-current-deck = Current Deck
Expand Down Expand Up @@ -70,14 +76,11 @@ browsing-question = Question
browsing-queue-bottom = Queue bottom: { $val }
browsing-queue-top = Queue top: { $val }
browsing-randomize-order = Randomize order
browsing-remove-current-filter = Remove Current Filter...
browsing-remove-from-your-saved-searches = Remove { $val } from your saved searches?
browsing-remove-tags = Remove Tags...
browsing-replace-with = <b>Replace With</b>:
browsing-reposition = Reposition...
browsing-reposition-new-cards = Reposition New Cards
browsing-reschedule = Reschedule
browsing-save-current-filter = Save Current Filter...
RumovZ marked this conversation as resolved.
Show resolved Hide resolved
browsing-search-bar-hint = Search cards/notes (type text, then press Enter)
browsing-search-in = Search in:
browsing-search-within-formatting-slow = Search within formatting (slow)
Expand Down Expand Up @@ -112,7 +115,14 @@ browsing-note-deleted =
[one] { $count } note deleted.
*[other] { $count } notes deleted.
}
browsing-notes-updated =
{ $count ->
[one] { $count } note updated.
*[other] { $count } notes updated.
}
browsing-window-title = Browse ({ $selected } of { $total } cards selected)
browsing-sidebar-expand = Expand
browsing-sidebar-collapse = Collapse
browsing-sidebar-expand-children = Expand Children
browsing-sidebar-collapse-children = Collapse Children
browsing-sidebar-decks = Decks
Expand Down
6 changes: 0 additions & 6 deletions ftl/core/decks.ftl
@@ -1,5 +1,4 @@
decks-add-new-deck-ctrlandn = Add New Deck (Ctrl+N)
decks-are-you-sure-you-wish-to = Are you sure you wish to delete { $val }?
decks-build = Build
decks-cards-selected-by = cards selected by
decks-create-deck = Create Deck
RumovZ marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -32,8 +31,3 @@ decks-study = Study
decks-study-deck = Study Deck
decks-the-provided-search-did-not-match = The provided search did not match any cards. Would you like to revise it?
decks-unmovable-cards = Show any excluded cards
decks-it-has-card =
{ $count ->
[one] It has { $count } card.
*[other] It has { $count } cards.
}
19 changes: 14 additions & 5 deletions pylib/anki/decks.py
Expand Up @@ -13,7 +13,7 @@
import anki._backend.backend_pb2 as _pb
from anki.consts import *
from anki.errors import NotFoundError
from anki.utils import from_json_bytes, ids2str, intTime, to_json_bytes
from anki.utils import from_json_bytes, ids2str, intTime, legacy_func, to_json_bytes

# public exports
DeckTreeNode = _pb.DeckTreeNode
Expand Down Expand Up @@ -130,12 +130,16 @@ def id(

return deck["id"]

@legacy_func(sub="remove")
def rem(self, did: int, cardsToo: bool = True, childrenToo: bool = True) -> None:
"Remove the deck. If cardsToo, delete any cards inside."
if isinstance(did, str):
did = int(did)
assert cardsToo and childrenToo
self.col._backend.remove_deck(did)
self.remove([did])

def remove(self, dids: List[int]) -> int:
return self.col._backend.remove_decks(dids)

def all_names_and_ids(
self, skip_empty_default: bool = False, include_filtered: bool = True
Expand Down Expand Up @@ -212,10 +216,15 @@ def collapseBrowser(self, did: int) -> None:
def count(self) -> int:
return len(self.all_names_and_ids())

def card_count(self, did: int, include_subdecks: bool) -> Any:
dids: List[int] = [did]
def card_count(
self, dids: Union[int, Iterable[int]], include_subdecks: bool
) -> Any:
if isinstance(dids, int):
dids = {dids}
else:
dids = set(dids)
if include_subdecks:
dids += [r[1] for r in self.children(did)]
dids.update([child[1] for did in dids for child in self.children(did)])
count = self.col.db.scalar(
"select count() from cards where did in {0} or "
"odid in {0}".format(ids2str(dids))
Expand Down
25 changes: 24 additions & 1 deletion pylib/anki/utils.py
Expand Up @@ -18,7 +18,7 @@
from contextlib import contextmanager
from hashlib import sha1
from html.entities import name2codepoint
from typing import Any, Iterable, Iterator, List, Match, Optional, Union
from typing import Any, Callable, Iterable, Iterator, List, Match, Optional, Union

from anki.dbproxy import DBProxy

Expand Down Expand Up @@ -372,3 +372,26 @@ def pointVersion() -> int:
from anki.buildinfo import version

return int(version.split(".")[-1])


# Legacy support
##############################################################################


def legacy_func(sub: Optional[str] = None) -> Callable:
"""Print a deprecation warning for the decorated callable recommending the use of
'sub' instead, if provided.
"""
if sub:
hint = f", use '{sub}' instead"
else:
hint = ""

def decorater(func: Callable) -> Callable:
def decorated_func(*args: Any, **kwargs: Any) -> Any:
print(f"'{func.__name__}' is deprecated{hint}.")
return func(*args, **kwargs)

return decorated_func

return decorater
1 change: 1 addition & 0 deletions qt/aqt/about.py
Expand Up @@ -205,6 +205,7 @@ def onCopy() -> None:
"Gustavo Costa",
"余时行",
"叶峻峣",
"RumovZ",
)
)

Expand Down
16 changes: 9 additions & 7 deletions qt/aqt/browser.py
Expand Up @@ -28,7 +28,7 @@
from aqt.previewer import Previewer
from aqt.qt import *
from aqt.scheduling import forget_cards, set_due_date_dialog
from aqt.sidebar import SidebarSearchBar, SidebarTreeView
from aqt.sidebar import SidebarSearchBar, SidebarToolbar, SidebarTreeView
from aqt.theme import theme_manager
from aqt.utils import (
TR,
Expand Down Expand Up @@ -941,18 +941,20 @@ def setupSidebar(self) -> None:
self.sidebar = SidebarTreeView(self)
self.sidebarTree = self.sidebar # legacy alias
dw.setWidget(self.sidebar)
self.sidebar.toolbar = toolbar = SidebarToolbar(self.sidebar)
self.sidebar.searchBar = searchBar = SidebarSearchBar(self.sidebar)
qconnect(
self.form.actionSidebarFilter.triggered,
self.focusSidebarSearchBar,
)
l = QVBoxLayout()
l.addWidget(searchBar)
l.addWidget(self.sidebar)
l.setContentsMargins(0, 0, 0, 0)
l.setSpacing(0)
grid = QGridLayout()
grid.addWidget(searchBar, 0, 0)
grid.addWidget(toolbar, 0, 1)
grid.addWidget(self.sidebar, 1, 0, 1, 2)
grid.setContentsMargins(0, 0, 0, 0)
grid.setSpacing(0)
w = QWidget()
w.setLayout(l)
w.setLayout(grid)
dw.setWidget(w)
self.sidebarDockWidget.setFloating(False)

Expand Down
33 changes: 8 additions & 25 deletions qt/aqt/deckbrowser.py
Expand Up @@ -23,6 +23,7 @@
shortcut,
showInfo,
showWarning,
tooltip,
tr,
)

Expand Down Expand Up @@ -303,34 +304,16 @@ def on_done(fut: Future) -> None:

self.mw.taskman.with_progress(process, on_done)

def ask_delete_deck(self, did: int) -> bool:
deck = self.mw.col.decks.get(did)
if deck["dyn"]:
return True

count = self.mw.col.decks.card_count(did, include_subdecks=True)
if not count:
return True

extra = tr(TR.DECKS_IT_HAS_CARD, count=count)
if askUser(
f"{tr(TR.DECKS_ARE_YOU_SURE_YOU_WISH_TO, val=deck['name'])} {extra}"
):
return True
return False

def _delete(self, did: int) -> None:
if self.ask_delete_deck(did):

def do_delete() -> None:
return self.mw.col.decks.rem(did, True)
def do_delete() -> int:
return self.mw.col.decks.remove([did])

def on_done(fut: Future) -> None:
self.mw.update_undo_actions()
self.show()
res = fut.result() # Required to check for errors
def on_done(fut: Future) -> None:
self.mw.update_undo_actions()
self.show()
tooltip(tr(TR.BROWSING_CARDS_DELETED, count=fut.result()))

self.mw.taskman.with_progress(do_delete, on_done)
self.mw.taskman.with_progress(do_delete, on_done)

# Top buttons
######################################################################
Expand Down
2 changes: 2 additions & 0 deletions qt/aqt/forms/icons.qrc
Expand Up @@ -10,5 +10,7 @@
<file>icons/clock.svg</file>
<file>icons/card-state.svg</file>
<file>icons/flag.svg</file>
<file>icons/select.svg</file>
<file>icons/magnifying_glass.svg</file>
</qresource>
</RCC>
84 changes: 84 additions & 0 deletions qt/aqt/forms/icons/magnifying_glass.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.