blob: 5710c9ecadc360c3994e04b80c87ff54236711e2 [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
18 minimumWidth: column.implicitWidth
19
20 required property ApplicationWindow welcomeWindow
21
22 function openNotebook(path) {
23 notebook.open(path);
24 }
25
26 menuBar: MenuBar {
27 Menu {
28 title: qsTr("&File")
29
30 Action {
31 text: qsTr("&New")
32
33 onTriggered: {
34 welcomeWindow.openNotebook();
35 }
36 }
37
38 Action {
39 text: qsTr("&Save")
40 shortcut: "Ctrl+s"
41
42 onTriggered: {
43 notebook.save()
44 }
45 }
46
47 Action {
48 text: qsTr("&Open")
49 shortcut: "Ctrl+o"
50
51 onTriggered: {
52 notebook.open();
53 }
54 }
55 }
56
57 Menu {
58 title: qsTr("&View")
59
60 Action {
61 text: qsTr("&Welcome Window")
62 checkable: true
63
64 checked: welcomeWindow.visible
65
66 onTriggered: {
67 welcomeWindow.toggleVisible()
68 }
69 }
70
71 Action {
72 id: varInspector
73 text: qsTr("&Variable Inspector")
74
75 checkable: true
76 }
77 }
78
79 Menu {
80 title: qsTr("&Runtime")
81
82 Action {
83 text: qsTr("Run &Selected Cell")
84 shortcut: "Ctrl+Return"
85
86 onTriggered: {
87 if (codeEditor.currentItem !== null) {
88 notebook.runCell(codeEditor.currentItem.uuid)
89 }
90 }
91 }
92
93 Action {
94 text: qsTr("Run &All")
95 }
96
97 Action {
98 text: qsTr("&Reset Runtime State")
99 }
100 }
101 }
102
103 Notebook {
104 id: notebook
105
106 onSaveError: (message) =>
107 {
108 console.error(message)
109 }
110 }
111
112 ColumnLayout {
113 id: column
114 anchors.fill: parent
115
116 SplitView {
117 id: split
118 Layout.fillHeight: true
119 Layout.fillWidth: true
120 orientation: Qt.Horizontal
121
122 ListView {
123 id: codeEditor
124 SplitView.fillWidth: true
125 SplitView.minimumWidth: 400
126 model: notebook.cellModel
127 clip: true
128
129 spacing: 5
130
131 header: ColumnLayout {
132 width: codeEditor.width
133
134 Pane {
135 Layout.bottomMargin: 0
136
137 ColumnLayout {
138 Label {
139 font.pointSize: 18
140 text: qsTr("Notebook")
141 }
142
143 Label {
144 visible: codeEditor.count === 0
145
146 text: qsTr("Looks like you haven't created any cells yet. Click the + button below to create one.")
147 }
148 }
149 }
150
151 InsertRow {
152 onInsertClicked: notebook.cellModel.insertCellBefore(0)
153 }
154
155 Item {
156 height: 5 // JANK!
157 }
158 }
159
160 delegate: NotebookCell {
161 id: notebookCell
162
163 required property var model
164 required property var index
165 required property var uuid
166
167 width: codeEditor.width
168
169 code: model.code
170 result: model.result.trim()
171 status: model.status
172 resultType: model.resultType
173 cellActive: codeEditor.currentIndex === index
174
175 onCodeEditingFinished: code => model.code = code
176
177 onInsertBelowClicked: {
178 console.info(index);
179 notebook.cellModel.insertCellBefore(index + 1);
180 }
181
182 onRunClicked: {
183 notebook.runCell(uuid)
184 }
185
186 onCellFocused: {
187 codeEditor.currentIndex = index
188 }
189
190 onDeleteClicked: {
191 notebook.cellModel.deleteCellAt(index)
192 }
193
194 onCellUnfocused: {
195 codeEditor.currentIndex = -1
196 }
197 }
198 }
199
200 Item {
201 id: variables
202 SplitView.minimumWidth: 240
203
204 visible: varInspector.checked
205
206 Label {
207 anchors.centerIn: parent
208 text: qsTr("Variables")
209 }
210 }
211 }
212 }
213}