* You can now also select the preferred application using the "Select..." and

"Same As..." buttons and a file panel.
* The preferred application of a file type is now also displayed correctly if
  it's not part of the list of supporting applications.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16389 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-02-14 02:07:47 +00:00
parent 8d577b370f
commit 43fd6fc453
4 changed files with 132 additions and 13 deletions

View File

@ -51,7 +51,8 @@ FileTypes::FileTypes()
fTypesWindow(NULL),
fWindowCount(0)
{
fFilePanel = new BFilePanel();
fFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
B_FILE_NODE | B_DIRECTORY_NODE, false);
fTypesWindowFrame = BRect(80.0f, 80.0f, 600.0f, 480.0f);
// TODO: read from settings
}
@ -162,8 +163,38 @@ FileTypes::MessageReceived(BMessage *message)
break;
case kMsgOpenFilePanel:
fFilePanel->Show();
// the open file panel sends us a message when it's done
fFilePanel->Window()->SetTitle("Open File");
fFilePanel->SetMessage(new BMessage(B_REFS_RECEIVED));
if (!fFilePanel->IsShowing())
fFilePanel->Show();
break;
case kMsgOpenSelectPanel:
fFilePanel->Window()->SetTitle("Select Preferred Application");
fFilePanel->SetMessage(new BMessage(kMsgPreferredAppOpened));
if (!fFilePanel->IsShowing())
fFilePanel->Show();
break;
case kMsgPreferredAppOpened:
if (fTypesWindow != NULL)
fTypesWindow->PostMessage(message);
break;
case kMsgOpenSameAsPanel:
fFilePanel->Window()->SetTitle("Select Same Preferred Application As");
fFilePanel->SetMessage(new BMessage(kMsgSamePreferredAppAsOpened));
if (!fFilePanel->IsShowing())
fFilePanel->Show();
break;
case kMsgSamePreferredAppAsOpened:
if (fTypesWindow != NULL)
fTypesWindow->PostMessage(message);
break;
case B_CANCEL:
if (fWindowCount == 0)
PostMessage(B_QUIT_REQUESTED);

View File

@ -12,6 +12,9 @@
extern const char* kSignature;
static const uint32 kMsgOpenFilePanel = 'opFp';
static const uint32 kMsgOpenSelectPanel = 'opSp';
static const uint32 kMsgOpenSameAsPanel = 'opAp';
static const uint32 kMsgOpenTypesWindow = 'opTw';
static const uint32 kMsgTypesWindowClosed = 'clTw';
static const uint32 kMsgWindowClosed = 'WiCl';

View File

@ -9,6 +9,7 @@
#include "MimeTypeListView.h"
#include <Alert.h>
#include <AppFileInfo.h>
#include <Application.h>
#include <Bitmap.h>
#include <Box.h>
@ -18,6 +19,7 @@
#include <MenuField.h>
#include <MenuItem.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <OutlineListView.h>
#include <PopUpMenu.h>
#include <ScrollView.h>
@ -761,6 +763,56 @@ FileTypesWindow::_UpdateExtensions(BMimeType* type)
}
void
FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
{
if (fCurrentType.Type() == NULL)
return;
entry_ref ref;
if (message->FindRef("refs", &ref) != B_OK)
return;
// TODO: add error reporting!
BFile file(&ref, B_READ_ONLY);
if (file.InitCheck() != B_OK)
return;
char preferred[B_MIME_TYPE_LENGTH];
if (sameAs) {
// get preferred app from file
BNodeInfo nodeInfo(&file);
if (nodeInfo.InitCheck() != B_OK)
return;
if (nodeInfo.GetPreferredApp(preferred) != B_OK)
preferred[0] = '\0';
if (!preferred[0]) {
// get MIME type from file
char type[B_MIME_TYPE_LENGTH];
if (nodeInfo.GetType(type) == B_OK) {
BMimeType mimeType(type);
mimeType.GetPreferredApp(preferred);
}
}
} else {
// get application signature
BAppFileInfo appInfo(&file);
if (appInfo.InitCheck() != B_OK)
return;
if (appInfo.GetSignature(preferred) != B_OK)
preferred[0] = '\0';
}
if (preferred[0])
fCurrentType.SetPreferredApp(preferred);
}
void
FileTypesWindow::_AddSignature(BMenuItem* item, const char* signature)
{
@ -775,6 +827,22 @@ FileTypesWindow::_AddSignature(BMenuItem* item, const char* signature)
}
BMenuItem*
FileTypesWindow::_CreateApplicationItem(const char* signature)
{
char name[B_FILE_NAME_LENGTH];
BMessage* message = new BMessage(kMsgPreferredAppChosen);
message->AddString("signature", signature);
BMimeType applicationType(signature);
if (applicationType.GetShortDescription(name) == B_OK)
return new BMenuItem(name, message);
return new BMenuItem(signature, message);
}
void
FileTypesWindow::_UpdatePreferredApps(BMimeType* type)
{
@ -807,17 +875,7 @@ FileTypesWindow::_UpdatePreferredApps(BMimeType* type)
const char* signature;
int32 i = 0;
while (applications.FindString("applications", i, &signature) == B_OK) {
char name[B_FILE_NAME_LENGTH];
BMenuItem *item;
BMessage* message = new BMessage(kMsgPreferredAppChosen);
message->AddString("signature", signature);
BMimeType applicationType(signature);
if (applicationType.GetShortDescription(name) == B_OK)
item = new BMenuItem(name, message);
else
item = new BMenuItem(signature, message);
BMenuItem* item = _CreateApplicationItem(signature);
if (i < lastFullSupport)
subList.AddItem(item);
@ -892,6 +950,14 @@ FileTypesWindow::_UpdatePreferredApps(BMimeType* type)
// We don't select the item earlier, so that the menu field can
// pick up the signature as well as label.
select->SetMarked(true);
} else if (preferred[0]) {
// The preferred application is not an application that support
// this file type!
BMenuItem* item = _CreateApplicationItem(preferred);
menu->AddSeparatorItem();
menu->AddItem(item);
item->SetMarked(item);
}
}
@ -1079,6 +1145,20 @@ FileTypesWindow::MessageReceived(BMessage* message)
break;
}
case kMsgSelectPreferredApp:
be_app->PostMessage(kMsgOpenSelectPanel);
break;
case kMsgPreferredAppOpened:
_AdoptPreferredApplication(message, false);
break;
case kMsgSamePreferredAppAs:
be_app->PostMessage(kMsgOpenSameAsPanel);
break;
case kMsgSamePreferredAppAsOpened:
_AdoptPreferredApplication(message, true);
break;
// Extra Attributes group
case kMsgAttributeSelected:

View File

@ -31,7 +31,9 @@ class FileTypesWindow : public BWindow {
private:
void _UpdateExtensions(BMimeType* type);
void _AdoptPreferredApplication(BMessage* message, bool sameAs);
void _AddSignature(BMenuItem* item, const char* signature);
BMenuItem* _CreateApplicationItem(const char* signature);
void _UpdatePreferredApps(BMimeType* type);
void _UpdateIcon(BMimeType* type);
void _SetType(BMimeType* type, int32 forceUpdate = 0);
@ -62,4 +64,7 @@ class FileTypesWindow : public BWindow {
};
static const uint32 kMsgPreferredAppOpened = 'paOp';
static const uint32 kMsgSamePreferredAppAsOpened = 'spaO';
#endif // FILE_TYPES_WINDOW_H