89ff195c8d
If the user has permission to change a room's subject or name, they can now edit the text views displaying them (toward the top of the window). When enter is pressed, the changes will be sent to the protocol. To do this, a BTextView subclass was added to libinterface (splitting somewhat from SendTextView)― EnterTextView sends a message containing the text to the given target when the user hits enter sans modifiers.
82 lines
1.7 KiB
C++
82 lines
1.7 KiB
C++
/*
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
*/
|
|
|
|
#include "SendTextView.h"
|
|
|
|
#include <StringList.h>
|
|
#include <Window.h>
|
|
|
|
#include "AppMessages.h"
|
|
|
|
|
|
SendTextView::SendTextView(const char* name, ConversationView* convView)
|
|
:
|
|
EnterTextView(name),
|
|
fConversationView(convView),
|
|
fCurrentIndex(0)
|
|
{
|
|
SetMessage(BMessage(APP_CHAT));
|
|
SetTarget(convView);
|
|
}
|
|
|
|
|
|
void
|
|
SendTextView::KeyDown(const char* bytes, int32 numBytes)
|
|
{
|
|
int32 modifiers = Window()->CurrentMessage()->GetInt32("modifiers", 0);
|
|
|
|
if (bytes[0] == B_TAB) {
|
|
_AutoComplete();
|
|
return;
|
|
}
|
|
// Reset auto-complete state if user typed/sent something
|
|
fCurrentIndex = 0;
|
|
fCurrentWord.SetTo("");
|
|
|
|
if ((bytes[0] == B_ENTER) && (modifiers & B_COMMAND_KEY))
|
|
Insert("\n");
|
|
else
|
|
EnterTextView::KeyDown(bytes, numBytes);
|
|
}
|
|
|
|
|
|
void
|
|
SendTextView::_AutoComplete()
|
|
{
|
|
BStringList words;
|
|
BString text = Text();
|
|
text.Split(" ", true, words);
|
|
if (words.CountStrings() <= 0)
|
|
return;
|
|
BString lastWord = words.StringAt(words.CountStrings() - 1);
|
|
|
|
if (fCurrentWord.IsEmpty() == true)
|
|
fCurrentWord = lastWord;
|
|
|
|
// No command auto-completion (yet)
|
|
if (fCurrentWord.StartsWith("/") == true)
|
|
return;
|
|
|
|
BString user;
|
|
UserMap users = fConversationView->GetConversation()->Users();
|
|
for (int i, j = 0; i < users.CountItems(); i++)
|
|
if (users.KeyAt(i).StartsWith(fCurrentWord)) {
|
|
if (j == fCurrentIndex) {
|
|
user = users.KeyAt(i);
|
|
fCurrentIndex++;
|
|
break;
|
|
}
|
|
j++;
|
|
}
|
|
|
|
if (user.IsEmpty() == true)
|
|
fCurrentIndex = 0;
|
|
else {
|
|
text.ReplaceLast(lastWord.String(), user.String());
|
|
SetText(text.String());
|
|
Select(TextLength(), TextLength());
|
|
}
|
|
}
|