From 42cb481fe45322e10415a2b8ea9ae7edac94e58f Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Tue, 3 Sep 2013 20:30:47 +0200 Subject: [PATCH] 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! --- src/apps/stylededit/StatusView.cpp | 9 ++++++--- src/apps/stylededit/StatusView.h | 1 + src/apps/stylededit/StyledEditWindow.cpp | 12 +++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/apps/stylededit/StatusView.cpp b/src/apps/stylededit/StatusView.cpp index ea29c26da8..d9501a1a38 100644 --- a/src/apps/stylededit/StatusView.cpp +++ b/src/apps/stylededit/StatusView.cpp @@ -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); diff --git a/src/apps/stylededit/StatusView.h b/src/apps/stylededit/StatusView.h index 80f92b5606..b32d6a82c0 100644 --- a/src/apps/stylededit/StatusView.h +++ b/src/apps/stylededit/StatusView.h @@ -45,6 +45,7 @@ private: BString fCellText[kStatusCellCount]; float fCellWidth[kStatusCellCount]; bool fReadOnly; + bool fCanUnlock; BString fEncoding; }; diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 4eee321e08..d2704b04c7 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -48,6 +48,7 @@ #include #include #include +#include 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); }