Exemplo n.º 1
0
        private void NickComplete()
        {
            string afterComplete = FormMain.Instance.IceChatOptions.NickCompleteAfter.Replace("", ((char)3).ToString()).Replace("", ((char)2).ToString());

            if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Console)
            {
                //tab complete in Console, just send current nick
                if (parent.CurrentConnection != null)
                {
                    this.Text          += parent.CurrentConnection.ServerSetting.CurrentNickName;
                    this.SelectionStart = this.Text.Length;
                }
            }
            else if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Channel)
            {
                if (this.Text.Length == 0)
                {
                    return;
                }

                string boxText        = this.Text;
                int    selectionStart = this.SelectionStart;
                int    tabStart       = 0;

                if (boxText.EndsWith(afterComplete) && afterComplete.Length > 0)
                {
                    boxText        = boxText.Substring(0, boxText.Length - afterComplete.Length);
                    selectionStart = selectionStart - afterComplete.Length;
                }

                //get the partial nick
                if (boxText.IndexOf(' ') == -1)
                {
                    _partialNick = boxText;
                }
                else
                {
                    //at the end of the inputbox
                    if (selectionStart == boxText.Length)
                    {
                        _partialNick = boxText.Substring(boxText.LastIndexOf(' ') + 1);
                    }
                    else
                    {
                        tabStart     = boxText.Substring(0, selectionStart).LastIndexOf(' ') + 1;
                        _partialNick = boxText.Substring(tabStart, selectionStart - tabStart);
                        if (tabStart == 0)
                        {
                            tabStart = _partialNick.Length;
                        }
                    }
                }
                if (_partialNick.Length == 0)
                {
                    return;
                }

                //get the current window
                if (Array.IndexOf(FormMain.Instance.CurrentWindow.Connection.ServerSetting.ChannelTypes, _partialNick[0]) != -1)
                {
                    //channel name complete
                    this.Text           = this.Text.Substring(0, this.Text.Length - _partialNick.Length) + FormMain.Instance.CurrentWindow.TabCaption;
                    this.SelectionStart = this.Text.Length;
                    this._nickNumber    = -1;
                    return;
                }

                if (_nickNumber == -1)
                {
                    _nickCompleteNames.Clear();

                    foreach (User u in FormMain.Instance.CurrentWindow.Nicks.Values)
                    {
                        if (u.NickName.Length > _partialNick.Length)
                        {
                            if (u.NickName.Substring(0, _partialNick.Length).ToLower() == _partialNick.ToLower())
                            {
                                NickList.Nick n = new NickList.Nick();
                                n.nick  = u.NickName;
                                n.Level = u.Level;
                                _nickCompleteNames.Add(n);
                            }
                        }
                    }
                    if (_nickCompleteNames.Count == 0)
                    {
                        return;
                    }

                    _nickCompleteNames.Sort();

                    _nickNumber = 0;
                }
                else
                {
                    if (_nickCompleteNames.Count == 0)
                    {
                        _nickNumber = -1;
                        return;
                    }

                    _nickNumber++;

                    if (_nickNumber > (_nickCompleteNames.Count - 1))
                    {
                        _nickNumber = 0;
                    }
                }
                //add to the end of the box
                if (tabStart == 0)
                {
                    this.Text           = boxText.Substring(0, boxText.Length - _partialNick.Length) + _nickCompleteNames[_nickNumber] + afterComplete;
                    this.SelectionStart = this.Text.Length;
                }
                else
                {
                    string firstPart = boxText.Substring(0, selectionStart - _partialNick.Length) + _nickCompleteNames[_nickNumber];
                    this.Text           = firstPart + boxText.Substring(selectionStart);
                    this.SelectionStart = firstPart.Length;
                }
            }
            else if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Query || FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.DCCChat)
            {
                string boxText = this.Text;
                if (boxText.EndsWith(afterComplete) && afterComplete.Length > 0)
                {
                    boxText = boxText.Substring(0, boxText.Length - afterComplete.Length);
                }

                if (boxText.IndexOf(' ') == -1)
                {
                    _partialNick = boxText;
                }
                else
                {
                    _partialNick = boxText.Substring(boxText.LastIndexOf(' ') + 1);
                }

                if (_partialNick.Length == 0)
                {
                    this.Text += FormMain.Instance.CurrentWindow.TabCaption;
                }
                else
                {
                    this.Text = boxText.Substring(0, this.Text.Length - _partialNick.Length) + FormMain.Instance.CurrentWindow.TabCaption + afterComplete;
                }

                this.SelectionStart = this.Text.Length;
            }
        }
