FileTypes: save ApplicationTypeWindow position

* Move the default size and position settings for ApplicationTypeWindow from its constructor to FileTypesWindow::fSettings, and update these settings when the window is closed.
* Add _Frame() for extracting a BRect from fSettings.
* Keep a BPoint parameter in the constructor, which allows each new instance of the window to be slightly offset from the last one.
* Submitted in response to a comment by humdinger on https://review.haiku-os.org/c/haiku/+/4926

Change-Id: I0fa8a9ca8f18cf4093363bff713f0f80f6c04cd5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5164
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jim906 2022-03-29 14:03:19 -04:00 committed by Adrien Destugues
parent 7c3cd8fc3f
commit a12cf089ee
3 changed files with 83 additions and 65 deletions

View File

@ -298,10 +298,10 @@ SupportedTypeListView::AcceptsDrag(const BMessage* message)
// #pragma mark -
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position,
ApplicationTypeWindow::ApplicationTypeWindow(const BMessage& settings, BPoint offset,
const BEntry& entry)
:
BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position),
BWindow(_Frame(settings).OffsetBySelf(offset),
B_TRANSLATE("Application type"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS |
B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS),
@ -531,6 +531,15 @@ ApplicationTypeWindow::~ApplicationTypeWindow()
BMimeType::StopWatching(this);
}
BRect
ApplicationTypeWindow::_Frame(const BMessage& settings) const
{
BRect rect;
if (settings.FindRect("app_type_frame", &rect) == B_OK)
return rect;
return BRect(100.0f, 110.0f, 250.0f, 340.0f);
}
BString
ApplicationTypeWindow::_Title(const BEntry& entry)
@ -1076,6 +1085,10 @@ ApplicationTypeWindow::QuitRequested()
}
}
BMessage update(kMsgSettingsChanged);
update.AddRect("app_type_frame", Frame());
be_app_messenger.SendMessage(&update);
be_app->PostMessage(kMsgTypeWindowClosed);
return true;
}

View File

