]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/baseuiwindow.js
Inheritance tidying + tidying!
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
index ded43fda2bda65df0e0cfb0bdb05a178af9285cf..84d337e366c5a4460773093a87e272ca768ec018 100644 (file)
@@ -16,15 +16,18 @@ qwebirc.ui.Window = new Class({
     this.scrolltimer = null;
     this.commandhistory = this.parentObject.commandhistory;
     this.scrolleddown = true;
+    this.scrollpos = null;
     this.lastNickHash = {};
-    //new CommandHistory();
-  },
-  updateNickList: function(nicks) {
+    this.lastSelected = null;
+    this.subWindow = null;
+    this.closed = false;
   },
   updateTopic: function(topic, element)  {
     qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
   },
   close: function() {
+    this.closed = true;
+    
     if($defined(this.scrolltimer)) {
       $clear(this.scrolltimer);
       this.scrolltimer = null;
@@ -33,17 +36,27 @@ qwebirc.ui.Window = new Class({
     this.parentObject.__closed(this);
     this.fireEvent("close", this);
   },
+  subEvent: function(event) {
+    if($defined(this.subWindow))
+      this.subWindow.fireEvent(event);
+  },
+  setSubWindow: function(window) {
+    this.subWindow = window;
+  },
   select: function() {
     this.active = true;
     this.parentObject.__setActiveWindow(this);
     if(this.hilighted)
       this.setHilighted(qwebirc.ui.HILIGHT_NONE);
-    if(this.scrolleddown)
-      this.scrollToBottom();
+
+    this.subEvent("select");      
+    this.resetScrollPos();
+    this.lastSelected = new Date();
   },
   deselect: function() {
-    if(!this.parentObject.singleWindow)
-      this.scrolleddown = this.scrolledDown();
+    this.subEvent("deselect");
+    
+    this.setScrollPos();
     if($defined(this.scrolltimer)) {
       $clear(this.scrolltimer);
       this.scrolltimer = null;
@@ -51,17 +64,40 @@ qwebirc.ui.Window = new Class({
 
     this.active = false;
   },
+  resetScrollPos: function() {
+    if(this.scrolleddown) {
+      this.scrollToBottom();
+    } else if($defined(this.scrollpos)) {
+      this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
+    }
+  },
+  setScrollPos: function() {
+    if(!this.parentObject.singleWindow) {
+      this.scrolleddown = this.scrolledDown();
+      this.scrollpos = this.lines.getScroll();
+    }
+  },
   addLine: function(type, line, colour, element) {
     var hilight = qwebirc.ui.HILIGHT_NONE;
+    var lhilight = false;
+    
     if(type) {
       hilight = qwebirc.ui.HILIGHT_ACTIVITY;
       
       if(type.match(/(NOTICE|ACTION|MSG)$/)) {
-        if(this.type == qwebirc.ui.WINDOW_QUERY) {
-          hilight = qwebirc.ui.HILIGHT_US
-        } else if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
+        if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) {
+          if(type.match(/^OUR/) || type.match(/NOTICE$/)) {
+            hilight = qwebirc.ui.HILIGHT_ACTIVITY;
+          } else {
+            hilight = qwebirc.ui.HILIGHT_US;
+            this.parentObject.beep();
+          }
+        }
+        if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
+          lhilight = true;
           hilight = qwebirc.ui.HILIGHT_US;
-        } else {
+          this.parentObject.beep();
+        } else if(hilight != qwebirc.ui.HILIGHT_US) {
           hilight = qwebirc.ui.HILIGHT_SPEECH;
         }
       }
@@ -71,13 +107,16 @@ qwebirc.ui.Window = new Class({
       this.setHilighted(hilight);
 
     if(type)
-      line = this.parentObject.theme.message(type, line, hilight == qwebirc.ui.HILIGHT_US);
+      line = this.parentObject.theme.message(type, line, lhilight);
     
     qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
     this.scrollAdd(element);
   },
   errorMessage: function(message) {
-    this.addLine("", message, "red");
+    this.addLine("", message, "warncolour");
+  },
+  infoMessage: function(message) {
+    this.addLine("", message, "infocolour");
   },
   setHilighted: function(state) {
     if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
@@ -99,12 +138,19 @@ qwebirc.ui.Window = new Class({
       
     return prev.y + prevsize.y == prevbottom;
   },
-  scrollToBottom: function() {
-    var parent = this.lines;
-    var scrollparent = parent;
+  getScrollParent: function() {
+    var scrollparent = this.lines;
 
     if($defined(this.scroller))
       scrollparent = this.scroller;
+    return scrollparent;
+  },
+  scrollToBottom: function() {
+    if(this.type == qwebirc.ui.WINDOW_CUSTOM || this.type == qwebirc.ui.WINDOW_CONNECT)
+      return;
+
+    var parent = this.lines;
+    var scrollparent = this.getScrollParent();
       
     scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
   },
@@ -126,10 +172,17 @@ qwebirc.ui.Window = new Class({
     }
   },
   updateNickList: function(nicks) {
-    var nickHash = {};
+    var nickHash = {}, present = {};
     var added = [];
     var lnh = this.lastNickHash;
     
+    for(var i=0;i<nicks.length;i++)
+      present[nicks[i]] = 1;
+    
+    for(var k in lnh)
+      if(!present[k])
+        this.nickListRemove(k, lnh[k]);
+        
     for(var i=0;i<nicks.length;i++) {
       var n = nicks[i];
       var l = lnh[n];
@@ -141,10 +194,6 @@ qwebirc.ui.Window = new Class({
       nickHash[n] = l;
     }
     
-    for(var k in lnh)
-      if(!nickHash[k])
-        this.nickListRemove(k, lnh[k]);
-        
     this.lastNickHash = nickHash;
   },
   nickListAdd: function(position, nick) {
@@ -154,5 +203,5 @@ qwebirc.ui.Window = new Class({
   historyExec: function(line) {
     this.commandhistory.addLine(line);
     this.client.exec(line);
-  }
+  }  
 });