Patch by rossi, but I ended u rewriting half of it :
* Save terminal windows positions * Also save their size and workspace, but these aren't used (size is overriden by the menu setting and workspace is annoying) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38192 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include <Catalog.h>
|
||||
#include <Clipboard.h>
|
||||
#include <Catalog.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Locale.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Path.h>
|
||||
@@ -70,12 +72,14 @@ TermApp::TermApp()
|
||||
if (fWindowNumber > 0)
|
||||
fWindowTitle << " " << fWindowNumber;
|
||||
|
||||
int i = fWindowNumber / 16;
|
||||
int j = fWindowNumber % 16;
|
||||
int k = (j * 16) + (i * 64) + 50;
|
||||
int l = (j * 16) + 50;
|
||||
if (_LoadWindowPosition(&fTermFrame, &fTermWorkspaces) != B_OK) {
|
||||
int i = fWindowNumber / 16;
|
||||
int j = fWindowNumber % 16;
|
||||
int k = (j * 16) + (i * 64) + 50;
|
||||
int l = (j * 16) + 50;
|
||||
|
||||
fTermFrame.Set(k, l, k + 50, k + 50);
|
||||
fTermFrame.Set(k, l, k + 50, k + 50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +118,7 @@ TermApp::ReadyToRun()
|
||||
// init the mouse copy'n'paste clipboard
|
||||
gMouseClipboard = new BClipboard(MOUSE_CLIPBOARD_NAME, true);
|
||||
|
||||
status_t status = _MakeTermWindow(fTermFrame);
|
||||
status_t status = _MakeTermWindow(fTermFrame, fTermWorkspaces);
|
||||
|
||||
// failed spawn, print stdout and open alert panel
|
||||
// TODO: This alert does never show up.
|
||||
@@ -171,6 +175,10 @@ TermApp::MessageReceived(BMessage* msg)
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_SAVE_WINDOW_POSITION:
|
||||
_SaveWindowPosition(msg);
|
||||
break;
|
||||
|
||||
case MSG_CHECK_CHILDREN:
|
||||
_HandleChildCleanup();
|
||||
break;
|
||||
@@ -239,10 +247,101 @@ TermApp::RefsReceived(BMessage* message)
|
||||
|
||||
|
||||
status_t
|
||||
TermApp::_MakeTermWindow(BRect &frame)
|
||||
TermApp::_GetWindowPositionFile(BFile* file, uint32 openMode)
|
||||
{
|
||||
BPath path;
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status = path.Append("Terminal_windows");
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
return file->SetTo(path.Path(), openMode);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TermApp::_LoadWindowPosition(BRect* frame, uint32* workspaces)
|
||||
{
|
||||
status_t status = B_ERROR;
|
||||
BMessage position = BMessage();
|
||||
|
||||
BFile file;
|
||||
status = _GetWindowPositionFile(&file, B_READ_ONLY);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status = position.Unflatten(&file);
|
||||
|
||||
file.Unset();
|
||||
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
status = position.FindRect("rect", fWindowNumber - 1, frame);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
int32 _workspaces;
|
||||
status = position.FindInt32("workspaces", fWindowNumber - 1, &_workspaces);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
if (modifiers() & B_OPTION_KEY)
|
||||
*workspaces = _workspaces;
|
||||
|
||||
printf("loading settings ok\n");
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TermApp::_SaveWindowPosition(BMessage* position)
|
||||
{
|
||||
BFile file;
|
||||
BMessage originalSettings;
|
||||
|
||||
// We append ourself to the existing settings file
|
||||
// So we have to read it, insert our BMessage, and rewrite it.
|
||||
|
||||
status_t status = _GetWindowPositionFile(&file, B_READ_ONLY);
|
||||
if (status == B_OK) {
|
||||
originalSettings.Unflatten(&file);
|
||||
// No error checking on that : it fails if the settings
|
||||
// file is missing, but we can create it.
|
||||
|
||||
file.Unset();
|
||||
}
|
||||
|
||||
// Append the new settings
|
||||
BRect rect;
|
||||
position->FindRect("rect", &rect);
|
||||
if (originalSettings.ReplaceRect("rect", fWindowNumber - 1, rect) != B_OK)
|
||||
originalSettings.AddRect("rect", rect);
|
||||
|
||||
int32 workspaces;
|
||||
position->FindInt32("workspaces", &workspaces);
|
||||
if (originalSettings.ReplaceInt32("workspaces", fWindowNumber - 1, workspaces)
|
||||
!= B_OK)
|
||||
originalSettings.AddInt32("workspaces", workspaces);
|
||||
|
||||
// Resave the whole thing
|
||||
status = _GetWindowPositionFile (&file,
|
||||
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
|
||||
return originalSettings.Flatten(&file);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TermApp::_MakeTermWindow(BRect &frame, uint32 workspaces)
|
||||
{
|
||||
try {
|
||||
fTermWindow = new TermWindow(frame, fWindowTitle.String(), fArgs);
|
||||
fTermWindow = new TermWindow(frame, fWindowTitle.String(), workspaces,
|
||||
fArgs);
|
||||
} catch (int error) {
|
||||
return (status_t)error;
|
||||
} catch (...) {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <Application.h>
|
||||
#include <Catalog.h>
|
||||
#include <File.h>
|
||||
#include <String.h>
|
||||
|
||||
class Arguments;
|
||||
@@ -53,7 +54,10 @@ class TermApp : public BApplication {
|
||||
void ArgvReceived(int32 argc, char** argv);
|
||||
|
||||
private:
|
||||
status_t _MakeTermWindow(BRect& frame);
|
||||
status_t _MakeTermWindow(BRect& frame, uint32 workspaces);
|
||||
status_t _GetWindowPositionFile(BFile* file, uint32 openMode);
|
||||
status_t _LoadWindowPosition(BRect* frame, uint32* workspaces);
|
||||
status_t _SaveWindowPosition(BMessage* message);
|
||||
void _SwitchTerm();
|
||||
void _ActivateTermWindow(team_id id);
|
||||
bool _IsSwitchTarget(team_id id);
|
||||
@@ -73,9 +77,10 @@ class TermApp : public BApplication {
|
||||
bool fStartFullscreen;
|
||||
BString fWindowTitle;
|
||||
int32 fWindowNumber;
|
||||
|
||||
|
||||
BWindow* fTermWindow;
|
||||
BRect fTermFrame;
|
||||
uint32 fTermWorkspaces;
|
||||
Arguments *fArgs;
|
||||
};
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ const uint32 MSG_TERMINAL_BUFFER_CHANGED = 'bufc';
|
||||
const uint32 MSG_SET_TERMNAL_TITLE = 'sett';
|
||||
const uint32 MSG_QUIT_TERMNAL = 'qutt';
|
||||
const uint32 MSG_REPORT_MOUSE_EVENT = 'mous';
|
||||
const uint32 MSG_SAVE_WINDOW_POSITION = 'swps';
|
||||
|
||||
// Preference Read/Write Keys
|
||||
const char* const PREF_HALF_FONT_FAMILY = "Half Font Family";
|
||||
|
||||
@@ -135,10 +135,11 @@ private:
|
||||
};
|
||||
|
||||
|
||||
TermWindow::TermWindow(BRect frame, const char* title, Arguments* args)
|
||||
TermWindow::TermWindow(BRect frame, const char* title, uint32 workspaces,
|
||||
Arguments* args)
|
||||
:
|
||||
BWindow(frame, title, B_DOCUMENT_WINDOW,
|
||||
B_CURRENT_WORKSPACE | B_QUIT_ON_WINDOW_CLOSE),
|
||||
B_CURRENT_WORKSPACE | B_QUIT_ON_WINDOW_CLOSE, workspaces),
|
||||
fInitialTitle(title),
|
||||
fTabView(NULL),
|
||||
fMenubar(NULL),
|
||||
@@ -257,6 +258,11 @@ TermWindow::QuitRequested()
|
||||
return false;
|
||||
}
|
||||
|
||||
BMessage position = BMessage(MSG_SAVE_WINDOW_POSITION);
|
||||
position.AddRect("rect", Frame());
|
||||
position.AddInt32("workspaces", Workspaces());
|
||||
be_app->PostMessage(&position);
|
||||
|
||||
return BWindow::QuitRequested();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ class TermViewContainerView;
|
||||
|
||||
class TermWindow : public BWindow {
|
||||
public:
|
||||
TermWindow(BRect frame, const char* title, Arguments *args);
|
||||
TermWindow(BRect frame, const char* title, uint32 workspaces,
|
||||
Arguments *args);
|
||||
virtual ~TermWindow();
|
||||
|
||||
void SetSessionWindowTitle(TermView* termView,
|
||||
|
||||
Reference in New Issue
Block a user