2
* Smuxi - Smart MUltipleXed Irc
4
* Copyright (c) 2005-2013 Mirco Bauer <meebey@meebey.net>
5
* Copyright (c) 2013 Ondra Hosek <ondra.hosek@gmail.com>
7
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
using System.Collections.Generic;
28
namespace Smuxi.Frontend
31
/// Automatically completes nicknames (e.g. when the user presses the Tab key).
33
public abstract class NickCompleter
35
public string CompletionChar = ":";
38
/// Isolates the nickname that should be completed.
40
/// <returns>The isolated nickname.</returns>
41
/// <param name="entryLine">The text currently typed into the input text box.</param>
42
/// <param name="cursorPosition">The current location of the cursor in the input text box.</param>
43
/// <param name="nickBeginning">Stores where the isolated nickname begins in the entered text.</param>
44
/// <param name="appendSpace">Whether to append a space when the nickname is completed.</param>
45
/// <param name="leadingAt">Whether the nickname started with a leading @ (which was stripped away).</param>
46
protected static string IsolateNickToComplete(string entryLine, int cursorPosition, out int nickBeginning, out bool appendSpace, out bool leadingAt)
49
int prev_space = entryLine.Substring(0, cursorPosition).LastIndexOf(' ');
50
int next_space = entryLine.IndexOf(' ', cursorPosition);
53
if (prev_space == -1 && next_space == -1) {
54
// no spaces (the nick is the only thing)
58
} else if (prev_space == -1) {
60
ret = entryLine.Substring(0, next_space);
61
} else if (next_space == -1) {
62
nickBeginning = prev_space + 1;
64
ret = entryLine.Substring(nickBeginning);
66
nickBeginning = prev_space + 1;
67
ret = entryLine.Substring(prev_space + 1, next_space - prev_space - 1);
71
if (ret.StartsWith("@")) {
74
ret = ret.Substring(1);
81
/// Returns a list containing only the nicknames matching the given prefix.
84
/// The (sorted) list of nicknames matching the given prefix.
86
/// <param name="persons">List of people to enumerate.</param>
87
/// <param name="prefix">Prefix of nicknames to return.</param>
88
protected static IList<string> NicksMatchingPrefix(IList<PersonModel> persons, string prefix)
90
var ret = new List<string>();
91
string lowerPfx = prefix.ToLower();
92
foreach (PersonModel person in persons) {
93
string nick = person.IdentityName;
94
if (nick.ToLower().StartsWith(lowerPfx)) {
103
/// Performs nickname tab completion on the specified input.
105
/// <param name="entryLine">The text currently typed into the input text box.</param>
106
/// <param name="cursorPosition">
107
/// The current location of the cursor in the input text box. Equal to the index of the
108
/// character after the current cursor position.
110
/// <param name="currentChatView">
111
/// The current chat view. The list of participants is fetched from it; the completer may
112
/// also append messages to the chat to provide further information.
114
abstract public void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView);