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),
|
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT, B_WILL_DRAW),
|
||||||
fScrollView(scrollView),
|
fScrollView(scrollView),
|
||||||
fPreferredSize(0., 0.),
|
fPreferredSize(0., 0.),
|
||||||
fReadOnly(false)
|
fReadOnly(false),
|
||||||
|
fCanUnlock(false)
|
||||||
{
|
{
|
||||||
memset(fCellWidth, 0, sizeof(fCellWidth));
|
memset(fCellWidth, 0, sizeof(fCellWidth));
|
||||||
}
|
}
|
||||||
@@ -155,7 +156,7 @@ StatusView::Draw(BRect updateRect)
|
|||||||
void
|
void
|
||||||
StatusView::MouseDown(BPoint where)
|
StatusView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (!fReadOnly)
|
if (!fReadOnly || !fCanUnlock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell];
|
float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell];
|
||||||
@@ -212,10 +213,12 @@ StatusView::SetStatus(BMessage* message)
|
|||||||
|
|
||||||
bool modified = false;
|
bool modified = false;
|
||||||
fReadOnly = false;
|
fReadOnly = false;
|
||||||
|
fCanUnlock = false;
|
||||||
if (B_OK == message->FindBool("modified", &modified) && modified) {
|
if (B_OK == message->FindBool("modified", &modified) && modified) {
|
||||||
fCellText[kFileStateCell] = B_TRANSLATE("Modified");
|
fCellText[kFileStateCell] = B_TRANSLATE("Modified");
|
||||||
} else if (B_OK == message->FindBool("readOnly", &fReadOnly) && fReadOnly) {
|
} else if (B_OK == message->FindBool("readOnly", &fReadOnly) && fReadOnly) {
|
||||||
fCellText[kFileStateCell] = B_TRANSLATE("Read-only");
|
fCellText[kFileStateCell] = B_TRANSLATE("Read-only");
|
||||||
|
if (B_OK == message->FindBool("canUnlock", &fCanUnlock) && fCanUnlock)
|
||||||
fCellText[kFileStateCell] << " " UTF8_EXPAND_ARROW;
|
fCellText[kFileStateCell] << " " UTF8_EXPAND_ARROW;
|
||||||
} else
|
} else
|
||||||
fCellText[kFileStateCell].Truncate(0);
|
fCellText[kFileStateCell].Truncate(0);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ private:
|
|||||||
BString fCellText[kStatusCellCount];
|
BString fCellText[kStatusCellCount];
|
||||||
float fCellWidth[kStatusCellCount];
|
float fCellWidth[kStatusCellCount];
|
||||||
bool fReadOnly;
|
bool fReadOnly;
|
||||||
|
bool fCanUnlock;
|
||||||
BString fEncoding;
|
BString fEncoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
#include <UnicodeChar.h>
|
#include <UnicodeChar.h>
|
||||||
#include <UTF8.h>
|
#include <UTF8.h>
|
||||||
|
#include <Volume.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
@@ -517,10 +518,17 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_STATUS:
|
case UPDATE_STATUS:
|
||||||
|
{
|
||||||
message->AddBool("modified", !fClean);
|
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);
|
fStatusView->SetStatus(message);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case UNLOCK_FILE:
|
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)
|
bool editable = (getuid() == st.st_uid && S_IWUSR & st.st_mode)
|
||||||
|| (getgid() == st.st_gid && S_IWGRP & st.st_mode)
|
|| (getgid() == st.st_gid && S_IWGRP & st.st_mode)
|
||||||
|| (S_IWOTH & st.st_mode);
|
|| (S_IWOTH & st.st_mode);
|
||||||
|
BVolume volume(ref->device);
|
||||||
|
editable = editable && !volume.IsReadOnly();
|
||||||
_SetReadOnly(!editable);
|
_SetReadOnly(!editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user