Chat history in send textbox
History of sent messages is now saved― if the user presses the up or down arrows, history will be traversed in the textbox.
This commit is contained in:
parent
8855464d02
commit
2e3742d4e1
|
@ -13,12 +13,11 @@
|
|||
|
||||
SendTextView::SendTextView(const char* name, ConversationView* convView)
|
||||
:
|
||||
EnterTextView(name),
|
||||
BTextView(name),
|
||||
fConversationView(convView),
|
||||
fCurrentIndex(0)
|
||||
fCurrentIndex(0),
|
||||
fHistoryIndex(0)
|
||||
{
|
||||
SetMessage(BMessage(APP_CHAT));
|
||||
SetTarget(convView);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,14 +30,27 @@ SendTextView::KeyDown(const char* bytes, int32 numBytes)
|
|||
_AutoComplete();
|
||||
return;
|
||||
}
|
||||
// Reset auto-complete state if user typed/sent something
|
||||
// Reset auto-complete state if user typed/sent something other than tab
|
||||
fCurrentIndex = 0;
|
||||
fCurrentWord.SetTo("");
|
||||
|
||||
if ((bytes[0] == B_UP_ARROW) && (modifiers == 0)) {
|
||||
_UpHistory();
|
||||
return;
|
||||
}
|
||||
else if ((bytes[0] == B_DOWN_ARROW) && (modifiers == 0)) {
|
||||
_DownHistory();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bytes[0] == B_ENTER) && (modifiers & B_COMMAND_KEY))
|
||||
Insert("\n");
|
||||
else if ((bytes[0] == B_ENTER) && (modifiers == 0)) {
|
||||
_AppendHistory();
|
||||
fConversationView->MessageReceived(new BMessage(APP_CHAT));
|
||||
}
|
||||
else
|
||||
EnterTextView::KeyDown(bytes, numBytes);
|
||||
BTextView::KeyDown(bytes, numBytes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,3 +91,36 @@ SendTextView::_AutoComplete()
|
|||
Select(TextLength(), TextLength());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SendTextView::_AppendHistory()
|
||||
{
|
||||
fHistoryIndex = 0;
|
||||
fHistory.Add(BString(Text()), 0);
|
||||
if (fHistory.CountStrings() == 21)
|
||||
fHistory.Remove(20);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SendTextView::_UpHistory()
|
||||
{
|
||||
if (fHistoryIndex == 0 && TextLength() > 0)
|
||||
_AppendHistory();
|
||||
|
||||
if (fHistoryIndex < fHistory.CountStrings()) {
|
||||
fHistoryIndex++;
|
||||
SetText(fHistory.StringAt(fHistoryIndex - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SendTextView::_DownHistory()
|
||||
{
|
||||
if (fHistoryIndex > 1) {
|
||||
fHistoryIndex--;
|
||||
SetText(fHistory.StringAt(fHistoryIndex - 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
#ifndef _SEND_TEXT_VIEW_H
|
||||
#define _SEND_TEXT_VIEW_H
|
||||
|
||||
#include <libinterface/EnterTextView.h>
|
||||
#include <StringList.h>
|
||||
#include <TextView.h>
|
||||
|
||||
#include "ConversationView.h"
|
||||
|
||||
|
||||
class SendTextView : public EnterTextView {
|
||||
class SendTextView : public BTextView {
|
||||
public:
|
||||
SendTextView(const char* name, ConversationView* convView);
|
||||
|
||||
|
@ -19,10 +20,17 @@ public:
|
|||
private:
|
||||
void _AutoComplete();
|
||||
|
||||
void _AppendHistory();
|
||||
void _UpHistory();
|
||||
void _DownHistory();
|
||||
|
||||
ConversationView* fConversationView;
|
||||
|
||||
int32 fCurrentIndex;
|
||||
BString fCurrentWord;
|
||||
|
||||
BStringList fHistory;
|
||||
int32 fHistoryIndex;
|
||||
};
|
||||
|
||||
#endif // _SEND_TEXT_VIEW_H
|
||||
|
|
Ŝarĝante…
Reference in New Issue