Skip to content

Commit

Permalink
Make RTL per document & remembered across the sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Nov 30, 2023
1 parent 0978b2e commit 119dc5e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 19 deletions.
7 changes: 1 addition & 6 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,6 @@ LRESULT Notepad_plus::init(HWND hwnd)

_mainEditView.getFocus();

if (_nativeLangSpeaker.isRTL())
{
_mainEditView.changeTextDirection(true);
_subEditView.changeTextDirection(true);
}

return TRUE;
}

Expand Down Expand Up @@ -6227,6 +6221,7 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session, bool includUntitledD

sfi._isMonitoring = buf->isMonitoringOn();
sfi._individualTabColour = docTab[k]->getIndividualTabColour(static_cast<int>(i));
sfi._isRTL = buf->isRTL();

_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument());
size_t maxLine = static_cast<size_t>(_invisibleEditView.execute(SCI_GETLINECOUNT));
Expand Down
4 changes: 0 additions & 4 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3851,16 +3851,12 @@ void Notepad_plus::command(int id)
}

_pEditView->changeTextDirection(toRTL);
_pNonEditView->changeTextDirection(toRTL);

// Wrap then !wrap to fix problem of mirror characters
bool isWraped = _pEditView->isWrap();
_pEditView->wrap(!isWraped);
_pEditView->wrap(isWraped);

_pNonEditView->wrap(!isWraped);
_pNonEditView->wrap(isWraped);

if (_pDocMap)
{
_pDocMap->changeTextDirection(toRTL);
Expand Down
6 changes: 6 additions & 0 deletions PowerEditor/src/NppIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,10 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch
if (isSnapshotMode && session._mainViewFiles[i]._backupFilePath != TEXT("") && PathFileExists(session._mainViewFiles[i]._backupFilePath.c_str()))
buf->setDirty(true);

buf->setRTL(session._mainViewFiles[i]._isRTL);
if (i == 0 && session._activeMainIndex == 0)
_mainEditView.changeTextDirection(buf->isRTL());

_mainDocTab.setIndividualTabColour(lastOpened, session._mainViewFiles[i]._individualTabColour);

//Force in the document so we can add the markers
Expand Down Expand Up @@ -2340,6 +2344,8 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch
if (isSnapshotMode && session._subViewFiles[k]._backupFilePath != TEXT("") && PathFileExists(session._subViewFiles[k]._backupFilePath.c_str()))
buf->setDirty(true);

buf->setRTL(session._subViewFiles[k]._isRTL);

_subDocTab.setIndividualTabColour(lastOpened, session._subViewFiles[k]._individualTabColour);

//Force in the document so we can add the markers
Expand Down
7 changes: 7 additions & 0 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,12 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session& s
sfi._individualTabColour = _wtoi(intStrTabColour);
}

const TCHAR* rtlStr = (childNode->ToElement())->Attribute(TEXT("RTL"));
if (rtlStr)
{
sfi._isRTL = _wcsicmp(TEXT("yes"), rtlStr) == 0;
}

for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
markNode;
markNode = markNode->NextSibling(TEXT("Mark")))
Expand Down Expand Up @@ -3588,6 +3594,7 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestamp"), static_cast<int32_t>(viewSessionFiles[i]._originalFileLastModifTimestamp.dwLowDateTime));
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestampHigh"), static_cast<int32_t>(viewSessionFiles[i]._originalFileLastModifTimestamp.dwHighDateTime));
(fileNameNode->ToElement())->SetAttribute(TEXT("tabColourId"), static_cast<int32_t>(viewSessionFiles[i]._individualTabColour));
(fileNameNode->ToElement())->SetAttribute(TEXT("RTL"), viewSessionFiles[i]._isRTL ? TEXT("yes") : TEXT("no"));

