removed FileType code files and a few minor cleanups
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4304 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
#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::IsClean() const
|
||||
{
|
||||
if (fFileType.Compare(GetFileType()) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (fPreferredApplication.Compare(GetPreferredApplication()) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *
|
||||
FileTypeView::GetFileType() const
|
||||
{
|
||||
// return from UI
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *
|
||||
FileTypeView::GetPreferredApplication() const
|
||||
{
|
||||
// return from UI
|
||||
return "";
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#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 IsClean() 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
|
||||
@@ -1,191 +0,0 @@
|
||||
#include <Alert.h>
|
||||
#include <Debug.h>
|
||||
#include <Entry.h>
|
||||
#include <Node.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(strdup(title.String()));
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fileType != 0) {
|
||||
fView->SetFileType(fileType->String());
|
||||
delete fileType;
|
||||
}
|
||||
if (preferredApplication != 0) {
|
||||
fView->SetPreferredApplication(preferredApplication->String());
|
||||
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;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#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
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <Path.h>
|
||||
#include <Roster.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Constants.h>
|
||||
#include <FileTypesConstants.h>
|
||||
#include <FileTypesApp.h>
|
||||
#include <FileTypesWindow.h>
|
||||
|
||||
@@ -68,6 +70,7 @@ FileTypesApp::RefsReceived(BMessage *message)
|
||||
void
|
||||
FileTypesApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
|
||||
{
|
||||
BMessage refsReceived(B_REFS_RECEIVED);
|
||||
for (int i = 1 ; (i < argc) ; i++) {
|
||||
BPath path;
|
||||
if (argv[i][0] == '/') {
|
||||
@@ -93,14 +96,26 @@ FileTypesApp::ArgvReceived(int32 argc, const char *argv[], const char * cwd)
|
||||
printf("\".\n");
|
||||
continue;
|
||||
}
|
||||
OpenDocument(&ref);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FileTypesApp::ReadyToRun()
|
||||
{
|
||||
if (fWindowCount == 0) {
|
||||
OpenDocument();
|
||||
if (!fArgvOkay) {
|
||||
Quit();
|
||||
return;
|
||||
}
|
||||
if (fWindow == 0) {
|
||||
OpenPanel()->Show();
|
||||
}
|
||||
}
|
||||
|
||||
BFilePanel *
|
||||
FileTypesApp::OpenPanel()
|
||||
{
|
||||
if (fOpenPanel == 0) {
|
||||
fOpenPanel = new BFilePanel(B_OPEN_PANEL);
|
||||
}
|
||||
return fOpenPanel;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,12 @@ public:
|
||||
virtual void DispatchMessage(BMessage *an_event, BHandler *handler);
|
||||
|
||||
private:
|
||||
BFilePanel * fOpenPanel;
|
||||
BFilePanel * OpenPanel();
|
||||
|
||||
FileTypesWindow * fWindow;
|
||||
BFilePanel * fOpenPanel;
|
||||
|
||||
bool fArgvOkay;
|
||||
};
|
||||
|
||||
extern FileTypesApp * file_types_app;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FILE_TYPES_VIEW_H
|
||||
#define FILE_TYPES_VIEW_H
|
||||
|
||||
#include <BView.h>
|
||||
#include <View.h>
|
||||
|
||||
class FileTypesView : public BView {
|
||||
public:
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
|
||||
#include <FileTypeWindow.h>
|
||||
#include <FileTypeView.h>
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ Preference FileTypes :
|
||||
FileTypesApp.cpp
|
||||
FileTypesView.cpp
|
||||
FileTypesWindow.cpp
|
||||
FileTypeView.cpp
|
||||
FileTypeWindow.cpp
|
||||
;
|
||||
|
||||
LinkSharedOSLibs FileTypes : be ;
|
||||
LinkSharedOSLibs FileTypes : be tracker ;
|
||||
|
||||
Reference in New Issue
Block a user