Skip to content

Commit

Permalink
Better selection with invisibleRootItem
Browse files Browse the repository at this point in the history
  • Loading branch information
bordaigorl committed Mar 23, 2021
1 parent a549c9e commit 9c5d689
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions remy/gui/filebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __lt__(self, other):

class DocTree(QTreeWidget):

contextMenu = pyqtSignal(object,QContextMenuEvent)
contextMenu = pyqtSignal(QTreeWidgetItem,QContextMenuEvent)

def __init__(self, index, *a, uid=None, show_trash=True, **kw):
super(DocTree, self).__init__(*a, **kw)
Expand Down Expand Up @@ -328,7 +328,7 @@ def __init__(self, index, *a, uid=None, show_trash=True, **kw):
if uid is None:
uid = index.root().uid
self._rootEntry = index.get(uid)
p = nodes[uid] = self
p = nodes[uid] = self.invisibleRootItem()
for f in index.scanFolders(uid):
p = nodes[f.uid]
for d in f.files:
Expand Down Expand Up @@ -363,23 +363,16 @@ def mouseReleaseEvent(self, event):
i = self.indexAt(event.pos())
QTreeView.mouseReleaseEvent(self, event)
if not i.isValid():
# self.clearSelection()
self.setCurrentItem(None)
# self.selectionCleared.emit()
self.setCurrentItem(self.invisibleRootItem())

def contextMenuEvent(self, event):
i = self.indexAt(event.pos())
if i.isValid():
item = self.itemFromIndex(i)
self.setCurrentItem(item)
self.contextMenu.emit(item, event)
else:
# self.clearSelection()
self.setCurrentItem(None)
# self.selectionCleared.emit()
self.contextMenu.emit(None, event)

# TODO: doctree.index, emit root if no item, store item on event and fetch it when triggering actions
item = self.invisibleRootItem()
self.setCurrentItem(item)
self.contextMenu.emit(item, event)

def indexUpdated(self, success, action, entries, index, extra):
if success:
Expand Down Expand Up @@ -470,8 +463,9 @@ def __init__(self, index, *args, **kwargs):
if not index.isReadOnly():
self.folderMenu.addAction(self.importAction)

self.tree.setCurrentItem(None)
self.entrySelected(None,None)
rootitem = self.tree.invisibleRootItem()
self.tree.setCurrentItem(rootitem)
self.entrySelected(rootitem,rootitem)

@pyqtSlot(str, list,list)
def _import(self, p, dirs, files):
Expand All @@ -497,7 +491,7 @@ def entrySelected(self, cur, prev):
self.info.setEntry(entry)


@pyqtSlot(object,QContextMenuEvent)
@pyqtSlot(QTreeWidgetItem,QContextMenuEvent)
def contextMenu(self, item, event):
entry = self.tree.currentEntry()
if isinstance(entry, Folder):
Expand Down

0 comments on commit 9c5d689

Please sign in to comment.