swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 1 | import QtQuick 2.5 |
2 | import QtQuick.Controls 2.15 | ||||
3 | import QtQuick.Controls.Material 2.0 | ||||
4 | import QtQuick.Layouts 1.3 | ||||
5 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 6 | import sh.swisschili.REFAL 1.0 |
7 | |||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 8 | ApplicationWindow { |
9 | id: root | ||||
10 | width: 1080 | ||||
11 | height: 720 | ||||
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame^] | 12 | title: "Refal Notebook -- " + notebook.savePath |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 13 | visible: true |
14 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 15 | Material.theme: Material.Light |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 16 | Material.accent: Material.Orange |
17 | |||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 18 | menuBar: MenuBar { |
19 | Menu { | ||||
20 | title: qsTr("&File") | ||||
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame^] | 21 | |
22 | Action { | ||||
23 | text: "&Save" | ||||
24 | shortcut: "Ctrl+s" | ||||
25 | |||||
26 | onTriggered: { | ||||
27 | notebook.save() | ||||
28 | } | ||||
29 | } | ||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 30 | } |
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 | |||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 48 | Notebook { |
49 | id: notebook | ||||
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame^] | 50 | |
51 | onSaveError: (message) => | ||||
52 | { | ||||
53 | console.error(message) | ||||
54 | } | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 55 | } |
56 | |||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 57 | ColumnLayout { |
58 | id: column | ||||
59 | anchors.fill: parent | ||||
60 | |||||
61 | TabBar { | ||||
62 | id: bar | ||||
63 | |||||
64 | Layout.fillWidth: true | ||||
65 | |||||
66 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 67 | text: "Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 68 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 69 | } |
70 | |||||
71 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 72 | text: "Another Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 73 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 74 | } |
75 | |||||
76 | TabButton { | ||||
77 | text: "Testing" | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 78 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 79 | } |
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 | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 92 | model: notebook.cellModel |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 93 | clip: true |
94 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 95 | spacing: 5 |
96 | |||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 97 | header: ColumnLayout { |
98 | width: codeEditor.width | ||||
99 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 100 | Pane { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 101 | Layout.bottomMargin: 0 |
102 | |||||
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 103 | 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 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 114 | } |
115 | } | ||||
116 | |||||
117 | InsertRow { | ||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 118 | onInsertClicked: notebook.cellModel.insertCellBefore(0) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 119 | } |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 120 | |
121 | Item { | ||||
122 | height: 5 // JANK! | ||||
123 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 124 | } |
125 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 126 | delegate: NotebookCell { |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 127 | id: notebookCell |
128 | |||||
129 | required property var model | ||||
130 | required property var index | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 131 | required property var uuid |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 132 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 133 | width: codeEditor.width |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 134 | |
135 | code: model.code | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 136 | result: model.result.trim() |
137 | status: model.status | ||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 138 | resultType: model.resultType |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 139 | cellActive: codeEditor.currentIndex === index |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 140 | |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 141 | onCodeEditingFinished: code => model.code = code |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 142 | |
143 | onInsertBelowClicked: { | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 144 | console.info(index); |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 145 | notebook.cellModel.insertCellBefore(index + 1); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 146 | } |
147 | |||||
148 | onRunClicked: { | ||||
149 | console.info("Cell run clicked") | ||||
150 | notebook.runCell(uuid) | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 151 | } |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 152 | |
153 | onCellFocused: { | ||||
154 | codeEditor.currentIndex = index | ||||
155 | } | ||||
156 | |||||
157 | onDeleteClicked: { | ||||
158 | notebook.cellModel.deleteCellAt(index) | ||||
159 | } | ||||
160 | |||||
161 | onCellUnfocused: { | ||||
162 | codeEditor.currentIndex = -1 | ||||
163 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 164 | } |
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 | } |