mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 02:12:29 +12:00
Settings: saves last selected index
This commit is contained in:
parent
f89998743f
commit
df0190f08f
|
@ -392,6 +392,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
self.btnRedacFolderCork.setChecked(True)
|
||||
elif settings.folderView == "outline":
|
||||
self.btnRedacFolderOutline.setChecked(True)
|
||||
self.tabMain.setCurrentIndex(settings.lastTab)
|
||||
self.treeRedacOutline.setCurrentIndex(self.mdlOutline.indexFromPath(settings.lastIndex))
|
||||
|
||||
|
||||
# Stuff
|
||||
self.checkPersosID()
|
||||
|
@ -411,6 +414,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||
stgs.setValue("geometry", self.saveGeometry())
|
||||
stgs.setValue("windowState", self.saveState())
|
||||
|
||||
# Specific settings to save before quitting
|
||||
settings.lastTab = self.tabMain.currentIndex()
|
||||
if len(self.treeRedacOutline.selectedIndexes()) == 0:
|
||||
sel = QModelIndex()
|
||||
else:
|
||||
sel = self.treeRedacOutline.currentIndex()
|
||||
settings.lastIndex = self.mdlOutline.pathToIndex(sel)
|
||||
|
||||
# Save data from models
|
||||
saveStandardItemModelXML(self.mdlFlatData, "{}/flatModel.xml".format(self.currentProject))
|
||||
saveStandardItemModelXML(self.mdlPersos, "{}/perso.xml".format(self.currentProject))
|
||||
|
|
|
@ -37,7 +37,7 @@ class outlineModel(QAbstractItemModel):
|
|||
|
||||
def indexFromItem(self, item, column=0):
|
||||
if item == self.rootItem:
|
||||
return None
|
||||
return QModelIndex()
|
||||
|
||||
parent = item.parent()
|
||||
if not parent:
|
||||
|
@ -294,7 +294,7 @@ class outlineModel(QAbstractItemModel):
|
|||
#self.endInsertRows()
|
||||
|
||||
|
||||
################# XML #################
|
||||
################# XML / saving / loading #################
|
||||
|
||||
def saveToXML(self, xml):
|
||||
root = ET.XML(self.rootItem.toXML())
|
||||
|
@ -307,7 +307,26 @@ class outlineModel(QAbstractItemModel):
|
|||
#except:
|
||||
#print("N'arrive pas à ouvrir {}".format(xml))
|
||||
#return
|
||||
|
||||
def pathToIndex(self, index, path=""):
|
||||
if not index.isValid():
|
||||
return ""
|
||||
if index.parent().isValid():
|
||||
path = self.pathToIndex(index.parent())
|
||||
if path:
|
||||
path = "{},{}".format(path, str(index.row()))
|
||||
else:
|
||||
path = str(index.row())
|
||||
|
||||
return path
|
||||
|
||||
def indexFromPath(self, path):
|
||||
path = path.split(",")
|
||||
item = self.rootItem
|
||||
for p in path:
|
||||
if p != "":
|
||||
item = item.child(int(p))
|
||||
return self.indexFromItem(item)
|
||||
|
||||
class outlineItem():
|
||||
|
||||
|
|
|
@ -27,17 +27,21 @@ spellcheck = False
|
|||
dict = None
|
||||
corkSizeFactor = 100
|
||||
folderView = "cork"
|
||||
lastTab = 0
|
||||
lastIndex = ""
|
||||
|
||||
def save(filename):
|
||||
|
||||
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView
|
||||
global spellcheck, dict, corkSliderFactor, viewSettings, corkSizeFactor, folderView, lastTab, lastIndex
|
||||
|
||||
allSettings = {
|
||||
"viewSettings": viewSettings,
|
||||
"dict": dict,
|
||||
"spellcheck": spellcheck,
|
||||
"corkSizeFactor": corkSizeFactor,
|
||||
"folderView": folderView
|
||||
"folderView": folderView,
|
||||
"lastTab": lastTab,
|
||||
"lastIndex": lastIndex
|
||||
}
|
||||
|
||||
#pp=pprint.PrettyPrinter(indent=4, compact=False)
|
||||
|
@ -82,5 +86,13 @@ def load(filename):
|
|||
global folderView
|
||||
folderView = allSettings["folderView"]
|
||||
|
||||
if "lastTab" in allSettings:
|
||||
global lastTab
|
||||
lastTab = allSettings["lastTab"]
|
||||
|
||||
if "lastIndex" in allSettings:
|
||||
global lastIndex
|
||||
lastIndex = allSettings["lastIndex"]
|
||||
|
||||
|
||||
|
Binary file not shown.
Loading…
Reference in a new issue