diff --git a/application/CayaMessages.h b/application/CayaMessages.h index 4b50edf..c59ba3d 100644 --- a/application/CayaMessages.h +++ b/application/CayaMessages.h @@ -32,4 +32,10 @@ const uint32 CAYA_REPLICANT_EXIT = 'RPEX'; //! Show main window replicant notification const uint32 CAYA_REPLICANT_SHOW_WINDOW = 'CYSW'; +//! Select the upward conversation +const uint32 CAYA_MOVE_UP = 'CYmu'; + +//! Select the downward conversation +const uint32 CAYA_MOVE_DOWN = 'CYmd'; + #endif // _CAYA_MESSAGES_H diff --git a/application/Conversation.cpp b/application/Conversation.cpp index b04ff23..e286f4e 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -99,13 +99,6 @@ Conversation::ObserveInteger(int32 what, int32 val) } -void -Conversation::ShowView(bool typing, bool userAction) -{ - ((TheApp*)be_app)->GetMainWindow()->SetConversation(this); -} - - BMessenger Conversation::Messenger() const { @@ -134,13 +127,6 @@ Conversation::SetProtocolLooper(ProtocolLooper* looper) } -ConversationItem* -Conversation::GetConversationItem() -{ - return fConversationItem; -} - - BString Conversation::GetName() const { @@ -172,6 +158,13 @@ Conversation::AddUser(User* user) } +void +Conversation::ShowView(bool typing, bool userAction) +{ + ((TheApp*)be_app)->GetMainWindow()->SetConversation(this); +} + + ConversationView* Conversation::GetView() { @@ -193,6 +186,13 @@ Conversation::GetView() } +ConversationItem* +Conversation::GetListItem() +{ + return fConversationItem; +} + + void Conversation::_LogChatMessage(BMessage* msg) { diff --git a/application/Conversation.h b/application/Conversation.h index 439ed25..a6b7d4d 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -39,17 +39,16 @@ public: void ObserveInteger(int32 what, int32 value); void ObservePointer(int32 what, void* ptr); - ConversationView* GetView(); - - void ShowView(bool typing, bool userAction); - BMessenger Messenger() const; void SetMessenger(BMessenger messenger); ProtocolLooper* GetProtocolLooper() const; void SetProtocolLooper(ProtocolLooper* looper); - ConversationItem* GetConversationItem(); + void ShowView(bool typing, bool userAction); + + ConversationView* GetView(); + ConversationItem* GetListItem(); BString GetName() const; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 3aeaece..0f5dab6 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -39,6 +39,7 @@ MainWindow::MainWindow() : BWindow(BRect(0, 0, 300, 400), "Caya", B_TITLED_WINDOW, 0), fWorkspaceChanged(false), + fConversation(NULL), fRosterWindow(NULL) { _InitInterface(); @@ -110,6 +111,29 @@ MainWindow::MessageReceived(BMessage* message) break; } + case CAYA_MOVE_UP: + { + if (fConversation == NULL) + return; + + int32 index = fListView->IndexOf(fConversation->GetListItem()); + if (index > 0) + fListView->Select(index - 1); + break; + } + + case CAYA_MOVE_DOWN: + { + if (fConversation == NULL) + return; + + int32 index = fListView->IndexOf(fConversation->GetListItem()); + int32 count = fListView->CountItems(); + if (index < (count - 1)) + fListView->Select(index + 1); + break; + } + case CAYA_REPLICANT_STATUS_SET: { int32 status; @@ -256,8 +280,10 @@ MainWindow::SetConversation(Conversation* chat) fRightView->RemoveChild(fRightView->FindView("chatView")); fRightView->RemoveChild(fRightView->FindView("fSendScroll")); - if (chat != NULL) + if (chat != NULL) { fChatView = chat->GetView(); + fConversation = chat; + } fRightView->AddChild(fChatView, 9); fRightView->AddChild(fSendScroll, 1); @@ -323,8 +349,15 @@ MainWindow::_CreateMenuBar() new BMessage(CAYA_NEW_CHAT), 'M', B_COMMAND_KEY)); chatMenu->SetTargetForItems(this); + BMenu* windowMenu = new BMenu("Window"); + windowMenu->AddItem(new BMenuItem("Up", + new BMessage(CAYA_MOVE_UP), B_UP_ARROW, B_COMMAND_KEY)); + windowMenu->AddItem(new BMenuItem("Down", + new BMessage(CAYA_MOVE_DOWN), B_DOWN_ARROW, B_COMMAND_KEY)); + menuBar->AddItem(programMenu); menuBar->AddItem(chatMenu); + menuBar->AddItem(windowMenu); return menuBar; } @@ -338,13 +371,16 @@ MainWindow::_EnsureConversationItem(BMessage* msg) Conversation* chat = fServer->ConversationById(chat_id); if (chat != NULL) { - ConversationItem* item = chat->GetConversationItem(); + ConversationItem* item = chat->GetListItem(); if (fListView->HasItem(item)) { _UpdateListItem(item); } else if (item != NULL) { fListView->AddItem(item); } + + if (fListView->CountItems() == 1) + fListView->Select(0); return item; } diff --git a/application/MainWindow.h b/application/MainWindow.h index 7ef8827..12bdc2d 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -64,6 +64,7 @@ private: BScrollView* fSendScroll; BTextView* fSendView; ConversationView* fChatView; + Conversation* fConversation; }; diff --git a/application/views/ConversationListView.cpp b/application/views/ConversationListView.cpp index b1efa31..69514a0 100644 --- a/application/views/ConversationListView.cpp +++ b/application/views/ConversationListView.cpp @@ -52,9 +52,6 @@ ConversationListView::MouseDown(BPoint where) uint32 buttons = 0; Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); - if (buttons & B_PRIMARY_MOUSE_BUTTON) - MessageReceived(new BMessage(kOpenSelectedChat)); - if (!(buttons & B_SECONDARY_MOUSE_BUTTON)) return; @@ -65,6 +62,13 @@ ConversationListView::MouseDown(BPoint where) } +void +ConversationListView::SelectionChanged() +{ + MessageReceived(new BMessage(kOpenSelectedChat)); +} + + BPopUpMenu* ConversationListView::_ConversationPopUp() { diff --git a/application/views/ConversationListView.h b/application/views/ConversationListView.h index 9336888..6d56a9d 100644 --- a/application/views/ConversationListView.h +++ b/application/views/ConversationListView.h @@ -15,6 +15,7 @@ public: ConversationListView(const char* name); void MessageReceived(BMessage* msg); + void SelectionChanged(); void MouseDown(BPoint where); private: