Incorporate work done by James Urquhart (jamesu):
* Use our own BBitmapStringField implementation which also requires our own BColumn implementation. This is just a visual improvement which makes both the eventual partiton icon and device label indent with the outline level of the list item * when setting the Unmount menu item enabled state, check wether the partition in question is the /boot volume and disallow unmounting. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23845 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
#include <Volume.h>
|
||||||
|
#include <VolumeRoster.h>
|
||||||
|
|
||||||
|
|
||||||
class ListPopulatorVisitor : public BDiskDeviceVisitor {
|
class ListPopulatorVisitor : public BDiskDeviceVisitor {
|
||||||
@@ -81,9 +83,6 @@ private:
|
|||||||
i++) {
|
i++) {
|
||||||
fPartitionList->AddSpace(partition->ID(), offset, size);
|
fPartitionList->AddSpace(partition->ID(), offset, size);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fprintf(stderr, "failed to get partitioning info: %s\n",
|
|
||||||
strerror(ret));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +479,18 @@ fCreateMenu->SetEnabled(false);
|
|||||||
// fDeleteMI->SetEnabled(!partition->IsMounted());
|
// fDeleteMI->SetEnabled(!partition->IsMounted());
|
||||||
fDeleteMI->SetEnabled(false);
|
fDeleteMI->SetEnabled(false);
|
||||||
fMountMI->SetEnabled(!partition->IsMounted());
|
fMountMI->SetEnabled(!partition->IsMounted());
|
||||||
fUnmountMI->SetEnabled(partition->IsMounted());
|
|
||||||
|
if (partition->IsMounted()) {
|
||||||
|
// see if this partition is the boot volume
|
||||||
|
BVolume volume;
|
||||||
|
BVolume bootVolume;
|
||||||
|
if (BVolumeRoster().GetBootVolume(&bootVolume) == B_OK
|
||||||
|
&& partition->GetVolume(&volume) == B_OK) {
|
||||||
|
fUnmountMI->SetEnabled(volume != bootVolume);
|
||||||
|
} else {
|
||||||
|
fUnmountMI->SetEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fInitMenu->SetEnabled(false);
|
fInitMenu->SetEnabled(false);
|
||||||
fDeleteMI->SetEnabled(false);
|
fDeleteMI->SetEnabled(false);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
|
* James Urquhart
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#include "PartitionList.h"
|
#include "PartitionList.h"
|
||||||
@@ -13,10 +14,132 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - BBitmapStringField
|
||||||
|
|
||||||
|
|
||||||
|
BBitmapStringField::BBitmapStringField(BBitmap* bitmap, const char* string)
|
||||||
|
: Inherited(string)
|
||||||
|
, fBitmap(bitmap)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BBitmapStringField::~BBitmapStringField()
|
||||||
|
{
|
||||||
|
delete fBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BBitmapStringField::SetBitmap(BBitmap* bitmap)
|
||||||
|
{
|
||||||
|
delete fBitmap;
|
||||||
|
fBitmap = bitmap;
|
||||||
|
// TODO: cause a redraw?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - PartitionColumn
|
||||||
|
|
||||||
|
|
||||||
|
float PartitionColumn::fTextMargin = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
PartitionColumn::PartitionColumn(const char* title, float width, float minWidth,
|
||||||
|
float maxWidth, uint32 truncateMode, alignment align)
|
||||||
|
: Inherited(title, width, minWidth, maxWidth, align),
|
||||||
|
fTruncateMode(truncateMode)
|
||||||
|
{
|
||||||
|
SetWantsEvents(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
|
||||||
|
{
|
||||||
|
if (fTextMargin == 0.0) {
|
||||||
|
// we are the first column to draw something and need to
|
||||||
|
// init the text margin
|
||||||
|
BFont font;
|
||||||
|
parent->GetFont(&font);
|
||||||
|
fTextMargin = ceilf(font.Size() * 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
BBitmapStringField* bitmapField
|
||||||
|
= dynamic_cast<BBitmapStringField*>(field);
|
||||||
|
BStringField* stringField = dynamic_cast<BStringField*>(field);
|
||||||
|
|
||||||
|
if (bitmapField) {
|
||||||
|
const BBitmap* bitmap = bitmapField->Bitmap();
|
||||||
|
|
||||||
|
// figure out the placement
|
||||||
|
float x = 0.0;
|
||||||
|
BRect r = bitmap ? bitmap->Bounds() : BRect(0, 0, 15, 15);
|
||||||
|
float y = rect.top + ((rect.Height() - r.Height()) / 2);
|
||||||
|
float width = 0.0;
|
||||||
|
|
||||||
|
switch (Alignment()) {
|
||||||
|
default:
|
||||||
|
case B_ALIGN_LEFT:
|
||||||
|
case B_ALIGN_CENTER:
|
||||||
|
x = rect.left + fTextMargin;
|
||||||
|
width = rect.right - (x + r.Width()) - (2 * fTextMargin);
|
||||||
|
r.Set(x + r.Width(), rect.top, rect.right - width, rect.bottom);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_ALIGN_RIGHT:
|
||||||
|
x = rect.right - fTextMargin - r.Width();
|
||||||
|
width = (x - rect.left - (2 * fTextMargin));
|
||||||
|
r.Set(rect.left, rect.top, rect.left + width, rect.bottom);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width != bitmapField->Width()) {
|
||||||
|
BString truncatedString(bitmapField->String());
|
||||||
|
parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
|
||||||
|
bitmapField->SetClippedString(truncatedString.String());
|
||||||
|
bitmapField->SetWidth(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw the bitmap
|
||||||
|
if (bitmap) {
|
||||||
|
parent->SetDrawingMode(B_OP_ALPHA);
|
||||||
|
parent->DrawBitmap(bitmap, BPoint(x, y));
|
||||||
|
parent->SetDrawingMode(B_OP_OVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw the string
|
||||||
|
DrawString(bitmapField->ClippedString(), parent, r);
|
||||||
|
|
||||||
|
} else if (stringField) {
|
||||||
|
|
||||||
|
float width = rect.Width() - (2 * fTextMargin);
|
||||||
|
|
||||||
|
if (width != stringField->Width()) {
|
||||||
|
BString truncatedString(stringField->String());
|
||||||
|
|
||||||
|
parent->TruncateString(&truncatedString, fTruncateMode, width + 2);
|
||||||
|
stringField->SetClippedString(truncatedString.String());
|
||||||
|
stringField->SetWidth(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawString(stringField->ClippedString(), parent, rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PartitionColumn::AcceptsField(const BField* field) const
|
||||||
|
{
|
||||||
|
return dynamic_cast<const BStringField*>(field) != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - PartitionListRow
|
||||||
|
|
||||||
|
|
||||||
static const char* kUnavailableString = "";
|
static const char* kUnavailableString = "";
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
// kBitmapColumn,
|
|
||||||
kDeviceColumn,
|
kDeviceColumn,
|
||||||
kFilesystemColumn,
|
kFilesystemColumn,
|
||||||
kVolumeNameColumn,
|
kVolumeNameColumn,
|
||||||
@@ -32,11 +155,20 @@ PartitionListRow::PartitionListRow(BPartition* partition)
|
|||||||
, fOffset(partition->Offset())
|
, fOffset(partition->Offset())
|
||||||
, fSize(partition->Size())
|
, fSize(partition->Size())
|
||||||
{
|
{
|
||||||
// SetField(new BBitmapField(NULL), kBitmapColumn);
|
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
partition->GetPath(&path);
|
partition->GetPath(&path);
|
||||||
SetField(new BStringField(path.Path()), kDeviceColumn);
|
|
||||||
|
BBitmap* icon = NULL;
|
||||||
|
if (partition->IsDevice()) {
|
||||||
|
icon_size size = B_MINI_ICON;
|
||||||
|
icon = new BBitmap(BRect(0, 0, size - 1, size - 1), B_RGBA32);
|
||||||
|
if (partition->GetIcon(icon, size) != B_OK) {
|
||||||
|
delete icon;
|
||||||
|
icon = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetField(new BBitmapStringField(icon, path.Path()), kDeviceColumn);
|
||||||
|
|
||||||
if (partition->ContainsFileSystem()) {
|
if (partition->ContainsFileSystem()) {
|
||||||
SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
||||||
@@ -66,11 +198,10 @@ PartitionListRow::PartitionListRow(partition_id parentID, off_t offset,
|
|||||||
, fOffset(offset)
|
, fOffset(offset)
|
||||||
, fSize(size)
|
, fSize(size)
|
||||||
{
|
{
|
||||||
// SetField(new BBitmapField(NULL), kBitmapColumn);
|
// TODO: design icon for spaces on partitions
|
||||||
|
SetField(new BBitmapStringField(NULL, "-"), kDeviceColumn);
|
||||||
|
|
||||||
SetField(new BStringField("-"), kDeviceColumn);
|
SetField(new BStringField("<empty>"), kFilesystemColumn);
|
||||||
|
|
||||||
SetField(new BStringField("Empty"), kFilesystemColumn);
|
|
||||||
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
|
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
|
||||||
|
|
||||||
SetField(new BStringField(kUnavailableString), kMountedAtColumn);
|
SetField(new BStringField(kUnavailableString), kMountedAtColumn);
|
||||||
@@ -83,18 +214,16 @@ PartitionListRow::PartitionListRow(partition_id parentID, off_t offset,
|
|||||||
PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
|
PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
|
||||||
: Inherited(frame, "storagelist", resizeMode, 0, B_NO_BORDER, true)
|
: Inherited(frame, "storagelist", resizeMode, 0, B_NO_BORDER, true)
|
||||||
{
|
{
|
||||||
// AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER),
|
AddColumn(new PartitionColumn("Device", 150, 50, 500,
|
||||||
// kBitmapColumn);
|
B_TRUNCATE_MIDDLE), kDeviceColumn);
|
||||||
AddColumn(new BStringColumn("Device", 150, 50, 500, B_TRUNCATE_MIDDLE),
|
AddColumn(new PartitionColumn("Filesystem", 100, 50, 500,
|
||||||
kDeviceColumn);
|
B_TRUNCATE_MIDDLE), kFilesystemColumn);
|
||||||
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE),
|
AddColumn(new PartitionColumn("Volume Name", 130, 50, 500,
|
||||||
kFilesystemColumn);
|
B_TRUNCATE_MIDDLE), kVolumeNameColumn);
|
||||||
AddColumn(new BStringColumn("Volume Name", 130, 50, 500, B_TRUNCATE_MIDDLE),
|
AddColumn(new PartitionColumn("Mounted At", 100, 50, 500,
|
||||||
kVolumeNameColumn);
|
B_TRUNCATE_MIDDLE), kMountedAtColumn);
|
||||||
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE),
|
AddColumn(new PartitionColumn("Size", 100, 50, 500,
|
||||||
kMountedAtColumn);
|
B_TRUNCATE_END, B_ALIGN_RIGHT), kSizeColumn);
|
||||||
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END,
|
|
||||||
B_ALIGN_RIGHT), kSizeColumn);
|
|
||||||
|
|
||||||
SetSortingEnabled(false);
|
SetSortingEnabled(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,23 +4,61 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Ithamar R. Adema <[email protected]>
|
* Ithamar R. Adema <[email protected]>
|
||||||
|
* James Urquhart
|
||||||
* Stephan Aßmus <[email protected]>
|
* Stephan Aßmus <[email protected]>
|
||||||
*/
|
*/
|
||||||
#ifndef PARTITIONLIST_H
|
#ifndef PARTITIONLIST_H
|
||||||
#define PARTITIONLIST_H
|
#define PARTITIONLIST_H
|
||||||
|
|
||||||
|
|
||||||
class PartitionListRow;
|
|
||||||
class PartitionListView;
|
|
||||||
|
|
||||||
|
|
||||||
#include <ColumnListView.h>
|
#include <ColumnListView.h>
|
||||||
|
#include <ColumnTypes.h>
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
|
|
||||||
|
|
||||||
class BPartition;
|
class BPartition;
|
||||||
|
|
||||||
|
|
||||||
|
// A field type displaying both a bitmap and a string so that the
|
||||||
|
// tree display looks nicer (both text and bitmap are indented)
|
||||||
|
class BBitmapStringField : public BStringField {
|
||||||
|
typedef BStringField Inherited;
|
||||||
|
public:
|
||||||
|
BBitmapStringField(BBitmap* bitmap,
|
||||||
|
const char* string);
|
||||||
|
virtual ~BBitmapStringField();
|
||||||
|
|
||||||
|
void SetBitmap(BBitmap* bitmap);
|
||||||
|
const BBitmap* Bitmap() const
|
||||||
|
{ return fBitmap; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
BBitmap* fBitmap;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// BColumn for PartitionListView which knows how to render
|
||||||
|
// a BBitmapStringField
|
||||||
|
class PartitionColumn : public BTitledColumn {
|
||||||
|
typedef BTitledColumn Inherited;
|
||||||
|
public:
|
||||||
|
PartitionColumn(const char* title,
|
||||||
|
float width, float minWidth,
|
||||||
|
float maxWidth, uint32 truncateMode,
|
||||||
|
alignment align = B_ALIGN_LEFT);
|
||||||
|
|
||||||
|
virtual void DrawField(BField* field, BRect rect,
|
||||||
|
BView* parent);
|
||||||
|
|
||||||
|
virtual bool AcceptsField(const BField* field) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32 fTruncateMode;
|
||||||
|
static float fTextMargin;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// BRow for the PartitionListView
|
||||||
class PartitionListRow : public BRow {
|
class PartitionListRow : public BRow {
|
||||||
typedef BRow Inherited;
|
typedef BRow Inherited;
|
||||||
public:
|
public:
|
||||||
@@ -30,6 +68,8 @@ public:
|
|||||||
|
|
||||||
partition_id ID() const
|
partition_id ID() const
|
||||||
{ return fPartitionID; }
|
{ return fPartitionID; }
|
||||||
|
partition_id ParentID() const
|
||||||
|
{ return fParentID; }
|
||||||
off_t Offset() const
|
off_t Offset() const
|
||||||
{ return fOffset; }
|
{ return fOffset; }
|
||||||
off_t Size() const
|
off_t Size() const
|
||||||
|
|||||||
Reference in New Issue
Block a user