diff --git a/src/apps/diskprobe/AttributeWindow.cpp b/src/apps/diskprobe/AttributeWindow.cpp new file mode 100644 index 0000000000..0ed21047db --- /dev/null +++ b/src/apps/diskprobe/AttributeWindow.cpp @@ -0,0 +1,61 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include "AttributeWindow.h" +#include "ProbeView.h" + +#include +#include + +#include + + +AttributeWindow::AttributeWindow(BRect rect, entry_ref *ref, const char *attribute) + : ProbeWindow(rect, ref), + fAttribute(strdup(attribute)) +{ + char buffer[256]; + snprintf(buffer, sizeof(buffer), "%s: %s", ref->name, attribute); + SetTitle(buffer); + + // add the menu + + BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); + AddChild(menuBar); + + BMenu *menu = new BMenu("Attribute"); + + // the ProbeView file menu items will be inserted here + menu->AddSeparatorItem(); + + menu->AddItem(new BMenuItem("Close", new BMessage(B_CLOSE_REQUESTED), 'W', B_COMMAND_KEY)); + menu->SetTargetForItems(this); + menuBar->AddItem(menu); + + // add our interface widgets + + BRect rect = Bounds(); + rect.top = menuBar->Bounds().Height() + 1; + ProbeView *probeView = new ProbeView(rect, ref, attribute); + probeView->AddFileMenuItems(menu, 0); + AddChild(probeView); + + probeView->UpdateSizeLimits(); +} + + +AttributeWindow::~AttributeWindow() +{ + free(fAttribute); +} + + +bool +AttributeWindow::Contains(const entry_ref &ref, const char *attribute) +{ + return ref == Ref() && attribute != NULL && !strcmp(attribute, fAttribute); +} + diff --git a/src/apps/diskprobe/AttributeWindow.h b/src/apps/diskprobe/AttributeWindow.h new file mode 100644 index 0000000000..791a5919c1 --- /dev/null +++ b/src/apps/diskprobe/AttributeWindow.h @@ -0,0 +1,23 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef ATTRIBUTE_WINDOW_H +#define ATTRIBUTE_WINDOW_H + + +#include "ProbeWindow.h" + + +class AttributeWindow : public ProbeWindow { + public: + AttributeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL); + virtual ~AttributeWindow(); + + bool Contains(const entry_ref &ref, const char *attribute); + + private: + char *fAttribute; +}; + +#endif /* ATTRIBUTE_WINDOW_H */ diff --git a/src/apps/diskprobe/DiskProbe.cpp b/src/apps/diskprobe/DiskProbe.cpp index 20dd9a7cb2..2ee3fef5e4 100644 --- a/src/apps/diskprobe/DiskProbe.cpp +++ b/src/apps/diskprobe/DiskProbe.cpp @@ -6,7 +6,8 @@ #include "DiskProbe.h" #include "DataEditor.h" -#include "ProbeWindow.h" +#include "FileWindow.h" +#include "AttributeWindow.h" #include "OpenWindow.h" #include @@ -42,7 +43,7 @@ class DiskProbe : public BApplication { virtual bool QuitRequested(); private: - status_t Probe(entry_ref &ref); + status_t Probe(entry_ref &ref, const char *attribute = NULL); BFilePanel *fFilePanel; BWindow *fOpenWindow; @@ -93,7 +94,7 @@ DiskProbe::ReadyToRun() */ status_t -DiskProbe::Probe(entry_ref &ref) +DiskProbe::Probe(entry_ref &ref, const char *attribute) { int32 probeWindows = 0; @@ -102,8 +103,8 @@ DiskProbe::Probe(entry_ref &ref) ProbeWindow *window = dynamic_cast(WindowAt(i)); if (window == NULL) continue; - - if (window->EntryRef() == ref) { + + if (window->Contains(ref, attribute)) { window->Activate(true); return B_OK; } @@ -120,7 +121,12 @@ DiskProbe::Probe(entry_ref &ref) BRect rect = fWindowPosition; rect.OffsetBy(probeWindows * kCascadeOffset, probeWindows * kCascadeOffset); - BWindow *window = new ProbeWindow(rect, &ref); + BWindow *window; + if (attribute != NULL) + window = new AttributeWindow(rect, &ref, attribute); + else + window = new FileWindow(rect, &ref); + window->Show(); fWindowCount++; @@ -134,7 +140,10 @@ DiskProbe::RefsReceived(BMessage *message) int32 index = 0; entry_ref ref; while (message->FindRef("refs", index++, &ref) == B_OK) { - Probe(ref); + const char *attribute = NULL; + message->FindString("attributes", index - 1, &attribute); + + Probe(ref, attribute); } } diff --git a/src/apps/diskprobe/FileWindow.cpp b/src/apps/diskprobe/FileWindow.cpp new file mode 100644 index 0000000000..2bdf535e68 --- /dev/null +++ b/src/apps/diskprobe/FileWindow.cpp @@ -0,0 +1,78 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include "FileWindow.h" +#include "OpenWindow.h" +#include "DiskProbe.h" +#include "ProbeView.h" + +#include +#include +#include +#include + + +FileWindow::FileWindow(BRect rect, entry_ref *ref) + : ProbeWindow(rect, ref) +{ + // Set alternative window title for devices + + BEntry entry(ref); + struct stat stat; + if (entry.GetStat(&stat) == B_OK && (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0) { + BPath path(ref); + SetTitle(path.Path()); + } + + // add the menu + + BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); + AddChild(menuBar); + + BMenu *menu = new BMenu("File"); + menu->AddItem(new BMenuItem("New" B_UTF8_ELLIPSIS, + new BMessage(kMsgOpenOpenWindow), 'N', B_COMMAND_KEY)); + + BMenu *devicesMenu = new BMenu("Open Device"); + OpenWindow::CollectDevices(devicesMenu); + devicesMenu->SetTargetForItems(be_app); + menu->AddItem(new BMenuItem(devicesMenu)); + + menu->AddItem(new BMenuItem("Open File" B_UTF8_ELLIPSIS, + new BMessage(kMsgOpenFilePanel), 'O', B_COMMAND_KEY)); + menu->AddSeparatorItem(); + + // the ProbeView file menu items will be inserted here + menu->AddSeparatorItem(); + + menu->AddItem(new BMenuItem("About DiskProbe" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); + menu->AddSeparatorItem(); + + menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); + menu->SetTargetForItems(be_app); + menuBar->AddItem(menu); + + // add our interface widgets + + BRect rect = Bounds(); + rect.top = menuBar->Bounds().Height() + 1; + ProbeView *probeView = new ProbeView(rect, ref); + probeView->AddFileMenuItems(menu, menu->CountItems() - 4); + AddChild(probeView); + + probeView->UpdateSizeLimits(); +} + + +bool +FileWindow::Contains(const entry_ref &ref, const char *attribute) +{ + if (attribute != NULL) + return false; + + return ref == Ref(); +} + diff --git a/src/apps/diskprobe/FileWindow.h b/src/apps/diskprobe/FileWindow.h new file mode 100644 index 0000000000..74030e7f3c --- /dev/null +++ b/src/apps/diskprobe/FileWindow.h @@ -0,0 +1,19 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef FILE_WINDOW_H +#define FILE_WINDOW_H + + +#include "ProbeWindow.h" + + +class FileWindow : public ProbeWindow { + public: + FileWindow(BRect rect, entry_ref *ref); + + virtual bool Contains(const entry_ref &ref, const char *attribute); +}; + +#endif /* FILE_WINDOW_H */ diff --git a/src/apps/diskprobe/Jamfile b/src/apps/diskprobe/Jamfile index 5861b55f5d..3d2b516cee 100644 --- a/src/apps/diskprobe/Jamfile +++ b/src/apps/diskprobe/Jamfile @@ -9,6 +9,8 @@ App DiskProbe : DataEditor.cpp DataView.cpp ProbeWindow.cpp + FileWindow.cpp + AttributeWindow.cpp ProbeView.cpp OpenWindow.cpp ; diff --git a/src/apps/diskprobe/ProbeWindow.cpp b/src/apps/diskprobe/ProbeWindow.cpp index 6ba8025db0..203be9ae86 100644 --- a/src/apps/diskprobe/ProbeWindow.cpp +++ b/src/apps/diskprobe/ProbeWindow.cpp @@ -5,73 +5,15 @@ #include "ProbeWindow.h" -#include "OpenWindow.h" #include "DiskProbe.h" -#include "ProbeView.h" #include -#include -#include -#include -#include - -#include -#include -ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref, const char *attribute) +ProbeWindow::ProbeWindow(BRect rect, entry_ref *ref) : BWindow(rect, ref->name, B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS), fRef(*ref) { - // Set alternative title for certain cases - - if (attribute != NULL) { - char buffer[256]; - snprintf(buffer, sizeof(buffer), "%s: %s", ref->name, attribute); - SetTitle(buffer); - } else { - BPath path(ref); - if (!strncmp("/dev/", path.Path(), 5)) - SetTitle(path.Path()); - } - - // add the menu - - BMenuBar *menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); - AddChild(menuBar); - - BMenu *menu = new BMenu("File"); - menu->AddItem(new BMenuItem("New" B_UTF8_ELLIPSIS, - new BMessage(kMsgOpenOpenWindow), 'N', B_COMMAND_KEY)); - - BMenu *devicesMenu = new BMenu("Open Device"); - OpenWindow::CollectDevices(devicesMenu); - devicesMenu->SetTargetForItems(be_app); - menu->AddItem(new BMenuItem(devicesMenu)); - - menu->AddItem(new BMenuItem("Open File" B_UTF8_ELLIPSIS, - new BMessage(kMsgOpenFilePanel), 'O', B_COMMAND_KEY)); - menu->AddSeparatorItem(); - - // the ProbeView file menu items will be inserted here - menu->AddSeparatorItem(); - - menu->AddItem(new BMenuItem("About DiskProbe" B_UTF8_ELLIPSIS, new BMessage(B_ABOUT_REQUESTED))); - menu->AddSeparatorItem(); - - menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); - menu->SetTargetForItems(be_app); - menuBar->AddItem(menu); - - // add our interface widgets - - BRect rect = Bounds(); - rect.top = menuBar->Bounds().Height() + 1; - ProbeView *probeView = new ProbeView(rect, ref, attribute); - probeView->AddFileMenuItems(menu, menu->CountItems() - 4); - AddChild(probeView); - - probeView->UpdateSizeLimits(); } diff --git a/src/apps/diskprobe/ProbeWindow.h b/src/apps/diskprobe/ProbeWindow.h index 73938c618e..53c7be0e77 100644 --- a/src/apps/diskprobe/ProbeWindow.h +++ b/src/apps/diskprobe/ProbeWindow.h @@ -12,13 +12,16 @@ class ProbeWindow : public BWindow { public: - ProbeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL); + ProbeWindow(BRect rect, entry_ref *ref); virtual ~ProbeWindow(); virtual void MessageReceived(BMessage *message); virtual bool QuitRequested(); - const entry_ref &EntryRef() const { return fRef; } + virtual bool Contains(const entry_ref &ref, const char *attribute) = 0; + + protected: + const entry_ref &Ref() const { return fRef; } private: entry_ref fRef;