Implemented R5 compatible settings.
The number base type (hex or decimal) and the window frame is already correctly maintained (font size is only displayed, but not yet changed). I don't know the meaning of the last 4 bytes in DiskProbe_data, but it's probably not that bad. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6714 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d11ec0829b
commit
7fff3ed096
@ -13,7 +13,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribute)
|
||||
AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribute,
|
||||
const BMessage *settings)
|
||||
: ProbeWindow(rect, ref),
|
||||
fAttribute(strdup(attribute))
|
||||
{
|
||||
@ -39,7 +40,7 @@ AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribu
|
||||
|
||||
BRect rect = Bounds();
|
||||
rect.top = menuBar->Bounds().Height() + 1;
|
||||
ProbeView *probeView = new ProbeView(rect, ref, attribute);
|
||||
ProbeView *probeView = new ProbeView(rect, ref, attribute, settings);
|
||||
probeView->AddFileMenuItems(menu, 0);
|
||||
AddChild(probeView);
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
class AttributeWindow : public ProbeWindow {
|
||||
public:
|
||||
AttributeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL);
|
||||
AttributeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL,
|
||||
const BMessage *settings = NULL);
|
||||
virtual ~AttributeWindow();
|
||||
|
||||
bool Contains(const entry_ref &ref, const char *attribute);
|
||||
|
@ -879,9 +879,23 @@ DataView::SetFont(const BFont *font, uint32 properties)
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
DataView::FontSize() const
|
||||
{
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
|
||||
return font.Size();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DataView::SetFontSize(float point)
|
||||
{
|
||||
// ToDo: "fit" is not yet supported
|
||||
if (point == 0.0f)
|
||||
point = 12.0f;
|
||||
|
||||
BFont font = be_fixed_font;
|
||||
font.SetSize(point);
|
||||
|
||||
|
@ -14,8 +14,8 @@
|
||||
class DataEditor;
|
||||
|
||||
enum base_type {
|
||||
kHexBase,
|
||||
kDecimalBase
|
||||
kHexBase = 16,
|
||||
kDecimalBase = 10
|
||||
};
|
||||
|
||||
enum view_focus {
|
||||
@ -46,7 +46,9 @@ class DataView : public BView {
|
||||
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL);
|
||||
virtual void GetPreferredSize(float *_width, float *_height);
|
||||
|
||||
float FontSize() const;
|
||||
void SetFontSize(float point);
|
||||
|
||||
void UpdateScroller();
|
||||
|
||||
void MakeVisible(int32 position);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "DiskProbe.h"
|
||||
#include "DataEditor.h"
|
||||
#include "DataView.h"
|
||||
#include "FileWindow.h"
|
||||
#include "AttributeWindow.h"
|
||||
#include "OpenWindow.h"
|
||||
@ -15,6 +16,7 @@
|
||||
#include <Alert.h>
|
||||
#include <TextView.h>
|
||||
#include <FilePanel.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
@ -27,6 +29,31 @@ static const char *kSignature = "application/x-vnd.OpenBeOS-DiskProbe";
|
||||
|
||||
static const uint32 kCascadeOffset = 20;
|
||||
|
||||
static const uint32 kMsgDiskProbeSettings = 'DPst';
|
||||
|
||||
struct disk_probe_settings {
|
||||
BRect window_frame;
|
||||
int32 base_type;
|
||||
int32 font_size;
|
||||
int32 unknown;
|
||||
};
|
||||
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
~Settings();
|
||||
|
||||
const BMessage &Message() const { return fMessage; }
|
||||
void UpdateFrom(BMessage *message);
|
||||
|
||||
private:
|
||||
status_t Open(BFile *file, int32 mode);
|
||||
|
||||
BMessage fMessage;
|
||||
bool fUpdated;
|
||||
};
|
||||
|
||||
|
||||
class DiskProbe : public BApplication {
|
||||
public:
|
||||
@ -45,25 +72,115 @@ class DiskProbe : public BApplication {
|
||||
private:
|
||||
status_t Probe(entry_ref &ref, const char *attribute = NULL);
|
||||
|
||||
Settings fSettings;
|
||||
BFilePanel *fFilePanel;
|
||||
BWindow *fOpenWindow;
|
||||
uint32 fWindowCount;
|
||||
BRect fWindowPosition;
|
||||
BRect fWindowFrame;
|
||||
};
|
||||
|
||||
|
||||
//-----------------
|
||||
|
||||
|
||||
Settings::Settings()
|
||||
:
|
||||
fMessage(kMsgDiskProbeSettings),
|
||||
fUpdated(false)
|
||||
{
|
||||
fMessage.AddRect("window_frame", BRect(50, 50, 550, 500));
|
||||
fMessage.AddInt32("base_type", kHexBase);
|
||||
fMessage.AddFloat("font_size", 12.0f);
|
||||
|
||||
BFile file;
|
||||
if (Open(&file, B_READ_ONLY) != B_OK)
|
||||
return;
|
||||
|
||||
// ToDo: load/save settings as flattened BMessage - but not yet,
|
||||
// since that will break compatibility with R5's DiskProbe
|
||||
|
||||
disk_probe_settings settings;
|
||||
if (file.Read(&settings, sizeof(settings)) == sizeof(settings)) {
|
||||
#if B_HOST_IS_BENDIAN
|
||||
// settings are saved in little endian
|
||||
settings.window_frame.left = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.left);
|
||||
settings.window_frame.top = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.top);
|
||||
settings.window_frame.right = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.right);
|
||||
settings.window_frame.bottom = B_LENDIAN_TO_HOST_FLOAT(settings.window_frame.bottom);
|
||||
settings.base_type = B_LENDIAN_TO_HOST_INT32(settings.base_type);
|
||||
settings.font_size = B_LENDIAN_TO_HOST_INT32(settings.font_size);
|
||||
#endif
|
||||
|
||||
fMessage.ReplaceRect("window_frame", settings.window_frame);
|
||||
fMessage.ReplaceInt32("base_type", settings.base_type);
|
||||
fMessage.ReplaceFloat("font_size", (float)settings.font_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
// only save the settings if something has changed
|
||||
if (!fUpdated)
|
||||
return;
|
||||
|
||||
BFile file;
|
||||
if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
|
||||
return;
|
||||
|
||||
disk_probe_settings settings;
|
||||
settings.window_frame = fMessage.FindRect("window_frame");
|
||||
settings.base_type = fMessage.FindInt32("base_type");
|
||||
settings.font_size = int32(fMessage.FindFloat("font_size") + 0.5f);
|
||||
settings.unknown = 1;
|
||||
// That's what DiskProbe R5 puts in there
|
||||
|
||||
file.Write(&settings, sizeof(settings));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Settings::Open(BFile *file, int32 mode)
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
path.Append("DiskProbe_data");
|
||||
|
||||
return file->SetTo(path.Path(), mode);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::UpdateFrom(BMessage *message)
|
||||
{
|
||||
BRect frame;
|
||||
if (message->FindRect("window_frame", &frame) == B_OK)
|
||||
fMessage.ReplaceRect("window_frame", frame);
|
||||
|
||||
int32 baseType;
|
||||
if (message->FindInt32("base_type", &baseType) == B_OK)
|
||||
fMessage.ReplaceInt32("base_type", baseType);
|
||||
|
||||
float fontSize;
|
||||
if (message->FindFloat("font_size", &fontSize) == B_OK)
|
||||
fMessage.ReplaceFloat("font_size", fontSize);
|
||||
|
||||
fUpdated = true;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
DiskProbe::DiskProbe()
|
||||
: BApplication(kSignature),
|
||||
fOpenWindow(NULL),
|
||||
fWindowCount(0),
|
||||
fWindowPosition(50, 50, 550, 500)
|
||||
fWindowCount(0)
|
||||
{
|
||||
fFilePanel = new BFilePanel();
|
||||
|
||||
// ToDo: maintain the window position on disk
|
||||
fWindowFrame = fSettings.Message().FindRect("window_frame");
|
||||
}
|
||||
|
||||
|
||||
@ -118,14 +235,14 @@ DiskProbe::Probe(entry_ref &ref, const char *attribute)
|
||||
return status;
|
||||
|
||||
// cascade window
|
||||
BRect rect = fWindowPosition;
|
||||
BRect rect = fWindowFrame;
|
||||
rect.OffsetBy(probeWindows * kCascadeOffset, probeWindows * kCascadeOffset);
|
||||
|
||||
BWindow *window;
|
||||
if (attribute != NULL)
|
||||
window = new AttributeWindow(rect, &ref, attribute);
|
||||
window = new AttributeWindow(rect, &ref, attribute, &fSettings.Message());
|
||||
else
|
||||
window = new FileWindow(rect, &ref);
|
||||
window = new FileWindow(rect, &ref, &fSettings.Message());
|
||||
|
||||
window->Show();
|
||||
fWindowCount++;
|
||||
@ -202,6 +319,10 @@ DiskProbe::MessageReceived(BMessage *message)
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
break;
|
||||
|
||||
case kMsgSettingsChanged:
|
||||
fSettings.UpdateFrom(message);
|
||||
break;
|
||||
|
||||
case kMsgOpenFilePanel:
|
||||
fFilePanel->Show();
|
||||
break;
|
||||
|
@ -13,5 +13,6 @@ static const uint32 kMsgOpenFilePanel = 'opFp';
|
||||
static const uint32 kMsgOpenOpenWindow = 'opOw';
|
||||
static const uint32 kMsgOpenWindowClosed = 'clOw';
|
||||
static const uint32 kMsgWindowClosed = 'WiCl';
|
||||
static const uint32 kMsgSettingsChanged = 'SeCh';
|
||||
|
||||
#endif /* DISK_PROBE_H */
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
FileWindow::FileWindow(BRect rect, entry_ref *ref)
|
||||
FileWindow::FileWindow(BRect rect, entry_ref *ref, const BMessage *settings)
|
||||
: ProbeWindow(rect, ref)
|
||||
{
|
||||
// Set alternative window title for devices
|
||||
@ -59,7 +59,7 @@ FileWindow::FileWindow(BRect rect, entry_ref *ref)
|
||||
|
||||
BRect rect = Bounds();
|
||||
rect.top = menuBar->Bounds().Height() + 1;
|
||||
ProbeView *probeView = new ProbeView(rect, ref);
|
||||
ProbeView *probeView = new ProbeView(rect, ref, NULL, settings);
|
||||
probeView->AddFileMenuItems(menu, menu->CountItems() - 4);
|
||||
AddChild(probeView);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
class FileWindow : public ProbeWindow {
|
||||
public:
|
||||
FileWindow(BRect rect, entry_ref *ref);
|
||||
FileWindow(BRect rect, entry_ref *ref, const BMessage *settings = NULL);
|
||||
|
||||
virtual bool Contains(const entry_ref &ref, const char *attribute);
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "ProbeView.h"
|
||||
#include "DataView.h"
|
||||
#include "DiskProbe.h"
|
||||
|
||||
#define BEOS_R5_COMPATIBLE
|
||||
// for SetLimits()
|
||||
@ -430,7 +431,7 @@ HeaderView::HeaderView(BRect frame, entry_ref *ref, DataEditor &editor)
|
||||
rect.right += 100;
|
||||
rect.OffsetBy(0, -2);
|
||||
// BTextControl oddities
|
||||
|
||||
|
||||
char buffer[16];
|
||||
get_type_string(buffer, sizeof(buffer), editor.Type());
|
||||
fTypeControl = new BTextControl(rect, B_EMPTY_STRING, NULL, buffer, new BMessage(kMsgPositionUpdate));
|
||||
@ -832,14 +833,22 @@ UpdateLooper::MessageReceived(BMessage *message)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
|
||||
ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute, const BMessage *settings)
|
||||
: BView(rect, "probeView", B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
{
|
||||
fEditor.SetTo(*ref, attribute);
|
||||
|
||||
int32 baseType = kHexBase;
|
||||
float fontSize = 12.0f;
|
||||
if (settings != NULL) {
|
||||
settings->FindInt32("base_type", &baseType);
|
||||
settings->FindFloat("font_size", &fontSize);
|
||||
}
|
||||
|
||||
rect = Bounds();
|
||||
fHeaderView = new HeaderView(rect, ref, fEditor);
|
||||
fHeaderView->ResizeToPreferred();
|
||||
fHeaderView->SetBase((base_type)baseType);
|
||||
AddChild(fHeaderView);
|
||||
|
||||
rect = fHeaderView->Frame();
|
||||
@ -847,6 +856,8 @@ ProbeView::ProbeView(BRect rect, entry_ref *ref, const char *attribute)
|
||||
rect.bottom = Bounds().bottom - B_H_SCROLL_BAR_HEIGHT;
|
||||
rect.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
fDataView = new DataView(rect, fEditor);
|
||||
fDataView->SetBase((base_type)baseType);
|
||||
fDataView->SetFontSize(fontSize);
|
||||
|
||||
fScrollView = new BScrollView("scroller", fDataView, B_FOLLOW_ALL, B_WILL_DRAW, true, true);
|
||||
AddChild(fScrollView);
|
||||
@ -1046,14 +1057,14 @@ ProbeView::AttachedToWindow()
|
||||
|
||||
subMenu = new BMenu("Base");
|
||||
message = new BMessage(kMsgBaseType);
|
||||
message->AddInt32("base", kDecimalBase);
|
||||
message->AddInt32("base_type", kDecimalBase);
|
||||
subMenu->AddItem(item = new BMenuItem("Decimal", message, 'D', B_COMMAND_KEY));
|
||||
item->SetTarget(this);
|
||||
if (fHeaderView->Base() == kDecimalBase)
|
||||
item->SetMarked(true);
|
||||
|
||||
message = new BMessage(kMsgBaseType);
|
||||
message->AddInt32("base", kHexBase);
|
||||
message->AddInt32("base_type", kHexBase);
|
||||
subMenu->AddItem(item = new BMenuItem("Hex", message, 'H', B_COMMAND_KEY));
|
||||
item->SetTarget(this);
|
||||
if (fHeaderView->Base() == kHexBase)
|
||||
@ -1073,15 +1084,22 @@ ProbeView::AttachedToWindow()
|
||||
|
||||
subMenu = new BMenu("Font Size");
|
||||
const int32 fontSizes[] = {9, 10, 12, 14, 18, 24, 36, 48};
|
||||
int32 fontSize = int32(fDataView->FontSize() + 0.5);
|
||||
for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) {
|
||||
char buffer[16];
|
||||
snprintf(buffer, sizeof(buffer), "%ld", fontSizes[i]);
|
||||
subMenu->AddItem(new BMenuItem(buffer, NULL));
|
||||
subMenu->AddItem(item = new BMenuItem(buffer, NULL));
|
||||
if (fontSizes[i] == fontSize)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
subMenu->AddSeparatorItem();
|
||||
subMenu->AddItem(new BMenuItem("Fit", NULL));
|
||||
subMenu->AddItem(item = new BMenuItem("Fit", NULL));
|
||||
if (fontSize == 0)
|
||||
item->SetMarked(true);
|
||||
|
||||
subMenu->SetRadioMode(true);
|
||||
menu->AddItem(new BMenuItem(subMenu));
|
||||
|
||||
bar->AddItem(menu);
|
||||
}
|
||||
|
||||
@ -1093,7 +1111,7 @@ ProbeView::AllAttached()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
ProbeView::WindowActivated(bool active)
|
||||
{
|
||||
if (active)
|
||||
@ -1101,7 +1119,7 @@ ProbeView::WindowActivated(bool active)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void
|
||||
ProbeView::CheckClipboard()
|
||||
{
|
||||
if (!be_clipboard->Lock())
|
||||
@ -1130,11 +1148,16 @@ ProbeView::MessageReceived(BMessage *message)
|
||||
case kMsgBaseType:
|
||||
{
|
||||
int32 type;
|
||||
if (message->FindInt32("base", &type) != B_OK)
|
||||
if (message->FindInt32("base_type", &type) != B_OK)
|
||||
break;
|
||||
|
||||
fHeaderView->SetBase((base_type)type);
|
||||
fDataView->SetBase((base_type)type);
|
||||
|
||||
// update the applications settings
|
||||
BMessage update(*message);
|
||||
update.what = kMsgSettingsChanged;
|
||||
be_app_messenger.SendMessage(&update);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ class UpdateLooper;
|
||||
|
||||
class ProbeView : public BView {
|
||||
public:
|
||||
ProbeView(BRect rect, entry_ref *ref, const char *attribute = NULL);
|
||||
ProbeView(BRect rect, entry_ref *ref, const char *attribute = NULL,
|
||||
const BMessage *settings = NULL);
|
||||
virtual ~ProbeView();
|
||||
|
||||
virtual void DetachedFromWindow();
|
||||
|
@ -39,6 +39,10 @@ ProbeWindow::MessageReceived(BMessage *message)
|
||||
bool
|
||||
ProbeWindow::QuitRequested()
|
||||
{
|
||||
BMessage update(kMsgSettingsChanged);
|
||||
update.AddRect("window_frame", Frame());
|
||||
be_app_messenger.SendMessage(&update);
|
||||
|
||||
be_app_messenger.SendMessage(kMsgWindowClosed);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user