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 | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 18 | Notebook { |
19 | id: notebook | ||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 20 | } |
21 | |||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 22 | ColumnLayout { |
23 | id: column | ||||
24 | anchors.fill: parent | ||||
25 | |||||
26 | TabBar { | ||||
27 | id: bar | ||||
28 | |||||
29 | Layout.fillWidth: true | ||||
30 | |||||
31 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 32 | text: "Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 33 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 34 | } |
35 | |||||
36 | TabButton { | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 37 | text: "Another Notebook" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 38 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 39 | } |
40 | |||||
41 | TabButton { | ||||
42 | text: "Testing" | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 43 | width: implicitWidth |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 44 | } |
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 | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 57 | model: notebook.cellModel |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 58 | clip: true |
59 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 60 | spacing: 5 |
61 | |||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 62 | header: ColumnLayout { |
63 | width: codeEditor.width | ||||
64 | |||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 65 | Pane { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 66 | Layout.bottomMargin: 0 |
67 | |||||
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame^] | 68 | 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 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 79 | } |
80 | } | ||||
81 | |||||
82 | InsertRow { | ||||
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 83 | onInsertClicked: notebook.cellModel.insertCellBefore(0) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 84 | } |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame^] | 85 | |
86 | Item { | ||||
87 | height: 5 // JANK! | ||||
88 | } | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 89 | } |
90 | |||||
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 91 | delegate: NotebookCell { |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 92 | id: notebookCell |
93 | |||||
94 | required property var model | ||||
95 | required property var index | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 96 | required property var uuid |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 97 | |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 98 | width: codeEditor.width |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 99 | |
100 | code: model.code | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 101 | result: model.result.trim() |
102 | status: model.status | ||||
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 103 | cellActive: codeEditor.currentIndex === index |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 104 | |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame^] | 105 | onCodeEditingFinished: code => model.code = code |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 106 | |
107 | onInsertBelowClicked: { | ||||
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 108 | console.info(index); |
swissChili | 5d3e556 | 2022-02-24 16:49:19 -0800 | [diff] [blame] | 109 | notebook.cellModel.insertCellBefore(index + 1); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 110 | } |
111 | |||||
112 | onRunClicked: { | ||||
113 | console.info("Cell run clicked") | ||||
114 | notebook.runCell(uuid) | ||||
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 115 | } |
swissChili | 06cec4e | 2022-02-24 19:04:32 -0800 | [diff] [blame] | 116 | |
117 | onCellFocused: { | ||||
118 | codeEditor.currentIndex = index | ||||
119 | } | ||||
120 | |||||
121 | onDeleteClicked: { | ||||
122 | notebook.cellModel.deleteCellAt(index) | ||||
123 | } | ||||
124 | |||||
125 | onCellUnfocused: { | ||||
126 | codeEditor.currentIndex = -1 | ||||
127 | } | ||||
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 128 | } |
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 | } |