blob: 2439e6c69907497db894157f5f35e4cd44740545 [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
12 title: "Notebook"
13 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")
21 }
22
23 Menu {
24 title: qsTr("&Runtime")
25
26 Action {
27 text: qsTr("Run &Selected Cell")
28 shortcut: "Ctrl+Return"
29
30 onTriggered: {
31 if (codeEditor.currentItem !== null) {
32 notebook.runCell(codeEditor.currentItem.uuid)
33 }
34 }
35 }
36 }
37 }
38
swissChili25620b02022-02-23 17:15:16 -080039 Notebook {
40 id: notebook
swissChili4b3105a2022-02-22 16:34:39 -080041 }
42
swissChili23958ca2022-02-21 19:23:34 -080043 ColumnLayout {
44 id: column
45 anchors.fill: parent
46
47 TabBar {
48 id: bar
49
50 Layout.fillWidth: true
51
52 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080053 text: "Notebook"
swissChili25620b02022-02-23 17:15:16 -080054 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080055 }
56
57 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080058 text: "Another Notebook"
swissChili25620b02022-02-23 17:15:16 -080059 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080060 }
61
62 TabButton {
63 text: "Testing"
swissChili25620b02022-02-23 17:15:16 -080064 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080065 }
66 }
67
68 SplitView {
69 id: split
70 Layout.fillHeight: true
71 Layout.fillWidth: true
72 orientation: Qt.Horizontal
73
74 ListView {
75 id: codeEditor
76 SplitView.fillWidth: true
77 SplitView.minimumWidth: 400
swissChili25620b02022-02-23 17:15:16 -080078 model: notebook.cellModel
swissChili23958ca2022-02-21 19:23:34 -080079 clip: true
80
swissChili06cec4e2022-02-24 19:04:32 -080081 spacing: 5
82
swissChilid85daa92022-02-24 15:29:02 -080083 header: ColumnLayout {
84 width: codeEditor.width
85
swissChili06cec4e2022-02-24 19:04:32 -080086 Pane {
swissChilid85daa92022-02-24 15:29:02 -080087 Layout.bottomMargin: 0
88
swissChilie386bc72022-02-24 21:31:31 -080089 ColumnLayout {
90 Label {
91 font.pointSize: 18
92 text: "Notebook"
93 }
94
95 Label {
96 visible: codeEditor.count === 0
97
98 text: "Looks like you haven't created any cells yet. Click the + button below to create one."
99 }
swissChilid85daa92022-02-24 15:29:02 -0800100 }
101 }
102
103 InsertRow {
swissChili5d3e5562022-02-24 16:49:19 -0800104 onInsertClicked: notebook.cellModel.insertCellBefore(0)
swissChilid85daa92022-02-24 15:29:02 -0800105 }
swissChilie386bc72022-02-24 21:31:31 -0800106
107 Item {
108 height: 5 // JANK!
109 }
swissChilid85daa92022-02-24 15:29:02 -0800110 }
111
swissChili4b3105a2022-02-22 16:34:39 -0800112 delegate: NotebookCell {
swissChili25620b02022-02-23 17:15:16 -0800113 id: notebookCell
114
115 required property var model
116 required property var index
swissChilid85daa92022-02-24 15:29:02 -0800117 required property var uuid
swissChili25620b02022-02-23 17:15:16 -0800118
swissChili06cec4e2022-02-24 19:04:32 -0800119 width: codeEditor.width
swissChili25620b02022-02-23 17:15:16 -0800120
121 code: model.code
swissChilid85daa92022-02-24 15:29:02 -0800122 result: model.result.trim()
123 status: model.status
swissChiliece1ac82022-02-25 11:20:42 -0800124 resultType: model.resultType
swissChili06cec4e2022-02-24 19:04:32 -0800125 cellActive: codeEditor.currentIndex === index
swissChili25620b02022-02-23 17:15:16 -0800126
swissChilie386bc72022-02-24 21:31:31 -0800127 onCodeEditingFinished: code => model.code = code
swissChili25620b02022-02-23 17:15:16 -0800128
129 onInsertBelowClicked: {
swissChilid85daa92022-02-24 15:29:02 -0800130 console.info(index);
swissChili5d3e5562022-02-24 16:49:19 -0800131 notebook.cellModel.insertCellBefore(index + 1);
swissChilid85daa92022-02-24 15:29:02 -0800132 }
133
134 onRunClicked: {
135 console.info("Cell run clicked")
136 notebook.runCell(uuid)
swissChili25620b02022-02-23 17:15:16 -0800137 }
swissChili06cec4e2022-02-24 19:04:32 -0800138
139 onCellFocused: {
140 codeEditor.currentIndex = index
141 }
142
143 onDeleteClicked: {
144 notebook.cellModel.deleteCellAt(index)
145 }
146
147 onCellUnfocused: {
148 codeEditor.currentIndex = -1
149 }
swissChili23958ca2022-02-21 19:23:34 -0800150 }
151 }
152
153 Item {
154 id: variables
155 SplitView.minimumWidth: 240
156
157 Label {
158 anchors.centerIn: parent
159 text: "Vars"
160 }
161 }
162 }
163 }
164}