mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-18 04:07:57 -06:00
Add support for listing recent files
Fixes Asana issue 33694049548880
This commit is contained in:
parent
478babff9a
commit
56454a9c7a
2 changed files with 46 additions and 0 deletions
|
@ -17,6 +17,7 @@ from UM.Logger import Logger
|
||||||
from UM.Preferences import Preferences
|
from UM.Preferences import Preferences
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
from UM.PluginRegistry import PluginRegistry
|
from UM.PluginRegistry import PluginRegistry
|
||||||
|
from UM.JobQueue import JobQueue
|
||||||
|
|
||||||
from UM.Scene.BoxRenderer import BoxRenderer
|
from UM.Scene.BoxRenderer import BoxRenderer
|
||||||
from UM.Scene.Selection import Selection
|
from UM.Scene.Selection import Selection
|
||||||
|
@ -71,6 +72,17 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
Preferences.getInstance().addPreference("cura/active_machine", "")
|
Preferences.getInstance().addPreference("cura/active_machine", "")
|
||||||
Preferences.getInstance().addPreference("cura/active_mode", "simple")
|
Preferences.getInstance().addPreference("cura/active_mode", "simple")
|
||||||
|
Preferences.getInstance().addPreference("cura/recent_files", "")
|
||||||
|
|
||||||
|
JobQueue.getInstance().jobFinished.connect(self._onJobFinished)
|
||||||
|
|
||||||
|
self._recent_files = []
|
||||||
|
files = Preferences.getInstance().getValue("cura/recent_files").split(";")
|
||||||
|
for f in files:
|
||||||
|
if not os.path.isfile(f):
|
||||||
|
continue
|
||||||
|
|
||||||
|
self._recent_files.append(f)
|
||||||
|
|
||||||
## Handle loading of all plugin types (and the backend explicitly)
|
## Handle loading of all plugin types (and the backend explicitly)
|
||||||
# \sa PluginRegistery
|
# \sa PluginRegistery
|
||||||
|
@ -305,6 +317,11 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
|
||||||
|
recentFilesChanged = pyqtSignal()
|
||||||
|
@pyqtProperty("QStringList", notify = recentFilesChanged)
|
||||||
|
def recentFiles(self):
|
||||||
|
return self._recent_files
|
||||||
|
|
||||||
outputDevicesChanged = pyqtSignal()
|
outputDevicesChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty("QVariantMap", notify = outputDevicesChanged)
|
@pyqtProperty("QVariantMap", notify = outputDevicesChanged)
|
||||||
|
@ -460,3 +477,18 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
|
op = AddSceneNodeOperation(node, self.getController().getScene().getRoot())
|
||||||
op.push()
|
op.push()
|
||||||
|
|
||||||
|
def _onJobFinished(self, job):
|
||||||
|
if type(job) is not ReadMeshJob:
|
||||||
|
return
|
||||||
|
|
||||||
|
f = job.getFileName()
|
||||||
|
if f in self._recent_files:
|
||||||
|
self._recent_files.remove(f)
|
||||||
|
|
||||||
|
self._recent_files.insert(0, f)
|
||||||
|
if len(self._recent_files) > 10:
|
||||||
|
del self._recent_files[10]
|
||||||
|
|
||||||
|
Preferences.getInstance().setValue("cura/recent_files", ";".join(self._recent_files))
|
||||||
|
self.recentFilesChanged.emit()
|
||||||
|
|
|
@ -25,6 +25,7 @@ UM.MainWindow {
|
||||||
window: base
|
window: base
|
||||||
|
|
||||||
Menu {
|
Menu {
|
||||||
|
id: fileMenu
|
||||||
//: File menu
|
//: File menu
|
||||||
title: qsTr("&File");
|
title: qsTr("&File");
|
||||||
|
|
||||||
|
@ -33,6 +34,19 @@ UM.MainWindow {
|
||||||
|
|
||||||
MenuSeparator { }
|
MenuSeparator { }
|
||||||
|
|
||||||
|
Instantiator {
|
||||||
|
model: Printer.recentFiles
|
||||||
|
MenuItem {
|
||||||
|
property url filePath: modelData;
|
||||||
|
text: (index + 1) + ". " + modelData.slice(modelData.lastIndexOf("/") + 1);
|
||||||
|
onTriggered: UM.MeshFileHandler.readLocalFile(filePath);
|
||||||
|
}
|
||||||
|
onObjectAdded: fileMenu.insertItem(index, object)
|
||||||
|
onObjectRemoved: fileMenu.removeItem(object)
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuSeparator { }
|
||||||
|
|
||||||
MenuItem { action: actions.quit; }
|
MenuItem { action: actions.quit; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue