This commit is contained in:
Damien Elmes 2014-08-22 22:06:13 +09:00
commit 591015417b
9 changed files with 53 additions and 16 deletions

View File

@ -233,6 +233,11 @@ class DeckManager(object):
raise DeckRenameError(_("That deck already exists.")) raise DeckRenameError(_("That deck already exists."))
# ensure we have parents # ensure we have parents
newName = self._ensureParents(newName) newName = self._ensureParents(newName)
# make sure we're not nesting under a filtered deck
if '::' in newName:
newParent = '::'.join(newName.split('::')[:-1])
if self.byName(newParent)['dyn']:
raise DeckRenameError(_("A filtered deck cannot have subdecks."))
# rename children # rename children
for grp in self.all(): for grp in self.all():
if grp['name'].startswith(g['name'] + "::"): if grp['name'].startswith(g['name'] + "::"):
@ -266,8 +271,6 @@ class DeckManager(object):
or self._isParent(ontoDeckName, draggedDeckName) \ or self._isParent(ontoDeckName, draggedDeckName) \
or self._isAncestor(draggedDeckName, ontoDeckName): or self._isAncestor(draggedDeckName, ontoDeckName):
return False return False
elif self.byName(ontoDeckName)['dyn']:
raise DeckRenameError(_("A filtered deck cannot have subdecks."))
else: else:
return True return True

View File

@ -304,10 +304,10 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
def renameField(self, m, field, newName): def renameField(self, m, field, newName):
self.col.modSchema() self.col.modSchema()
pat = r'{{([:#^/]|[^:#/^}][^:}]*?:|)%s}}' pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
def wrap(txt): def wrap(txt):
def repl(match): def repl(match):
return '{{' + match.group(1) + txt + '}}' return '{{' + match.group(1) + match.group(2) + txt + '}}'
return repl return repl
for t in m['tmpls']: for t in m['tmpls']:
for fmt in ('qfmt', 'afmt'): for fmt in ('qfmt', 'afmt'):

View File

@ -109,7 +109,7 @@ class TagManager(object):
def split(self, tags): def split(self, tags):
"Parse a string and return a list of tags." "Parse a string and return a list of tags."
return [t for t in tags.split(" ") if t] return [t for t in tags.replace(u'\u3000', ' ').split(" ") if t]
def join(self, tags): def join(self, tags):
"Join tags into a single string, with leading and trailing spaces." "Join tags into a single string, with leading and trailing spaces."

View File

@ -28,7 +28,7 @@ system. It's free and open source.")
"</span>" "</span>"
abouttext += '<p>' + _("Written by Damien Elmes, with patches, translation,\ abouttext += '<p>' + _("Written by Damien Elmes, with patches, translation,\
testing and design from:<p>%(cont)s") % {'cont': u"""Aaron Harsh, Ádám Szegi, testing and design from:<p>%(cont)s") % {'cont': u"""Aaron Harsh, Ádám Szegi,
Alex Fraser, Andreas Klauer, Andrew Wright, Bernhard Ibertsberger, Charlene Barina, Alex Fraser, Andreas Klauer, Andrew Wright, Bernhard Ibertsberger, C. van Rooyen, Charlene Barina,
Christian Krause, Christian Rusche, David Smith, Dave Druelinger, Dotan Cohen, Christian Krause, Christian Rusche, David Smith, Dave Druelinger, Dotan Cohen,
Emilio Wuerges, Emmanuel Jarri, Frank Harper, Gregor Skumavc, H. Mijail, Emilio Wuerges, Emmanuel Jarri, Frank Harper, Gregor Skumavc, H. Mijail,
Houssam Salem, Ian Lewis, Immanuel Asmus, Iroiro, Jarvik7, Houssam Salem, Ian Lewis, Immanuel Asmus, Iroiro, Jarvik7,

View File

@ -1109,12 +1109,26 @@ where id in %s""" % ids2str(sf))
return return
self.mw.checkpoint(_("Delete Notes")) self.mw.checkpoint(_("Delete Notes"))
self.model.beginReset() self.model.beginReset()
oldRow = self.form.tableView.selectionModel().currentIndex().row() # figure out where to place the cursor after the deletion
curRow = self.form.tableView.selectionModel().currentIndex().row()
selectedRows = [i.row() for i in
self.form.tableView.selectionModel().selectedRows()]
if min(selectedRows) < curRow < max(selectedRows):
# last selection in middle; place one below last selected item
move = sum(1 for i in selectedRows if i > curRow)
newRow = curRow - move
elif max(selectedRows) <= curRow:
# last selection at bottom; place one below bottommost selection
newRow = max(selectedRows) - len(nids) + 1
else:
# last selection at top; place one above topmost selection
newRow = min(selectedRows) - 1
self.col.remNotes(nids) self.col.remNotes(nids)
self.onSearch(reset=False) self.onSearch(reset=False)
if len(self.model.cards): if len(self.model.cards):
new = min(oldRow, len(self.model.cards) - 1) newRow = min(newRow, len(self.model.cards) - 1)
self.model.focusedCard = self.model.cards[new] newRow = max(newRow, 0)
self.model.focusedCard = self.model.cards[newRow]
self.model.endReset() self.model.endReset()
self.mw.requireReset() self.mw.requireReset()
tooltip(_("%s deleted.") % (ngettext("%d note", "%d notes", len(nids)) % len(nids))) tooltip(_("%s deleted.") % (ngettext("%d note", "%d notes", len(nids)) % len(nids)))

View File

@ -204,6 +204,12 @@ Please create a new card type first."""))
self.tab['tform'].front.setPlainText(t['qfmt']) self.tab['tform'].front.setPlainText(t['qfmt'])
self.tab['tform'].css.setPlainText(self.model['css']) self.tab['tform'].css.setPlainText(self.model['css'])
self.tab['tform'].back.setPlainText(t['afmt']) self.tab['tform'].back.setPlainText(t['afmt'])
self.tab['tform'].front.setAcceptRichText(False)
self.tab['tform'].css.setAcceptRichText(False)
self.tab['tform'].back.setAcceptRichText(False)
self.tab['tform'].front.setTabStopWidth(30)
self.tab['tform'].css.setTabStopWidth(30)
self.tab['tform'].back.setTabStopWidth(30)
self.redrawing = False self.redrawing = False
def saveCard(self): def saveCard(self):

