@@ -17,6 +17,13 @@ import ArrowForwardIcon from '@material-ui/icons/ArrowForward';
17
17
import AutorenewIcon from '@material-ui/icons/Autorenew' ;
18
18
import VerticalSplitIcon from '@material-ui/icons/VerticalSplit' ;
19
19
/* NAVBAR */
20
+ /** DIALOG **/
21
+ import Dialog from '@material-ui/core/Dialog' ;
22
+ import DialogActions from '@material-ui/core/DialogActions' ;
23
+ import DialogContent from '@material-ui/core/DialogContent' ;
24
+ import DialogTitle from '@material-ui/core/DialogTitle' ;
25
+ import Button from '@material-ui/core/Button' ;
26
+ /** DIALOG **/
20
27
const { remote } = window . require ( 'electron' ) ;
21
28
/* STORE */
22
29
const Store = window . require ( 'electron-store' ) ;
@@ -26,15 +33,19 @@ const store = new Store();
26
33
window . React = React ;
27
34
const { BrowserWindow, BrowserView } = window . require ( 'electron' ) . remote ;
28
35
36
+ const ipc = window . require ( 'electron' ) . ipcRenderer ;
37
+
29
38
export default class ViewB extends React . Component {
30
39
31
40
constructor ( props ) {
32
41
super ( props ) ;
33
42
this . state = {
34
43
anchorEl : null ,
35
- session : props . session ,
44
+ session : props . session ,
45
+ workspaceImage : '' ,
46
+ open : false ,
36
47
tabs :[
37
- ( < Tab key = { 'tab0' } title = { 'Fixed - ' + props . session } unclosable = { true } >
48
+ ( < Tab key = { 'tab0' } title = { 'Fixed - ' + props . session } >
38
49
< AppBar position = "static" className = "AppBar" >
39
50
< Toolbar className = "Toolbar" >
40
51
< IconButton onClick = { ( ) => { this . goBack ( 'tab0' ) } } >
@@ -237,6 +248,47 @@ export default class ViewB extends React.Component {
237
248
238
249
/* APPBAR */
239
250
251
+ /* CHANGE IMAGE */
252
+ changeImage = async ( ) => {
253
+ var b64 ;
254
+ if ( this . state . workspaceImage !== '' ) {
255
+ b64 = await this . getBase64 ( this . state . workspaceImage ) ;
256
+ } else {
257
+ b64 = '' ;
258
+ }
259
+ var images = store . get ( 'images' ) ;
260
+ if ( b64 ) {
261
+ images [ this . state . session ] = b64 ;
262
+ await store . set ( 'images' , images ) ;
263
+ ipc . send ( 'update-image' , [ this . state . session ] ) ;
264
+ }
265
+ this . handleCloseImg ( ) ;
266
+ this . handleClose ( ) ;
267
+ }
268
+
269
+ getBase64 = async ( file ) => {
270
+ return new Promise ( ( resolve , reject ) => {
271
+ const reader = new FileReader ( ) ;
272
+ reader . onload = ( ) => resolve ( reader . result ) ;
273
+ reader . onerror = error => reject ( '' ) ;
274
+ reader . readAsDataURL ( file ) ;
275
+ } ) ;
276
+ }
277
+
278
+ fileChangedHandler = ( event ) => {
279
+ const file = event . target . files [ 0 ] ;
280
+ this . setState ( { workspaceImage : file } ) ;
281
+ }
282
+
283
+ handleOpen = ( ) => {
284
+ this . setState ( { open : true } ) ;
285
+ }
286
+
287
+ handleCloseImg = ( ) => {
288
+ this . setState ( { open : false , workspaceImage :'' } ) ;
289
+ }
290
+ /* CHANGE IMAGE */
291
+
240
292
render ( ) {
241
293
const { anchorEl } = this . state ;
242
294
@@ -308,9 +360,26 @@ export default class ViewB extends React.Component {
308
360
open = { Boolean ( anchorEl ) }
309
361
onClose = { this . handleClose }
310
362
>
311
- < MenuItem onClick = { ( ) => { this . loadImage ( '../icon-devo.png' ) } } > Change workspace image</ MenuItem >
363
+ < MenuItem onClick = { ( ) => { this . handleOpen ( ) } } > Change workspace image</ MenuItem >
312
364
< MenuItem onClick = { ( ) => { this . _deteteWorkspace ( ) } } > Delete workspace</ MenuItem >
313
365
</ Menu >
366
+ < Dialog open = { this . state . open } onClose = { ( ) => this . handleCloseImg ( ) } aria-labelledby = "form-dialog-title" >
367
+ < DialogTitle id = "form-dialog-title" > Change workspace image</ DialogTitle >
368
+ < DialogContent >
369
+ < Button variant = "contained" component = "label" >
370
+ Select image
371
+ < input type = "file" accept = "image/*" style = { { display : "none" } } onChange = { this . fileChangedHandler } />
372
+ </ Button >
373
+ </ DialogContent >
374
+ < DialogActions >
375
+ < Button onClick = { ( ) => this . handleCloseImg ( ) } color = "secondary" >
376
+ Cancel
377
+ </ Button >
378
+ < Button onClick = { ( ) => this . changeImage ( ) } color = "primary" >
379
+ Change
380
+ </ Button >
381
+ </ DialogActions >
382
+ </ Dialog >
314
383
</ div >
315
384
316
385
)
0 commit comments