has some usefulness now
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5978 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Mime.h>
|
#include <Mime.h>
|
||||||
|
#include <Window.h>
|
||||||
#include <FileTypeView.h>
|
#include <FileTypeView.h>
|
||||||
|
|
||||||
FileTypeView::FileTypeView(BRect viewFrame)
|
FileTypeView::FileTypeView(BRect viewFrame)
|
||||||
@@ -12,7 +13,7 @@ FileTypeView::FileTypeView(BRect viewFrame)
|
|||||||
const char * fileTypeLabel = "File Type";
|
const char * fileTypeLabel = "File Type";
|
||||||
BRect fileTypeRect(10,10,viewFrame.Width()-55,90);
|
BRect fileTypeRect(10,10,viewFrame.Width()-55,90);
|
||||||
fFileTypeBox = new BBox(fileTypeRect,fileTypeLabel,
|
fFileTypeBox = new BBox(fileTypeRect,fileTypeLabel,
|
||||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP);
|
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP, B_WILL_DRAW);
|
||||||
fFileTypeBox->SetLabel(fileTypeLabel);
|
fFileTypeBox->SetLabel(fileTypeLabel);
|
||||||
AddChild(fFileTypeBox);
|
AddChild(fFileTypeBox);
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ FileTypeView::FileTypeView(BRect viewFrame)
|
|||||||
const char * preferredAppLabel = "Preferred Application";
|
const char * preferredAppLabel = "Preferred Application";
|
||||||
BRect preferredAppRect(10,95,viewFrame.Width()-55,170);
|
BRect preferredAppRect(10,95,viewFrame.Width()-55,170);
|
||||||
fPreferredAppBox = new BBox(preferredAppRect,preferredAppLabel,
|
fPreferredAppBox = new BBox(preferredAppRect,preferredAppLabel,
|
||||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM);
|
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM, B_WILL_DRAW);
|
||||||
fPreferredAppBox->SetLabel(preferredAppLabel);
|
fPreferredAppBox->SetLabel(preferredAppLabel);
|
||||||
AddChild(fPreferredAppBox);
|
AddChild(fPreferredAppBox);
|
||||||
|
|
||||||
@@ -48,11 +49,59 @@ FileTypeView::~FileTypeView()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BAppMenuItem : public BMenuItem {
|
||||||
|
private:
|
||||||
|
const char * fMimestr;
|
||||||
|
BAppMenuItem(const char * label)
|
||||||
|
: BMenuItem(label,NULL) {
|
||||||
|
fMimestr = 0;
|
||||||
|
}
|
||||||
|
void SetMime(const char * mimestr) {
|
||||||
|
fMimestr = mimestr;
|
||||||
|
}
|
||||||
|
~BAppMenuItem() {
|
||||||
|
if (fMimestr != Label()) {
|
||||||
|
delete fMimestr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
const char * Mime() {
|
||||||
|
return fMimestr;
|
||||||
|
}
|
||||||
|
static BAppMenuItem * CreateItemForMime(const char * mimestr) {
|
||||||
|
BMimeType mime(mimestr);
|
||||||
|
entry_ref ref;
|
||||||
|
const char * label = mimestr;
|
||||||
|
if (mime.InitCheck() == B_OK) {
|
||||||
|
if (mime.GetAppHint(&ref) == B_OK) {
|
||||||
|
label = ref.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BAppMenuItem * item = new BAppMenuItem(label);
|
||||||
|
item->SetMime(strdup(mimestr));
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypeView::SetFileType(const char * fileType)
|
FileTypeView::SetFileType(const char * fileType)
|
||||||
{
|
{
|
||||||
|
bool fast = (fFileType.Compare(fileType) == 0);
|
||||||
fFileType.SetTo(fileType);
|
fFileType.SetTo(fileType);
|
||||||
fFileTypeTextControl->SetText(fileType);
|
fFileTypeTextControl->SetText(fileType);
|
||||||
|
if (fast)
|
||||||
|
return;
|
||||||
|
BWindow * window = Window();
|
||||||
|
if (window) {
|
||||||
|
window->DisableUpdates();
|
||||||
|
}
|
||||||
|
for (int i = fPreferredAppMenu->CountItems() ; (i > 1) ; i--) {
|
||||||
|
BMenuItem * item = fPreferredAppMenu->ItemAt(i);
|
||||||
|
fPreferredAppMenu->RemoveItem(i);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
BMimeType mime(fileType);
|
BMimeType mime(fileType);
|
||||||
if (mime.InitCheck() != B_OK) {
|
if (mime.InitCheck() != B_OK) {
|
||||||
return;
|
return;
|
||||||
@@ -69,48 +118,47 @@ FileTypeView::SetFileType(const char * fileType)
|
|||||||
if (applications.FindInt32("be:super", &supers) != B_OK) {
|
if (applications.FindInt32("be:super", &supers) != B_OK) {
|
||||||
supers = 0;
|
supers = 0;
|
||||||
}
|
}
|
||||||
for (int i = fPreferredAppMenu->CountItems() ; (i > 2) ; i--) {
|
|
||||||
BMenuItem * item = fPreferredAppMenu->ItemAt(i);
|
|
||||||
fPreferredAppMenu->RemoveItem(i);
|
|
||||||
delete item;
|
|
||||||
}
|
|
||||||
bool separator = false;
|
bool separator = false;
|
||||||
for (int i = 0 ; (i < subs+supers) ; i++) {
|
for (int i = 0 ; (i < subs+supers) ; i++) {
|
||||||
const char * str;
|
const char * str;
|
||||||
if (applications.FindString("applications", i, &str) == B_OK) {
|
if (applications.FindString("applications", i, &str) == B_OK) {
|
||||||
BMimeType app_mime(str);
|
|
||||||
BMessage * message = NULL;
|
|
||||||
entry_ref ref;
|
|
||||||
if (app_mime.InitCheck() == B_OK) {
|
|
||||||
if (app_mime.GetAppHint(&ref) == B_OK) {
|
|
||||||
message = new BMessage();
|
|
||||||
message->AddString("mimetype",str);
|
|
||||||
str = ref.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i < subs) {
|
if (i < subs) {
|
||||||
separator = true;
|
separator = true;
|
||||||
} else if (separator) {
|
} else if (separator) {
|
||||||
fPreferredAppMenu->AddSeparatorItem();
|
fPreferredAppMenu->AddSeparatorItem();
|
||||||
separator = false;
|
separator = false;
|
||||||
}
|
}
|
||||||
fPreferredAppMenu->AddItem(new BMenuItem(str,message));
|
fPreferredAppMenu->AddItem(BAppMenuItem::CreateItemForMime(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (window) {
|
||||||
|
window->EnableUpdates();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FileTypeView::SetPreferredApplication(const char * preferredApplication)
|
FileTypeView::SetPreferredApplication(const char * preferredApplication)
|
||||||
{
|
{
|
||||||
if (preferredApplication == 0) {
|
fPreferredApp.SetTo(preferredApplication);
|
||||||
fPreferredApp.SetTo(preferredApplication);
|
if (preferredApplication == NULL) {
|
||||||
fPreferredAppMenuItemNone->SetMarked(true);
|
fPreferredAppMenuItemNone->SetMarked(true);
|
||||||
} else {
|
} else {
|
||||||
BMenuItem * item = fPreferredAppMenu->FindItem(preferredApplication);
|
for (int i = 0 ; (i < fPreferredAppMenu->CountItems()) ; i++) {
|
||||||
if (item != 0) {
|
BAppMenuItem * item
|
||||||
fPreferredApp.SetTo(preferredApplication);
|
= dynamic_cast<BAppMenuItem*>(fPreferredAppMenu->ItemAt(i));
|
||||||
item->SetMarked(true);
|
if (item) {
|
||||||
|
if ((strcmp(item->Label(),preferredApplication) == 0) ||
|
||||||
|
(strcmp(item->Mime(),preferredApplication) == 0)) {
|
||||||
|
if (!item->IsMarked()) {
|
||||||
|
item->SetMarked(true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BAppMenuItem * item = BAppMenuItem::CreateItemForMime(preferredApplication);
|
||||||
|
fPreferredAppMenu->AddItem(item);
|
||||||
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,12 +183,13 @@ FileTypeView::GetFileType() const
|
|||||||
const char *
|
const char *
|
||||||
FileTypeView::GetPreferredApplication() const
|
FileTypeView::GetPreferredApplication() const
|
||||||
{
|
{
|
||||||
BMenuItem * item = fPreferredAppMenu->FindMarked();
|
BAppMenuItem * item
|
||||||
|
= dynamic_cast<BAppMenuItem*>(fPreferredAppMenu->FindMarked());
|
||||||
if (item == 0) {
|
if (item == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (item == fPreferredAppMenuItemNone) {
|
if (item == fPreferredAppMenuItemNone) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return item->Label();
|
return item->Mime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ FileTypeWindow::SaveRequested()
|
|||||||
{
|
{
|
||||||
status_t result = B_OK;
|
status_t result = B_OK;
|
||||||
|
|
||||||
const char * fileType = fView->GetFileType();
|
BString fileType(fView->GetFileType());
|
||||||
const char * preferredApplication = fView->GetPreferredApplication();
|
BString preferredApplication(fView->GetPreferredApplication());
|
||||||
|
|
||||||
if (fEntryList != 0) {
|
if (fEntryList != 0) {
|
||||||
for (int32 i = 0 ; (i < fEntryList->CountItems()) ; i++) {
|
for (int32 i = 0 ; (i < fEntryList->CountItems()) ; i++) {
|
||||||
@@ -133,17 +133,17 @@ FileTypeWindow::SaveRequested()
|
|||||||
// save errors are ignored: there's usually no good way for the user to recover
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
continue; // can't proceed with an invalid nodeinfo
|
continue; // can't proceed with an invalid nodeinfo
|
||||||
}
|
}
|
||||||
if ((result = nodeInfo.SetType(fileType)) != B_OK) {
|
if ((result = nodeInfo.SetType(fileType.String())) != B_OK) {
|
||||||
// save errors are ignored: there's usually no good way for the user to recover
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
}
|
}
|
||||||
if ((result = nodeInfo.SetPreferredApp(preferredApplication)) != B_OK) {
|
if ((result = nodeInfo.SetPreferredApp(preferredApplication.String())) != B_OK) {
|
||||||
// save errors are ignored: there's usually no good way for the user to recover
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fView->SetFileType(fileType);
|
fView->SetFileType(fileType.String());
|
||||||
fView->SetPreferredApplication(preferredApplication);
|
fView->SetPreferredApplication(preferredApplication.String());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user