Exemplo n.º 2
0
        private void NickComplete()
        {
            string afterComplete = FormMain.Instance.IceChatOptions.NickCompleteAfter.Replace("", ((char)3).ToString()).Replace("", ((char)2).ToString());

            if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Console)
            {
                //tab complete in Console, just send current nick
                if (parent.CurrentConnection != null)
                {
                    this.Text += parent.CurrentConnection.ServerSetting.CurrentNickName;
                    this.SelectionStart = this.Text.Length;
                }
            }
            else if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Channel)
            {
                if (this.Text.Length == 0)
                    return;

                string boxText = this.Text;
                int selectionStart = this.SelectionStart;
                int tabStart = 0;

                if (boxText.EndsWith(afterComplete) && afterComplete.Length > 0)
                {
                    boxText = boxText.Substring(0, boxText.Length - afterComplete.Length);
                    selectionStart = selectionStart - afterComplete.Length;
                }

                //get the partial nick
                if (boxText.IndexOf(' ') == -1)
                    _partialNick = boxText;
                else
                {
                    //at the end of the inputbox
                    if (selectionStart == boxText.Length)
                        _partialNick = boxText.Substring(boxText.LastIndexOf(' ') + 1);
                    else
                    {
                        tabStart = boxText.Substring(0, selectionStart).LastIndexOf(' ') + 1;
                        _partialNick = boxText.Substring(tabStart, selectionStart - tabStart);
                        if (tabStart == 0)
                            tabStart = _partialNick.Length;
                    }
                }
                if (_partialNick.Length == 0)
                    return;

                //get the current window
                if (Array.IndexOf(FormMain.Instance.CurrentWindow.Connection.ServerSetting.ChannelTypes, _partialNick[0]) != -1)
                {
                    //channel name complete
                    this.Text = this.Text.Substring(0, this.Text.Length - _partialNick.Length) + FormMain.Instance.CurrentWindow.TabCaption;
                    this.SelectionStart = this.Text.Length;
                    this._nickNumber = -1;
                    return;
                }

                if (_nickNumber == -1)
                {
                    _nickCompleteNames.Clear();

                    foreach (User u in FormMain.Instance.CurrentWindow.Nicks.Values)
                    {
                        if (u.NickName.Length > _partialNick.Length)
                        {
                            if (u.NickName.Substring(0, _partialNick.Length).ToLower() == _partialNick.ToLower())
                            {
                                NickList.Nick n = new NickList.Nick();
                                n.nick = u.NickName;
                                n.Level = u.Level;
                                _nickCompleteNames.Add(n);
                            }
                        }
                    }
                    if (_nickCompleteNames.Count == 0)
                        return;

                    _nickCompleteNames.Sort();

                    _nickNumber = 0;
                }
                else
                {
                    if (_nickCompleteNames.Count == 0)
                    {
                        _nickNumber = -1;
                        return;
                    }

                    _nickNumber++;

                    if (_nickNumber > (_nickCompleteNames.Count - 1))
                        _nickNumber = 0;
                }
                //add to the end of the box
                if (tabStart == 0)
                {
                    this.Text = boxText.Substring(0, boxText.Length - _partialNick.Length) + _nickCompleteNames[_nickNumber] + afterComplete;
                    this.SelectionStart = this.Text.Length;
                }
                else
                {
                    string firstPart = boxText.Substring(0, selectionStart - _partialNick.Length) + _nickCompleteNames[_nickNumber];
                    this.Text = firstPart + boxText.Substring(selectionStart);
                    this.SelectionStart = firstPart.Length;
                }

            }
            else if (FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.Query || FormMain.Instance.CurrentWindowStyle == IceTabPage.WindowType.DCCChat)
            {
                string boxText = this.Text;
                if (boxText.EndsWith(afterComplete) && afterComplete.Length > 0)
                {
                    boxText = boxText.Substring(0, boxText.Length - afterComplete.Length);
                }

                if (boxText.IndexOf(' ') == -1)
                    _partialNick = boxText;
                else
                    _partialNick = boxText.Substring(boxText.LastIndexOf(' ') + 1);

                if (_partialNick.Length == 0)
                    this.Text += FormMain.Instance.CurrentWindow.TabCaption;
                else
                    this.Text = boxText.Substring(0, this.Text.Length - _partialNick.Length) + FormMain.Instance.CurrentWindow.TabCaption + afterComplete;

                this.SelectionStart = this.Text.Length;

            }
        }