@@ -6,6 +6,7 @@ Class.define("AppFileManager",{
66 proto : {
77 init : function ( context ) {
88
9+
910 var i = this . internal . AppFileManager . data = { } ;
1011 this . table = null ;
1112 var self = this ;
@@ -195,6 +196,15 @@ Class.define("AppFileManager",{
195196 . done ( function ( data ) {
196197 data = JSON . parse ( data ) ;
197198 if ( data . result ) {
199+ // delete in use
200+ if ( app . editor . fileSelected == file ) {
201+ app . editor . fileSelected = "" ;
202+ app . editor . main . setValue ( "" ) ;
203+ // disable notes too
204+ p . $ . title . elementSetPacket ( "[temporary]" ) ;
205+ closeNotes ( ) ;
206+
207+ }
198208 alert ( "file:'" + unescape ( file ) + "' removed!" ) ;
199209 refresh_server_files ( ) ;
200210 } else {
@@ -442,109 +452,94 @@ Class.define("AppFileManager",{
442452 self . server_files_placeholder = t . $ . elementPush ( "WithDOMElements2" ) ;
443453 function saveFile ( ) {
444454 // fileSelected is used because app.selected.path confuse with context menu use.
445-
446455 if ( app . editor . fileSelected != "" ) {
447- var str = app . editor . main . getValue ( ) ;
448- var dict = { 0 : "0" , 1 : "1" , 2 : "2" , 3 : "3" , 4 : "4" , 5 : "5" , 6 : "6" , 7 : "7" , 8 : "8" , 9 : "9" , 10 : "A" , 11 : "B" , 12 : "C" , 13 : "D" , 14 : "E" , 15 : "F" } ;
449- var sb = [ ] ;
450- for ( var x = 0 ; x < str . length ; x ++ ) {
451- var code = str . charCodeAt ( x ) ;
452- sb . push ( dict [ ( 0xF0 & code ) >> 4 ] + dict [ 0xF & code ] ) ;
453- }
454456
455- Import ( { method :"post" , url :"/file/update" , data :{ data : sb . join ( "" ) , file : escape ( app . editor . fileSelected ) } } )
457+ Import ( { method :"post" , url :"/file/update" , data :{ data : Export . Codec . Hex ( app . editor . main . getValue ( ) ) , file : escape ( app . editor . fileSelected ) } } )
456458 . done ( function ( response ) {
457-
458-
459459 alert ( response ) ;
460460 UI . Window . keyboard . ctrl = false ;
461461 } )
462462 . send ( ) ;
463+ } else {
464+ // choose path to save
465+ alert ( "todo, save a temporary file." ) ;
463466 }
464467 } ;
465468 function refresh_all_files ( ) {
466469 refresh_server_files ( ) ;
467470
468471
472+ }
473+ function openNotes ( ) {
474+ var titleHeight = 0 ;
475+ var adjust = 16 ;
476+ p . el . notesContainer . style . top = ( window . innerHeight - 57 - ( ( window . innerHeight - 40 - titleHeight - 70 - 50 ) ) + adjust ) + "px" ;
477+ var height = ( 38 + ( ( window . innerHeight - 40 - titleHeight - 70 - 50 ) ) - adjust ) ;
478+ p . el . notesContainer . style . height = height + "px" ;
479+ p . el . notesData . style . height = ( height - 50 ) + "px" ;
480+ p . el . notesData . style . border = "solid 1px #f00" ;
481+ p . el . notesData . style . overflowY = "auto" ;
482+ p . el . notesData . style . display = "" ;
483+
484+ if ( app . notes . id == "" ) {
485+ if ( app . editor . fileSelected != "" ) {
486+ loadNotes ( app . editor . fileSelected ) ;
487+ }
488+ } else {
489+ var context = {
490+ args : {
491+ view : "interact" ,
492+ id : app . notes . id
493+ }
494+ } ;
495+ p . $ . appNotes . elementsClear ( ) ;
496+ p . $ . appNotes . init ( context ) ;
497+ }
498+ // load notes
499+ app . notes . active = true ;
500+ }
501+ function closeNotes ( ) {
502+ p . el . notesContainer . style . top = ( window . innerHeight - 57 ) + "px" ;
503+ p . el . notesContainer . style . height = "38px" ;
504+ p . $ . notesData . elementsClear ( ) ;
505+ p . el . notesData . style . display = "none" ;
506+ app . notes . active = false ;
469507 }
470508 p . el . notesTitle . addEventListener ( "click" , function ( ) {
471509 if ( ! app . notes . active ) {
472- var titleHeight = 0 ;
473- var adjust = 16 ;
474- p . el . notesContainer . style . top = ( window . innerHeight - 57 - ( ( window . innerHeight - 40 - titleHeight - 70 - 50 ) ) + adjust ) + "px" ;
475- var height = ( 38 + ( ( window . innerHeight - 40 - titleHeight - 70 - 50 ) ) - adjust ) ;
476- p . el . notesContainer . style . height = height + "px" ;
477- p . el . notesData . style . height = ( height - 50 ) + "px" ;
478- p . el . notesData . style . border = "solid 1px #f00" ;
479- p . el . notesData . style . overflowY = "auto" ;
480- p . el . notesData . style . display = "" ;
510+ openNotes ( ) ;
511+ } else {
512+ closeNotes ( ) ;
513+ }
514+ } ) ;
515+ function loadNotes ( path ) {
516+
517+ Import ( { url :"/notes/create" , method :"post" , data :{
518+ title : "file" ,
519+ reference : path
520+ } } )
521+ . done ( function ( data ) {
522+
523+ data = JSON . parse ( data ) ;
524+ if ( data . result ) {
525+ app . notes . id = data . id ;
526+ app . notes . cache [ path ] = data . id ;
481527
482- if ( app . notes . id == "" ) {
483- if ( app . editor . fileSelected != "" ) {
484- loadNotes ( app . editor . fileSelected ) ;
485- }
486- } else {
487528 var context = {
488529 args : {
489530 view : "interact" ,
490- id : app . notes . id
531+ id : data . id
491532 }
492533 } ;
493534 p . $ . appNotes . elementsClear ( ) ;
494535 p . $ . appNotes . init ( context ) ;
536+
537+ } else {
538+ alert ( "failed to create a note." ) ;
495539 }
496- // load notes
497- app . notes . active = true ;
498- } else {
499- p . el . notesContainer . style . top = ( window . innerHeight - 57 ) + "px" ;
500- p . el . notesContainer . style . height = "38px" ;
501- p . $ . notesData . elementsClear ( ) ;
502- p . el . notesData . style . display = "none" ;
503- app . notes . active = false ;
504- }
540+ } )
541+ . send ( ) ;
505542
506- } ) ;
507- function loadNotes ( path ) {
508- if ( ! ( path in app . notes . cache ) ) {
509- Import ( { url :"/notes/create" , method :"post" , data :{
510- title : "file" ,
511- reference : path
512- } } )
513- . done ( function ( data ) {
514-
515- data = JSON . parse ( data ) ;
516- if ( data . result ) {
517- app . notes . id = data . id ;
518- app . notes . cache [ path ] = data . id ;
519-
520- var context = {
521- args : {
522- view : "interact" ,
523- id : data . id
524- }
525- } ;
526- p . $ . appNotes . elementsClear ( ) ;
527- p . $ . appNotes . init ( context ) ;
528-
529- } else {
530- alert ( "failed to create a note." ) ;
531- }
532- } )
533- . send ( ) ;
534- } else {
535- var id = app . notes . cache [ path ] ;
536- app . notes . id = id ;
537-
538- var context = {
539- args : {
540- view : "interact" ,
541- id : id
542- }
543- } ;
544- p . $ . appNotes . elementsClear ( ) ;
545- p . $ . appNotes . init ( context ) ;
546-
547- }
548543 }
549544 function loadFileOnEditor ( path ) {
550545 Import ( { url :"/load" , data :{ file :escape ( path ) } } )
@@ -669,7 +664,9 @@ Class.define("AppFileManager",{
669664 var td = tr . $ . elementPush ( "td_" + file , "td" , {
670665 class : { add : [ "groupDir" , "borderBottom" ] }
671666 } ) ;
672- td . $ . elementSetPacket ( "Server" ) ;
667+ td . el . style . display = "flex" ;
668+ td . el . style . cursor = "default" ;
669+ td . $ . elementSetPacket ( "<span style='flex:1;'>Server</span><span style='font-size:10px;'>(context menu)</span>" ) ;
673670 setContext ( td . el , "Server" , { sourceType : "server" , folder : true , path : "." } ) ;
674671
675672
0 commit comments