Implemented initial attribute support.

ProbeWindow is now the base class for FileWindow and AttributeWindow.
Currently, attribute window has no special additional controls, but that will come.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6713 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-02-24 07:24:05 +00:00
parent 595bb3098e
commit d11ec0829b
8 changed files with 205 additions and 68 deletions

View File

@ -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 <MenuBar.h>
#include <MenuItem.h>
#include <stdio.h>
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);
}

View File

@ -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 */

View File

@ -6,7 +6,8 @@
#include "DiskProbe.h" #include "DiskProbe.h"
#include "DataEditor.h" #include "DataEditor.h"
#include "ProbeWindow.h" #include "FileWindow.h"
#include "AttributeWindow.h"
#include "OpenWindow.h" #include "OpenWindow.h"
#include <Application.h> #include <Application.h>
@ -42,7 +43,7 @@ class DiskProbe : public BApplication {
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
status_t Probe(entry_ref &ref); status_t Probe(entry_ref &ref, const char *attribute = NULL);
BFilePanel *fFilePanel; BFilePanel *fFilePanel;
BWindow *fOpenWindow; BWindow *fOpenWindow;
@ -93,7 +94,7 @@ DiskProbe::ReadyToRun()
*/ */
status_t status_t
DiskProbe::Probe(entry_ref &ref) DiskProbe::Probe(entry_ref &ref, const char *attribute)
{ {
int32 probeWindows = 0; int32 probeWindows = 0;
@ -103,7 +104,7 @@ DiskProbe::Probe(entry_ref &ref)
if (window == NULL) if (window == NULL)
continue; continue;
if (window->EntryRef() == ref) { if (window->Contains(ref, attribute)) {
window->Activate(true); window->Activate(true);
return B_OK; return B_OK;
} }
@ -120,7 +121,12 @@ DiskProbe::Probe(entry_ref &ref)
BRect rect = fWindowPosition; BRect rect = fWindowPosition;
rect.OffsetBy(probeWindows * kCascadeOffset, probeWindows * kCascadeOffset); 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(); window->Show();
fWindowCount++; fWindowCount++;
@ -134,7 +140,10 @@ DiskProbe::RefsReceived(BMessage *message)
int32 index = 0; int32 index = 0;
entry_ref ref; entry_ref ref;
while (message->FindRef("refs", index++, &ref) == B_OK) { while (message->FindRef("refs", index++, &ref) == B_OK) {
Probe(ref); const char *attribute = NULL;
message->FindString("attributes", index - 1, &attribute);
Probe(ref, attribute);
} }
} }

View File

@ -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 <Application.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Path.h>
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();
}

View File

@ -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 */

View File

@ -9,6 +9,8 @@ App DiskProbe :
DataEditor.cpp DataEditor.cpp
DataView.cpp DataView.cpp
ProbeWindow.cpp ProbeWindow.cpp
FileWindow.cpp
AttributeWindow.cpp
ProbeView.cpp ProbeView.cpp
OpenWindow.cpp OpenWindow.cpp
; ;

View File

@ -5,73 +5,15 @@
#include "ProbeWindow.h" #include "ProbeWindow.h"
#include "OpenWindow.h"
#include "DiskProbe.h" #include "DiskProbe.h"
#include "ProbeView.h"
#include <Application.h> #include <Application.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Entry.h>
#include <Path.h>
#include <string.h>
#include <stdio.h>
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), : BWindow(rect, ref->name, B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS),
fRef(*ref) 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();
} }

View File

@ -12,13 +12,16 @@
class ProbeWindow : public BWindow { class ProbeWindow : public BWindow {
public: public:
ProbeWindow(BRect rect, entry_ref *ref, const char *attribute = NULL); ProbeWindow(BRect rect, entry_ref *ref);
virtual ~ProbeWindow(); virtual ~ProbeWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested(); 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: private:
entry_ref fRef; entry_ref fRef;