* FileTypes now stores and retrieves its settings.
* The "Show Icons" option now defaults to true. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17689 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -158,8 +158,8 @@ ProgressWindow::MessageReceived(BMessage* message)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
ApplicationTypesWindow::ApplicationTypesWindow(BRect frame)
|
ApplicationTypesWindow::ApplicationTypesWindow(const BMessage &settings)
|
||||||
: BWindow(frame, "Application Types", B_TITLED_WINDOW,
|
: BWindow(_Frame(settings), "Application Types", B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
||||||
{
|
{
|
||||||
// Application list
|
// Application list
|
||||||
@@ -295,6 +295,17 @@ ApplicationTypesWindow::~ApplicationTypesWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
ApplicationTypesWindow::_Frame(const BMessage& settings) const
|
||||||
|
{
|
||||||
|
BRect rect;
|
||||||
|
if (settings.FindRect("app_types_frame", &rect) == B_OK)
|
||||||
|
return rect;
|
||||||
|
|
||||||
|
return BRect(100.0f, 100.0f, 540.0f, 480.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ApplicationTypesWindow::_RemoveUninstalled()
|
ApplicationTypesWindow::_RemoveUninstalled()
|
||||||
{
|
{
|
||||||
@@ -542,6 +553,10 @@ ApplicationTypesWindow::MessageReceived(BMessage* message)
|
|||||||
bool
|
bool
|
||||||
ApplicationTypesWindow::QuitRequested()
|
ApplicationTypesWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
BMessage update(kMsgSettingsChanged);
|
||||||
|
update.AddRect("app_types_frame", Frame());
|
||||||
|
be_app_messenger.SendMessage(&update);
|
||||||
|
|
||||||
be_app->PostMessage(kMsgApplicationTypesWindowClosed);
|
be_app->PostMessage(kMsgApplicationTypesWindowClosed);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class StringView;
|
|||||||
|
|
||||||
class ApplicationTypesWindow : public BWindow {
|
class ApplicationTypesWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
ApplicationTypesWindow(BRect frame);
|
ApplicationTypesWindow(const BMessage& settings);
|
||||||
virtual ~ApplicationTypesWindow();
|
virtual ~ApplicationTypesWindow();
|
||||||
|
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
@@ -32,6 +32,7 @@ class ApplicationTypesWindow : public BWindow {
|
|||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BRect _Frame(const BMessage& settings) const;
|
||||||
void _SetType(BMimeType* type, int32 forceUpdate = 0);
|
void _SetType(BMimeType* type, int32 forceUpdate = 0);
|
||||||
void _UpdateCounter();
|
void _UpdateCounter();
|
||||||
void _RemoveUninstalled();
|
void _RemoveUninstalled();
|
||||||
|
|||||||
@@ -26,6 +26,26 @@
|
|||||||
|
|
||||||
const char *kSignature = "application/x-vnd.Haiku-FileTypes";
|
const char *kSignature = "application/x-vnd.Haiku-FileTypes";
|
||||||
|
|
||||||
|
static const uint32 kMsgFileTypesSettings = 'FTst';
|
||||||
|
static const uint32 kCascadeOffset = 20;
|
||||||
|
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
public:
|
||||||
|
Settings();
|
||||||
|
~Settings();
|
||||||
|
|
||||||
|
const BMessage &Message() const { return fMessage; }
|
||||||
|
void UpdateFrom(BMessage *message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _SetDefaults();
|
||||||
|
status_t _Open(BFile *file, int32 mode);
|
||||||
|
|
||||||
|
BMessage fMessage;
|
||||||
|
bool fUpdated;
|
||||||
|
};
|
||||||
|
|
||||||
class FileTypes : public BApplication {
|
class FileTypes : public BApplication {
|
||||||
public:
|
public:
|
||||||
FileTypes();
|
FileTypes();
|
||||||
@@ -43,17 +63,99 @@ class FileTypes : public BApplication {
|
|||||||
private:
|
private:
|
||||||
void _WindowClosed();
|
void _WindowClosed();
|
||||||
|
|
||||||
|
Settings fSettings;
|
||||||
BFilePanel *fFilePanel;
|
BFilePanel *fFilePanel;
|
||||||
BMessenger fFilePanelTarget;
|
BMessenger fFilePanelTarget;
|
||||||
BWindow *fTypesWindow;
|
BWindow *fTypesWindow;
|
||||||
BWindow *fApplicationTypesWindow;
|
BWindow *fApplicationTypesWindow;
|
||||||
uint32 fWindowCount;
|
uint32 fWindowCount;
|
||||||
uint32 fTypeWindowCount;
|
uint32 fTypeWindowCount;
|
||||||
BRect fTypesWindowFrame;
|
|
||||||
BRect fApplicationTypesWindowFrame;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Settings::Settings()
|
||||||
|
:
|
||||||
|
fMessage(kMsgFileTypesSettings),
|
||||||
|
fUpdated(false)
|
||||||
|
{
|
||||||
|
_SetDefaults();
|
||||||
|
|
||||||
|
BFile file;
|
||||||
|
if (_Open(&file, B_READ_ONLY) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BMessage settings;
|
||||||
|
if (settings.Unflatten(&file) == B_OK) {
|
||||||
|
// We don't unflatten into our default message to make sure
|
||||||
|
// nothing is lost (because of old or corrupted on disk settings)
|
||||||
|
UpdateFrom(&settings);
|
||||||
|
fUpdated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Settings::~Settings()
|
||||||
|
{
|
||||||
|
// only save the settings if something has changed
|
||||||
|
if (!fUpdated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BFile file;
|
||||||
|
if (_Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fMessage.Flatten(&file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
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.AddBool("show_icons", true);
|
||||||
|
fMessage.AddBool("show_rule", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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("FileTypes settings");
|
||||||
|
|
||||||
|
return file->SetTo(path.Path(), mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Settings::UpdateFrom(BMessage *message)
|
||||||
|
{
|
||||||
|
BRect frame;
|
||||||
|
if (message->FindRect("file_types_frame", &frame) == B_OK)
|
||||||
|
fMessage.ReplaceRect("file_types_frame", frame);
|
||||||
|
|
||||||
|
if (message->FindRect("app_types_frame", &frame) == B_OK)
|
||||||
|
fMessage.ReplaceRect("app_types_frame", frame);
|
||||||
|
|
||||||
|
bool showIcons;
|
||||||
|
if (message->FindBool("show_icons", &showIcons) == B_OK)
|
||||||
|
fMessage.ReplaceBool("show_icons", showIcons);
|
||||||
|
|
||||||
|
bool showRule;
|
||||||
|
if (message->FindBool("show_rule", &showRule) == B_OK)
|
||||||
|
fMessage.ReplaceBool("show_rule", showRule);
|
||||||
|
|
||||||
|
fUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FileTypes::FileTypes()
|
FileTypes::FileTypes()
|
||||||
: BApplication(kSignature),
|
: BApplication(kSignature),
|
||||||
fTypesWindow(NULL),
|
fTypesWindow(NULL),
|
||||||
@@ -63,10 +165,6 @@ FileTypes::FileTypes()
|
|||||||
{
|
{
|
||||||
fFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
fFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
||||||
B_FILE_NODE | B_DIRECTORY_NODE, false);
|
B_FILE_NODE | B_DIRECTORY_NODE, false);
|
||||||
|
|
||||||
fTypesWindowFrame = BRect(80.0f, 80.0f, 600.0f, 480.0f);
|
|
||||||
fApplicationTypesWindowFrame = BRect(100.0f, 100.0f, 540.0f, 480.0f);
|
|
||||||
// TODO: read from settings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -131,7 +229,8 @@ FileTypes::RefsReceived(BMessage *message)
|
|||||||
message->RemoveData("refs", --index);
|
message->RemoveData("refs", --index);
|
||||||
|
|
||||||
// There are some refs left that want to be handled by the type window
|
// There are some refs left that want to be handled by the type window
|
||||||
BPoint point(100.0f + 20.0f * fTypeWindowCount, 110.0f + 20.0f * fTypeWindowCount);
|
BPoint point(100.0f + kCascadeOffset * fTypeWindowCount,
|
||||||
|
110.0f + kCascadeOffset * fTypeWindowCount);
|
||||||
|
|
||||||
BWindow* window = new ApplicationTypeWindow(point, entry);
|
BWindow* window = new ApplicationTypeWindow(point, entry);
|
||||||
window->Show();
|
window->Show();
|
||||||
@@ -144,7 +243,8 @@ FileTypes::RefsReceived(BMessage *message)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// There are some refs left that want to be handled by the type window
|
// There are some refs left that want to be handled by the type window
|
||||||
BPoint point(100.0f + 20.0f * fTypeWindowCount, 110.0f + 20.0f * fTypeWindowCount);
|
BPoint point(100.0f + kCascadeOffset * fTypeWindowCount,
|
||||||
|
110.0f + kCascadeOffset * fTypeWindowCount);
|
||||||
|
|
||||||
BWindow* window = new FileTypeWindow(point, *message);
|
BWindow* window = new FileTypeWindow(point, *message);
|
||||||
window->Show();
|
window->Show();
|
||||||
@@ -202,9 +302,13 @@ void
|
|||||||
FileTypes::MessageReceived(BMessage *message)
|
FileTypes::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case kMsgSettingsChanged:
|
||||||
|
fSettings.UpdateFrom(message);
|
||||||
|
break;
|
||||||
|
|
||||||
case kMsgOpenTypesWindow:
|
case kMsgOpenTypesWindow:
|
||||||
if (fTypesWindow == NULL) {
|
if (fTypesWindow == NULL) {
|
||||||
fTypesWindow = new FileTypesWindow(fTypesWindowFrame);
|
fTypesWindow = new FileTypesWindow(fSettings.Message());
|
||||||
fTypesWindow->Show();
|
fTypesWindow->Show();
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
} else
|
} else
|
||||||
@@ -218,7 +322,7 @@ FileTypes::MessageReceived(BMessage *message)
|
|||||||
case kMsgOpenApplicationTypesWindow:
|
case kMsgOpenApplicationTypesWindow:
|
||||||
if (fApplicationTypesWindow == NULL) {
|
if (fApplicationTypesWindow == NULL) {
|
||||||
fApplicationTypesWindow = new ApplicationTypesWindow(
|
fApplicationTypesWindow = new ApplicationTypesWindow(
|
||||||
fApplicationTypesWindowFrame);
|
fSettings.Message());
|
||||||
fApplicationTypesWindow->Show();
|
fApplicationTypesWindow->Show();
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
} else
|
} else
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ static const uint32 kMsgApplicationTypesWindowClosed = 'clAw';
|
|||||||
static const uint32 kMsgTypeWindowClosed = 'cltw';
|
static const uint32 kMsgTypeWindowClosed = 'cltw';
|
||||||
static const uint32 kMsgWindowClosed = 'WiCl';
|
static const uint32 kMsgWindowClosed = 'WiCl';
|
||||||
|
|
||||||
|
static const uint32 kMsgSettingsChanged = 'SeCh';
|
||||||
|
|
||||||
|
|
||||||
// exported functions
|
// exported functions
|
||||||
|
|
||||||
|
|||||||
@@ -232,11 +232,18 @@ TypeIconView::MouseDown(BPoint where)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FileTypesWindow::FileTypesWindow(BRect frame)
|
FileTypesWindow::FileTypesWindow(const BMessage& settings)
|
||||||
: BWindow(frame, "FileTypes", B_TITLED_WINDOW,
|
: BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW,
|
||||||
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
|
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
|
||||||
fNewTypeWindow(NULL)
|
fNewTypeWindow(NULL)
|
||||||
{
|
{
|
||||||
|
bool showIcons;
|
||||||
|
bool showRule;
|
||||||
|
if (settings.FindBool("show_icons", &showIcons) != B_OK)
|
||||||
|
showIcons = true;
|
||||||
|
if (settings.FindBool("show_rule", &showRule) != B_OK)
|
||||||
|
showRule = false;
|
||||||
|
|
||||||
// add the menu
|
// add the menu
|
||||||
|
|
||||||
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
|
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
|
||||||
@@ -268,10 +275,12 @@ FileTypesWindow::FileTypesWindow(BRect frame)
|
|||||||
|
|
||||||
menu = new BMenu("Settings");
|
menu = new BMenu("Settings");
|
||||||
item = new BMenuItem("Show Icons in List", new BMessage(kMsgToggleIcons));
|
item = new BMenuItem("Show Icons in List", new BMessage(kMsgToggleIcons));
|
||||||
|
item->SetMarked(showIcons);
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
item = new BMenuItem("Show Recognition Rule", new BMessage(kMsgToggleRule));
|
item = new BMenuItem("Show Recognition Rule", new BMessage(kMsgToggleRule));
|
||||||
|
item->SetMarked(showRule);
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
menuBar->AddItem(menu);
|
menuBar->AddItem(menu);
|
||||||
@@ -304,7 +313,7 @@ FileTypesWindow::FileTypesWindow(BRect frame)
|
|||||||
if (rect.right < 180)
|
if (rect.right < 180)
|
||||||
rect.right = 180;
|
rect.right = 180;
|
||||||
|
|
||||||
fTypeListView = new MimeTypeListView(rect, "typeview", NULL, false, false,
|
fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false,
|
||||||
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
|
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
|
||||||
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
|
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
|
||||||
|
|
||||||
@@ -527,6 +536,8 @@ FileTypesWindow::FileTypesWindow(BRect frame)
|
|||||||
+ 32.0f + menuBar->Bounds().Height(), 32767.0f);
|
+ 32.0f + menuBar->Bounds().Height(), 32767.0f);
|
||||||
|
|
||||||
_SetType(NULL);
|
_SetType(NULL);
|
||||||
|
_ShowSnifferRule(showRule);
|
||||||
|
|
||||||
BMimeType::StartWatching(this);
|
BMimeType::StartWatching(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,6 +548,17 @@ FileTypesWindow::~FileTypesWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
FileTypesWindow::_Frame(const BMessage& settings) const
|
||||||
|
{
|
||||||
|
BRect rect;
|
||||||
|
if (settings.FindRect("file_types_frame", &rect) == B_OK)
|
||||||
|
return rect;
|
||||||
|
|
||||||
|
return BRect(80.0f, 80.0f, 600.0f, 480.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypesWindow::_ShowSnifferRule(bool show)
|
FileTypesWindow::_ShowSnifferRule(bool show)
|
||||||
{
|
{
|
||||||
@@ -741,6 +763,11 @@ FileTypesWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
item->SetMarked(!fTypeListView->IsShowingIcons());
|
item->SetMarked(!fTypeListView->IsShowingIcons());
|
||||||
fTypeListView->ShowIcons(item->IsMarked());
|
fTypeListView->ShowIcons(item->IsMarked());
|
||||||
|
|
||||||
|
// update settings
|
||||||
|
BMessage update(kMsgSettingsChanged);
|
||||||
|
update.AddBool("show_icons", item->IsMarked());
|
||||||
|
be_app_messenger.SendMessage(&update);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,6 +779,11 @@ FileTypesWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
item->SetMarked(fRuleControl->IsHidden());
|
item->SetMarked(fRuleControl->IsHidden());
|
||||||
_ShowSnifferRule(item->IsMarked());
|
_ShowSnifferRule(item->IsMarked());
|
||||||
|
|
||||||
|
// update settings
|
||||||
|
BMessage update(kMsgSettingsChanged);
|
||||||
|
update.AddBool("show_rule", item->IsMarked());
|
||||||
|
be_app_messenger.SendMessage(&update);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1044,6 +1076,10 @@ FileTypesWindow::MessageReceived(BMessage* message)
|
|||||||
bool
|
bool
|
||||||
FileTypesWindow::QuitRequested()
|
FileTypesWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
BMessage update(kMsgSettingsChanged);
|
||||||
|
update.AddRect("file_types_frame", Frame());
|
||||||
|
be_app_messenger.SendMessage(&update);
|
||||||
|
|
||||||
be_app->PostMessage(kMsgTypesWindowClosed);
|
be_app->PostMessage(kMsgTypesWindowClosed);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class StringView;
|
|||||||
|
|
||||||
class FileTypesWindow : public BWindow {
|
class FileTypesWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
FileTypesWindow(BRect frame);
|
FileTypesWindow(const BMessage& settings);
|
||||||
virtual ~FileTypesWindow();
|
virtual ~FileTypesWindow();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
@@ -35,6 +35,7 @@ class FileTypesWindow : public BWindow {
|
|||||||
void PlaceSubWindow(BWindow* window);
|
void PlaceSubWindow(BWindow* window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BRect _Frame(const BMessage& settings) const;
|
||||||
void _ShowSnifferRule(bool show);
|
void _ShowSnifferRule(bool show);
|
||||||
void _UpdateExtensions(BMimeType* type);
|
void _UpdateExtensions(BMimeType* type);
|
||||||
void _AdoptPreferredApplication(BMessage* message, bool sameAs);
|
void _AdoptPreferredApplication(BMessage* message, bool sameAs);
|
||||||
|
|||||||
Reference in New Issue
Block a user