CHUI-105 WIP Minor code clean up and optimization.

Removed overloaded updateTitleButtons() and moved its functionality to a new method that should be called less frequently.
meow-7.2.2
Seth ProductEngine 2012-05-18 02:04:22 +03:00
parent 4fc8000d66
commit acbce32489
2 changed files with 61 additions and 68 deletions

View File

@ -65,6 +65,7 @@ LLIMFloater::LLIMFloater(const LLUUID& session_id)
mLastMessageIndex(-1),
mDialog(IM_NOTHING_SPECIAL),
mInputEditor(NULL),
mCloseBtn(NULL),
mExpandCollapseBtn(NULL),
mTearOffBtn(NULL),
mSavedTitle(),
@ -192,6 +193,8 @@ void LLIMFloater::onOpen(const LLSD& key)
// Show the messages pane when opening a floater hosted in the Conversations
host_floater->collapseMessagesPane(false);
}
updateHeaderAndToolbar();
}
// virtual
@ -308,7 +311,8 @@ BOOL LLIMFloater::postBuild()
boundVoiceChannel();
getChild<LLButton>("close_btn")->setCommitCallback(boost::bind(&LLFloater::onClickClose, this));
mCloseBtn = getChild<LLButton>("close_btn");
mCloseBtn->setCommitCallback(boost::bind(&LLFloater::onClickClose, this));
mExpandCollapseBtn = getChild<LLButton>("expand_collapse_btn");
mExpandCollapseBtn->setClickedCallback(boost::bind(&LLIMFloater::onSlide, this));
@ -328,7 +332,7 @@ BOOL LLIMFloater::postBuild()
}
mTearOffBtn = getChild<LLButton>("tear_off_btn");
mTearOffBtn->setCommitCallback(boost::bind(&LLFloater::onClickTearOff, this));
mTearOffBtn->setCommitCallback(boost::bind(&LLIMFloater::onTearOffClicked, this));
mInputEditor = getChild<LLLineEditor>("chat_editor");
mInputEditor->setMaxTextLength(1023);
@ -391,10 +395,11 @@ BOOL LLIMFloater::postBuild()
}
}
void LLIMFloater::onTearOffClicked(LLIMFloater* self)
void LLIMFloater::onTearOffClicked()
{
onClickTearOff(self);
updateTitleButtons();
onClickTearOff(this);
updateHeaderAndToolbar();
}
void LLIMFloater::boundVoiceChannel()
@ -1256,6 +1261,51 @@ void LLIMFloater::removeTypingIndicator(const LLIMInfo* im_info)
}
}
void LLIMFloater::updateHeaderAndToolbar()
{
bool is_hosted = getHost() != NULL;
if (is_hosted)
{
for (S32 i = 0; i < BUTTON_COUNT; i++)
{
if (!mButtons[i])
{
continue;
}
// Hide the standard header buttons in a docked IM floater.
mButtons[i]->setVisible(false);
}
}
// Display collapse image (<<) if the floater is hosted
// or if it is torn off but has an open control panel.
bool is_expanded = is_hosted || (mControlPanel && mControlPanel->getParent()->getVisible());
mExpandCollapseBtn->setImageOverlay(getString(is_expanded ? "collapse_icon" : "expand_icon"));
LLIMModel::LLIMSession* session = LLIMModel::instance().findIMSession(mSessionID);
if (session)
{
// The button (>>) should be disabled for torn off P2P conversations.
mExpandCollapseBtn->setEnabled(is_hosted || !session->isP2PSessionType());
}
else
{
llwarns << "IM session not found." << llendl;
}
if (mDragHandle)
{
// toggle floater's drag handle and title visibility
mDragHandle->setVisible(!is_hosted);
}
mTearOffBtn->setImageOverlay(getString(is_hosted ? "tear_off_icon" : "return_icon"));
mCloseBtn->setVisible(is_hosted);
}
// static
void LLIMFloater::closeHiddenIMToasts()
{
@ -1376,63 +1426,3 @@ void LLIMFloater::onClickCloseBtn()
LLFloater::onClickCloseBtn();
}
// virtual
void LLIMFloater::updateTitleButtons()
{
// This gets called before LLIMFloater::postBuild() while some LLIMFloater members are NULL
if ( !mDragHandle
//|| !mControlPanel
|| !mExpandCollapseBtn
|| !mTearOffBtn)
{
return;
}
bool is_hosted = getHost() != NULL;
if (is_hosted) ///< floater is hosted
{
for (S32 i = 0; i < BUTTON_COUNT; i++)
{
if (!mButtons[i])
{
continue;
}
// Hide the standard header buttons in a docked IM floater.
mButtons[i]->setVisible(false);
}
mExpandCollapseBtn->setImageOverlay(getString("collapse_icon"));
}
else ///< floater is torn off
{
LLFloater::updateTitleButtons();
if (mControlPanel)
{
bool is_expanded = mControlPanel->getParent()->getVisible();
mExpandCollapseBtn->setImageOverlay(getString(is_expanded ? "collapse_icon" : "expand_icon"));
}
}
getChild<LLButton>("close_btn")->setVisible(is_hosted);
LLIMModel::LLIMSession* session = LLIMModel::instance().findIMSession(mSessionID);
if (session)
{
mExpandCollapseBtn->setEnabled(is_hosted || !session->isP2PSessionType());
}
else
{
llwarns << "Empty session." << llendl;
return;
}
// toggle floater's drag handle and title visibility
mDragHandle->setVisible(!is_hosted);
mTearOffBtn->setImageOverlay(getString(is_hosted ? "tear_off_icon" : "return_icon"));
}

View File

@ -134,15 +134,12 @@ public:
protected:
/* virtual */ void onClickCloseBtn();
/* virtual */ void updateTitleButtons();
private:
// process focus events to set a currently active session
/* virtual */ void onFocusLost();
/* virtual */ void onFocusReceived();
void onTearOffClicked(LLIMFloater *self);
// Update the window title, input field help text, etc.
void updateSessionName(const std::string& ui_title, const std::string& ui_label);
@ -163,6 +160,8 @@ private:
static void* createPanelGroupControl(void* userdata);
static void* createPanelAdHocControl(void* userdata);
void onTearOffClicked();
bool onIMCompactExpandedMenuItemCheck(const LLSD& userdata);
bool onIMShowModesMenuItemCheck(const LLSD& userdata);
bool onIMShowModesMenuItemEnable(const LLSD& userdata);
@ -181,6 +180,9 @@ private:
// Remove the "User is typing..." indicator.
void removeTypingIndicator(const LLIMInfo* im_info = NULL);
/// Update floater header and toolbar buttons when hosted/torn off state is toggled.
void updateHeaderAndToolbar();
static void closeHiddenIMToasts();
static void confirmLeaveCallCallback(const LLSD& notification, const LLSD& response);
@ -212,6 +214,7 @@ private:
// connection to voice channel state change signal
boost::signals2::connection mVoiceChannelStateChangeConnection;
LLButton* mCloseBtn;
LLButton* mExpandCollapseBtn;
LLButton* mTearOffBtn;
};