diff --git a/src/apps/stylededit/StatusView.cpp b/src/apps/stylededit/StatusView.cpp index edd3d9878ee..4d65f7c1476 100644 --- a/src/apps/stylededit/StatusView.cpp +++ b/src/apps/stylededit/StatusView.cpp @@ -26,6 +26,7 @@ #include #include "Constants.h" +#include "StyledEditWindow.h" const float kHorzSpacing = 5.f; @@ -158,17 +159,19 @@ StatusView::MouseDown(BPoint where) if (!fReadOnly) return; - float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell]; - if (where.x < left) + if (where.x < fCellWidth[kPositionCell]) return; + BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); + float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell]; + if (where.x < left) + StyledEditWindow::PopulateEncodingMenu(menu, fEncoding); + else + menu->AddItem(new BMenuItem(B_TRANSLATE("Unlock file"), + new BMessage(UNLOCK_FILE))); where.x = left; where.y = Bounds().bottom; - BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); - menu->AddItem(new BMenuItem(B_TRANSLATE("Unlock file"), - new BMessage(UNLOCK_FILE))); - ConvertToScreen(&where); menu->SetTargetForItems(this); menu->Go(where, true, true, true); @@ -188,20 +191,21 @@ StatusView::SetStatus(BMessage* message) fCellText[kPositionCell].SetTo(info); } - BString encoding; - if (B_OK == message->FindString("encoding", &encoding)) { + if (B_OK == message->FindString("encoding", &fEncoding)) { // sometime corresponding Int-32 "encoding" attrib is read as string :( - if (encoding.Length() == 0 - || encoding.Compare("\xff\xff") == 0 - || encoding.Compare("UTF-8") == 0) + if (fEncoding.Length() == 0 + || fEncoding.Compare("\xff\xff") == 0 + || fEncoding.Compare("UTF-8") == 0) { fCellText[kEncodingCell] = "UTF-8"; + fEncoding.Truncate(0); } else { const BCharacterSet* charset - = BCharacterSetRoster::FindCharacterSetByName(encoding); + = BCharacterSetRoster::FindCharacterSetByName(fEncoding); fCellText[kEncodingCell] = charset != NULL ? charset->GetPrintName() : ""; } + fCellText[kEncodingCell] << " " UTF8_EXPAND_ARROW; } bool modified = false; diff --git a/src/apps/stylededit/StatusView.h b/src/apps/stylededit/StatusView.h index fcf542f3033..80f92b56062 100644 --- a/src/apps/stylededit/StatusView.h +++ b/src/apps/stylededit/StatusView.h @@ -45,6 +45,7 @@ class StatusView : public BView { BString fCellText[kStatusCellCount]; float fCellWidth[kStatusCellCount]; bool fReadOnly; + BString fEncoding; }; #endif // STATUS_VIEW_H diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp index 9e08d4f5ad9..7732017d45e 100644 --- a/src/apps/stylededit/StyledEditWindow.cpp +++ b/src/apps/stylededit/StyledEditWindow.cpp @@ -287,8 +287,8 @@ StyledEditWindow::MessageReceived(BMessage* message) case MSG_REPLACE_ALL: { message->FindBool("casesens", &fCaseSensitive); - message->FindString("FindText",&fStringToFind); - message->FindString("ReplaceText",&fReplaceString); + message->FindString("FindText", &fStringToFind); + message->FindString("ReplaceText", &fReplaceString); bool allWindows; message->FindBool("allwindows", &allWindows); @@ -1291,7 +1291,9 @@ StyledEditWindow::_InitWindow(uint32 encoding) fWrapItem->SetMarked(true); fWrapItem->SetShortcut('W', B_OPTION_KEY); - menu->AddItem(fEncodingItem = _MakeEncodingMenuItem()); + menu->AddItem(fEncodingItem = new BMenuItem(PopulateEncodingMenu( + new BMenu(B_TRANSLATE("Text encoding")), "UTF-8"), + new BMessage(MENU_RELOAD))); fEncodingItem->SetEnabled(false); menu->AddSeparatorItem(); @@ -1564,7 +1566,7 @@ StyledEditWindow::_UnlockFile() status_t status = dir.InitCheck(); if (status != B_OK) return status; - + status = entry.InitCheck(); if (status != B_OK) return status; @@ -1578,7 +1580,7 @@ StyledEditWindow::_UnlockFile() status = file.GetStat(&st); if (status != B_OK) return status; - + st.st_mode |= S_IWUSR; status = file.SetPermissions(st.st_mode); if (status == B_OK) @@ -1882,10 +1884,13 @@ StyledEditWindow::_ShowAlert(const BString& text, const BString& label, } -BMenuItem* -StyledEditWindow::_MakeEncodingMenuItem() +BMenu* +StyledEditWindow::PopulateEncodingMenu(BMenu* menu, const char* currentEncoding) { - BMenu* menu = new BMenu(B_TRANSLATE("Text encoding")); + menu->SetRadioMode(true); + BString encoding(currentEncoding); + if (encoding.Length() == 0) + encoding.SetTo("UTF-8"); BCharacterSetRoster roster; BCharacterSet charset; @@ -1899,7 +1904,10 @@ StyledEditWindow::_MakeEncodingMenuItem() BMessage *message = new BMessage(MENU_RELOAD); if (message != NULL) { message->AddString("encoding", charset.GetName()); - menu->AddItem(new BMenuItem(name, message)); + BMenuItem* item = new BMenuItem(name, message); + if (encoding.Compare(charset.GetName()) == 0) + item->SetMarked(true); + menu->AddItem(item); } } @@ -1908,9 +1916,7 @@ StyledEditWindow::_MakeEncodingMenuItem() message->AddString("encoding", "auto"); menu->AddItem(new BMenuItem(B_TRANSLATE("Autodetect"), message)); - menu->SetRadioMode(true); - - return new BMenuItem(menu, new BMessage(MENU_RELOAD)); + return menu; } diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h index ae8aac3efa0..af8dc04f4b7 100644 --- a/src/apps/stylededit/StyledEditWindow.h +++ b/src/apps/stylededit/StyledEditWindow.h @@ -49,9 +49,10 @@ class StyledEditWindow : public BWindow { bool caseSensitive); bool IsDocumentEntryRef(const entry_ref* ref); + static BMenu* PopulateEncodingMenu(BMenu* menu, + const char* encoding); private: void _InitWindow(uint32 encoding = 0); - BMenuItem* _MakeEncodingMenuItem(); void _LoadAttrs(); void _SaveAttrs(); status_t _LoadFile(entry_ref* ref,