mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Add copy/move to drag onto user category
2) Have manage categories create empty categories for all intermediate nodes in a category tree
This commit is contained in:
parent
3a29e61660
commit
725634062b
@ -232,6 +232,12 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.save_category()
|
self.save_category()
|
||||||
|
for cat in sorted(self.categories.keys(), key=sort_key):
|
||||||
|
components = cat.split('.')
|
||||||
|
for i in range(0,len(components)):
|
||||||
|
c = '.'.join(components[0:i+1])
|
||||||
|
if c not in self.categories:
|
||||||
|
self.categories[c] = []
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
||||||
def save_category(self):
|
def save_category(self):
|
||||||
|
@ -403,21 +403,27 @@ class TagsView(QTreeView): # {{{
|
|||||||
flags = self._model.flags(index)
|
flags = self._model.flags(index)
|
||||||
if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
|
if item.type == TagTreeItem.TAG and flags & Qt.ItemIsDropEnabled:
|
||||||
self.setDropIndicatorShown(not src_is_tb)
|
self.setDropIndicatorShown(not src_is_tb)
|
||||||
else:
|
return
|
||||||
if item.type == TagTreeItem.CATEGORY:
|
if item.type == TagTreeItem.CATEGORY:
|
||||||
fm_dest = self.db.metadata_for_field(item.category_key)
|
fm_dest = self.db.metadata_for_field(item.category_key)
|
||||||
if fm_dest['kind'] == 'user':
|
if fm_dest['kind'] == 'user':
|
||||||
if src_is_tb:
|
if src_is_tb:
|
||||||
|
if event.dropAction() == Qt.MoveAction:
|
||||||
|
data = str(event.mimeData().data('application/calibre+from_tag_browser'))
|
||||||
|
src = cPickle.loads(data)
|
||||||
|
for s in src:
|
||||||
|
if s[0] == TagTreeItem.TAG and not s[1].startswith('@'):
|
||||||
|
return
|
||||||
|
self.setDropIndicatorShown(True)
|
||||||
|
return
|
||||||
|
md = event.mimeData()
|
||||||
|
if hasattr(md, 'column_name'):
|
||||||
|
fm_src = self.db.metadata_for_field(md.column_name)
|
||||||
|
if md.column_name in ['authors', 'publisher', 'series'] or \
|
||||||
|
(fm_src['is_custom'] and
|
||||||
|
fm_src['datatype'] in ['series', 'text'] and
|
||||||
|
not fm_src['is_multiple']):
|
||||||
self.setDropIndicatorShown(True)
|
self.setDropIndicatorShown(True)
|
||||||
return
|
|
||||||
md = event.mimeData()
|
|
||||||
if hasattr(md, 'column_name'):
|
|
||||||
fm_src = self.db.metadata_for_field(md.column_name)
|
|
||||||
if md.column_name in ['authors', 'publisher', 'series'] or \
|
|
||||||
(fm_src['is_custom'] and
|
|
||||||
fm_src['datatype'] in ['series', 'text'] and
|
|
||||||
not fm_src['is_multiple']):
|
|
||||||
self.setDropIndicatorShown(True)
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
if self.model():
|
if self.model():
|
||||||
@ -698,10 +704,11 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
|
|
||||||
def dropMimeData(self, md, action, row, column, parent):
|
def dropMimeData(self, md, action, row, column, parent):
|
||||||
fmts = set([unicode(x) for x in md.formats()])
|
fmts = set([unicode(x) for x in md.formats()])
|
||||||
if not fmts.intersection(set(self.mimeTypes())) or \
|
if not fmts.intersection(set(self.mimeTypes())):
|
||||||
action != Qt.CopyAction:
|
|
||||||
return False
|
return False
|
||||||
if "application/calibre+from_library" in fmts:
|
if "application/calibre+from_library" in fmts:
|
||||||
|
if action != Qt.CopyAction:
|
||||||
|
return False
|
||||||
return self.do_drop_from_library(md, action, row, column, parent)
|
return self.do_drop_from_library(md, action, row, column, parent)
|
||||||
elif 'application/calibre+from_tag_browser' in fmts:
|
elif 'application/calibre+from_tag_browser' in fmts:
|
||||||
return self.do_drop_from_tag_browser(md, action, row, column, parent)
|
return self.do_drop_from_tag_browser(md, action, row, column, parent)
|
||||||
@ -727,8 +734,8 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if dest_key not in user_cats:
|
if dest_key not in user_cats:
|
||||||
continue
|
continue
|
||||||
new_cat = []
|
new_cat = []
|
||||||
# delete the item if the source is a user category
|
# delete the item if the source is a user category and action is move
|
||||||
if src_parent in user_cats:
|
if src_parent in user_cats and action == Qt.MoveAction:
|
||||||
for tup in user_cats[src_parent]:
|
for tup in user_cats[src_parent]:
|
||||||
if src_name == tup[0] and src_cat == tup[1]:
|
if src_name == tup[0] and src_cat == tup[1]:
|
||||||
continue
|
continue
|
||||||
@ -742,9 +749,13 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if add_it:
|
if add_it:
|
||||||
user_cats[dest_key].append([src_name, src_cat, 0])
|
user_cats[dest_key].append([src_name, src_cat, 0])
|
||||||
self.db.prefs.set('user_categories', user_cats)
|
self.db.prefs.set('user_categories', user_cats)
|
||||||
path = self.path_for_index(parent)
|
|
||||||
self.tags_view.set_new_model()
|
self.tags_view.set_new_model()
|
||||||
self.tags_view.model().show_item_at_path(path)
|
# Must work with the new model here
|
||||||
|
m = self.tags_view.model()
|
||||||
|
path = m.find_category_node('@' + src_parent)
|
||||||
|
idx = m.index_for_path(path)
|
||||||
|
self.tags_view.setExpanded(idx, True)
|
||||||
|
m.show_item_at_index(idx)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def do_drop_from_library(self, md, action, row, column, parent):
|
def do_drop_from_library(self, md, action, row, column, parent):
|
||||||
@ -1175,7 +1186,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def supportedDropActions(self):
|
def supportedDropActions(self):
|
||||||
return Qt.CopyAction
|
return Qt.CopyAction|Qt.MoveAction
|
||||||
|
|
||||||
def path_for_index(self, index):
|
def path_for_index(self, index):
|
||||||
ans = []
|
ans = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user