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 | ||||
12 | title: "Notebook" | ||||
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") | ||||
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 | |||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 39 | Notebook { |
40 | id: notebook | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 41 | } |
42 | |||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 43 | ColumnLayout { |
44 | id: column | ||||
45 | anchors.fill: parent | ||||
46 | |||||
47 | TabBar { | ||||
48 | id: bar | ||||
49 | |||||
50 | Layout.fillWidth: true | ||||
51 | |||||
52 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 53 | text: "Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 54 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 55 | } |
56 | |||||
57 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 58 | text: "Another Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 59 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 60 | } |
61 | |||||
62 | TabButton { | ||||
63 | text: "Testing" | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 64 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 65 | } |
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 | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 78 | model: notebook.cellModel |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 79 | clip: true |
80 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 81 | spacing: 5 |
82 | |||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 83 | header: ColumnLayout { |
84 | width: codeEditor.width | ||||
85 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 86 | Pane { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 87 | Layout.bottomMargin: 0 |
88 | |||||
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 89 | 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 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 100 | } |
101 | } | ||||
102 | |||||
103 | InsertRow { | ||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 104 | onInsertClicked: notebook.cellModel.insertCellBefore(0) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 105 | } |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 106 | |
107 | Item { | ||||
108 | height: 5 // JANK! | ||||
109 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 110 | } |
111 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 112 | delegate: NotebookCell { |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 113 | id: notebookCell |
114 | |||||
115 | required property var model | ||||
116 | required property var index | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 117 | required property var uuid |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 118 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 119 | width: codeEditor.width |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 120 | |
121 | code: model.code | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 122 | result: model.result.trim() |
123 | status: model.status | ||||
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame^] | 124 | resultType: model.resultType |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 125 | cellActive: codeEditor.currentIndex === index |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 126 | |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 127 | onCodeEditingFinished: code => model.code = code |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 128 | |
129 | onInsertBelowClicked: { | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 130 | console.info(index); |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 131 | notebook.cellModel.insertCellBefore(index + 1); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 132 | } |
133 | |||||
134 | onRunClicked: { | ||||
135 | console.info("Cell run clicked") | ||||
136 | notebook.runCell(uuid) | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 137 | } |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 138 | |
139 | onCellFocused: { | ||||
140 | codeEditor.currentIndex = index | ||||
141 | } | ||||
142 | |||||
143 | onDeleteClicked: { | ||||
144 | notebook.cellModel.deleteCellAt(index) | ||||
145 | } | ||||
146 | |||||
147 | onCellUnfocused: { | ||||
148 | codeEditor.currentIndex = -1 | ||||
149 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 150 | } |
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 | } |