Ticket #2389: rename-tab.diff
File rename-tab.diff, 7.3 KB (added by , 15 years ago) |
---|
-
src/apps/terminal/TermWindow.cpp
125 125 fWindow->_RemoveTab(index); 126 126 } 127 127 128 virtual void TabRenameFinished(int32 index) 129 { 130 SmartTabView::TabRenameFinished(index); 131 fWindow->UpdateSessionWindowTitle(index); 132 TabAt(Selection())->View()->MakeFocus(); 133 } 134 128 135 private: 129 136 TermWindow* fWindow; 130 137 }; … … 184 191 session->windowTitle = title; 185 192 BTab* tab = fTabView->TabAt(index); 186 193 tab->SetLabel(session->windowTitle.String()); 194 fTabView->Invalidate(fTabView->TabFrame(index)); 187 195 if (index == fTabView->Selection()) 188 196 SetTitle(session->windowTitle.String()); 189 197 } … … 200 208 201 209 202 210 void 211 TermWindow::UpdateSessionWindowTitle(int32 index) 212 { 213 Session* session = (Session*) fSessions.ItemAt(index); 214 if (session != NULL) { 215 session->windowTitle = fTabView->TabAt(index)->Label(); 216 if (index == fTabView->Selection()) 217 SetTitle(session->windowTitle.String()); 218 } 219 } 220 221 222 void 203 223 TermWindow::_InitWindow() 204 224 { 205 225 // make menu bar -
src/apps/terminal/SmartTabView.h
11 11 #include <TabView.h> 12 12 13 13 class BPopUpMenu; 14 class BTextControl; 14 15 class SmartTabView : public BTabView { 15 16 public: 16 SmartTabView(BRect frame, const char *name,17 button_width width = B_WIDTH_AS_USUAL,18 uint32 resizingMode = B_FOLLOW_ALL,19 uint32 flags = B_FULL_UPDATE_ON_RESIZE |20 B_WILL_DRAW | B_NAVIGABLE_JUMP |21 B_FRAME_EVENTS | B_NAVIGABLE);22 virtual ~SmartTabView();17 SmartTabView(BRect frame, const char *name, 18 button_width width = B_WIDTH_AS_USUAL, 19 uint32 resizingMode = B_FOLLOW_ALL, 20 uint32 flags = B_FULL_UPDATE_ON_RESIZE | 21 B_WILL_DRAW | B_NAVIGABLE_JUMP | 22 B_FRAME_EVENTS | B_NAVIGABLE); 23 virtual ~SmartTabView(); 23 24 24 void SetInsets(float left, float top, float right, float bottom);25 void SetInsets(float left, float top, float right, float bottom); 25 26 26 virtual void MouseDown(BPoint where);27 virtual void MouseDown(BPoint where); 27 28 28 virtual void AttachedToWindow();29 virtual void AllAttached();29 virtual void AttachedToWindow(); 30 virtual void AllAttached(); 30 31 31 virtual void MessageReceived(BMessage *message);32 virtual void MessageReceived(BMessage *message); 32 33 33 virtual void Select(int32 tab);34 virtual void Select(int32 tab); 34 35 35 virtual void RemoveAndDeleteTab(int32 index); 36 virtual void AddTab(BView *target, BTab *tab = NULL); 37 virtual void RenameTab(int32 index); 38 virtual void RemoveAndDeleteTab(int32 index); 39 virtual BTab* RemoveTab(int32 index); 36 40 37 virtual void AddTab(BView *target, BTab *tab = NULL); 38 virtual BTab* RemoveTab(int32 index); 41 virtual BRect DrawTabs(); 39 42 40 virtual BRect DrawTabs(); 43 protected: 44 virtual void TabRenameFinished(int32 index); 41 45 42 46 private: 43 int32_ClickedTabIndex(const BPoint &point);47 int32 _ClickedTabIndex(const BPoint &point); 44 48 45 private: 46 BRect fInsets;49 BRect fInsets; 50 BTextControl* fRenameTabControl; 47 51 }; 48 52 49 53 #endif // __SMARTTABVIEW_H -
src/apps/terminal/TermScrollView.cpp
58 58 TermScrollView::~TermScrollView() 59 59 { 60 60 } 61 62 63 void 64 TermScrollView::MakeFocus(bool focused) 65 { 66 BScrollView::MakeFocus(focused); 67 if (focused && fVerticalScrollBar != NULL 68 && fVerticalScrollBar->Target() != NULL) 69 fVerticalScrollBar->Target()->MakeFocus(focused); 70 } -
src/apps/terminal/TermWindow.h
54 54 void SetSessionWindowTitle(TermView* termView, 55 55 const char* title); 56 56 void SessionChanged(); 57 void UpdateSessionWindowTitle(int32 index); 57 58 58 59 protected: 59 60 virtual void MessageReceived(BMessage *message); -
src/apps/terminal/SmartTabView.cpp
13 13 #include <Messenger.h> 14 14 #include <PopUpMenu.h> 15 15 #include <Screen.h> 16 #include <TextControl.h> 16 17 #include <Window.h> 17 18 18 19 #include <stdio.h> 19 20 20 21 const static uint32 kCloseTab = 'ClTb'; 22 const static uint32 kTabRenamed = 'TbRn'; 21 23 22 24 SmartTabView::SmartTabView(BRect frame, const char *name, button_width width, 23 25 uint32 resizingMode, uint32 flags) 24 26 : 25 27 BTabView(frame, name, width, resizingMode, flags), 26 fInsets(0, 0, 0, 0) 28 fInsets(0, 0, 0, 0), 29 fRenameTabControl(NULL) 27 30 { 28 31 // Resize the container view to fill the complete tab view for single-tab 29 32 // mode. Later, when more than one tab is added, we shrink the container … … 59 62 if (tabIndex >= 0) { 60 63 int32 buttons; 61 64 Window()->CurrentMessage()->FindInt32("buttons", &buttons); 62 if (buttons & B_SECONDARY_MOUSE_BUTTON) { 65 if (buttons & B_PRIMARY_MOUSE_BUTTON) { 66 int32 clicks; 67 Window()->CurrentMessage()->FindInt32("clicks", &clicks); 68 if (clicks == 2) { 69 RenameTab(tabIndex); 70 handled = true; 71 } 72 } else if (buttons & B_SECONDARY_MOUSE_BUTTON) { 63 73 BMessage *message = new BMessage(kCloseTab); 64 74 message->AddInt32("index", tabIndex); 65 75 … … 108 118 RemoveAndDeleteTab(tabIndex); 109 119 break; 110 120 } 121 case kTabRenamed: 122 { 123 int32 tabIndex; 124 if (message->FindInt32("index", &tabIndex) != B_OK) 125 tabIndex = -1; 126 TabRenameFinished(tabIndex); 127 } 111 128 default: 112 129 BTabView::MessageReceived(message); 113 130 break; … … 200 217 } 201 218 202 219 220 void 221 SmartTabView::RenameTab(int32 index) 222 { 223 if (!Window()->LockLooper()) 224 return; 225 if (fRenameTabControl != NULL) 226 TabRenameFinished(-1); 227 228 BMessage *renamedMessage = new BMessage(kTabRenamed); 229 if (renamedMessage != NULL 230 && renamedMessage->AddInt32("index", index) == B_OK) { 231 fRenameTabControl = new BTextControl(TabFrame(index), "renameTab", NULL, 232 TabAt(index)->Label(), renamedMessage); 233 if (fRenameTabControl != NULL) { 234 fRenameTabControl->SetTarget(BMessenger(this)); 235 AddChild(fRenameTabControl); 236 fRenameTabControl->MakeFocus(); 237 } 238 } 239 240 Window()->UnlockLooper(); 241 } 242 243 244 void 245 SmartTabView::TabRenameFinished(int32 index) 246 { 247 if (!Window()->LockLooper()) 248 return; 249 250 if (fRenameTabControl != NULL) { 251 if (index >= 0) { 252 BTab* tab = TabAt(index); 253 if (tab != NULL) 254 tab->SetLabel(fRenameTabControl->Text()); 255 } 256 RemoveChild(fRenameTabControl); 257 delete fRenameTabControl; 258 fRenameTabControl = NULL; 259 } 260 261 Window()->UnlockLooper(); 262 } 263 264 203 265 BRect 204 266 SmartTabView::DrawTabs() 205 267 { -
src/apps/terminal/TermScrollView.h
14 14 BView* target, 15 15 uint32 resizingMode = B_FOLLOW_ALL); 16 16 ~TermScrollView(); 17 18 virtual void MakeFocus(bool focused = true); 17 19 }; 18 20 19 21