From 7abe9c7a3528782316b34328c8799c8e8f1933bb Mon Sep 17 00:00:00 2001 From: amy Date: Mon, 27 Feb 2023 20:47:08 +0000 Subject: woah i did stuff --- src/window-utils.js | 116 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 16 deletions(-) (limited to 'src/window-utils.js') diff --git a/src/window-utils.js b/src/window-utils.js index 40b5c62..4744f77 100644 --- a/src/window-utils.js +++ b/src/window-utils.js @@ -1,5 +1,5 @@ let util = { - context_menu(target,opt){ + context_menu(target,opt,other_targets=[]){ /* opt = {"menu":[ {"name":string, @@ -14,24 +14,64 @@ let util = { ! is optional */ - (()=>{ + function mm(){ target.oncontextmenu = ((ev)=>{ - console.log(ev) - try{document.getElementById(target.id+"-menu").remove()}catch(e){} + if(ev.target!=target&&other_targets.includes(ev.target)==false) + return + function clean(){ + try{document.getElementById(target.id+"-menu").remove()}catch(e){} + let nu = document.getElementsByClassName('context-menu-root') + for(let i = nu.length -1;i>=0;i--){ + nu.item(i).remove() + } + + } + if(!(window.contextm == null || window.contextm.tokill == null)){ + for(let i in window.contextm.tokill){ + window.contextm.tokill[i]() + + } + window.contextm.tokill = null + } + document.body.addEventListener("click",function tem(){ + clean() + document.body.removeEventListener("click",tem) + }) + + //console.log(ev) + clean() + //if(window.contextm == null || window.contextm.tokill == null){ + window.contextm = {} + if(opt.on_exit!=null) + window.contextm.tokill = [opt.on_exit] + //} else { + + //} let aa = "" for(let op of opt.menu){ - aa+=`
${op.name}
` + if(op=="seper") + aa+="
" + else if(op.allow_if == undefined || op.allow_if()) + aa+=`
${op.name}
` + else + aa+=`
${op.name}
` } - target.innerHTML += "
"+aa+"
" + appendHtml(target,"
"+aa+"
") for(let op of opt.menu){ + if(op!="seper"&&(op.allow_if == undefined || op.allow_if())) document.getElementById(`${target.id}-menu-${opt.menu.indexOf(op)}`).onclick = (()=>{ op.callback() }) } return false }) - })() + }; + mm() + return ({append:function append(items){ + opt.menu.push(items) + mm() + }}) }, scrollbar(uid,minor_uid,root,target){ (()=>{ @@ -41,12 +81,12 @@ let util = { //target is where the scrollbar will be placed, this element should be //larger than the root with scrollable overflow let scrolling = false - console.log(uid,minor_uid) + //console.log(uid,minor_uid) //try{document.getElementById(uid + "-" + minor_uid + "-content-scrollbar").remove()}catch(e){console.log(e)} if(undefined==procs[uid]) procs[uid] = {} - console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") - target.innerHTML += "
" + //console.log("'" + uid + "-" + minor_uid + "-content-scrollbar'") + appendHtml(target,"
") let thi_point = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar-point") let thi_base = document.getElementById(uid + "-" + minor_uid + "-content-scrollbar") procs[uid].refresh = ()=>{ @@ -166,6 +206,7 @@ let util = { window_create(i, "fs", "",{scroll:false}); let ll = await new jssh(fs, "/", i, "null", "null", window_create); async function load() { + refresh_windows() let fil = [] let tfs = ll.set_wd(ll.clean_path(inp.path)); @@ -213,7 +254,7 @@ let util = { } } }*/ - console.log(inp.path) + //console.log(inp.path) files+= "
"+bar_opt+"
" files += "
" files += "
" @@ -224,7 +265,7 @@ let util = { i + "-id-name-" + f.name + - "' style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + + "' style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + f.name + "
"; fil.push(f) @@ -235,7 +276,7 @@ let util = { i + "-id-name-" + f.name + - "'style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + + "'style='height:55px;position:relative;width:48px;display:inline-block;padding:10px;'>
" + f.name + "
"; fil.push(f) @@ -284,12 +325,25 @@ let util = { let ele = document.getElementById(i+"-fs-inner-cont") let ele_root = document.getElementById(i+"-content-content") - console.log(inp.path.split("/").filter(rem_emp)) + //console.log(inp.path.split("/").filter(rem_emp)) util.scrollbar(i,'root-bar',ele_root.parentElement,ele) - util.context_menu(ele,{menu:[ + let contmenu = util.context_menu(ele,{menu:[ {name:'new file',callback:()=>{ll.add_file(ll.fs,[...inp.path.split("/").filter(rem_emp),'untitled'],false);load()}}, {name:'new directory',callback:()=>{ll.add_file(ll.fs,[...inp.path.split("/").filter(rem_emp),'untitled'],true);load()}}, + "seper", + {name:'paste',callback:()=>{ + let lll = ll.set_wd((inp.path)) + ll.rem_file(fs,(inp.path + "/" +window.clipboard.path).split("/").filter(rem_emp)); + ll.add_file(fs,(inp.path + "/" +window.clipboard.path).split("/").filter(rem_emp),window.clipboard.dir); + for(let ooo of lll){ + if(ooo.name==window.clipboard.path) + ooo.content=window.clipboard.content; + } + + load()}, + allow_if:()=>{return(window.clipboard!=null&&window.clipboard.type=="file")}} ]}) + //contmenu.append(['seper']) //document.getElementById(i+"-fs-inner-cont").oncontextmenu = (ev) => { // return false //} @@ -332,7 +386,37 @@ let util = { } for (let f of fil) { let tt = document.getElementById(i + "-id-name-" + f.name); - //console.log(tt,f) + //console.log(tt.firstChild) + util.context_menu(tt,{menu:[ + {name:'rename',callback:()=>{ + for(let z in tt.children){ + if(tt.children.item(z).className=="file-name"){ + tt.children.item(z).innerHTML = "
" + tt.children.item(z).firstChild.onsubmit = (()=>{fil[fil.indexOf(f)].name=tt.children.item(z).firstChild.firstChild.value;load();return false}) + tt.children.item(z).firstChild.firstChild.focus() + break + } + } + }}, + {name:'copy',callback:()=>{ + window.clipboard = {type:"file",path:f.name,dir:f.dir,content:f.content} + + }}, + {name:'cut',callback:()=>{ + //console.log(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + window.clipboard = {type:"file",path:f.name,dir:f.dir,content:f.content} + ll.rem_file(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + //console.log(fs) + load() + + }}, + {name:'del',callback:()=>{ + ll.rem_file(fs,ll.clean_path(inp.path + "/" + f.name).split("/").filter(rem_emp)) + //console.log(fs) + load() + + }} + ],on_exit:()=>{for(let z in tt.children){tt.children.item(z).innerHTML = fil[fil.indexOf(f)].name} }},Array.from(tt.children)) let dou = false; tt.onclick = (ev) => { if (dou) { -- cgit v1.2.3