blob: ab86efdfa94573fd2ffafb6138a04eb64b8659dd [file] [log] [blame]
swissChili23958ca2022-02-21 19:23:34 -08001import QtQuick 2.5
2import QtQuick.Controls 2.15
3import QtQuick.Controls.Material 2.0
4import QtQuick.Layouts 1.3
5
swissChili4b3105a2022-02-22 16:34:39 -08006import sh.swisschili.REFAL 1.0
7
swissChili23958ca2022-02-21 19:23:34 -08008ApplicationWindow {
9 id: root
10 width: 1080
11 height: 720
swissChili505de412022-03-24 12:35:08 -070012 title: "Refal Notebook -- " + notebook.savePath
swissChili23958ca2022-02-21 19:23:34 -080013 visible: true
14
swissChili4b3105a2022-02-22 16:34:39 -080015 Material.theme: Material.Light
swissChili23958ca2022-02-21 19:23:34 -080016 Material.accent: Material.Orange
17
swissChiliece1ac82022-02-25 11:20:42 -080018 menuBar: MenuBar {
19 Menu {
20 title: qsTr("&File")
swissChili505de412022-03-24 12:35:08 -070021
22 Action {
23 text: "&Save"
24 shortcut: "Ctrl+s"
25
26 onTriggered: {
27 notebook.save()
28 }
29 }
swissChiliece1ac82022-02-25 11:20:42 -080030 }
31
32 Menu {
33 title: qsTr("&Runtime")
34
35 Action {
36 text: qsTr("Run &Selected Cell")
37 shortcut: "Ctrl+Return"
38
39 onTriggered: {
40 if (codeEditor.currentItem !== null) {
41 notebook.runCell(codeEditor.currentItem.uuid)
42 }
43 }
44 }
45 }
46 }
47
swissChili25620b02022-02-23 17:15:16 -080048 Notebook {
49 id: notebook
swissChili505de412022-03-24 12:35:08 -070050
51 onSaveError: (message) =>
52 {
53 console.error(message)
54 }
swissChili4b3105a2022-02-22 16:34:39 -080055 }
56
swissChili23958ca2022-02-21 19:23:34 -080057 ColumnLayout {
58 id: column
59 anchors.fill: parent
60
61 TabBar {
62 id: bar
63
64 Layout.fillWidth: true
65
66 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080067 text: "Notebook"
swissChili25620b02022-02-23 17:15:16 -080068 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080069 }
70
71 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080072 text: "Another Notebook"
swissChili25620b02022-02-23 17:15:16 -080073 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080074 }
75
76 TabButton {
77 text: "Testing"
swissChili25620b02022-02-23 17:15:16 -080078 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080079 }
80 }
81
82 SplitView {
83 id: split
84 Layout.fillHeight: true
85 Layout.fillWidth: true
86 orientation: Qt.Horizontal
87
88 ListView {
89 id: codeEditor
90 SplitView.fillWidth: true
91 SplitView.minimumWidth: 400
swissChili25620b02022-02-23 17:15:16 -080092 model: notebook.cellModel
swissChili23958ca2022-02-21 19:23:34 -080093 clip: true
94
swissChili06cec4e2022-02-24 19:04:32 -080095 spacing: 5
96
swissChilid85daa92022-02-24 15:29:02 -080097 header: ColumnLayout {
98 width: codeEditor.width
99
swissChili06cec4e2022-02-24 19:04:32 -0800100 Pane {
swissChilid85daa92022-02-24 15:29:02 -0800101 Layout.bottomMargin: 0
102
swissChilie386bc72022-02-24 21:31:31 -0800103 ColumnLayout {
104 Label {
105 font.pointSize: 18
106 text: "Notebook"
107 }
108
109 Label {
110 visible: codeEditor.count === 0
111
112 text: "Looks like you haven't created any cells yet. Click the + button below to create one."
113 }
swissChilid85daa92022-02-24 15:29:02 -0800114 }
115 }
116
117 InsertRow {
swissChili5d3e5562022-02-24 16:49:19 -0800118 onInsertClicked: notebook.cellModel.insertCellBefore(0)
swissChilid85daa92022-02-24 15:29:02 -0800119 }
swissChilie386bc72022-02-24 21:31:31 -0800120
121 Item {
122 height: 5 // JANK!
123 }
swissChilid85daa92022-02-24 15:29:02 -0800124 }
125
swissChili4b3105a2022-02-22 16:34:39 -0800126 delegate: NotebookCell {
swissChili25620b02022-02-23 17:15:16 -0800127 id: notebookCell
128
129 required property var model
130 required property var index
swissChilid85daa92022-02-24 15:29:02 -0800131 required property var uuid
swissChili25620b02022-02-23 17:15:16 -0800132
swissChili06cec4e2022-02-24 19:04:32 -0800133 width: codeEditor.width
swissChili25620b02022-02-23 17:15:16 -0800134
135 code: model.code
swissChilid85daa92022-02-24 15:29:02 -0800136 result: model.result.trim()
137 status: model.status
swissChiliece1ac82022-02-25 11:20:42 -0800138 resultType: model.resultType
swissChili06cec4e2022-02-24 19:04:32 -0800139 cellActive: codeEditor.currentIndex === index
swissChili25620b02022-02-23 17:15:16 -0800140
swissChilie386bc72022-02-24 21:31:31 -0800141 onCodeEditingFinished: code => model.code = code
swissChili25620b02022-02-23 17:15:16 -0800142
143 onInsertBelowClicked: {
swissChilid85daa92022-02-24 15:29:02 -0800144 console.info(index);
swissChili5d3e5562022-02-24 16:49:19 -0800145 notebook.cellModel.insertCellBefore(index + 1);
swissChilid85daa92022-02-24 15:29:02 -0800146 }
147
148 onRunClicked: {
149 console.info("Cell run clicked")
150 notebook.runCell(uuid)
swissChili25620b02022-02-23 17:15:16 -0800151 }
swissChili06cec4e2022-02-24 19:04:32 -0800152
153 onCellFocused: {
154 codeEditor.currentIndex = index
155 }
156
157 onDeleteClicked: {
158 notebook.cellModel.deleteCellAt(index)
159 }
160
161 onCellUnfocused: {
162 codeEditor.currentIndex = -1
163 }
swissChili23958ca2022-02-21 19:23:34 -0800164 }
165 }
166
167 Item {
168 id: variables
169 SplitView.minimumWidth: 240
170
171 Label {
172 anchors.centerIn: parent
173 text: "Vars"
174 }
175 }
176 }
177 }
178}