Skip to content
Snippets Groups Projects
Commit ad1145f5 authored by mcmlxxix's avatar mcmlxxix
Browse files

add home/end controls

remove frame.refresh() call from tree.addItem()
use frame.setData() to display menu (faster)
parent 21dcf57b
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
// display the frame contents // display the frame contents
frame.draw(); frame.draw();
*/ */
load("funclib.js"); load("funclib.js");
...@@ -75,6 +76,7 @@ function Tree(frame,text,tree) { ...@@ -75,6 +76,7 @@ function Tree(frame,text,tree) {
index:0, index:0,
text:"", text:"",
line:1, line:1,
list:[],
items:[] items:[]
}; };
...@@ -203,6 +205,12 @@ function Tree(frame,text,tree) { ...@@ -203,6 +205,12 @@ function Tree(frame,text,tree) {
case KEY_UP: case KEY_UP:
retval = moveUp(this.depth==0); retval = moveUp(this.depth==0);
break; break;
case KEY_HOME:
retval = home();
break;
case KEY_END:
retval = end();
break;
case "\r": case "\r":
if(properties.index >= 0) if(properties.index >= 0)
retval = this.current.action(); retval = this.current.action();
...@@ -241,7 +249,7 @@ function Tree(frame,text,tree) { ...@@ -241,7 +249,7 @@ function Tree(frame,text,tree) {
var args = Array.prototype.slice.apply(arguments); var args = Array.prototype.slice.apply(arguments);
var item=new TreeItem(args.shift(),this,args.shift(),args); var item=new TreeItem(args.shift(),this,args.shift(),args);
this.items.push(item); this.items.push(item);
this.refresh(); //this.refresh();
return item; return item;
} }
this.open = function() { this.open = function() {
...@@ -300,6 +308,12 @@ function Tree(frame,text,tree) { ...@@ -300,6 +308,12 @@ function Tree(frame,text,tree) {
} }
return false; return false;
} }
this.list = function(list) {
if(properties.parent)
properties.parent.list(list);
else
properties.list.push(list);
}
this.refresh=function() { this.refresh=function() {
if(properties.parent) { if(properties.parent) {
properties.parent.refresh(); properties.parent.refresh();
...@@ -308,8 +322,17 @@ function Tree(frame,text,tree) { ...@@ -308,8 +322,17 @@ function Tree(frame,text,tree) {
if(!this.frame) if(!this.frame)
return; return;
this.generate(); this.generate();
var offset = this.line - this.frame.height; var offset = 0;
this.frame.scrollTo(undefined,offset); if(this.line > this.frame.height)
offset = this.line-this.frame.height;
var output = properties.list.splice(offset,this.frame.height);
for(var y=0;y<output.length;y++) {
for(var x=0;x<output[y].length;x++) {
var d = output[y][x];
this.frame.setData(x,y,d.ch,d.attr,false);
}
}
properties.list=[];
} }
} }
...@@ -317,55 +340,78 @@ function Tree(frame,text,tree) { ...@@ -317,55 +340,78 @@ function Tree(frame,text,tree) {
this.generate=function(last,current,line) { this.generate=function(last,current,line) {
if(properties.status&flags.HIDDEN) if(properties.status&flags.HIDDEN)
return line; return line;
var list=[];
var bg;
var fg;
/* if this tree is the top level, initialize recursive shit */
if(this.depth == 0) { if(this.depth == 0) {
current = true; current = true;
line = 1; line = 1;
this.frame.clear();
this.frame.scrollTo(0,0);
} }
/* if this is a subtree, do stuff? */
else if(this.depth > 0) { else if(this.depth > 0) {
var str="";
/* set initial background color */ /* if this is the current item, set lightbar bg color */
if(current && properties.index == -1) { if(current) {
str+=getColor(this.colors.lbg); bg=this.colors.lbg;
this.line = line; this.line = line;
} }
/* otherwise use regular menu bg color */
else { else {
str+=getColor(this.colors.hbg); bg=this.colors.bg;
} }
/* add indentation on subtrees */ /* add indentation on subtrees */
str+=format("%-*s",this.depth-1,""); for(var i=0;i<this.depth-1;i++)
/* set color for expansion character */ list.push({ch:undefined,attr:bg+fg});
/* do not draw tree branches on top level tree */
if(this.depth == 1) if(this.depth == 1)
str+=" "; list.push({ch:undefined,attr:bg+fg});
else if(last) /* if this is the bottom of a subtree */
str+=getColor(this.colors.tfg)+"\xC0"; else if(last) {
else fg=this.colors.tfg;
str+=getColor(this.colors.tfg)+"\xC3"; list.push({ch:"\xC0",attr:bg+fg});
str+=getColor(this.colors.xfg); }
if(properties.status&flags.CLOSED) /* otherwise draw a right-hand tee for a tree item */
str+="+"; else {
else fg=this.colors.tfg;
str+="-"; list.push({ch:"\xC3",attr:bg+fg});
}
/* if this tree is disabled, use disabled fg */
if(properties.status&flags.DISABLED) if(properties.status&flags.DISABLED)
str+=getColor(this.colors.dfg); fg=this.colors.dfg;
else if(current && properties.index == -1) /* otherwise, if current? lightbar fg */
str+=getColor(this.colors.lfg); else if(current)
fg=this.colors.lfg;
/* normal menu fg */
else else
str+=getColor(this.colors.hfg); fg=this.colors.fg;
str+=properties.text;
str+=format("%-*s",this.frame.width-console.strlen(str),""); /* push text string into list */
this.frame.putmsg(str+"\r\n"); for(var i=0;i<properties.text.length;i++)
list.push({ch:properties.text[i],attr:bg+fg});
/* populate remaining characters as undefined */
for(var i=0;i<this.frame.width-list.length;i++)
list.push({ch:undefined,attr:bg+fg});
line++; line++;
this.list(list);
} }
/* if this tree is "open", list its items */
if(!(properties.status&flags.CLOSED)) { if(!(properties.status&flags.CLOSED)) {
for(var i in properties.items) { for(var i in properties.items) {
line = properties.items[i].generate( var l = (i == properties.items.length-1);
(i == properties.items.length-1), var c = (current && properties.index == i);
(current && properties.index == i), line = properties.items[i].generate(l,c,line);
line);
} }
} }
return line; return line;
} }
this.updateIndex=function(cmd) { this.updateIndex=function(cmd) {
...@@ -416,6 +462,20 @@ function Tree(frame,text,tree) { ...@@ -416,6 +462,20 @@ function Tree(frame,text,tree) {
} }
return false; return false;
} }
function home() {
if(properties.index == 0)
return false;
properties.index = 0;
return true;
}
function end() {
if(properties.index == properties.items.length-1)
return false;
if(!(properties.items[properties.index].status&flags.disabled))
return true;
properties.index = properties.items.length-1;
return true;
}
function matchHotkey(cmd) { function matchHotkey(cmd) {
if(!cmd.match(/\w/)) if(!cmd.match(/\w/))
return false; return false;
...@@ -450,9 +510,10 @@ function Tree(frame,text,tree) { ...@@ -450,9 +510,10 @@ function Tree(frame,text,tree) {
properties.frame=frame; properties.frame=frame;
properties.frame.attr = this.colors.bg + this.colors.fg; properties.frame.attr = this.colors.bg + this.colors.fg;
} }
if(text) if(text) {
properties.text = text; properties.text = text;
} }
}
init.apply(this,arguments); init.apply(this,arguments);
} }
...@@ -551,6 +612,9 @@ function TreeItem(text,parent,func,args) { ...@@ -551,6 +612,9 @@ function TreeItem(text,parent,func,args) {
this.refresh(); this.refresh();
return true; return true;
} }
this.list=function(str) {
properties.parent.list(str);
}
this.refresh=function() { this.refresh=function() {
properties.parent.refresh(); properties.parent.refresh();
} }
...@@ -559,32 +623,57 @@ function TreeItem(text,parent,func,args) { ...@@ -559,32 +623,57 @@ function TreeItem(text,parent,func,args) {
this.generate=function(last,current,line) { this.generate=function(last,current,line) {
if(properties.status&flags.HIDDEN) if(properties.status&flags.HIDDEN)
return line; return line;
var str="";
/* set initial background color */ var list=[];
var bg;
var fg;
/* if this is the current item, set lightbar bg color */
if(current) { if(current) {
str+=getColor(this.colors.lbg); bg=this.colors.lbg;
this.line = line; this.line = line;
} }
/* otherwise use regular menu bg color */
else { else {
str+=getColor(this.colors.bg); bg=this.colors.bg;
} }
/* add indentation on subtrees */ /* add indentation on subtrees */
str+=format("%-*s",this.depth-1,""); for(var i=0;i<this.depth-1;i++)
list.push({ch:undefined,attr:bg+fg});
/* do not draw tree branches on top level tree */
if(this.depth == 1) if(this.depth == 1)
str+=" "; list.push({ch:undefined,attr:bg+fg});
else if(last) /* if this is the bottom of a subtree */
str+=getColor(this.colors.tfg)+"\xC0"; else if(last) {
else fg=this.colors.tfg;
str+=getColor(this.colors.tfg)+"\xC3"; list.push({ch:"\xC0",attr:bg+fg});
}
/* otherwise draw a right-hand tee for a tree item */
else {
fg=this.colors.tfg;
list.push({ch:"\xC3",attr:bg+fg});
}
/* if this tree is disabled, use disabled fg */
if(properties.status&flags.DISABLED) if(properties.status&flags.DISABLED)
str+=getColor(this.colors.dfg); fg=this.colors.dfg;
/* otherwise, if current? lightbar fg */
else if(current) else if(current)
str+=getColor(this.colors.lfg); fg=this.colors.lfg;
/* normal menu fg */
else else
str+=getColor(this.colors.fg); fg=this.colors.fg;
str+=properties.text;
str+=format("%-*s",this.frame.width-console.strlen(str),""); /* push text string into list */
this.frame.putmsg(str+"\r\n"); for(var i=0;i<properties.text.length;i++)
list.push({ch:properties.text[i],attr:bg+fg});
/* populate remaining characters as undefined */
for(var i=0;i<this.frame.width-list.length;i++)
list.push({ch:undefined,attr:bg+fg});
this.list(list);
return ++line; return ++line;
} }
...@@ -602,3 +691,4 @@ function TreeItem(text,parent,func,args) { ...@@ -602,3 +691,4 @@ function TreeItem(text,parent,func,args) {
} }
init.apply(this,arguments); init.apply(this,arguments);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment