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:
shatty 2003-08-18 08:30:32 +00:00
parent a749a4600e
commit a11f505d56
6 changed files with 136 additions and 31 deletions

View File

@ -46,7 +46,13 @@ FileTypeApp::RefsReceived(BMessage * message)
int32 i; int32 i;
entry_ref ref; entry_ref ref;
while (message->FindRef("refs",i++,&ref) == B_OK) { 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) { if (entryList.CountItems() == 0) {
return; return;
@ -62,9 +68,11 @@ FileTypeApp::PrintUsage(const char * execname) {
if (execname == 0) { if (execname == 0) {
execname = "FileType"; 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,"Open a FileType window for the given FILES.\n");
fprintf(stderr,"\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,"Report bugs to shatty@myrealbox.com\n");
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
@ -92,15 +100,45 @@ FileTypeApp::ArgvReceived(int32 argc, const char * argv[], const char * cwd)
continue; continue;
} }
entry_ref ref; BEntry * entry = new BEntry(path.Path(),true);
if (get_ref_for_path(path.Path(), &ref) != B_OK) { if (!entry || (entry->InitCheck() != B_OK)) {
printf("get_ref_for_path failed: \""); printf("failed to allocate BEntry: \"");
printf("%s",path.Path()); if (argv[i][0] == '/') {
printf("%s",argv[i]);
} else {
printf("%s/%s",cwd,argv[i]);
}
printf("\".\n"); printf("\".\n");
delete entry;
continue; 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) { if (entryList.CountItems() == 0) {
PrintUsage(argv[0]); PrintUsage(argv[0]);
@ -111,6 +149,7 @@ FileTypeApp::ArgvReceived(int32 argc, const char * argv[], const char * cwd)
printf("Failed to create FileTypeWindow\n"); printf("Failed to create FileTypeWindow\n");
return; return;
} }
fWindow = window;
fArgvOkay = true; fArgvOkay = true;
} }

View File

@ -27,6 +27,6 @@ private:
bool fArgvOkay; bool fArgvOkay;
}; };
extern FileTypeApp * file_types_app; extern FileTypeApp * file_type_app;
#endif // FILE_TYPE_APP #endif // FILE_TYPE_APP

View File

@ -1,14 +1,46 @@
#include <MenuItem.h>
#include <FileTypeView.h> #include <FileTypeView.h>
FileTypeView::FileTypeView(BRect viewFrame) FileTypeView::FileTypeView(BRect viewFrame)
: BView(viewFrame, "FileTypeView", B_FOLLOW_ALL, : BView(viewFrame, "FileTypeView", B_FOLLOW_ALL,
B_FRAME_EVENTS|B_WILL_DRAW) 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); AddChild(fFileTypeBox);
fPreferredApplicationBox = new BBox(BRect(25,225,325,375),"Preferred Application"); BRect fileTypeTextControlRect(10,18,fileTypeRect.Width()-10,fileTypeRect.Height());
AddChild(fPreferredApplicationBox); 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() FileTypeView::~FileTypeView()
@ -19,14 +51,22 @@ void
FileTypeView::SetFileType(const char * fileType) FileTypeView::SetFileType(const char * fileType)
{ {
fFileType.SetTo(fileType); fFileType.SetTo(fileType);
// change UI fFileTypeTextControl->SetText(fileType);
} }
void void
FileTypeView::SetPreferredApplication(const char * preferredApplication) FileTypeView::SetPreferredApplication(const char * preferredApplication)
{ {
fPreferredApplication.SetTo(preferredApplication); if (preferredApplication == 0) {
// change UI fPreferredApp.SetTo(preferredApplication);
fPreferredAppMenuItemNone->SetMarked(true);
} else {
BMenuItem * item = fPreferredAppMenu->FindItem(preferredApplication);
if (item != 0) {
fPreferredApp.SetTo(preferredApplication);
item->SetMarked(true);
}
}
} }
bool bool
@ -35,7 +75,7 @@ FileTypeView::IsClean() const
if (fFileType.Compare(GetFileType()) != 0) { if (fFileType.Compare(GetFileType()) != 0) {
return false; return false;
} }
if (fPreferredApplication.Compare(GetPreferredApplication()) != 0) { if (fPreferredApp.Compare(GetPreferredApplication()) != 0) {
return false; return false;
} }
return true; return true;
@ -44,13 +84,18 @@ FileTypeView::IsClean() const
const char * const char *
FileTypeView::GetFileType() const FileTypeView::GetFileType() const
{ {
// return from UI return fFileTypeTextControl->Text();
return "";
} }
const char * const char *
FileTypeView::GetPreferredApplication() const FileTypeView::GetPreferredApplication() const
{ {
// return from UI BMenuItem * item = fPreferredAppMenu->FindMarked();
return ""; if (item == 0) {
return 0;
}
if (item == fPreferredAppMenuItemNone) {
return 0;
}
return item->Label();
} }

View File

@ -3,8 +3,9 @@
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <PopUpMenu.h> #include <MenuField.h>
#include <String.h> #include <String.h>
#include <TextControl.h>
#include <View.h> #include <View.h>
class FileTypeView : public BView { class FileTypeView : public BView {
@ -20,16 +21,18 @@ public:
const char * GetPreferredApplication() const; const char * GetPreferredApplication() const;
private: private:
BString fFileType; BString fFileType;
BString fPreferredApplication; BString fPreferredApp;
BBox * fFileTypeBox; BBox * fFileTypeBox;
BTextView * fFileTypeTextView; BTextControl * fFileTypeTextControl;
BButton * fFileTypeSelectButton; BButton * fFileTypeSelectButton;
BButton * fFileTypeSameAsButton; BButton * fFileTypeSameAsButton;
BBox * fPreferredApplicationBox; BBox * fPreferredAppBox;
BPopUpMenu * fPreferredApplicationMenu; BMenu * fPreferredAppMenu;
BButton * fPreferredApplicationSelectButton; BMenuItem * fPreferredAppMenuItemNone;
BButton * fPreferredApplicationSameAsButton; BMenuField * fPreferredAppMenuField;
BButton * fPreferredAppSelectButton;
BButton * fPreferredAppSameAsButton;
}; };
#endif // FILE_TYPE_VIEW_H #endif // FILE_TYPE_VIEW_H

View File

@ -1,14 +1,16 @@
#include <Alert.h> #include <Alert.h>
#include <Autolock.h>
#include <Debug.h> #include <Debug.h>
#include <Entry.h> #include <Entry.h>
#include <Node.h> #include <Node.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <FileTypeApp.h>
#include <FileTypeView.h> #include <FileTypeView.h>
#include <FileTypeWindow.h> #include <FileTypeWindow.h>
FileTypeWindow::FileTypeWindow(const BList * entryList) 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) B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS)
{ {
initStatus = B_ERROR; 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 bool
FileTypeWindow::QuitRequested() FileTypeWindow::QuitRequested()
{ {
@ -127,6 +141,9 @@ FileTypeWindow::SaveRequested()
} }
} }
} }
fView->SetFileType(fileType);
fView->SetPreferredApplication(preferredApplication);
return result; return result;
} }

View File

@ -16,6 +16,7 @@ public:
FileTypeWindow(const BList * entryList); FileTypeWindow(const BList * entryList);
~FileTypeWindow(); ~FileTypeWindow();
virtual void Quit();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage * message); virtual void MessageReceived(BMessage * message);