X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/fccb1dac95b0b61b3dd7eee539b7dda9c93004d7..5f2808af69256656fead748a8c5ee46f41177ce1:/js/ui/baseuiwindow.js diff --git a/js/ui/baseuiwindow.js b/js/ui/baseuiwindow.js index 112f6c5..84d337e 100644 --- a/js/ui/baseuiwindow.js +++ b/js/ui/baseuiwindow.js @@ -1,4 +1,9 @@ -var UIWindow = new Class({ +qwebirc.ui.HILIGHT_NONE = 0; +qwebirc.ui.HILIGHT_ACTIVITY = 1; +qwebirc.ui.HILIGHT_SPEECH = 2; +qwebirc.ui.HILIGHT_US = 3; + +qwebirc.ui.Window = new Class({ Implements: [Events], initialize: function(parentObject, client, type, name, identifier) { this.parentObject = parentObject; @@ -7,17 +12,22 @@ var UIWindow = new Class({ this.active = false; this.client = client; this.identifier = identifier; - this.hilighted = false; + this.hilighted = qwebirc.ui.HILIGHT_NONE; this.scrolltimer = null; this.commandhistory = this.parentObject.commandhistory; this.scrolleddown = true; - //new CommandHistory(); - }, - updateNickList: function(nicks) { + this.scrollpos = null; + this.lastNickHash = {}; + this.lastSelected = null; + this.subWindow = null; + this.closed = false; }, - updateTopic: function(topic) { + 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; @@ -26,17 +36,27 @@ var UIWindow = 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(false); - if(this.scrolleddown) - this.scrollToBottom(); + this.setHilighted(qwebirc.ui.HILIGHT_NONE); + + 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; @@ -44,21 +64,63 @@ var UIWindow = 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) { - if(!this.active && !this.hilighted) - this.setHilighted(true); - if(type) - line = this.parentObject.theme.message(type, line); + var hilight = qwebirc.ui.HILIGHT_NONE; + var lhilight = false; - Colourise(IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject)); + if(type) { + hilight = qwebirc.ui.HILIGHT_ACTIVITY; + + if(type.match(/(NOTICE|ACTION|MSG)$/)) { + 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; + this.parentObject.beep(); + } else if(hilight != qwebirc.ui.HILIGHT_US) { + hilight = qwebirc.ui.HILIGHT_SPEECH; + } + } + } + + if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE)) + this.setHilighted(hilight); + + if(type) + 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) { - this.hilighted = state; + if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) + this.hilighted = state; }, scrolledDown: function() { if(this.scrolltimer) @@ -76,12 +138,19 @@ var UIWindow = 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); }, @@ -102,8 +171,37 @@ var UIWindow = new Class({ this.scrolltimer = null; } }, + updateNickList: function(nicks) { + var nickHash = {}, present = {}; + var added = []; + var lnh = this.lastNickHash; + + for(var i=0;i