aboutsummaryrefslogtreecommitdiff
path: root/kodereviewer/qml/FilesChangedPage.qml
blob: 1aa823bf25954d1d34a1f928acfb962267a1a544 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
pragma ComponentBehavior: Bound
import QtQuick
import QtCore
import QtQuick.Controls as QQC2
import QtQuick.Layouts

import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.kirigamiaddons.components as KirigamiComponents

import org.deprecated.kodereviewer 1.0

Kirigami.ScrollablePage {
    id: root

    property var pullRequest
    property NetworkManager connection

    Kirigami.Theme.colorSet: Kirigami.Theme.View
    Kirigami.Theme.inherit: false

    title: pullRequest ? `#${pullRequest.number}` : ""

    property ReviewHelper reviewHelper: applicationWindow().reviewHelper


    property string currentFile: ""
    property string currentText: ""

    DiffFileModel {
        id: diffFileModel
        diff: root.currentText

        onDiffChanged: {
            console.log('expanding')
            contentTreeView.expandRecursively()
        }
    }

    onPullRequestChanged: {
        root.currentFile = ""
        root.currentText = ""
        root.currentSha = ""
    }

    Component.onCompleted: {
        actions = commonActions.concat(actions)
    }

    actions: [
        Kirigami.Action {
            id: openFiles
            text: "Files"
            icon.name: "file-catalog-symbolic"
            enabled: !!root.pullRequest
            onTriggered: {
                if(contextDrawer.opened) {
                    contextDrawer.close()
                } else {
                    contextDrawer.open()
                }
            }
        }
    ]

    Kirigami.Dialog {
        id: popup
        popupType: QQC2.Popup.Window
        focus: true
        title: i18n("Add review to " + root.currentFile)
        showCloseButton: false
        preferredWidth: Kirigami.Units.gridUnit * 20
        preferredHeight: Kirigami.Units.gridUnit * 20
        padding: Kirigami.Units.largeSpacing
        MarkdownTextArea {
            id: reviewTextArea
        }
        standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel

        onAccepted: {
            root.reviewHelper.addFileReview(root.currentFile, reviewTextArea.text, editor.selectionEndLine())
        }
    }

    Kirigami.PlaceholderMessage {
        visible: root.currentFile == ''
        anchors.centerIn: parent
        icon.name: "org.deprecated.kodereviewer"
        text: "No file selected"
    }

    TreeView {
        id: contentTreeView

        visible: root.currentFile != ''
        model: diffFileModel
        anchors.fill: parent
        clip: true

        delegate: Item {
            id: itemDelegate
            // Assigned to by TreeView:
            required property TreeView treeView
            required property bool isTreeNode
            required property bool expanded
            required property int hasChildren
            required property int depth
            required property int row
            required property int column
            required property bool current
            required property string text

            property bool isHeading: isTreeNode && hasChildren
            implicitHeight: isHeading ? heading.implicitHeight : diffEditor.implicitHeight
            implicitWidth: treeView.width


            onExpandedChanged: indicator.rotation = expanded ? 90 : 0

            MouseArea {
                enabled: parent.isHeading

                onClicked: parent.treeView.toggleExpanded(itemDelegate.row)
                anchors.fill: parent
            }

            RowLayout {
                id: headingLayout
                visible: parent.isHeading
                property string itemText: parent.text
                QQC2.Label {
                    id: indicator
                    text: "▶"
                }
                Kirigami.Heading {
                    id: heading
                    level: 2
                    text: `Context: ${parent.itemText}`
                    Layout.fillWidth: true
                }
            }

            Editor {
                id: diffEditor
                visible: !parent.isHeading
                file: 'bla.diff'
                text: parent.text

                MouseArea {
                    anchors.fill: parent
                    //propagateComposedEvents: true
                    acceptedButtons: Qt.RightButton
                    cursorShape: Qt.IBeamCursor

                    onClicked: event => {
                        if (event.button === Qt.RightButton) { // 'mouse' is a MouseEvent argument passed into the onClicked signal handler
                            editorMenu.popup()
                        }
                    }

                    QQC2.Menu {
                        id: editorMenu
                        QQC2.MenuItem {
                            text: "Add review"
                            icon.name: "preview-symbolic"
                            onTriggered: {
                                console.log("triggered review")
                                console.log(`start line: ${diffEditor.selectionStartLine()} to ${diffEditor.selectionEndLine()}`)

                                const component = Qt.createComponent("ReviewWindow.qml")
                                print(applicationWindow().project)
                                const params = {
                                    project: applicationWindow().project,
                                    pullRequestNumber: root.pullRequest.number,
                                    diffText: root.currentText,
                                    path: root.currentFile,
                                    startLine: diffEditor.selectionStartLine(),
                                    endLine: diffEditor.selectionEndLine(),
                                    commitId: root.pullRequest.last_commit
                                }
                                component.createObject(applicationWindow(), params)

                                //popup.open()
                            }
                        }
                    }
                }
            }
        }
    }

    Connections {
        target: contextDrawer
        function onFileSelected(filename, text) {
            root.currentFile = filename
            root.currentText = text
        }
    }
}