round two on FileType app/add-on : ability to open file(s), set and save mime types
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4303 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a749a4600e
commit
a11f505d56
@ -46,7 +46,13 @@ FileTypeApp::RefsReceived(BMessage * message)
|
||||
int32 i;
|
||||
entry_ref ref;
|
||||
while (message->FindRef("refs",i++,&ref) == B_OK) {
|
||||
entryList.AddItem(new BEntry(&ref,true));
|
||||
BEntry * entry = new BEntry(&ref,true);
|
||||
if (!entry || (entry->InitCheck() != B_OK) || (!entry->Exists())) {
|
||||
// ignore bogus refs
|
||||
delete entry;
|
||||
continue;
|
||||
}
|
||||
entryList.AddItem(entry);
|
||||
}
|
||||
if (entryList.CountItems() == 0) {
|
||||
return;
|
||||
@ -62,9 +68,11 @@ FileTypeApp::PrintUsage(const char * execname) {
|
||||
if (execname == 0) {
|
||||
execname = "FileType";
|
||||
}
|
||||
fprintf(stderr,"Usage: %s [FILES]\n",execname);
|
||||
fprintf(stderr,"Usage: %s [OPTIONS] [FILES]\n",execname);
|
||||
fprintf(stderr,"Open a FileType window for the given FILES.\n");
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr," -h, --help print this help\n");
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr,"Report bugs to shatty@myrealbox.com\n");
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
@ -92,15 +100,45 @@ FileTypeApp::ArgvReceived(int32 argc, const char * argv[], const char * cwd)
|
||||
continue;
|
||||
}
|
||||
|
||||
entry_ref ref;
|
||||
if (get_ref_for_path(path.Path(), &ref) != B_OK) {
|
||||
printf("get_ref_for_path failed: \"");
|
||||
printf("%s",path.Path());
|
||||
BEntry * entry = new BEntry(path.Path(),true);
|
||||
if (!entry || (entry->InitCheck() != B_OK)) {
|
||||
printf("failed to allocate BEntry: \"");
|
||||
if (argv[i][0] == '/') {
|
||||
printf("%s",argv[i]);
|
||||
} else {
|
||||
printf("%s/%s",cwd,argv[i]);
|
||||
}
|
||||
printf("\".\n");
|
||||
delete entry;
|
||||
continue;
|
||||
}
|
||||
|
||||
entryList.AddItem(new BEntry(&ref,true));
|
||||
if (!entry->Exists()) {
|
||||
if ((strcmp(argv[i],"-h") == 0) ||
|
||||
(strcmp(argv[i],"-H") == 0) ||
|
||||
(strcmp(argv[i],"-help") == 0) ||
|
||||
(strcmp(argv[i],"--help") == 0)) {
|
||||
void * item;
|
||||
for (int32 i = 0 ; (i < entryList.CountItems()) ; i++) {
|
||||
delete entryList.ItemAt(i);
|
||||
}
|
||||
entryList.MakeEmpty();
|
||||
delete entry;
|
||||
break;
|
||||
} else {
|
||||
printf("file does not exist: \"");
|
||||
if (argv[i][0] == '/') {
|
||||
printf("%s",argv[i]);
|
||||
} else {
|
||||
printf("%s/%s",cwd,argv[i]);
|
||||
}
|
||||
printf("\".\n");
|
||||
delete entry;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
entryList.AddItem(entry);
|
||||
}
|
||||
if (entryList.CountItems() == 0) {
|
||||
PrintUsage(argv[0]);
|
||||
@ -111,6 +149,7 @@ FileTypeApp::ArgvReceived(int32 argc, const char * argv[], const char * cwd)
|
||||
printf("Failed to create FileTypeWindow\n");
|
||||
return;
|
||||
}
|
||||
fWindow = window;
|
||||
fArgvOkay = true;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,6 @@ private:
|
||||
bool fArgvOkay;
|
||||
};
|
||||
|
||||
extern FileTypeApp * file_types_app;
|
||||
extern FileTypeApp * file_type_app;
|
||||
|
||||
#endif // FILE_TYPE_APP
|
||||
|
@ -1,14 +1,46 @@
|
||||
#include <MenuItem.h>
|
||||
|
||||
#include <FileTypeView.h>
|
||||
|
||||
FileTypeView::FileTypeView(BRect viewFrame)
|
||||
: BView(viewFrame, "FileTypeView", B_FOLLOW_ALL,
|
||||
B_FRAME_EVENTS|B_WILL_DRAW)
|
||||
{
|
||||
fFileTypeBox = new BBox(BRect(25,25,325,175),"File Type");
|
||||
SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
|
||||
|
||||
const char * fileTypeLabel = "File Type";
|
||||
BRect fileTypeRect(10,10,viewFrame.Width()-55,90);
|
||||
fFileTypeBox = new BBox(fileTypeRect,fileTypeLabel,
|
||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP);
|
||||
fFileTypeBox->SetLabel(fileTypeLabel);
|
||||
AddChild(fFileTypeBox);
|
||||
|
||||
fPreferredApplicationBox = new BBox(BRect(25,225,325,375),"Preferred Application");
|
||||
AddChild(fPreferredApplicationBox);
|
||||
BRect fileTypeTextControlRect(10,18,fileTypeRect.Width()-10,fileTypeRect.Height());
|
||||
fFileTypeTextControl = new BTextControl(fileTypeTextControlRect,"mime",
|
||||
NULL,NULL,NULL,
|
||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP);
|
||||
fFileTypeBox->AddChild(fFileTypeTextControl);
|
||||
|
||||
const char * preferredAppLabel = "Preferred Application";
|
||||
BRect preferredAppRect(10,95,viewFrame.Width()-55,170);
|
||||
fPreferredAppBox = new BBox(preferredAppRect,preferredAppLabel,
|
||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_BOTTOM);
|
||||
fPreferredAppBox->SetLabel(preferredAppLabel);
|
||||
AddChild(fPreferredAppBox);
|
||||
|
||||
fPreferredAppMenu = new BMenu("app");
|
||||
fPreferredAppMenuItemNone = new BMenuItem("None",NULL);
|
||||
fPreferredAppMenu->AddItem(fPreferredAppMenuItemNone);
|
||||
fPreferredAppMenu->AddSeparatorItem();
|
||||
fPreferredAppMenu->SetRadioMode(true);
|
||||
fPreferredAppMenu->SetLabelFromMarked(true);
|
||||
fPreferredAppMenuItemNone->SetMarked(true);
|
||||
|
||||
BRect preferredAppMenuFieldRect(10,15,preferredAppRect.Width()-10,
|
||||
preferredAppRect.Height());
|
||||
fPreferredAppMenuField = new BMenuField(preferredAppMenuFieldRect,
|
||||
"appField",NULL,fPreferredAppMenu);
|
||||
fPreferredAppBox->AddChild(fPreferredAppMenuField);
|
||||
}
|
||||
|
||||
FileTypeView::~FileTypeView()
|
||||
@ -19,14 +51,22 @@ void
|
||||
FileTypeView::SetFileType(const char * fileType)
|
||||
{
|
||||
fFileType.SetTo(fileType);
|
||||
// change UI
|
||||
fFileTypeTextControl->SetText(fileType);
|
||||
}
|
||||
|
||||
void
|
||||
FileTypeView::SetPreferredApplication(const char * preferredApplication)
|
||||
{
|
||||
fPreferredApplication.SetTo(preferredApplication);
|
||||
// change UI
|
||||
if (preferredApplication == 0) {
|
||||
fPreferredApp.SetTo(preferredApplication);
|
||||
fPreferredAppMenuItemNone->SetMarked(true);
|
||||
} else {
|
||||
BMenuItem * item = fPreferredAppMenu->FindItem(preferredApplication);
|
||||
if (item != 0) {
|
||||
fPreferredApp.SetTo(preferredApplication);
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@ -35,7 +75,7 @@ FileTypeView::IsClean() const
|
||||
if (fFileType.Compare(GetFileType()) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (fPreferredApplication.Compare(GetPreferredApplication()) != 0) {
|
||||
if (fPreferredApp.Compare(GetPreferredApplication()) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -44,13 +84,18 @@ FileTypeView::IsClean() const
|
||||
const char *
|
||||
FileTypeView::GetFileType() const
|
||||
{
|
||||
// return from UI
|
||||
return "";
|
||||
return fFileTypeTextControl->Text();
|
||||
}
|
||||
|
||||
const char *
|
||||
FileTypeView::GetPreferredApplication() const
|
||||
{
|
||||
// return from UI
|
||||
return "";
|
||||
BMenuItem * item = fPreferredAppMenu->FindMarked();
|
||||
if (item == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (item == fPreferredAppMenuItemNone) {
|
||||
return 0;
|
||||
}
|
||||
return item->Label();
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <MenuField.h>
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
#include <View.h>
|
||||
|
||||
class FileTypeView : public BView {
|
||||
@ -20,16 +21,18 @@ public:
|
||||
const char * GetPreferredApplication() const;
|
||||
private:
|
||||
BString fFileType;
|
||||
BString fPreferredApplication;
|
||||
BString fPreferredApp;
|
||||
|
||||
BBox * fFileTypeBox;
|
||||
BTextView * fFileTypeTextView;
|
||||
BButton * fFileTypeSelectButton;
|
||||
BButton * fFileTypeSameAsButton;
|
||||
BBox * fPreferredApplicationBox;
|
||||
BPopUpMenu * fPreferredApplicationMenu;
|
||||
BButton * fPreferredApplicationSelectButton;
|
||||
BButton * fPreferredApplicationSameAsButton;
|
||||
BBox * fFileTypeBox;
|
||||
BTextControl * fFileTypeTextControl;
|
||||
BButton * fFileTypeSelectButton;
|
||||
BButton * fFileTypeSameAsButton;
|
||||
BBox * fPreferredAppBox;
|
||||
BMenu * fPreferredAppMenu;
|
||||
BMenuItem * fPreferredAppMenuItemNone;
|
||||
BMenuField * fPreferredAppMenuField;
|
||||
BButton * fPreferredAppSelectButton;
|
||||
BButton * fPreferredAppSameAsButton;
|
||||
};
|
||||
|
||||
#endif // FILE_TYPE_VIEW_H
|
||||
|
@ -1,14 +1,16 @@
|
||||
#include <Alert.h>
|
||||
#include <Autolock.h>
|
||||
#include <Debug.h>
|
||||
#include <Entry.h>
|
||||
#include <Node.h>
|
||||
#include <NodeInfo.h>
|
||||
|
||||
#include <FileTypeApp.h>
|
||||
#include <FileTypeView.h>
|
||||
#include <FileTypeWindow.h>
|
||||
|
||||
FileTypeWindow::FileTypeWindow(const BList * entryList)
|
||||
: BWindow(BRect(250,150,350,400),"File Type",B_TITLED_WINDOW,
|
||||
: BWindow(BRect(100,100,380,300),"File Type",B_TITLED_WINDOW,
|
||||
B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS)
|
||||
{
|
||||
initStatus = B_ERROR;
|
||||
@ -69,6 +71,18 @@ FileTypeWindow::MessageReceived(BMessage * message)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FileTypeWindow::Quit()
|
||||
{
|
||||
{
|
||||
// This is in its own scope because it must be released
|
||||
// before the call to BWindow::Quit()
|
||||
BAutolock lock(file_type_app);
|
||||
file_type_app->Quit();
|
||||
}
|
||||
BWindow::Quit();
|
||||
}
|
||||
|
||||
bool
|
||||
FileTypeWindow::QuitRequested()
|
||||
{
|
||||
@ -96,7 +110,7 @@ FileTypeWindow::QuitRequested()
|
||||
} else {
|
||||
// save errors are ignored: there's usually no good way for the user to recover
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status_t
|
||||
@ -127,6 +141,9 @@ FileTypeWindow::SaveRequested()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fView->SetFileType(fileType);
|
||||
fView->SetPreferredApplication(preferredApplication);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
FileTypeWindow(const BList * entryList);
|
||||
~FileTypeWindow();
|
||||
|
||||
virtual void Quit();
|
||||
virtual bool QuitRequested();
|
||||
virtual void MessageReceived(BMessage * message);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user