1- import { Layout , Model , IJsonModel , TabNode , Action , Actions , ITabRenderValues } from 'flexlayout-react' ;
1+ import {
2+ Layout ,
3+ Model ,
4+ IJsonModel ,
5+ TabNode ,
6+ Action ,
7+ Actions ,
8+ ITabRenderValues ,
9+ } from 'flexlayout-react' ;
210import React , { useEffect , useRef , useState } from 'react' ;
311import BlocklyEditor from '@components/blockly' ;
412import MonacoEditor from '@components/MonacoEditor' ;
513import XRPShell from '@components/xrpshell' ;
614import FolderIcon from '@assets/images/folder-24.png' ;
715import ShellIcon from '@assets/images/shell.svg' ;
16+ import GoogleDriveLogo from '@assets/images/Google_Drive-Logo.svg' ;
817//import treeDaaJson from '@/utils/testdata';
918import AppMgr , { EventType , Themes } from '@/managers/appmgr' ;
1019import FolderTree from './folder-tree' ;
@@ -28,7 +37,7 @@ const layout_json: IJsonModel = {
2837 tabEnablePopout : false ,
2938 tabSetEnableDrag : false ,
3039 tabSetEnableDrop : false ,
31- tabEnableRename : false
40+ tabEnableRename : false ,
3241 } ,
3342 borders : [
3443 {
@@ -85,7 +94,7 @@ const layout_json: IJsonModel = {
8594 component : 'xterm' ,
8695 enableClose : false ,
8796 enableDrag : false ,
88- enablePopout : false
97+ enablePopout : false ,
8998 } ,
9099 ] ,
91100 } ,
@@ -104,7 +113,14 @@ let layoutRef: React.RefObject<Layout> = {
104113const factory = ( node : TabNode ) => {
105114 const component = node . getComponent ( ) ;
106115 if ( component == 'editor' ) {
107- return < MonacoEditor tabId = { node . getId ( ) } tabname = { node . getName ( ) } width = "100vw" height = "100vh" /> ;
116+ return (
117+ < MonacoEditor
118+ tabId = { node . getId ( ) }
119+ tabname = { node . getName ( ) }
120+ width = "100vw"
121+ height = "100vh"
122+ />
123+ ) ;
108124 } else if ( component == 'xterm' ) {
109125 return < XRPShell /> ;
110126 } else if ( component == 'folders' ) {
@@ -127,17 +143,17 @@ let hasSubscribed = false;
127143
128144/**
129145 * useOnceCall - call the function once
130- * @param cb
131- * @param condition
146+ * @param cb
147+ * @param condition
132148 */
133149function useOnceCall ( cb : ( ) => void , condition = true ) {
134150 const isCalledRef = React . useRef ( false ) ;
135-
151+
136152 React . useEffect ( ( ) => {
137- if ( condition && ! isCalledRef . current ) {
138- isCalledRef . current = true ;
139- cb ( ) ;
140- }
153+ if ( condition && ! isCalledRef . current ) {
154+ isCalledRef . current = true ;
155+ cb ( ) ;
156+ }
141157 } , [ cb , condition ] ) ;
142158}
143159
@@ -223,7 +239,7 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
223239 gpath : store . gpath ,
224240 filetype : store . isBlockly ? FileType . BLOCKLY : FileType . PYTHON ,
225241 content : store . content ,
226- }
242+ } ;
227243 CreateEditorTab ( fileData , layoutRef ) ;
228244 let content : string | undefined ;
229245 if ( fileData . filetype === FileType . BLOCKLY ) {
@@ -233,12 +249,18 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
233249 content = store . content ;
234250 }
235251 const loadContent = { name : store . name , path : store . path , content : content } ;
236- AppMgr . getInstance ( ) . emit ( EventType . EVENT_EDITOR_LOAD , JSON . stringify ( loadContent ) ) ;
252+ AppMgr . getInstance ( ) . emit (
253+ EventType . EVENT_EDITOR_LOAD ,
254+ JSON . stringify ( loadContent ) ,
255+ ) ;
237256 if ( ! store . isSavedToXRP ) {
238257 // update the editor session and update the tab dirty status
239258 const editorSession = EditorMgr . getInstance ( ) . getEditorSession ( store . id ) ;
240259 if ( editorSession ) {
241- EditorMgr . getInstance ( ) . updateEditorSessionChange ( store . id , ! store . isSavedToXRP ) ;
260+ EditorMgr . getInstance ( ) . updateEditorSessionChange (
261+ store . id ,
262+ ! store . isSavedToXRP ,
263+ ) ;
242264 }
243265 }
244266 setActiveTab ( store . id ) ;
@@ -250,7 +272,7 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
250272 const currentVersion = Constants . APP_VERSION ;
251273 if ( version === null || version !== currentVersion ) {
252274 AppMgr . getInstance ( ) . emit ( EventType . EVENT_SHOWCHANGELOG , Constants . SHOW_CHANGELOG ) ;
253- }
275+ }
254276 localStorage . setItem ( StorageKeys . VERSION , currentVersion || '' ) ;
255277 } ;
256278
@@ -261,7 +283,7 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
261283 }
262284 return ( ) => {
263285 window . removeEventListener ( 'load' , handleWindowLoad ) ;
264- }
286+ } ;
265287 } ) ;
266288
267289 /**
@@ -273,8 +295,7 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
273295 }
274296 if ( dialogRef . current . hasAttribute ( 'open' ) ) {
275297 dialogRef . current . close ( ) ;
276- }
277- else dialogRef . current . showModal ( ) ;
298+ } else dialogRef . current . showModal ( ) ;
278299 } ;
279300
280301 /**
@@ -291,7 +312,7 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
291312 setActiveTab ( id ) ;
292313 }
293314 }
294- }
315+ } ;
295316
296317 /**
297318 * handleActions - handle the actions from the layout
@@ -301,64 +322,102 @@ function XRPLayout({ forwardedref }: XRPLayoutProps) {
301322 function handleActions ( action : Action ) : Action | undefined {
302323 console . log ( 'Handle Action: Action Type:' , action . type , activeTab ) ;
303324 switch ( action . type ) {
304- case Actions . SELECT_TAB : {
305- console . log ( 'Selected Tab:' , action . data . tabNode ) ;
306- if ( EditorMgr . getInstance ( ) . hasEditorSession ( action . data . tabNode ) ) {
307- const editorType = EditorMgr . getInstance ( ) . getEditorSession ( action . data . tabNode ) ?. type ;
308- if ( editorType !== undefined ) {
309- AppMgr . getInstance ( ) . emit ( EventType . EVENT_EDITOR , editorType ) ;
325+ case Actions . SELECT_TAB :
326+ {
327+ console . log ( 'Selected Tab:' , action . data . tabNode ) ;
328+ if ( EditorMgr . getInstance ( ) . hasEditorSession ( action . data . tabNode ) ) {
329+ const editorType = EditorMgr . getInstance ( ) . getEditorSession (
330+ action . data . tabNode ,
331+ ) ?. type ;
332+ if ( editorType !== undefined ) {
333+ AppMgr . getInstance ( ) . emit ( EventType . EVENT_EDITOR , editorType ) ;
334+ }
335+ setActiveTab ( action . data . tabNode ) ;
310336 }
311- setActiveTab ( action . data . tabNode ) ;
312- }
313- }
314- break ;
315- case Actions . DELETE_TAB : {
316- console . log ( 'Delete Node:' , action . data ) ;
317- const isDirty = EditorMgr . getInstance ( ) . hasSessionChanged ( action . data . node ) ;
318- if ( isDirty ) {
319- setDialogContent ( < ConfirmationDlg acceptCallback = { handleDeleteTabConfirmation } toggleDialog = { toggleDialog } confirmationMessage = { t ( 'confirmDeleteTab' , { name : action . data . node } ) } name = { action . data . node } /> ) ;
320- toggleDialog ( ) ;
321-
322- return undefined ;
323337 }
338+ break ;
339+ case Actions . DELETE_TAB :
340+ {
341+ console . log ( 'Delete Node:' , action . data ) ;
342+ const isDirty = EditorMgr . getInstance ( ) . hasSessionChanged ( action . data . node ) ;
343+ if ( isDirty ) {
344+ setDialogContent (
345+ < ConfirmationDlg
346+ acceptCallback = { handleDeleteTabConfirmation }
347+ toggleDialog = { toggleDialog }
348+ confirmationMessage = { t ( 'confirmDeleteTab' , {
349+ name : action . data . node ,
350+ } ) }
351+ name = { action . data . node }
352+ /> ,
353+ ) ;
354+ toggleDialog ( ) ;
324355
325- const name = EditorMgr . getInstance ( ) . RemoveEditor ( action . data . node ) ;
326- if ( name ) {
327- setActiveTab ( name ) ;
356+ return undefined ;
357+ }
358+
359+ const name = EditorMgr . getInstance ( ) . RemoveEditor ( action . data . node ) ;
360+ if ( name ) {
361+ setActiveTab ( name ) ;
362+ }
328363 }
329- }
330- break ;
331- default : {
332- console . log ( 'Default Action:' , action ) ;
333- }
334- break ;
364+ break ;
365+ default :
366+ {
367+ console . log ( 'Default Action:' , action ) ;
368+ }
369+ break ;
335370 }
336371 return action ;
337372 }
338373
339374 /**
340375 * onRenderTab - render the tab with custom functionality
341- * @param node
376+ * @param node
342377 * @param renderValues
343- * @returns
378+ * @returns
344379 */
345380 const onRenderTab = ( node : TabNode , renderValues : ITabRenderValues ) => {
346381 // Override the content to use the translated tab names
347382 if ( node . getId ( ) === Constants . FOLDER_TAB_ID ) {
348- renderValues . leading = < img src = { FolderIcon } alt = "icon" style = { { width : '16px' , height : '16px' , marginRight : '16px' } } /> ;
383+ renderValues . leading = (
384+ < img
385+ src = { FolderIcon }
386+ alt = "icon"
387+ style = { { width : '16px' , height : '16px' , marginRight : '16px' } }
388+ />
389+ ) ;
349390 } else if ( node . getId ( ) === Constants . SHELL_TAB_ID ) {
350- renderValues . leading = < img src = { ShellIcon } alt = "icon" style = { { width : '16px' , height : '16px' , marginRight : '0px' } } /> ;
391+ renderValues . leading = (
392+ < img
393+ src = { ShellIcon }
394+ alt = "icon"
395+ style = { { width : '16px' , height : '16px' , marginRight : '0px' } }
396+ />
397+ ) ;
398+ } else if ( EditorMgr . getInstance ( ) . getEditorSession ( node . getId ( ) ) ?. gpath !== undefined ) {
399+ renderValues . leading = (
400+ < img src = { GoogleDriveLogo } alt = "icon" style = { { width : '16px' , height : '16px' } } />
401+ ) ;
351402 }
352403 renderValues . content = t ( node . getName ( ) ) ;
353404 if ( EditorMgr . getInstance ( ) . hasSessionChanged ( node . getId ( ) ) ) {
354- renderValues . buttons . push ( < div className = 'w-2 h-2 bg-shark-800 dark:bg-shark-200 rounded-full' /> )
405+ renderValues . buttons . push (
406+ < div className = { `h-2 w-2 rounded-full bg-shark-800 dark:bg-shark-200` } /> ,
407+ ) ;
355408 }
356409 return renderValues ;
357410 } ;
358411
359412 return (
360413 < >
361- < Layout ref = { forwardedref } model = { model } factory = { factory } onAction = { handleActions } onRenderTab = { onRenderTab } />
414+ < Layout
415+ ref = { forwardedref }
416+ model = { model }
417+ factory = { factory }
418+ onAction = { handleActions }
419+ onRenderTab = { onRenderTab }
420+ />
362421 < Dialog isOpen = { false } toggleDialog = { toggleDialog } ref = { dialogRef } >
363422 { dialogContent }
364423 </ Dialog >
0 commit comments