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:
@@ -623,7 +623,11 @@ ConfirmChangeIfWellKnownDirectory(const BEntry *entry, const char *ifYouDoAction
|
|||||||
if (confirmedAlready && *confirmedAlready == kConfirmedAll)
|
if (confirmedAlready && *confirmedAlready == kConfirmedAll)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (FSIsDeskDir(entry) || FSIsTrashDir(entry) || FSIsRootDir(entry))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)
|
if (!DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)
|
||||||
|
&& !DirectoryMatchesOrContains(entry, B_COMMON_DIRECTORY)
|
||||||
&& !DirectoryMatchesOrContains(entry, B_USER_DIRECTORY))
|
&& !DirectoryMatchesOrContains(entry, B_USER_DIRECTORY))
|
||||||
// quick way out
|
// quick way out
|
||||||
return true;
|
return true;
|
||||||
@@ -631,18 +635,24 @@ ConfirmChangeIfWellKnownDirectory(const BEntry *entry, const char *ifYouDoAction
|
|||||||
BString warning;
|
BString warning;
|
||||||
bool requireOverride = true;
|
bool requireOverride = true;
|
||||||
|
|
||||||
if (DirectoryMatchesOrContains(entry, B_BEOS_DIRECTORY)) {
|
if (DirectoryMatchesOrContains(entry, B_SYSTEM_DIRECTORY)) {
|
||||||
warning.SetTo(
|
warning.SetTo(
|
||||||
B_TRANSLATE("If you %ifYouDoAction the system folder or its "
|
B_TRANSLATE("If you %ifYouDoAction the system folder or its "
|
||||||
"contents, you won't be able to boot " OS_NAME "! Are you sure you "
|
"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 "
|
"want to do this? To %toDoAction the system folder or its contents "
|
||||||
"anyway, hold down the Shift key and click \"Do it\"."));
|
"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)) {
|
} else if (DirectoryMatches(entry, B_USER_DIRECTORY)) {
|
||||||
warning .SetTo(
|
warning .SetTo(
|
||||||
B_TRANSLATE("If you %ifYouDoAction the home folder, " OS_NAME
|
B_TRANSLATE("If you %ifYouDoAction the home folder, " OS_NAME
|
||||||
" may not behave properly! Are you sure you want to do this? "
|
" may not behave properly! Are you sure you want to do this? "
|
||||||
"To %toDoAction the home anyway, click \"Do it\"."));
|
"To %toDoAction the home folder anyway, hold down the "
|
||||||
requireOverride = false;
|
"Shift key and click \"Do it\"."));
|
||||||
} else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY)
|
} else if (DirectoryMatchesOrContains(entry, B_USER_CONFIG_DIRECTORY)
|
||||||
|| DirectoryMatchesOrContains(entry, B_COMMON_SETTINGS_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
|
bool
|
||||||
DirectoryMatchesOrContains(const BEntry *entry, directory_which which)
|
DirectoryMatchesOrContains(const BEntry *entry, directory_which which)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ _IMPEXP_TRACKER bool FSIsTrashDir(const BEntry *);
|
|||||||
_IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry *);
|
_IMPEXP_TRACKER bool FSIsPrintersDir(const BEntry *);
|
||||||
_IMPEXP_TRACKER bool FSIsDeskDir(const BEntry *);
|
_IMPEXP_TRACKER bool FSIsDeskDir(const BEntry *);
|
||||||
_IMPEXP_TRACKER bool FSIsHomeDir(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,
|
_IMPEXP_TRACKER void FSMoveToTrash(BObjectList<entry_ref> *srcList, BList *pointList = NULL,
|
||||||
bool async = true);
|
bool async = true);
|
||||||
// Deprecated
|
// Deprecated
|
||||||
|
|||||||
@@ -299,9 +299,7 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *
|
|||||||
if (list)
|
if (list)
|
||||||
list->AddItem(this);
|
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('O', 0, new BMessage(kOpenSelection));
|
||||||
AddShortcut('U', 0, new BMessage(kUnmountVolume));
|
AddShortcut('U', 0, new BMessage(kUnmountVolume));
|
||||||
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
|
AddShortcut('P', 0, new BMessage(kPermissionsSelected));
|
||||||
@@ -433,7 +431,8 @@ BInfoWindow::MessageReceived(BMessage *message)
|
|||||||
case kEditItem:
|
case kEditItem:
|
||||||
{
|
{
|
||||||
BEntry entry(fModel->EntryRef());
|
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 'If you rename ...'"),
|
||||||
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'")))
|
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'")))
|
||||||
fAttributeView->BeginEditingTitle();
|
fAttributeView->BeginEditingTitle();
|
||||||
@@ -1222,9 +1221,7 @@ AttributeView::MouseDown(BPoint point)
|
|||||||
InvertRect(fPathRect);
|
InvertRect(fPathRect);
|
||||||
fTrackingState = path_track;
|
fTrackingState = path_track;
|
||||||
} else if (fTitleRect.Contains(point)) {
|
} else if (fTitleRect.Contains(point)) {
|
||||||
// You can't change the name of the trash
|
if (!fModel->HasLocalizedName()
|
||||||
if (!fModel->IsTrash()
|
|
||||||
&& !fModel->HasLocalizedName()
|
|
||||||
&& ConfirmChangeIfWellKnownDirectory(&entry,
|
&& ConfirmChangeIfWellKnownDirectory(&entry,
|
||||||
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
|
B_TRANSLATE_COMMENT("rename", "As in 'If you rename ...'"),
|
||||||
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
|
B_TRANSLATE_COMMENT("rename", "As in 'To rename ...'"), true)
|
||||||
@@ -2039,12 +2036,12 @@ AttributeView::BuildContextMenu(BMenu *parent)
|
|||||||
parent->AddItem(new BMenuItem(B_TRANSLATE("Open"),
|
parent->AddItem(new BMenuItem(B_TRANSLATE("Open"),
|
||||||
new BMessage(kOpenSelection), 'O'));
|
new BMessage(kOpenSelection), 'O'));
|
||||||
|
|
||||||
if (!model.IsTrash()) {
|
if (!model.IsDesktop() && !model.IsRoot() && !model.IsTrash()
|
||||||
if (!fModel->HasLocalizedName()) {
|
&& !fModel->HasLocalizedName()) {
|
||||||
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
||||||
new BMessage(kEditItem), 'E'));
|
new BMessage(kEditItem), 'E'));
|
||||||
parent->AddSeparatorItem();
|
parent->AddSeparatorItem();
|
||||||
}
|
|
||||||
if (fModel->IsVolume()) {
|
if (fModel->IsVolume()) {
|
||||||
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
|
BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
|
||||||
new BMessage(kUnmountVolume), 'U');
|
new BMessage(kUnmountVolume), 'U');
|
||||||
@@ -2056,14 +2053,16 @@ AttributeView::BuildContextMenu(BMenu *parent)
|
|||||||
volume.SetTo(fModel->NodeRef()->device);
|
volume.SetTo(fModel->NodeRef()->device);
|
||||||
if (volume == boot)
|
if (volume == boot)
|
||||||
item->SetEnabled(false);
|
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"),
|
parent->AddItem(new BMenuItem(B_TRANSLATE("Empty Trash"),
|
||||||
new BMessage(kEmptyTrash)));
|
new BMessage(kEmptyTrash)));
|
||||||
}
|
|
||||||
|
|
||||||
BMenuItem *sizeItem = NULL;
|
BMenuItem *sizeItem = NULL;
|
||||||
if (model.IsDirectory() && !model.IsVolume() && !model.IsRoot()) {
|
if (model.IsDirectory() && !model.IsVolume() && !model.IsRoot()) {
|
||||||
|
|||||||
@@ -321,12 +321,7 @@ BTextWidget::StartEdit(BRect bounds, BPoseView *view, BPose *pose)
|
|||||||
if (!IsEditable())
|
if (!IsEditable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// don't allow editing of the trash directory name
|
if (pose->TargetModel()->HasLocalizedName())
|
||||||
if (pose->TargetModel()->IsTrash())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// don't allow editing of the "Disks" icon name
|
|
||||||
if (pose->TargetModel()->IsRoot())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BEntry entry(pose->TargetModel()->EntryRef());
|
BEntry entry(pose->TargetModel()->EntryRef());
|
||||||
|
|||||||
Reference in New Issue
Block a user