From 17ecdb5b2f88c22bb3271cdd77dc5c42a462c483 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 20 Nov 2009 20:34:03 +0000 Subject: [PATCH] TermView doesn't know about PrefHandler anymore (again), so that, in case it's used as replicant (but I think it won't work anymore, yet), it doesn't influence the global settings. TermWindow saves the preferences on quit, if the PrefWindow was never instantiated. This allows the window size to be saved also when it's resized manually (not via menu). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34165 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermView.cpp | 18 ++++++++++++++---- src/apps/terminal/TermView.h | 2 ++ src/apps/terminal/TermWindow.cpp | 21 ++++++++++++++++++++- src/apps/terminal/TermWindow.h | 1 + 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index c0487fe4c1..7dc56efc45 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -47,7 +47,6 @@ #include "CodeConv.h" #include "Globals.h" -#include "PrefHandler.h" #include "Shell.h" #include "TermConst.h" #include "TerminalCharClassifier.h" @@ -469,6 +468,20 @@ TermView::GetFontSize(int* _width, int* _height) } +int +TermView::Rows() const +{ + return fRows; +} + + +int +TermView::Columns() const +{ + return fColumns; +} + + //! Set number of rows and columns in terminal BRect TermView::SetTermSize(int rows, int columns, bool resize) @@ -479,9 +492,6 @@ TermView::SetTermSize(int rows, int columns, bool resize) if (columns > 0) fColumns = columns; - PrefHandler::Default()->setInt32(PREF_COLS, fColumns); - PrefHandler::Default()->setInt32(PREF_ROWS, fRows); - // To keep things simple, get rid of the selection first. _Deselect(); diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index a355c19735..225aa1e784 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -51,6 +51,8 @@ public: void SetTermFont(const BFont* font); void GetFontSize(int* width, int* height); + int Rows() const; + int Columns() const; BRect SetTermSize(int rows, int cols, bool resize); void SetTextColor(rgb_color fore, rgb_color back); diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 0b1050a738..f908a46ffe 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -162,9 +162,17 @@ TermWindow::TermWindow(BRect frame, const char* title, Arguments *args) TermWindow::~TermWindow() { + // If there's no prefwindow, save the preferences by ourselves. + // For example, this saves the columns/rows number. + // TODO: Code duplication. Exterminate if (fPrefWindow) fPrefWindow->PostMessage(B_QUIT_REQUESTED); - + else { + BPath path; + if (PrefHandler::GetDefaultPath(path) == B_OK) + PrefHandler::Default()->SaveAsText(path.Path(), PREFFILE_MIMETYPE); + } + if (fFindPanel && fFindPanel->Lock()) { fFindPanel->Quit(); fFindPanel = NULL; @@ -902,6 +910,17 @@ TermWindow::Zoom(BPoint leftTop, float width, float height) } +void +TermWindow::FrameResized(float newWidth, float newHeight) +{ + BWindow::FrameResized(newWidth, newHeight); + + TermView *view = _ActiveTermView(); + PrefHandler::Default()->setInt32(PREF_COLS, view->Columns()); + PrefHandler::Default()->setInt32(PREF_ROWS, view->Rows()); +} + + void TermWindow::_ResizeView(TermView *view) { diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 72b8703292..0656b6bb01 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -60,6 +60,7 @@ protected: virtual void WindowActivated(bool); virtual void MenusBeginning(); virtual void Zoom(BPoint leftTop, float width, float height); + virtual void FrameResized(float newWidth, float newHeight); private: struct Session;