StyledEdit::StatusView Encoding context menu implemented

This commit is contained in:
Siarzhuk Zharski 2013-01-16 14:51:41 +01:00
parent c45e8003d3
commit 8a85cd4ce8
4 changed files with 37 additions and 25 deletions

View File

@ -26,6 +26,7 @@
#include <Window.h>
#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;

View File

@ -45,6 +45,7 @@ private:
BString fCellText[kStatusCellCount];
float fCellWidth[kStatusCellCount];
bool fReadOnly;
BString fEncoding;
};
#endif // STATUS_VIEW_H

View File

@ -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;
}

View File

@ -49,9 +49,10 @@ public:
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,