blob: 63eb0047001a0133de1b33af56047ab7ad1b85e8 [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
swissChili25620b02022-02-23 17:15:16 -080018 Notebook {
19 id: notebook
swissChili4b3105a2022-02-22 16:34:39 -080020 }
21
swissChili23958ca2022-02-21 19:23:34 -080022 ColumnLayout {
23 id: column
24 anchors.fill: parent
25
26 TabBar {
27 id: bar
28
29 Layout.fillWidth: true
30
31 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080032 text: "Notebook"
swissChili25620b02022-02-23 17:15:16 -080033 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080034 }
35
36 TabButton {
swissChili06cec4e2022-02-24 19:04:32 -080037 text: "Another Notebook"
swissChili25620b02022-02-23 17:15:16 -080038 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080039 }
40
41 TabButton {
42 text: "Testing"
swissChili25620b02022-02-23 17:15:16 -080043 width: implicitWidth
swissChili23958ca2022-02-21 19:23:34 -080044 }
45 }
46
47 SplitView {
48 id: split
49 Layout.fillHeight: true
50 Layout.fillWidth: true
51 orientation: Qt.Horizontal
52
53 ListView {
54 id: codeEditor
55 SplitView.fillWidth: true
56 SplitView.minimumWidth: 400
swissChili25620b02022-02-23 17:15:16 -080057 model: notebook.cellModel
swissChili23958ca2022-02-21 19:23:34 -080058 clip: true
59
swissChili06cec4e2022-02-24 19:04:32 -080060 spacing: 5
61
swissChilid85daa92022-02-24 15:29:02 -080062 header: ColumnLayout {
63 width: codeEditor.width
64
swissChili06cec4e2022-02-24 19:04:32 -080065 Pane {
swissChilid85daa92022-02-24 15:29:02 -080066 Layout.bottomMargin: 0
67
swissChilie386bc72022-02-24 21:31:31 -080068 ColumnLayout {
69 Label {
70 font.pointSize: 18
71 text: "Notebook"
72 }
73
74 Label {
75 visible: codeEditor.count === 0
76
77 text: "Looks like you haven't created any cells yet. Click the + button below to create one."
78 }
swissChilid85daa92022-02-24 15:29:02 -080079 }
80 }
81
82 InsertRow {
swissChili5d3e5562022-02-24 16:49:19 -080083 onInsertClicked: notebook.cellModel.insertCellBefore(0)
swissChilid85daa92022-02-24 15:29:02 -080084 }
swissChilie386bc72022-02-24 21:31:31 -080085
86 Item {
87 height: 5 // JANK!
88 }
swissChilid85daa92022-02-24 15:29:02 -080089 }
90
swissChili4b3105a2022-02-22 16:34:39 -080091 delegate: NotebookCell {
swissChili25620b02022-02-23 17:15:16 -080092 id: notebookCell
93
94 required property var model
95 required property var index
swissChilid85daa92022-02-24 15:29:02 -080096 required property var uuid
swissChili25620b02022-02-23 17:15:16 -080097
swissChili06cec4e2022-02-24 19:04:32 -080098 width: codeEditor.width
swissChili25620b02022-02-23 17:15:16 -080099
100 code: model.code
swissChilid85daa92022-02-24 15:29:02 -0800101 result: model.result.trim()
102 status: model.status
swissChili06cec4e2022-02-24 19:04:32 -0800103 cellActive: codeEditor.currentIndex === index
swissChili25620b02022-02-23 17:15:16 -0800104
swissChilie386bc72022-02-24 21:31:31 -0800105 onCodeEditingFinished: code => model.code = code
swissChili25620b02022-02-23 17:15:16 -0800106
107 onInsertBelowClicked: {
swissChilid85daa92022-02-24 15:29:02 -0800108 console.info(index);
swissChili5d3e5562022-02-24 16:49:19 -0800109 notebook.cellModel.insertCellBefore(index + 1);
swissChilid85daa92022-02-24 15:29:02 -0800110 }
111
112 onRunClicked: {
113 console.info("Cell run clicked")
114 notebook.runCell(uuid)
swissChili25620b02022-02-23 17:15:16 -0800115 }
swissChili06cec4e2022-02-24 19:04:32 -0800116
117 onCellFocused: {
118 codeEditor.currentIndex = index
119 }
120
121 onDeleteClicked: {
122 notebook.cellModel.deleteCellAt(index)
123 }
124
125 onCellUnfocused: {
126 codeEditor.currentIndex = -1
127 }
swissChili23958ca2022-02-21 19:23:34 -0800128 }
129 }
130
131 Item {
132 id: variables
133 SplitView.minimumWidth: 240
134
135 Label {
136 anchors.centerIn: parent
137 text: "Vars"
138 }
139 }
140 }
141 }
142}