Skip to content

Commit

Permalink
StyledEdit::StatusView Encoding context menu implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
siarzhuk committed Jan 18, 2013
1 parent c45e800 commit 8a85cd4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
28 changes: 16 additions & 12 deletions src/apps/stylededit/StatusView.cpp
Expand Up @@ -26,6 +26,7 @@
#include <Window.h>

#include "Constants.h"
#include "StyledEditWindow.h"


const float kHorzSpacing = 5.f;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/apps/stylededit/StatusView.h
Expand Up @@ -45,6 +45,7 @@ class StatusView : public BView {
BString fCellText[kStatusCellCount];
float fCellWidth[kStatusCellCount];
bool fReadOnly;
BString fEncoding;
};

#endif // STATUS_VIEW_H
30 changes: 18 additions & 12 deletions src/apps/stylededit/StyledEditWindow.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

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


Expand Down
3 changes: 2 additions & 1 deletion src/apps/stylededit/StyledEditWindow.h
Expand Up @@ -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,
Expand Down

0 comments on commit 8a85cd4

Please sign in to comment.