Save account selection in account menus

This commit is contained in:
Jaidyn Ann 2021-07-28 10:13:31 -05:00
parent 758bbb072a
commit e33dd92375
5 changed files with 70 additions and 6 deletions

View File

@ -56,6 +56,7 @@ SRCS = \
application/preferences/PreferencesBehavior.cpp \ application/preferences/PreferencesBehavior.cpp \
application/preferences/PreferencesReplicant.cpp \ application/preferences/PreferencesReplicant.cpp \
application/views/AccountsMenu.cpp \ application/views/AccountsMenu.cpp \
application/views/AccountMenuItem.cpp \
application/views/RenderView.cpp \ application/views/RenderView.cpp \
application/views/ConversationAccountItem.cpp \ application/views/ConversationAccountItem.cpp \
application/views/ConversationItem.cpp \ application/views/ConversationItem.cpp \

View File

@ -0,0 +1,24 @@
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "AccountMenuItem.h"
#include "AccountsMenu.h"
AccountMenuItem::AccountMenuItem(const char* label, BMessage* msg)
:
BMenuItem(label, msg)
{
}
void
AccountMenuItem::SetMarked(bool mark)
{
BMenuItem::SetMarked(mark);
if (mark == true)
((AccountsMenu*)Menu())->SetDefaultSelection(this);
}

View File

@ -0,0 +1,18 @@
/*
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef _ACCOUNT_MENU_ITEM_H
#define _ACCOUNT_MENU_ITEM_H
#include <MenuItem.h>
class AccountMenuItem : public BMenuItem {
public:
AccountMenuItem(const char* label, BMessage* msg);
virtual void SetMarked(bool mark);
};
#endif // _ACCOUNT_MENU_ITEM_H

View File

@ -8,6 +8,7 @@
#include <Catalog.h> #include <Catalog.h>
#include <MenuItem.h> #include <MenuItem.h>
#include "AccountMenuItem.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "Server.h" #include "Server.h"
#include "TheApp.h" #include "TheApp.h"
@ -17,6 +18,9 @@
#define B_TRANSLATION_CONTEXT "AccountsMenu" #define B_TRANSLATION_CONTEXT "AccountsMenu"
int32 AccountsMenu::fDefaultSelection = 0;
AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg) AccountsMenu::AccountsMenu(const char* name, BMessage msg, BMessage* allMsg)
: :
BMenu(name), BMenu(name),
@ -48,6 +52,15 @@ AccountsMenu::ObserveInteger(int32 what, int32 value)
} }
void
AccountsMenu::SetDefaultSelection(BMenuItem* item)
{
fDefaultSelection = IndexOf(item);
if (fAllMessage != NULL)
fDefaultSelection--;
}
void void
AccountsMenu::_PopulateMenu() AccountsMenu::_PopulateMenu()
{ {
@ -66,10 +79,14 @@ AccountsMenu::_PopulateMenu()
label.RemoveChars(16, label.CountChars() - 16); label.RemoveChars(16, label.CountChars() - 16);
label << B_UTF8_ELLIPSIS; label << B_UTF8_ELLIPSIS;
} }
AddItem(new BMenuItem(label.String(), new BMessage(fAccountMessage))); AddItem(new AccountMenuItem(label.String(), new BMessage(fAccountMessage)));
} }
if (CountItems() > 0) int32 selection = fDefaultSelection;
if (fAllMessage == NULL && selection < CountItems() && selection >= 0)
ItemAt(selection)->SetMarked(true);
else if (CountItems() > 0)
ItemAt(0)->SetMarked(true); ItemAt(0)->SetMarked(true);
else else
SetEnabled(false); SetEnabled(false);

View File

@ -12,16 +12,20 @@
class AccountsMenu : public BMenu, public Observer { class AccountsMenu : public BMenu, public Observer {
public: public:
AccountsMenu(const char* name, BMessage msg, BMessage* allMsg = NULL); AccountsMenu(const char* name, BMessage msg,
~AccountsMenu(); BMessage* allMsg = NULL);
~AccountsMenu();
virtual void ObserveInteger(int32 what, int32 value); virtual void ObserveInteger(int32 what, int32 value);
void SetDefaultSelection(BMenuItem* item);
private: private:
void _PopulateMenu(); void _PopulateMenu();
BMessage fAccountMessage; BMessage fAccountMessage;
BMessage* fAllMessage; BMessage* fAllMessage;
static int32 fDefaultSelection;
}; };
#endif // _ACCOUNTS_MENU_H #endif // _ACCOUNTS_MENU_H