View File

@ -64,13 +64,20 @@ class ExportDialog(QDialog):
self.exporter.did): self.exporter.did):
verbatim = True verbatim = True
# it's a verbatim apkg export, so place on desktop instead of # it's a verbatim apkg export, so place on desktop instead of
# choosing file # choosing file; use homedir if no desktop
usingHomedir = False
file = os.path.join(QDesktopServices.storageLocation( file = os.path.join(QDesktopServices.storageLocation(
QDesktopServices.DesktopLocation), "collection.apkg") QDesktopServices.DesktopLocation), "collection.apkg")
if not os.path.exists(os.path.dirname(file)):
usingHomedir = True
file = os.path.join(QDesktopServices.storageLocation(
QDesktopServices.HomeLocation), "collection.apkg")
if os.path.exists(file): if os.path.exists(file):
if not askUser( if usingHomedir:
_("%s already exists on your desktop. Overwrite it?")% question = _("%s already exists in your home directory. Overwrite it?")
"collection.apkg"): else:
question = _("%s already exists on your desktop. Overwrite it?")
if not askUser(question % "collection.apkg"):
return return
else: else:
verbatim = False verbatim = False
@ -100,7 +107,11 @@ class ExportDialog(QDialog):
os.unlink(file) os.unlink(file)
self.exporter.exportInto(file) self.exporter.exportInto(file)
if verbatim: if verbatim:
msg = _("A file called collection.apkg was saved on your desktop.") if usingHomedir:
msg = _("A file called %s was saved in your home directory.")
else:
msg = _("A file called %s was saved on your desktop.")
msg = msg % "collection.apkg"
period = 5000 period = 5000
else: else:
period = 3000 period = 3000

View File

@ -34,7 +34,7 @@ class ChangeMap(QDialog):
self.frm.fields.setCurrentRow(n) self.frm.fields.setCurrentRow(n)
n += 1 n += 1
self.frm.fields.addItem(QListWidgetItem(_("Map to Tags"))) self.frm.fields.addItem(QListWidgetItem(_("Map to Tags")))
self.frm.fields.addItem(QListWidgetItem(_("Discard field"))) self.frm.fields.addItem(QListWidgetItem(_("Ignore field")))
if not setCurrent: if not setCurrent:
if current == "_tags": if current == "_tags":
self.frm.fields.setCurrentRow(n) self.frm.fields.setCurrentRow(n)

View File

@ -46,7 +46,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>412</width> <width>412</width>
<height>22</height> <height>27</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuHelp"> <widget class="QMenu" name="menuHelp">
@ -237,6 +237,9 @@
<property name="text"> <property name="text">
<string>Manage Note Types...</string> <string>Manage Note Types...</string>
</property> </property>
<property name="shortcut">
<string>Ctrl+Shift+N</string>
</property>
</action> </action>
</widget> </widget>
<resources> <resources>