@@ -17,6 +17,13 @@ import ArrowForwardIcon from '@material-ui/icons/ArrowForward';
1717import AutorenewIcon from '@material-ui/icons/Autorenew' ;
1818import VerticalSplitIcon from '@material-ui/icons/VerticalSplit' ;
1919/* 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 **/
2027const { remote } = window . require ( 'electron' ) ;
2128/* STORE */
2229const Store = window . require ( 'electron-store' ) ;
@@ -26,15 +33,19 @@ const store = new Store();
2633window . React = React ;
2734const { BrowserWindow, BrowserView } = window . require ( 'electron' ) . remote ;
2835
36+ const ipc = window . require ( 'electron' ) . ipcRenderer ;
37+
2938export default class ViewB extends React . Component {
3039
3140 constructor ( props ) {
3241 super ( props ) ;
3342 this . state = {
3443 anchorEl : null ,
35- session : props . session ,
44+ session : props . session ,
45+ workspaceImage : '' ,
46+ open : false ,
3647 tabs :[
37- ( < Tab key = { 'tab0' } title = { 'Fixed - ' + props . session } unclosable = { true } >
48+ ( < Tab key = { 'tab0' } title = { 'Fixed - ' + props . session } >
3849 < AppBar position = "static" className = "AppBar" >
3950 < Toolbar className = "Toolbar" >
4051 < IconButton onClick = { ( ) => { this . goBack ( 'tab0' ) } } >
@@ -237,6 +248,47 @@ export default class ViewB extends React.Component {
237248
238249 /* APPBAR */
239250
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+
240292 render ( ) {
241293 const { anchorEl } = this . state ;
242294
@@ -308,9 +360,26 @@ export default class ViewB extends React.Component {
308360 open = { Boolean ( anchorEl ) }
309361 onClose = { this . handleClose }
310362 >
311- < MenuItem onClick = { ( ) => { this . loadImage ( '../icon-devo.png' ) } } > Change workspace image</ MenuItem >
363+ < MenuItem onClick = { ( ) => { this . handleOpen ( ) } } > Change workspace image</ MenuItem >
312364 < MenuItem onClick = { ( ) => { this . _deteteWorkspace ( ) } } > Delete workspace</ MenuItem >
313365 </ 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 >
314383 </ div >
315384
316385 )
0 commit comments