Skip to content

Commit

Permalink
Node monitoring and on-the-fly textencoding change
Browse files Browse the repository at this point in the history
This work is based on the draft node monitoring implementation
created by Vlad Slepukhin during GCI 2012 and includes following:

* Refactoring of the document "Reload" feature - it replaces
"Revert to saved" one because do the same things and a bit more.
Looks like we have to keep "Reload" menu entry alive until
StyledEdit will get more functional Undo/Redo features. Reload
functionality is also heavily used in node monitoring and
on-the-fly text encoding changing. Fixes #6887;

* Support for text encoding on-the-fly switching. This make
life easier for those who lives in countires with multiple
popular 8-bit encodings. Russia is the sample of such
de facto standards' clash (KOI-8R vs CP1251 etc.);

* Node Monitoring support with alerting user in case the file
size or modification time were changed. Another alert is shown
in case edited file was removed or moved outside of the current
volume. Moving file inside of current volume silently changes
references. Choosing "Ignore" will supress new change alerts
until next Reload or Save user request;

* Do not nag user on quiting window with zero-length untitled
document. Not a Big Deal but annoys in some cases using this
editor session as temporary storage.
  • Loading branch information
siarzhuk committed Dec 10, 2012
1 parent 1d95a50 commit 0cc8d8a
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/apps/stylededit/Constants.h
Expand Up @@ -25,7 +25,7 @@ const uint32 MENU_NEW = 'MFnw';
const uint32 MENU_OPEN = 'MFop';
const uint32 MENU_SAVE = 'MSav';
const uint32 MENU_SAVEAS = 'MEsa';
const uint32 MENU_REVERT = 'MFre';
const uint32 MENU_RELOAD = 'MFrl';
const uint32 MENU_CLOSE = 'MFcl';
const uint32 MENU_PAGESETUP = 'MFps';
const uint32 MENU_PRINT = 'MFpr';
Expand Down
36 changes: 20 additions & 16 deletions src/apps/stylededit/StyledEditView.cpp
Expand Up @@ -73,8 +73,11 @@ StyledEditView::SetSuppressChanges(bool suppressChanges)


status_t
StyledEditView::GetStyledText(BPositionIO* stream)
StyledEditView::GetStyledText(BPositionIO* stream, const char* forceEncoding)
{
if (forceEncoding != NULL)
fEncoding = strcmp(forceEncoding, "auto") != 0 ? forceEncoding : "";

fSuppressChanges = true;
status_t result = BTranslationUtils::GetStyledText(stream, this,
fEncoding.String());
Expand All @@ -85,24 +88,25 @@ StyledEditView::GetStyledText(BPositionIO* stream)

BNode* node = dynamic_cast<BNode*>(stream);
if (node != NULL) {
// get encoding
if (node->ReadAttrString("be:encoding", &fEncoding) != B_OK) {
// try to read as "int32"
int32 encoding;
ssize_t bytesRead = node->ReadAttr("be:encoding", B_INT32_TYPE, 0,
&encoding, sizeof(encoding));
if (bytesRead == (ssize_t)sizeof(encoding)) {
if (encoding == 65535) {
fEncoding = "UTF-8";
} else {
const BCharacterSet* characterSet
= BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
if (characterSet != NULL)
fEncoding = characterSet->GetName();
if (forceEncoding == NULL) {
// get encoding
if (node->ReadAttrString("be:encoding", &fEncoding) != B_OK) {
// try to read as "int32"
int32 encoding;
ssize_t bytesRead = node->ReadAttr("be:encoding", B_INT32_TYPE, 0,
&encoding, sizeof(encoding));
if (bytesRead == (ssize_t)sizeof(encoding)) {
if (encoding == 65535) {
fEncoding = "UTF-8";
} else {
const BCharacterSet* characterSet
= BCharacterSetRoster::GetCharacterSetByConversionID(encoding);
if (characterSet != NULL)
fEncoding = characterSet->GetName();
}
}
}
}

// TODO: move those into BTranslationUtils::GetStyledText() as well?

// restore alignment
Expand Down
3 changes: 2 additions & 1 deletion src/apps/stylededit/StyledEditView.h
Expand Up @@ -34,7 +34,8 @@ class StyledEditView : public BTextView {

void Reset();
void SetSuppressChanges(bool suppressChanges);
status_t GetStyledText(BPositionIO* stream);
status_t GetStyledText(BPositionIO* stream,
const char* forceEncoding = NULL);
status_t WriteStyledEditFile(BFile* file);

void SetEncoding(uint32 encoding);
Expand Down

0 comments on commit 0cc8d8a

Please sign in to comment.