Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HaikuArchives/ArmyKnife
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 71bd498c8bd1
Choose a base ref
...
head repository: HaikuArchives/ArmyKnife
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3b409aebfa0b
Choose a head ref
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Oct 30, 2021

  1. Save window settings on quit (#66)

    Saves window position, size and split view ratio on quit.
    Fixes #64
    humdinger authored Oct 30, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3b409ae View commit details
Showing with 57 additions and 32 deletions.
  1. +13 −5 source/appview.cpp
  2. +2 −1 source/appview.h
  3. +7 −20 source/appwindow.cpp
  4. +1 −3 source/appwindow.h
  5. +30 −0 source/preferences.cpp
  6. +4 −3 source/preferences.h
18 changes: 13 additions & 5 deletions source/appview.cpp
Original file line number Diff line number Diff line change
@@ -61,18 +61,19 @@ AppView::~AppView()
{
PRINT(("AppView::~AppView()\n"));

m_preferences->SetMode(m_pick_list_view->SelectedIndex());

delete m_preferences;
}

void
AppView::SaveWindowFrame()
AppView::SaveWindowSettings()
{
PRINT(("AppView::SaveWindowFrame()\n"));

BRect rect = Window()->Frame();
m_preferences->SetWindowFrame(rect);
float left = m_split_view->ItemWeight((int32)0);
float right = m_split_view->ItemWeight(1);
m_preferences->SetSplitWeights(left, right);
m_preferences->SetWindowFrame(Window()->Frame());
m_preferences->SetMode(m_pick_list_view->SelectedIndex());
}


@@ -157,6 +158,7 @@ AppView::InitView()
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_WINDOW_INSETS, 0, B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS)
.AddSplit(B_HORIZONTAL)
.GetSplitView(&m_split_view)
.Add(m_scroll_view_left)
.Add(m_scroll_view_right)
.End()
@@ -196,6 +198,12 @@ AppView::InitView()
}

SelectView(m_preferences->GetMode());

float left;
float right;
m_preferences->GetSplitWeights(&left, &right);
m_split_view->SetItemWeight(0, left, false);
m_split_view->SetItemWeight(1, right, true);
}

void // *******
3 changes: 2 additions & 1 deletion source/appview.h
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ class AppView : public BView
void SetPreviousMode();
void SetNextMode();

void SaveWindowFrame();
void SaveWindowSettings();

BButton* m_apply_button;

@@ -74,6 +74,7 @@ class AppView : public BView
BScrollView* m_scroll_view_right;
BScrollView* m_scroll_view_left;
BStringView* m_selected_string_view;
BSplitView* m_split_view;

BButton* m_reset_button;
BStatusBar* m_status_bar;
27 changes: 7 additions & 20 deletions source/appwindow.cpp
Original file line number Diff line number Diff line change
@@ -30,14 +30,10 @@
#include "guistrings.h"
#include "preferences.h"

#define WIN_LEFT 100
#define WIN_TOP 100
#define WIN_RIGHT 600
#define WIN_BOTTOM 700
#define WIN_MIN_WIDTH 550
#define WIN_MIN_HEIGHT 400

AppWindow::AppWindow() : BWindow(BRect(WIN_LEFT,WIN_TOP,WIN_RIGHT,WIN_BOTTOM),
AppWindow::AppWindow(BRect frame) : BWindow(frame,
WIN_TITLE,B_TITLED_WINDOW,B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
PRINT(("AppWindow::AppWindow()\n"));
@@ -159,8 +155,6 @@ AppWindow::InitWindow()
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(m_menu_bar)
.Add(m_app_view);

ResizeToPreferred();
}

void
@@ -319,23 +313,13 @@ AppWindow::MessageReceived(BMessage* message)
}
}

void
AppWindow::FrameMoved(BPoint point)
{
m_app_view->SaveWindowFrame();
}

void
AppWindow::FrameResized(float width, float height)
{
m_app_view->SaveWindowFrame();
}

bool
AppWindow::QuitRequested()
{
PRINT(("AppWindow::QuitRequested()\n"));

m_app_view->SaveWindowSettings();

thread_id addrefs = find_thread("AddRefs");
if(addrefs != B_NAME_NOT_FOUND)
{
@@ -398,7 +382,10 @@ AppWindow::CreateWindow()
}
else
{
win = new AppWindow();
Preferences prefs = Preferences();
BRect frame;
prefs.GetWindowFrame(&frame);
win = new AppWindow(frame);
}
return(win);
}
4 changes: 1 addition & 3 deletions source/appwindow.h
Original file line number Diff line number Diff line change
@@ -17,14 +17,12 @@ class Preferences;
class AppWindow : public BWindow
{
public:
AppWindow();
AppWindow(BRect frame);
AppWindow(BMessage* archive);
~AppWindow();
static AppWindow* CreateWindow();
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
virtual void FrameMoved(BPoint point);
virtual void FrameResized(float width, float height);

void DisableInterface();
void EnableInterface();
30 changes: 30 additions & 0 deletions source/preferences.cpp
Original file line number Diff line number Diff line change
@@ -163,6 +163,24 @@ Preferences::SetWindowFrame(BRect rect)
m_window_frame = rect;
}

void
Preferences::GetSplitWeights(float * left, float * right)
{
PRINT(("Preferences::GetSplitWeights()\n"));

*left = m_split_left;
*right = m_split_right;
}

void
Preferences::SetSplitWeights(float left, float right)
{
PRINT(("Preferences::SetSplitWeights()\n"));

m_split_left = left;
m_split_right = right;
}

void
Preferences::GetPreferences()
{
@@ -186,6 +204,8 @@ Preferences::GetPreferences()
int32 pattern = 0;
BMessage patterns;
BRect rect (200,200,700,600);
float left = 0;
float right = 0;

status = message.FindInt32("mode", &mode);
if(status == B_OK)
@@ -202,6 +222,14 @@ Preferences::GetPreferences()
status = message.FindRect("winframe", &rect);
if(status == B_OK)
m_window_frame = rect;

status = message.FindFloat("splitleft", &left);
if(status == B_OK)
m_split_left = left;

status = message.FindFloat("splitright", &right);
if(status == B_OK)
m_split_right = right;
}
else
PRINT(("Error: %s\n", strerror(status)));
@@ -217,6 +245,8 @@ Preferences::SavePreferences()
preferences.AddInt32("pattern", m_pattern);
preferences.AddMessage("patterns", & m_filename_patterns);
preferences.AddRect("winframe", m_window_frame);
preferences.AddFloat("splitleft", m_split_left);
preferences.AddFloat("splitright", m_split_right);

BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY,&path);
7 changes: 4 additions & 3 deletions source/preferences.h
Original file line number Diff line number Diff line change
@@ -36,7 +36,8 @@ class Preferences

void GetWindowFrame(BRect * rect);
void SetWindowFrame(BRect rect);

void GetSplitWeights(float * left, float * right);
void SetSplitWeights(float left, float right);
private:

void MakeDefaults();
@@ -45,8 +46,8 @@ class Preferences
int32 m_pattern;
BMessage m_filename_patterns;
BRect m_window_frame;


float m_split_left;
float m_split_right;
};

#endif