mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-03 08:48:40 +02:00
[ui] improve open recent files
* fix path conversion on windows * remove invalid paths from the list on error * explicit error message for "No Such File"
This commit is contained in:
parent
dcf91c244e
commit
0e434908a5
6 changed files with 101 additions and 19 deletions
|
@ -8,6 +8,8 @@ from PySide2.QtWidgets import QApplication
|
|||
|
||||
import meshroom
|
||||
from meshroom.core import nodesDesc
|
||||
from meshroom.core import pyCompatibility
|
||||
|
||||
from meshroom.ui import components
|
||||
from meshroom.ui.components.clipboard import ClipboardHelper
|
||||
from meshroom.ui.components.filepath import FilepathHelper
|
||||
|
@ -183,8 +185,19 @@ class MeshroomApp(QApplication):
|
|||
return projects
|
||||
|
||||
@Slot(str)
|
||||
@Slot(QUrl)
|
||||
def addRecentProjectFile(self, projectFile):
|
||||
projectFile = QUrl(projectFile).path()
|
||||
if not isinstance(projectFile, (QUrl, pyCompatibility.basestring)):
|
||||
raise TypeError("Unexpected data type: {}".format(projectFile.__class__))
|
||||
if isinstance(projectFile, QUrl):
|
||||
projectFileNorm = projectFile.toLocalFile()
|
||||
if not projectFileNorm:
|
||||
projectFileNorm = projectFile.toString()
|
||||
else:
|
||||
projectFileNorm = QUrl(projectFile).toLocalFile()
|
||||
if not projectFileNorm:
|
||||
projectFileNorm = QUrl.fromLocalFile(projectFile).toLocalFile()
|
||||
|
||||
projects = self._recentProjectFiles()
|
||||
|
||||
# remove duplicates while preserving order
|
||||
|
@ -192,10 +205,10 @@ class MeshroomApp(QApplication):
|
|||
uniqueProjects = OrderedDict.fromkeys(projects)
|
||||
projects = list(uniqueProjects)
|
||||
# remove previous usage of the value
|
||||
if projectFile in uniqueProjects:
|
||||
projects.remove(projectFile)
|
||||
if projectFileNorm in uniqueProjects:
|
||||
projects.remove(projectFileNorm)
|
||||
# add the new value in the first place
|
||||
projects.insert(0, projectFile)
|
||||
projects.insert(0, projectFileNorm)
|
||||
|
||||
# keep only the 10 first elements
|
||||
projects = projects[0:20]
|
||||
|
@ -211,6 +224,43 @@ class MeshroomApp(QApplication):
|
|||
|
||||
self.recentProjectFilesChanged.emit()
|
||||
|
||||
@Slot(str)
|
||||
@Slot(QUrl)
|
||||
def removeRecentProjectFile(self, projectFile):
|
||||
if not isinstance(projectFile, (QUrl, pyCompatibility.basestring)):
|
||||
raise TypeError("Unexpected data type: {}".format(projectFile.__class__))
|
||||
if isinstance(projectFile, QUrl):
|
||||
projectFileNorm = projectFile.toLocalFile()
|
||||
if not projectFileNorm:
|
||||
projectFileNorm = projectFile.toString()
|
||||
else:
|
||||
projectFileNorm = QUrl(projectFile).toLocalFile()
|
||||
if not projectFileNorm:
|
||||
projectFileNorm = QUrl.fromLocalFile(projectFile).toLocalFile()
|
||||
|
||||
projects = self._recentProjectFiles()
|
||||
|
||||
# remove duplicates while preserving order
|
||||
from collections import OrderedDict
|
||||
uniqueProjects = OrderedDict.fromkeys(projects)
|
||||
projects = list(uniqueProjects)
|
||||
# remove previous usage of the value
|
||||
if projectFileNorm not in uniqueProjects:
|
||||
return
|
||||
|
||||
projects.remove(projectFileNorm)
|
||||
|
||||
settings = QSettings()
|
||||
settings.beginGroup("RecentFiles")
|
||||
size = settings.beginWriteArray("Projects")
|
||||
for i, p in enumerate(projects):
|
||||
settings.setArrayIndex(i)
|
||||
settings.setValue("filepath", p)
|
||||
settings.endArray()
|
||||
settings.sync()
|
||||
|
||||
self.recentProjectFilesChanged.emit()
|
||||
|
||||
@Slot(str, result=str)
|
||||
def markdownToHtml(self, md):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue