public ChatControl(ChatContext context) { _history = new LinkedList<string>(); this.Nicknames = new ObservableCollection<NicknameItem>(); this.Context = context; this.Header = context.Target == null ? "Server" : context.Target.ToString(); InitializeComponent(); this.SubscribeEvents(); if (!this.IsServer) { _logFile = App.OpenLogFile(context.Key); while (_logFile.Buffer.Count > 0) { var cl = _logFile.Buffer.Dequeue(); cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None; boxOutput.AppendLine(cl); } } var state = App.Settings.Current.Windows.States[context.Key]; if (this.IsChannel) { this.Write("Join", string.Format("Now talking on {0}", this.Target.Name)); this.Session.AddHandler(new IrcCodeHandler(IrcCode.ChannelModes, true, (msg) => { if (msg.Parameters.Count == 3 && this.Target.Equals(new IrcTarget(msg.Parameters[1]))) { this.Invoke(() => { _channelModes = msg.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray(); this.SetTitle(); }); return true; } return false; })); this.Session.Mode(this.Target); splitter.IsEnabled = true; colNickList.Width = new GridLength(state.NickListWidth); } else if (this.IsNickname) { _prefix = this.Target.Name; } boxOutput.ColumnWidth = state.ColumnWidth; this.Loaded += new RoutedEventHandler(ChatControl_Loaded); this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded); this.PrepareContextMenus(); boxOutput.ContextMenu = this.GetDefaultContextMenu(); }
public ChatControl(ChatPageType type, IrcSession session, IrcTarget target) : base(type, session, target, type == ChatPageType.Server ? "server" : (type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant())) { _history = new LinkedList<string>(); _nickList = new NicknameList(); InitializeComponent(); var state = App.Settings.Current.Windows.States[this.Id]; if (this.Type == ChatPageType.DccChat) { this.Header = string.Format("[CHAT] {0}", this.Target.Name); } else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server) { this.Header = this.Target == null ? "Server" : this.Target.ToString(); this.SubscribeEvents(); if (!this.IsServer) { _logFile = App.OpenLogFile(this.Id); var logLines = new List<ChatLine>(); while (_logFile.Buffer.Count > 0) { var cl = _logFile.Buffer.Dequeue(); cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None; logLines.Add(cl); } boxOutput.AppendBulkLines(logLines); } if (this.IsChannel) { colNickList.MinWidth = MinNickListWidth; colNickList.Width = new GridLength(state.NickListWidth); this.Write("Join", string.Format("Now talking on {0}", this.Target.Name)); this.Session.AddHandler(new IrcCodeHandler((e) => { if (e.Message.Parameters.Count > 2 && this.Target.Equals(new IrcTarget(e.Message.Parameters[1]))) { _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray(); this.SetTitle(); } e.Handled = true; return true; }, IrcCode.RPL_CHANNELMODEIS)); this.Session.Mode(this.Target); splitter.IsEnabled = true; var nameHandler = new IrcCodeHandler((e) => { if (e.Message.Parameters.Count >= 3) { var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]); if (this.Target.Equals(to)) { _nickList.AddRange(e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' '). Where((n) => n.Length > 0)); } } e.Handled = true; return false; }, IrcCode.RPL_NAMEREPLY); this.Session.AddHandler(nameHandler); this.Session.AddHandler(new IrcCodeHandler((e) => { this.Session.RemoveHandler(nameHandler); e.Handled = true; return true; }, IrcCode.RPL_ENDOFNAMES)); } else if (this.IsNickname) { _prefix = this.Target.Name; } } else { throw new ArgumentException("Page type is not supported."); } boxOutput.ColumnWidth = state.ColumnWidth; this.Loaded += new RoutedEventHandler(ChatControl_Loaded); this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded); this.PrepareContextMenus(); boxOutput.ContextMenu = this.GetDefaultContextMenu(); }
public ChatControl(ChatPageType type, IrcSession session, IrcTarget target) : base(type, session, target, type == ChatPageType.Server ? "server" : (type == ChatPageType.DccChat ? "dcc-chat" : string.Format("{0}.{1}", session.NetworkName, target.Name).ToLowerInvariant())) { _history = new LinkedList <string>(); this.Nicknames = new ObservableCollection <NicknameItem>(); InitializeComponent(); var state = App.Settings.Current.Windows.States[this.Id]; if (this.Type == ChatPageType.DccChat) { this.Header = string.Format("[CHAT] {0}", this.Target.Name); } else if (this.Type == ChatPageType.Chat || this.Type == ChatPageType.Server) { this.Header = this.Target == null ? "Server" : this.Target.ToString(); this.SubscribeEvents(); if (!this.IsServer) { _logFile = App.OpenLogFile(this.Id); var logLines = new List <ChatLine>(); while (_logFile.Buffer.Count > 0) { var cl = _logFile.Buffer.Dequeue(); cl.Marker = _logFile.Buffer.Count == 0 ? ChatMarker.OldMarker : ChatMarker.None; logLines.Add(cl); } boxOutput.AppendBulkLines(logLines); } if (this.IsChannel) { colNickList.MinWidth = MinNickListWidth; colNickList.Width = new GridLength(state.NickListWidth); this.Write("Join", string.Format("Now talking on {0}", this.Target.Name)); this.Session.AddHandler(new IrcCodeHandler((e) => { if (e.Message.Parameters.Count > 2 && this.Target.Equals(new IrcTarget(e.Message.Parameters[1]))) { _channelModes = e.Message.Parameters[2].ToCharArray().Where((c) => c != '+').ToArray(); this.SetTitle(); } e.Handled = true; return(true); }, IrcCode.RPL_CHANNELMODEIS)); this.Session.Mode(this.Target); splitter.IsEnabled = true; var nameHandler = new IrcCodeHandler((e) => { if (e.Message.Parameters.Count >= 3) { var to = new IrcTarget(e.Message.Parameters[e.Message.Parameters.Count - 2]); if (this.Target.Equals(to)) { foreach (var nick in e.Message.Parameters[e.Message.Parameters.Count - 1].Split(' ')) { this.AddNick(nick); } } } e.Handled = true; return(false); }, IrcCode.RPL_NAMEREPLY); this.Session.AddHandler(nameHandler); this.Session.AddHandler(new IrcCodeHandler((e) => { this.Session.RemoveHandler(nameHandler); e.Handled = true; return(true); }, IrcCode.RPL_ENDOFNAMES)); } else if (this.IsNickname) { _prefix = this.Target.Name; } } else { throw new ArgumentException("Page type is not supported."); } boxOutput.ColumnWidth = state.ColumnWidth; this.Loaded += new RoutedEventHandler(ChatControl_Loaded); this.Unloaded += new RoutedEventHandler(ChatControl_Unloaded); this.PrepareContextMenus(); boxOutput.ContextMenu = this.GetDefaultContextMenu(); }