@@ -15,13 +15,20 @@ import { wait } from "../tools/tools";
1515import { openSingleFileDialog } from "../tools/dialog" ;
1616import { ProjectType , projectsKey } from "../tools/project" ;
1717import { checkNodeJSAvailable , nodeJSAvailable } from "../tools/process" ;
18- import { tryAddProjectToLocalStorage , tryGetProjectsFromLocalStorage } from "../tools/local-storage" ;
18+ import {
19+ tryAddProjectToLocalStorage ,
20+ tryGetCloseDashboardOnProjectOpenFromLocalStorage ,
21+ tryGetProjectsFromLocalStorage ,
22+ trySetCloseDashboardOnProjectOpenInLocalStorage ,
23+ } from "../tools/local-storage" ;
1924
2025import { DashboardProjectItem } from "./item" ;
2126import { DashboardCreateProjectDialog } from "./create" ;
2227import { DashboardWindowControls } from "./window-controls" ;
2328
2429import packageJson from "../../package.json" ;
30+ import { Switch } from "../ui/shadcn/ui/switch" ;
31+ import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "../ui/shadcn/ui/tooltip" ;
2532
2633export function createDashboard ( ) : void {
2734 const theme = localStorage . getItem ( "editor-theme" ) ?? "dark" ;
@@ -48,6 +55,7 @@ export interface IDashboardState {
4855 openedProjects : string [ ] ;
4956
5057 createProject : boolean ;
58+ closeDashboardOnProjectOpen : boolean ;
5159}
5260
5361export class Dashboard extends Component < IDashboardProps , IDashboardState > {
@@ -59,48 +67,61 @@ export class Dashboard extends Component<IDashboardProps, IDashboardState> {
5967 projects : tryGetProjectsFromLocalStorage ( ) ,
6068
6169 createProject : false ,
70+ closeDashboardOnProjectOpen : tryGetCloseDashboardOnProjectOpenFromLocalStorage ( ) ,
6271 } ;
6372
6473 webFrame . setZoomFactor ( 0.8 ) ;
6574 }
6675
6776 public render ( ) : ReactNode {
68- return (
69- < >
70- < div className = "flex flex-col gap-4 w-screen h-screen p-5 select-none overflow-x-hidden pt-10" >
71- < DashboardWindowControls />
72-
73- < Fade delay = { 0 } >
74- < div className = "flex justify-between items-end w-full mt-1" >
75- < div className = "text-5xl font-semibold" > Dashboard</ div >
77+ const handleKeepDashboardChanged = ( checked : boolean ) : void => {
78+ const shouldClose = ! checked ;
7679
77- < div className = "flex flex-col items-end gap-2" >
78- < img alt = "" src = "assets/babylonjs_icon.png" className = "w-[48px] object-contain" />
79- < div className = "text-xs" > Babylon.js Editor v{ packageJson . version } </ div >
80- </ div >
81- </ div >
82- </ Fade >
80+ this . setState ( {
81+ closeDashboardOnProjectOpen : shouldClose ,
82+ } ) ;
8383
84- < Fade delay = { 250 } >
85- < Separator />
86- </ Fade >
84+ trySetCloseDashboardOnProjectOpenInLocalStorage ( shouldClose ) ;
85+ } ;
8786
88- < Fade delay = { 500 } >
89- < div className = "flex justify-between items-center" >
90- < div className = "text-3xl font-semibold" > Projects</ div >
91-
92- < div className = "flex gap-2" >
93- < Button variant = "secondary" className = "font-semibold" onClick = { ( ) => this . _handleImportProject ( ) } >
94- Import project
95- </ Button >
96- < Button className = "font-semibold" onClick = { ( ) => this . setState ( { createProject : true } ) } >
97- Create project
98- </ Button >
87+ return (
88+ < >
89+ < div className = "flex flex-col gap-4 w-screen h-screen p-5 select-none pt-10" >
90+ < div className = "flex flex-col gap-4 flex-[0_0_auto]" >
91+ < DashboardWindowControls />
92+
93+ < Fade delay = { 0 } >
94+ < div className = "flex justify-between items-end w-full mt-1" >
95+ < div className = "text-5xl font-semibold" > Dashboard</ div >
96+
97+ < div className = "flex flex-col items-end gap-2" >
98+ < img alt = "" src = "assets/babylonjs_icon.png" className = "w-[48px] object-contain" />
99+ < div className = "text-xs" > Babylon.js Editor v{ packageJson . version } </ div >
100+ </ div >
99101 </ div >
100- </ div >
101- </ Fade >
102+ </ Fade >
103+
104+ < Fade delay = { 250 } >
105+ < Separator />
106+ </ Fade >
107+
108+ < Fade delay = { 500 } >
109+ < div className = "flex justify-between items-center" >
110+ < div className = "text-3xl font-semibold" > Projects</ div >
111+
112+ < div className = "flex gap-2" >
113+ < Button variant = "secondary" className = "font-semibold" onClick = { ( ) => this . _handleImportProject ( ) } >
114+ Import project
115+ </ Button >
116+ < Button className = "font-semibold" onClick = { ( ) => this . setState ( { createProject : true } ) } >
117+ Create project
118+ </ Button >
119+ </ div >
120+ </ div >
121+ </ Fade >
122+ </ div >
102123
103- < Fade delay = { 750 } >
124+ < Fade delay = { 750 } className = "flex-auto overflow-y-auto p-2" >
104125 { ! this . state . projects . length && < div className = "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2" > No project found.</ div > }
105126
106127 { this . state . projects . length && (
@@ -110,16 +131,39 @@ export class Dashboard extends Component<IDashboardProps, IDashboardState> {
110131 project = { project }
111132 key = { project . absolutePath }
112133 isOpened = { this . state . openedProjects . includes ( project . absolutePath ) }
134+ closeDashboardOnProjectOpen = { this . state . closeDashboardOnProjectOpen }
113135 onRemove = { ( ) => this . _tryRemoveProjectFromLocalStorage ( project ) }
114136 />
115137 ) ) }
116138 </ div >
117139 ) }
118140 </ Fade >
141+
142+ < Fade delay = { 1000 } className = "flex-[0_0_auto]" >
143+ < div >
144+ < Separator />
145+ < div className = "flex justify-end pt-3 pb-1" >
146+ < TooltipProvider >
147+ < Tooltip >
148+ < TooltipTrigger className = "flex items-center gap-2 cursor-auto" >
149+ < Switch checked = { ! this . state . closeDashboardOnProjectOpen } onCheckedChange = { handleKeepDashboardChanged } />
150+ < span > Keep dashboard open</ span >
151+ </ TooltipTrigger >
152+ < TooltipContent align = "end" side = "top" collisionPadding = { 8 } >
153+ If enabled, the dashboard will stay open when a project starts.
154+ < br />
155+ If disabled, the dashboard will close when a project starts and reopen after the project is closed.
156+ </ TooltipContent >
157+ </ Tooltip >
158+ </ TooltipProvider >
159+ </ div >
160+ </ div >
161+ </ Fade >
119162 </ div >
120163
121164 < DashboardCreateProjectDialog
122165 isOpened = { this . state . createProject }
166+ closeDashboardOnProjectOpen = { this . state . closeDashboardOnProjectOpen }
123167 onClose = { ( ) => {
124168 this . setState ( {
125169 createProject : false ,
0 commit comments