blob: 858fb5e3a2b8d4aeb397e0f423c34850bc880c1c [file] [log] [blame]
swissChilid2af6ad2022-04-16 14:42:17 -07001import QtQuick 2.5
2import QtQuick.Controls 2.15
3import QtQuick.Controls.Material 2.0
4import QtQuick.Layouts 1.3
5
6import sh.swisschili.REFAL 1.0
7
8ApplicationWindow {
9 id: root
10 width: 800
11 height: 800
12 title: "Refal Notebook — " + notebook.savePath
13 visible: true
14
15 Material.theme: Material.Light
16 Material.accent: Material.Orange
17
swissChilia44bf722022-04-16 18:41:54 -070018 minimumWidth: 600
19 minimumHeight: 400
swissChilid2af6ad2022-04-16 14:42:17 -070020
21 required property ApplicationWindow welcomeWindow
22
23 function openNotebook(path) {
24 notebook.open(path);
25 }
26
27 menuBar: MenuBar {
28 Menu {
29 title: qsTr("&File")
30
31 Action {
32 text: qsTr("&New")
33
34 onTriggered: {
35 welcomeWindow.openNotebook();
36 }
37 }
38
39 Action {
40 text: qsTr("&Save")
41 shortcut: "Ctrl+s"
42
43 onTriggered: {
44 notebook.save()
45 }
46 }
47
48 Action {
49 text: qsTr("&Open")
50 shortcut: "Ctrl+o"
51
52 onTriggered: {
53 notebook.open();
54 }
55 }
56 }
57
58 Menu {
59 title: qsTr("&View")
60
61 Action {
62 text: qsTr("&Welcome Window")
63 checkable: true
64
65 checked: welcomeWindow.visible
66
67 onTriggered: {
68 welcomeWindow.toggleVisible()
69 }
70 }
71
72 Action {
73 id: varInspector
74 text: qsTr("&Variable Inspector")
75
76 checkable: true
77 }
78 }
79
80 Menu {
81 title: qsTr("&Runtime")
82
83 Action {
84 text: qsTr("Run &Selected Cell")
85 shortcut: "Ctrl+Return"
86
87 onTriggered: {
88 if (codeEditor.currentItem !== null) {
89 notebook.runCell(codeEditor.currentItem.uuid)
90 }
91 }
92 }
93
94 Action {
95 text: qsTr("Run &All")
swissChilia44bf722022-04-16 18:41:54 -070096
97 onTriggered: notebook.runAll();
swissChilid2af6ad2022-04-16 14:42:17 -070098 }
99
100 Action {
101 text: qsTr("&Reset Runtime State")
swissChilia44bf722022-04-16 18:41:54 -0700102
103 onTriggered: notebook.reset();
swissChilid2af6ad2022-04-16 14:42:17 -0700104 }
105 }
106 }
107
108 Notebook {
109 id: notebook
110
111 onSaveError: (message) =>
112 {
113 console.error(message)
114 }
swissChilia44bf722022-04-16 18:41:54 -0700115
116 onSaved: welcomeWindow.recentModel.add(notebook.savePath)
swissChilid2af6ad2022-04-16 14:42:17 -0700117 }
118
119 ColumnLayout {
120 id: column
121 anchors.fill: parent
122
123 SplitView {
124 id: split
125 Layout.fillHeight: true
126 Layout.fillWidth: true
127 orientation: Qt.Horizontal
128
129 ListView {
130 id: codeEditor
131 SplitView.fillWidth: true
132 SplitView.minimumWidth: 400
133 model: notebook.cellModel
134 clip: true
135
136 spacing: 5
137
138 header: ColumnLayout {
139 width: codeEditor.width
140
141 Pane {
142 Layout.bottomMargin: 0
143
144 ColumnLayout {
145 Label {
146 font.pointSize: 18
swissChilia44bf722022-04-16 18:41:54 -0700147 text: notebook.savePath != "" ? notebook.savePath.split("/").pop().split(".").slice(0,-1).join('.') : qsTr("Notebook")
swissChilid2af6ad2022-04-16 14:42:17 -0700148 }
149
150 Label {
151 visible: codeEditor.count === 0
152
153 text: qsTr("Looks like you haven't created any cells yet. Click the + button below to create one.")
154 }
155 }
156 }
157
158 InsertRow {
159 onInsertClicked: notebook.cellModel.insertCellBefore(0)
160 }
161
162 Item {
163 height: 5 // JANK!
164 }
165 }
166
167 delegate: NotebookCell {
168 id: notebookCell
169
170 required property var model
171 required property var index
172 required property var uuid
173
174 width: codeEditor.width
175
176 code: model.code
177 result: model.result.trim()
178 status: model.status
179 resultType: model.resultType
180 cellActive: codeEditor.currentIndex === index
181
182 onCodeEditingFinished: code => model.code = code
183
184 onInsertBelowClicked: {
185 console.info(index);
186 notebook.cellModel.insertCellBefore(index + 1);
187 }
188
189 onRunClicked: {
190 notebook.runCell(uuid)
191 }
192
193 onCellFocused: {
194 codeEditor.currentIndex = index
195 }
196
197 onDeleteClicked: {
198 notebook.cellModel.deleteCellAt(index)
199 }
200
201 onCellUnfocused: {
202 codeEditor.currentIndex = -1
203 }
204 }
205 }
206
207 Item {
208 id: variables
209 SplitView.minimumWidth: 240
210
211 visible: varInspector.checked
212
213 Label {
214 anchors.centerIn: parent
215 text: qsTr("Variables")
216 }
217 }
218 }
219 }
220}