~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to src/Frontend-SWF/Entry.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        private int              _HistoryPosition;
48
48
        private bool             _HistoryChangedLine;
49
49
        private Notebook         _Notebook;
 
50
        private NickCompleter NickCompleter { get; set; }
50
51
        
51
52
        public  EventHandler     Activated;
52
53
        
204
205
                font = new Font(fontFamily, fontSize, style);
205
206
            }
206
207
            Font = font;
 
208
 
 
209
            // replace nick completer if needed
 
210
            bool wantBashCompletion = (bool)config["Interface/Entry/BashStyleCompletion"];
 
211
            if (wantBashCompletion && !(NickCompleter is LongestPrefixNickCompleter)) {
 
212
                NickCompleter = new LongestPrefixNickCompleter();
 
213
            } else if (!wantBashCompletion && !(NickCompleter is TabCycleNickCompleter)) {
 
214
                NickCompleter = new TabCycleNickCompleter();
 
215
            }
 
216
 
 
217
            // set the completion character
 
218
            NickCompleter.CompletionChar = (string)config["Interface/Entry/CompletionChar"];
 
219
 
207
220
        }
208
221
        
209
222
        public string HistoryCurrent()
670
683
        
671
684
        private void _NickCompletion()
672
685
        {
 
686
            // perform completion
 
687
            string text = Text;
673
688
            int position = SelectionStart;
674
 
            string text = Text;
675
 
            string word;
676
 
            int previous_space;
677
 
            int next_space;
678
 
 
679
 
            // find the current word
680
 
            string temp;
681
 
            temp = text.Substring(0, position);
682
 
            previous_space = temp.LastIndexOf(' ');
683
 
            next_space = text.IndexOf(' ', position);
684
 
 
685
 
#if LOG4NET
686
 
            _Logger.Debug("previous_space: "+previous_space);
687
 
            _Logger.Debug("next_space: "+next_space);
688
 
#endif
689
 
 
690
 
            if (previous_space != -1 && next_space != -1) {
691
 
                // previous and next space exist
692
 
                word = text.Substring(previous_space + 1, next_space - previous_space - 1);
693
 
            } else if (previous_space != -1) {
694
 
                // previous space exist
695
 
                word = text.Substring(previous_space + 1);
696
 
            } else if (next_space != -1) {
697
 
                // next space exist
698
 
                word = text.Substring(0, next_space);
699
 
            } else {
700
 
                // no spaces
701
 
                word = text;
702
 
            }
703
 
 
704
 
            if (word == String.Empty) {
705
 
                return;
706
 
            }
707
 
 
708
 
            // find the possible nickname
709
 
            bool found = false;
710
 
            bool partial_found = false;
711
 
            string nick = null;
712
 
            //GroupChatModel cp = (GroupChatModel) Frontend.FrontendManager.CurrentChat;
713
 
            GroupChatModel cp = (GroupChatModel) _Notebook.CurrentChatView.ChatModel;
714
 
            if ((bool)Frontend.UserConfig["Interface/Entry/BashStyleCompletion"]) {
715
 
                IList<string> result = cp.PersonLookupAll(word);
716
 
                if (result == null || result.Count == 0) {
717
 
                    // no match
718
 
                } else if (result.Count == 1) {
719
 
                    found = true;
720
 
                    nick = result[0];
721
 
                } else if (result.Count >= 2) {
722
 
                    string[] nickArray = new string[result.Count];
723
 
                    result.CopyTo(nickArray, 0);
724
 
                    string nicks = String.Join(" ", nickArray, 1, nickArray.Length - 1);
725
 
                    Frontend.FrontendManager.AddTextToChat(cp, "-!- " + nicks);
726
 
                    found = true;
727
 
                    partial_found = true;
728
 
                    nick = result[0];
729
 
                }
730
 
            } else {
731
 
                PersonModel person = cp.PersonLookup(word);
732
 
                if (person != null) {
733
 
                    found = true;
734
 
                    nick = person.IdentityName;
735
 
                 }
736
 
            }
737
 
 
738
 
            if (found) {
739
 
                // put the found nickname in place
740
 
                if (previous_space != -1 && next_space != -1) {
741
 
                    // previous and next space exist
742
 
                    temp = text.Remove(previous_space + 1, word.Length);
743
 
                    temp = temp.Insert(previous_space + 1, nick);
744
 
                    Text = temp;
745
 
                    if (partial_found) {
746
 
                        SelectionStart = previous_space + 1 + nick.Length;
747
 
                    } else {
748
 
                        SelectionStart = previous_space + 2 + nick.Length;
749
 
                    }
750
 
                } else if (previous_space != -1) {
751
 
                    // only previous space exist
752
 
                    temp = text.Remove(previous_space + 1, word.Length);
753
 
                    temp = temp.Insert(previous_space + 1, nick);
754
 
                    if (partial_found) {
755
 
                        Text = temp;
756
 
                    } else {
757
 
                        Text = temp+" ";
758
 
                    }
759
 
                    SelectionStart = previous_space + 2 + nick.Length;
760
 
                } else if (next_space != -1) {
761
 
                    // only next space exist
762
 
                    temp = text.Remove(0, next_space + 1);
763
 
                    if (partial_found) {
764
 
                        Text = nick + " " + temp;
765
 
                        SelectionStart = nick.Length;
766
 
                    } else {
767
 
                        Text = nick+(string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"] + " " + temp;
768
 
                        SelectionStart = nick.Length + 2;
769
 
                    }
770
 
                } else {
771
 
                    // no spaces
772
 
                    if (partial_found) {
773
 
                        Text = nick;
774
 
                    } else {
775
 
                        Text = nick+(string)Frontend.UserConfig["Interface/Entry/CompletionCharacter"]+" ";
776
 
                    }
777
 
                    SelectionStart = -1;
778
 
                }
779
 
            }
 
689
            NickCompleter.Complete(ref text, ref position, _Notebook.CurrentChatView);
 
690
            Text = text;
 
691
            SelectionStart = position;
780
692
        }
781
693
        
782
694
        private static string _(string msg)