StyledEdit:supress unlock if the file is on RO volume
Show the "Read-only" status for documents that are living on read-only volumes and do not show unlock menu for such files. * The enhancement pointed out by Sergei Reznikov (Diver). Thanks!
This commit is contained in:
@@ -44,7 +44,8 @@ StatusView::StatusView(BScrollView* scrollView)
|
||||
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT, B_WILL_DRAW),
|
||||
fScrollView(scrollView),
|
||||
fPreferredSize(0., 0.),
|
||||
fReadOnly(false)
|
||||
fReadOnly(false),
|
||||
fCanUnlock(false)
|
||||
{
|
||||
memset(fCellWidth, 0, sizeof(fCellWidth));
|
||||
}
|
||||
@@ -155,7 +156,7 @@ StatusView::Draw(BRect updateRect)
|
||||
void
|
||||
StatusView::MouseDown(BPoint where)
|
||||
{
|
||||
if (!fReadOnly)
|
||||
if (!fReadOnly || !fCanUnlock)
|
||||
return;
|
||||
|
||||
float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell];
|
||||
@@ -212,11 +213,13 @@ StatusView::SetStatus(BMessage* message)
|
||||
|
||||
bool modified = false;
|
||||
fReadOnly = false;
|
||||
fCanUnlock = false;
|
||||
if (B_OK == message->FindBool("modified", &modified) && modified) {
|
||||
fCellText[kFileStateCell] = B_TRANSLATE("Modified");
|
||||
} else if (B_OK == message->FindBool("readOnly", &fReadOnly) && fReadOnly) {
|
||||
fCellText[kFileStateCell] = B_TRANSLATE("Read-only");
|
||||
fCellText[kFileStateCell] << " " UTF8_EXPAND_ARROW;
|
||||
if (B_OK == message->FindBool("canUnlock", &fCanUnlock) && fCanUnlock)
|
||||
fCellText[kFileStateCell] << " " UTF8_EXPAND_ARROW;
|
||||
} else
|
||||
fCellText[kFileStateCell].Truncate(0);
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
BString fCellText[kStatusCellCount];
|
||||
float fCellWidth[kStatusCellCount];
|
||||
bool fReadOnly;
|
||||
bool fCanUnlock;
|
||||
BString fEncoding;
|
||||
};
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <TranslationUtils.h>
|
||||
#include <UnicodeChar.h>
|
||||
#include <UTF8.h>
|
||||
#include <Volume.h>
|
||||
|
||||
|
||||
using namespace BPrivate;
|
||||
@@ -517,10 +518,17 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
|
||||
case UPDATE_STATUS:
|
||||
{
|
||||
message->AddBool("modified", !fClean);
|
||||
message->AddBool("readOnly", !fTextView->IsEditable());
|
||||
bool readOnly = !fTextView->IsEditable();
|
||||
message->AddBool("readOnly", readOnly);
|
||||
if (readOnly) {
|
||||
BVolume volume(fNodeRef.device);
|
||||
message->AddBool("canUnlock", !volume.IsReadOnly());
|
||||
}
|
||||
fStatusView->SetStatus(message);
|
||||
break;
|
||||
}
|
||||
|
||||
case UNLOCK_FILE:
|
||||
{
|
||||
@@ -1437,6 +1445,8 @@ StyledEditWindow::_LoadFile(entry_ref* ref, const char* forceEncoding)
|
||||
bool editable = (getuid() == st.st_uid && S_IWUSR & st.st_mode)
|
||||
|| (getgid() == st.st_gid && S_IWGRP & st.st_mode)
|
||||
|| (S_IWOTH & st.st_mode);
|
||||
BVolume volume(ref->device);
|
||||
editable = editable && !volume.IsReadOnly();
|
||||
_SetReadOnly(!editable);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user