Improve File Encoding StatusView cell. (Fixes #9653)

* Encoding cell of the StyledEdit StatusView is visible now only in case
  the currently opened file encoding is not equal to default UTF-8 one;
* The Encodings menu that was opened by click on this cell is removed;
* Cmd-Opt-PgDn/PgUp shortcuts are added for quick iteration through the
  list of encodings.
This commit is contained in:
Siarzhuk Zharski
2013-04-14 21:39:16 +02:00
parent 1f8d927251
commit f8668ab42f
3 changed files with 34 additions and 16 deletions
+5 -9
View File
@@ -26,7 +26,6 @@
#include <Window.h> #include <Window.h>
#include "Constants.h" #include "Constants.h"
#include "StyledEditWindow.h"
const float kHorzSpacing = 5.f; const float kHorzSpacing = 5.f;
@@ -159,7 +158,8 @@ StatusView::MouseDown(BPoint where)
if (!fReadOnly) if (!fReadOnly)
return; return;
if (where.x < fCellWidth[kPositionCell]) float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell];
if (where.x < left)
return; return;
int32 clicks = 0; int32 clicks = 0;
@@ -169,11 +169,7 @@ StatusView::MouseDown(BPoint where)
return; return;
BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
float left = fCellWidth[kPositionCell] + fCellWidth[kEncodingCell]; menu->AddItem(new BMenuItem(B_TRANSLATE("Unlock file"),
if (where.x < left)
StyledEditWindow::PopulateEncodingMenu(menu, fEncoding);
else
menu->AddItem(new BMenuItem(B_TRANSLATE("Unlock file"),
new BMessage(UNLOCK_FILE))); new BMessage(UNLOCK_FILE)));
where.x = left; where.x = left;
where.y = Bounds().bottom; where.y = Bounds().bottom;
@@ -203,7 +199,8 @@ StatusView::SetStatus(BMessage* message)
|| fEncoding.Compare("\xff\xff") == 0 || fEncoding.Compare("\xff\xff") == 0
|| fEncoding.Compare("UTF-8") == 0) || fEncoding.Compare("UTF-8") == 0)
{ {
fCellText[kEncodingCell] = "UTF-8"; // do not display default UTF-8 encoding
fCellText[kEncodingCell].Truncate(0);
fEncoding.Truncate(0); fEncoding.Truncate(0);
} else { } else {
const BCharacterSet* charset const BCharacterSet* charset
@@ -211,7 +208,6 @@ StatusView::SetStatus(BMessage* message)
fCellText[kEncodingCell] fCellText[kEncodingCell]
= charset != NULL ? charset->GetPrintName() : ""; = charset != NULL ? charset->GetPrintName() : "";
} }
fCellText[kEncodingCell] << " " UTF8_EXPAND_ARROW;
} }
bool modified = false; bool modified = false;
+27 -5
View File
@@ -47,6 +47,7 @@
#include <TextView.h> #include <TextView.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <UnicodeChar.h> #include <UnicodeChar.h>
#include <UTF8.h>
using namespace BPrivate; using namespace BPrivate;
@@ -1295,7 +1296,7 @@ StyledEditWindow::_InitWindow(uint32 encoding)
BMessage *message = new BMessage(MENU_RELOAD); BMessage *message = new BMessage(MENU_RELOAD);
message->AddString("encoding", "auto"); message->AddString("encoding", "auto");
menu->AddItem(fEncodingItem = new BMenuItem(PopulateEncodingMenu( menu->AddItem(fEncodingItem = new BMenuItem(_PopulateEncodingMenu(
new BMenu(B_TRANSLATE("Text encoding")), "UTF-8"), new BMenu(B_TRANSLATE("Text encoding")), "UTF-8"),
message)); message));
fEncodingItem->SetEnabled(false); fEncodingItem->SetEnabled(false);
@@ -1501,13 +1502,27 @@ StyledEditWindow::_ReloadDocument(BMessage* message)
return; return;
} }
const BCharacterSet* charset
= BCharacterSetRoster::GetCharacterSetByFontID(
fTextView->GetEncoding());
const char* forceEncoding = NULL; const char* forceEncoding = NULL;
if (message->FindString("encoding", &forceEncoding) != B_OK) { if (message->FindString("encoding", &forceEncoding) != B_OK) {
const BCharacterSet* charset
= BCharacterSetRoster::GetCharacterSetByFontID(
fTextView->GetEncoding());
if (charset != NULL) if (charset != NULL)
forceEncoding = charset->GetName(); forceEncoding = charset->GetName();
} else {
if (charset != NULL) {
// UTF8 id assumed equal to -1
const uint32 idUTF8 = -1;
uint32 id = charset->GetConversionID();
if (strcmp(forceEncoding, "next") == 0)
id = id == B_MS_WINDOWS_1250_CONVERSION ? idUTF8 : id + 1;
else if (strcmp(forceEncoding, "previous") == 0)
id = id == idUTF8 ? B_MS_WINDOWS_1250_CONVERSION : id - 1;
const BCharacterSet* newCharset
= BCharacterSetRoster::GetCharacterSetByConversionID(id);
if (newCharset != NULL)
forceEncoding = newCharset->GetName();
}
} }
BScrollBar* vertBar = fScrollView->ScrollBar(B_VERTICAL); BScrollBar* vertBar = fScrollView->ScrollBar(B_VERTICAL);
@@ -1888,7 +1903,7 @@ StyledEditWindow::_ShowAlert(const BString& text, const BString& label,
BMenu* BMenu*
StyledEditWindow::PopulateEncodingMenu(BMenu* menu, const char* currentEncoding) StyledEditWindow::_PopulateEncodingMenu(BMenu* menu, const char* currentEncoding)
{ {
menu->SetRadioMode(true); menu->SetRadioMode(true);
BString encoding(currentEncoding); BString encoding(currentEncoding);
@@ -1919,6 +1934,13 @@ StyledEditWindow::PopulateEncodingMenu(BMenu* menu, const char* currentEncoding)
message->AddString("encoding", "auto"); message->AddString("encoding", "auto");
menu->AddItem(new BMenuItem(B_TRANSLATE("Autodetect"), message)); menu->AddItem(new BMenuItem(B_TRANSLATE("Autodetect"), message));
message = new BMessage(MENU_RELOAD);
message->AddString("encoding", "next");
AddShortcut(B_PAGE_DOWN, B_OPTION_KEY, message);
message = new BMessage(MENU_RELOAD);
message->AddString("encoding", "previous");
AddShortcut(B_PAGE_UP, B_OPTION_KEY, message);
return menu; return menu;
} }
+2 -2
View File
@@ -49,8 +49,6 @@ public:
bool caseSensitive); bool caseSensitive);
bool IsDocumentEntryRef(const entry_ref* ref); bool IsDocumentEntryRef(const entry_ref* ref);
static BMenu* PopulateEncodingMenu(BMenu* menu,
const char* encoding);
private: private:
void _InitWindow(uint32 encoding = 0); void _InitWindow(uint32 encoding = 0);
void _LoadAttrs(); void _LoadAttrs();
@@ -79,6 +77,8 @@ private:
const BString& label, const BString& label2, const BString& label, const BString& label2,
const BString& label3, const BString& label3,
alert_type type) const; alert_type type) const;
BMenu* _PopulateEncodingMenu(BMenu* menu,
const char* encoding);
// node monitoring helper // node monitoring helper
class _NodeMonitorSuspender { class _NodeMonitorSuspender {