diff --git a/src/preferences/filetypes/AttributeWindow.cpp b/src/preferences/filetypes/AttributeWindow.cpp index 9538841324..c3dc1a3ddc 100644 --- a/src/preferences/filetypes/AttributeWindow.cpp +++ b/src/preferences/filetypes/AttributeWindow.cpp @@ -384,6 +384,10 @@ AttributeWindow::MessageReceived(BMessage* message) PostMessage(B_QUIT_REQUESTED); break; } + + default: + BWindow::MessageReceived(message); + break; } } diff --git a/src/preferences/filetypes/ExtensionWindow.cpp b/src/preferences/filetypes/ExtensionWindow.cpp index 0e2ba1d9aa..d5ec5f3444 100644 --- a/src/preferences/filetypes/ExtensionWindow.cpp +++ b/src/preferences/filetypes/ExtensionWindow.cpp @@ -176,6 +176,10 @@ ExtensionWindow::MessageReceived(BMessage* message) PostMessage(B_QUIT_REQUESTED); break; } + + default: + BWindow::MessageReceived(message); + break; } } diff --git a/src/preferences/filetypes/FileTypeWindow.cpp b/src/preferences/filetypes/FileTypeWindow.cpp index 9cb802b860..a192c1b206 100644 --- a/src/preferences/filetypes/FileTypeWindow.cpp +++ b/src/preferences/filetypes/FileTypeWindow.cpp @@ -8,6 +8,7 @@ #include "FileTypeWindow.h" #include "IconView.h" #include "PreferredAppMenu.h" +#include "TypeListWindow.h" #include #include @@ -26,6 +27,7 @@ const uint32 kMsgTypeEntered = 'type'; const uint32 kMsgSelectType = 'sltp'; +const uint32 kMsgTypeSelected = 'tpsd'; const uint32 kMsgSameTypeAs = 'stpa'; const uint32 kMsgSameTypeAsOpened = 'stpO'; @@ -366,6 +368,24 @@ FileTypeWindow::MessageReceived(BMessage* message) _AdoptType(); break; + case kMsgSelectType: + { + BWindow* window = new TypeListWindow(fCommonType.String(), + kMsgTypeSelected, this); + window->Show(); + break; + } + case kMsgTypeSelected: + { + const char* type; + if (message->FindString("type", &type) == B_OK) { + fCommonType = type; + fTypeControl->SetText(type); + _AdoptType(); + } + break; + } + case kMsgSameTypeAs: { BMessage panel(kMsgOpenFilePanel); diff --git a/src/preferences/filetypes/Jamfile b/src/preferences/filetypes/Jamfile index 3e29e31af2..fe2ab09bf3 100644 --- a/src/preferences/filetypes/Jamfile +++ b/src/preferences/filetypes/Jamfile @@ -16,6 +16,7 @@ Preference FileTypes : AttributeWindow.cpp ExtensionWindow.cpp FileTypeWindow.cpp + TypeListWindow.cpp IconView.cpp PreferredAppMenu.cpp StringView.cpp diff --git a/src/preferences/filetypes/NewFileTypeWindow.cpp b/src/preferences/filetypes/NewFileTypeWindow.cpp index 884f565b0a..f7df0399bf 100644 --- a/src/preferences/filetypes/NewFileTypeWindow.cpp +++ b/src/preferences/filetypes/NewFileTypeWindow.cpp @@ -181,6 +181,10 @@ NewFileTypeWindow::MessageReceived(BMessage* message) PostMessage(B_QUIT_REQUESTED); break; } + + default: + BWindow::MessageReceived(message); + break; } } diff --git a/src/preferences/filetypes/TypeListWindow.cpp b/src/preferences/filetypes/TypeListWindow.cpp new file mode 100644 index 0000000000..7ed4efe8b4 --- /dev/null +++ b/src/preferences/filetypes/TypeListWindow.cpp @@ -0,0 +1,97 @@ +/* + * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "MimeTypeListView.h" +#include "TypeListWindow.h" + +#include +#include + +#include + + +const uint32 kMsgTypeSelected = 'tpsl'; +const uint32 kMsgSelected = 'seld'; + + +TypeListWindow::TypeListWindow(const char* currentType, uint32 what, BWindow* target) + : BWindow(BRect(100, 100, 360, 440), "Choose Type", B_MODAL_WINDOW, + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), + fTarget(target), + fWhat(what) +{ + BRect rect = Bounds(); + BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); + topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(topView); + + fSelectButton = new BButton(rect, "select", "Done", + new BMessage(kMsgSelected), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + fSelectButton->ResizeToPreferred(); + fSelectButton->MoveTo(topView->Bounds().right - 8.0f - fSelectButton->Bounds().Width(), + topView->Bounds().bottom - 8.0f - fSelectButton->Bounds().Height()); + fSelectButton->SetEnabled(false); + topView->AddChild(fSelectButton); + fSelectButton->MakeDefault(true); + + BButton* button = new BButton(fSelectButton->Frame(), "cancel", "Cancel", + new BMessage(B_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + button->ResizeToPreferred(); + button->MoveBy(-button->Bounds().Width() - 8.0f, 0.0f); + topView->AddChild(button); + + rect.bottom = button->Frame().top - 10.0f; + rect.top = 10.0f; + rect.left = 10.0f; + rect.right -= 10.0f + B_V_SCROLL_BAR_WIDTH; + fListView = new MimeTypeListView(rect, "typeview", NULL, true, false, + B_FOLLOW_ALL); + fListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); + fListView->SetInvocationMessage(new BMessage(kMsgSelected)); + + BScrollView* scrollView = new BScrollView("scrollview", fListView, + B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); + topView->AddChild(scrollView); + + MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f)); +} + + +TypeListWindow::~TypeListWindow() +{ +} + + +void +TypeListWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgTypeSelected: + fSelectButton->SetEnabled(fListView->CurrentSelection() >= 0); + break; + + case kMsgSelected: + { + MimeTypeItem* item = dynamic_cast(fListView->ItemAt( + fListView->CurrentSelection())); + if (item != NULL) { + BMessage select(fWhat); + select.AddString("type", item->Type()); + fTarget.SendMessage(&select); + } + + // supposed to fall through + } + case B_CANCEL: + PostMessage(B_QUIT_REQUESTED); + break; + + default: + BWindow::MessageReceived(message); + break; + } +} + diff --git a/src/preferences/filetypes/TypeListWindow.h b/src/preferences/filetypes/TypeListWindow.h new file mode 100644 index 0000000000..771be8cfa0 --- /dev/null +++ b/src/preferences/filetypes/TypeListWindow.h @@ -0,0 +1,33 @@ +/* + * Copyright 2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef TYPE_LIST_WINDOW_H +#define TYPE_LIST_WINDOW_H + + +#include +#include + +class BButton; +class BMenu; +class BTextControl; + +class MimeTypeListView; + + +class TypeListWindow : public BWindow { + public: + TypeListWindow(const char* currentType, uint32 what, BWindow* target); + virtual ~TypeListWindow(); + + virtual void MessageReceived(BMessage* message); + + private: + BMessenger fTarget; + uint32 fWhat; + MimeTypeListView* fListView; + BButton* fSelectButton; +}; + +#endif // TYPE_LIST_WINDOW_H