@@ -7,7 +7,9 @@ import {instructions} from "./fetches.js";
77import { I18n } from "./i18n.js" ;
88import { Project } from "./projects/project.js" ;
99import { ProjFiles } from "./projects/projectFiles.js" ;
10+ import { getUserUpload } from "./utils/utils.js" ;
1011import "./ziputils/zip.js" ;
12+ import { CentDir , Zip } from "./ziputils/zip.js" ;
1113const actionRow = document . getElementById ( "actionRow" ) ;
1214if ( ! actionRow ) throw Error ( "action row not in document" ) ;
1315const cons = new Console ( ) ;
@@ -32,12 +34,14 @@ fileMenu.addButton(
3234 focusedEditor . save ( ) ;
3335 } ,
3436) ;
37+
3538fileMenu . addButton (
3639 ( ) => I18n . file . saveAll ( ) ,
3740 ( ) => {
3841 editors . map ( ( _ ) => _ . save ( ) ) ;
3942 } ,
4043) ;
44+
4145fileMenu . addButton (
4246 ( ) => I18n . file . saveAs ( ) ,
4347 ( ) => {
@@ -80,6 +84,57 @@ fileButton.textContent = I18n.file.file();
8084actionRow . append ( fileButton ) ;
8185fileMenu . bindContextmenu ( fileButton , undefined , undefined , true ) ;
8286
87+ const projectMenu = new Contextmenu ( "Project" ) ;
88+ projectMenu . addButton (
89+ ( ) => I18n . file . download ( ) ,
90+ ( ) => {
91+ projFile ?. pro . downloadProject ( ) ;
92+ } ,
93+ {
94+ visable : ( ) => ! ! projFile ,
95+ } ,
96+ ) ;
97+ projectMenu . addButton (
98+ ( ) => I18n . file . deleteProject ( ) ,
99+ async ( ) => {
100+ if ( curProject ) {
101+ if ( ! confirm ( I18n . confirmDeleteProject ( curProject . name ) ) ) {
102+ return ;
103+ }
104+
105+ await curProject . deleteProject ( ) ;
106+ openProject ( undefined ) ;
107+ }
108+ } ,
109+ {
110+ visable : ( ) => ! ! projFile ,
111+ } ,
112+ ) ;
113+ projectMenu . addButton (
114+ ( ) => I18n . file . import ( ) ,
115+ async ( ) => {
116+ const user = await getUserUpload ( "application/zip" ) ;
117+ if ( ! user ) return ;
118+ const zip = new Zip ( await user . arrayBuffer ( ) ) ;
119+ let fs = zip . fileStructure ;
120+ let entries = Object . entries ( fs ) ;
121+ let name = user . name . split ( "." ) [ 0 ] ;
122+ while ( entries . length === 1 && ! ( entries [ 0 ] [ 1 ] instanceof CentDir ) ) {
123+ fs = entries [ 0 ] [ 1 ] ;
124+ name = entries [ 0 ] [ 0 ] ;
125+ entries = Object . entries ( fs ) ;
126+ }
127+ const project = await Project . new ( name ) ;
128+ await zip . writeIntoDir ( project . dir . handle , fs ) ;
129+ openProject ( project ) ;
130+ } ,
131+ ) ;
132+
133+ const projectButton = document . createElement ( "button" ) ;
134+ projectButton . textContent = I18n . file . project ( ) ;
135+ actionRow . append ( projectButton ) ;
136+ projectMenu . bindContextmenu ( projectButton , undefined , undefined , true ) ;
137+
83138const menu = new Contextmenu ( "run" ) ;
84139
85140const assemble = document . getElementById ( "assemble" ) as HTMLElement ;
@@ -656,8 +711,16 @@ function downloadEditor(editor: Editor) {
656711}
657712let curProject : Project | undefined ;
658713let projFile : ProjFiles | undefined ;
659- async function openProject ( proj : Project ) {
714+ async function openProject ( proj ?: Project ) {
715+ if ( ! proj ) {
716+ curProject = undefined ;
717+ projFile = undefined ;
718+ editors = [ ] ;
719+ editArea ( ) ;
720+ return ;
721+ }
660722 curProject = proj ;
723+
661724 projFile = new ProjFiles ( proj ) ;
662725 projFile . addEventListener ( "open" , async ( e ) => {
663726 const editor = Editor . editMap . get ( `${ proj . name } :${ e . fileName } ` ) ;
0 commit comments