added AppType window for when a single application is selected

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4306 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
shatty 2003-08-18 22:06:23 +00:00
parent aa4dee1bda
commit ed9b1292f5
10 changed files with 372 additions and 8 deletions

View File

@ -0,0 +1,18 @@
#include <AppTypeVersionInfoView.h>
AppTypeVersionInfoView::AppTypeVersionInfoView(BRect viewFrame)
: BView(viewFrame, "AppTypeVersionInfoView", B_FOLLOW_ALL,
B_FRAME_EVENTS|B_WILL_DRAW)
{
SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
}
AppTypeVersionInfoView::~AppTypeVersionInfoView()
{
}
bool
AppTypeVersionInfoView::IsClean() const
{
return true;
}

View File

@ -0,0 +1,47 @@
#ifndef APP_TYPE_VERSION_INFO_VIEW_H
#define APP_TYPE_VERSION_INFO_VIEW_H
#include <Box.h>
#include <Menu.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <String.h>
#include <StringView.h>
#include <TextControl.h>
#include <TextView.h>
#include <View.h>
class AppTypeVersionInfoView : public BView {
public:
AppTypeVersionInfoView(BRect viewFrame);
~AppTypeVersionInfoView();
bool IsClean() const;
private:
BBox * fVersionInfoBox;
BMenu * fVersionKindMenu;
BMenuItem * fVersionApplicationMenuItem;
BMenuItem * fVersionSystemMenuItem;
BMenuField * fVersionKindMenuField;
BStringView * fVersionStringView;
BTextControl * fVersionMajorTextControl;
BTextControl * fVersionMiddleTextControl;
BTextControl * fVersionMinorTextControl;
BMenu * fVarietyMenu;
BMenuItem * fVarietyDevelopmentMenuItem;
BMenuItem * fVarietyAlphaMenuItem;
BMenuItem * fVarietyBetaMenuItem;
BMenuItem * fVarietyGammaMenuItem;
BMenuItem * fVarietyGoldenMasterMenuItem;
BMenuItem * fVarietyFinalMenuItem;
BMenuField * fVarietyMenuField;
BStringView * fSlashStringView;
BTextControl * fInternalTextControl;
BStringView * fShortDescriptionStringView;
BTextControl * fShortDescriptionTextControl;
BStringView * fLongDescriptionStringView;
BTextView * fLongDescriptionTextView;
};
#endif // APP_TYPE_VERSION_INFO_VIEW_H

View File

@ -0,0 +1,29 @@
#include <AppTypeView.h>
#include <AppTypeVersionInfoView.h>
AppTypeView::AppTypeView(BRect viewFrame)
: BView(viewFrame, "AppTypeView", B_FOLLOW_ALL,
B_FRAME_EVENTS|B_WILL_DRAW)
{
fVersionInfoView = 0;
SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
BRect versionInfoViewFrame = Bounds();
versionInfoViewFrame.top = Bounds().Height()/2;
fVersionInfoView = new AppTypeVersionInfoView(versionInfoViewFrame);
AddChild(fVersionInfoView);
}
AppTypeView::~AppTypeView()
{
delete fVersionInfoView;
}
bool
AppTypeView::IsClean() const
{
if (!fVersionInfoView->IsClean()) {
return false;
}
return true;
}

View File

@ -0,0 +1,40 @@
#ifndef APP_TYPE_VIEW_H
#define APP_TYPE_VIEW_H
#include <Box.h>
#include <Button.h>
#include <MenuField.h>
#include <String.h>
#include <TextControl.h>
#include <View.h>
class AppTypeVersionInfoView;
class AppTypeView : public BView {
public:
AppTypeView(BRect viewFrame);
~AppTypeView();
bool IsClean() const;
private:
BTextControl * fSignatureTextControl;
BBox * fAppFlagsBox;
BCheckBox * fAppFlagsCheckBox;
BRadioButton * fAppFlagsSingleRadioButton;
BRadioButton * fAppFlagsMultipleRadioButton;
BRadioButton * fAppFlagsExclusiveRadioButton;
BCheckBox * fAppFlagsArgvOnlyCheckBox;
BCheckBox * fAppFlagsBackOnlyCheckBox;
BBox * fSupportedTypesBox;
BListView * fSupportedTypesListView;
BScrollView * fSupportedTypesScrollView;
BButton * fSupportedTypesAddButton;
BButton * fSupportedTypesRemoveButton;
AppTypeVersionInfoView * fVersionInfoView;
};
#endif // APP_TYPE_VIEW_H

