Have ConfirmChangeIfWellKnownDirectory() protect the folders Common, Desktop, Root and Trash from renames and moves. Shift-key dialog protection added for the Home folder. Attempts on Desktop, Root and Trash are blocked silently. I admitt it's a bit odd to protect these so resolutely, unlike system, common and home, which are truly essential to the system. Would it be patronizing to enforce a stricter regime?

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41131 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström 2011-03-28 06:44:46 +00:00
parent 5a63a4576e
commit 77e2c2dad3
4 changed files with 40 additions and 27 deletions

View File

@ -623,7 +623,11 @@ ConfirmChangeIfWellKnownDirectory(const BEntry *entry, const char *ifYouDoAction
if (confirmedAlready && *confirmedAlready == kConfirmedAll)
return true;
if (FSIsDeskDir(entry) || FSIsTrashDir(entry) || FSIsRootDir(entry))
return false;
if (!DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)
&& !DirectoryMatchesOrContains(entry, B_COMMON_DIRECTORY)
&& !DirectoryMatchesOrContains(entry, B_USER_DIRECTORY))
// quick way out
return true;
@ -631,18 +635,24 @@ ConfirmChangeIfWellKnownDirectory(const BEntry *entry, const char *ifYouDoAction
BString warning;
bool requireOverride = true;
if (DirectoryMatchesOrContains(entry, B_BEOS_DIRECTORY)) {
if (DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)) {
warning.SetTo(
B_TRANSLATE("If you %ifYouDoAction the system folder or its "
"contents, you won't be able to boot " OS_NAME "! Are you sure you "
"want to do this? To %toDoAction the system folder or its contents "
"anyway, hold down the Shift key and click \"Do it\"."));
} else if (DirectoryMatches(entry, B_COMMON_DIRECTORY)) {
warning.SetTo(
B_TRANSLATE("If you %ifYouDoAction the common folder, " OS_NAME
" may not behave properly! Are you sure you want to do this? "
"To %toDoAction the common folder anyway, hold down the "
"Shift key and click \"Do it\"."));
} else if (DirectoryMatches(entry, B_USER_DIRECTORY)) {
warning .SetTo(
B_TRANSLATE("If you %ifYouDoAction the home folder, " OS_NAME
" may not behave properly! Are you sure you want to do this? "
"To %toDoAction the home anyway, click \"Do it\"."));
requireOverride = false;
"To %toDoAction the home folder anyway, hold down the "
"Shift key and click \"Do it\"."));
} else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY)
|| DirectoryMatchesOrContains(entry, B_COMMON_SETTINGS_DIRECTORY)) {
@ -2597,6 +2607,14 @@ FSIsHomeDir(const BEntry *entry)
}
bool
FSIsRootDir(const BEntry *entry)
{
BPath path(entry);
return path == "/";
}
bool
DirectoryMatchesOrContains(const BEntry *entry, directory_which which)
{

View File

@ -172,6 +172,7 @@ _IMPEXP_TRACKER bool FSIsTrashDir(const BEntry *);
_IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry *);
_IMPEXP_TRACKER bool FSIsDeskDir(const BEntry *);
_IMPEXP_TRACKER bool FSIsHomeDir(const BEntry *);
_IMPEXP_TRACKER bool FSIsRootDir(const BEntry *);
_IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList = NULL,
bool async = true);
// Deprecated

View File

@ -299,9 +299,7 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *
if (list)
list->AddItem(this);
if (!model->IsTrash() && !model->HasLocalizedName())
AddShortcut('E', 0, new BMessage(kEditItem));
AddShortcut('E', 0, new BMessage(kEditItem));
AddShortcut('O', 0, new BMessage(kOpenSelection));
AddShortcut('U', 0, new BMessage(kUnmountVolume));
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
@ -433,7 +431,8 @@ BInfoWindow::MessageReceived(BMessage *message)
case kEditItem:
{
BEntry entry(fModel->EntryRef());
if (ConfirmChangeIfWellKnownDirectory(&entry,
if (!fModel->HasLocalizedName()
&& ConfirmChangeIfWellKnownDirectory(&entry,
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'")))
fAttributeView->BeginEditingTitle();
@ -1222,9 +1221,7 @@ AttributeView::MouseDown(BPoint point)
InvertRect(fPathRect);
fTrackingState = path_track;
} else if (fTitleRect.Contains(point)) {
// You can't change the name of the trash
if (!fModel->IsTrash()
&& !fModel->HasLocalizedName()
if (!fModel->HasLocalizedName()
&& ConfirmChangeIfWellKnownDirectory(&entry,
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
@ -2039,12 +2036,12 @@ AttributeView::BuildContextMenu(BMenu *parent)
parent->AddItem(new BMenuItem(B_TRANSLATE("Open"),
new BMessage(kOpenSelection), 'O'));
if (!model.IsTrash()) {
if (!fModel->HasLocalizedName()) {
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
new BMessage(kEditItem), 'E'));
parent->AddSeparatorItem();
}
if (!model.IsDesktop() && !model.IsRoot() && !model.IsTrash()
&& !fModel->HasLocalizedName()) {
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
new BMessage(kEditItem), 'E'));
parent->AddSeparatorItem();
if (fModel->IsVolume()) {
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
new BMessage(kUnmountVolume), 'U');
@ -2056,14 +2053,16 @@ AttributeView::BuildContextMenu(BMenu *parent)
volume.SetTo(fModel->NodeRef()->device);
if (volume == boot)
item->SetEnabled(false);
} else {
parent->AddItem(new BMenuItem(B_TRANSLATE("Identify"),
new BMessage(kIdentifyEntry)));
}
} else {
}
if (!model.IsRoot() && !model.IsVolume() && !model.IsTrash())
parent->AddItem(new BMenuItem(B_TRANSLATE("Identify"),
new BMessage(kIdentifyEntry)));
if (model.IsTrash())
parent->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
new BMessage(kEmptyTrash)));
}
BMenuItem *sizeItem = NULL;
if (model.IsDirectory() && !model.IsVolume() && !model.IsRoot()) {

View File

@ -321,12 +321,7 @@ BTextWidget::StartEdit(BRect bounds, BPoseView *view, BPose *pose)
if (!IsEditable())
return;
// don't allow editing of the trash directory name
if (pose->TargetModel()->IsTrash())
return;
// don't allow editing of the "Disks" icon name
if (pose->TargetModel()->IsRoot())
if (pose->TargetModel()->HasLocalizedName())
return;
BEntry entry(pose->TargetModel()->EntryRef());