From b1b6854036607df8753533f0c4541de7c26857fd Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 18 Nov 2010 16:26:36 +0000 Subject: [PATCH] * Renamed the session ID to index. * Introduced class SessionID to uniquely identify a session. Unlike the indexes the IDs aren't reused. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39484 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermWindow.cpp | 62 ++++++++++++++++++++++++++++---- src/apps/terminal/TermWindow.h | 16 ++++++++- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index df56a70a01..c256067551 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -63,6 +63,9 @@ const static uint32 kUpdateTitles = 'UPti'; #define B_TRANSLATE_CONTEXT "Terminal TermWindow" +// #pragma mark - CustomTermView + + class CustomTermView : public TermView { public: CustomTermView(int32 rows, int32 columns, @@ -72,6 +75,9 @@ public: }; +// #pragma mark - TermViewContainerView + + class TermViewContainerView : public BView { public: TermViewContainerView(TermView* termView) @@ -100,23 +106,56 @@ private: }; +// #pragma mark - SessionID + + +TermWindow::SessionID::SessionID(int32 id) + : + fID(id) +{ +} + + +TermWindow::SessionID::SessionID(const BMessage& message, const char* field) + : + fID(-1) +{ + message.FindInt32(field, &fID); +} + + +status_t +TermWindow::SessionID::AddToMessage(BMessage& message, const char* field) const +{ + return message.AddInt32(field, fID); +} + + +// #pragma mark - Session + + struct TermWindow::Session { - int32 id; + SessionID id; + int32 index; Title title; TermViewContainerView* containerView; - Session(int32 id, TermViewContainerView* containerView) + Session(SessionID id, int32 index, TermViewContainerView* containerView) : id(id), + index(index), containerView(containerView) { title.title = B_TRANSLATE("Shell "); - title.title << id; + title.title << index; title.patternUserDefined = false; } }; +// #pragma mark - TermWindow + + TermWindow::TermWindow(BRect frame, const BString& title, bool isUserDefinedTitle, int32 windowIndex, uint32 workspaces, Arguments* args) @@ -125,6 +164,7 @@ TermWindow::TermWindow(BRect frame, const BString& title, B_CURRENT_WORKSPACE | B_QUIT_ON_WINDOW_CLOSE, workspaces), fWindowIndex(windowIndex), fTitleUpdateRunner(this, BMessage(kUpdateTitles), 1000000), + fNextSessionID(0), fTabView(NULL), fMenubar(NULL), fFilemenu(NULL), @@ -867,7 +907,8 @@ TermWindow::_AddTab(Arguments* args, const BString& currentDirectory) if (fSessions.IsEmpty()) fTabView->SetScrollView(scrollView); - Session* session = new Session(_NewSessionID(), containerView); + Session* session = new Session(_NewSessionID(), _NewSessionIndex(), + containerView); fSessions.AddItem(session); BFont font; @@ -1179,7 +1220,7 @@ TermWindow::_UpdateSessionTitle(int32 index) // evaluate the session title pattern BString sessionTitlePattern = session->title.patternUserDefined ? session->title.pattern : fSessionTitlePattern; - TabTitlePlaceholderMapper tabMapper(activeProcessInfo, session->id); + TabTitlePlaceholderMapper tabMapper(activeProcessInfo, session->index); const BString& sessionTitle = PatternEvaluator::Evaluate( sessionTitlePattern, tabMapper); @@ -1210,15 +1251,22 @@ TermWindow::_UpdateSessionTitle(int32 index) } -int32 +TermWindow::SessionID TermWindow::_NewSessionID() +{ + return fNextSessionID++; +} + + +int32 +TermWindow::_NewSessionIndex() { for (int32 id = 1; ; id++) { bool used = false; for (int32 i = 0; Session* session = (Session*)fSessions.ItemAt(i); i++) { - if (id == session->id) { + if (id == session->index) { used = true; break; } diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 30ee797bd7..778b4de2e6 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -85,6 +85,18 @@ private: bool patternUserDefined; }; + struct SessionID { + SessionID(int32 id); + SessionID(const BMessage& message, + const char* field); + + status_t AddToMessage(BMessage& message, + const char* field) const; + + private: + int32 fID; + }; + struct Session; void _SetTermColors(TermViewContainerView* termView); @@ -114,7 +126,8 @@ private: void _UpdateTitles(); void _UpdateSessionTitle(int32 index); - int32 _NewSessionID(); + SessionID _NewSessionID(); + int32 _NewSessionIndex(); private: Title fTitle; @@ -123,6 +136,7 @@ private: BMessageRunner fTitleUpdateRunner; BList fSessions; + int32 fNextSessionID; SmartTabView* fTabView; TermView* fTermView;