View File

@ -0,0 +1,138 @@
#include <Alert.h>
#include <Autolock.h>
#include <Debug.h>
#include <Entry.h>
#include <Node.h>
#include <NodeInfo.h>
#include <FileTypeApp.h>
#include <AppTypeView.h>
#include <AppTypeWindow.h>
AppTypeWindow::AppTypeWindow(const BEntry * entry)
: BWindow(BRect(100,100,400,520),"Application Type",B_TITLED_WINDOW,
B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS)
{
initStatus = B_ERROR;
fEntry = 0;
if (entry == 0) {
initStatus = B_BAD_VALUE;
return;
}
fMenuBar = new BMenuBar(BRect(0,0,0,0),"menubar");
AddChild(fMenuBar);
BRect viewFrame = Bounds();
viewFrame.top = fMenuBar->Bounds().Height()+1;
fView = new AppTypeView(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->AddSeparatorItem();
fCloseItem = new BMenuItem("Close",new BMessage(B_QUIT_REQUESTED), 'W');
fFileMenu->AddItem(fCloseItem);
SetEntry(entry);
initStatus = B_OK;
Show();
}
AppTypeWindow::~AppTypeWindow()
{
delete fEntry;
}
status_t
AppTypeWindow::InitCheck() const
{
return initStatus;
}
void
AppTypeWindow::MessageReceived(BMessage * message)
{
switch (message->what) {
case B_SAVE_REQUESTED:
SaveRequested();
break;
default:
BWindow::MessageReceived(message);
break;
}
}
void
AppTypeWindow::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
AppTypeWindow::QuitRequested()
{
if (fView->IsClean()) {
return true;
}
if (!fEntry) {
// no entry to save to!
return true;
}
BAlert * saveAlert;
char name[MAXPATHLEN];
fEntry->GetName(name);
BString alertText("Would you like to save changes to file type attributes of ");
alertText << name << "?";
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');
int32 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
AppTypeWindow::SaveRequested()
{
status_t result = B_OK;
// TODO : save new settings
return result;
}
void
AppTypeWindow::SetEntry(const BEntry * entry)
{
fEntry = new BEntry(*entry);
char name[MAXPATHLEN];
entry->GetName(name);
BString title(name);
title.Append(" Application Type");
SetTitle(strdup(title.String()));
// TODO : set old settings
}

View File

@ -0,0 +1,39 @@
#ifndef APP_TYPE_WINDOW_H
#define APP_TYPE_WINDOW_H
#include <EntryList.h>
#include <List.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Window.h>
class AppTypeView;
class AppTypeWindow
: public BWindow
{
public:
AppTypeWindow(const BEntry * entry);
~AppTypeWindow();
virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage * message);
status_t InitCheck() const;
private:
status_t SaveRequested();
void SetEntry(const BEntry * entry);
BMenuBar * fMenuBar;
BMenu * fFileMenu;
BMenuItem * fSaveItem;
BMenuItem * fCloseItem;
AppTypeView * fView;
BEntry * fEntry;
status_t initStatus;
};
#endif // APP_TYPE_WINDOW_H

View File

@ -1,7 +1,10 @@
#include <Node.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Roster.h>
#include <stdio.h>
#include <AppTypeWindow.h>
#include <FileTypeApp.h>
#include <FileTypeConstants.h>
#include <FileTypeWindow.h>
@ -38,6 +41,20 @@ void FileTypeApp::DispatchMessage(BMessage * msg, BHandler * handler)
}
}
void
FileTypeApp::MessageReceived(BMessage *message)
{
switch(message->what) {
case B_CANCEL:
if (fWindow == 0) {
Quit();
}
break;
default:
BApplication::MessageReceived(message);
break;
}
}
void
FileTypeApp::RefsReceived(BMessage * message)
@ -57,6 +74,28 @@ FileTypeApp::RefsReceived(BMessage * message)
if (entryList.CountItems() == 0) {
return;
}
if (entryList.CountItems() == 1) {
BEntry * entry = static_cast<BEntry*>(entryList.FirstItem());
BNode node(entry);
if (node.InitCheck() != B_OK) {
delete entry;
return;
}
BNodeInfo nodeInfo(&node);
if (nodeInfo.InitCheck() != B_OK) {
delete entry;
return;
}
char string[MAXPATHLEN];
if ((nodeInfo.GetType(string) == B_OK)
&& (strcmp(string,"application/x-vnd.Be-elfexecutable") == 0)) {
AppTypeWindow * window = new AppTypeWindow(entry);
if (window->InitCheck() == B_OK) {
fWindow = window;
}
return;
}
}
FileTypeWindow * window = new FileTypeWindow(&entryList);
if (window->InitCheck() == B_OK) {
fWindow = window;

View File

@ -11,6 +11,7 @@ class FileTypeApp
{
public:
FileTypeApp();
virtual void MessageReceived(BMessage *message);
virtual void ArgvReceived(int32 argc, const char *argv[], const char * cwd);
virtual void RefsReceived(BMessage *message);
virtual void ReadyToRun();
@ -21,7 +22,7 @@ private:
BFilePanel * OpenPanel();
void PrintUsage(const char * execname);
FileTypeWindow * fWindow;
BWindow * fWindow;
BFilePanel * fOpenPanel;
bool fArgvOkay;

View File

@ -170,9 +170,10 @@ FileTypeWindow::SetEntries(const BList * entryList)
continue; // can't proceed with an invalid nodeinfo
}
char string[MAXPATHLEN];
if (nodeInfo.GetType(string) != B_OK) {
// errors are ignored: there's usually no good way for the user to recover
} else {
switch (nodeInfo.GetType(string)) {
case B_ENTRY_NOT_FOUND:
strcpy(string,"");
case B_OK:
if (fileType == 0) {
fileType = new BString(string);
} else if (fileType->Compare(string) != 0) {
@ -181,10 +182,15 @@ FileTypeWindow::SetEntries(const BList * entryList)
break; // stop now, don't waste time checking the rest
}
}
}
if (nodeInfo.GetPreferredApp(string) != B_OK) {
break;
default:
// errors are ignored: there's usually no good way for the user to recover
} else {
break;
}
switch (nodeInfo.GetPreferredApp(string)) {
case B_ENTRY_NOT_FOUND:
strcpy(string,"");
case B_OK:
if (preferredApplication == 0) {
preferredApplication = new BString(string);
} else if (preferredApplication->Compare(string) != 0) {
@ -193,13 +199,17 @@ FileTypeWindow::SetEntries(const BList * entryList)
break; // stop now, don't waste time checking the rest
}
}
break;
default:
// errors are ignored: there's usually no good way for the user to recover
break;
}
}
if (fileType != 0) {
fView->SetFileType(fileType->String());
delete fileType;
}
if (preferredApplication != 0) {
if ((preferredApplication != 0) && (preferredApplication->Length() > 0)) {
fView->SetPreferredApplication(preferredApplication->String());
delete preferredApplication;
}

View File

@ -9,6 +9,9 @@ App FileType-F :
FileTypeApp.cpp
FileTypeView.cpp
FileTypeWindow.cpp
AppTypeWindow.cpp
AppTypeView.cpp
AppTypeVersionInfoView.cpp
process_refs.cpp
;