Puh... basically this is the patch by "yourpalal" from ticket #5690, which

converts the FileTypes preflet to use layout management. However, I had to
revert r36252, apply the patch and then manually add r36252 back on top.
I have fixed issues both in the layout management patch (broken layout
in the ApplicationTypesWindow) as well as the translation (untranslated labels
in alerts) and other problems with composed strings (one problem remains, but
already had a TODO). However, the hard work was taken care of by yourpalal!
Thanks a bunch!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-04-21 20:05:31 +00:00
parent 17c5e0648d
commit 50a2f6d7b2
23 changed files with 976 additions and 1403 deletions
@@ -18,8 +18,12 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ControlLook.h>
#include <File.h> #include <File.h>
#include <Locale.h> #include <Locale.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <GroupView.h>
#include <ListView.h> #include <ListView.h>
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuField.h> #include <MenuField.h>
@@ -30,6 +34,7 @@
#include <RadioButton.h> #include <RadioButton.h>
#include <Roster.h> #include <Roster.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <ctype.h> #include <ctype.h>
@@ -60,16 +65,14 @@ const uint32 kMsgTypeRemoved = 'tprm';
// TextView that filters the tab key to be able to tab-navigate while editing // TextView that filters the tab key to be able to tab-navigate while editing
class TabFilteringTextView : public BTextView { class TabFilteringTextView : public BTextView {
public: public:
TabFilteringTextView(BRect frame, const char* name, BRect textRect, TabFilteringTextView(const char* name);
uint32 resizeMask, uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED);
virtual ~TabFilteringTextView(); virtual ~TabFilteringTextView();
virtual void KeyDown(const char* bytes, int32 count); virtual void KeyDown(const char* bytes, int32 count);
}; };
TabFilteringTextView::TabFilteringTextView(BRect frame, const char* name, TabFilteringTextView::TabFilteringTextView(const char* name)
BRect textRect, uint32 resizeMask, uint32 flags) : BTextView(name, B_WILL_DRAW | B_PULSE_NEEDED)
: BTextView(frame, name, textRect, resizeMask, flags)
{ {
} }
@@ -108,9 +111,8 @@ class SupportedTypeItem : public BStringItem {
class SupportedTypeListView : public DropTargetListView { class SupportedTypeListView : public DropTargetListView {
public: public:
SupportedTypeListView(BRect frame, const char* name, SupportedTypeListView(const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST, list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~SupportedTypeListView(); virtual ~SupportedTypeListView();
@@ -159,11 +161,11 @@ SupportedTypeItem::Compare(const void* _a, const void* _b)
{ {
const SupportedTypeItem* a = *(const SupportedTypeItem**)_a; const SupportedTypeItem* a = *(const SupportedTypeItem**)_a;
const SupportedTypeItem* b = *(const SupportedTypeItem**)_b; const SupportedTypeItem* b = *(const SupportedTypeItem**)_b;
int compare = strcasecmp(a->Text(), b->Text()); int compare = strcasecmp(a->Text(), b->Text());
if (compare != 0) if (compare != 0)
return compare; return compare;
return strcasecmp(a->Type(), b->Type()); return strcasecmp(a->Type(), b->Type());
} }
@@ -171,9 +173,10 @@ SupportedTypeItem::Compare(const void* _a, const void* _b)
// #pragma mark - // #pragma mark -
SupportedTypeListView::SupportedTypeListView(BRect frame, const char* name, SupportedTypeListView::SupportedTypeListView(const char* name,
list_view_type type, uint32 resizeMask, uint32 flags) list_view_type type, uint32 flags)
: DropTargetListView(frame, name, type, resizeMask, flags) :
DropTargetListView(name, type, flags)
{ {
} }
@@ -194,12 +197,12 @@ SupportedTypeListView::MessageReceived(BMessage* message)
BNodeInfo info(&node); BNodeInfo info(&node);
if (node.InitCheck() != B_OK || info.InitCheck() != B_OK) if (node.InitCheck() != B_OK || info.InitCheck() != B_OK)
continue; continue;
// TODO: we could identify the file in case it doesn't have a type... // TODO: we could identify the file in case it doesn't have a type...
char type[B_MIME_TYPE_LENGTH]; char type[B_MIME_TYPE_LENGTH];
if (info.GetType(type) != B_OK) if (info.GetType(type) != B_OK)
continue; continue;
// check if that type is already in our list // check if that type is already in our list
bool found = false; bool found = false;
for (int32 i = CountItems(); i-- > 0;) { for (int32 i = CountItems(); i-- > 0;) {
@@ -209,13 +212,13 @@ SupportedTypeListView::MessageReceived(BMessage* message)
break; break;
} }
} }
if (!found) { if (!found) {
// add type // add type
AddItem(new SupportedTypeItem(type)); AddItem(new SupportedTypeItem(type));
} }
} }
SortItems(&SupportedTypeItem::Compare); SortItems(&SupportedTypeItem::Compare);
} else } else
DropTargetListView::MessageReceived(message); DropTargetListView::MessageReceived(message);
@@ -233,17 +236,26 @@ SupportedTypeListView::AcceptsDrag(const BMessage* message)
// #pragma mark - // #pragma mark -
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry) ApplicationTypeWindow::ApplicationTypeWindow(BPoint position,
: BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), const BEntry& entry)
TR("Application Type"), B_TITLED_WINDOW, :
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position),
TR("Application type"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS |
B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS),
fChangedProperties(0) fChangedProperties(0)
{ {
// add the menu float padding = 3.0f;
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); if (be_control_look){
AddChild(menuBar); // padding = be_control_look->DefaultItemSpacing();
// seems too big
labelAlignment = be_control_look->DefaultLabelAlignment();
}
BMenuBar* menuBar = new BMenuBar((char*)NULL);
menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP));
BMenu* menu = new BMenu(TR("File")); BMenu* menu = new BMenu(TR("File"));
fSaveMenuItem = new BMenuItem(TR("Save"), new BMessage(kMsgSave), 'S'); fSaveMenuItem = new BMenuItem(TR("Save"), new BMessage(kMsgSave), 'S');
fSaveMenuItem->SetEnabled(false); fSaveMenuItem->SetEnabled(false);
@@ -252,32 +264,20 @@ ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entr
menu->AddItem(item = new BMenuItem( menu->AddItem(item = new BMenuItem(
TR("Save into resource file" B_UTF8_ELLIPSIS), NULL)); TR("Save into resource file" B_UTF8_ELLIPSIS), NULL));
item->SetEnabled(false); item->SetEnabled(false);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(TR("Close"), new BMessage(B_QUIT_REQUESTED), menu->AddItem(new BMenuItem(TR("Close"), new BMessage(B_QUIT_REQUESTED),
'W', B_COMMAND_KEY)); 'W', B_COMMAND_KEY));
menuBar->AddItem(menu); menuBar->AddItem(menu);
// Top view and signature // Signature
BRect rect = Bounds(); fSignatureControl = new BTextControl(TR("Signature:"), NULL,
rect.top = menuBar->Bounds().Height() + 1.0f;
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
rect = topView->Bounds().InsetByCopy(8.0f, 8.0f);
fSignatureControl = new BTextControl(rect, "signature", TR("Signature:"), NULL,
new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT);
fSignatureControl->SetModificationMessage(
new BMessage(kMsgSignatureChanged)); new BMessage(kMsgSignatureChanged));
fSignatureControl->SetDivider(fSignatureControl->StringWidth( fSignatureControl->SetModificationMessage(
fSignatureControl->Label()) + 4.0f); new BMessage(kMsgSignatureChanged));
float width, height;
fSignatureControl->GetPreferredSize(&width, &height);
fSignatureControl->ResizeTo(rect.Width(), height);
topView->AddChild(fSignatureControl);
// filter out invalid characters that can't be part of a MIME type name // filter out invalid characters that can't be part of a MIME type name
BTextView* textView = fSignatureControl->TextView(); BTextView* textView = fSignatureControl->TextView();
textView->SetMaxBytes(B_MIME_TYPE_LENGTH); textView->SetMaxBytes(B_MIME_TYPE_LENGTH);
@@ -285,278 +285,162 @@ ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entr
for (int32 i = 0; disallowedCharacters[i]; i++) { for (int32 i = 0; disallowedCharacters[i]; i++) {
textView->DisallowChar(disallowedCharacters[i]); textView->DisallowChar(disallowedCharacters[i]);
} }
// "Application Flags" group // "Application Flags" group
BBox* flagsBox = new BBox("flagsBox");
BFont font(be_bold_font); fFlagsCheckBox = new BCheckBox("flags", TR("Application flags"),
font_height fontHeight;
font.GetHeight(&fontHeight);
width = font.StringWidth("Icon") + 16.0f;
if (width < B_LARGE_ICON + 16.0f)
width = B_LARGE_ICON + 16.0f;
rect.top = fSignatureControl->Frame().bottom + 4.0f;
rect.bottom = rect.top + 100.0f;
rect.right -= width + 8.0f;
BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
topView->AddChild(box);
fFlagsCheckBox = new BCheckBox(rect, "flags", TR("Application flags"),
new BMessage(kMsgToggleAppFlags)); new BMessage(kMsgToggleAppFlags));
fFlagsCheckBox->SetValue(B_CONTROL_ON); fFlagsCheckBox->SetValue(B_CONTROL_ON);
fFlagsCheckBox->ResizeToPreferred();
box->SetLabel(fFlagsCheckBox); fSingleLaunchButton = new BRadioButton("single", TR("Single launch"),
rect.top = fFlagsCheckBox->Bounds().Height() + 4.0f;
fSingleLaunchButton = new BRadioButton(rect, "single", TR("Single launch"),
new BMessage(kMsgAppFlagsChanged)); new BMessage(kMsgAppFlagsChanged));
fSingleLaunchButton->ResizeToPreferred();
box->AddChild(fSingleLaunchButton); fMultipleLaunchButton = new BRadioButton("multiple",
rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
fMultipleLaunchButton = new BRadioButton(rect, "multiple",
TR("Multiple launch"), new BMessage(kMsgAppFlagsChanged)); TR("Multiple launch"), new BMessage(kMsgAppFlagsChanged));
fMultipleLaunchButton->ResizeToPreferred();
box->AddChild(fMultipleLaunchButton); fExclusiveLaunchButton = new BRadioButton("exclusive",
rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
fExclusiveLaunchButton = new BRadioButton(rect, "exclusive",
TR("Exclusive launch"), new BMessage(kMsgAppFlagsChanged)); TR("Exclusive launch"), new BMessage(kMsgAppFlagsChanged));
fExclusiveLaunchButton->ResizeToPreferred();
box->AddChild(fExclusiveLaunchButton); fArgsOnlyCheckBox = new BCheckBox("args only", TR("Args only"),
rect.top = fSingleLaunchButton->Frame().top;
rect.left = fExclusiveLaunchButton->Frame().right + 4.0f;
fArgsOnlyCheckBox = new BCheckBox(rect, "args only", TR("Args only"),
new BMessage(kMsgAppFlagsChanged)); new BMessage(kMsgAppFlagsChanged));
fArgsOnlyCheckBox->ResizeToPreferred();
box->AddChild(fArgsOnlyCheckBox); fBackgroundAppCheckBox = new BCheckBox("background",
rect.top += fArgsOnlyCheckBox->Bounds().Height();
fBackgroundAppCheckBox = new BCheckBox(rect, "background",
TR("Background app"), new BMessage(kMsgAppFlagsChanged)); TR("Background app"), new BMessage(kMsgAppFlagsChanged));
fBackgroundAppCheckBox->ResizeToPreferred();
box->AddChild(fBackgroundAppCheckBox); flagsBox->AddChild(BGridLayoutBuilder(padding, padding)
.Add(fSingleLaunchButton, 0, 0).Add(fArgsOnlyCheckBox, 1, 0)
box->ResizeTo(box->Bounds().Width(), .Add(fMultipleLaunchButton, 0, 1).Add(fBackgroundAppCheckBox, 1, 1)
fExclusiveLaunchButton->Frame().bottom + 8.0f); .Add(fExclusiveLaunchButton, 0, 2)
.SetInsets(padding, padding, padding, padding));
flagsBox->SetLabel(fFlagsCheckBox);
// "Icon" group // "Icon" group
rect = box->Frame(); BBox* iconBox = new BBox("IconBox");
#ifdef __HAIKU__ iconBox->SetLabel(TR("Icon"));
rect.top += box->TopBorderOffset(); fIconView = new IconView("icon");
#endif
rect.left = rect.right + 8.0f;
rect.right += width + 8.0f;
float iconBoxWidth = rect.Width();
box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
box->SetLabel("Icon");
#ifdef __HAIKU__
box->MoveBy(0.0f, -box->TopBorderOffset());
box->ResizeBy(0.0f, box->TopBorderOffset());
#endif
topView->AddChild(box);
rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f);
#ifdef __HAIKU__
rect.OffsetBy(0.0f, (box->Bounds().Height() + box->TopBorderOffset()
- rect.Height()) / 2.0f);
#else
rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f);
#endif
if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f)
rect.top = fontHeight.ascent + fontHeight.descent + 4.0f;
fIconView = new IconView(rect, "icon");
fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); fIconView->SetModificationMessage(new BMessage(kMsgIconChanged));
box->AddChild(fIconView); iconBox->AddChild(
BGroupLayoutBuilder(B_HORIZONTAL)
.Add(fIconView)
.SetInsets(padding, padding, padding, padding)
);
// "Supported Types" group // "Supported Types" group
rect.top = box->Frame().bottom + 8.0f; BBox* typeBox = new BBox("typesBox");
rect.bottom = rect.top + box->Bounds().Height();
rect.left = 8.0f;
rect.right = Bounds().Width() - 8.0f;
BBox* typeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
typeBox->SetLabel(TR("Supported types")); typeBox->SetLabel(TR("Supported types"));
topView->AddChild(typeBox);
fTypeListView = new SupportedTypeListView("Suppported Types",
rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f); B_SINGLE_SELECTION_LIST);
rect.top += ceilf(fontHeight.ascent);
fAddTypeButton = new BButton(rect, "add type", TR("Add" B_UTF8_ELLIPSIS),
new BMessage(kMsgAddType), B_FOLLOW_RIGHT);
fAddTypeButton->ResizeToPreferred();
fAddTypeButton->MoveBy(rect.right - fAddTypeButton->Bounds().Width()
- B_LARGE_ICON - 16.0f, 0.0f);
typeBox->AddChild(fAddTypeButton);
rect = fAddTypeButton->Frame();
rect.OffsetBy(0, rect.Height() + 4.0f);
fRemoveTypeButton = new BButton(rect, "remove type", TR("Remove"),
new BMessage(kMsgRemoveType), B_FOLLOW_RIGHT);
typeBox->AddChild(fRemoveTypeButton);
rect.right = rect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
rect.left = 10.0f;
rect.top = 8.0f + ceilf(fontHeight.ascent);
rect.bottom -= 2.0f;
// take scrollview border into account
fTypeListView = new SupportedTypeListView(rect, "type listview",
B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView, BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView,
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); B_FRAME_EVENTS | B_WILL_DRAW, false, true);
typeBox->ResizeTo(typeBox->Bounds().Width(), fRemoveTypeButton->Frame().bottom + 8.0f); fAddTypeButton = new BButton("add type", TR("Add" B_UTF8_ELLIPSIS),
typeBox->AddChild(scrollView); new BMessage(kMsgAddType));
rect.left = fRemoveTypeButton->Frame().right + 8.0f; fRemoveTypeButton = new BButton("remove type", TR("Remove"),
#ifdef __HAIKU__ new BMessage(kMsgRemoveType));
rect.top = (box->Bounds().Height() + box->TopBorderOffset() - B_LARGE_ICON) / 2.0f;
#else fTypeIconView = new IconView("type icon");
rect.top = (box->Bounds().Height() - B_LARGE_ICON) / 2.0f; BView* iconHolder = BGroupLayoutBuilder(B_HORIZONTAL).Add(fTypeIconView);
#endif
rect.right = rect.left + B_LARGE_ICON - 1.0f;
rect.bottom = rect.top + B_LARGE_ICON - 1.0f;
fTypeIconView = new IconView(rect, "type icon", B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged));
typeBox->AddChild(fTypeIconView);
typeBox->AddChild(BGridLayoutBuilder(padding, padding)
.Add(scrollView, 0, 0, 1, 4)
.Add(fAddTypeButton, 1, 0, 1, 2)
.Add(fRemoveTypeButton, 1, 2, 1, 2)
.Add(iconHolder, 2, 1, 1, 2)
.SetInsets(padding, padding, padding, padding)
.SetColumnWeight(0, 3)
.SetColumnWeight(1, 2)
.SetColumnWeight(2, 1)
);
iconHolder->SetExplicitAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
// "Version Info" group // "Version Info" group
rect.top = typeBox->Frame().bottom + 8.0f; BBox* versionBox = new BBox("versionBox");
rect.bottom = rect.top + typeBox->Bounds().Height(); versionBox->SetLabel(TR("Version info"));
rect.left = 8.0f;
rect.right = Bounds().Width() - 8.0f; fMajorVersionControl = new BTextControl(TR("Version:"), NULL, NULL);
box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
// the resizing mode will later also be set to B_FOLLOW_BOTTOM
box->SetLabel(TR("Version info"));
topView->AddChild(box);
BMenuField* menuField;
#if 0
BPopUpMenu *popUpMenu = new BPopUpMenu("version info", true, true);
item = new BMenuItem("Version Info", NULL);
item->SetMarked(true);
popUpMenu->AddItem(item);
item = new BMenuItem("System Version Info", NULL);
popUpMenu->AddItem(item);
menuField = new BMenuField(BRect(0, 0, 100, 15),
"version kind", NULL, popUpMenu, true);
menuField->ResizeToPreferred();
box->SetLabel(menuField);
#endif
rect.top = 4.0f + ceilf(fontHeight.ascent + fontHeight.descent);
rect.bottom = rect.top + height;
fMajorVersionControl = new BTextControl(rect, "major", TR("Version:"), NULL,
NULL);
fMajorVersionControl->SetDivider(fMajorVersionControl->StringWidth(
fMajorVersionControl->Label()) + 4.0f);
fMajorVersionControl->GetPreferredSize(&width, &height);
width = 12.0f + fMajorVersionControl->StringWidth("99");
fMajorVersionControl->ResizeTo(fMajorVersionControl->Divider() + width, height);
_MakeNumberTextControl(fMajorVersionControl); _MakeNumberTextControl(fMajorVersionControl);
box->AddChild(fMajorVersionControl);
fMiddleVersionControl = new BTextControl(".", NULL, NULL);
rect.left = fMajorVersionControl->Frame().right + 1.0f;
fMiddleVersionControl = new BTextControl(rect, "middle", ".", NULL,
NULL);
fMiddleVersionControl->SetDivider(fMiddleVersionControl->StringWidth(
fMiddleVersionControl->Label()) + 4.0f);
fMiddleVersionControl->ResizeTo(fMiddleVersionControl->Divider() + width, height);
_MakeNumberTextControl(fMiddleVersionControl); _MakeNumberTextControl(fMiddleVersionControl);
box->AddChild(fMiddleVersionControl);
fMinorVersionControl = new BTextControl(".", NULL, NULL);
rect.left = fMiddleVersionControl->Frame().right + 1.0f;
fMinorVersionControl = new BTextControl(rect, "middle", ".", NULL,
NULL);
fMinorVersionControl->SetDivider(fMinorVersionControl->StringWidth(
fMinorVersionControl->Label()) + 4.0f);
fMinorVersionControl->ResizeTo(fMinorVersionControl->Divider() + width, height);
_MakeNumberTextControl(fMinorVersionControl); _MakeNumberTextControl(fMinorVersionControl);
box->AddChild(fMinorVersionControl);
fVarietyMenu = new BPopUpMenu("variety", true, true); fVarietyMenu = new BPopUpMenu("variety", true, true);
fVarietyMenu->AddItem(new BMenuItem(TR("Development"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Development"), NULL));
fVarietyMenu->AddItem(new BMenuItem(TR("Alpha"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Alpha"), NULL));
fVarietyMenu->AddItem(new BMenuItem(TR("Beta"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Beta"), NULL));
fVarietyMenu->AddItem(new BMenuItem(TR("Gamma"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Gamma"), NULL));
fVarietyMenu->AddItem(item = new BMenuItem(TR("Golden master"), NULL)); item = new BMenuItem(TR("Golden master"), NULL);
fVarietyMenu->AddItem(item);
item->SetMarked(true); item->SetMarked(true);
fVarietyMenu->AddItem(new BMenuItem(TR("Final"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Final"), NULL));
rect.top--; BMenuField* varietyField = new BMenuField("", fVarietyMenu);
// BMenuField oddity fInternalVersionControl = new BTextControl("/", NULL, NULL);
rect.left = fMinorVersionControl->Frame().right + 6.0f; fShortDescriptionControl =
menuField = new BMenuField(rect, new BTextControl(TR("Short description:"), NULL, NULL);
"variety", NULL, fVarietyMenu, true);
menuField->ResizeToPreferred();
box->AddChild(menuField);
rect.top++;
rect.left = menuField->Frame().right;
rect.right = rect.left + 30.0f;
fInternalVersionControl = new BTextControl(rect, "internal", "/", NULL,
NULL);
fInternalVersionControl->SetDivider(fInternalVersionControl->StringWidth(
fInternalVersionControl->Label()) + 4.0f);
fInternalVersionControl->ResizeTo(fInternalVersionControl->Divider() + width, height);
box->AddChild(fInternalVersionControl);
rect = box->Bounds().InsetByCopy(8.0f, 0.0f);
rect.top = fInternalVersionControl->Frame().bottom + 8.0f;
fShortDescriptionControl = new BTextControl(rect, "short desc", TR("Short description:"),
NULL, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
float labelWidth = fShortDescriptionControl->StringWidth(
fShortDescriptionControl->Label()) + 4.0f;
fShortDescriptionControl->SetDivider(labelWidth);
fShortDescriptionControl->GetPreferredSize(&width, &height);
fShortDescriptionControl->ResizeTo(rect.Width(), height);
// TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says? // TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says?
version_info versionInfo; version_info versionInfo;
fShortDescriptionControl->TextView()->SetMaxBytes(sizeof(versionInfo.short_info)); fShortDescriptionControl->TextView()->SetMaxBytes(
box->AddChild(fShortDescriptionControl); sizeof(versionInfo.short_info));
rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f); BStringView* longLabel = new BStringView(NULL, TR("Long description:"));
rect.right = rect.left + labelWidth; longLabel->SetExplicitAlignment(labelAlignment);
StringView* label = new StringView(rect, NULL, TR("Long description:"), NULL); fLongDescriptionView = new TabFilteringTextView("long desc");
label->SetDivider(labelWidth);
box->AddChild(label);
rect.left = rect.right + 3.0f;
rect.top += 1.0f;
rect.right = box->Bounds().Width() - 10.0f - B_V_SCROLL_BAR_WIDTH;
rect.bottom = rect.top + fShortDescriptionControl->Bounds().Height() * 3.0f - 1.0f;
fLongDescriptionView = new TabFilteringTextView(rect, "long desc",
rect.OffsetToCopy(B_ORIGIN), B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS
| B_NAVIGABLE);
fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info)); fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info));
scrollView = new BScrollView("desc scrollview", fLongDescriptionView, scrollView = new BScrollView("desc scrollview", fLongDescriptionView,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FRAME_EVENTS | B_WILL_DRAW, false, true); B_FRAME_EVENTS | B_WILL_DRAW, false, true);
box->ResizeTo(box->Bounds().Width(), scrollView->Frame().bottom + 8.0f);
box->AddChild(scrollView);
// Adjust window size and limits // TODO: remove workaround (bug #5678)
BSize minScrollSize = scrollView->ScrollBar(B_VERTICAL)->MinSize();
minScrollSize.width+=fLongDescriptionView->MinSize().width;
scrollView->SetExplicitMinSize(minScrollSize);
versionBox->AddChild(BGridLayoutBuilder(padding, padding)
.Add(fMajorVersionControl->CreateLabelLayoutItem(), 0, 0)
.Add(fMajorVersionControl->CreateTextViewLayoutItem(), 1, 0)
.Add(fMiddleVersionControl, 2, 0, 2)
.Add(fMinorVersionControl, 4, 0, 2)
.Add(varietyField, 6, 0, 3)
.Add(fInternalVersionControl, 9, 0, 2)
.Add(fShortDescriptionControl->CreateLabelLayoutItem(), 0, 1)
.Add(fShortDescriptionControl->CreateTextViewLayoutItem(), 1, 1, 10)
.Add(longLabel, 0, 2)
.Add(scrollView, 1, 2, 10, 3)
.SetInsets(padding, padding, padding, padding)
.SetRowWeight(3, 3)
);
width = fInternalVersionControl->Frame().right + 16.0f; // put it all together
float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f; SetLayout(new BGroupLayout(B_VERTICAL));
if (width > minWidth) AddChild(menuBar);
minWidth = width; AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(fSignatureControl)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(flagsBox, 3)
.Add(iconBox, 1)
)
.Add(typeBox)
.Add(versionBox)
.SetInsets(padding, padding, padding, padding)
);
ResizeTo(Bounds().Width() > minWidth ? Bounds().Width() : minWidth, SetKeyMenuBar(menuBar);
box->Frame().bottom + topView->Frame().top + 8.0f);
SetSizeLimits(minWidth, 32767.0f, Bounds().Height(), 32767.0f);
typeBox->SetResizingMode(B_FOLLOW_ALL);
box->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
fSignatureControl->MakeFocus(true); fSignatureControl->MakeFocus(true);
BMimeType::StartWatching(this); BMimeType::StartWatching(this);
_SetTo(entry); _SetTo(entry);
} }
@@ -982,7 +866,8 @@ ApplicationTypeWindow::MessageReceived(BMessage* message)
{ {
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
SupportedTypeItem* item = (SupportedTypeItem*)fTypeListView->ItemAt(index); SupportedTypeItem* item
= (SupportedTypeItem*)fTypeListView->ItemAt(index);
fTypeIconView->SetModificationMessage(NULL); fTypeIconView->SetModificationMessage(NULL);
fTypeIconView->SetTo(item != NULL ? &item->Icon() : NULL); fTypeIconView->SetTo(item != NULL ? &item->Icon() : NULL);
@@ -18,6 +18,9 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
@@ -60,7 +63,7 @@ const uint32 kMsgRemoveUninstalled = 'runs';
const uint32 kMsgEdit = 'edit'; const uint32 kMsgEdit = 'edit';
const char* const char*
variety_to_text(uint32 variety) variety_to_text(uint32 variety)
{ {
#if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE) #if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE)
@@ -94,42 +97,34 @@ variety_to_text(uint32 variety)
// #pragma mark - // #pragma mark -
ProgressWindow::ProgressWindow(const char* message, int32 max, volatile bool* signalQuit) ProgressWindow::ProgressWindow(const char* message,
: BWindow(BRect(0, 0, 300, 200), TR("Progress"), B_MODAL_WINDOW_LOOK, int32 max, volatile bool* signalQuit)
B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), :
BWindow(BRect(0, 0, 300, 200), TR("Progress"), B_MODAL_WINDOW_LOOK,
B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS |
B_NOT_V_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fQuitListener(signalQuit) fQuitListener(signalQuit)
{ {
BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
char count[100]; char count[100];
snprintf(count, sizeof(count), "/%ld", max); snprintf(count, sizeof(count), "/%ld", max);
BRect rect = Bounds().InsetByCopy(8, 8); fStatusBar = new BStatusBar("status", message, count);
fStatusBar = new BStatusBar(rect, "status", message, count);
fStatusBar->SetMaxValue(max); fStatusBar->SetMaxValue(max);
fStatusBar->SetResizingMode(B_FOLLOW_LEFT_RIGHT); fAbortButton = new BButton("abort", TR("Abort"), new BMessage(B_CANCEL));
float width, height;
fStatusBar->GetPreferredSize(&width, &height); SetLayout(new BGroupLayout(B_VERTICAL));
fStatusBar->ResizeTo(rect.Width(), height); AddChild(BGroupLayoutBuilder(B_VERTICAL, 3.0f)
topView->AddChild(fStatusBar); .Add(fStatusBar)
.Add(fAbortButton)
fAbortButton = new BButton(rect, "abort", TR("Abort"), new BMessage(B_CANCEL), .SetInsets(3.0f, 3.0f, 3.0f, 3.0f)
B_FOLLOW_H_CENTER | B_FOLLOW_TOP); );
fAbortButton->ResizeToPreferred();
fAbortButton->MoveTo((Bounds().Width() - fAbortButton->Bounds().Width()) / 2,
fStatusBar->Frame().bottom + 10.0f);
topView->AddChild(fAbortButton);
ResizeTo(width * 1.4f, fAbortButton->Frame().bottom + 8.0f);
SetSizeLimits(width + 42.0f, 32767.0f,
Bounds().Height(), Bounds().Height());
// center on screen // center on screen
BScreen screen(this); BScreen screen(this);
MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2.0f, MoveTo(screen.Frame().left + (screen.Frame().Width()
screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2.0f); - Bounds().Width()) / 2.0f,
screen.Frame().top + (screen.Frame().Height()
- Bounds().Height()) / 2.0f);
} }
@@ -165,138 +160,115 @@ ProgressWindow::MessageReceived(BMessage* message)
// #pragma mark - // #pragma mark -
ApplicationTypesWindow::ApplicationTypesWindow(const BMessage &settings) ApplicationTypesWindow::ApplicationTypesWindow(const BMessage& settings)
: BWindow(_Frame(settings), TR("Application types"), B_TITLED_WINDOW, : BWindow(_Frame(settings), TR("Application types"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
float padding = 3.0f;
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
BAlignment fullWidthTopAlignment =
BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP);
if (be_control_look) {
// padding = be_control_look->DefaultItemSpacing();
// seems too big
labelAlignment = be_control_look->DefaultLabelAlignment();
}
// Application list // Application list
BView* currentView = new BGroupView(B_VERTICAL, padding);
BRect rect = Bounds(); fTypeListView = new MimeTypeListView("listview", "application", true, true);
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
BButton* button = new BButton(rect, "remove", TR("Remove uninstalled"),
new BMessage(kMsgRemoveUninstalled), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->MoveTo(8.0f, rect.bottom - 8.0f - button->Bounds().Height());
topView->AddChild(button);
rect.bottom = button->Frame().top - 10.0f;
rect.top = 10.0f;
rect.left = 10.0f;
rect.right = 170;
fTypeListView = new MimeTypeListView(rect, "listview", "application", true, true,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
fTypeListView->SetInvocationMessage(new BMessage(kMsgTypeInvoked)); fTypeListView->SetInvocationMessage(new BMessage(kMsgTypeInvoked));
BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, BScrollView* scrollView = new BScrollView("scrollview", fTypeListView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); B_FRAME_EVENTS | B_WILL_DRAW, false, true);
topView->AddChild(scrollView);
BButton* button = new BButton("remove", TR("Remove uninstalled"),
new BMessage(kMsgRemoveUninstalled));
SetLayout(BGroupLayoutBuilder(B_HORIZONTAL));
// "Information" group // "Information" group
BFont font(be_bold_font); BBox* infoBox = new BBox((char*)NULL);
font_height fontHeight; infoBox->SetLabel(TR("Information"));
font.GetHeight(&fontHeight); infoBox->SetExplicitAlignment(fullWidthTopAlignment);
fNameView = new StringView(TR("Name:"), NULL);
fNameView->TextView()->SetExplicitAlignment(labelAlignment);
fNameView->LabelView()->SetExplicitAlignment(labelAlignment);
fSignatureView = new StringView(TR("Signature:"), NULL);
fSignatureView->TextView()->SetExplicitAlignment(labelAlignment);
fSignatureView->LabelView()->SetExplicitAlignment(labelAlignment);
fPathView = new StringView(TR("Path:"), NULL);
fPathView->TextView()->SetExplicitAlignment(labelAlignment);
fPathView->LabelView()->SetExplicitAlignment(labelAlignment);
rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; infoBox->AddChild(
rect.top -= 2.0f; BGridLayoutBuilder(padding, padding)
rect.right = topView->Bounds().Width() - 8.0f; .Add(fNameView->LabelView(), 0, 0)
rect.bottom = rect.top + ceilf(fontHeight.ascent) + 24.0f; .Add(fNameView->TextView(), 1, 0, 2)
BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); .Add(fSignatureView->LabelView(), 0, 1)
box->SetLabel(TR("Information")); .Add(fSignatureView->TextView(), 1, 1, 2)
topView->AddChild(box); .Add(fPathView->LabelView(), 0, 2)
.Add(fPathView->TextView(), 1, 2, 2)
BRect innerRect = box->Bounds().InsetByCopy(8.0f, 6.0f); .SetInsets(padding, padding, padding, padding)
float labelWidth = topView->StringWidth(TR("Description:")) + 4.0f; );
innerRect.right = box->Bounds().Width() - 8.0f;
innerRect.top += ceilf(fontHeight.ascent);
fNameView = new StringView(innerRect, "name", TR("Name:"), NULL, B_FOLLOW_LEFT_RIGHT);
fNameView->SetDivider(labelWidth);
float width, height;
fNameView->GetPreferredSize(&width, &height);
fNameView->ResizeTo(innerRect.Width(), height);
box->ResizeBy(0, fNameView->Bounds().Height() * 3.0f);
box->AddChild(fNameView);
innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f);
innerRect.bottom = innerRect.top + height;
fSignatureView = new StringView(innerRect, "signature", TR("Signature:"), NULL,
B_FOLLOW_LEFT_RIGHT);
fSignatureView->SetDivider(labelWidth);
box->AddChild(fSignatureView);
innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f);
fPathView = new StringView(innerRect, "path", TR("Path:"), NULL,
B_FOLLOW_LEFT_RIGHT);
fPathView->SetDivider(labelWidth);
box->AddChild(fPathView);
// "Version" group // "Version" group
rect.top = box->Frame().bottom + 8.0f; BBox* versionBox = new BBox("");
rect.bottom = rect.top + ceilf(fontHeight.ascent) versionBox->SetLabel(TR("Version"));
+ fNameView->Bounds().Height() * 4.0f + 20.0f; versionBox->SetExplicitAlignment(fullWidthTopAlignment);
box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
box->SetLabel(TR("Version"));
topView->AddChild(box);
innerRect = fNameView->Frame(); fVersionView = new StringView(TR("Version:"), NULL);
fVersionView = new StringView(innerRect, "version", TR("Version:"), NULL, fVersionView->TextView()->SetExplicitAlignment(labelAlignment);
B_FOLLOW_LEFT_RIGHT); fVersionView->LabelView()->SetExplicitAlignment(labelAlignment);
fVersionView->SetDivider(labelWidth); fDescriptionLabel = new StringView(TR("Description:"), NULL);
box->AddChild(fVersionView); fDescriptionLabel->LabelView()->SetExplicitAlignment(labelAlignment);
fDescriptionView = new BTextView("description");
innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f);
innerRect.right = innerRect.left + labelWidth;
fDescriptionLabel = new StringView(innerRect, "description", TR("Description:"), NULL);
fDescriptionLabel->SetDivider(labelWidth);
box->AddChild(fDescriptionLabel);
innerRect.left = innerRect.right + 3.0f;
innerRect.top += 1.0f;
innerRect.right = box->Bounds().Width() - 8.0f;
innerRect.bottom += fNameView->Bounds().Height() * 2.0f - 1.0f;
fDescriptionView = new BTextView(innerRect, "description",
innerRect.OffsetToCopy(B_ORIGIN), B_FOLLOW_LEFT_RIGHT,
B_WILL_DRAW | B_FRAME_EVENTS);
fDescriptionView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fDescriptionView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fDescriptionView->SetLowColor(fDescriptionView->ViewColor()); fDescriptionView->SetLowColor(fDescriptionView->ViewColor());
fDescriptionView->MakeEditable(false); fDescriptionView->MakeEditable(false);
box->AddChild(fDescriptionView);
versionBox->AddChild(currentView =
BGridLayoutBuilder(padding, padding)
.Add(fVersionView->LabelView(), 0, 0)
.Add(fVersionView->TextView(), 1, 0)
.Add(fDescriptionLabel->LabelView(), 0, 1)
.Add(fDescriptionView, 1, 1, 2, 2)
.SetInsets(padding, padding, padding, padding)
);
currentView->SetExplicitAlignment(fullWidthTopAlignment);
// Launch and Tracker buttons // Launch and Tracker buttons
rect = box->Frame(); fEditButton = new BButton(TR("Edit" B_UTF8_ELLIPSIS), new BMessage(kMsgEdit));
rect.top = rect.bottom + 8.0f; // launch and tracker buttons get messages in _SetType()
rect.bottom = rect.top + 20.0f; fLaunchButton = new BButton(TR("Launch"));
fTrackerButton = new BButton(rect, "tracker", TR("Show in Tracker" B_UTF8_ELLIPSIS), NULL, fTrackerButton = new BButton(TR("Show in Tracker" B_UTF8_ELLIPSIS));
B_FOLLOW_RIGHT);
fTrackerButton->ResizeToPreferred();
fTrackerButton->MoveTo(rect.right - fTrackerButton->Bounds().Width(), rect.top);
topView->AddChild(fTrackerButton);
fLaunchButton = new BButton(rect, "launch", TR("Launch"), NULL, AddChild(BGroupLayoutBuilder(B_HORIZONTAL, padding)
B_FOLLOW_RIGHT); .Add(BGroupLayoutBuilder(B_VERTICAL, padding)
fLaunchButton->ResizeToPreferred(); .Add(scrollView)
fLaunchButton->MoveTo(fTrackerButton->Frame().left - 6.0f .Add(button)
- fLaunchButton->Bounds().Width(), rect.top); .SetInsets(padding, padding, padding, padding)
topView->AddChild(fLaunchButton); , 3)
.Add(BGroupLayoutBuilder(B_VERTICAL, padding)
fEditButton = new BButton(rect, "edit", TR("Edit" B_UTF8_ELLIPSIS), new BMessage(kMsgEdit), .Add(infoBox)
B_FOLLOW_RIGHT); .Add(versionBox)
fEditButton->ResizeToPreferred(); .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
fEditButton->MoveTo(fLaunchButton->Frame().left - 6.0f .Add(fEditButton)
- fEditButton->Bounds().Width(), rect.top); .Add(fLaunchButton)
topView->AddChild(fEditButton); .Add(fTrackerButton)
)
SetSizeLimits(scrollView->Frame().right + 22.0f + fTrackerButton->Frame().Width() .AddGlue()
+ fLaunchButton->Frame().Width() + 6 + fEditButton->Frame().Width(), 32767.0f, .SetInsets(padding, padding, padding, padding)
fTrackerButton->Frame().bottom + 8.0f, 32767.0f); )
.SetInsets(padding, padding, padding, padding)
);
BMimeType::StartWatching(this); BMimeType::StartWatching(this);
_SetType(NULL); _SetType(NULL);
@@ -328,13 +300,15 @@ ApplicationTypesWindow::_RemoveUninstalled()
int32 removed = 0; int32 removed = 0;
volatile bool quit = false; volatile bool quit = false;
BWindow* progressWindow = new ProgressWindow(TR("Removing uninstalled application types"), BWindow* progressWindow =
fTypeListView->FullListCountItems(), &quit); new ProgressWindow(TR("Removing uninstalled application types"),
fTypeListView->FullListCountItems(), &quit);
progressWindow->AddToSubset(this); progressWindow->AddToSubset(this);
progressWindow->Show(); progressWindow->Show();
for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) { for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) {
MimeTypeItem* item = dynamic_cast<MimeTypeItem*>(fTypeListView->FullListItemAt(i)); MimeTypeItem* item = dynamic_cast<MimeTypeItem*>
(fTypeListView->FullListItemAt(i));
progressWindow->PostMessage(B_UPDATE_STATUS_BAR); progressWindow->PostMessage(B_UPDATE_STATUS_BAR);
if (item == NULL) if (item == NULL)
@@ -381,9 +355,9 @@ ApplicationTypesWindow::_RemoveUninstalled()
progressWindow->PostMessage(B_QUIT_REQUESTED); progressWindow->PostMessage(B_QUIT_REQUESTED);
char message[512]; char message[512];
// TODO : use ICU to properly format this // TODO: Use ICU to properly format this.
snprintf(message, sizeof(message), TR("%ld Application type%s could be removed."), snprintf(message, sizeof(message), TR("%ld Application type%s could be "
removed, removed == 1 ? "" : "s"); "removed."), removed, removed == 1 ? "" : "s");
error_alert(message, B_OK, B_INFO_ALERT); error_alert(message, B_OK, B_INFO_ALERT);
} }
@@ -456,11 +430,14 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate)
BAppFileInfo appInfo(&file); BAppFileInfo appInfo(&file);
version_info versionInfo; version_info versionInfo;
if (appInfo.InitCheck() == B_OK if (appInfo.InitCheck() == B_OK
&& appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) { && appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND)
== B_OK) {
char version[256]; char version[256];
snprintf(version, sizeof(version), "%lu.%lu.%lu, %s/%lu", snprintf(version, sizeof(version), "%lu.%lu.%lu, %s/%lu",
versionInfo.major, versionInfo.middle, versionInfo.minor, versionInfo.major, versionInfo.middle,
variety_to_text(versionInfo.variety), versionInfo.internal); versionInfo.minor,
variety_to_text(versionInfo.variety),
versionInfo.internal);
fVersionView->SetText(version); fVersionView->SetText(version);
fDescriptionView->SetText(versionInfo.long_info); fDescriptionView->SetText(versionInfo.long_info);
} else { } else {
@@ -481,7 +458,7 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate)
fNameView->SetEnabled(enabled); fNameView->SetEnabled(enabled);
fSignatureView->SetEnabled(enabled); fSignatureView->SetEnabled(enabled);
fPathView->SetEnabled(enabled); fPathView->SetEnabled(enabled);
fVersionView->SetEnabled(enabled); fVersionView->SetEnabled(enabled);
fDescriptionLabel->SetEnabled(enabled); fDescriptionLabel->SetEnabled(enabled);
@@ -491,14 +468,6 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate)
} }
void
ApplicationTypesWindow::FrameResized(float width, float height)
{
// This works around a flaw of BTextView
fDescriptionView->SetTextRect(fDescriptionView->Bounds());
}
void void
ApplicationTypesWindow::MessageReceived(BMessage* message) ApplicationTypesWindow::MessageReceived(BMessage* message)
{ {
@@ -537,10 +506,8 @@ ApplicationTypesWindow::MessageReceived(BMessage* message)
} }
case kMsgEdit: case kMsgEdit:
{
fTypeListView->Invoke(); fTypeListView->Invoke();
break; break;
}
case kMsgRemoveUninstalled: case kMsgRemoveUninstalled:
_RemoveUninstalled(); _RemoveUninstalled();
@@ -551,8 +518,9 @@ ApplicationTypesWindow::MessageReceived(BMessage* message)
const char* type; const char* type;
int32 which; int32 which;
if (message->FindString("be:type", &type) != B_OK if (message->FindString("be:type", &type) != B_OK
|| message->FindInt32("be:which", &which) != B_OK) || message->FindInt32("be:which", &which) != B_OK) {
break; break;
}
if (fCurrentType.Type() == NULL) if (fCurrentType.Type() == NULL)
break; break;
@@ -27,7 +27,6 @@ class ApplicationTypesWindow : public BWindow {
ApplicationTypesWindow(const BMessage& settings); ApplicationTypesWindow(const BMessage& settings);
virtual ~ApplicationTypesWindow(); virtual ~ApplicationTypesWindow();
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested(); virtual bool QuitRequested();
@@ -71,7 +71,7 @@ name_for_type(BString& string, type_code type, const char* displayAs)
buffer[4] = 0xff & (type); buffer[4] = 0xff & (type);
buffer[5] = '\''; buffer[5] = '\'';
buffer[6] = 0; buffer[6] = 0;
for (int16 i = 0;i < 4;i++) { for (int16 i = 0; i < 4; i++) {
if (buffer[i] < ' ') if (buffer[i] < ' ')
buffer[i] = '.'; buffer[i] = '.';
} }
@@ -81,7 +81,7 @@ name_for_type(BString& string, type_code type, const char* displayAs)
} }
AttributeItem * AttributeItem*
create_attribute_item(BMessage& attributes, int32 index) create_attribute_item(BMessage& attributes, int32 index)
{ {
const char* publicName; const char* publicName;
@@ -235,9 +235,8 @@ AttributeItem::operator!=(const AttributeItem& other) const
// #pragma mark - // #pragma mark -
AttributeListView::AttributeListView(BRect frame, const char* name, AttributeListView::AttributeListView(const char* name)
uint32 resizingMode) : BListView(name, B_SINGLE_SELECTION_LIST,
: BListView(frame, name, B_SINGLE_SELECTION_LIST, resizingMode,
B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS)
{ {
} }
@@ -50,7 +50,7 @@ class AttributeItem : public BStringItem {
class AttributeListView : public BListView { class AttributeListView : public BListView {
public: public:
AttributeListView(BRect frame, const char* name, uint32 resizingMode); AttributeListView(const char* name);
virtual ~AttributeListView(); virtual ~AttributeListView();
void SetTo(BMimeType* type); void SetTo(BMimeType* type);
@@ -76,6 +76,6 @@ struct display_as_map {
extern const struct display_as_map kDisplayAsMap[]; extern const struct display_as_map kDisplayAsMap[];
AttributeItem *create_attribute_item(BMessage& attributes, int32 index); AttributeItem* create_attribute_item(BMessage& attributes, int32 index);
#endif // ATTRIBUTE_LIST_VIEW_H #endif // ATTRIBUTE_LIST_VIEW_H
+81 -101
View File
@@ -13,10 +13,14 @@
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Locale.h> #include <Locale.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <SpaceLayoutItem.h>
#include <String.h> #include <String.h>
#include <TextControl.h> #include <TextControl.h>
@@ -91,40 +95,30 @@ display_as_parameter(const char* special)
AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
AttributeItem* attributeItem) AttributeItem* attributeItem)
: BWindow(BRect(100, 100, 350, 200), TR("Attribute"), B_MODAL_WINDOW_LOOK, :
B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE BWindow(BRect(100, 100, 350, 200), TR("Attribute"), B_MODAL_WINDOW_LOOK,
B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS
| B_ASYNCHRONOUS_CONTROLS), | B_ASYNCHRONOUS_CONTROLS),
fTarget(target), fTarget(target),
fMimeType(mimeType.Type()) fMimeType(mimeType.Type())
{ {
float padding = 3.0f;
//if (be_control_look)
//padding = be_control_look->DefaultItemSpacing();
if (attributeItem != NULL) if (attributeItem != NULL)
fAttribute = *attributeItem; fAttribute = *attributeItem;
BRect rect = Bounds(); fPublicNameControl = new BTextControl(TR("Attribute name:"),
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); fAttribute.PublicName(), NULL);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fPublicNameControl->SetModificationMessage(
AddChild(topView); new BMessage(kMsgAttributeUpdated));
rect.InsetBy(8.0f, 8.0f);
fPublicNameControl = new BTextControl(rect, "public", TR("Attribute name:"),
fAttribute.PublicName(), NULL, B_FOLLOW_LEFT_RIGHT);
fPublicNameControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated));
float labelWidth = fPublicNameControl->StringWidth(fPublicNameControl->Label()) + 2.0f;
fPublicNameControl->SetDivider(labelWidth);
fPublicNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fPublicNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
float width, height; fAttributeControl = new BTextControl(TR("Internal name:"),
fPublicNameControl->GetPreferredSize(&width, &height); fAttribute.Name(), NULL);
fPublicNameControl->ResizeTo(rect.Width(), height); fAttributeControl->SetModificationMessage(
topView->AddChild(fPublicNameControl); new BMessage(kMsgAttributeUpdated));
rect = fPublicNameControl->Frame();
rect.OffsetBy(0.0f, rect.Height() + 5.0f);
fAttributeControl = new BTextControl(rect, "internal", TR("Internal name:"),
fAttribute.Name(), NULL, B_FOLLOW_LEFT_RIGHT);
fAttributeControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated));
fAttributeControl->SetDivider(labelWidth);
fAttributeControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fAttributeControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
// filter out invalid characters that can't be part of an attribute // filter out invalid characters that can't be part of an attribute
@@ -134,8 +128,6 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
textView->DisallowChar(disallowedCharacters[i]); textView->DisallowChar(disallowedCharacters[i]);
} }
topView->AddChild(fAttributeControl);
fTypeMenu = new BPopUpMenu("type"); fTypeMenu = new BPopUpMenu("type");
BMenuItem* item = NULL; BMenuItem* item = NULL;
for (int32 i = 0; kTypeMap[i].name != NULL; i++) { for (int32 i = 0; kTypeMap[i].name != NULL; i++) {
@@ -149,27 +141,13 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
item->SetMarked(true); item->SetMarked(true);
} }
rect.OffsetBy(0.0f, rect.Height() + 4.0f); BMenuField* typeMenuField = new BMenuField("types" , TR("Type:"),
BMenuField* menuField = new BMenuField(rect, "types", fTypeMenu);
TR("Type:"), fTypeMenu); typeMenuField->SetAlignment(B_ALIGN_RIGHT);
menuField->SetDivider(labelWidth);
menuField->SetAlignment(B_ALIGN_RIGHT);
menuField->GetPreferredSize(&width, &height);
menuField->ResizeTo(rect.Width(), height);
topView->AddChild(menuField);
rect.OffsetBy(0.0f, rect.Height() + 4.0f); fVisibleCheckBox = new BCheckBox("visible", TR("Visible"),
rect.bottom = rect.top + fAttributeControl->Bounds().Height() * 2.0f + 18.0f;
BBox* box = new BBox(rect, "", B_FOLLOW_LEFT_RIGHT);
topView->AddChild(box);
fVisibleCheckBox = new BCheckBox(rect, "visible", TR("Visible"),
new BMessage(kMsgVisibilityChanged)); new BMessage(kMsgVisibilityChanged));
fVisibleCheckBox->SetValue(fAttribute.Visible()); fVisibleCheckBox->SetValue(fAttribute.Visible());
fVisibleCheckBox->ResizeToPreferred();
box->SetLabel(fVisibleCheckBox);
labelWidth -= 8.0f;
BMenu* menu = new BPopUpMenu("display as"); BMenu* menu = new BPopUpMenu("display as");
for (int32 i = 0; kDisplayAsMap[i].name != NULL; i++) { for (int32 i = 0; kDisplayAsMap[i].name != NULL; i++) {
@@ -188,42 +166,29 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
item->SetMarked(true); item->SetMarked(true);
} }
rect.OffsetTo(8.0f, fVisibleCheckBox->Bounds().Height()); fDisplayAsMenuField = new BMenuField("display as",
rect.right -= 18.0f; TR_CMT("Display as:", "Tracker offers different display modes for "
fDisplayAsMenuField = new BMenuField(rect, "display as", "attributes."), menu);
TR("Display as:"), menu);
fDisplayAsMenuField->SetDivider(labelWidth);
fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT); fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT);
fDisplayAsMenuField->ResizeTo(rect.Width(), height);
box->AddChild(fDisplayAsMenuField);
fEditableCheckBox = new BCheckBox(rect, "editable", TR("Editable"), fEditableCheckBox = new BCheckBox("editable", TR_CMT("Editable",
new BMessage(kMsgAttributeUpdated), B_FOLLOW_RIGHT); "If Tracker allows to edit this attribute."),
new BMessage(kMsgAttributeUpdated));
fEditableCheckBox->SetValue(fAttribute.Editable()); fEditableCheckBox->SetValue(fAttribute.Editable());
fEditableCheckBox->ResizeToPreferred();
fEditableCheckBox->MoveTo(rect.right - fEditableCheckBox->Bounds().Width(),
rect.top + (fDisplayAsMenuField->Bounds().Height()
- fEditableCheckBox->Bounds().Height()) / 2.0f);
box->AddChild(fEditableCheckBox);
rect.OffsetBy(0.0f, menuField->Bounds().Height() + 4.0f); fSpecialControl = new BTextControl(TR("Special:"),
rect.bottom = rect.top + fPublicNameControl->Bounds().Height(); display_as_parameter(fAttribute.DisplayAs()), NULL);
fSpecialControl = new BTextControl(rect, "special", TR("Special:"), fSpecialControl->SetModificationMessage(
display_as_parameter(fAttribute.DisplayAs()), NULL, new BMessage(kMsgAttributeUpdated));
B_FOLLOW_LEFT_RIGHT);
fSpecialControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated));
fSpecialControl->SetDivider(labelWidth);
fSpecialControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fSpecialControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fSpecialControl->SetEnabled(false); fSpecialControl->SetEnabled(false);
box->AddChild(fSpecialControl);
char text[64]; char text[64];
snprintf(text, sizeof(text), "%ld", fAttribute.Width()); snprintf(text, sizeof(text), "%ld", fAttribute.Width());
rect.OffsetBy(0.0f, fSpecialControl->Bounds().Height() + 4.0f); fWidthControl = new BTextControl(TR_CMT("Width:",
fWidthControl = new BTextControl(rect, "width", TR("Width:"), "Default column width in Tracker for this attribute."), text, NULL);
text, NULL, B_FOLLOW_LEFT_RIGHT); fWidthControl->SetModificationMessage(
fWidthControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); new BMessage(kMsgAttributeUpdated));
fWidthControl->SetDivider(labelWidth);
fWidthControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fWidthControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
// filter out invalid characters that can't be part of a width // filter out invalid characters that can't be part of a width
@@ -234,15 +199,16 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
} }
textView->SetMaxBytes(4); textView->SetMaxBytes(4);
box->AddChild(fWidthControl);
const struct alignment_map { const struct alignment_map {
int32 alignment; int32 alignment;
const char* name; const char* name;
} kAlignmentMap[] = { } kAlignmentMap[] = {
{B_ALIGN_LEFT, TR("Left")}, {B_ALIGN_LEFT, TR_CMT("Left", "Attribute column alignment in "
{B_ALIGN_RIGHT, TR("Right")}, "Tracker")},
{B_ALIGN_CENTER, TR("Center")}, {B_ALIGN_RIGHT, TR_CMT("Right", "Attribute column alignment in "
"Tracker")},
{B_ALIGN_CENTER, TR_CMT("Center", "Attribute column alignment in "
"Tracker")},
{0, NULL} {0, NULL}
}; };
@@ -258,36 +224,50 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType,
item->SetMarked(true); item->SetMarked(true);
} }
rect.OffsetBy(0.0f, menuField->Bounds().Height() + 1.0f); fAlignmentMenuField = new BMenuField("alignment",
fAlignmentMenuField = new BMenuField(rect, "alignment",
TR("Alignment:"), menu); TR("Alignment:"), menu);
fAlignmentMenuField->SetDivider(labelWidth);
fAlignmentMenuField->SetAlignment(B_ALIGN_RIGHT); fAlignmentMenuField->SetAlignment(B_ALIGN_RIGHT);
fAlignmentMenuField->ResizeTo(rect.Width(), height);
box->AddChild(fAlignmentMenuField);
box->ResizeBy(0.0f, fAlignmentMenuField->Bounds().Height() * 2.0f
+ fVisibleCheckBox->Bounds().Height());
fAcceptButton = new BButton(rect, "add", item ? TR("Done") : TR("Add"), fAcceptButton = new BButton("add", item ? TR("Done") : TR("Add"),
new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(kMsgAccept));
fAcceptButton->ResizeToPreferred();
fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(),
Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height());
fAcceptButton->SetEnabled(false); fAcceptButton->SetEnabled(false);
topView->AddChild(fAcceptButton);
BButton* button = new BButton(rect, "cancel", TR("Cancel"), BButton* cancelButton = new BButton("cancel", TR("Cancel"),
new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(B_QUIT_REQUESTED));
button->ResizeToPreferred();
button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(),
fAcceptButton->Frame().top);
topView->AddChild(button);
ResizeTo(labelWidth * 4.0f + 24.0f, box->Frame().bottom BBox* visibleBox;
+ button->Bounds().Height() + 20.0f); SetLayout(new BGroupLayout(B_VERTICAL));
SetSizeLimits(fEditableCheckBox->Bounds().Width() + button->Bounds().Width() AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
+ fAcceptButton->Bounds().Width() + labelWidth + 24.0f, .SetInsets(padding, padding, padding, padding)
32767.0f, Frame().Height(), Frame().Height()); .Add(BGridLayoutBuilder(padding, padding)
.Add(fPublicNameControl->CreateLabelLayoutItem(), 0, 0)
.Add(fPublicNameControl->CreateTextViewLayoutItem(), 1, 0)
.Add(fAttributeControl->CreateLabelLayoutItem(), 0, 1)
.Add(fAttributeControl->CreateTextViewLayoutItem(), 1, 1)
.Add(typeMenuField->CreateLabelLayoutItem(), 0, 2)
.Add(typeMenuField->CreateMenuBarLayoutItem(), 1, 2)
)
.Add(visibleBox = new BBox(B_FANCY_BORDER,
BGridLayoutBuilder(padding, padding)
.Add(fDisplayAsMenuField->CreateLabelLayoutItem(), 0, 0)
.Add(fDisplayAsMenuField->CreateMenuBarLayoutItem(), 1, 0)
.Add(fEditableCheckBox, 3, 0)
.Add(fSpecialControl->CreateLabelLayoutItem(), 0, 1)
.Add(fSpecialControl->CreateTextViewLayoutItem(), 1, 1, 3)
.Add(fWidthControl->CreateLabelLayoutItem(), 0, 2)
.Add(fWidthControl->CreateTextViewLayoutItem(), 1, 2, 3)
.Add(fAlignmentMenuField->CreateLabelLayoutItem(), 0, 3)
.Add(fAlignmentMenuField->CreateMenuBarLayoutItem(), 1, 3, 3)
.SetInsets(padding, padding, padding, padding)
))
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(BSpaceLayoutItem::CreateGlue())
.Add(BSpaceLayoutItem::CreateGlue())
.Add(cancelButton)
.Add(fAcceptButton)
)
);
visibleBox->SetLabel(fVisibleCheckBox);
fAcceptButton->MakeDefault(true); fAcceptButton->MakeDefault(true);
fPublicNameControl->MakeFocus(true); fPublicNameControl->MakeFocus(true);
@@ -7,9 +7,9 @@
#include "DropTargetListView.h" #include "DropTargetListView.h"
DropTargetListView::DropTargetListView(BRect frame, const char* name, DropTargetListView::DropTargetListView(const char* name,
list_view_type type, uint32 resizeMask, uint32 flags) list_view_type type, uint32 flags)
: BListView(frame, name, type, resizeMask, flags), : BListView(name, type, flags),
fDropTarget(false) fDropTarget(false)
{ {
} }
@@ -11,9 +11,8 @@
class DropTargetListView : public BListView { class DropTargetListView : public BListView {
public: public:
DropTargetListView(BRect frame, const char* name, DropTargetListView(const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST, list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~DropTargetListView(); virtual ~DropTargetListView();
+26 -35
View File
@@ -10,6 +10,9 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <Locale.h> #include <Locale.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -110,25 +113,23 @@ replace_extension(BMimeType& type, const char* newExtension,
ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type, ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type,
const char* extension) const char* extension)
: BWindow(BRect(100, 100, 350, 200), TR("Extension"), B_MODAL_WINDOW_LOOK, : BWindow(BRect(100, 100, 350, 200), TR("Extension"), B_MODAL_WINDOW_LOOK,
B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE
| B_ASYNCHRONOUS_CONTROLS), | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fTarget(target), fTarget(target),
fMimeType(type.Type()), fMimeType(type.Type()),
fExtension(extension) fExtension(extension)
{ {
BRect rect = Bounds(); SetLayout(new BGroupLayout(B_VERTICAL));
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
rect.InsetBy(8.0f, 8.0f); float padding = 3.0f;
fExtensionControl = new BTextControl(rect, "extension", TR("Extension:"), extension, //if (be_control_look)
NULL, B_FOLLOW_LEFT_RIGHT); // padding = be_control_look->DefaultItemSpacing();
// this seems to be very large!
float labelWidth = fExtensionControl->StringWidth(fExtensionControl->Label()) + 2.0f;
fExtensionControl->SetModificationMessage(new BMessage(kMsgExtensionUpdated)); fExtensionControl = new BTextControl(TR("Extension:"), extension, NULL);
fExtensionControl->SetDivider(labelWidth); fExtensionControl->SetModificationMessage(
fExtensionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); new BMessage(kMsgExtensionUpdated));
fExtensionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
// filter out invalid characters that can't be part of an extension // filter out invalid characters that can't be part of an extension
BTextView* textView = fExtensionControl->TextView(); BTextView* textView = fExtensionControl->TextView();
@@ -137,30 +138,20 @@ ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type,
textView->DisallowChar(disallowedCharacters[i]); textView->DisallowChar(disallowedCharacters[i]);
} }
float width, height; fAcceptButton = new BButton(extension ? TR("Done") : TR("Add"),
fExtensionControl->GetPreferredSize(&width, &height); new BMessage(kMsgAccept));
fExtensionControl->ResizeTo(rect.Width(), height);
topView->AddChild(fExtensionControl);
fAcceptButton = new BButton(rect, "add", extension ? TR("Done") : TR("Add"),
new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
fAcceptButton->ResizeToPreferred();
fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(),
Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height());
fAcceptButton->SetEnabled(false); fAcceptButton->SetEnabled(false);
topView->AddChild(fAcceptButton);
BButton* button = new BButton(rect, "cancel", TR("Cancel"), BButton* button = new BButton(TR("Cancel"),
new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(B_QUIT_REQUESTED));
button->ResizeToPreferred();
button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(),
fAcceptButton->Frame().top);
topView->AddChild(button);
ResizeTo(labelWidth * 4.0f + 24.0f, fExtensionControl->Bounds().Height() AddChild(BGridLayoutBuilder(padding, padding)
+ fAcceptButton->Bounds().Height() + 28.0f); .Add(fExtensionControl->CreateLabelLayoutItem(), 0, 0)
SetSizeLimits(button->Bounds().Width() + fAcceptButton->Bounds().Width() + 26.0f, .Add(fExtensionControl->CreateTextViewLayoutItem(), 1, 0)
32767.0f, Frame().Height(), Frame().Height()); .Add(fAcceptButton, 0, 1)
.Add(button, 1, 1)
.SetInsets(padding, padding, padding, padding)
);
// omit the leading dot // omit the leading dot
if (fExtension.ByteAt(0) == '.') if (fExtension.ByteAt(0) == '.')
+68 -108
View File
@@ -15,13 +15,17 @@
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <File.h> #include <File.h>
#include <Locale.h> #include <Locale.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <SpaceLayoutItem.h>
#include <TextControl.h> #include <TextControl.h>
#include <stdio.h> #include <stdio.h>
@@ -45,35 +49,23 @@ const uint32 kMsgSamePreferredAppAsOpened = 'spaO';
FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs)
: BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position), :
BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position),
TR("File type"), B_TITLED_WINDOW, TR("File type"), B_TITLED_WINDOW,
B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE |
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
BRect rect = Bounds(); float padding = 3.0f;
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); // if (be_control_look)
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // padding = be_control_look->DefaultItemSpacing();
AddChild(topView); // too big!
// "File Type" group // "File Type" group
BBox* fileTypeBox = new BBox("file type BBox");
fileTypeBox->SetLabel(TR("File type"));
BFont font(be_bold_font); fTypeControl = new BTextControl("type", NULL, "Type Control",
font_height fontHeight; new BMessage(kMsgTypeEntered));
font.GetHeight(&fontHeight);
rect.InsetBy(8.0f, 8.0f);
BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
box->SetLabel(TR("File type"));
topView->AddChild(box);
rect = box->Bounds();
rect.InsetBy(8.0f, 4.0f + fontHeight.ascent + fontHeight.descent);
fTypeControl = new BTextControl(rect, "type", NULL, NULL,
new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT);
fTypeControl->SetDivider(0.0f);
float width, height;
fTypeControl->GetPreferredSize(&width, &height);
fTypeControl->ResizeTo(rect.Width(), height);
box->AddChild(fTypeControl);
// filter out invalid characters that can't be part of a MIME type name // filter out invalid characters that can't be part of a MIME type name
BTextView* textView = fTypeControl->TextView(); BTextView* textView = fTypeControl->TextView();
@@ -82,55 +74,32 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs)
textView->DisallowChar(disallowedCharacters[i]); textView->DisallowChar(disallowedCharacters[i]);
} }
rect.OffsetBy(0.0f, fTypeControl->Bounds().Height() + 5.0f); fSelectTypeButton = new BButton("select type",
fSelectTypeButton = new BButton(rect, "select type", TR("Select" B_UTF8_ELLIPSIS), new BMessage(kMsgSelectType));
TR("Select" B_UTF8_ELLIPSIS),
new BMessage(kMsgSelectType), B_FOLLOW_LEFT | B_FOLLOW_TOP);
fSelectTypeButton->ResizeToPreferred();
box->AddChild(fSelectTypeButton);
rect.OffsetBy(fSelectTypeButton->Bounds().Width() + 8.0f, 0.0f); fSameTypeAsButton = new BButton("same type as",
fSameTypeAsButton = new BButton(rect, "same type as", TR("Same as" B_UTF8_ELLIPSIS), new BMessage(kMsgSameTypeAs));
TR("Same as" B_UTF8_ELLIPSIS),
new BMessage(kMsgSameTypeAs), B_FOLLOW_LEFT | B_FOLLOW_TOP);
fSameTypeAsButton->ResizeToPreferred();
box->AddChild(fSameTypeAsButton);
width = font.StringWidth("Icon") + 16.0f; fileTypeBox->AddChild(BGridLayoutBuilder(padding, padding)
if (width < B_LARGE_ICON + 16.0f) .Add(fTypeControl, 0, 0, 2, 1)
width = B_LARGE_ICON + 16.0f; .Add(fSelectTypeButton, 0, 1)
.Add(fSameTypeAsButton, 1, 1)
height = fSelectTypeButton->Frame().bottom + 8.0f; .SetInsets(padding, padding, padding, padding)
if (height < 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent) );
height = 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent;
box->ResizeTo(box->Bounds().Width() - width - 8.0f, height);
// "Icon" group // "Icon" group
rect = box->Frame(); BBox* iconBox = new BBox("icon BBox");
rect.left = rect.right + 8.0f; iconBox->SetLabel(TR("Icon"));
rect.right += width + 8.0f; fIconView = new IconView("icon");
float iconBoxWidth = rect.Width(); iconBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP); .Add(fIconView)
box->SetLabel("Icon"); .SetInsets(padding, padding, padding, padding));
topView->AddChild(box);
rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f);
rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f);
if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f)
rect.top = fontHeight.ascent + fontHeight.descent + 4.0f;
fIconView = new IconView(rect, "icon");
box->AddChild(fIconView);
// "Preferred Application" group // "Preferred Application" group
rect.top = box->Frame().bottom + 8.0f; BBox* preferredBox = new BBox("preferred BBox");
rect.bottom = rect.top + box->Bounds().Height(); preferredBox->SetLabel(TR("Preferred application"));
rect.left = 8.0f;
rect.right = Bounds().Width() - 8.0f;
box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
box->SetLabel(TR("Preferred application"));
topView->AddChild(box);
BMenu* menu = new BPopUpMenu("preferred"); BMenu* menu = new BPopUpMenu("preferred");
BMenuItem* item; BMenuItem* item;
@@ -138,43 +107,31 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs)
new BMessage(kMsgPreferredAppChosen))); new BMessage(kMsgPreferredAppChosen)));
item->SetMarked(true); item->SetMarked(true);
rect = fTypeControl->Frame(); fPreferredField = new BMenuField("preferred", NULL, menu);
BView* constrainingView = new BView(rect, NULL, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW);
constrainingView->SetViewColor(topView->ViewColor());
fPreferredField = new BMenuField(rect.OffsetToCopy(B_ORIGIN), "preferred", fSelectAppButton = new BButton("select app", TR("Select" B_UTF8_ELLIPSIS),
NULL, menu); new BMessage(kMsgSelectPreferredApp));
fPreferredField->GetPreferredSize(&width, &height);
fPreferredField->ResizeTo(rect.Width(), height);
constrainingView->ResizeTo(rect.Width(), height);
constrainingView->AddChild(fPreferredField);
// we embed the menu field in another view to make it behave like
// we want so that it can't obscure other elements with larger
// labels
box->AddChild(constrainingView); fSameAppAsButton = new BButton("same app as", TR("Same as" B_UTF8_ELLIPSIS),
new BMessage(kMsgSamePreferredAppAs));
rect.OffsetBy(0.0f, height + 5.0f); preferredBox->AddChild(BGridLayoutBuilder(padding, padding)
fSelectAppButton = new BButton(rect, "select app", .Add(fPreferredField, 0, 0, 2, 1)
TR("Select" B_UTF8_ELLIPSIS), .Add(fSelectAppButton, 0, 1)
new BMessage(kMsgSelectPreferredApp), B_FOLLOW_LEFT | B_FOLLOW_TOP); .Add(fSameAppAsButton, 1, 1)
fSelectAppButton->ResizeToPreferred(); .Add(BSpaceLayoutItem::CreateGlue(), 3, 0, 1, 2)
box->AddChild(fSelectAppButton); .SetInsets(padding, padding, padding, padding)
);
rect.OffsetBy(fSelectAppButton->Bounds().Width() + 8.0f, 0.0f); SetLayout(new BGroupLayout(B_VERTICAL));
fSameAppAsButton = new BButton(rect, "same app as", AddChild(BGridLayoutBuilder(padding, padding)
TR("Same as" B_UTF8_ELLIPSIS), .Add(fileTypeBox, 0, 0, 1, 2)
new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_LEFT | B_FOLLOW_TOP); .Add(iconBox, 1, 1, 1, 2)
fSameAppAsButton->ResizeToPreferred(); .Add(preferredBox, 0, 2, 1, 2)
box->AddChild(fSameAppAsButton); .SetInsets(padding, padding, padding, padding)
box->ResizeBy(0.0f, height - fTypeControl->Bounds().Height()); );
ResizeTo(fSameAppAsButton->Frame().right + 100.0f, box->Frame().bottom + 8.0f);
SetSizeLimits(fSameAppAsButton->Frame().right + iconBoxWidth + 32.0f, 32767.0f,
Bounds().Height(), Bounds().Height());
fTypeControl->MakeFocus(true); fTypeControl->MakeFocus(true);
BMimeType::StartWatching(this); BMimeType::StartWatching(this);
_SetTo(refs); _SetTo(refs);
} }
@@ -190,6 +147,7 @@ BString
FileTypeWindow::_Title(const BMessage& refs) FileTypeWindow::_Title(const BMessage& refs)
{ {
BString title; BString title;
entry_ref ref; entry_ref ref;
if (refs.FindRef("refs", 1, &ref) == B_OK) { if (refs.FindRef("refs", 1, &ref) == B_OK) {
bool same = false; bool same = false;
@@ -213,15 +171,18 @@ FileTypeWindow::_Title(const BMessage& refs)
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
if (same && parent.GetName(name) == B_OK) { if (same && parent.GetName(name) == B_OK) {
title = TR("Multiple files from \""); char buffer[512];
title.Append(name); snprintf(buffer, sizeof(buffer),
title.Append("\""); TR("Multiple files from \"%s\" file type"), name);
title = buffer;
} else } else
title = TR("[Multiple files]"); title = TR("[Multiple files] file types");
} else if (refs.FindRef("refs", 0, &ref) == B_OK) } else if (refs.FindRef("refs", 0, &ref) == B_OK) {
title = ref.name; char buffer[512];
snprintf(buffer, sizeof(buffer), TR("%s file type"), ref.name);
title = buffer;
}
title.Append(" file type");
return title; return title;
} }
@@ -443,7 +404,8 @@ FileTypeWindow::MessageReceived(BMessage* message)
case kMsgSamePreferredAppAs: case kMsgSamePreferredAppAs:
{ {
BMessage panel(kMsgOpenFilePanel); BMessage panel(kMsgOpenFilePanel);
panel.AddString("title", TR("Select same preferred application as")); panel.AddString("title",
TR("Select same preferred application as"));
panel.AddInt32("message", kMsgSamePreferredAppAsOpened); panel.AddInt32("message", kMsgSamePreferredAppAsOpened);
panel.AddMessenger("target", this); panel.AddMessenger("target", this);
@@ -478,11 +440,9 @@ FileTypeWindow::MessageReceived(BMessage* message)
break; break;
if (which == B_MIME_TYPE_DELETED if (which == B_MIME_TYPE_DELETED
#ifdef __HAIKU__ || which == B_SUPPORTED_TYPES_CHANGED) {
|| which == B_SUPPORTED_TYPES_CHANGED
#endif
)
_UpdatePreferredApps(); _UpdatePreferredApps();
}
break; break;
default: default:
+21 -16
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright 2006-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Copyright 2006-2007, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@@ -76,8 +76,8 @@ class FileTypes : public BApplication {
BWindow *fApplicationTypesWindow; BWindow *fApplicationTypesWindow;
uint32 fWindowCount; uint32 fWindowCount;
uint32 fTypeWindowCount; uint32 fTypeWindowCount;
BCatalog fCatalog; BCatalog fCatalog;
}; };
@@ -221,7 +221,7 @@ FileTypes::RefsReceived(BMessage *message)
ref.name, strerror(status)); ref.name, strerror(status));
(new BAlert(TR("FileTypes request"), (new BAlert(TR("FileTypes request"),
buffer, "Ok", NULL, NULL, buffer, TR("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
message->RemoveData("refs", --index); message->RemoveData("refs", --index);
@@ -287,7 +287,7 @@ FileTypes::ArgvReceived(int32 argc, char **argv)
if ((status = entry.SetTo(path.Path(), false)) != B_OK if ((status = entry.SetTo(path.Path(), false)) != B_OK
|| (status = entry.GetRef(&ref)) != B_OK) { || (status = entry.GetRef(&ref)) != B_OK) {
fprintf(stderr, TR("Could not open file \"%s\": %s\n"), fprintf(stderr, "Could not open file \"%s\": %s\n",
path.Path(), strerror(status)); path.Path(), strerror(status));
continue; continue;
} }
@@ -356,7 +356,7 @@ FileTypes::MessageReceived(BMessage *message)
// the open file panel sends us a message when it's done // the open file panel sends us a message when it's done
const char* subTitle; const char* subTitle;
if (message->FindString("title", &subTitle) != B_OK) if (message->FindString("title", &subTitle) != B_OK)
subTitle = TR("Open File"); subTitle = TR("Open file");
int32 what; int32 what;
if (message->FindInt32("message", &what) != B_OK) if (message->FindInt32("message", &what) != B_OK)
@@ -366,7 +366,7 @@ FileTypes::MessageReceived(BMessage *message)
if (message->FindMessenger("target", &target) != B_OK) if (message->FindMessenger("target", &target) != B_OK)
target = be_app_messenger; target = be_app_messenger;
BString title = "FileTypes"; BString title = TR("FileTypes");
if (subTitle != NULL && subTitle[0]) { if (subTitle != NULL && subTitle[0]) {
title.Append(": "); title.Append(": ");
title.Append(subTitle); title.Append(subTitle);
@@ -407,9 +407,12 @@ FileTypes::MessageReceived(BMessage *message)
void void
FileTypes::AboutRequested() FileTypes::AboutRequested()
{ {
BAlert *alert = new BAlert("about", TR("FileTypes\n" BString aboutText(TR("FileTypes"));
"\twritten by Axel Dörfler\n" int32 titleLength = aboutText.Length();
"\tCopyright 2006-2007, Haiku.\n"), TR("Ok")); aboutText << "\n";
aboutText << TR("\twritten by Axel Dörfler\n"
"\tCopyright 2006-2007, Haiku.\n");
BAlert *alert = new BAlert("about", aboutText.String(), TR("OK"));
BTextView *view = alert->TextView(); BTextView *view = alert->TextView();
BFont font; BFont font;
@@ -418,7 +421,7 @@ FileTypes::AboutRequested()
view->GetFont(&font); view->GetFont(&font);
font.SetSize(18); font.SetSize(18);
font.SetFace(B_BOLD_FACE); font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 9, &font); view->SetFontAndColor(0, titleLength, &font);
alert->Go(); alert->Go();
} }
@@ -454,12 +457,14 @@ void
error_alert(const char* message, status_t status, alert_type type) error_alert(const char* message, status_t status, alert_type type)
{ {
char warning[512]; char warning[512];
if (status != B_OK) if (status != B_OK) {
snprintf(warning, sizeof(warning), "%s:\n\t%s\n", message, strerror(status)); snprintf(warning, sizeof(warning), "%s:\n\t%s\n", message,
strerror(status));
}
(new BAlert(TR("FileTypes Request"), (new BAlert(TR("FileTypes request"),
status == B_OK ? message : warning, status == B_OK ? message : warning,
"Ok", NULL, NULL, B_WIDTH_AS_USUAL, type))->Go(); TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, type))->Go();
} }
+205 -266
View File
@@ -16,12 +16,16 @@
#include "PreferredAppMenu.h" #include "PreferredAppMenu.h"
#include "StringView.h" #include "StringView.h"
#include <Alignment.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Application.h> #include <Application.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <ListView.h> #include <ListView.h>
#include <Locale.h> #include <Locale.h>
#include <MenuBar.h> #include <MenuBar.h>
@@ -32,6 +36,8 @@
#include <OutlineListView.h> #include <OutlineListView.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <SpaceLayoutItem.h>
#include <SplitView.h>
#include <TextControl.h> #include <TextControl.h>
#include <OverrideAlert.h> #include <OverrideAlert.h>
@@ -42,7 +48,7 @@
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "FileType Window" #define TR_CONTEXT "FileTypes Window"
const uint32 kMsgTypeSelected = 'typs'; const uint32 kMsgTypeSelected = 'typs';
@@ -73,10 +79,10 @@ const uint32 kMsgDescriptionEntered = 'dsce';
const uint32 kMsgToggleIcons = 'tgic'; const uint32 kMsgToggleIcons = 'tgic';
const uint32 kMsgToggleRule = 'tgrl'; const uint32 kMsgToggleRule = 'tgrl';
class TypeIconView : public IconView { class TypeIconView : public IconView {
public: public:
TypeIconView(BRect frame, const char* name, TypeIconView(const char* name);
int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
virtual ~TypeIconView(); virtual ~TypeIconView();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
@@ -86,11 +92,11 @@ class TypeIconView : public IconView {
virtual BRect BitmapRect() const; virtual BRect BitmapRect() const;
}; };
class ExtensionListView : public DropTargetListView { class ExtensionListView : public DropTargetListView {
public: public:
ExtensionListView(BRect frame, const char* name, ExtensionListView(const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST, list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~ExtensionListView(); virtual ~ExtensionListView();
@@ -107,8 +113,8 @@ class ExtensionListView : public DropTargetListView {
// #pragma mark - // #pragma mark -
TypeIconView::TypeIconView(BRect frame, const char* name, int32 resizingMode) TypeIconView::TypeIconView(const char* name)
: IconView(frame, name, resizingMode) : IconView(name)
{ {
ShowEmptyFrame(false); ShowEmptyFrame(false);
} }
@@ -179,7 +185,8 @@ TypeIconView::GetPreferredSize(float* _width, float* _height)
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
*_height = IconSize() + 3.0f + ceilf(fontHeight.ascent + fontHeight.descent); *_height = IconSize() + 3.0f + ceilf(fontHeight.ascent
+ fontHeight.descent);
} }
} }
@@ -195,7 +202,8 @@ TypeIconView::BitmapRect() const
float width = StringWidth(TR("no icon")) + 8.0f; float width = StringWidth(TR("no icon")) + 8.0f;
float height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0f; float height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0f;
float x = (Bounds().Width() - width) / 2.0f; float x = (Bounds().Width() - width) / 2.0f;
float y = ceilf((IconSize() - fontHeight.ascent - fontHeight.descent) / 2.0f) - 3.0f; float y = ceilf((IconSize() - fontHeight.ascent - fontHeight.descent)
/ 2.0f) - 3.0f;
return BRect(x, y, x + width, y + height); return BRect(x, y, x + width, y + height);
} }
@@ -208,9 +216,9 @@ TypeIconView::BitmapRect() const
// #pragma mark - // #pragma mark -
ExtensionListView::ExtensionListView(BRect frame, const char* name, ExtensionListView::ExtensionListView(const char* name,
list_view_type type, uint32 resizeMask, uint32 flags) list_view_type type, uint32 flags)
: DropTargetListView(frame, name, type, resizeMask, flags) : DropTargetListView(name, type, flags)
{ {
} }
@@ -277,8 +285,9 @@ ExtensionListView::SetType(BMimeType* type)
FileTypesWindow::FileTypesWindow(const BMessage& settings) FileTypesWindow::FileTypesWindow(const BMessage& settings)
: BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW, :
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), BWindow(_Frame(settings), TR("FileTypes"), B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fNewTypeWindow(NULL) fNewTypeWindow(NULL)
{ {
bool showIcons; bool showIcons;
@@ -288,10 +297,19 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings)
if (settings.FindBool("show_rule", &showRule) != B_OK) if (settings.FindBool("show_rule", &showRule) != B_OK)
showRule = false; showRule = false;
// add the menu SetLayout(new BGroupLayout(B_VERTICAL));
float padding = 3.0f;
BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
if (be_control_look) {
// padding = be_control_look->DefaultItemSpacing();
// this seems to be very large!
labelAlignment = be_control_look->DefaultLabelAlignment();
}
BAlignment fullAlignment =
BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); // add the menu
AddChild(menuBar); BMenuBar* menuBar = new BMenuBar("");
BMenu* menu = new BMenu(TR("File")); BMenu* menu = new BMenu(TR("File"));
BMenuItem* item; BMenuItem* item;
@@ -300,11 +318,12 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings)
item->SetEnabled(false); item->SetEnabled(false);
BMenu* recentsMenu = BRecentFilesList::NewFileListMenu( BMenu* recentsMenu = BRecentFilesList::NewFileListMenu(
TR("Open" B_UTF8_ELLIPSIS), TR("Open" B_UTF8_ELLIPSIS), NULL, NULL, be_app, 10, false, NULL,
NULL, NULL, be_app, 10, false, NULL, kSignature); kSignature);
item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel)); item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel));
item->SetShortcut('O', B_COMMAND_KEY); item->SetShortcut('O', B_COMMAND_KEY);
menu->AddItem(item); menu->AddItem(item);
menu->AddItem(new BMenuItem(TR("Application types" B_UTF8_ELLIPSIS), menu->AddItem(new BMenuItem(TR("Application types" B_UTF8_ELLIPSIS),
new BMessage(kMsgOpenApplicationTypesWindow))); new BMessage(kMsgOpenApplicationTypesWindow)));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
@@ -319,264 +338,187 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings)
menuBar->AddItem(menu); menuBar->AddItem(menu);
menu = new BMenu(TR("Settings")); menu = new BMenu(TR("Settings"));
item = new BMenuItem(TR("Show icons in list"), new BMessage(kMsgToggleIcons)); item = new BMenuItem(TR("Show icons in list"),
new BMessage(kMsgToggleIcons));
item->SetMarked(showIcons); item->SetMarked(showIcons);
item->SetTarget(this); item->SetTarget(this);
menu->AddItem(item); menu->AddItem(item);
item = new BMenuItem(TR("Show recognition rule"), new BMessage(kMsgToggleRule)); item = new BMenuItem(TR("Show recognition rule"),
new BMessage(kMsgToggleRule));
item->SetMarked(showRule); item->SetMarked(showRule);
item->SetTarget(this); item->SetTarget(this);
menu->AddItem(item); menu->AddItem(item);
menuBar->AddItem(menu); menuBar->AddItem(menu);
AddChild(menuBar);
menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP));
// MIME Types list // MIME Types list
BButton* addTypeButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS),
new BMessage(kMsgAddType));
BRect rect = Bounds(); fRemoveTypeButton = new BButton("remove", TR("Remove"),
rect.top = menuBar->Bounds().Height() + 1.0f; new BMessage(kMsgRemoveType) );
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
BButton* button = new BButton(rect, "add", TR("Add" B_UTF8_ELLIPSIS), fTypeListView = new MimeTypeListView("typeview", NULL, showIcons, false);
new BMessage(kMsgAddType), B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height());
topView->AddChild(button);
rect = button->Frame();
rect.OffsetBy(rect.Width() + 8.0f, 0.0f);
fRemoveTypeButton = new BButton(rect, "remove", TR("Remove"),
new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM);
fRemoveTypeButton->ResizeToPreferred();
topView->AddChild(fRemoveTypeButton);
rect.bottom = rect.top - 10.0f;
rect.top = 10.0f;
rect.left = 10.0f;
rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f;
if (rect.right < 180)
rect.right = 180;
fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, BScrollView* typeListScrollView = new BScrollView("scrollview",
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
topView->AddChild(scrollView);
// "Icon" group // "Icon" group
font_height plainHeight; fIconView = new TypeIconView("icon");
be_plain_font->GetHeight(&plainHeight); fIconBox = new BBox("Icon BBox");
float height = ceilf(plainHeight.ascent + plainHeight.descent
+ plainHeight.leading) + 2.0f;
BFont font(be_bold_font);
float labelWidth = font.StringWidth(TR("Icon"));
font_height boldHeight;
font.GetHeight(&boldHeight);
BRect innerRect;
fIconView = new TypeIconView(innerRect, "icon",
B_FOLLOW_LEFT | B_FOLLOW_V_CENTER);
fIconView->ResizeToPreferred();
rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH;
rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f;
rect.bottom = rect.top + ceilf(boldHeight.ascent)
+ max_c(fIconView->Bounds().Height(),
button->Bounds().Height() * 2.0f + height + 4.0f) + 12.0f;
rect.top -= 2.0f;
fIconBox = new BBox(rect);
fIconBox->SetLabel(TR("Icon")); fIconBox->SetLabel(TR("Icon"));
topView->AddChild(fIconBox); fIconBox->AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(BSpaceLayoutItem::CreateGlue(), 1)
innerRect.left = 8.0f; .Add(fIconView, 3)
innerRect.top = plainHeight.ascent + 3.0f .Add(BSpaceLayoutItem::CreateGlue(), 1)
+ (rect.Height() - boldHeight.ascent - fIconView->Bounds().Height()) / 2.0f; .SetInsets(padding, padding, padding, padding)
if (innerRect.top + fIconView->Bounds().Height() > fIconBox->Bounds().Height() - 6.0f) );
innerRect.top = fIconBox->Bounds().Height() - 6.0f - fIconView->Bounds().Height();
fIconView->MoveTo(innerRect.LeftTop());
fIconBox->AddChild(fIconView);
// "File Recognition" group // "File Recognition" group
BRect rightRect(rect); fRecognitionBox = new BBox("Recognition Box");
rightRect.left = rect.right + 8.0f;
rightRect.right = topView->Bounds().Width() - 8.0f;
fRecognitionBox = new BBox(rightRect, NULL, B_FOLLOW_LEFT_RIGHT);
fRecognitionBox->SetLabel(TR("File recognition")); fRecognitionBox->SetLabel(TR("File recognition"));
topView->AddChild(fRecognitionBox); fRecognitionBox->SetExplicitAlignment(fullAlignment);
innerRect = fRecognitionBox->Bounds().InsetByCopy(8.0f, 4.0f); fExtensionLabel = new StringView(TR("Extensions:"), NULL);
innerRect.top += ceilf(boldHeight.ascent); fExtensionLabel->LabelView()->SetExplicitAlignment(labelAlignment);
fExtensionLabel = new StringView(innerRect, "extension", TR("Extensions:"), NULL);
fExtensionLabel->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
fExtensionLabel->ResizeToPreferred();
fRecognitionBox->AddChild(fExtensionLabel);
innerRect.top += fExtensionLabel->Bounds().Height() + 2.0f; fAddExtensionButton = new BButton("add ext", TR("Add" B_UTF8_ELLIPSIS),
innerRect.left = innerRect.right - button->StringWidth(TR("Remove")) - 16.0f; new BMessage(kMsgAddExtension));
innerRect.bottom = innerRect.top + button->Bounds().Height();
fAddExtensionButton = new BButton(innerRect, "add ext", TR("Add" B_UTF8_ELLIPSIS),
new BMessage(kMsgAddExtension), B_FOLLOW_RIGHT);
fRecognitionBox->AddChild(fAddExtensionButton);
innerRect.OffsetBy(0, innerRect.Height() + 4.0f); fRemoveExtensionButton = new BButton("remove ext", TR("Remove"),
fRemoveExtensionButton = new BButton(innerRect, "remove ext", TR("Remove"), new BMessage(kMsgRemoveExtension));
new BMessage(kMsgRemoveExtension), B_FOLLOW_RIGHT);
fRecognitionBox->AddChild(fRemoveExtensionButton);
innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; fExtensionListView = new ExtensionListView("listview ext",
innerRect.left = 10.0f; B_SINGLE_SELECTION_LIST);
innerRect.top = fAddExtensionButton->Frame().top + 2.0f; fExtensionListView->SetSelectionMessage(
innerRect.bottom = innerRect.bottom - 2.0f; new BMessage(kMsgExtensionSelected));
// take scrollview border into account fExtensionListView->SetInvocationMessage(
fExtensionListView = new ExtensionListView(innerRect, "listview ext", new BMessage(kMsgExtensionInvoked));
B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT);
fExtensionListView->SetSelectionMessage(new BMessage(kMsgExtensionSelected));
fExtensionListView->SetInvocationMessage(new BMessage(kMsgExtensionInvoked));
scrollView = new BScrollView("scrollview ext", fExtensionListView, BScrollView* scrollView = new BScrollView("scrollview ext",
B_FOLLOW_LEFT_RIGHT, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fExtensionListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
fRecognitionBox->AddChild(scrollView);
innerRect.left = 8.0f; fRuleControl = new BTextControl("rule", TR("Rule:"), "",
innerRect.top = innerRect.bottom + 10.0f; new BMessage(kMsgRuleEntered));
innerRect.right = fRecognitionBox->Bounds().right - 8.0f; fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
innerRect.bottom = innerRect.top + 20.0f;
fRuleControl = new BTextControl(innerRect, "rule", TR("Rule:"), "",
new BMessage(kMsgRuleEntered), B_FOLLOW_LEFT_RIGHT);
//fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fRuleControl->SetDivider(fRuleControl->StringWidth(fRuleControl->Label()) + 6.0f);
fRuleControl->Hide(); fRuleControl->Hide();
fRecognitionBox->AddChild(fRuleControl);
BView* recognitionBoxGrid =
BGridLayoutBuilder(padding, padding)
.Add(fExtensionLabel->LabelView(), 0, 0)
.Add(scrollView, 0, 1, 2, 3)
.Add(fAddExtensionButton, 2, 1)
.Add(fRemoveExtensionButton, 2, 2)
.Add(fRuleControl, 0, 4, 3, 1)
.SetInsets(padding, padding, padding, padding);
recognitionBoxGrid->SetExplicitAlignment(fullAlignment);
fRecognitionBox->AddChild(recognitionBoxGrid);
// "Description" group // "Description" group
rect.top = rect.bottom + 8.0f; fDescriptionBox = new BBox("description BBox");
rect.bottom = rect.top + ceilf(boldHeight.ascent) + 24.0f;
rect.right = rightRect.right;
fDescriptionBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
fDescriptionBox->SetLabel(TR("Description")); fDescriptionBox->SetLabel(TR("Description"));
topView->AddChild(fDescriptionBox); fDescriptionBox->SetExplicitAlignment(fullAlignment);
innerRect = fDescriptionBox->Bounds().InsetByCopy(8.0f, 6.0f); fInternalNameView = new StringView(TR("Internal name:"), NULL);
innerRect.top += ceilf(boldHeight.ascent);
innerRect.bottom = innerRect.top + button->Bounds().Height();
fInternalNameView = new StringView(innerRect, "internal", TR("Internal name:"), "",
B_FOLLOW_LEFT_RIGHT);
labelWidth = fInternalNameView->StringWidth(fInternalNameView->Label()) + 2.0f;
fInternalNameView->SetDivider(labelWidth);
fInternalNameView->SetEnabled(false); fInternalNameView->SetEnabled(false);
fInternalNameView->ResizeToPreferred(); fTypeNameControl = new BTextControl("type", TR("Type name:"), "",
fDescriptionBox->AddChild(fInternalNameView); new BMessage(kMsgTypeEntered));
fDescriptionControl = new BTextControl("description", TR("Description:"),
"", new BMessage(kMsgDescriptionEntered));
innerRect.OffsetBy(0, fInternalNameView->Bounds().Height() + 5.0f); fDescriptionBox->AddChild(BGridLayoutBuilder(padding, padding)
fTypeNameControl = new BTextControl(innerRect, "type", TR("Type name:"), "", .Add(fInternalNameView->LabelView(), 0, 0)
new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT); .Add(fInternalNameView->TextView(), 1, 0)
fTypeNameControl->SetDivider(labelWidth); .Add(fTypeNameControl->CreateLabelLayoutItem(), 0, 1)
fTypeNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); .Add(fTypeNameControl->CreateTextViewLayoutItem(), 1, 1, 2)
fDescriptionBox->ResizeBy(0, fInternalNameView->Bounds().Height() .Add(fDescriptionControl->CreateLabelLayoutItem(), 0, 2)
+ fTypeNameControl->Bounds().Height() * 2.0f); .Add(fDescriptionControl->CreateTextViewLayoutItem(), 1, 2, 2)
fDescriptionBox->AddChild(fTypeNameControl); .SetInsets(padding, padding, padding, padding)
);
innerRect.OffsetBy(0, fTypeNameControl->Bounds().Height() + 5.0f);
fDescriptionControl = new BTextControl(innerRect, "description", TR("Description:"), "",
new BMessage(kMsgDescriptionEntered), B_FOLLOW_LEFT_RIGHT);
fDescriptionControl->SetDivider(labelWidth);
fDescriptionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fDescriptionBox->AddChild(fDescriptionControl);
// "Preferred Application" group // "Preferred Application" group
rect = fDescriptionBox->Frame(); fPreferredBox = new BBox("preferred BBox");
rect.top = rect.bottom + 8.0f;
rect.bottom = rect.top + ceilf(boldHeight.ascent)
+ button->Bounds().Height() + 14.0f;
fPreferredBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
fPreferredBox->SetLabel(TR("Preferred application")); fPreferredBox->SetLabel(TR("Preferred application"));
topView->AddChild(fPreferredBox);
innerRect = fPreferredBox->Bounds().InsetByCopy(8.0f, 6.0f);
innerRect.top += ceilf(boldHeight.ascent);
innerRect.left = innerRect.right - button->StringWidth(
TR("Same as" B_UTF8_ELLIPSIS)) - 24.0f;
innerRect.bottom = innerRect.top + button->Bounds().Height();
fSameAsButton = new BButton(innerRect, "same as",
TR("Same as" B_UTF8_ELLIPSIS),
new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_RIGHT);
fPreferredBox->AddChild(fSameAsButton);
innerRect.OffsetBy(-innerRect.Width() - 6.0f, 0.0f);
fSelectButton = new BButton(innerRect, "select", TR("Select" B_UTF8_ELLIPSIS),
new BMessage(kMsgSelectPreferredApp), B_FOLLOW_RIGHT);
fPreferredBox->AddChild(fSelectButton);
menu = new BPopUpMenu("preferred"); menu = new BPopUpMenu("preferred");
menu->AddItem(item = new BMenuItem(TR("None"), menu->AddItem(item = new BMenuItem(TR("None"),
new BMessage(kMsgPreferredAppChosen))); new BMessage(kMsgPreferredAppChosen)));
item->SetMarked(true); item->SetMarked(true);
fPreferredField = new BMenuField("preferred", (char*)NULL, menu);
innerRect.right = innerRect.left - 6.0f; fSelectButton = new BButton("select", TR("Select" B_UTF8_ELLIPSIS),
innerRect.left = 8.0f; new BMessage(kMsgSelectPreferredApp));
fPreferredField = new BMenuField(innerRect, "preferred", NULL, menu, true, fSameAsButton = new BButton("same as", TR("Same as" B_UTF8_ELLIPSIS),
B_FOLLOW_LEFT_RIGHT); new BMessage(kMsgSamePreferredAppAs));
float width;
fPreferredField->GetPreferredSize(&width, &height);
fPreferredField->ResizeTo(innerRect.Width(), height);
fPreferredField->MoveBy(0.0f, (innerRect.Height() - height) / 2.0f);
fPreferredBox->AddChild(fPreferredField); fPreferredBox->AddChild(
BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(fPreferredField)
.Add(fSelectButton)
.Add(fSameAsButton)
.SetInsets(padding, padding, padding, padding)
);
// "Extra Attributes" group // "Extra Attributes" group
fAttributeBox = new BBox("Attribute Box");
rect.top = rect.bottom + 8.0f;
rect.bottom = topView->Bounds().Height() - 8.0f;
fAttributeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT
| B_FOLLOW_TOP_BOTTOM);
fAttributeBox->SetLabel(TR("Extra attributes")); fAttributeBox->SetLabel(TR("Extra attributes"));
topView->AddChild(fAttributeBox);
innerRect = fAttributeBox->Bounds().InsetByCopy(8.0f, 6.0f); fAddAttributeButton = new BButton("add attr",
innerRect.top += ceilf(boldHeight.ascent); "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute));
innerRect.left = innerRect.right - button->StringWidth(TR("Remove")) - 16.0f;
innerRect.bottom = innerRect.top + button->Bounds().Height();
fAddAttributeButton = new BButton(innerRect, "add attr",
TR("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddAttribute), B_FOLLOW_RIGHT);
fAttributeBox->AddChild(fAddAttributeButton);
innerRect.OffsetBy(0, innerRect.Height() + 4.0f); fRemoveAttributeButton = new BButton("remove attr", TR("Remove"),
fRemoveAttributeButton = new BButton(innerRect, "remove attr", TR("Remove"), new BMessage(kMsgRemoveAttribute));
new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
fAttributeBox->AddChild(fRemoveAttributeButton);
/*
innerRect.OffsetBy(0, innerRect.Height() + 4.0f);
button = new BButton(innerRect, "push attr", "Push Up",
new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
fAttributeBox->AddChild(button);
*/
innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
innerRect.left = 10.0f;
innerRect.top = 8.0f + ceilf(boldHeight.ascent);
innerRect.bottom = fAttributeBox->Bounds().bottom - 10.0f;
// take scrollview border into account
fAttributeListView = new AttributeListView(innerRect, "listview attr",
B_FOLLOW_ALL);
fAttributeListView->SetSelectionMessage(new BMessage(kMsgAttributeSelected));
fAttributeListView->SetInvocationMessage(new BMessage(kMsgAttributeInvoked));
scrollView = new BScrollView("scrollview attr", fAttributeListView, fAttributeListView = new AttributeListView("listview attr");
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fAttributeListView->SetSelectionMessage(
fAttributeBox->AddChild(scrollView); new BMessage(kMsgAttributeSelected));
fAttributeListView->SetInvocationMessage(
new BMessage(kMsgAttributeInvoked));
SetSizeLimits(rightRect.left + 72.0f + font.StringWidth("jpg") BScrollView* attributesScroller = new BScrollView("scrollview attr",
+ font.StringWidth(fRecognitionBox->Label()), 32767.0f, fAttributeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
rect.top + 2.0f * button->Bounds().Height() + boldHeight.ascent
+ 32.0f + menuBar->Bounds().Height(), 32767.0f); fAttributeBox->AddChild(BGridLayoutBuilder(padding, padding)
.Add(attributesScroller, 0, 0, 2, 3)
.Add(fAddAttributeButton, 2, 0)
.Add(fRemoveAttributeButton, 2, 1)
.SetInsets(padding, padding, padding, padding)
);
BView* topView =
BGroupLayoutBuilder(B_HORIZONTAL, padding)
.SetInsets(padding, padding, padding, padding)
.Add(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(typeListScrollView)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(addTypeButton).Add(fRemoveTypeButton)
)
)
// Right side
.Add(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(fIconBox, 1).Add(fRecognitionBox, 3)
)
.Add(fDescriptionBox)
.Add(fPreferredBox)
.Add(fAttributeBox, 5)
);
//topView->SetExplicitAlignment(fullAlignment);
//topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
_SetType(NULL); _SetType(NULL);
_ShowSnifferRule(showRule); _ShowSnifferRule(showRule);
@@ -598,7 +540,7 @@ FileTypesWindow::_Frame(const BMessage& settings) const
if (settings.FindRect("file_types_frame", &rect) == B_OK) if (settings.FindRect("file_types_frame", &rect) == B_OK)
return rect; return rect;
return BRect(80.0f, 80.0f, 600.0f, 480.0f); return BRect(80.0f, 80.0f, 0.0f, 0.0f);
} }
@@ -608,29 +550,10 @@ FileTypesWindow::_ShowSnifferRule(bool show)
if (fRuleControl->IsHidden() == !show) if (fRuleControl->IsHidden() == !show)
return; return;
float minWidth, maxWidth, minHeight, maxHeight; if (!show)
GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight);
float diff = fRuleControl->Bounds().Height() + 8.0f;
if (!show) {
fRuleControl->Hide(); fRuleControl->Hide();
diff = -diff; else
}
// adjust other controls to make space or take it again
fIconBox->ResizeBy(0.0f, diff);
fRecognitionBox->ResizeBy(0.0f, diff);
fDescriptionBox->MoveBy(0.0f, diff);
fPreferredBox->MoveBy(0.0f, diff);
fAttributeBox->MoveBy(0.0f, diff);
fAttributeBox->ResizeBy(0.0f, -diff);
if (show)
fRuleControl->Show(); fRuleControl->Show();
SetSizeLimits(minWidth, maxWidth, minHeight + diff, maxHeight);
} }
@@ -671,8 +594,10 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
return; return;
BString preferred; BString preferred;
if (retrieve_preferred_app(message, sameAs, fCurrentType.Type(), preferred) != B_OK) if (retrieve_preferred_app(message, sameAs, fCurrentType.Type(), preferred)
!= B_OK) {
return; return;
}
status_t status = fCurrentType.SetPreferredApp(preferred.String()); status_t status = fCurrentType.SetPreferredApp(preferred.String());
if (status != B_OK) if (status != B_OK)
@@ -683,7 +608,8 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
void void
FileTypesWindow::_UpdatePreferredApps(BMimeType* type) FileTypesWindow::_UpdatePreferredApps(BMimeType* type)
{ {
update_preferred_app_menu(fPreferredField->Menu(), type, kMsgPreferredAppChosen); update_preferred_app_menu(fPreferredField->Menu(), type,
kMsgPreferredAppChosen);
} }
@@ -787,8 +713,9 @@ FileTypesWindow::_SetType(BMimeType* type, int32 forceUpdate)
void void
FileTypesWindow::PlaceSubWindow(BWindow* window) FileTypesWindow::PlaceSubWindow(BWindow* window)
{ {
window->MoveTo(Frame().left + (Frame().Width() - window->Frame().Width()) / 2.0f, window->MoveTo(Frame().left + (Frame().Width() - window->Frame().Width())
Frame().top + (Frame().Height() - window->Frame().Height()) / 2.0f); / 2.0f, Frame().top + (Frame().Height() - window->Frame().Height())
/ 2.0f);
} }
@@ -797,12 +724,14 @@ FileTypesWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
{
type_code type; type_code type;
if (message->GetInfo("refs", &type) == B_OK if (message->GetInfo("refs", &type) == B_OK
&& type == B_REF_TYPE) { && type == B_REF_TYPE) {
be_app->PostMessage(message); be_app->PostMessage(message);
} }
break; break;
}
case kMsgToggleIcons: case kMsgToggleIcons:
{ {
@@ -840,7 +769,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
{ {
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index); MimeTypeItem* item
= (MimeTypeItem*)fTypeListView->ItemAt(index);
if (item != NULL) { if (item != NULL) {
BMimeType type(item->Type()); BMimeType type(item->Type());
_SetType(&type); _SetType(&type);
@@ -851,14 +781,14 @@ FileTypesWindow::MessageReceived(BMessage* message)
} }
case kMsgAddType: case kMsgAddType:
{
if (fNewTypeWindow == NULL) { if (fNewTypeWindow == NULL) {
fNewTypeWindow = new NewFileTypeWindow(this, fCurrentType.Type()); fNewTypeWindow
= new NewFileTypeWindow(this, fCurrentType.Type());
fNewTypeWindow->Show(); fNewTypeWindow->Show();
} else } else
fNewTypeWindow->Activate(); fNewTypeWindow->Activate();
break; break;
}
case kMsgNewTypeWindowClosed: case kMsgNewTypeWindowClosed:
fNewTypeWindow = NULL; fNewTypeWindow = NULL;
break; break;
@@ -870,7 +800,7 @@ FileTypesWindow::MessageReceived(BMessage* message)
BAlert* alert; BAlert* alert;
if (fCurrentType.IsSupertypeOnly()) { if (fCurrentType.IsSupertypeOnly()) {
alert = new BPrivate::OverrideAlert(TR("FileTypes Request"), alert = new BPrivate::OverrideAlert(TR("FileTypes request"),
TR("Removing a super type cannot be reverted.\n" TR("Removing a super type cannot be reverted.\n"
"All file types that belong to this super type " "All file types that belong to this super type "
"will be lost!\n\n" "will be lost!\n\n"
@@ -879,17 +809,20 @@ FileTypesWindow::MessageReceived(BMessage* message)
TR("Remove"), B_SHIFT_KEY, TR("Cancel"), 0, NULL, 0, TR("Remove"), B_SHIFT_KEY, TR("Cancel"), 0, NULL, 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT); B_WIDTH_AS_USUAL, B_STOP_ALERT);
} else { } else {
alert = new BAlert(TR("FileTypes Request"), alert = new BAlert(TR("FileTypes request"),
TR("Removing a file type cannot be reverted.\n" TR("Removing a file type cannot be reverted.\n"
"Are you sure you want to remove it?"), "Are you sure you want to remove it?"),
TR("Remove"), TR("Cancel"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); TR("Remove"), TR("Cancel"), NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT);
} }
if (alert->Go()) if (alert->Go())
break; break;
status_t status = fCurrentType.Delete(); status_t status = fCurrentType.Delete();
if (status != B_OK) if (status != B_OK) {
fprintf(stderr, TR("Could not remove file type: %s\n"), strerror(status)); fprintf(stderr, TR("Could not remove file type: %s\n"),
strerror(status));
}
break; break;
} }
@@ -907,7 +840,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
{ {
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); BStringItem* item
= (BStringItem*)fExtensionListView->ItemAt(index);
fRemoveExtensionButton->SetEnabled(item != NULL); fRemoveExtensionButton->SetEnabled(item != NULL);
} }
break; break;
@@ -920,11 +854,13 @@ FileTypesWindow::MessageReceived(BMessage* message)
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); BStringItem* item
= (BStringItem*)fExtensionListView->ItemAt(index);
if (item == NULL) if (item == NULL)
break; break;
BWindow* window = new ExtensionWindow(this, fCurrentType, item->Text()); BWindow* window
= new ExtensionWindow(this, fCurrentType, item->Text());
window->Show(); window->Show();
} }
break; break;
@@ -958,7 +894,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
{ {
// check rule // check rule
BString parseError; BString parseError;
if (BMimeType::CheckSnifferRule(fRuleControl->Text(), &parseError) != B_OK) { if (BMimeType::CheckSnifferRule(fRuleControl->Text(),
&parseError) != B_OK) {
parseError.Prepend(TR("Recognition rule is not valid:\n\n")); parseError.Prepend(TR("Recognition rule is not valid:\n\n"));
error_alert(parseError.String()); error_alert(parseError.String());
} else } else
@@ -1009,7 +946,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
case kMsgSamePreferredAppAs: case kMsgSamePreferredAppAs:
{ {
BMessage panel(kMsgOpenFilePanel); BMessage panel(kMsgOpenFilePanel);
panel.AddString("title", TR("Select same preferred application as")); panel.AddString("title", TR("Select same preferred application "
"as"));
panel.AddInt32("message", kMsgSamePreferredAppAsOpened); panel.AddInt32("message", kMsgSamePreferredAppAsOpened);
panel.AddMessenger("target", this); panel.AddMessenger("target", this);
@@ -1026,7 +964,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
{ {
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); AttributeItem* item
= (AttributeItem*)fAttributeListView->ItemAt(index);
fRemoveAttributeButton->SetEnabled(item != NULL); fRemoveAttributeButton->SetEnabled(item != NULL);
} }
break; break;
@@ -1039,7 +978,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
int32 index; int32 index;
if (message->FindInt32("index", &index) == B_OK) { if (message->FindInt32("index", &index) == B_OK) {
AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); AttributeItem* item
= (AttributeItem*)fAttributeListView->ItemAt(index);
if (item == NULL) if (item == NULL)
break; break;
@@ -1075,7 +1015,8 @@ FileTypesWindow::MessageReceived(BMessage* message)
}; };
for (uint32 i = 0; i < for (uint32 i = 0; i <
sizeof(kAttributeNames) / sizeof(kAttributeNames[0]); i++) { sizeof(kAttributeNames) / sizeof(kAttributeNames[0]);
i++) {
attributes.RemoveData(kAttributeNames[i], index); attributes.RemoveData(kAttributeNames[i], index);
} }
@@ -1104,9 +1045,7 @@ FileTypesWindow::MessageReceived(BMessage* message)
// this change could still affect our current type // this change could still affect our current type
if (which == B_MIME_TYPE_DELETED if (which == B_MIME_TYPE_DELETED
#ifdef __HAIKU__
|| which == B_SUPPORTED_TYPES_CHANGED || which == B_SUPPORTED_TYPES_CHANGED
#endif
|| which == B_PREFERRED_APP_CHANGED) || which == B_PREFERRED_APP_CHANGED)
_UpdatePreferredApps(&fCurrentType); _UpdatePreferredApps(&fCurrentType);
} }
+1 -1
View File
@@ -20,9 +20,9 @@ class BTextControl;
class AttributeListView; class AttributeListView;
class ExtensionListView; class ExtensionListView;
class TypeIconView;
class MimeTypeListView; class MimeTypeListView;
class StringView; class StringView;
class TypeIconView;
class FileTypesWindow : public BWindow { class FileTypesWindow : public BWindow {
+45 -66
View File
@@ -7,15 +7,12 @@
#include "IconView.h" #include "IconView.h"
#include "MimeTypeListView.h" #include "MimeTypeListView.h"
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
# include <IconUtils.h>
# include <IconEditorProtocol.h>
#endif
#include <Application.h> #include <Application.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h> #include <Catalog.h>
#include <IconEditorProtocol.h>
#include <IconUtils.h>
#include <Locale.h> #include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
@@ -23,6 +20,7 @@
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Resources.h> #include <Resources.h>
#include <Roster.h> #include <Roster.h>
#include <Size.h>
#include <new> #include <new>
#include <stdlib.h> #include <stdlib.h>
@@ -36,7 +34,6 @@
using namespace std; using namespace std;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
status_t status_t
icon_for_type(const BMimeType& type, uint8** _data, size_t* _size, icon_for_type(const BMimeType& type, uint8** _data, size_t* _size,
icon_source* _source) icon_source* _source)
@@ -93,7 +90,6 @@ icon_for_type(const BMimeType& type, uint8** _data, size_t* _size,
return source != kNoIcon ? B_OK : B_ERROR; return source != kNoIcon ? B_OK : B_ERROR;
} }
#endif
status_t status_t
@@ -182,7 +178,6 @@ Icon::SetTo(const BAppFileInfo& info, const char* type)
{ {
Unset(); Unset();
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
uint8* data; uint8* data;
size_t size; size_t size;
if (info.GetIconForType(type, &data, &size) == B_OK) { if (info.GetIconForType(type, &data, &size) == B_OK) {
@@ -190,7 +185,6 @@ Icon::SetTo(const BAppFileInfo& info, const char* type)
AdoptData(data, size); AdoptData(data, size);
return; return;
} }
#endif
BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8); BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8);
if (icon && info.GetIconForType(type, icon, B_LARGE_ICON) == B_OK) if (icon && info.GetIconForType(type, icon, B_LARGE_ICON) == B_OK)
@@ -224,7 +218,6 @@ Icon::SetTo(const BMimeType& type, icon_source* _source)
{ {
Unset(); Unset();
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
uint8* data; uint8* data;
size_t size; size_t size;
if (icon_for_type(type, &data, &size, _source) == B_OK) { if (icon_for_type(type, &data, &size, _source) == B_OK) {
@@ -232,7 +225,6 @@ Icon::SetTo(const BMimeType& type, icon_source* _source)
AdoptData(data, size); AdoptData(data, size);
return; return;
} }
#endif
BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8); BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8);
if (icon && icon_for_type(type, *icon, B_LARGE_ICON, _source) == B_OK) if (icon && icon_for_type(type, *icon, B_LARGE_ICON, _source) == B_OK)
@@ -257,10 +249,8 @@ Icon::CopyTo(BAppFileInfo& info, const char* type, bool force) const
status = info.SetIconForType(type, fLarge, B_LARGE_ICON); status = info.SetIconForType(type, fLarge, B_LARGE_ICON);
if (fMini != NULL || force) if (fMini != NULL || force)
status = info.SetIconForType(type, fMini, B_MINI_ICON); status = info.SetIconForType(type, fMini, B_MINI_ICON);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (fData != NULL || force) if (fData != NULL || force)
status = info.SetIconForType(type, fData, fSize); status = info.SetIconForType(type, fData, fSize);
#endif
return status; return status;
} }
@@ -291,10 +281,8 @@ Icon::CopyTo(BMimeType& type, bool force) const
status = type.SetIcon(fLarge, B_LARGE_ICON); status = type.SetIcon(fLarge, B_LARGE_ICON);
if (fMini != NULL || force) if (fMini != NULL || force)
status = type.SetIcon(fMini, B_MINI_ICON); status = type.SetIcon(fMini, B_MINI_ICON);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (fData != NULL || force) if (fData != NULL || force)
status = type.SetIcon(fData, fSize); status = type.SetIcon(fData, fSize);
#endif
return status; return status;
} }
@@ -316,10 +304,8 @@ Icon::CopyTo(BMessage& message) const
if (status == B_OK) if (status == B_OK)
status = message.AddMessage("icon/mini", &archive); status = message.AddMessage("icon/mini", &archive);
} }
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (status == B_OK && fData != NULL) if (status == B_OK && fData != NULL)
status = message.AddData("icon", B_VECTOR_ICON_TYPE, fData, fSize); status = message.AddData("icon", B_VECTOR_ICON_TYPE, fData, fSize);
#endif
return B_OK; return B_OK;
} }
@@ -360,7 +346,6 @@ Icon::SetMini(const BBitmap* mini)
void void
Icon::SetData(const uint8* data, size_t size) Icon::SetData(const uint8* data, size_t size)
{ {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
free(fData); free(fData);
fData = NULL; fData = NULL;
@@ -372,7 +357,6 @@ Icon::SetData(const uint8* data, size_t size)
memcpy(fData, data, size); memcpy(fData, data, size);
} }
} }
#endif
} }
@@ -447,10 +431,8 @@ Icon::GetIcon(BBitmap* bitmap) const
if (bitmap == NULL) if (bitmap == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (fData != NULL && BIconUtils::GetVectorIcon(fData, fSize, bitmap) == B_OK) if (fData != NULL && BIconUtils::GetVectorIcon(fData, fSize, bitmap) == B_OK)
return B_OK; return B_OK;
#endif
int32 width = bitmap->Bounds().IntegerWidth() + 1; int32 width = bitmap->Bounds().IntegerWidth() + 1;
@@ -508,11 +490,7 @@ Icon::AdoptData(uint8* data, size_t size)
/*static*/ BBitmap* /*static*/ BBitmap*
Icon::AllocateBitmap(int32 size, int32 space) Icon::AllocateBitmap(int32 size, int32 space)
{ {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
int32 kSpace = B_RGBA32; int32 kSpace = B_RGBA32;
#else
int32 kSpace = B_CMAP8;
#endif
if (space == -1) if (space == -1)
space = kSpace; space = kSpace;
@@ -530,8 +508,8 @@ Icon::AllocateBitmap(int32 size, int32 space)
// #pragma mark - // #pragma mark -
IconView::IconView(BRect rect, const char* name, uint32 resizeMode, uint32 flags) IconView::IconView(const char* name, uint32 flags)
: BControl(rect, name, NULL, NULL, resizeMode, B_WILL_DRAW | flags), : BControl(name, NULL, NULL, B_WILL_DRAW | flags),
fModificationMessage(NULL), fModificationMessage(NULL),
fIconSize(B_LARGE_ICON), fIconSize(B_LARGE_ICON),
fIcon(NULL), fIcon(NULL),
@@ -588,9 +566,8 @@ IconView::MessageReceived(BMessage* message)
const uint8* data = NULL; const uint8* data = NULL;
ssize_t size = 0; ssize_t size = 0;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU message->FindData("icon", B_VECTOR_ICON_TYPE, (const void**)&data,
message->FindData("icon", B_VECTOR_ICON_TYPE, (const void**)&data, &size); &size);
#endif
BMessage archive; BMessage archive;
if (message->FindMessage("icon/large", &archive) == B_OK) if (message->FindMessage("icon/large", &archive) == B_OK)
@@ -672,16 +649,13 @@ IconView::MessageReceived(BMessage* message)
if (which == B_MIME_TYPE_DELETED if (which == B_MIME_TYPE_DELETED
|| which == B_PREFERRED_APP_CHANGED || which == B_PREFERRED_APP_CHANGED
#ifdef __HAIKU__
|| which == B_SUPPORTED_TYPES_CHANGED || which == B_SUPPORTED_TYPES_CHANGED
#endif
|| which == B_ICON_FOR_TYPE_CHANGED) || which == B_ICON_FOR_TYPE_CHANGED)
Update(); Update();
} }
break; break;
} }
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
case B_ICON_DATA_EDITED: case B_ICON_DATA_EDITED:
{ {
const uint8* data; const uint8* data;
@@ -693,7 +667,6 @@ IconView::MessageReceived(BMessage* message)
_SetIcon(NULL, NULL, data, size); _SetIcon(NULL, NULL, data, size);
break; break;
} }
#endif
default: default:
BControl::MessageReceived(message); BControl::MessageReceived(message);
@@ -710,7 +683,8 @@ IconView::AcceptsDrag(const BMessage* message)
type_code type; type_code type;
int32 count; int32 count;
if (message->GetInfo("refs", &type, &count) == B_OK && count == 1 && type == B_REF_TYPE) { if (message->GetInfo("refs", &type, &count) == B_OK && count == 1
&& type == B_REF_TYPE) {
// if we're bound to an entry, check that no one drops this to us // if we're bound to an entry, check that no one drops this to us
entry_ref ref; entry_ref ref;
if (fHasRef && message->FindRef("refs", &ref) == B_OK && fRef == ref) if (fHasRef && message->FindRef("refs", &ref) == B_OK && fRef == ref)
@@ -719,11 +693,12 @@ IconView::AcceptsDrag(const BMessage* message)
return true; return true;
} }
if (message->GetInfo("icon/large", &type) == B_OK && type == B_MESSAGE_TYPE if (message->GetInfo("icon/large", &type) == B_OK
#ifdef HAIKU_TARGET_PLATFORM_HAIKU && type == B_MESSAGE_TYPE
|| message->GetInfo("icon", &type) == B_OK && type == B_VECTOR_ICON_TYPE || message->GetInfo("icon", &type) == B_OK
#endif && type == B_VECTOR_ICON_TYPE
|| message->GetInfo("icon/mini", &type) == B_OK && type == B_MESSAGE_TYPE) || message->GetInfo("icon/mini", &type) == B_OK
&& type == B_MESSAGE_TYPE)
return true; return true;
return false; return false;
@@ -764,13 +739,10 @@ IconView::Draw(BRect updateRect)
SetPenSize(2); SetPenSize(2);
BRect rect = BitmapRect(); BRect rect = BitmapRect();
// TODO: this is an incompatibility between R5 and Haiku and should be fixed! // TODO: this is an incompatibility between R5 and Haiku and should be fixed!
#ifdef HAIKU_TARGET_PLATFORM_HAIKU // (Necessary adjustment differs.)
rect.left++; rect.left++;
rect.top++; rect.top++;
#else
rect.right--;
rect.bottom--;
#endif
StrokeRect(rect); StrokeRect(rect);
SetPenSize(1); SetPenSize(1);
} }
@@ -788,6 +760,29 @@ IconView::GetPreferredSize(float* _width, float* _height)
} }
BSize
IconView::MinSize()
{
float width, height;
GetPreferredSize(&width, &height);
return BSize(width, height);
}
BSize
IconView::PreferredSize()
{
return MinSize();
}
BSize
IconView::MaxSize()
{
return MinSize();
}
void void
IconView::MouseDown(BPoint where) IconView::MouseDown(BPoint where)
{ {
@@ -1075,7 +1070,6 @@ IconView::ShowIconHeap(bool show)
BResources* resources = be_app->AppResources(); BResources* resources = be_app->AppResources();
if (resources != NULL) { if (resources != NULL) {
const void* data = NULL; const void* data = NULL;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
size_t size; size_t size;
data = resources->LoadResource('VICN', "icon heap", &size); data = resources->LoadResource('VICN', "icon heap", &size);
if (data != NULL) { if (data != NULL) {
@@ -1089,7 +1083,6 @@ IconView::ShowIconHeap(bool show)
data = NULL; data = NULL;
} }
} }
#endif // HAIKU_TARGET_PLATFORM_HAIKU
if (data == NULL) { if (data == NULL) {
// no vector icon or failed to get bitmap // no vector icon or failed to get bitmap
// try bitmap icon // try bitmap icon
@@ -1119,10 +1112,11 @@ IconView::ShowEmptyFrame(bool show)
} }
void status_t
IconView::SetTarget(const BMessenger& target) IconView::SetTarget(const BMessenger& target)
{ {
fTarget = target; fTarget = target;
return B_OK;
} }
@@ -1134,7 +1128,7 @@ IconView::SetModificationMessage(BMessage* message)
} }
void status_t
IconView::Invoke(const BMessage* _message) IconView::Invoke(const BMessage* _message)
{ {
if (_message == NULL) if (_message == NULL)
@@ -1143,6 +1137,7 @@ IconView::Invoke(const BMessage* _message)
BMessage message(*_message); BMessage message(*_message);
fTarget.SendMessage(&message); fTarget.SendMessage(&message);
} }
return B_OK;
} }
@@ -1178,8 +1173,6 @@ IconView::GetMimeType(BMimeType& type) const
void void
IconView::_AddOrEditIcon() IconView::_AddOrEditIcon()
{ {
// this works only in Haiku! (the icon editor is built-in in R5's FileType)
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
BMessage message; BMessage message;
if (fHasRef && fType.Type() == NULL) { if (fHasRef && fType.Type() == NULL) {
// in ref mode, Icon-O-Matic can change the icon directly, and // in ref mode, Icon-O-Matic can change the icon directly, and
@@ -1216,7 +1209,6 @@ IconView::_AddOrEditIcon()
} }
be_roster->Launch("application/x-vnd.haiku-icon_o_matic", &message); be_roster->Launch("application/x-vnd.haiku-icon_o_matic", &message);
#endif
} }
@@ -1232,10 +1224,8 @@ IconView::_SetIcon(BBitmap* large, BBitmap* mini, const uint8* data, size_t size
info.SetIconForType(fType.Type(), large, B_LARGE_ICON); info.SetIconForType(fType.Type(), large, B_LARGE_ICON);
if (mini != NULL || force) if (mini != NULL || force)
info.SetIconForType(fType.Type(), mini, B_MINI_ICON); info.SetIconForType(fType.Type(), mini, B_MINI_ICON);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (data != NULL || force) if (data != NULL || force)
info.SetIconForType(fType.Type(), data, size); info.SetIconForType(fType.Type(), data, size);
#endif
} }
// the icon shown will be updated using node monitoring // the icon shown will be updated using node monitoring
} else if (fHasType) { } else if (fHasType) {
@@ -1243,10 +1233,8 @@ IconView::_SetIcon(BBitmap* large, BBitmap* mini, const uint8* data, size_t size
fType.SetIcon(large, B_LARGE_ICON); fType.SetIcon(large, B_LARGE_ICON);
if (mini != NULL || force) if (mini != NULL || force)
fType.SetIcon(mini, B_MINI_ICON); fType.SetIcon(mini, B_MINI_ICON);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (data != NULL || force) if (data != NULL || force)
fType.SetIcon(data, size); fType.SetIcon(data, size);
#endif
// the icon shown will be updated automatically - we're watching // the icon shown will be updated automatically - we're watching
// any changes to the MIME database // any changes to the MIME database
} else if (fIconData != NULL) { } else if (fIconData != NULL) {
@@ -1282,7 +1270,6 @@ IconView::_SetIcon(entry_ref* ref)
if (file.InitCheck() != B_OK || info.InitCheck() != B_OK) if (file.InitCheck() != B_OK || info.InitCheck() != B_OK)
return; return;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
// try vector/PNG icon first // try vector/PNG icon first
uint8* data = NULL; uint8* data = NULL;
size_t size = 0; size_t size = 0;
@@ -1291,7 +1278,6 @@ IconView::_SetIcon(entry_ref* ref)
free(data); free(data);
return; return;
} }
#endif
// try large/mini icons // try large/mini icons
bool hasMini = false; bool hasMini = false;
@@ -1322,26 +1308,19 @@ IconView::_SetIcon(entry_ref* ref)
return; return;
BMimeType mimeType(type); BMimeType mimeType(type);
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (icon_for_type(mimeType, &data, &size) != B_OK) { if (icon_for_type(mimeType, &data, &size) != B_OK) {
// only try large/mini icons when there is no vector icon // only try large/mini icons when there is no vector icon
#endif
if (large != NULL && icon_for_type(mimeType, *large, B_LARGE_ICON) == B_OK) if (large != NULL && icon_for_type(mimeType, *large, B_LARGE_ICON) == B_OK)
hasLarge = true; hasLarge = true;
if (mini != NULL && icon_for_type(mimeType, *mini, B_MINI_ICON) == B_OK) if (mini != NULL && icon_for_type(mimeType, *mini, B_MINI_ICON) == B_OK)
hasMini = true; hasMini = true;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
} }
#endif
} }
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
if (data != NULL) { if (data != NULL) {
_SetIcon(NULL, NULL, data, size); _SetIcon(NULL, NULL, data, size);
free(data); free(data);
} else } else if (hasLarge || hasMini)
#endif
if (hasLarge || hasMini)
_SetIcon(large, mini, NULL, 0); _SetIcon(large, mini, NULL, 0);
delete large; delete large;
+11 -7
View File
@@ -50,8 +50,8 @@ class Icon {
Icon& operator=(const Icon& source); Icon& operator=(const Icon& source);
void AdoptLarge(BBitmap *large); void AdoptLarge(BBitmap* large);
void AdoptMini(BBitmap *mini); void AdoptMini(BBitmap* mini);
void AdoptData(uint8* data, size_t size); void AdoptData(uint8* data, size_t size);
static BBitmap* AllocateBitmap(int32 size, int32 space = -1); static BBitmap* AllocateBitmap(int32 size, int32 space = -1);
@@ -63,11 +63,11 @@ class Icon {
size_t fSize; size_t fSize;
}; };
class BSize;
class IconView : public BControl { class IconView : public BControl {
public: public:
IconView(BRect rect, const char* name, IconView(const char* name, uint32 flags = B_NAVIGABLE);
uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE);
virtual ~IconView(); virtual ~IconView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
@@ -76,6 +76,10 @@ class IconView : public BControl {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void GetPreferredSize(float* _width, float* _height); virtual void GetPreferredSize(float* _width, float* _height);
virtual BSize MaxSize();
virtual BSize MinSize();
virtual BSize PreferredSize();
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where); virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage);
@@ -92,9 +96,9 @@ class IconView : public BControl {
void SetIconSize(int32 size); void SetIconSize(int32 size);
void ShowIconHeap(bool show); void ShowIconHeap(bool show);
void ShowEmptyFrame(bool show); void ShowEmptyFrame(bool show);
void SetTarget(const BMessenger& target); status_t SetTarget(const BMessenger& target);
void SetModificationMessage(BMessage* message); void SetModificationMessage(BMessage* message);
void Invoke(const BMessage* message = NULL); status_t Invoke(const BMessage* message = NULL);
::Icon* Icon(); ::Icon* Icon();
int32 IconSize() const { return fIconSize; } int32 IconSize() const { return fIconSize; }
+12 -26
View File
@@ -89,11 +89,7 @@ MimeTypeItem::DrawItem(BView* owner, BRect frame, bool complete)
owner->FillRect(rect, B_SOLID_LOW); owner->FillRect(rect, B_SOLID_LOW);
} }
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_RGBA32); BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_RGBA32);
#else
BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8);
#endif
BMimeType mimeType(fType.String()); BMimeType mimeType(fType.String());
status_t status = icon_for_type(mimeType, bitmap, B_MINI_ICON); status_t status = icon_for_type(mimeType, bitmap, B_MINI_ICON);
if (status < B_OK) { if (status < B_OK) {
@@ -267,10 +263,9 @@ MimeTypeItem::CompareLabels(const BListItem* a, const BListItem* b)
// #pragma mark - // #pragma mark -
MimeTypeListView::MimeTypeListView(BRect rect, const char* name, MimeTypeListView::MimeTypeListView(const char* name,
const char* supertype, bool showIcons, bool applicationMode, const char* supertype, bool showIcons, bool applicationMode)
uint32 resizingMode) : BOutlineListView(name, B_SINGLE_SELECTION_LIST),
: BOutlineListView(rect, name, B_SINGLE_SELECTION_LIST, resizingMode),
fSupertype(supertype), fSupertype(supertype),
fShowIcons(showIcons), fShowIcons(showIcons),
fApplicationMode(applicationMode) fApplicationMode(applicationMode)
@@ -284,7 +279,8 @@ MimeTypeListView::~MimeTypeListView()
void void
MimeTypeListView::_CollectSubtypes(const char* supertype, MimeTypeItem* supertypeItem) MimeTypeListView::_CollectSubtypes(const char* supertype,
MimeTypeItem* supertypeItem)
{ {
BMessage types; BMessage types;
if (BMimeType::GetInstalledTypes(supertype, &types) != B_OK) if (BMimeType::GetInstalledTypes(supertype, &types) != B_OK)
@@ -324,7 +320,8 @@ MimeTypeListView::_CollectTypes()
const char* supertype; const char* supertype;
int32 index = 0; int32 index = 0;
while (superTypes.FindString("super_types", index++, &supertype) == B_OK) { while (superTypes.FindString("super_types", index++, &supertype)
== B_OK) {
MimeTypeItem* supertypeItem = new MimeTypeItem(supertype); MimeTypeItem* supertypeItem = new MimeTypeItem(supertype);
AddItem(supertypeItem); AddItem(supertypeItem);
@@ -339,10 +336,7 @@ MimeTypeListView::_CollectTypes()
void void
MimeTypeListView::_MakeTypesUnique(MimeTypeItem* underItem) MimeTypeListView::_MakeTypesUnique(MimeTypeItem* underItem)
{ {
#ifndef __HAIKU__ SortItemsUnder(underItem, underItem != NULL, &MimeTypeItem::Compare);
if (fSupertype.Type() == NULL)
#endif
SortItemsUnder(underItem, underItem != NULL, &MimeTypeItem::Compare);
bool lastItemSame = false; bool lastItemSame = false;
MimeTypeItem* last = NULL; MimeTypeItem* last = NULL;
@@ -494,18 +488,10 @@ MimeTypeListView::MessageReceived(BMessage* message)
BMessage addType(kMsgAddType); BMessage addType(kMsgAddType);
addType.AddString("type", type); addType.AddString("type", type);
#ifdef __HAIKU__ if (BMessageRunner::StartSending(this, &addType, 200000ULL,
if (BMessageRunner::StartSending(this, &addType, 200000ULL, 1) != B_OK) 1) != B_OK) {
_AddNewType(type);
#else
// TODO: free runner again!
BMessageRunner* runner = new BMessageRunner(this, &addType,
200000ULL, 1);
if (runner->InitCheck() != B_OK) {
delete runner;
_AddNewType(type); _AddNewType(type);
} }
#endif
break; break;
} }
case B_MIME_TYPE_DELETED: case B_MIME_TYPE_DELETED:
@@ -520,8 +506,8 @@ MimeTypeListView::MessageReceived(BMessage* message)
} }
case B_PREFERRED_APP_CHANGED: case B_PREFERRED_APP_CHANGED:
{ {
// try to add or remove this type (changing the preferred app // try to add or remove this type (changing the preferred
// might change visibility in our list) // app might change visibility in our list)
_AddNewType(type); _AddNewType(type);
// supposed to fall through // supposed to fall through
+2 -3
View File
@@ -52,10 +52,9 @@ class MimeTypeItem : public BStringItem {
class MimeTypeListView : public BOutlineListView { class MimeTypeListView : public BOutlineListView {
public: public:
MimeTypeListView(BRect rect, const char* name, MimeTypeListView(const char* name,
const char* supertype = NULL, bool showIcons = false, const char* supertype = NULL, bool showIcons = false,
bool applicationMode = false, bool applicationMode = false);
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
virtual ~MimeTypeListView(); virtual ~MimeTypeListView();
void SelectNewType(const char* type); void SelectNewType(const char* type);
+53 -48
View File
@@ -10,12 +10,18 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <GroupLayout.h>
#include <GridLayoutBuilder.h>
#include <Locale.h> #include <Locale.h>
#include <MenuBar.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <SpaceLayoutItem.h>
#include <String.h> #include <String.h>
#include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <string.h> #include <string.h>
@@ -33,19 +39,14 @@ const uint32 kMsgNameUpdated = 'nmup';
const uint32 kMsgAddType = 'atyp'; const uint32 kMsgAddType = 'atyp';
NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, const char* currentType) NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target,
: BWindow(BRect(100, 100, 350, 200), TR("New file type"), B_TITLED_WINDOW, const char* currentType)
B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), :
BWindow(BRect(100, 100, 350, 200), TR("New file type"), B_MODAL_WINDOW,
B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
| B_AUTO_UPDATE_SIZE_LIMITS ),
fTarget(target) fTarget(target)
{ {
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);
float labelWidth = be_plain_font->StringWidth(TR("Internal name:")) + 2.0f;
rect.InsetBy(8.0f, 6.0f);
fSupertypesMenu = new BPopUpMenu("supertypes"); fSupertypesMenu = new BPopUpMenu("supertypes");
BMenuItem* item; BMenuItem* item;
BMessage types; BMessage types;
@@ -67,55 +68,54 @@ NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, const char* curren
if (i > 1) if (i > 1)
fSupertypesMenu->AddSeparatorItem(); fSupertypesMenu->AddSeparatorItem();
} }
fSupertypesMenu->AddItem(new BMenuItem(TR("Add new group"), fSupertypesMenu->AddItem(new BMenuItem(TR("Add new group"),
new BMessage(kMsgNewSupertypeChosen))); new BMessage(kMsgNewSupertypeChosen)));
BMenuField* typesMenuField = new BMenuField(NULL, fSupertypesMenu);
BMenuField* menuField = new BMenuField(rect, "supertypes", BStringView* typesMenuLabel = new BStringView(NULL, TR("Group:"));
TR("Group:"), fSupertypesMenu); // Create a separate label view, otherwise things don't line up right
menuField->SetDivider(labelWidth); typesMenuLabel->SetAlignment(B_ALIGN_LEFT);
menuField->SetAlignment(B_ALIGN_RIGHT); typesMenuLabel->SetExplicitAlignment(
float width, height; BAlignment(B_ALIGN_LEFT, B_ALIGN_USE_FULL_HEIGHT));
menuField->GetPreferredSize(&width, &height);
menuField->ResizeTo(rect.Width(), height);
topView->AddChild(menuField);
fNameControl = new BTextControl(rect, "internal", TR("Internal name:"), "", fNameControl = new BTextControl(TR("Internal name:"), "", NULL);
NULL, B_FOLLOW_LEFT_RIGHT);
fNameControl->SetModificationMessage(new BMessage(kMsgNameUpdated)); fNameControl->SetModificationMessage(new BMessage(kMsgNameUpdated));
fNameControl->SetDivider(labelWidth);
fNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
// filter out invalid characters that can't be part of a MIME type name // filter out invalid characters that can't be part of a MIME type name
BTextView* textView = fNameControl->TextView(); BTextView* nameControlTextView = fNameControl->TextView();
const char* disallowedCharacters = "/<>@,;:\"()[]?="; const char* disallowedCharacters = "/<>@,;:\"()[]?=";
for (int32 i = 0; disallowedCharacters[i]; i++) { for (int32 i = 0; disallowedCharacters[i]; i++) {
textView->DisallowChar(disallowedCharacters[i]); nameControlTextView->DisallowChar(disallowedCharacters[i]);
} }
fNameControl->GetPreferredSize(&width, &height); fAddButton = new BButton(TR("Add type"), new BMessage(kMsgAddType));
fNameControl->ResizeTo(rect.Width(), height);
fNameControl->MoveTo(8.0f, 12.0f + menuField->Bounds().Height());
topView->AddChild(fNameControl);
fAddButton = new BButton(rect, "add", TR("Add type"), new BMessage(kMsgAddType), float padding = 3.0f;
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); // if (be_control_look)
fAddButton->ResizeToPreferred(); // padding = be_control_look->DefaultItemSpacing();
fAddButton->MoveTo(Bounds().Width() - 8.0f - fAddButton->Bounds().Width(),
Bounds().Height() - 8.0f - fAddButton->Bounds().Height());
fAddButton->SetEnabled(false);
topView->AddChild(fAddButton);
BButton* button = new BButton(rect, "cancel", TR("Cancel"), SetLayout(new BGroupLayout(B_VERTICAL));
new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); AddChild(BGridLayoutBuilder(padding, padding)
button->ResizeToPreferred(); .SetInsets(padding, padding, padding, padding)
button->MoveTo(fAddButton->Frame().left - 10.0f - button->Bounds().Width(), .Add(typesMenuLabel, 0, 0)
fAddButton->Frame().top); .Add(typesMenuField, 1, 0, 2)
topView->AddChild(button); .Add(fNameControl->CreateLabelLayoutItem(), 0, 1)
.Add(fNameControl->CreateTextViewLayoutItem(), 1, 1, 2)
.Add(BSpaceLayoutItem::CreateGlue(), 0, 2)
.Add(new BButton(TR("Cancel"), new BMessage(B_QUIT_REQUESTED)), 1, 2)
.Add(fAddButton, 2, 2)
.SetColumnWeight(0, 3)
);
ResizeTo(labelWidth * 4.0f + 24.0f, fNameControl->Bounds().Height() BAlignment fullSize = BAlignment(B_ALIGN_USE_FULL_WIDTH,
+ menuField->Bounds().Height() + fAddButton->Bounds().Height() + 30.0f); B_ALIGN_USE_FULL_HEIGHT);
SetSizeLimits(button->Bounds().Width() + fAddButton->Bounds().Width() + 26.0f, typesMenuField->MenuBar()->SetExplicitAlignment(fullSize);
32767.0f, Frame().Height(), Frame().Height()); fNameControl->TextView()->SetExplicitAlignment(fullSize);
BLayoutItem* nameControlLabelItem = fNameControl->CreateLabelLayoutItem();
nameControlLabelItem->SetExplicitMinSize(nameControlLabelItem->MinSize());
// stops fNameControl's label from truncating under certain conditions
fAddButton->MakeDefault(true); fAddButton->MakeDefault(true);
fNameControl->MakeFocus(true); fNameControl->MakeFocus(true);
@@ -137,12 +137,14 @@ NewFileTypeWindow::MessageReceived(BMessage* message)
fAddButton->SetLabel(TR("Add type")); fAddButton->SetLabel(TR("Add type"));
fNameControl->SetLabel(TR("Internal name:")); fNameControl->SetLabel(TR("Internal name:"));
fNameControl->MakeFocus(true); fNameControl->MakeFocus(true);
InvalidateLayout(true);
break; break;
case kMsgNewSupertypeChosen: case kMsgNewSupertypeChosen:
fAddButton->SetLabel(TR("Add group")); fAddButton->SetLabel(TR("Add group"));
fNameControl->SetLabel(TR("Group name:")); fNameControl->SetLabel(TR("Group name:"));
fNameControl->MakeFocus(true); fNameControl->MakeFocus(true);
InvalidateLayout(true);
break; break;
case kMsgNameUpdated: case kMsgNameUpdated:
@@ -160,7 +162,8 @@ NewFileTypeWindow::MessageReceived(BMessage* message)
BMenuItem* item = fSupertypesMenu->FindMarked(); BMenuItem* item = fSupertypesMenu->FindMarked();
if (item != NULL) { if (item != NULL) {
BString type; BString type;
if (fSupertypesMenu->IndexOf(item) != fSupertypesMenu->CountItems() - 1) { if (fSupertypesMenu->IndexOf(item)
!= fSupertypesMenu->CountItems() - 1) {
// add normal type // add normal type
type = item->Label(); type = item->Label();
type.Append("/"); type.Append("/");
@@ -170,7 +173,7 @@ NewFileTypeWindow::MessageReceived(BMessage* message)
BMimeType mimeType(type.String()); BMimeType mimeType(type.String());
if (mimeType.IsInstalled()) { if (mimeType.IsInstalled()) {
error_alert(TR("This file type already exists.")); error_alert(TR("This file type already exists"));
break; break;
} }
@@ -201,3 +204,5 @@ NewFileTypeWindow::QuitRequested()
fTarget.SendMessage(kMsgNewTypeWindowClosed); fTarget.SendMessage(kMsgNewTypeWindowClosed);
return true; return true;
} }
+14 -13
View File
@@ -9,15 +9,14 @@
#include <Alert.h> #include <Alert.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Catalog.h>
#include <Locale.h>
#include <Menu.h> #include <Menu.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <String.h> #include <String.h>
#include <Catalog.h>
#include <Locale.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -163,9 +162,11 @@ update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what,
|| item->Message()->FindString("signature", &signature) != B_OK) || item->Message()->FindString("signature", &signature) != B_OK)
continue; continue;
if (preferredFrom == NULL && !strcasecmp(signature, preferred) if ((preferredFrom == NULL && !strcasecmp(signature, preferred))
|| preferredFrom != NULL && !strcasecmp(signature, preferredFrom)) || (preferredFrom != NULL
&& !strcasecmp(signature, preferredFrom))) {
select = item; select = item;
}
if (last == NULL || strcmp(last->Label(), item->Label())) { if (last == NULL || strcmp(last->Label(), item->Label())) {
if (lastItemSame) if (lastItemSame)
@@ -191,8 +192,8 @@ update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what,
// We don't select the item earlier, so that the menu field can // We don't select the item earlier, so that the menu field can
// pick up the signature as well as label. // pick up the signature as well as label.
select->SetMarked(true); select->SetMarked(true);
} else if (preferredFrom == NULL && preferred[0] } else if ((preferredFrom == NULL && preferred[0])
|| preferredFrom && preferredFrom[0]) { || (preferredFrom != NULL && preferredFrom[0])) {
// The preferred application is not an application that support // The preferred application is not an application that support
// this file type! // this file type!
BMenuItem* item = create_application_item(preferredFrom BMenuItem* item = create_application_item(preferredFrom
@@ -252,9 +253,9 @@ retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType,
} }
if (!preferred[0]) { if (!preferred[0]) {
error_alert(sameAs ? error_alert(sameAs
TR("Could not retrieve preferred application of this file.") ? TR("Could not retrieve preferred application of this file")
: TR("Could not retrieve application signature.")); : TR("Could not retrieve application signature"));
return B_ERROR; return B_ERROR;
} }
@@ -287,9 +288,9 @@ retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType,
"Are you sure you want to set it anyway?"), "Are you sure you want to set it anyway?"),
description[0] ? description : preferred); description[0] ? description : preferred);
BAlert* alert = new BAlert("FileTypes Request", warning, BAlert* alert = new BAlert(TR("FileTypes request"), warning,
TR("Set Preferred Application"), "Cancel", NULL, B_WIDTH_AS_USUAL, TR("Set Preferred Application"), TR("Cancel"), NULL,
B_WARNING_ALERT); B_WIDTH_AS_USUAL, B_WARNING_ALERT);
if (alert->Go() == 1) if (alert->Go() == 1)
return B_ERROR; return B_ERROR;
} }
+3 -2
View File
@@ -15,7 +15,8 @@ class BString;
void update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, void update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what,
const char* preferredFrom = NULL); const char* preferredFrom = NULL);
status_t retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType,
BString& preferredApp); status_t retrieve_preferred_app(BMessage* message, bool sameAs,
const char* forType, BString& preferredApp);
#endif // PREFERRED_APP_MENU_H #endif // PREFERRED_APP_MENU_H
+79 -195
View File
@@ -4,220 +4,104 @@
*/ */
#include <GroupView.h>
#include <LayoutItem.h>
#include <StringView.h>
#include "StringView.h" #include "StringView.h"
StringView::StringView(BRect frame, const char* name, const char* label, StringView::StringView(const char* label, const char* text)
const char* text, uint32 resizeMask, uint32 flags) :
: BView(frame, name, resizeMask, flags), fView(NULL),
fLabel(label), fLabel(new BStringView(NULL, label)),
fText(text), fLabelItem(NULL),
fLabelAlignment(B_ALIGN_RIGHT), fText(new BStringView(NULL, text)),
fTextAlignment(B_ALIGN_LEFT), fTextItem(NULL)
fEnabled(true)
{ {
fDivider = StringWidth(label) + 4.0f;
}
StringView::~StringView()
{
}
void
StringView::SetAlignment(alignment labelAlignment, alignment textAlignment)
{
if (labelAlignment == fLabelAlignment && textAlignment == fTextAlignment)
return;
fLabelAlignment = labelAlignment;
fTextAlignment = textAlignment;
Invalidate();
}
void
StringView::GetAlignment(alignment* _label, alignment* _text) const
{
if (_label)
*_label = fLabelAlignment;
if (_text)
*_text = fTextAlignment;
}
void
StringView::SetDivider(float divider)
{
fDivider = divider;
_UpdateText();
Invalidate();
}
void
StringView::AttachedToWindow()
{
if (Parent() != NULL)
SetViewColor(Parent()->ViewColor());
else
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor());
_UpdateText();
}
void
StringView::Draw(BRect updateRect)
{
BRect rect = Bounds();
font_height fontHeight;
GetFontHeight(&fontHeight);
float y = ceilf(fontHeight.ascent) + 1.0f;
float x;
#if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE)
rgb_color textColor = {0, 0, 0, 255};
#else
rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR);
#endif
SetHighColor(IsEnabled() ? textColor
: tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT));
if (Label()) {
switch (fLabelAlignment) {
case B_ALIGN_RIGHT:
x = Divider() - StringWidth(Label()) - 3.0f;
break;
case B_ALIGN_CENTER:
x = Divider() - StringWidth(Label()) / 2.0f;
break;
default:
x = 1.0f;
break;
}
DrawString(Label(), BPoint(x, y));
}
if (fTruncatedText.String() != NULL) {
switch (fTextAlignment) {
case B_ALIGN_RIGHT:
x = rect.Width() - StringWidth(fTruncatedText.String());
break;
case B_ALIGN_CENTER:
x = Divider() + (rect.Width() - Divider() - StringWidth(Label())) / 2.0f;
break;
default:
x = Divider() + 3.0f;
break;
}
DrawString(fTruncatedText.String(), BPoint(x, y));
}
}
void
StringView::FrameResized(float width, float height)
{
BString oldTruncated = fTruncatedText;
_UpdateText();
if (oldTruncated != fTruncatedText) {
// invalidate text portion only
BRect rect = Bounds();
rect.left = Divider();
Invalidate(rect);
}
}
void
StringView::ResizeToPreferred()
{
float width, height;
GetPreferredSize(&width, &height);
// Resize the width only for B_ALIGN_LEFT (if its large enough already, that is)
if (Bounds().Width() > width
&& (fLabelAlignment != B_ALIGN_LEFT || fTextAlignment != B_ALIGN_LEFT))
width = Bounds().Width();
BView::ResizeTo(width, height);
}
void
StringView::GetPreferredSize(float* _width, float* _height)
{
if (!Text() && !Label()) {
BView::GetPreferredSize(_width, _height);
return;
}
if (_width)
*_width = 7.0f + ceilf(StringWidth(Label()) + StringWidth(Text()));
if (_height) {
font_height fontHeight;
GetFontHeight(&fontHeight);
*_height = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 2.0f;
}
}
void
StringView::SetEnabled(bool enabled)
{
if (IsEnabled() == enabled)
return;
fEnabled = enabled;
Invalidate();
} }
void void
StringView::SetLabel(const char* label) StringView::SetLabel(const char* label)
{ {
fLabel = label; fLabel->SetText(label);
// invalidate label portion only
BRect rect = Bounds();
rect.right = Divider();
Invalidate(rect);
} }
void void
StringView::SetText(const char* text) StringView::SetText(const char* text)
{ {
fText = text; fText->SetText(text);
_UpdateText();
// invalidate text portion only
BRect rect = Bounds();
rect.left = Divider();
Invalidate(rect);
} }
BLayoutItem*
StringView::GetLabelLayoutItem()
{
return fLabelItem;
}
BView*
StringView::LabelView()
{ return fLabel; }
BLayoutItem*
StringView::GetTextLayoutItem()
{
return fTextItem;
}
BView*
StringView::TextView()
{ return fText; }
void void
StringView::_UpdateText() StringView::SetEnabled(bool enabled)
{ {
fTruncatedText = fText;
TruncateString(&fTruncatedText, B_TRUNCATE_MIDDLE, Bounds().Width() - Divider()); rgb_color color;
if (!enabled) {
color = tint_color(
ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT);
} else
color = ui_color(B_CONTROL_TEXT_COLOR);
fLabel->SetHighColor(color);
fText->SetHighColor(color);
fLabel->Invalidate();
fText->Invalidate();
} }
//cast operator BView*
StringView::operator BView*()
{
if (fView)
return fView;
fView = new BGroupView(B_HORIZONTAL);
BLayout* layout = fView->GroupLayout();
fLabelItem = layout->AddView(fLabel);
fTextItem = layout->AddView(fText);
return fView;
}
const char*
StringView::Label() const
{
return fLabel->Text();
}
const char*
StringView::Text() const
{
return fText->Text();
}
+19 -32
View File
@@ -6,50 +6,37 @@
#define STRING_VIEW_H #define STRING_VIEW_H
#include <String.h> class BLayoutItem;
#include <View.h> class BGroupView;
class BStringView;
class StringView {
class StringView : public BView {
public: public:
StringView(BRect frame, const char* name, const char* label, StringView(const char* label,
const char* text, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, const char* text);
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS);
virtual ~StringView();
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void FrameResized(float width, float height);
virtual void GetPreferredSize(float* _width, float* _height);
virtual void ResizeToPreferred();
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
bool IsEnabled() const { return fEnabled; }
void SetLabel(const char* label); void SetLabel(const char* label);
const char* Label() const { return fLabel.String(); } const char* Label() const;
void SetText(const char* text); void SetText(const char* text);
const char* Text() const { return fText.String(); } const char* Text() const;
void SetDivider(float divider); BLayoutItem* GetLabelLayoutItem();
float Divider() const { return fDivider; } BView* LabelView();
BLayoutItem* GetTextLayoutItem();
BView* TextView();
void SetAlignment(alignment labelAlignment, alignment textAlignment); operator BView*();
void GetAlignment(alignment* _label, alignment* _text) const;
private: private:
void _UpdateText();
BString fLabel; BGroupView* fView;
BString fText; BStringView* fLabel;
BString fTruncatedText; BLayoutItem* fLabelItem;
float fDivider; BStringView* fText;
alignment fLabelAlignment; BLayoutItem* fTextItem;
alignment fTextAlignment;
bool fEnabled;
}; };
#endif // STRING_VIEW_H #endif // STRING_VIEW_H
+33 -31
View File
@@ -9,6 +9,8 @@
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <GroupLayoutBuilder.h>
#include <Locale.h> #include <Locale.h>
#include <ScrollView.h> #include <ScrollView.h>
@@ -16,58 +18,58 @@
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "TypeListWindow" #define TR_CONTEXT "Type List Window"
const uint32 kMsgTypeSelected = 'tpsl'; const uint32 kMsgTypeSelected = 'tpsl';
const uint32 kMsgSelected = 'seld'; const uint32 kMsgSelected = 'seld';
TypeListWindow::TypeListWindow(const char* currentType, uint32 what, TypeListWindow::TypeListWindow(const char* currentType,
BWindow* target) uint32 what, BWindow* target)
: BWindow(BRect(100, 100, 360, 440), TR("Choose type"), B_MODAL_WINDOW, :
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), BWindow(BRect(100, 100, 360, 440), TR("Choose type"), B_MODAL_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fTarget(target), fTarget(target),
fWhat(what) fWhat(what)
{ {
BRect rect = Bounds(); float padding = 3.0f;
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); //if (be_control_look)
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // padding = be_control_look->DefaultItemSpacing();
AddChild(topView); // seems too big
fSelectButton = new BButton(rect, "select", TR("Done"), fSelectButton = new BButton("select", TR("Done"),
new BMessage(kMsgSelected), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(kMsgSelected));
fSelectButton->ResizeToPreferred();
fSelectButton->MoveTo(topView->Bounds().right - 8.0f
- fSelectButton->Bounds().Width(),
topView->Bounds().bottom - 8.0f - fSelectButton->Bounds().Height());
fSelectButton->SetEnabled(false); fSelectButton->SetEnabled(false);
topView->AddChild(fSelectButton);
BButton* button = new BButton(fSelectButton->Frame(), "cancel", TR("Cancel"), BButton* button = new BButton("cancel", TR("Cancel"),
new BMessage(B_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(B_CANCEL));
button->ResizeToPreferred();
button->MoveBy(-button->Bounds().Width() - 8.0f, 0.0f);
topView->AddChild(button);
fSelectButton->MakeDefault(true); fSelectButton->MakeDefault(true);
rect.bottom = button->Frame().top - 10.0f; fListView = new MimeTypeListView("typeview", NULL, true, false);
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->SetSelectionMessage(new BMessage(kMsgTypeSelected));
fListView->SetInvocationMessage(new BMessage(kMsgSelected)); fListView->SetInvocationMessage(new BMessage(kMsgSelected));
BScrollView* scrollView = new BScrollView("scrollview", fListView, BScrollView* scrollView = new BScrollView("scrollview", fListView,
B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); B_FRAME_EVENTS | B_WILL_DRAW, false, true);
topView->AddChild(scrollView);
SetLayout(new BGroupLayout(B_VERTICAL));
AddChild(BGroupLayoutBuilder(B_VERTICAL, padding)
.Add(scrollView)
.Add(BGroupLayoutBuilder(B_HORIZONTAL, padding)
.Add(button)
.Add(fSelectButton)
)
.SetInsets(padding, padding, padding, padding)
);
BAlignment buttonAlignment =
BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER);
button->SetExplicitAlignment(buttonAlignment);
fSelectButton->SetExplicitAlignment(buttonAlignment);
MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f)); MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f));
SetSizeLimits(button->Bounds().Width() + fSelectButton->Bounds().Width() + 64.0f, 32767.0f,
fSelectButton->Bounds().Height() * 5.0f, 32767.0f);
} }