From ed9b1292f5a3e66ca423cdeddd45d75bd022f7d9 Mon Sep 17 00:00:00 2001 From: shatty Date: Mon, 18 Aug 2003 22:06:23 +0000 Subject: [PATCH] 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 --- .../filetype/AppTypeVersionInfoView.cpp | 18 +++ .../tracker/filetype/AppTypeVersionInfoView.h | 47 ++++++ src/add-ons/tracker/filetype/AppTypeView.cpp | 29 ++++ src/add-ons/tracker/filetype/AppTypeView.h | 40 +++++ .../tracker/filetype/AppTypeWindow.cpp | 138 ++++++++++++++++++ src/add-ons/tracker/filetype/AppTypeWindow.h | 39 +++++ src/add-ons/tracker/filetype/FileTypeApp.cpp | 39 +++++ src/add-ons/tracker/filetype/FileTypeApp.h | 3 +- .../tracker/filetype/FileTypeWindow.cpp | 24 ++- src/add-ons/tracker/filetype/Jamfile | 3 + 10 files changed, 372 insertions(+), 8 deletions(-) create mode 100644 src/add-ons/tracker/filetype/AppTypeVersionInfoView.cpp create mode 100644 src/add-ons/tracker/filetype/AppTypeVersionInfoView.h create mode 100644 src/add-ons/tracker/filetype/AppTypeView.cpp create mode 100644 src/add-ons/tracker/filetype/AppTypeView.h create mode 100644 src/add-ons/tracker/filetype/AppTypeWindow.cpp create mode 100644 src/add-ons/tracker/filetype/AppTypeWindow.h diff --git a/src/add-ons/tracker/filetype/AppTypeVersionInfoView.cpp b/src/add-ons/tracker/filetype/AppTypeVersionInfoView.cpp new file mode 100644 index 0000000000..6f071821d1 --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeVersionInfoView.cpp @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/src/add-ons/tracker/filetype/AppTypeVersionInfoView.h b/src/add-ons/tracker/filetype/AppTypeVersionInfoView.h new file mode 100644 index 0000000000..c8dd2acc2e --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeVersionInfoView.h @@ -0,0 +1,47 @@ +#ifndef APP_TYPE_VERSION_INFO_VIEW_H +#define APP_TYPE_VERSION_INFO_VIEW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 diff --git a/src/add-ons/tracker/filetype/AppTypeView.cpp b/src/add-ons/tracker/filetype/AppTypeView.cpp new file mode 100644 index 0000000000..9cedc91efe --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeView.cpp @@ -0,0 +1,29 @@ +#include +#include + +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; +} diff --git a/src/add-ons/tracker/filetype/AppTypeView.h b/src/add-ons/tracker/filetype/AppTypeView.h new file mode 100644 index 0000000000..7e66ddd820 --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeView.h @@ -0,0 +1,40 @@ +#ifndef APP_TYPE_VIEW_H +#define APP_TYPE_VIEW_H + +#include +#include +#include +#include +#include +#include + +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 diff --git a/src/add-ons/tracker/filetype/AppTypeWindow.cpp b/src/add-ons/tracker/filetype/AppTypeWindow.cpp new file mode 100644 index 0000000000..577cc5fb40 --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeWindow.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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 +} diff --git a/src/add-ons/tracker/filetype/AppTypeWindow.h b/src/add-ons/tracker/filetype/AppTypeWindow.h new file mode 100644 index 0000000000..69962674ef --- /dev/null +++ b/src/add-ons/tracker/filetype/AppTypeWindow.h @@ -0,0 +1,39 @@ +#ifndef APP_TYPE_WINDOW_H +#define APP_TYPE_WINDOW_H + +#include +#include +#include +#include +#include + +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 diff --git a/src/add-ons/tracker/filetype/FileTypeApp.cpp b/src/add-ons/tracker/filetype/FileTypeApp.cpp index 0770abe968..db2e50a7d4 100644 --- a/src/add-ons/tracker/filetype/FileTypeApp.cpp +++ b/src/add-ons/tracker/filetype/FileTypeApp.cpp @@ -1,7 +1,10 @@ +#include +#include #include #include #include +#include #include #include #include @@ -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(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; diff --git a/src/add-ons/tracker/filetype/FileTypeApp.h b/src/add-ons/tracker/filetype/FileTypeApp.h index 289dd14755..2517a94933 100644 --- a/src/add-ons/tracker/filetype/FileTypeApp.h +++ b/src/add-ons/tracker/filetype/FileTypeApp.h @@ -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; diff --git a/src/add-ons/tracker/filetype/FileTypeWindow.cpp b/src/add-ons/tracker/filetype/FileTypeWindow.cpp index 0faa4a08cf..6b9da6a489 100644 --- a/src/add-ons/tracker/filetype/FileTypeWindow.cpp +++ b/src/add-ons/tracker/filetype/FileTypeWindow.cpp @@ -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; } diff --git a/src/add-ons/tracker/filetype/Jamfile b/src/add-ons/tracker/filetype/Jamfile index 1217be384c..e8921bb2ec 100644 --- a/src/add-ons/tracker/filetype/Jamfile +++ b/src/add-ons/tracker/filetype/Jamfile @@ -9,6 +9,9 @@ App FileType-F : FileTypeApp.cpp FileTypeView.cpp FileTypeWindow.cpp + AppTypeWindow.cpp + AppTypeView.cpp + AppTypeVersionInfoView.cpp process_refs.cpp ;