// docMap
(fileNameNode->ToElement())->SetAttribute(TEXT("mapFirstVisibleDisplayLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._firstVisibleDisplayLine), szInt64, 10));
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct sessionFileInfo : public Position
bool _isUserReadOnly = false;
bool _isMonitoring = false;
int _individualTabColour = -1;

bool _isRTL = false;
std::wstring _backupFilePath;
FILETIME _originalFileLastModifTimestamp {};

Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/ScintillaComponent/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus

// reset after initialization
_canNotify = true;

if (nppParamInst.getNativeLangSpeaker()->isRTL() && nppParamInst.getNativeLangSpeaker()->isEditZoneRTL())
_isRTL = true;
}


Expand Down
5 changes: 5 additions & 0 deletions PowerEditor/src/ScintillaComponent/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ class Buffer final {
return _docColorId;
};

bool isRTL() const { return _isRTL; };
void setRTL(bool isRTL) { _isRTL = isRTL; };

private:
int indexOfReference(const ScintillaEditView * identifier) const;

Expand Down Expand Up @@ -420,4 +423,6 @@ class Buffer final {
std::mutex _reloadFromDiskRequestGuard;

bool _isInaccessible = false;

bool _isRTL = false;
};
9 changes: 9 additions & 0 deletions PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,9 @@ void ScintillaEditView::activateBuffer(BufferID buffer, bool force)
int enabledCH = svp._isChangeHistoryEnabled ? (SC_CHANGE_HISTORY_ENABLED | SC_CHANGE_HISTORY_MARKERS) : SC_CHANGE_HISTORY_DISABLED;
execute(SCI_SETCHANGEHISTORY, enabledCH);

if (isTextDirectionRTL() != buffer->isRTL())
changeTextDirection(buffer->isRTL());

return; //all done
}

Expand Down Expand Up @@ -4214,6 +4217,9 @@ bool ScintillaEditView::isTextDirectionRTL() const

void ScintillaEditView::changeTextDirection(bool isRTL)
{
if (isTextDirectionRTL() == isRTL)
return;

long exStyle = static_cast<long>(::GetWindowLongPtr(_hSelf, GWL_EXSTYLE));
exStyle = isRTL ? (exStyle | WS_EX_LAYOUTRTL) : (exStyle & (~WS_EX_LAYOUTRTL));
::SetWindowLongPtr(_hSelf, GWL_EXSTYLE, exStyle);
Expand Down Expand Up @@ -4246,6 +4252,9 @@ void ScintillaEditView::changeTextDirection(bool isRTL)
execute(SCI_ASSIGNCMDKEY, SCK_LEFT + (SCMOD_CTRL << 16), SCI_WORDLEFT);
execute(SCI_ASSIGNCMDKEY, SCK_LEFT + ((SCMOD_SHIFT + SCMOD_CTRL) << 16), SCI_WORDLEFTEXTEND);
}

Buffer* buf = getCurrentBuffer();
buf->setRTL(isRTL);
}

generic_string ScintillaEditView::getEOLString() const
Expand Down
24 changes: 21 additions & 3 deletions PowerEditor/src/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,30 @@ void NativeLangSpeaker::init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEngl
{
TiXmlElementA *element = _nativeLangA->ToElement();
const char *rtl = element->Attribute("RTL");

if (rtl)
{
_isRTL = (strcmp(rtl, "yes") == 0);
else
_isRTL = false;

// get original file name (defined by Notpad++) from the attribute
if (_isRTL)
{
const char* editZoneRtl = element->Attribute("editZoneRTL");
if (editZoneRtl)
_isEditZoneRTL = !(strcmp(editZoneRtl, "no") == 0);
else
_isEditZoneRTL = true;
}
else
_isEditZoneRTL = false;
}
else
{
_isRTL = false;
_isEditZoneRTL = false;
}


// get original file name (defined by Notpad++) from the attribute
_fileName = element->Attribute("filename");

if (!loadIfEnglish && _fileName && stricmp("english.xml", _fileName) == 0)
Expand Down
14 changes: 9 additions & 5 deletions PowerEditor/src/localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class MenuPosition {

class NativeLangSpeaker {
public:
NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){};
void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false);
void changeConfigLang(HWND hDlg);
void changeLangTabContextMenu(HMENU hCM);
Expand All @@ -66,6 +65,10 @@ class NativeLangSpeaker {
return _isRTL;
};

bool isEditZoneRTL() const {
return _isEditZoneRTL;
};

const char * getFileName() const {
return _fileName;
};
Expand All @@ -92,10 +95,11 @@ class NativeLangSpeaker {

int messageBox(const char *msgBoxTagName, HWND hWnd, const TCHAR *message, const TCHAR *title, int msgBoxType, int intInfo = 0, const TCHAR *strInfo = NULL);
private:
TiXmlNodeA *_nativeLangA;
int _nativeLangEncoding;
bool _isRTL;
const char *_fileName;
TiXmlNodeA *_nativeLangA = nullptr;
int _nativeLangEncoding = CP_ACP;
bool _isRTL = false; // for Notepad++ GUI
bool _isEditZoneRTL = false; // for Scitilla
const char *_fileName = nullptr;
std::map<std::string, std::wstring> _shortcutMenuEntryNameMap;
};

Expand Down

0 comments on commit 119dc5e

Please sign in to comment.