Move sendbox to conversation view, replace filter
The BTextBox used for sending messages has been moved from the main window to individual ConversationViews, allowing seperate histories, texts, etc., to exist in different conversations. EditingFilter (a filter that hooked into MainWindow) was previously used to field special key combos with this textbox, including "ENTER" for sending, but this has been replaced with a new textview subclass (SendTextView).
This commit is contained in:
parent
352a6751da
commit
8a3f22d5e9
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Andrea Anzani, andrea.anzani@gmail.com
|
||||
*/
|
||||
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Message.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "AppMessages.h"
|
||||
#include "EditingFilter.h"
|
||||
|
||||
|
||||
EditingFilter::EditingFilter(BTextView* view)
|
||||
:
|
||||
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, B_KEY_DOWN, NULL),
|
||||
fView(view)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
filter_result
|
||||
EditingFilter::Filter(BMessage* message, BHandler** target)
|
||||
{
|
||||
int32 modifiers;
|
||||
|
||||
int8 byte;
|
||||
message->FindInt8("byte", &byte);
|
||||
|
||||
// If we have modifiers but none are the Alt key
|
||||
if (message->FindInt32("modifiers", &modifiers))
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
// If the Alt key jives with the command_enter status
|
||||
if ((modifiers & B_COMMAND_KEY) != 0 && byte == B_ENTER) {
|
||||
fView->Insert("\n");
|
||||
return B_SKIP_MESSAGE;
|
||||
} else if ((modifiers & B_COMMAND_KEY) == 0 && byte == B_ENTER) {
|
||||
fView->Window()->PostMessage(APP_CHAT);
|
||||
return B_SKIP_MESSAGE;
|
||||
}
|
||||
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _EDITING_FILTER_H
|
||||
#define _EDITING_FILTER_H
|
||||
|
||||
#include <MessageFilter.h>
|
||||
#include <TextView.h>
|
||||
|
||||
class EditingFilter : public BMessageFilter {
|
||||
public:
|
||||
EditingFilter(BTextView* view);
|
||||
|
||||
virtual filter_result Filter(BMessage* message, BHandler** target);
|
||||
|
||||
private:
|
||||
BTextView* fView;
|
||||
};
|
||||
|
||||
#endif // _EDITING_FILTER_H
|
|
@ -38,7 +38,6 @@ SRCS = \
|
|||
application/ChatCommand.cpp \
|
||||
application/Contact.cpp \
|
||||
application/Conversation.cpp \
|
||||
application/EditingFilter.cpp \
|
||||
application/ImageCache.cpp \
|
||||
application/Notifier.cpp \
|
||||
application/ProtocolLooper.cpp \
|
||||
|
@ -68,6 +67,7 @@ SRCS = \
|
|||
application/views/RosterItem.cpp \
|
||||
application/views/RosterListView.cpp \
|
||||
application/views/RosterView.cpp \
|
||||
application/views/SendTextView.cpp \
|
||||
application/views/StatusMenuItem.cpp \
|
||||
application/views/StatusView.cpp \
|
||||
application/views/TemplateView.cpp \
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "RenderView.h"
|
||||
#include "Conversation.h"
|
||||
#include "NotifyMessage.h"
|
||||
#include "SendTextView.h"
|
||||
#include "User.h"
|
||||
#include "UserItem.h"
|
||||
#include "UserListView.h"
|
||||
|
@ -40,6 +41,7 @@ ConversationView::ConversationView()
|
|||
{
|
||||
fMessageCount = 0;
|
||||
_InitInterface();
|
||||
fSendView->MakeFocus(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,7 +91,7 @@ ConversationView::MessageReceived(BMessage* message)
|
|||
switch (message->what) {
|
||||
case APP_CHAT:
|
||||
{
|
||||
BString text = message->FindString("body");
|
||||
BString text = fSendView->Text();
|
||||
if (text == "")
|
||||
return;
|
||||
int64 instance = fConversation->GetProtocolLooper()->GetInstance();
|
||||
|
@ -100,6 +102,8 @@ ConversationView::MessageReceived(BMessage* message)
|
|||
msg.AddString("chat_id", fConversation->GetId());
|
||||
msg.AddString("body", text);
|
||||
fConversation->ImMessage(&msg);
|
||||
|
||||
fSendView->SetText("");
|
||||
break;
|
||||
}
|
||||
case IM_MESSAGE:
|
||||
|
@ -277,10 +281,12 @@ ConversationView::ObserveString(int32 what, BString str)
|
|||
void
|
||||
ConversationView::_InitInterface()
|
||||
{
|
||||
fReceiveView = new RenderView("fReceiveView");
|
||||
fReceiveView = new RenderView("receiveView");
|
||||
BScrollView* scrollViewReceive = new BScrollView("receiveScrollView",
|
||||
fReceiveView, B_WILL_DRAW, false, true);
|
||||
|
||||
fSendView = new SendTextView("sendView", this);
|
||||
|
||||
fNameTextView = new BTextView("roomName", B_WILL_DRAW);
|
||||
fNameTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
fNameTextView->MakeEditable(false);
|
||||
|
@ -310,9 +316,13 @@ ConversationView::_InitInterface()
|
|||
.Add(fProtocolView)
|
||||
.End()
|
||||
.AddSplit(B_HORIZONTAL, 0)
|
||||
.Add(scrollViewReceive, 5)
|
||||
.AddGroup(B_VERTICAL, B_USE_HALF_ITEM_SPACING, 8)
|
||||
.Add(scrollViewReceive, 20)
|
||||
.Add(fSendView, 1)
|
||||
.End()
|
||||
.Add(scrollViewUsers, 1)
|
||||
.End();
|
||||
.End()
|
||||
.End();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class BTextView;
|
|||
|
||||
class BitmapView;
|
||||
class RenderView;
|
||||
class SendTextView;
|
||||
class User;
|
||||
class UserListView;
|
||||
|
||||
|
@ -62,8 +63,9 @@ private:
|
|||
BitmapView* fProtocolView;
|
||||
BitmapView* fIcon;
|
||||
|
||||
RenderView* fReceiveView;
|
||||
RenderView* fReceiveView;
|
||||
UserListView* fUserList;
|
||||
SendTextView* fSendView;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
#include "SendTextView.h"
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
#include "AppMessages.h"
|
||||
|
||||
|
||||
SendTextView::SendTextView(const char* name, ConversationView* convView)
|
||||
:
|
||||
BTextView(name),
|
||||
fConversationView(convView)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SendTextView::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
int32 modifiers = Window()->CurrentMessage()->GetInt32("modifiers", 0);
|
||||
|
||||
if ((bytes[0] == B_ENTER) && (modifiers & B_COMMAND_KEY))
|
||||
Insert("\n");
|
||||
else if (bytes[0] == B_ENTER)
|
||||
fConversationView->MessageReceived(new BMessage(APP_CHAT));
|
||||
else
|
||||
BTextView::KeyDown(bytes, numBytes);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
||||
* All rights reserved. Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef _SEND_TEXT_VIEW_H
|
||||
#define _SEND_TEXT_VIEW_H
|
||||
|
||||
#include <TextView.h>
|
||||
|
||||
#include "ConversationView.h"
|
||||
|
||||
|
||||
class SendTextView : public BTextView {
|
||||
public:
|
||||
SendTextView(const char* name, ConversationView* convView);
|
||||
|
||||
void KeyDown(const char* bytes, int32 numBytes);
|
||||
|
||||
private:
|
||||
ConversationView* fConversationView;
|
||||
};
|
||||
|
||||
|
||||
#endif // _SEND_TEXT_VIEW_H
|
|
@ -25,7 +25,6 @@
|
|||
#include "ConversationItem.h"
|
||||
#include "ConversationListView.h"
|
||||
#include "ConversationView.h"
|
||||
#include "EditingFilter.h"
|
||||
#include "MainWindow.h"
|
||||
#include "NotifyMessage.h"
|
||||
#include "PreferencesWindow.h"
|
||||
|
@ -55,8 +54,6 @@ MainWindow::MainWindow()
|
|||
AddFilter(fServer);
|
||||
|
||||
// Also through the editing filter (enter to send)
|
||||
AddCommonFilter(new EditingFilter(fSendView));
|
||||
fSendView->MakeFocus(true);
|
||||
|
||||
CenterOnScreen();
|
||||
|
||||
|
@ -208,13 +205,6 @@ MainWindow::MessageReceived(BMessage* message)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case APP_CHAT:
|
||||
{
|
||||
message->AddString("body", fSendView->Text());
|
||||
fChatView->MessageReceived(message);
|
||||
fSendView->SetText("");
|
||||
break;
|
||||
}
|
||||
case APP_DISABLE_ACCOUNT:
|
||||
_ToggleMenuItems();
|
||||
break;
|
||||
|
@ -337,7 +327,6 @@ MainWindow::SetConversation(Conversation* chat)
|
|||
float weightSend = fRightView->ItemWeight((int32)1);
|
||||
|
||||
fRightView->RemoveChild(fRightView->FindView("chatView"));
|
||||
fRightView->RemoveChild(fRightView->FindView("fSendScroll"));
|
||||
|
||||
if (chat != NULL) {
|
||||
fChatView = chat->GetView();
|
||||
|
@ -351,7 +340,6 @@ MainWindow::SetConversation(Conversation* chat)
|
|||
SetTitle(APP_NAME);
|
||||
|
||||
fRightView->AddChild(fChatView, 9);
|
||||
fRightView->AddChild(fSendScroll, 1);
|
||||
|
||||
// Apply saved chat and textbox size to new views
|
||||
if (weightChat * weightSend != 0) {
|
||||
|
@ -419,10 +407,6 @@ MainWindow::_InitInterface()
|
|||
// Right-side of window, Chat + Textbox
|
||||
fRightView = new BSplitView(B_VERTICAL, 0);
|
||||
fChatView = new ConversationView();
|
||||
fSendView = new BTextView("fSendView");
|
||||
fSendScroll = new BScrollView("fSendScroll", fSendView,
|
||||
B_WILL_DRAW, false, true);
|
||||
fSendView->SetWordWrap(true);
|
||||
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||
.Add((fMenuBar = _CreateMenuBar()))
|
||||
|
|
|
@ -68,8 +68,6 @@ private:
|
|||
|
||||
// Right panel, chat
|
||||
BSplitView* fRightView;
|
||||
BScrollView* fSendScroll;
|
||||
BTextView* fSendView;
|
||||
ConversationView* fChatView;
|
||||
Conversation* fConversation;
|
||||
};
|
||||
|
|
Ŝarĝante…
Reference in New Issue