blob: 6ceeb217b372fde08811e78eb0bf2c28ffba5278 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
Item {
id: settings
// This would come from a C++ type. We add a mock implementation here to make tst_snippets pass.
function displayableFilePath(path) {
return path
}
//! [menu]
Menu {
title: qsTr("File")
Menu {
id: recentFilesMenu
title: qsTr("Recent Files")
enabled: recentFilesInstantiator.count > 0
Instantiator {
id: recentFilesInstantiator
model: settings.recentFiles
delegate: MenuItem {
text: settings.displayableFilePath(modelData)
onTriggered: loadFile(modelData)
}
onObjectAdded: (index, object) => recentFilesMenu.insertItem(index, object)
onObjectRemoved: (index, object) => recentFilesMenu.removeItem(object)
}
MenuSeparator {}
MenuItem {
text: qsTr("Clear Recent Files")
onTriggered: settings.clearRecentFiles()
}
}
}
//! [menu]
}
|