Exemple #1
0
        public void UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
        {
            TraceRemotingCall(groupChat, topic);

            MethodBase mb = Trace.GetMethodBase();

            Gtk.Application.Invoke(delegate {
                TraceRemotingCall(mb, groupChat, topic);

                try {
                    GroupChatView groupChatView = (GroupChatView)Frontend.MainWindow.Notebook.GetChat(groupChat);
                    if (groupChatView == null)
                    {
#if LOG4NET
                        _Logger.Fatal(
                            String.Format(
                                "UpdateTopicInGroupChat(): " +
                                "_ChatViewManager.GetChat(groupChat) " +
                                "groupChat.Name: {0} returned null!",
                                groupChat.Name
                                )
                            );
#endif
                        return;
                    }
                    groupChatView.Topic = topic;
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            });
        }
Exemple #2
0
        public void RemovePersonFromGroupChat(GroupChatModel groupChat, PersonModel person)
        {
            TraceRemotingCall(groupChat, person);

            MethodBase mb = Trace.GetMethodBase();

            Gtk.Application.Invoke(delegate {
                TraceRemotingCall(mb, groupChat, person);

                try {
                    GroupChatView groupChatView = (GroupChatView)_ChatViewManager.GetChat(groupChat);
                    if (groupChatView == null)
                    {
#if LOG4NET
                        _Logger.Fatal(
                            String.Format(
                                "RemovePersonFromGroupChat(): " +
                                "_ChatViewManager.GetChat(groupChat) " +
                                "groupChat.Name: {0} returned null!",
                                groupChat.Name
                                )
                            );
#endif
                        return;
                    }
                    groupChatView.RemovePerson(person);
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            });
        }
Exemple #3
0
        private void _NickCompletion()
        {
            // return if we don't support the current ChatView
            if (!(ChatViewManager.CurrentChatView is GroupChatView) &&
                !(ChatViewManager.CurrentChatView is PersonChatView))
            {
                return;
            }

            int    position = CursorPosition;
            string text     = Text;
            string word;
            int    previous_space;
            int    next_space;

            // find the current word
            string temp;

            temp           = text.Substring(0, position);
            previous_space = temp.LastIndexOf(' ');
            next_space     = text.IndexOf(' ', position);

#if LOG4NET
            _Logger.Debug("previous_space: " + previous_space);
            _Logger.Debug("next_space: " + next_space);
#endif

            if (previous_space != -1 && next_space != -1)
            {
                // previous and next space exist
                word = text.Substring(previous_space + 1, next_space - previous_space - 1);
            }
            else if (previous_space != -1)
            {
                // previous space exist
                word = text.Substring(previous_space + 1);
            }
            else if (next_space != -1)
            {
                // next space exist
                word = text.Substring(0, next_space);
            }
            else
            {
                // no spaces
                word = text;
            }

            if (word == String.Empty)
            {
                return;
            }

            bool leadingAt = false;
            // remove leading @ character
            if (word.StartsWith("@"))
            {
                word      = word.Substring(1);
                leadingAt = true;
            }

            // find the possible nickname
            bool   found         = false;
            bool   partial_found = false;
            string nick          = null;

            ChatView view = ChatViewManager.CurrentChatView;
            if (view is GroupChatView)
            {
                GroupChatView cp = (GroupChatView)view;
                if (Settings.BashStyleCompletion)
                {
                    IList <string> result = cp.PersonLookupAll(word);
                    if (result == null || result.Count == 0)
                    {
                        // no match
                    }
                    else if (result.Count == 1)
                    {
                        found = true;
                        nick  = result[0];
                    }
                    else if (result.Count >= 2)
                    {
                        string[] nickArray = new string[result.Count];
                        result.CopyTo(nickArray, 0);
                        string nicks = String.Join(" ", nickArray, 1, nickArray.Length - 1);
                        ChatViewManager.CurrentChatView.AddMessage(
                            new MessageModel(String.Format("-!- {0}", nicks))
                            );
                        found         = true;
                        partial_found = true;
                        nick          = result[0];
                    }
                }
                else
                {
                    PersonModel person = cp.PersonLookup(word);
                    if (person != null)
                    {
                        found = true;
                        nick  = person.IdentityName;
                    }
                }
            }
            else
            {
                var personChat  = (PersonChatView)ChatViewManager.CurrentChatView;
                var personModel = personChat.PersonModel;
                if (personModel.IdentityName.StartsWith(word,
                                                        StringComparison.InvariantCultureIgnoreCase))
                {
                    found = true;
                    nick  = personModel.IdentityName;
                }
            }

            string completionChar = Settings.CompletionCharacter;
            // add leading @ back and supress completion character
            if (leadingAt)
            {
                word           = String.Format("@{0}", word);
                nick           = String.Format("@{0}", nick);
                completionChar = String.Empty;
            }

            if (found)
            {
                // put the found nickname in place
                if (previous_space != -1 && next_space != -1)
                {
                    // previous and next space exist
                    temp = text.Remove(previous_space + 1, word.Length);
                    temp = temp.Insert(previous_space + 1, nick);
                    Text = temp;
                    if (partial_found)
                    {
                        Position = previous_space + 1 + nick.Length;
                    }
                    else
                    {
                        Position = previous_space + 2 + nick.Length;
                    }
                }
                else if (previous_space != -1)
                {
                    // only previous space exist
                    temp = text.Remove(previous_space + 1, word.Length);
                    temp = temp.Insert(previous_space + 1, nick);
                    if (partial_found)
                    {
                        Text = temp;
                    }
                    else
                    {
                        Text = temp + " ";
                    }
                    Position = previous_space + 2 + nick.Length;
                }
                else if (next_space != -1)
                {
                    // only next space exist
                    temp = text.Remove(0, next_space + 1);
                    if (partial_found)
                    {
                        Text     = nick + " " + temp;
                        Position = nick.Length;
                    }
                    else
                    {
                        Text = String.Format("{0}{1} {2}", nick,
                                             completionChar, temp);
                        Position = nick.Length + completionChar.Length + 1;
                    }
                }
                else
                {
                    // no spaces
                    if (partial_found)
                    {
                        Text = nick;
                    }
                    else
                    {
                        Text = String.Format("{0}{1} ", nick, completionChar);
                    }
                    Position = -1;
                }
            }
        }