mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 02:12:29 +12:00
Adds: merge
This commit is contained in:
parent
a153606811
commit
bb57d3d057
|
@ -358,3 +358,6 @@ def customIcons():
|
|||
]
|
||||
|
||||
return sorted(r)
|
||||
|
||||
def statusMessage(message, duration=5000):
|
||||
mainWindow().statusBar().showMessage(message, duration)
|
||||
|
|
|
@ -214,7 +214,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
We get notified by qApp when focus changes, from old to new widget.
|
||||
"""
|
||||
|
||||
# Determine which item had focus last, to send the keyboard shortcuts
|
||||
# Determine which view had focus last, to send the keyboard shortcuts
|
||||
# to the right place
|
||||
|
||||
targets = [
|
||||
|
@ -476,7 +476,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
if self._lastFocus and self._lastFocus == self.mainEditor:
|
||||
self.mainEditor.splitCursor()
|
||||
def documentsMerge(self):
|
||||
print("documentsMerge::FIXME")
|
||||
"Merges selected item(s)."
|
||||
if self._lastFocus: self._lastFocus.merge()
|
||||
|
||||
###############################################################################
|
||||
# LOAD AND SAVE
|
||||
|
|
|
@ -928,6 +928,23 @@ class outlineItem():
|
|||
# Inserting item using the model to signal views
|
||||
self._model.insertItem(item, self.row()+1, self.parent().index())
|
||||
|
||||
def mergeWith(self, items, sep="\n---\n"):
|
||||
"""
|
||||
Merges item with several other items. Merge is basic, it merges only
|
||||
the text.
|
||||
|
||||
@param items: list of `outlineItem`s.
|
||||
@param sep: a text added between each item's text.
|
||||
"""
|
||||
|
||||
# Merges the texts
|
||||
text = [self.text()]
|
||||
text.extend([i.text() for i in items])
|
||||
self.setData(Outline.text.value, sep.join(text))
|
||||
|
||||
# Removes other items
|
||||
self._model.removeIndexes([i.index() for i in items])
|
||||
|
||||
###############################################################################
|
||||
# XML
|
||||
###############################################################################
|
||||
|
|
|
@ -331,6 +331,12 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
|
|||
###############################################################################
|
||||
|
||||
def getCurrentItemView(self):
|
||||
"""
|
||||
Returns the current item view, between txtRedacText, outlineView and
|
||||
corkView. If folder/text view, returns None. (Because handled
|
||||
differently)
|
||||
"""
|
||||
|
||||
if self.stack.currentIndex() == 0:
|
||||
return self.txtRedacText
|
||||
elif self.folderView == "outline":
|
||||
|
@ -370,7 +376,7 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
|
|||
splitDialog(self, [self.currentIndex], mark=sel)
|
||||
|
||||
elif self.getCurrentItemView():
|
||||
# One of the view
|
||||
# One of the views
|
||||
self.getCurrentItemView().splitDialog()
|
||||
|
||||
def splitCursor(self):
|
||||
|
@ -395,5 +401,16 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
|
|||
|
||||
item.splitAt(pos, len(title))
|
||||
|
||||
def documentsMerge(self):
|
||||
print("documentsMerge::FIXME")
|
||||
def merge(self):
|
||||
"""
|
||||
Merges selected items together.
|
||||
|
||||
Call context: Multiple selection, same parent.
|
||||
"""
|
||||
if self.getCurrentItemView() == self.txtRedacText:
|
||||
# Text editor, nothing to merge
|
||||
pass
|
||||
|
||||
elif self.getCurrentItemView():
|
||||
# One of the views
|
||||
self.getCurrentItemView().merge()
|
||||
|
|
|
@ -257,8 +257,7 @@ class mainEditor(QWidget, Ui_mainEditor):
|
|||
def moveDown(self): self.currentEditor().moveDown()
|
||||
def splitDialog(self): self.currentEditor().splitDialog()
|
||||
def splitCursor(self): self.currentEditor().splitCursor()
|
||||
def documentsMerge(self):
|
||||
print("documentsMerge::FIXME")
|
||||
def merge(self): self.currentEditor().merge()
|
||||
|
||||
###############################################################################
|
||||
# UI
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
from PyQt5.QtWidgets import QInputDialog
|
||||
from manuskript.functions import mainWindow
|
||||
|
||||
|
||||
class splitDialog(QInputDialog):
|
||||
|
@ -38,7 +39,16 @@ class splitDialog(QInputDialog):
|
|||
|
||||
self.setLabelText(description)
|
||||
self.setTextValue(mark)
|
||||
self.setWindowTitle(self.tr("Split item(s)"))
|
||||
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
if len(indexes) == 1:
|
||||
idx = indexes[0]
|
||||
self.setWindowTitle(
|
||||
self.tr("Split '{}'").format(self.getItem(idx).title())
|
||||
)
|
||||
else:
|
||||
self.setWindowTitle(self.tr("Split items"))
|
||||
|
||||
r = self.exec()
|
||||
|
||||
|
@ -50,6 +60,11 @@ class splitDialog(QInputDialog):
|
|||
mark = mark.replace("\\t", "\t")
|
||||
|
||||
for idx in indexes:
|
||||
if idx.isValid():
|
||||
item = idx.internalPointer()
|
||||
item.split(mark)
|
||||
item = self.getItem(idx)
|
||||
item.split(mark)
|
||||
|
||||
def getItem(self, index):
|
||||
if index.isValid():
|
||||
return index.internalPointer()
|
||||
else:
|
||||
return mainWindow().mdlOutline.rootItem
|
||||
|
|
|
@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QAbstractItemView, qApp, QMenu, QAction, \
|
|||
|
||||
from manuskript import settings
|
||||
from manuskript.enums import Outline
|
||||
from manuskript.functions import mainWindow
|
||||
from manuskript.functions import mainWindow, statusMessage
|
||||
from manuskript.functions import toInt, customIcons
|
||||
from manuskript.models.outlineModel import outlineItem
|
||||
from manuskript.ui.tools.splitDialog import splitDialog
|
||||
|
@ -374,10 +374,44 @@ class outlineBasics(QAbstractItemView):
|
|||
|
||||
indexes = self.getSelection()
|
||||
if len(indexes) == 0:
|
||||
return
|
||||
# No selection, we use parent
|
||||
indexes = [self.rootIndex()]
|
||||
|
||||
splitDialog(self, indexes)
|
||||
|
||||
def merge(self):
|
||||
"""
|
||||
Merges selected items together.
|
||||
|
||||
Call context: Multiple selection, same parent.
|
||||
"""
|
||||
|
||||
# Get selection
|
||||
indexes = self.getSelection()
|
||||
# Get items
|
||||
items = [i.internalPointer() for i in indexes if i.isValid()]
|
||||
# Remove folders
|
||||
items = [i for i in items if not i.isFolder()]
|
||||
|
||||
# Check that we have at least 2 items
|
||||
if len(items) < 2:
|
||||
statusMessage(qApp.translate("outlineBasics",
|
||||
"Select at least two items. Folders are ignored."))
|
||||
return
|
||||
|
||||
# Check that all share the same parent
|
||||
p = items[0].parent()
|
||||
for i in items:
|
||||
if i.parent() != p:
|
||||
statusMessage(qApp.translate("outlineBasics",
|
||||
"All items must be on the same level (share the same parent)."))
|
||||
return
|
||||
|
||||
# Sort items by row
|
||||
items = sorted(items, key=lambda i: i.row())
|
||||
|
||||
items[0].mergeWith(items[1:])
|
||||
|
||||
def setPOV(self, POV):
|
||||
for i in self.getSelection():
|
||||
self.model().setData(i.sibling(i.row(), Outline.POV.value), str(POV))
|
||||
|
|
|
@ -141,6 +141,21 @@ class textEditView(QTextEdit):
|
|||
self.setPlainText("")
|
||||
self.setEnabled(False)
|
||||
|
||||
def currentIndex(self):
|
||||
"""
|
||||
Getter function used to normalized views acces with QAbstractItemViews.
|
||||
"""
|
||||
if self._index:
|
||||
return self._index
|
||||
else:
|
||||
return QModelIndex()
|
||||
|
||||
def getSelection(self):
|
||||
"""
|
||||
Getter function used to normalized views acces with QAbstractItemViews.
|
||||
"""
|
||||
return [self.currentIndex()]
|
||||
|
||||
def setCurrentModelIndexes(self, indexes):
|
||||
self._index = None
|
||||
self._indexes = []
|
||||
|
|
Loading…
Reference in a new issue