first cut
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4292 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
#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");
|
||||||
|
AddChild(fFileTypeBox);
|
||||||
|
|
||||||
|
fPreferredApplicationBox = new BBox(BRect(25,225,325,375),"Preferred Application");
|
||||||
|
AddChild(fPreferredApplicationBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileTypeView::~FileTypeView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypeView::SetFileType(const char * fileType)
|
||||||
|
{
|
||||||
|
fFileType.SetTo(fileType);
|
||||||
|
// change UI
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypeView::SetPreferredApplication(const char * preferredApplication)
|
||||||
|
{
|
||||||
|
fPreferredApplication.SetTo(preferredApplication);
|
||||||
|
// change UI
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
FileTypeView::Clean()
|
||||||
|
{
|
||||||
|
if (fFileType.Compare(GetFileType()) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fPreferredApplication.Compare(GetPreferredApplication()) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
FileTypeView::GetFileType()
|
||||||
|
{
|
||||||
|
// return from UI
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
FileTypeView::GetPreferredApplication()
|
||||||
|
{
|
||||||
|
// return from UI
|
||||||
|
return "";
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef FILE_TYPE_VIEW_H
|
||||||
|
#define FILE_TYPE_VIEW_H
|
||||||
|
|
||||||
|
#include <Box.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
class FileTypeView : public BView {
|
||||||
|
public:
|
||||||
|
FileTypeView(BRect viewFrame);
|
||||||
|
~FileTypeView();
|
||||||
|
|
||||||
|
void SetFileType(const char * fileType);
|
||||||
|
void SetPreferredApplication(const char * preferredApplication);
|
||||||
|
|
||||||
|
bool Clean() const;
|
||||||
|
const char * GetFileType() const;
|
||||||
|
const char * GetPreferredApplication() const;
|
||||||
|
private:
|
||||||
|
BString fFileType;
|
||||||
|
BString fPreferredApplication;
|
||||||
|
|
||||||
|
BBox * fFileTypeBox;
|
||||||
|
BTextView * fFileTypeTextView;
|
||||||
|
BButton * fFileTypeSelectButton;
|
||||||
|
BButton * fFileTypeSameAsButton;
|
||||||
|
BBox * fPreferredApplicationBox;
|
||||||
|
BPopUpMenu * fPreferredApplicationMenu;
|
||||||
|
BButton * fPreferredApplicationSelectButton;
|
||||||
|
BButton * fPreferredApplicationSameAsButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILE_TYPE_VIEW_H
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
#include <Debug.h>
|
||||||
|
|
||||||
|
#include <FileTypeView.h>
|
||||||
|
#include <FileTypeWindow.h>
|
||||||
|
|
||||||
|
FileTypeWindow::FileTypeWindow(BEntryList entries)
|
||||||
|
: BWindow(BRect(250,150,350,400),"File Type",B_TITLED_WINDOW,
|
||||||
|
B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
{
|
||||||
|
fMenuBar = new BMenuBar(BRect(0,0,0,0),"menubar");
|
||||||
|
AddChild(fMenuBar);
|
||||||
|
|
||||||
|
BRect viewFrame = Bounds();
|
||||||
|
viewFrame.top = fMenuBar->Bounds().Height()+1;
|
||||||
|
fView = new FileTypeView(viewFrame);
|
||||||
|
AddChild(fView);
|
||||||
|
fView->MakeFocus(true);
|
||||||
|
|
||||||
|
fFileMenu = new BMenu("File");
|
||||||
|
fMenuBar->AddItem(fFileMenu);
|
||||||
|
fSaveItem = new BMenuItem("Save",new BMessage(B_SAVE_REQUESTED), 'S');
|
||||||
|
fFileMenu->AddItem(fSaveItem);
|
||||||
|
fFileMenu->AddSeperator();
|
||||||
|
fCloseItem = new BMenuItem("Close",new BMessage(B_QUIT_REQUESTED), 'W');
|
||||||
|
fFileMenu->AddItem(fCloseItem);
|
||||||
|
|
||||||
|
SetEntries(entries);
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileTypeWindow::~FileTypeWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypeWindow::MessageReceived(BMessage *message)
|
||||||
|
{
|
||||||
|
switch(message->what){
|
||||||
|
case B_SAVE_REQUESTED:
|
||||||
|
SaveRequested();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
FileTypeWindow::QuitRequested()
|
||||||
|
{
|
||||||
|
if (fView->Clean()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BAlert * saveAlert;
|
||||||
|
BString alertText("Would you like to save changes to file type attributes of ");
|
||||||
|
alertText << SummarizeEntries();
|
||||||
|
alertText << "? ";
|
||||||
|
saveAlert = new BAlert("savealert",alertText.String(), "Cancel", "Don't Save","Save",
|
||||||
|
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
|
||||||
|
saveAlert->SetShortcut(0, B_ESCAPE);
|
||||||
|
saveAlert->SetShortcut(1,'d');
|
||||||
|
saveAlert->SetShortcut(2,'s');
|
||||||
|
buttonIndex = saveAlert->Go();
|
||||||
|
|
||||||
|
if (buttonIndex==0) { //"cancel": dont save, dont close the window
|
||||||
|
return false;
|
||||||
|
} else if (buttonIndex==1) { // "don't save": just close the window
|
||||||
|
return true;
|
||||||
|
} else if (SaveRequested() == B_OK) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t
|
||||||
|
FileTypeWindow::SaveRequested(BMessage * message)
|
||||||
|
{
|
||||||
|
status_t result = B_OK;
|
||||||
|
|
||||||
|
const char * fileType = fView->GetFileType();
|
||||||
|
const char * preferredApplication = fView->GetPreferredApplication();
|
||||||
|
|
||||||
|
if ((result = fEntries->Rewind()) != B_OK) {
|
||||||
|
return result; // can't proceed with no entries
|
||||||
|
}
|
||||||
|
BEntry entry;
|
||||||
|
while (fEntries->GetNextEntry(&entry,true) != B_OK) {
|
||||||
|
BNode node(&entry);
|
||||||
|
if ((result = node.InitCheck()) != B_OK) {
|
||||||
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
|
continue; // can't proceed with an invalid node
|
||||||
|
}
|
||||||
|
BNodeInfo nodeInfo(&node);
|
||||||
|
if ((result = nodeInfo.InitCheck()) != B_OK) {
|
||||||
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
|
continue; // can't proceed with an invalid nodeinfo
|
||||||
|
}
|
||||||
|
if ((result = nodeInfo.SetType(fileType)) != B_OK) {
|
||||||
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
|
}
|
||||||
|
if ((result = nodeInfo.SetPreferredApp(preferredApplication)) != B_OK) {
|
||||||
|
// save errors are ignored: there's usually no good way for the user to recover
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FileTypeWindow::SetEntries(BEntryList entries)
|
||||||
|
{
|
||||||
|
fEntries = entries;
|
||||||
|
|
||||||
|
BString title = SummarizeEntries();
|
||||||
|
title.Append(" File Type");
|
||||||
|
SetTitle(title);
|
||||||
|
|
||||||
|
if (fEntries->Rewind() != B_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BString * fileType = 0;
|
||||||
|
BString * preferredApplication = 0;
|
||||||
|
BEntry entry;
|
||||||
|
while (fEntries->GetNextEntry(&entry,true) != B_OK) {
|
||||||
|
BNode node(&entry);
|
||||||
|
if ((result = node.InitCheck()) != B_OK) {
|
||||||
|
// errors are ignored: there's usually no good way for the user to recover
|
||||||
|
continue; // can't proceed with an invalid node
|
||||||
|
}
|
||||||
|
BNodeInfo nodeInfo(&node);
|
||||||
|
if ((result = nodeInfo.InitCheck()) != B_OK) {
|
||||||
|
// errors are ignored: there's usually no good way for the user to recover
|
||||||
|
continue; // can't proceed with an invalid nodeinfo
|
||||||
|
}
|
||||||
|
char string[MAXPATHLEN];
|
||||||
|
if ((result = nodeInfo.GetType(string)) != B_OK) {
|
||||||
|
// errors are ignored: there's usually no good way for the user to recover
|
||||||
|
} else {
|
||||||
|
if (fileType == 0) {
|
||||||
|
fileType = new BString(string);
|
||||||
|
} else if (fileType->Compare(string) != 0) {
|
||||||
|
fileType.SetTo("");
|
||||||
|
if (preferredApplication && (preferredApplication->Length() == 0)) {
|
||||||
|
break; // stop now, don't waste time checking the rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((result = nodeInfo.GetPreferredApp(string)) != B_OK) {
|
||||||
|
// errors are ignored: there's usually no good way for the user to recover
|
||||||
|
} else {
|
||||||
|
if (preferredApplication == 0) {
|
||||||
|
preferredApplication = new BString(string);
|
||||||
|
} else if (preferredApplication->Compare(string) != 0) {
|
||||||
|
preferredApplication.SetTo("");
|
||||||
|
if (fileType && (fileType->Length() == 0)) {
|
||||||
|
break; // stop now, don't waste time checking the rest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fView->SetFileType(fileType.String());
|
||||||
|
fView->SetPreferredApplication(preferredApplication.String());
|
||||||
|
delete fileType;
|
||||||
|
delete preferredApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
FileTypeWindow::SummarizeEntries()
|
||||||
|
{
|
||||||
|
if (fEntries->Rewind() != B_OK) {
|
||||||
|
return "<error>";
|
||||||
|
}
|
||||||
|
const char * result = "";
|
||||||
|
dirent dent;
|
||||||
|
if (fEntries->GetNextDirents(&dent,sizeof(dirent),1) != 0) {
|
||||||
|
result = strdup(dent.d_name);
|
||||||
|
if (fEntries->GetNextDirents(&dent,sizeof(dirent),1) != 0) {
|
||||||
|
result = "[Multiple Files]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef FILE_TYPE_WINDOW_H
|
||||||
|
#define FILE_TYPE_WINDOW_H
|
||||||
|
|
||||||
|
#include <EntryList.h>
|
||||||
|
#include <List.h>
|
||||||
|
#include <MenuBar.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
class FileTypeView;
|
||||||
|
|
||||||
|
class FileTypeWindow
|
||||||
|
: public BWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileTypeWindow(BEntryList entries);
|
||||||
|
~FileTypeWindow();
|
||||||
|
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
virtual void MessageReceived(BMessage * message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t SaveRequested();
|
||||||
|
void SetEntries(BEntryList entries);
|
||||||
|
const char * SummarizeEntries();
|
||||||
|
|
||||||
|
BMenuBar *fMenuBar;
|
||||||
|
BMenu *fFileMenu;
|
||||||
|
BMenuItem *fSaveItem;
|
||||||
|
BMenuItem *fCloseItem;
|
||||||
|
|
||||||
|
FileTypeView *fView;
|
||||||
|
|
||||||
|
BEntryList fEntries;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILE_TYPE_WINDOW_H
|
||||||
Reference in New Issue
Block a user