Debian Codegraph @

src/app/qml/ui/FolderListPageDefaultHeader.qml

raw
1 import QtQuick 2.4
2 import QtQuick.Layouts 1.12
3 import Lomiri.Components 1.3
4 import Lomiri.Components.Popups 1.3
5
6 import "../components" as Components
7 import "../actions" as FMActions
8
9 PageHeader {
10 id: rootItem
11
12 property bool narrowAspect: false
13 property bool selectionMode: false
14 property bool contentHubMode: false
15 property bool importMode: false
16
17 readonly property bool selectionHeaderMode: selectionMode && !contentHubMode
18 readonly property bool pickHeaderMode: selectionMode && contentHubMode
19
20 // temp
21 property var fileOperationDialog
22 property var folderPage
23 property var folderModel
24 property var selectionManager: folderModel.model.selectionObject
25 property var showPanelAction
26 property var popover
27 property bool showSearchBar: false
28 property bool searchRecursiveOptionChecked: false
29 property bool searchFilesOptionChecked: false
30 property int queryModeIndex: 0
31
32 property var leadingActions: []
33 property var trailingActions: []
34 property var secondaryTrailingActions: []
35 property var extensionLeadingActions: []
36 property var extensionTrailingActions: []
37
38 title: FmUtils.basename(folderModel.path)
39
40 function enterSearch() {
41 showSearchBar = !showSearchBar;
42 if (popover && !showSearchBar)
43 searchField.__closePopover()
44 }
45
46 contents: RowLayout {
47 anchors.fill: parent
48
49 ColumnLayout {
50 Layout.leftMargin: units.gu(1)
51 Layout.rightMargin: units.gu(1)
52
53 spacing: 0
54
55 Label {
56 id: titleItem
57
58 Layout.fillWidth: true
59
60 text: {
61 if (rootItem.selectionHeaderMode) {
62 return i18n.tr("%1 item selected", "%1 items selected", rootItem.selectionManager.counter).arg(rootItem.selectionManager.counter)
63 }
64
65 return showSearchBar && searchField.text.trim().length ? t_metrics.text : rootItem.title
66 }
67 elide: Text.ElideRight
68 wrapMode: Text.WrapAtWordBoundaryOrAnywhere
69 maximumLineCount: 2
70
71 TextMetrics {
72 id: t_metrics
73 font: titleItem.font
74 text: i18n.tr("Search Results")
75 }
76 }
77
78 Label {
79 Layout.fillWidth: true
80
81 text: {
82 if (rootItem.selectionHeaderMode) {
83 return rootItem.title
84 }
85
86 if (rootItem.contentHubMode) {
87 if (rootItem.importMode) {
88 i18n.tr("Save here")
89 } else {
90 i18n.tr("Select files (%1 selected)", rootItem.selectionManager.counter).arg(rootItem.selectionManager.counter)
91 }
92 }
93 return i18n.tr("%1 item", "%1 items", rootItem.folderModel.count).arg(rootItem.folderModel.count)
94 }
95 textSize: Label.Small
96 }
97 }
98
99 TextField {
100 id: searchField
101 visible: showSearchBar
102
103 Layout.alignment: Qt.AlignVCenter
104
105 function __openPopover() {
106 if (!popover) {
107 popover = PopupUtils.open(popoverComponent, this)
108 this.forceActiveFocus()
109 }
110 }
111
112 function __closePopover() {
113 if (popover) {
114 PopupUtils.close(popover)
115 popover = null
116 }
117 }
118
119 placeholderText: i18n.tr("Search...")
120
121 // Disable predictive text
122 inputMethodHints: Qt.ImhNoPredictiveText
123
124 // Force active focus when this becomes the current PageHead state and
125 // show OSK if appropriate.
126 onVisibleChanged: {
127 if (rootItem.contentHubMode) {
128 folderModel.model.setImporting(rootItem.contentHubMode && rootItem.importMode);
129 }
130 if (visible)
131 forceActiveFocus()
132 else
133 folderModel.model.setSearchString("");
134 }
135
136 onActiveFocusChanged: {
137 if (!popover && activeFocus)
138 this.__openPopover()
139 else if (popover && !activeFocus)
140 this.__closePopover()
141 }
142
143 // https://stackoverflow.com/questions/41232999/two-way-binding-c-model-in-qml
144 text: folderModel.model.searchString
145
146 Binding {
147 target: folderModel.model
148 property: "searchString"
149 value: searchField.text
150 }
151 }
152
153 // Spacer
154 Item {
155 Layout.fillWidth: true
156 }
157
158 ActionBar {
159 id: secondaryTrailingActionBar
160
161 Layout.fillHeight: true
162 Layout.alignment: Qt.AlignRight
163
164 actions: rootItem.secondaryTrailingActions
165 }
166
167 Components.VerticalDivider {
168 Layout.fillHeight: true
169 Layout.margins: units.gu(1)
170
171 visible: secondaryTrailingActionBar.width > 0
172 }
173
174 Component {
175 id: popoverComponent
176
177 Popover {
178 id: popover
179 contentWidth: Math.max(searchField.width, units.gu(22))
180 autoClose: false
181
182 Column {
183 id: containerLayout
184 anchors {
185 left: parent.left
186 top: parent.top
187 right: parent.right
188 }
189
190 ListItem {
191 visible: !(rootItem.contentHubMode && rootItem.importMode)
192 height: filesOptionLayout.height + (divider.visible ? divider.height : 0)
193 ListItemLayout {
194 id: filesOptionLayout
195 title.text: i18n.tr("File Contents")
196
197 CheckBox {
198 checked: searchFilesOptionChecked
199 onCheckedChanged: {
200 searchFilesOptionChecked = checked
201 folderModel.model.setSearchFileContents(checked)
202 }
203 }
204 }
205 }
206
207 ListItem {
208 height: recursiveOptionLayout.height + (divider.visible ? divider.height : 0)
209 ListItemLayout {
210 id: recursiveOptionLayout
211 title.text: i18n.tr("Recursive")
212 summary.text: i18n.tr("Note: Slow in large directories")
213 summary.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
214
215 CheckBox {
216 checked: searchRecursiveOptionChecked
217 onCheckedChanged: {
218 searchRecursiveOptionChecked = checked
219 folderModel.model.setSearchRecursive(checked)
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228
229 extension: PathHistoryToolbar {
230 folderModel: rootItem.folderModel
231 leadingActionBar.actions: rootItem.extensionLeadingActions
232 trailingActionBar.actions: rootItem.extensionTrailingActions
233 }
234
235 leadingActionBar.actions: rootItem.leadingActions
236
237 trailingActionBar.numberOfSlots: rootItem.narrowAspect ? 3 : 5
238 trailingActionBar.actions: rootItem.trailingActions
239
240 // *** STYLE HINTS ***
241
242 StyleHints { dividerColor: "transparent" }
243 }