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

add delTab (by title or index) method to layout object, remove non-existant...

add delTab (by title or index) method to layout object, remove non-existant chat channels from view (if present), miscellaneous hackery to keep the display current.
parent 15ff7919
No related branches found
No related tags found
No related merge requests found
...@@ -227,6 +227,10 @@ function JSONChat(usernum,jsonclient,host,port) { ...@@ -227,6 +227,10 @@ function JSONChat(usernum,jsonclient,host,port) {
view.addTab(c.name,"chat",chat); view.addTab(c.name,"chat",chat);
} }
} }
for (var t = 0;t<view.tabs.length;t++) {
if(!chat.channels[view.tabs[t].title.toUpperCase()])
view.delTab(t--);
}
} }
/* constructor */ /* constructor */
......
...@@ -75,7 +75,7 @@ function Layout(frame) { ...@@ -75,7 +75,7 @@ function Layout(frame) {
/* private properties */ /* private properties */
var properties={ var properties={
views:[], views:[],
index:undefined index:0
}; };
var frames={ var frames={
main:undefined main:undefined
...@@ -191,8 +191,8 @@ function LayoutView(title,frame,parent) { ...@@ -191,8 +191,8 @@ function LayoutView(title,frame,parent) {
/* private properties */ /* private properties */
var properties={ var properties={
title:undefined, title:undefined,
index:undefined, index:0,
tabs:[] tabs:[],
} }
var relations={ var relations={
parent:undefined parent:undefined
...@@ -233,6 +233,9 @@ function LayoutView(title,frame,parent) { ...@@ -233,6 +233,9 @@ function LayoutView(title,frame,parent) {
this.__defineGetter__("frame",function() { this.__defineGetter__("frame",function() {
return frames.main; return frames.main;
}); });
this.__defineGetter__("tabs",function() {
return properties.tabs;
});
/* settings */ /* settings */
this.__defineGetter__("show_title",function() { this.__defineGetter__("show_title",function() {
...@@ -282,16 +285,15 @@ function LayoutView(title,frame,parent) { ...@@ -282,16 +285,15 @@ function LayoutView(title,frame,parent) {
return false; return false;
}); });
this.__defineSetter__("active",function(bool) { this.__defineSetter__("active",function(bool) {
if(typeof bool == "boolean") { if(typeof bool !== "boolean")
settings.active = bool; return false;
if(settings.active) settings.active = bool;
frames.title.attr = this.colors.title_bg+this.colors.title_fg; if(settings.active)
else frames.title.attr = this.colors.title_bg+this.colors.title_fg;
frames.title.attr = this.colors.inactive_title_bg + this.colors.inactive_title_fg; else
setTitle(); frames.title.attr = this.colors.inactive_title_bg + this.colors.inactive_title_fg;
return true; setTitle();
} return true;
return false;
}); });
/* public methods */ /* public methods */
...@@ -320,16 +322,49 @@ function LayoutView(title,frame,parent) { ...@@ -320,16 +322,49 @@ function LayoutView(title,frame,parent) {
var attr = this.colors.view_bg + this.colors.view_fg; var attr = this.colors.view_bg + this.colors.view_fg;
var f = new Frame(x,y,w,h,attr,frames.content); var f = new Frame(x,y,w,h,attr,frames.content);
var t = new ViewTab(title,f,this); var t = new ViewTab(title,f,this);
f.open();
setContent(t,type,content); setContent(t,type,content);
properties.tabs.push(t); properties.tabs.push(t);
if(this.current)
this.current.active=true;
setTabs();
return t; return t;
} }
this.getTabByName=function(title) { this.getTab=function(title_or_index) {
for each(var t in properties.tabs) { if(isNaN(title_or_index)) {
if(t.title.toUpperCase() == title.toUpperCase()) for each(var t in properties.tabs) {
return t; if(t.title.toUpperCase() == title.toUpperCase())
return t;
}
}
else {
return properties.tabs[title_or_index];
} }
} }
this.delTab=function(title_or_index) {
var tab = false;
if(isNaN(title_or_index)) {
for(var t=0;t<properties.tabs.length;t++) {
if(properties.tabs[t].title.toUpperCase() == title.toUpperCase()) {
tab = properties.tabs[t];
properties.tabs.splice(t,1);
}
}
}
else if(properties.tabs[title_or_index]) {
tab = properties.tabs[title_or_index];
properties.tabs.splice(title_or_index,1);
}
if(tab) {
tab.frame.delete();
while(!properties.tabs[properties.index] && properties.index > 0)
properties.index--;
if(this.current)
this.current.active=true;
setTabs();
}
return tab;
}
this.getcmd=function(cmd) { this.getcmd=function(cmd) {
if(!cmd) if(!cmd)
return false; return false;
...@@ -401,6 +436,10 @@ function LayoutView(title,frame,parent) { ...@@ -401,6 +436,10 @@ function LayoutView(title,frame,parent) {
} }
tab.cycle = function() { tab.cycle = function() {
var chan = this.chat.channels[this.title.toUpperCase()]; var chan = this.chat.channels[this.title.toUpperCase()];
if(!chan) {
this.parent.delTab(this.title);
return false;
}
while(chan.messages.length > 0) { while(chan.messages.length > 0) {
var msg = chan.messages.shift(); var msg = chan.messages.shift();
var str = ""; var str = "";
...@@ -412,6 +451,7 @@ function LayoutView(title,frame,parent) { ...@@ -412,6 +451,7 @@ function LayoutView(title,frame,parent) {
this.frame.putmsg(str + "\r\n"); this.frame.putmsg(str + "\r\n");
} }
} }
properties.chat = tab.chat;
break; break;
case "GRAPHIC": case "GRAPHIC":
//ToDo //ToDo
...@@ -591,16 +631,20 @@ function ViewTab(title,frame,parent) { ...@@ -591,16 +631,20 @@ function ViewTab(title,frame,parent) {
this.__defineGetter__("frame",function() { this.__defineGetter__("frame",function() {
return frames.main; return frames.main;
}); });
this.__defineSetter__("active",function(bool) { this.__defineGetter__("parent",function() {
if(typeof bool == "boolean") { return relations.parent;
settings.active = bool;
if(settings.active)
frames.main.top();
return true;
}
return false;
}); });
/* settings */
this.__defineSetter__("active",function(bool) {
if(typeof bool !== "boolean")
return false;
settings.active = bool;
if(settings.active)
frames.main.top();
return true;
});
/* default command handler /* default command handler
* (can be overridden for specialized tabs) */ * (can be overridden for specialized tabs) */
this.getcmd = function(cmd) { this.getcmd = function(cmd) {
...@@ -618,4 +662,3 @@ function ViewTab(title,frame,parent) { ...@@ -618,4 +662,3 @@ function ViewTab(title,frame,parent) {
} }
init.call(this,title,frame,parent); init.call(this,title,frame,parent);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment