-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathAppMenu.tsx
249 lines (238 loc) · 7.37 KB
/
AppMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import {
CopyAll,
NoteAddOutlined,
OpenInNew,
Settings
} from "@mui/icons-material";
import MenuIcon from "@mui/icons-material/Menu";
import SaveIcon from "@mui/icons-material/Save";
import UploadIcon from "@mui/icons-material/UploadFile";
import {
Divider,
Drawer,
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText
} from "@mui/material";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import { dialog, path } from "@tauri-apps/api";
import { observer } from "mobx-react";
import { Component } from "react";
import { toast } from "react-toastify";
import {
newProject,
saveProjectDialog,
uiState,
openDiagnosticZipWithInfo,
openProjectSelectFeedback
} from "./document/DocumentManager";
import SettingsModal from "./components/config/SettingsModal";
import { Commands } from "./document/tauriCommands";
import { version } from "./util/version";
type Props = object;
type State = object;
class AppMenu extends Component<Props, State> {
private convertToRelative(filePath: string): string {
return filePath.replace(
RegExp(
`^(?:C:)?\\${path.sep}(Users|home)\\${path.sep}[a-zA-Z]+\\${path.sep}`
),
"~" + path.sep
);
}
CopyToClipboardButton({ data, tooltip }: { data: any; tooltip: string }) {
const handleAction = async function () {
await navigator.clipboard.writeText(data);
toast.success("Copied to clipboard");
};
return (
<Tooltip disableInteractive title={tooltip}>
<IconButton size="small" onClick={handleAction}>
<CopyAll fontSize="small"></CopyAll>
</IconButton>
</Tooltip>
);
}
OpenInFilesApp({ dir }: { dir: string }) {
const handleAction = async function () {
await Commands.openInExplorer(dir);
};
return (
<Tooltip disableInteractive title="Reveal in Files App">
<IconButton size="small" onClick={handleAction}>
<OpenInNew fontSize="small"></OpenInNew>
</IconButton>
</Tooltip>
);
}
render() {
const { mainMenuOpen, toggleMainMenu } = uiState;
return (
<Drawer
anchor="left"
open={mainMenuOpen}
onClose={(_) => {
uiState.setMainMenuOpen(false);
}}
>
<div
style={{
width: "var(--sidebar-width)",
backgroundColor: "var(--background-dark-gray)",
height: "100%"
}}
>
<div
style={{
flexShrink: 0,
height: "var(--top-nav-height)",
borderBottom: "thin solid var(--divider-gray)",
display: "flex",
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center",
paddingLeft: 0,
zIndex: 1000
}}
>
<Tooltip disableInteractive title="Main Menu">
<IconButton
onClick={() => {
toggleMainMenu();
}}
>
<MenuIcon></MenuIcon>
</IconButton>
</Tooltip>
Choreo v{version}
</div>
<List style={{ paddingBottom: "50px", paddingTop: "0px" }}>
{/* Document Settings (open the robot config, etc modal) */}
<Tooltip
disableInteractive
title="Robot configuration and other settings"
>
<ListItemButton onClick={() => uiState.setRobotConfigOpen(true)}>
<ListItemIcon>
<Settings />
</ListItemIcon>
<ListItemText primary="Document Settings"></ListItemText>
</ListItemButton>
</Tooltip>
<Divider></Divider>
{/* Open Project */}
<ListItemButton
onClick={async () => {
openProjectSelectFeedback();
}}
>
<ListItemIcon>
<UploadIcon />
</ListItemIcon>
<ListItemText primary="Open Project"></ListItemText>
</ListItemButton>
{/* Save Project */}
<ListItemButton
onClick={async () => {
saveProjectDialog();
}}
>
<ListItemIcon>
<SaveIcon />
</ListItemIcon>
<ListItemText
primary={
uiState.hasSaveLocation ? "Save Project As" : "Save Project"
}
></ListItemText>
</ListItemButton>
{/* New Project */}
<ListItemButton
onClick={async () => {
if (
await dialog.confirm(
"You may lose unsaved changes. Continue?",
{ title: "Choreo", type: "warning" }
)
) {
newProject();
}
}}
>
<ListItemIcon>
<NoteAddOutlined />
</ListItemIcon>
<ListItemText primary="New Project"></ListItemText>
</ListItemButton>
{/* Export Diagnostic Report */}
<ListItemButton
onClick={async () => {
openDiagnosticZipWithInfo();
}}
>
<ListItemIcon>
<SaveIcon />
</ListItemIcon>
<ListItemText primary="Export Diagnostic Report"></ListItemText>
</ListItemButton>
<Divider orientation="horizontal"></Divider>
{/* Info about save locations */}
<ListItem>
<div
style={{
overflowWrap: "break-word",
fontSize: "1.0em",
width: "100%"
}}
>
{uiState.hasSaveLocation ? (
<>
<div
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center"
}}
>
<span>Project saved at</span>
<span>
<this.CopyToClipboardButton
data={this.projectLocation(false)}
tooltip="Copy full path to clipboard"
></this.CopyToClipboardButton>
<this.OpenInFilesApp
dir={this.projectLocation(false)}
></this.OpenInFilesApp>
</span>
</div>
<div style={{ fontSize: "0.9em", color: "#D3D3D3" }}>
{this.projectLocation(true)}
</div>
</>
) : (
<>
Project not saved.
<br />
Click "Save Project" above to save.
</>
)}
</div>
</ListItem>
</List>
<SettingsModal></SettingsModal>
</div>
</Drawer>
);
}
private projectLocation(relativeFormat: boolean): string {
return (
(relativeFormat
? this.convertToRelative(uiState.projectDir as string)
: uiState.projectDir) + path.sep
);
}
}
export default observer(AppMenu);