@ -25,81 +25,83 @@ class MimeTypeListView;
class ApplicationTypeWindow : public BWindow {
public:
ApplicationTypeWindow(BPoint position, const BEntry& entry);
virtual ~ApplicationTypeWindow();
public:
ApplicationTypeWindow(const BMessage& settings, BPoint offset,
const BEntry& entry);
virtual ~ApplicationTypeWindow();
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
private:
BString _Title(const BEntry& entry);
void _SetTo(const BEntry& entry);
void _UpdateAppFlagsEnabled();
void _MakeNumberTextControl(BTextControl* control);
void _Save();
private:
BRect _Frame(const BMessage& settings) const;
BString _Title(const BEntry& entry);
void _SetTo(const BEntry& entry);
void _UpdateAppFlagsEnabled();
void _MakeNumberTextControl(BTextControl* control);
void _Save();
bool _Flags(uint32& flags) const;
BMessage _SupportedTypes() const;
version_info _VersionInfo() const;
bool _Flags(uint32& flags) const;
BMessage _SupportedTypes() const;
version_info _VersionInfo() const;
void _CheckSaveMenuItem(uint32 flags);
uint32 _NeedsSaving(uint32 flags) const;
void _CheckSaveMenuItem(uint32 flags);
uint32 _NeedsSaving(uint32 flags) const;
private:
struct AppInfo {
BString signature;
bool gotFlags;
uint32 flags;
version_info versionInfo;
private:
struct AppInfo {
BString signature;
bool gotFlags;
uint32 flags;
version_info versionInfo;
BMessage supportedTypes;
BMessage supportedTypes;
bool iconChanged;
bool typeIconsChanged;
};
enum {
CHECK_SIGNATUR = 1 << 0,
CHECK_FLAGS = 1 << 1,
CHECK_VERSION = 1 << 2,
CHECK_ICON = 1 << 3,
bool iconChanged;
bool typeIconsChanged;
};
enum {
CHECK_SIGNATUR = 1 << 0,
CHECK_FLAGS = 1 << 1,
CHECK_VERSION = 1 << 2,
CHECK_ICON = 1 << 3,
CHECK_TYPES = 1 << 4,
CHECK_TYPE_ICONS = 1 << 5,
CHECK_TYPES = 1 << 4,
CHECK_TYPE_ICONS = 1 << 5,
CHECK_ALL = 0xffffffff
};
CHECK_ALL = 0xffffffff
};
private:
BEntry fEntry;
AppInfo fOriginalInfo;
private:
BEntry fEntry;
AppInfo fOriginalInfo;
BTextControl* fSignatureControl;
IconView* fIconView;
Icon fIcon;
BTextControl* fSignatureControl;
IconView* fIconView;
Icon fIcon;
BCheckBox* fFlagsCheckBox;
BRadioButton* fSingleLaunchButton;
BRadioButton* fMultipleLaunchButton;
BRadioButton* fExclusiveLaunchButton;
BCheckBox* fArgsOnlyCheckBox;
BCheckBox* fBackgroundAppCheckBox;
BCheckBox* fFlagsCheckBox;
BRadioButton* fSingleLaunchButton;
BRadioButton* fMultipleLaunchButton;
BRadioButton* fExclusiveLaunchButton;
BCheckBox* fArgsOnlyCheckBox;
BCheckBox* fBackgroundAppCheckBox;
BListView* fTypeListView;
BButton* fAddTypeButton;
BButton* fRemoveTypeButton;
IconView* fTypeIconView;
BListView* fTypeListView;
BButton* fAddTypeButton;
BButton* fRemoveTypeButton;
IconView* fTypeIconView;
BTextControl* fMajorVersionControl;
BTextControl* fMiddleVersionControl;
BTextControl* fMinorVersionControl;
BPopUpMenu* fVarietyMenu;
BTextControl* fInternalVersionControl;
BTextControl* fShortDescriptionControl;
BTextView* fLongDescriptionView;
BTextControl* fMajorVersionControl;
BTextControl* fMiddleVersionControl;
BTextControl* fMinorVersionControl;
BPopUpMenu* fVarietyMenu;
BTextControl* fInternalVersionControl;
BTextControl* fShortDescriptionControl;
BTextView* fLongDescriptionView;
BMenuItem* fSaveMenuItem;
uint32 fChangedProperties;
BMenuItem* fSaveMenuItem;
uint32 fChangedProperties;
};
#endif // APPLICATION_TYPE_WINDOW_H

View File

@ -125,6 +125,9 @@ Settings::UpdateFrom(BMessage* message)
if (message->FindRect("app_types_frame", &frame) == B_OK)
fMessage.ReplaceRect("app_types_frame", frame);
if (message->FindRect("app_type_frame", &frame) == B_OK)
fMessage.ReplaceRect("app_type_frame", frame);
bool showIcons;
if (message->FindBool("show_icons", &showIcons) == B_OK)
fMessage.ReplaceBool("show_icons", showIcons);
@ -148,6 +151,7 @@ Settings::_SetDefaults()
{
fMessage.AddRect("file_types_frame", BRect(80.0f, 80.0f, 600.0f, 480.0f));
fMessage.AddRect("app_types_frame", BRect(100.0f, 100.0f, 540.0f, 480.0f));
fMessage.AddRect("app_type_frame", BRect(100.0f, 110.0f, 250.0f, 340.0f));
fMessage.AddBool("show_icons", true);
fMessage.AddBool("show_rule", false);
fMessage.AddFloat("left_split_weight", 0.2);
@ -248,10 +252,9 @@ FileTypes::RefsReceived(BMessage* message)
message->RemoveData("refs", --index);
// There are some refs left that want to be handled by the type window
BPoint point(100.0f + kCascadeOffset * fTypeWindowCount,
110.0f + kCascadeOffset * fTypeWindowCount);
BPoint totalOffset(kCascadeOffset * fTypeWindowCount, kCascadeOffset * fTypeWindowCount);
BWindow* window = new ApplicationTypeWindow(point, entry);
BWindow* window = new ApplicationTypeWindow(fSettings.Message(), totalOffset, entry);
window->Show();
fTypeWindowCount++;