Refactor to use Instantiator instead of doing it manually

This commit is contained in:
Nicolas Werner 2021-05-30 13:22:11 +02:00
parent 53fcf7f428
commit 7f4656d3c3
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 26 additions and 44 deletions

View file

@ -31,8 +31,8 @@ Rectangle {
TimelineView { TimelineView {
id: timeline id: timeline
room: Rooms.currentRoom
room: Rooms.currentRoom
SplitView.fillWidth: true SplitView.fillWidth: true
SplitView.minimumWidth: 400 SplitView.minimumWidth: 400
} }

View file

@ -4,6 +4,7 @@
import "./dialogs" import "./dialogs"
import Qt.labs.platform 1.1 as Platform import Qt.labs.platform 1.1 as Platform
import QtQml 2.13
import QtQuick 2.13 import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
@ -37,19 +38,12 @@ Page {
property string roomid property string roomid
property var tags property var tags
property var allTags
function show(roomid_, tags_) { function show(roomid_, tags_) {
roomid = roomid_; roomid = roomid_;
tags = tags_; tags = tags_;
roomContextMenu.clear(); allTags = Rooms.tags();
roomContextMenu.addItem(leaveOpt.createObject(roomContextMenu));
roomContextMenu.addItem(separatorOpt.createObject(roomContextMenu));
for (let tag of Rooms.tags()) {
roomContextMenu.addItem(tagDelegate.createObject(roomContextMenu, {
"t": tag
}));
}
roomContextMenu.addItem(newTagOpt.createObject(roomContextMenu));
open(); open();
} }
@ -63,30 +57,22 @@ Page {
} }
} }
Component { Platform.MenuItem {
id: leaveOpt text: qsTr("Leave room")
onTriggered: Rooms.leave(roomContextMenu.roomid)
Platform.MenuItem {
text: qsTr("Leave room")
onTriggered: Rooms.leave(roomContextMenu.roomid)
}
} }
Component { Platform.MenuSeparator {
id: separatorOpt text: qsTr("Tag room as:")
Platform.MenuSeparator {
text: qsTr("Tag room as:")
}
} }
Component { Instantiator {
id: tagDelegate model: roomContextMenu.allTags
onObjectAdded: roomContextMenu.insertItem(index + 2, object)
onObjectRemoved: roomContextMenu.removeItem(object)
Platform.MenuItem { delegate: Platform.MenuItem {
property string t property string t: modelData
text: { text: {
switch (t) { switch (t) {
@ -107,14 +93,9 @@ Page {
} }
Component { Platform.MenuItem {
id: newTagOpt text: qsTr("Create new tag...")
onTriggered: newTag.show()
Platform.MenuItem {
text: qsTr("Create new tag...")
onTriggered: newTag.show()
}
} }
} }
@ -166,9 +147,9 @@ Page {
TapHandler { TapHandler {
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onSingleTapped: { onSingleTapped: {
if (!TimelineManager.isInvite) { if (!TimelineManager.isInvite)
roomContextMenu.show(model.roomId, model.tags); roomContextMenu.show(model.roomId, model.tags);
}
} }
gesturePolicy: TapHandler.ReleaseWithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds
} }
@ -176,9 +157,9 @@ Page {
TapHandler { TapHandler {
onSingleTapped: Rooms.setCurrentRoom(model.roomId) onSingleTapped: Rooms.setCurrentRoom(model.roomId)
onLongPressed: { onLongPressed: {
if (!TimelineManager.isInvite) { if (!TimelineManager.isInvite)
roomContextMenu.show(model.roomId, model.tags); roomContextMenu.show(model.roomId, model.tags);
}
} }
} }
@ -524,7 +505,6 @@ Page {
ToolTip.visible: hovered ToolTip.visible: hovered
ToolTip.text: qsTr("Start a new chat") ToolTip.text: qsTr("Start a new chat")
Layout.margins: Nheko.paddingMedium Layout.margins: Nheko.paddingMedium
onClicked: roomJoinCreateMenu.open(parent) onClicked: roomJoinCreateMenu.open(parent)
Platform.Menu { Platform.Menu {
@ -541,6 +521,7 @@ Page {
} }
} }
} }
ImageButton { ImageButton {

View file

@ -74,11 +74,12 @@ Page {
Shortcut { Shortcut {
sequence: "Ctrl+Down" sequence: "Ctrl+Down"
onActivated: Rooms.nextRoom(); onActivated: Rooms.nextRoom()
} }
Shortcut { Shortcut {
sequence: "Ctrl+Up" sequence: "Ctrl+Up"
onActivated: Rooms.previousRoom(); onActivated: Rooms.previousRoom()
} }
Component { Component {