* Moved some locally used message constants from TermConst.h to TermWindow.cpp.

* Added an "Edit tab title..." item to the tab menu.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39514 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-11-19 15:24:33 +00:00
parent 486cd82188
commit ad617d3320
3 changed files with 70 additions and 44 deletions

View File

@ -93,8 +93,6 @@ static const uint32 MSG_REPORT_MOUSE_EVENT = 'mous';
static const uint32 MSG_SAVE_WINDOW_POSITION = 'swps';
static const uint32 MSG_MOVE_TAB_LEFT = 'mvtl';
static const uint32 MSG_MOVE_TAB_RIGHT = 'mvtr';
static const uint32 MSG_TAB_TITLE_CHANGED = 'ttch';
static const uint32 MSG_WINDOW_TITLE_CHANGED = 'wtch';
// Preference Read/Write Keys
static const char* const PREF_HALF_FONT_FAMILY = "Half Font Family";

View File

@ -53,13 +53,16 @@ const static int32 kMaxTabs = 6;
const static int32 kTermViewOffset = 3;
// messages constants
const static uint32 kNewTab = 'NTab';
const static uint32 kCloseView = 'ClVw';
const static uint32 kIncreaseFontSize = 'InFs';
const static uint32 kDecreaseFontSize = 'DcFs';
const static uint32 kSetActiveTab = 'STab';
const static uint32 kUpdateTitles = 'UPti';
const static uint32 kSetWindowTitle = 'SWti';
static const uint32 kNewTab = 'NTab';
static const uint32 kCloseView = 'ClVw';
static const uint32 kIncreaseFontSize = 'InFs';
static const uint32 kDecreaseFontSize = 'DcFs';
static const uint32 kSetActiveTab = 'STab';
static const uint32 kUpdateTitles = 'UPti';
static const uint32 kEditTabTitle = 'ETti';
static const uint32 kEditWindowTitle = 'EWti';
static const uint32 kTabTitleChanged = 'TTch';
static const uint32 kWindowTitleChanged = 'WTch';
#undef B_TRANSLATE_CONTEXT
@ -385,7 +388,7 @@ TermWindow::_SetupMenu()
.SetEnabled(false)
.AddSeparator()
.AddItem(B_TRANSLATE("Window title" B_UTF8_ELLIPSIS),
kSetWindowTitle)
kEditWindowTitle)
.End()
// Settings
@ -669,7 +672,7 @@ TermWindow::MessageReceived(BMessage *message)
message->what == MSG_MOVE_TAB_LEFT ? -1 : 1, true);
break;
case MSG_TAB_TITLE_CHANGED:
case kTabTitleChanged:
{
// tab title changed message from SetTitleDialog
SessionID sessionID(*message, "session");
@ -687,7 +690,7 @@ TermWindow::MessageReceived(BMessage *message)
break;
}
case MSG_WINDOW_TITLE_CHANGED:
case kWindowTitleChanged:
{
// window title changed message from SetTitleDialog
BString title;
@ -767,7 +770,15 @@ TermWindow::MessageReceived(BMessage *message)
_UpdateTitles();
break;
case kSetWindowTitle:
case kEditTabTitle:
{
SessionID sessionID(*message, "session");
if (Session* session = _SessionForID(sessionID))
_OpenSetTabTitleDialog(_IndexOfSession(session));
break;
}
case kEditWindowTitle:
_OpenSetWindowTitleDialog();
break;
@ -1126,32 +1137,8 @@ void
TermWindow::TabDoubleClicked(SmartTabView* tabView, BPoint point, int32 index)
{
if (index >= 0) {
// If a dialog is active, finish it.
_FinishTitleDialog();
BString toolTip = BString(B_TRANSLATE(
"The pattern specifying the current tab title. The following "
"placeholders\n"
"can be used:\n")) << kTooTipSetTabTitlePlaceholders;
fSetTabTitleDialog = new SetTitleDialog(
B_TRANSLATE("Set tab title"), B_TRANSLATE("Tab title:"),
toolTip);
Session* session = _SessionAt(index);
bool userDefined = session->title.patternUserDefined;
const BString& title = userDefined
? session->title.pattern : fSessionTitlePattern;
fSetTabTitleSession = session->id;
// place the dialog window directly under the tab, but keep it on screen
BPoint location = tabView->ConvertToScreen(
tabView->TabFrame(index).LeftBottom() + BPoint(0, 1));
BRect frame(fSetTabTitleDialog->Frame().OffsetToCopy(location));
BSize screenSize(BScreen(fSetTabTitleDialog).Frame().Size());
fSetTabTitleDialog->MoveTo(
BLayoutUtils::MoveIntoFrame(frame, screenSize).LeftTop());
fSetTabTitleDialog->Go(title, userDefined, this);
// clicked on a tab -- open the title dialog
_OpenSetTabTitleDialog(index);
} else {
// not clicked on a tab -- create a new one
_NewTab();
@ -1177,11 +1164,19 @@ TermWindow::TabRightClicked(SmartTabView* tabView, BPoint point, int32 index)
if (termView == NULL)
return;
BMessage* message = new BMessage(kCloseView);
_SessionAt(index)->id.AddToMessage(*message, "session");
BMessage* closeMessage = new BMessage(kCloseView);
_SessionAt(index)->id.AddToMessage(*closeMessage, "session");
BMessage* editTitleMessage = new BMessage(kEditTabTitle);
_SessionAt(index)->id.AddToMessage(*editTitleMessage, "session");
BPopUpMenu* popUpMenu = new BPopUpMenu("tab menu");
popUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Close tab"), message));
BLayoutBuilder::Menu<>(popUpMenu)
.AddItem(B_TRANSLATE("Close tab"), closeMessage)
.AddItem(B_TRANSLATE("Edit tab title" B_UTF8_ELLIPSIS),
editTitleMessage)
;
popUpMenu->SetAsyncAutoDestruct(true);
popUpMenu->SetTargetForItems(BMessenger(this));
@ -1224,7 +1219,7 @@ TermWindow::TitleChanged(SetTitleDialog* dialog, const BString& title,
{
if (dialog == fSetTabTitleDialog) {
// tab title
BMessage message(MSG_TAB_TITLE_CHANGED);
BMessage message(kTabTitleChanged);
fSetTabTitleSession.AddToMessage(message, "session");
if (titleUserDefined)
message.AddString("title", title);
@ -1232,7 +1227,7 @@ TermWindow::TitleChanged(SetTitleDialog* dialog, const BString& title,
PostMessage(&message);
} else if (dialog == fSetWindowTitleDialog) {
// window title
BMessage message(MSG_WINDOW_TITLE_CHANGED);
BMessage message(kWindowTitleChanged);
if (titleUserDefined)
message.AddString("title", title);
@ -1398,6 +1393,38 @@ TermWindow::_UpdateSessionTitle(int32 index)
}
void
TermWindow::_OpenSetTabTitleDialog(int32 index)
{
// If a dialog is active, finish it.
_FinishTitleDialog();
BString toolTip = BString(B_TRANSLATE(
"The pattern specifying the current tab title. The following "
"placeholders\n"
"can be used:\n")) << kTooTipSetTabTitlePlaceholders;
fSetTabTitleDialog = new SetTitleDialog(
B_TRANSLATE("Set tab title"), B_TRANSLATE("Tab title:"),
toolTip);
Session* session = _SessionAt(index);
bool userDefined = session->title.patternUserDefined;
const BString& title = userDefined
? session->title.pattern : fSessionTitlePattern;
fSetTabTitleSession = session->id;
// place the dialog window directly under the tab, but keep it on screen
BPoint location = fTabView->ConvertToScreen(
fTabView->TabFrame(index).LeftBottom() + BPoint(0, 1));
BRect frame(fSetTabTitleDialog->Frame().OffsetToCopy(location));
BSize screenSize(BScreen(fSetTabTitleDialog).Frame().Size());
fSetTabTitleDialog->MoveTo(
BLayoutUtils::MoveIntoFrame(frame, screenSize).LeftTop());
fSetTabTitleDialog->Go(title, userDefined, this);
}
void
TermWindow::_OpenSetWindowTitleDialog()
{

View File

@ -155,6 +155,7 @@ private:
void _TitleSettingsChanged();
void _UpdateTitles();
void _UpdateSessionTitle(int32 index);
void _OpenSetTabTitleDialog(int32 index);
void _OpenSetWindowTitleDialog();
void _FinishTitleDialog();