diff -rup texmaker-1.9.2-Original/blockdata.h texmaker-1.9.2-03DEC2009-Linux/blockdata.h --- texmaker-1.9.2-Original/blockdata.h 2009-06-01 12:22:23.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/blockdata.h 2009-08-01 22:29:54.000000000 +0430 @@ -26,6 +26,8 @@ struct BlockData : public QTextBlockUser { block.setUserData(this); } QList code; + bool bidiState;//Add by S. R. Alavizadeh + inline BlockData() : parenthesisMatchStart(-1), parenthesisMatchEnd(-1) {} QList parentheses; diff -rup texmaker-1.9.2-Original/configdialog.ui texmaker-1.9.2-03DEC2009-Linux/configdialog.ui --- texmaker-1.9.2-Original/configdialog.ui 2009-06-17 19:10:49.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/configdialog.ui 2009-11-22 12:09:39.000000000 +0330 @@ -66,7 +66,7 @@ - 0 + 1 @@ -100,7 +100,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -127,7 +127,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -154,7 +154,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -181,7 +181,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -208,7 +208,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -235,7 +235,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -262,7 +262,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -289,7 +289,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -316,7 +316,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -343,7 +343,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -370,7 +370,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -397,7 +397,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -424,7 +424,7 @@ - + :/images/fileopen.png:/images/fileopen.png @@ -509,7 +509,7 @@ - LaTeX + Asymptote + LaTeX + dvips + View PS + LaTeX + Asymptote + LaTeX + View PS @@ -589,7 +589,7 @@ Editor - + @@ -611,6 +611,13 @@ + + + + Show Line Numbers + + + @@ -635,6 +642,13 @@ + + + + Bi-Di Support + + + @@ -645,13 +659,6 @@ - - - - Show Line Numbers - - - @@ -821,15 +828,15 @@ - + Spelling dictionary - - + + 6 @@ -852,14 +859,14 @@ - + :/images/fileopen.png:/images/fileopen.png - + Inline Spell Checking @@ -869,7 +876,7 @@ - + @@ -879,21 +886,21 @@ - + Qt::Horizontal - + Shortcuts - + @@ -907,7 +914,7 @@ - + Qt::Vertical @@ -920,6 +927,50 @@ + + + + + + AutoSave + + + + + + + every: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignCenter + + + 1 + + + 120 + + + 5 + + + + + + + minute(s) + + + + + @@ -981,30 +1032,30 @@ lineEditLatex - pushButtonLatex lineEditDvips - pushButtonDvips lineEditBibtex - pushButtonBibtex lineEditMakeindex - pushButtonMakeindex lineEditDviviewer - pushButtonDviviewer lineEditPsviewer - pushButtonPsviewer lineEditPdflatex - pushButtonPdflatex lineEditDvipdfm - pushButtonDvipdfm lineEditPs2pdf - pushButtonPs2pdf lineEditPdfviewer - pushButtonPdfviewer lineEditMetapost - pushButtonMetapost lineEditGhostscript - pushButtonGhostscript lineEditAsymptote + pushButtonLatex + pushButtonDvips + pushButtonBibtex + pushButtonMakeindex + pushButtonDviviewer + pushButtonPsviewer + pushButtonPdflatex + pushButtonDvipdfm + pushButtonPs2pdf + pushButtonPdfviewer + pushButtonMetapost + pushButtonGhostscript pushButtonAsymptote radioButton1 radioButton2 @@ -1012,15 +1063,16 @@ radioButton4 radioButton5 radioButton7 - radioButton8 radioButton6 + radioButton8 lineEditUserquick comboBoxFont checkBoxWordwrap + checkBoxLinenumber spinBoxSize checkBoxCompletion + checkBoxBidiEnabled comboBoxEncoding - checkBoxLinenumber pushButtonColorMath pushButtonColorCommand pushButtonColorKeyword @@ -1032,9 +1084,7 @@ cancelButton contentsWidget - - - + okButton diff -rup texmaker-1.9.2-Original/latexeditor.cpp texmaker-1.9.2-03DEC2009-Linux/latexeditor.cpp --- texmaker-1.9.2-Original/latexeditor.cpp 2009-06-01 13:40:05.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/latexeditor.cpp 2009-11-30 21:41:42.000000000 +0330 @@ -31,7 +31,8 @@ #include #include #include "blockdata.h" - +#include //temp//new +#include //temp LatexEditor::LatexEditor(QWidget *parent,QFont & efont, QColor colMath, QColor colCommand, QColor colKeyword,bool inlinespelling,QString ignoredWords,Hunspell *spellChecker) : QTextEdit(parent),c(0) { QPalette p = palette(); @@ -66,6 +67,12 @@ if (wordsfile.open(QFile::ReadOnly)) } /********************************/ +oldLayoutDir=curLayoutDir=QApplication::keyboardInputDirection(); //add by S. R. Alavizadeh +layoutChanged = false; +shift = false; +backSpaceFlag=false;//new +appendLRM=false;//new + highlighter = new LatexHighlighter(document(),inlinespelling,ignoredWords,spellChecker); highlighter->setColors(colMath,colCommand,colKeyword); @@ -115,6 +122,14 @@ QTextEdit::paintEvent(event); void LatexEditor::contextMenuEvent(QContextMenuEvent *e) { + //if (e->modifiers()==Qt::ControlModifier) + //{ + // QMenu *bidiMenu = createStandardContextMenu(); + // bidiMenu->exec(e->globalPos()); + // delete bidiMenu; + // return; + //} + QMenu *menu=new QMenu(this); QAction *a; /*******************************************/ @@ -216,12 +231,50 @@ a = menu->addAction(tr("Select All"), th a->setShortcut(Qt::CTRL+Qt::Key_A); a->setEnabled(!document()->isEmpty()); menu->addSeparator(); +/*****************************/ //add by S. R. Alavizadeh +if (bidiEnabled) + { + a = menu->addAction(tr("insert LRM"), this, SLOT(contextMenuAddLRM())); + //a->setShortcut(Qt::CTRL+Qt::Key_L); + a->setEnabled(true); + ///////////////////////////////////////////////////////////////// + if (!textCursor().hasSelection()) + { + a = menu->addAction(tr("insert LTR text"), this, SLOT(contextMenuAddLRE())); + a->setShortcut(Qt::CTRL+Qt::Key_Period); + } + else + a = menu->addAction(tr("consider as LTR text"), this, SLOT(contextMenuAddLRE())); + ////a->setShortcut(Qt::CTRL+Qt::Key_L); + //a->setEnabled(true); + // a = menu->addAction(tr("insert RLE"), this, SLOT(contextMenuAddRLE())); + ////a->setShortcut(Qt::CTRL+Qt::Key_L); + //a->setEnabled(true); + // a = menu->addAction(tr("insert PDF"), this, SLOT(contextMenuAddPDF())); + ////a->setShortcut(Qt::CTRL+Qt::Key_L); + //a->setEnabled(true); + ///////////////////////////////////////////////////////////// + a = menu->addAction(tr("Remove Unicode Control Characters"), this, SLOT(remLRMfromSelection())); + a->setEnabled(textCursor().hasSelection()); + menu->addSeparator(); + } +/****************************/ a = menu->addAction(tr("Check Spelling Word"), this, SLOT(checkSpellingWord())); a->setEnabled(!document()->isEmpty()); a = menu->addAction(tr("Check Spelling Selection"), this, SLOT(checkSpellingDocument())); a->setEnabled(textCursor().hasSelection()); a = menu->addAction(tr("Check Spelling Document"), this, SLOT(checkSpellingDocument())); a->setEnabled(!document()->isEmpty() && !textCursor().hasSelection()); +/*******************************************/ +//add by S. R. Alavizadeh +#if defined ( Q_WS_WIN ) +QFileInfo SumtaraFS(QCoreApplication::applicationDirPath()+"/SumatraForwardsearch.exe"); + +menu->addSeparator(); +a = menu->addAction(tr("Jump to PDF"), this, SLOT(callForwardSearch())); +a->setVisible(!document()->isEmpty() && bidiEnabled && SumtaraFS.exists()); +#endif +/*******************************************/ menu->exec(e->globalPos()); delete menu; } @@ -337,6 +390,13 @@ if (cur.hasSelection()) while ( cur.position() < end && go) { cur.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor); + //add by S. R. Alavizadeh + while (cur.selectedText()==QString(QChar(LRM)) && cur.position() < end) + { + cur.clearSelection(); + cur.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor); + } + if (cur.selectedText()=="%") { cur.removeSelectedText(); @@ -481,6 +541,60 @@ if (word.right(1)!=sword.right(1)) word= return word; } +//add by S. R. Alavizadeh//new +void LatexEditor::mousePressEvent( QMouseEvent *ev ) +{ + layoutChanged = true; + curLayoutDir = QApplication::layoutDirection(); + if (curLayoutDir == Qt::RightToLeft) + oldLayoutDir = Qt::LeftToRight; + else + oldLayoutDir = Qt::RightToLeft; + QTextEdit::mousePressEvent(ev); +} + +//add by S. R. Alavizadeh//new +bool LatexEditor::event(QEvent *e) +{ +if (bidiEnabled) + { + if ( e->type() == QEvent::KeyboardLayoutChange ) + { + kbdLayoutChangingCanEmited = true; + layoutChanged = true; + //oldLayoutDir = curLayoutDir; + //curLayoutDir = QApplication::keyboardInputDirection(); + //QMessageBox::information(0,"QEvent",tr("KeyboardLayout=%1").arg(QApplication::keyboardInputDirection())); + } + //textCursor().insertText(QChar(LRM)); + //QMessageBox::information(0,"KeyPressEvent",tr("KeyboardLayout=%1").arg(QApplication::keyboardInputDirection())); + } +return QTextEdit::event(e); +} +//void LatexEditor::keyReleaseEvent( QKeyEvent *e)//add by S. R. Alavizadeh//new +//{ +// +// QString temp=e->text(); +// QChar::Category tempCat=temp.at(0).category(); +// if (tempCat == QChar::Symbol_Currency) +// QMessageBox::information(0,"Currency",tr("Key=%1").arg(QApplication::keyboardInputDirection())); +// +// QTextEdit::keyReleaseEvent(e);return; +//if (bidiEnabled) +// { +//// if ( e->matches(Qt::SHIFT+Qt::Key_4) ) +// { +// e->ignore(); +// textCursor().insertText(QChar('$')); +// +// //layoutChanged = true; +// //oldLayoutDir = curLayoutDir; +// //curLayoutDir = QApplication::keyboardInputDirection(); +// } +// //textCursor().insertText(QChar(LRM)); +// //QMessageBox::information(0,"KeyPressEvent",tr("KeyboardLayout=%1").arg(QApplication::keyboardInputDirection())); +// } +//} void LatexEditor::keyPressEvent ( QKeyEvent * e ) { if (c && c->popup()->isVisible()) @@ -500,6 +614,277 @@ if (c && c->popup()->isVisible()) } } +//add by S. R. Alavizadeh [start] +if (bidiEnabled) + { + if ( e->modifiers()==Qt::ShiftModifier ) + { + if (e->nativeVirtualKey() == Qt::Key_4) + { +#if defined( Q_WS_WIN ) + e->ignore(); + Qt::LayoutDirection tmpLayoutDir = curLayoutDir; + QString text; + if (QApplication::keyboardInputDirection()==Qt::RightToLeft) + text=QChar(LRM)+QString("$ "); + else + text=QChar(LRM)+QString("$")+QChar(LRM); + + +//////////////////// Win32 API ////////////////////////// + HKL loadedLayout=LoadKeyboardLayout(L"00000409" ,KLF_ACTIVATE);//load LANG_ENGLISH + ActivateKeyboardLayout(loadedLayout, 0); +//////////////////////////////////////////////////////// + QTextCursor tc=textCursor(); + tc.insertText(text);//+QChar(LRM) + //tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); + setTextCursor(tc); + return; + //QString text=e->text(); + //QMessageBox::information(0,"Qt::Key_Dollar",tr("Qt::Key_Dollar\ne->text()=*%1*\ne->key()=*%4*\ne->nativeVirtualKey()=*%2*\ne->nativeScanCode()=*%3*").arg(text).arg(e->nativeVirtualKey()).arg(e->nativeScanCode()).arg(e->key())); +#endif + } + } + + if (e->key() == Qt::Key_Up)//new + { + QTextCursor ttc=textCursor(); + int curLinPos=ttc.position(); + QTextCursor::MoveMode ttcMM; + if ( QApplication::keyboardModifiers() == Qt::ShiftModifier ) + ttcMM=QTextCursor::KeepAnchor; + else + ttcMM=QTextCursor::MoveAnchor; + ttc.movePosition(QTextCursor::Up, ttcMM); + int tmpPos=ttc.position(); + if ( tmpPos == curLinPos && linefromblock(textCursor().block())!=1 ) + { + ttc.movePosition(QTextCursor::Left, ttcMM); + ttc.movePosition(QTextCursor::Up, ttcMM); + ttc.movePosition(QTextCursor::Right, ttcMM); + } + setTextCursor(ttc); + e->ignore(); + return; + } + + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)//new + { + if (curLayoutDir == Qt::LeftToRight) textCursor().insertText(QChar(LRM)); + } + if (e->key() == Qt::Key_Left)//new + { + noLRMneed = true;//new + disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + QTextCursor tc = textCursor(); + if (!tc.hasSelection()) + { + int curPos = tc.position(); + int oldPos=curPos; + tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + curPos = tc.position(); + if (tc.hasSelection()) + { + int index; + if (curPos >= oldPos) index=tc.selectedText().size()-1; + else index=0; + QString tempCh,tempSel; + tempCh=tc.selectedText().at(index); + tempSel=tc.selectedText(); + QChar tempQCh=tc.selectedText().at(index); + while (tc.selectedText().at(index)==QChar(LRM) && !tc.atEnd() && !tc.atStart() ) + { + oldPos=curPos; + tempCh=tc.selectedText().at(index); + tempSel=tc.selectedText(); + tempQCh=tc.selectedText().at(index); + tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + curPos = tc.position(); + if (curPos >= oldPos) index=tc.selectedText().size()-1; + else index=0; + } + if ( tc.selectedText().at(index)!=QChar(LRM) )//new//if + tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + setTextCursor(tc); + } + } + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + } + if (e->key() == Qt::Key_Right)//new + { + noLRMneed = true;//new + disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + QTextCursor tc = textCursor(); + int curPos = tc.position(); + int oldPos=curPos; + tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + curPos = tc.position(); + if (tc.hasSelection()) + { + int index; + if (curPos >= oldPos) index=tc.selectedText().size()-1; + else index=0; + while (tc.selectedText().at(index)==QChar(LRM) && !tc.atEnd() && !tc.atStart() ) + { + oldPos=curPos; + tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + curPos = tc.position(); + if (curPos >= oldPos) index=tc.selectedText().size()-1; + else index=0; + } + if ( tc.selectedText().at(index)!=QChar(LRM) )//new//if + tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + setTextCursor(tc); + } + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + } + if (e->key() == Qt::Key_Backspace) + backSpaceFlag = true; + else + backSpaceFlag = false; + if (e->key() == Qt::Key_Space /*|| e->key() == Qt::Key_Tab*/)//new//Key_Tab has very bad effect in LTR text! + { + appendLRM=false; + noLRMneed = true;//new + disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + QTextCursor tc = textCursor(); + if (tc.hasSelection()) tc.removeSelectedText(); + int curPos = tc.position(); + int oldPos=curPos; + tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); + curPos = tc.position(); + QString tempSel;//temp + QChar tempCh;//temp + if (tc.hasSelection()) + { + int sizee=tc.selectedText().size(); + int countLRM=tc.selectedText().count(QChar(LRM)); + tempSel=tc.selectedText(); + tempCh=tc.selectedText().at(0);//temp + bool temp1=false,temp2=false; + if (tc.selectedText().at(0)==QChar(LRM)) + temp1=true; + if (tc.selectedText()==QChar(LRM)) + temp2=true; + while (tc.selectedText().at(0)==QChar(LRM) && !tc.atEnd() && !tc.atStart() ) + { + tempCh=tc.selectedText().at(0);//temp + oldPos=curPos; + tc.clearSelection(); + tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); + tempSel=tc.selectedText();//temp + sizee=tc.selectedText().size(); + countLRM=tc.selectedText().count(QChar(LRM)); + curPos = tc.position(); + } + if ( tc.selectedText().at(0)!=QChar(LRM) )//&& (tc.atEnd() || tc.atStart()) ) + tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); + tc.clearSelection(); + setTextCursor(tc); + } + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + } +/////////////////////////////////////////////////////////////////////// + /////////////////////////////// +//////////////////// + //if (false) + //{ + // if (flagAutoLRM && false) + // { + // if (e->key() == Qt::Key_Space || e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) + // { + // noLRMneed = true;//new + // QTextCursor tc=textCursor(); + // if (!tc.hasSelection()) + // { + // disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // int pos=tc.position(); + // QString tmpWord=""; + // tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); + // tmpWord = tc.selectedText(); + // tc.setPosition(pos, QTextCursor::MoveAnchor); + // if (!tmpWord.isEmpty()) + // { + // if ( !(tmpWord.at(0)==QChar(LRM) || tmpWord.at(0)=='(' || tmpWord.at(0)==')' || tmpWord.at(0)==' ' || isItDirR(tmpWord.at(0)) ) ) + // { + // tc.insertText(QChar(LRM)); + // } + // } + // connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // } + // } + // } + // + // if (e->key() == Qt::Key_Left) + // { + // noLRMneed = true;//new + // disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // QTextCursor tc = textCursor(); + // tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + // if (tc.hasSelection()) + // { + // if (tc.selectedText()==QChar(LRM)) setTextCursor(tc); + // else + // { + // tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + // setTextCursor(tc); + // } + // } + // if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // } + // if (e->key() == Qt::Key_Right) + // { + // noLRMneed = true;//new + // disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // QTextCursor tc = textCursor(); + // tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + // if (tc.hasSelection()) + // { + // if (tc.selectedText()==QChar(LRM)) setTextCursor(tc); + // else + // { + // tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + // setTextCursor(tc); + // } + // } + // if(flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // } + // if (e->key() == Qt::Key_Backspace) + // { + // disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // noLRMneed = true; + // QTextCursor tc = textCursor(); + // if (!tc.hasSelection()) + // { + // int pos = tc.position(); + // if (tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor)) + // { + // bool flag = false; + // while (tc.selectedText().at(0)==QChar(LRM)) + // { + // flag = true; + // if (!tc.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor)) break; + // } + // if (flag) + // { + // if (tc.selectedText().at(0)==QChar(LRM)) + // tc.removeSelectedText(); + // else + // { + // tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor); + // tc.removeSelectedText(); + // } + // } + // else + // tc.setPosition(pos, QTextCursor::MoveAnchor); + // } + // setTextCursor(tc); + // } + // if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // } + //} + } +//add by S. R. Alavizadeh [end] //bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E //if (!c || !isShortcut) // { @@ -573,6 +958,7 @@ bool hasModifier = (e->modifiers() & ( Q //bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift; QString completionPrefix = textUnderCursor(); +completionPrefix.remove(QChar(LRM),Qt::CaseInsensitive);//it just skips LRM in completer//Add by S. R. Alavizadeh if (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3 || eow.contains(e->text().right(1))) //if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3 || eow.contains(e->text().right(1)))) @@ -657,8 +1043,16 @@ if (completion.contains(rbb)) } else { - tc.insertText(insert_word); - if (offset!=0) tc.setPosition(pos+offset+1,QTextCursor::MoveAnchor); + if (flagAutoLRM && bidiEnabled) + { + tc.insertText(QChar(LRM)+insert_word+QChar(LRM));//add by S. R. Alavizadeh + if (offset!=0) tc.setPosition(pos+offset+1+1,QTextCursor::MoveAnchor);//'+1' for added LRM + } + else + { + tc.insertText(insert_word); + if (offset!=0) tc.setPosition(pos+offset+1,QTextCursor::MoveAnchor); + } } setTextCursor(tc); } @@ -680,4 +1074,602 @@ void LatexEditor::activateInlineSpell(bo inlinecheckSpelling=enable; } +//add by S. R. Alavizadeh +void LatexEditor::contextMenuAddLRM() +{ +disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +bool MODIFIED = document()->isModified();//new +QString word; +int startSel,endSel,pos,anch; +QTextCursor curCursor, tmpCursor; +curCursor = tmpCursor = textCursor(); +if ( textCursor().hasSelection() ) +{ + pos = textCursor().position(); + endSel = textCursor().anchor(); + startSel = textCursor().blockNumber(); + curCursor.setPosition( endSel, QTextCursor::MoveAnchor ); + setTextCursor(curCursor); + endSel = textCursor().blockNumber(); + if (endSel != startSel) + { + tmpCursor.clearSelection(); + setTextCursor(tmpCursor); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + curCursor.setPosition( pos, QTextCursor::KeepAnchor ); + setTextCursor(curCursor); + word = textCursor().selectedText(); +} +else + { + word = QChar(LRM); + textCursor().insertText(word); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } +//Remove Unicode Control Characters +word.remove(QChar(LRM)).remove(QChar(RLM)); +word = (word.append(QChar(LRM))).prepend(QChar(LRM)); +textCursor().beginEditBlock(); +textCursor().removeSelectedText(); +textCursor().insertText(word); +textCursor().endEditBlock(); +setTextCursor(tmpCursor); +document()->setModified( MODIFIED ); +if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +} + +//add by S. R. Alavizadeh +bool LatexEditor::isItDirR(QChar ch) +{ +//if(!(ch.direction() == QChar::DirAL || ch.direction() == QChar::DirR)) return false; +//else return true; +if (ch=='\"' || ch=='~') + return true; +if ( ch.direction() == QChar::DirON || ch.direction() == QChar::DirET || ch.direction() == QChar::DirL || ch.direction() == QChar::DirEN ) //new + return false; +else + return true; +} +//add by S. R. Alavizadeh +void LatexEditor::remLRMfromSelection() +{ +emit removeLRM(); +} +void LatexEditor::visibleLines(int flag) +{ +disconnect(verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT(visibleLines(int))); +if (!bidiEnabled) return; +/////////////////////////////////////// +int yOffset = verticalScrollBar()->value(); +int i = 0; +QTextBlock p = document()->begin(); +bool firstTime = true;//new +while ( p.isValid() ) + { + QPointF point = p.layout()->position(); + if ( point.y() + 20 - yOffset < 0 ) + { + ++i; + p = p.next(); + continue; + } + if (firstTime) //new + { + startLine = i; + firstTime = false; + } + if ( (int)(point.y()) - yOffset > height() ) break; + i++; + p = p.next(); + } +endLine = i; + +if (startLine < 0) startLine = 0; +if (endLine>numoflines()-1) endLine = numoflines()-1; +if (flag >= 0) + { + bool MODIFIED = document()->isModified(); + emit bidiVisibleLines(); + verticalScrollBar()->setValue(flag); + document()->setModified( MODIFIED ); + } +connect(verticalScrollBar(), SIGNAL( valueChanged( int ) ), this, SLOT(visibleLines(int))); +} + +void LatexEditor::addLRMinTyping() +{ +if (!flagAutoLRM) return; +if (parenMatcherStarted) return; +disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +if (!bidiEnabled) return; +bool tmpFlag=true, tmpAppendLRM=false; +QTextCharFormat LTRFormat; +// QTextCursor tmpCur = textCursor(); +//if (isItDirR( document()->characterAt(tmpCur.position()-1) )) +// QMessageBox::information(this,"addLRMinTyping",tr("*%1*=Right To Left").arg( document()->characterAt(tmpCur.position()-1) )); +//else +// QMessageBox::information(this,"addLRMinTyping",tr("*%1*=Left To Right").arg( document()->characterAt(tmpCur.position()-1) )); +//temp +kbdLayoutChangingCanEmited=false; +if (kbdLayoutChangingCanEmited) + { + if ( layoutChanged ) + { + curLayoutDir = QApplication::keyboardInputDirection(); + if (oldLayoutDir != curLayoutDir) + { + oldLayoutDir = curLayoutDir; + QTextCursor tmpCur = textCursor(); + QTextBlock currentBlock = tmpCur.block(); + if (bidiMode==3) + { + BlockData *thisBlockData = static_cast(currentBlock.userData()); + if (thisBlockData) thisBlockData->bidiState=false; + else + { + thisBlockData = new BlockData; + thisBlockData->bidiState = false; + currentBlock.setUserData(thisBlockData); + } + QTextBlockFormat tmpBlockFormat = tmpCur.blockFormat(); + tmpBlockFormat.setLayoutDirection( Qt::RightToLeft ); + tmpCur.beginEditBlock(); + tmpCur.setBlockFormat( tmpBlockFormat ); + LTRFormat = tmpCur.charFormat();//new + tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); + if (curLayoutDir == Qt::RightToLeft) + tmpCur.insertText(QString(QChar(LRM))+"%\n"); + else + tmpCur.insertText("%\n"+QString(QChar(LRM))); + tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor); + tmpCur.insertText(QChar(LRM)); + tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); + tmpCur.endEditBlock(); + setTextCursor(tmpCur); + connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + ////////////////////////////////////////////////////// + tmpCur.beginEditBlock(); + int tmpPos = tmpCur.position();//new + tmpCur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); + + QString curLine = tmpCur.selectedText(); + QStringList lineWords = curLine.split("",QString::SkipEmptyParts); + /*bool appendLRM=false;*/ + int lineSize=lineWords.size()-1; + QString ch; + if ( lineSize>=0 ) ch = lineWords.at(lineSize); + else ch = ""; + + if (!ch.isEmpty()) + { + if ( curLayoutDir == Qt::LeftToRight ) + { + if ( !ch.at(0).isSpace() ) + { + //new + int tmpIndex=lineSize; + QString tempp=lineWords.at(tmpIndex); + while (tmpIndex-1>=0) + { + tempp=lineWords.at(tmpIndex-1); + bool dirIsR=isItDirR( lineWords.at(tmpIndex-1).at(0) ); + if ( !isItDirR( lineWords.at(tmpIndex-1).at(0) ) ) + { + --tmpIndex; + } + else break; + } + lineWords[tmpIndex].prepend(QChar(LRM)); + lineWords[lineSize].append(QChar(LRM)); + //lineWords[lineSize].prepend(QChar(LRM)).append(QChar(LRM));//new//append is idea + appendLRM=true; + } + else + { + oldLayoutDir=Qt::RightToLeft;//new//Should be better + //lineWords[lineSize].append(QChar(LRM));//There is a better method + } + } + else + { + if (appendLRM) + { + lineWords[lineSize].prepend(QChar(LRM)); + appendLRM=false; + tmpCur.insertText(lineWords.join("")); + tmpCur.clearSelection(); + tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); + if (tmpCur.hasSelection()) + { + if (tmpCur.selectedText().at(0)==QChar(LRM)) + tmpCur.removeSelectedText(); + } + tmpFlag=false; + } + } + //else appendLRM=true;//new + + //else //if I use better method above else part isn't needed + // { + // for (int je = lineSize-1; je>=0;--je) + // { + // if ( lineWords.at(je)!=" " && lineWords.at(je)!="\t" ) + // { + // lineWords[je].append(QChar(LRM)); + // break; + // } + // } + // } + if (tmpFlag) + { + tmpCur.insertText(lineWords.join("")); + tmpCur.clearSelection(); + } + if (appendLRM) tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);//new + } + tmpCur.endEditBlock(); + setTextCursor(tmpCur); + } + } + } +else //else <- if (kbdLayoutChangingCanEmited) + { + if (backSpaceFlag) + { + connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + QTextCursor tmpCur = textCursor(); + QTextBlock currentBlock = tmpCur.block(); + if (bidiMode==3) + { + connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + ////////////////////////////////////////////////////// + tmpCur.beginEditBlock(); + int tmpPos = tmpCur.position();//new + tmpCur.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); + + QString curLine = tmpCur.selectedText(); + QStringList lineWords = curLine.split("",QString::SkipEmptyParts); + int lineSize=lineWords.size()-1; + QString ch; + if ( lineSize>=0 ) ch = lineWords.at(lineSize); + else ch = ""; + + if (!ch.isEmpty()) + { + bool chIsMirrored=ch.at(0).hasMirrored(); + if (appendLRM) + chIsMirrored=false; + bool test=isItDirR(QChar(LRM)); + if ( !isItDirR( ch.at(0) ) && !chIsMirrored ) + { + //new + int tmpIndex=lineSize; + QString tempp=lineWords.at(tmpIndex); + while (tmpIndex-1>=0) + { + tempp=lineWords.at(tmpIndex-1); + bool dirIsR=isItDirR( lineWords.at(tmpIndex-1).at(0) ); + if ( !isItDirR( lineWords.at(tmpIndex-1).at(0) ) ) + { + --tmpIndex; + } + else break; + } + for (int i=tmpIndex;i=0;--je) + // { + // if ( lineWords.at(je)!=" " && lineWords.at(je)!="\t" ) + // { + // lineWords[je].append(QChar(LRM)); + // break; + // } + // } + // } + if (tmpFlag) + { + tmpCur.insertText(lineWords.join("")); + tmpCur.clearSelection(); + setTextCursor(tmpCur);//new//temp + } + if ( !isItDirR( ch.at(0) ) && !chIsMirrored && !appendLRM) + { + int pos1=tmpCur.position(); + //bool mo=tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);//new + int pos2=tmpCur.position(); + //bool mo1=tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor);//new + int pos3=tmpCur.position(); + appendLRM=true; + } + } + tmpCur.endEditBlock(); + setTextCursor(tmpCur); + } + +connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +return; +} +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//void LatexEditor::addLRMinTyping() +//{ +//if (!flagAutoLRM) return; +//if (parenMatcherStarted) return; +//disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +//if (!bidiEnabled) return; +//if ( layoutChanged ) +// { +// curLayoutDir = QApplication::keyboardInputDirection(); +// if (oldLayoutDir != curLayoutDir) +// { +// oldLayoutDir = curLayoutDir; +// QTextCursor tmpCur = textCursor(); +// QTextBlock currentBlock = tmpCur.block(); +// if (bidiMode==3) //flagAutoNewLine)//new +// { +// BlockData *thisBlockData = static_cast(currentBlock.userData()); +// if (thisBlockData) thisBlockData->bidiState=false; +// +// QTextBlockFormat tmpBlockFormat = tmpCur.blockFormat(); +// tmpBlockFormat.setLayoutDirection( Qt::RightToLeft ); +// tmpCur.beginEditBlock(); +// tmpCur.setBlockFormat( tmpBlockFormat ); +// tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); +// if (curLayoutDir == Qt::RightToLeft) +// tmpCur.insertText(QString(QChar(LRM))+"%\n"); +// else +// tmpCur.insertText("%\n"+QString(QChar(LRM))); +// tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor); +// tmpCur.insertText(QChar(LRM)); +// tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); +// tmpCur.endEditBlock(); +// setTextCursor(tmpCur); +// connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +// return; +// } +// tmpCur.beginEditBlock(); +// tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); +// QString ch = tmpCur.selectedText(); +// tmpCur.clearSelection(); +// if (!ch.isEmpty()) +// { +// if ( curLayoutDir == Qt::RightToLeft || !ch.at(0).isSpace() ) +// { +// tmpCur.insertText(QChar(LRM)); +// tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor); +// } +// else +// { +// tmpCur.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor); +// tmpCur.insertText(QChar(LRM)); +// } +// } +// if ( curLayoutDir == Qt::LeftToRight ) +// { +// tmpCur.insertText(QChar(LRM)); +// tmpCur.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor); +// } +// tmpCur.endEditBlock(); +// setTextCursor(tmpCur); +// } +// } +//connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +//} + +//add by S. R. Alavizadeh +void LatexEditor::contextMenuAddLRE() +{ +disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +bool MODIFIED = document()->isModified();//new +QString word; +int startSel,endSel,pos,anch; +QTextCursor curCursor, tmpCursor; +curCursor = tmpCursor = textCursor(); +if ( textCursor().hasSelection() ) + { + pos = textCursor().position(); + endSel = textCursor().anchor(); + startSel = textCursor().blockNumber(); + curCursor.setPosition( endSel, QTextCursor::MoveAnchor ); + setTextCursor(curCursor); + endSel = textCursor().blockNumber(); + if (endSel != startSel) + { + tmpCursor.clearSelection(); + setTextCursor(tmpCursor); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + curCursor.setPosition( pos, QTextCursor::KeepAnchor ); + setTextCursor(curCursor); + word = textCursor().selectedText(); + } +else + { + QTextCursor tc=textCursor(); + //QTextCharFormat LTRFormat, curFormat; + //curFormat = LTRFormat = tc.charFormat();//new + //LTRFormat.setBackground(QColor("#FF0000"));//new + //tc.setCharFormat(LTRFormat);//new + word = QString(QChar(RLM))+"{"+QString(QChar(LRE))/*+"{}"*/+QString(QChar(LRM))+QString(QChar(PDF))+"}"+QString(QChar(RLM)); + tc.insertText(word); + //tc.setCharFormat(curFormat);//new + //tc.insertText(" "); + tc.movePosition(QTextCursor::PreviousCharacter,QTextCursor::MoveAnchor,4); + ////////////////////////////////////////////////////////////////////////// + ////////////////// Win32 API +#if defined( Q_WS_WIN ) + HKL loadedLayout=LoadKeyboardLayout(L"00000409" ,KLF_ACTIVATE);//load LANG_ENGLISH + ActivateKeyboardLayout(loadedLayout, 0); +#endif + //////////////////////////////////////////////////////////////////////////// + setTextCursor(tc); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } +//Remove Unicode Control Characters +word.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + +word = QString(QChar(RLM))+"{"+QString(QChar(LRE))+word+QString(QChar(LRM))+QString(QChar(PDF))+"}"+QString(QChar(RLM)); //.append(QChar(LRM)).append(QChar(PDF))).prepend(QChar(LRE)); +textCursor().beginEditBlock(); +textCursor().removeSelectedText(); +textCursor().insertText(word); +textCursor().endEditBlock(); +setTextCursor(tmpCursor); +document()->setModified( MODIFIED ); +if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +} + +//add by S. R. Alavizadeh +void LatexEditor::contextMenuAddRLE() +{ +disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +bool MODIFIED = document()->isModified();//new +QString word; +int startSel,endSel,pos,anch; +QTextCursor curCursor, tmpCursor; +curCursor = tmpCursor = textCursor(); +if ( textCursor().hasSelection() ) +{ + pos = textCursor().position(); + endSel = textCursor().anchor(); + startSel = textCursor().blockNumber(); + curCursor.setPosition( endSel, QTextCursor::MoveAnchor ); + setTextCursor(curCursor); + endSel = textCursor().blockNumber(); + if (endSel != startSel) + { + tmpCursor.clearSelection(); + setTextCursor(tmpCursor); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } + curCursor.setPosition( pos, QTextCursor::KeepAnchor ); + setTextCursor(curCursor); + word = textCursor().selectedText(); +} +else + { + word = QChar(RLE); + textCursor().insertText(word); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } +//Remove Unicode Control Characters +word.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + +word = (word.append(QChar(PDF))).prepend(QChar(RLE)); +textCursor().beginEditBlock(); +textCursor().removeSelectedText(); +textCursor().insertText(word); +textCursor().endEditBlock(); +setTextCursor(tmpCursor); +document()->setModified( MODIFIED ); +if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +} + +//add by S. R. Alavizadeh +void LatexEditor::contextMenuAddPDF() +{ +disconnect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +bool MODIFIED = document()->isModified();//new +QString word; +int startSel,endSel,pos,anch; +QTextCursor curCursor, tmpCursor; +curCursor = tmpCursor = textCursor(); +if ( textCursor().hasSelection() ) +{ +if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +return; + //pos = textCursor().position(); + //endSel = textCursor().anchor(); + //startSel = textCursor().blockNumber(); + //curCursor.setPosition( endSel, QTextCursor::MoveAnchor ); + //setTextCursor(curCursor); + //endSel = textCursor().blockNumber(); + //if (endSel != startSel) + //{ + // tmpCursor.clearSelection(); + // setTextCursor(tmpCursor); + // document()->setModified( MODIFIED ); + // if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + // return; + //} + //curCursor.setPosition( pos, QTextCursor::KeepAnchor ); + //setTextCursor(curCursor); + //word = textCursor().selectedText(); +} +else + { + word = QChar(PDF); + textCursor().insertText(word); + document()->setModified( MODIFIED ); + if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); + return; + } +//word.remove(QChar(LRM));//new +//word.remove(QChar(LRE));//new +//word.remove(QChar(RLE));//new +//word.remove(QChar(PDF));//new +//word = (word.append(QChar(PDF))).prepend(QChar(LRE)); +//textCursor().beginEditBlock(); +//textCursor().removeSelectedText(); +//textCursor().insertText(word); +//textCursor().endEditBlock(); +//setTextCursor(tmpCursor); +//document()->setModified( MODIFIED ); +//if (flagAutoLRM) connect(this->document(), SIGNAL(contentsChanged()), this, SLOT(addLRMinTyping())); +} + +//add by S. Razi Alavizadeh +void LatexEditor::callForwardSearch() +{ +emit callSumatraForwadSearch(); +} diff -rup texmaker-1.9.2-Original/latexeditor.h texmaker-1.9.2-03DEC2009-Linux/latexeditor.h --- texmaker-1.9.2-Original/latexeditor.h 2009-06-01 12:21:58.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/latexeditor.h 2009-11-30 14:13:44.000000000 +0330 @@ -24,10 +24,23 @@ #include "parenmatcher.h" #include "hunspell/hunspell.hxx" +//new//added by S. R. Alavizadeh +#if defined( Q_WS_WIN ) +#include "Windows.h" +#endif + //class QCompleter; //class ParenMatcher; //class QTextBlock; + +//#define LRE ','//0x202A //add By S. R. Alavizadeh//new +//#define RLE ';'//0x202B //add By S. R. Alavizadeh//new +//#define PDF '|'//0x202C //add By S. R. Alavizadeh//new + +extern bool flagAutoLRM, parenMatcherStarted, bidiEnabled, kbdLayoutChangingCanEmited;//new; +extern int bidiMode; + typedef int UserBookmarkList[3]; class LatexEditor : public QTextEdit { @@ -60,6 +73,10 @@ QStringList alwaysignoredwordList; void setSpellChecker(Hunspell * checker); void activateInlineSpell(bool enable); Hunspell * pChecker; +bool isItDirR(QChar ch);//add by S. R. Alavizadeh +int startLine, endLine;//add by S. R. Alavizadeh +Qt::LayoutDirection oldLayoutDir, curLayoutDir;//add by S. R. Alavizadeh +bool layoutChanged, shift, appendLRM, backSpaceFlag;//add by S. R. Alavizadeh private: QString encoding; @@ -69,6 +86,11 @@ ParenMatcher *matcher; QString spell_dic, spell_encoding; QStringList ignoredwordList, hardignoredwordList; bool inlinecheckSpelling; +bool noLRMneed;//add by S. R. Alavizadeh + +public slots: +void visibleLines(int flag);//add by S. R. Alavizadeh +void contextMenuAddLRE();//add by S. R. Alavizadeh//new private slots: void correctWord(); @@ -76,12 +98,25 @@ void checkSpellingWord(); void checkSpellingDocument(); void insertCompletion(const QString &completion); +void contextMenuAddLRM();//add by S. R. Alavizadeh +void contextMenuAddRLE();//add by S. R. Alavizadeh//new +void contextMenuAddPDF();//add by S. R. Alavizadeh//new +void remLRMfromSelection();//add by S. R. Alavizadeh +void addLRMinTyping();//add by S. R. Alavizadeh +void callForwardSearch(); + protected: void paintEvent(QPaintEvent *event); void contextMenuEvent(QContextMenuEvent *e); void keyPressEvent ( QKeyEvent * e ); void focusInEvent(QFocusEvent *e); +bool event(QEvent *e);//add by S. R. Alavizadeh //new +void mousePressEvent( QMouseEvent *ev );//add by S. R. Alavizadeh //new +//void keyReleaseEvent( QKeyEvent *e);//add by S. R. Alavizadeh //new signals: +void removeLRM();//add by S. R. Alavizadeh +void bidiVisibleLines();//add by S. R. Alavizadeh +void callSumatraForwadSearch();//add by S. R. Alavizadeh void spellme(); }; diff -rup texmaker-1.9.2-Original/latexeditorview.cpp texmaker-1.9.2-03DEC2009-Linux/latexeditorview.cpp --- texmaker-1.9.2-Original/latexeditorview.cpp 2009-05-08 14:59:17.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/latexeditorview.cpp 2009-08-06 03:53:18.000000000 +0430 @@ -34,6 +34,7 @@ m_lineNumberWidget = new LineNumberWidge m_lineNumberWidget->setFont(efont); QFontMetrics fm( efont ); m_lineNumberWidget->setFixedWidth( fm.width( "00000" ) + 14 ); + QHBoxLayout* lay = new QHBoxLayout( frame ); lay->setSpacing(0); lay->setMargin(0); diff -rup texmaker-1.9.2-Original/latexhighlighter.cpp texmaker-1.9.2-03DEC2009-Linux/latexhighlighter.cpp --- texmaker-1.9.2-Original/latexhighlighter.cpp 2009-06-11 19:25:47.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/latexhighlighter.cpp 2009-10-21 10:24:22.000000000 +0330 @@ -74,6 +74,7 @@ if (blockData) blockData->code.clear(); else { blockData = new BlockData; + blockData->bidiState = false;//add by S. R. Alavizadeh setCurrentBlockUserData(blockData); } for (int j=0; j < text.length(); j++) blockData->code.append(0); @@ -264,7 +265,12 @@ while (i < text.length()) { for ( QStringList::Iterator it = KeyWords.begin(); it != KeyWords.end(); ++it ) { - if (( *it ).indexOf( buffer )!=-1) + QString tmpBuffer = buffer;//add by S. R. Alavizadeh + //It's just skips Unicode Control Characters. + tmpBuffer.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + + if (( *it ).indexOf( tmpBuffer )!=-1) + //if (( *it ).indexOf( buffer )!=-1) { setFormat( i - buffer.length(), buffer.length(),ColorKeyword); blockData->code[i]=1; @@ -346,8 +352,12 @@ if (checkSpelling && pChecker) else break; } if ( (buffer.length() > 1) && (!ignoredwordList.contains(buffer)) && (!hardignoredwordList.contains(buffer))) - { - encodedString = codec->fromUnicode(buffer); + { + QString tmpBuffer = buffer;//Add by S. R. Alavizadeh //new + //It's just skips Unicode Control Characters. + tmpBuffer.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + encodedString = codec->fromUnicode(tmpBuffer); + //encodedString = codec->fromUnicode(buffer); check = pChecker->spell(encodedString.data()); if (!check) setFormat(i - buffer.length(), buffer.length(), spellingErrorFormat); } diff -rup texmaker-1.9.2-Original/latexhighlighter.h texmaker-1.9.2-03DEC2009-Linux/latexhighlighter.h --- texmaker-1.9.2-Original/latexhighlighter.h 2009-05-08 14:59:41.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/latexhighlighter.h 2009-10-21 10:26:25.000000000 +0330 @@ -21,6 +21,13 @@ #include #include "hunspell/hunspell.hxx" +//add By S. R. Alavizadeh +#define LRM 0x200E +#define RLM 0x200F +#define LRE 0x202A +#define RLE 0x202B +#define PDF 0x202C + class QTextDocument; class LatexHighlighter : public QSyntaxHighlighter diff -rup texmaker-1.9.2-Original/main.cpp texmaker-1.9.2-03DEC2009-Linux/main.cpp --- texmaker-1.9.2-Original/main.cpp 2009-06-01 12:58:35.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/main.cpp 2009-11-30 12:05:59.000000000 +0330 @@ -15,6 +15,8 @@ #include "texmakerapp.h" #include +bool parenMatcherStarted=false, flagAutoLRM=false, bidiEnabled=false, kbdLayoutChangingCanEmited=false;//new;//add by S. R. Alavizadeh +int bidiMode=1; int main( int argc, char ** argv ) { diff -rup texmaker-1.9.2-Original/parenmatcher.cpp texmaker-1.9.2-03DEC2009-Linux/parenmatcher.cpp --- texmaker-1.9.2-Original/parenmatcher.cpp 2009-06-01 13:01:06.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/parenmatcher.cpp 2009-09-24 21:59:38.000000000 +0330 @@ -190,6 +190,20 @@ ParenMatcher::MatchType ParenMatcher::ma QChar leftChar = charFromCursor(*cursor, QTextCursor::PreviousCharacter); QChar rightChar = charFromCursor(*cursor, QTextCursor::NextCharacter); +/************************************/ //add by S. R. Alavizadeh + while (leftChar == QChar(LRM) && !cursor->atEnd()) + { + cursor->clearSelection(); + cursor->movePosition( QTextCursor::PreviousCharacter,QTextCursor::MoveAnchor ); + leftChar = charFromCursor(*cursor, QTextCursor::PreviousCharacter); + } + while (rightChar == QChar(LRM) && !cursor->atEnd()) + { + cursor->clearSelection(); + cursor->movePosition( QTextCursor::NextCharacter,QTextCursor::MoveAnchor ); + rightChar = charFromCursor(*cursor, QTextCursor::NextCharacter); + } +/************************************/ if (rightChar == QLatin1Char('{')) { return checkOpenParenthesis(cursor, rightChar); } else if (leftChar == QLatin1Char('}')) { @@ -213,6 +227,7 @@ void ParenMatcher::matchFromSender() QTextEdit *edit = qobject_cast(sender()); if (!edit) return; + parenMatcherStarted = true;//add by S. R. Alavizadeh int rehighlightStart = currentMatch.selectionStart(); int rehighlightEnd = currentMatch.selectionEnd(); if (rehighlightStart != rehighlightEnd) { @@ -267,6 +282,7 @@ void ParenMatcher::matchFromSender() if (rehighlightStart != rehighlightEnd) edit->document()->markContentsDirty(rehighlightStart, rehighlightEnd-rehighlightStart); + parenMatcherStarted = false;//add by S. R. Alavizadeh } diff -rup texmaker-1.9.2-Original/parenmatcher.h texmaker-1.9.2-03DEC2009-Linux/parenmatcher.h --- texmaker-1.9.2-Original/parenmatcher.h 2009-06-01 13:01:54.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/parenmatcher.h 2009-08-01 22:33:34.000000000 +0430 @@ -41,6 +41,8 @@ #include #include +extern bool parenMatcherStarted;//add by S. R. Alavizadeh + class ParenMatcher : public QObject { Q_OBJECT diff -rup texmaker-1.9.2-Original/texmaker.cpp texmaker-1.9.2-03DEC2009-Linux/texmaker.cpp --- texmaker-1.9.2-Original/texmaker.cpp 2009-06-14 21:12:57.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/texmaker.cpp 2009-12-03 02:16:25.000000000 +0330 @@ -2,6 +2,8 @@ * copyright : (C) 2003-2009 by Pascal Brachet * * addons by Luis Silvestre * * http://www.xm1math.net/texmaker/ * + * Bi-directional support added by S. Razi Alavizadeh: * + * (mail:SRazi61@yahoo.com---weblog[Fa]:srazi.blogfa.com) * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -73,6 +75,7 @@ #include "spellerdialog.h" #include "webpublishdialog.h" +#include "blockdata.h"//'bidiState' need it//add by S. R. Alavizadeh #if defined( Q_WS_X11 ) #include "x11fontdialog.h" @@ -449,6 +452,17 @@ stat3->setText(QString(" %1 ").arg(input setAcceptDrops(true); +//add By S. R. Alavizadeh//new +if (bidiMode==3) autoNewLine(true); +else autoNewLine(false); +if (bidiMode==4) EditorView->setLayoutDirection(Qt::RightToLeft); +lastBiDiEnabledStatus=-1;//new +autoSaveTimer = new QTimer(this); +if (autoSaveFlag) + { + connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSaveDocs())); + autoSaveTimer->start(autoSaveInterval*60000); + } } Texmaker::~Texmaker(){ @@ -484,6 +498,38 @@ connect(Act, SIGNAL(triggered()), this, fileMenu->addAction(Act); Act->setEnabled(!sessionFilesList.isEmpty()); +//add by S. R. Alavizadeh +if (bidiEnabled) + { +#if defined( Q_WS_X11 ) + QFileInfo pyFtx(PREFIX"/share/texmaker/ftx2uni.py"); +#endif +#if defined( Q_WS_MACX ) + QFileInfo pyFtx(QCoreApplication::applicationDirPath() + "/../Resources/ftx2uni.py"); +#endif +#if defined(Q_WS_WIN) + QFileInfo exeFtx(QCoreApplication::applicationDirPath()+"/ftx2uni/ftx2uni.exe"); + QFileInfo pyFtx(QCoreApplication::applicationDirPath()+"/ftx2uni.py"); +#endif +#if defined(Q_WS_WIN) + if (exeFtx.exists() || pyFtx.exists()) + { + fileMenu->addSeparator(); + Act = new QAction(tr("Import FTX File(s)"), this); + connect(Act, SIGNAL(triggered()), this, SLOT(ftx2Unicode())); + fileMenu->addAction(Act); + } +#else + if (pyFtx.exists()) + { + fileMenu->addSeparator(); + Act = new QAction(tr("Import FTX File(s)"), this); + connect(Act, SIGNAL(triggered()), this, SLOT(ftx2Unicode())); + fileMenu->addAction(Act); + } +#endif + } + Act = new QAction(QIcon(":/images/filesave.png"), tr("Save"), this); Act->setShortcut(Qt::CTRL+Qt::Key_S); connect(Act, SIGNAL(triggered()), this, SLOT(fileSave())); @@ -670,7 +716,6 @@ Act = new QAction(tr("Convert to Html"), connect(Act, SIGNAL(triggered()), this, SLOT(WebPublish())); toolMenu->addAction(Act); - Act = new QAction(QIcon(":/images/errorprev.png"),tr("Previous LaTeX Error"), this); connect(Act, SIGNAL(triggered()), this, SLOT(PreviousError())); Act = new QAction(QIcon(":/images/errornext.png"),tr("Next LaTeX Error"), this); @@ -1392,6 +1437,111 @@ viewMenu->addSeparator(); viewMenu->addAction(StructureView->toggleViewAction()); viewMenu->addAction(OutputView->toggleViewAction()); +//add by S. R. alavizadeh [start] +if (bidiEnabled) + { + //Bi-Directional Menu + //new//QAction *actAutoBiDi; + bidiMenu = menuBar()->addMenu(tr("Bi-&Directional")); + actAutoBiDi = new QAction(tr("Auto &Bi-Director"), this); + actAutoBiDi->setCheckable(true); + //if (autoBiDiEnabled) Act->setChecked(true); + //autoBidi(autoBiDiEnabled); + //connect(actAutoBiDi, SIGNAL(toggled(bool)), this, SLOT(autoBidi(bool))); + if (autoBiDiEnabled) actAutoBiDi->setChecked(true); + bidiMenu->addAction(actAutoBiDi); + + Act = new QAction(tr("Add &LRM Automatically"), this); + Act->setCheckable(true); + connect(Act, SIGNAL(toggled(bool)), this, SLOT(autoLRM(bool))); + if (flagAutoLRM) Act->setChecked(true); + bidiMenu->addAction(Act); + + //Act = new QAction(tr("Auto New Line Method"), this); + //Act->setCheckable(true); + //connect(Act, SIGNAL(toggled(bool)), this, SLOT(autoNewLine(bool))); + //if (flagAutoNewLine) Act->setChecked(true); + //bidiMenu->addAction(Act); + + bidiMenu->addSeparator(); + + //BidiMode Menu [start] + QMenu *bidiModeMenu=bidiMenu->addMenu(tr("Bi-Directing &Method")); + bidiModes = new QActionGroup(this); + actFirstBiDiMode = new QAction(tr("&First Strong Character(LTR)"), bidiModes); + actFirstBiDiMode->setCheckable(true); + if (bidiMode == 1) actFirstBiDiMode->setChecked(true); + bidiModeMenu->addAction(actFirstBiDiMode); + + Act = new QAction(tr("&All Strong Character(RTL)"), bidiModes); + Act->setCheckable(true); + if (bidiMode == 2) Act->setChecked(true); + bidiModeMenu->addAction(Act); + Act = new QAction(tr("Auto New &Line(RTL)"), bidiModes); + Act->setCheckable(true); + if (bidiMode == 3) Act->setChecked(true); + bidiModeMenu->addAction(Act); + ////////////////////////////////////////// + Act = new QAction(tr("RTL &Environment"), bidiModes); + Act->setCheckable(true); + if (bidiMode == 4) Act->setChecked(true); + connect(bidiModes, SIGNAL(triggered(QAction *)), this, SLOT(bidiModeToggle(QAction *))); + bidiModeMenu->addAction(Act); + + //// BidiMode Menu [end] + + Act = new QAction(tr("Bi-Directing(&All Line)"), this); + Act->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_B,Qt::CTRL+Qt::ALT+Qt::Key_B)); + connect(Act, SIGNAL(triggered()), this, SLOT(editBiDiAll())); + bidiMenu->addAction(Act); + + actRTL = new QAction(tr("Text Direction &Right to Left"), this); + actRTL->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_B,Qt::CTRL+Qt::ALT+Qt::Key_R)); + connect(actRTL, SIGNAL(triggered()), this, SLOT(currentLineRTL())); + bidiMenu->addAction(actRTL); + if (autoBiDiEnabled) + { + actRTL->setVisible(false); + disconnect(actRTL,SIGNAL(triggered()), this, SLOT(currentLineRTL())); + } + else + { + actRTL->setVisible(true); + connect(actRTL,SIGNAL(triggered()), this, SLOT(currentLineRTL())); + } + + actLTR = new QAction(tr("Text Direction &Left to Right"), this); + actLTR->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_B,Qt::CTRL+Qt::ALT+Qt::Key_L)); + connect(actLTR, SIGNAL(triggered()), this, SLOT(currentLineLTR())); + bidiMenu->addAction(actLTR); + if (autoBiDiEnabled) + { + actLTR->setVisible(false); + disconnect(actLTR,SIGNAL(triggered()), this, SLOT(currentLineLTR())); + } + else + { + actLTR->setVisible(true); + connect(actLTR,SIGNAL(triggered()), this, SLOT(currentLineLTR())); + } + ////////////////////////////// + Act = new QAction(tr("Insert LTR Text"), this); + Act->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Period)); + connect(Act, SIGNAL(triggered()), this, SLOT(insertLTR())); + bidiMenu->addAction(Act); + connect(actAutoBiDi, SIGNAL(toggled(bool)), this, SLOT(autoBidi(bool))); + + bidiMenu->addSeparator();//new + Act = new QAction(tr("PTD File Support"), this); + Act->setToolTip("Save PTD file together with TEX file and open PTD file when opening TEX file, if exists"); + Act->setCheckable(true); + if (ptdSupportFlag) Act->setChecked(true); + else Act->setChecked(false); + bidiMenu->addAction(Act); + connect(Act, SIGNAL(toggled(bool)), this, SLOT(ptdSaveEnabled(bool))); + } +//add by S. R. Alavizadeh [end] + optionsMenu = menuBar()->addMenu(tr("&Options")); Act = new QAction(QIcon(":/images/configure.png"), tr("Configure Texmaker"), this); connect(Act, SIGNAL(triggered()), this, SLOT(GeneralOptions())); @@ -1449,6 +1599,11 @@ Act = new QAction(QIcon(":/images/appico connect(Act, SIGNAL(triggered()), this, SLOT(HelpAbout())); helpMenu->addAction(Act); +//add by S. R. Alavizadeh +Act = new QAction(tr("About BiDi Patch"), this); +connect(Act, SIGNAL(triggered()), this, SLOT(aboutBidiPatch())); +helpMenu->addAction(Act); + QList listaction; if (shortcuts.isEmpty()) { @@ -1663,7 +1818,7 @@ QString title; if ( !currentEditorView() ) {title="Texmaker";} else { - title="Document : "+getName(); + title="Document : "+getName(); //input_encoding=currentEditorView()->editor->getEncoding(); } setWindowTitle(title); @@ -1738,7 +1893,14 @@ edit->editor->setReadOnly(false); edit->editor->setEncoding(input_encoding); if (completion) edit->editor->setCompleter(completer); else edit->editor->setCompleter(0); -QFile file( f ); + +/////////////////////////////////////////////////////////////////////// +QString fn=f;//new +if (ptdSupportFlag) fn=openPtdFile(f);//new +/////////////////////////////////////////////////////////////////////// + +QFile file( fn ); +//QFile file( f ); if ( !file.open( QIODevice::ReadOnly ) ) { QMessageBox::warning( this,tr("Error"), tr("You do not have read permission to this file.")); @@ -1748,7 +1910,35 @@ QTextStream ts( &file ); QTextCodec* codec = QTextCodec::codecForName(input_encoding.toLatin1()); if(!codec) codec = QTextCodec::codecForLocale(); ts.setCodec(codec); -edit->editor->setPlainText( ts.readAll() ); + +//////////////////////////////////////////////////////////////////////// +//new +QList docUserState; +if ( file.fileName().endsWith(".ptd", Qt::CaseInsensitive) ) + { + QString htmlTmp=ts.readAll(); + //new//htmlTmp.remove(0,18); + int from=0;//, blockNumber=0; + int index2, index1;//=htmlTmp.indexOf("-qt-user-state:"); + while (htmlTmp.indexOf("-qt-user-state:",from)!=-1) + { + index1=htmlTmp.indexOf("-qt-user-state:",from); + index2=htmlTmp.indexOf("-qt-user-state:1",from); + if (index1==index2) + { + //docUserState[blockNumber]=1; + docUserState << 1; + } + else docUserState << 0; //docUserState[blockNumber]=-1; + //++blockNumber; + from = index1+17; + } + edit->editor->setHtml( htmlTmp ); + } +else + edit->editor->setPlainText( ts.readAll() ); +//////////////////////////////////////////////////////// + file.close(); filenames.remove( edit); filenames.insert( edit, f ); @@ -1756,14 +1946,54 @@ edit->editor->document()->setModified(fa connect(edit->editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(NewDocumentStatus(bool))); connect(edit->editor, SIGNAL(spellme()), this, SLOT(editSpell())); -if (wordwrap) {edit->editor->setWordWrapMode(QTextOption::WordWrap);} +//[start] add by S. R. Alavizadeh +if ( file.fileName().endsWith(".ptd", Qt::CaseInsensitive) ) + { + ptdOpenFlag = true; + QTextBlock p = edit->editor->document()->begin(); + while (p.isValid())//new + { + int userState=docUserState.at(p.blockNumber()); + p.setUserState(userState); + BlockData *thisBlockData = static_cast(p.userData()); + if (thisBlockData) + { + //if ( docUserState.at(p.blockNumber()) ) p.setUserState(); + //int userState=p.userState();/////////// + if ( userState==1 ) thisBlockData->bidiState=true;//new + else thisBlockData->bidiState=false; + } + else + { + thisBlockData = new BlockData; + if (p.userState()==1) thisBlockData->bidiState=true; + else thisBlockData->bidiState=false; + p.setUserData(thisBlockData); + } + p = p.next(); + } + QTextCursor tc(edit->editor->document()); + //tc.select(QTextCursor::LineUnderCursor); + tc.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor); + if ( tc.selectedText().startsWith(QChar('%')) ) + { + //QMessageBox::information(0,"Pause",tr("SEl=*%1*\nhasENTER=*%2*").arg(tc.selectedText()).arg(tc.selectedText().count("\n"))); + if ( QDateTime::fromString( tc.selectedText().remove(QChar('%')).trimmed(), Qt::TextDate ).isValid() ) + tc.removeSelectedText(); + } + } +else ptdOpenFlag = false; +if (bidiEnabled) + initBiDi(edit); +//[end] add by S. R. Alavizadeh + +if (wordwrap) {edit->editor->setWordWrapMode(/*QTextOption::WordWrap*/ QTextOption::WrapAtWordBoundaryOrAnywhere);} else {edit->editor->setWordWrapMode(QTextOption::NoWrap);} edit->editor->setFocus(); UpdateCaption(); NewDocumentStatus(false); AddRecentFile(f); ShowStructure(); - #ifndef Q_WS_MACX //bug Qt 4.5.1? //setWindowState(Qt::WindowMinimized); if (windowState()==Qt::WindowMinimized) setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive); @@ -1804,7 +2034,7 @@ if (completion) edit->editor->setComplet else edit->editor->setCompleter(0); EditorView->addTab( edit, "untitled" ); EditorView->setCurrentIndex(EditorView->indexOf(edit)); -if (wordwrap) {edit->editor->setWordWrapMode(QTextOption::WordWrap);} +if (wordwrap) {edit->editor->setWordWrapMode(/*QTextOption::WordWrap*/ QTextOption::WrapAtWordBoundaryOrAnywhere);} else {edit->editor->setWordWrapMode(QTextOption::NoWrap);} filenames.remove( edit); filenames.insert( edit, "untitled" ); @@ -1812,6 +2042,24 @@ edit->editor->document()->setModified(fa connect(edit->editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(NewDocumentStatus(bool))); connect(edit->editor, SIGNAL(spellme()), this, SLOT(editSpell())); +//add by S. R. Alavizadeh [start] +ptdOpenFlag=false; +if (bidiEnabled) initBiDi(edit);//new +//connect(edit->editor, SIGNAL(removeLRM()), this, SLOT(remLRMfromDocument())); +//flagBigDoc=false;//new +//currentTabChanged(); +//connect(EditorView, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged())); +//connect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(OldNumOfLines())); +//if (autoBiDiEnabled) +// connect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +//else +// disconnect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +//if (flagAutoLRM) +// connect(edit->editor->document(), SIGNAL(contentsChanged()), edit->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +//else +// disconnect(edit->editor->document(), SIGNAL(contentsChanged()), edit->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +//add by S. R. Alavizadeh [end] + UpdateCaption(); NewDocumentStatus(false); edit->editor->setFocus(); @@ -1845,7 +2093,19 @@ else QTextStream ts( &file ); QTextCodec* codec = QTextCodec::codecForName(currentEditorView()->editor->getEncoding().toLatin1()); ts.setCodec(codec ? codec : QTextCodec::codecForLocale()); - ts << currentEditorView()->editor->toPlainText(); +// ts << currentEditorView()->editor->toPlainText(); + QString tmp = currentEditorView()->editor->toPlainText();//add by S. R. Alavizadeh//new + //Remove Unicode Control Characters + tmp.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + + ts << tmp;//add by S. R. Alavizadeh//new + ////////////////////////////////// + file.close();//new; + QString curFileName = getName().right( getName().size()-getName().lastIndexOf(QChar('/'))-1 );//new + QString autoSaveFileName= getName().left( getName().lastIndexOf(QChar('/'))+1 )+"~Texmaker-AutoSaved__"+curFileName; + QFile::remove(autoSaveFileName); + if (ptdSupportFlag) savePtdFile(codec);//new + ////////////////////////////////// currentEditorView()->editor->document()->setModified(false); fn=getName(); AddRecentFile(fn); @@ -2234,7 +2494,7 @@ void Texmaker::ReadSettings() #ifdef USB_VERSION QSettings *config=new QSettings(QCoreApplication::applicationDirPath()+"/texmaker.ini",QSettings::IniFormat); //for USB-stick version : #else -QSettings *config=new QSettings(QSettings::IniFormat,QSettings::UserScope,"xm1","texmaker"); +QSettings *config=new QSettings(QSettings::NativeFormat /*QSettings::IniFormat*/,QSettings::UserScope,"xm1","texmaker"); #endif if (!config->contains("IniMode")) { @@ -2278,6 +2538,17 @@ wordwrap=config->value( "Editor/WordWrap parenmatch=config->value( "Editor/Parentheses Matching",true).toBool(); showline=config->value( "Editor/Line Numbers",true).toBool(); completion=config->value( "Editor/Completion",true).toBool(); +/******************************/ +//add by S. R. Alavizadeh +//Bi-Directional Support +autoBiDiEnabled=config->value("Editor/Auto Bidirector",true).toBool(); +flagAutoLRM=config->value("Editor/Add LRM Automatically",true).toBool(); +bidiMode=config->value("Editor/bidiMode",1).toInt(); +bidiEnabled=config->value("Editor/Bi-Di Support",true).toBool(); +autoSaveFlag=config->value("Editor/Auto Save",true).toBool(); +autoSaveInterval=config->value( "Editor/Auto Save Interval",5).toInt(); +ptdSupportFlag=config->value("Editor/PTD File Save",true).toBool(); +/******************************/ shortcuts.clear(); QStringList data,shortcut; @@ -2562,7 +2833,7 @@ void Texmaker::SaveSettings() #ifdef USB_VERSION QSettings config(QCoreApplication::applicationDirPath()+"/texmaker.ini",QSettings::IniFormat); //for USB-stick version #else -QSettings config(QSettings::IniFormat,QSettings::UserScope,"xm1","texmaker"); +QSettings config(QSettings::NativeFormat /*QSettings::IniFormat*/,QSettings::UserScope,"xm1","texmaker"); #endif config.setValue( "IniMode",true); @@ -2591,6 +2862,17 @@ config.setValue( "Editor/WordWrap",wordw config.setValue( "Editor/Parentheses Matching",parenmatch); config.setValue( "Editor/Line Numbers",showline); config.setValue( "Editor/Completion",completion); +/******************************/ +//add by S. R. Alavizadeh +//Bi-Directional Support +config.setValue("Editor/Auto Bidirector",autoBiDiEnabled); +config.setValue("Editor/Add LRM Automatically",flagAutoLRM); +config.setValue("Editor/bidiMode",bidiMode); +config.setValue("Editor/Bi-Di Support",bidiEnabled); +config.setValue("Editor/Auto Save",autoSaveFlag); +config.setValue("Editor/Auto Save Interval",autoSaveInterval); +config.setValue("Editor/PTD File Save",ptdSupportFlag); +/******************************/ QStringList data,shortcut; // data.clear(); @@ -3013,6 +3295,22 @@ void Texmaker::InsertTag(QString Entity, if ( !currentEditorView() ) return; QTextCursor cur=currentEditorView()->editor->textCursor(); int pos=cur.position(); +//new//added by S. R. Alavizadeh +if (bidiEnabled) + { + if ( Entity == "$ $" ) + { + Entity.prepend(QChar(LRM)).append(QChar(LRM)); + //Entity.prepend(QChar(LRE)).append(QChar(LRM)).append(QChar(PDF)); + ++dx; + } + ////////////////// Win32 API +#if defined( Q_WS_WIN ) + HKL loadedLayout=LoadKeyboardLayout(L"00000409" ,KLF_ACTIVATE);//load LANG_ENGLISH + ActivateKeyboardLayout(loadedLayout, 0); +#endif + //////////////////////////// + } currentEditorView()->editor->insertPlainText(Entity); cur.setPosition(pos,QTextCursor::MoveAnchor); if (dy>0) cur.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,dy); @@ -5221,6 +5519,20 @@ if (completion) {confDlg->ui.checkBoxCom else {confDlg->ui.checkBoxCompletion->setChecked(false);} if (inlinespellcheck) {confDlg->ui.checkBoxInlineSpell->setChecked(true);} else {confDlg->ui.checkBoxInlineSpell->setChecked(false);} +if (bidiEnabled) {confDlg->ui.checkBoxBidiEnabled->setChecked(true);}//add by S. R. Alavizadeh +else {confDlg->ui.checkBoxBidiEnabled->setChecked(false);} +if (autoSaveFlag) + { + confDlg->ui.checkBoxAutoSave->setChecked(true); + confDlg->ui.spinBoxAutoSaveInterval->setEnabled(true); + }//add by S. R. Alavizadeh +else + { + confDlg->ui.checkBoxAutoSave->setChecked(false); + confDlg->ui.spinBoxAutoSaveInterval->setEnabled(false); + } +confDlg->ui.spinBoxAutoSaveInterval->setValue(autoSaveInterval);//add by S. R. Alavizadeh +connect(confDlg->ui.checkBoxAutoSave, SIGNAL(toggled(bool)),confDlg->ui.spinBoxAutoSaveInterval, SLOT(setEnabled(bool)));//new confDlg->ui.lineEditAspellCommand->setText(spell_dic); @@ -5311,6 +5623,29 @@ if (confDlg->exec()) stat3->setText(QString(" %1 ").arg(input_encoding)); wordwrap=confDlg->ui.checkBoxWordwrap->isChecked(); + + bool bidiFlag=false; + if (bidiEnabled != confDlg->ui.checkBoxBidiEnabled->isChecked()) //add by S. R. Alavizadeh + { + bidiEnabled=confDlg->ui.checkBoxBidiEnabled->isChecked(); + //if (bidiEnabled) bidiMenu->setVisible(true); + //else bidiMenu->setVisible(false); + menuBar()->clear(); + //bidiMenu->set + setupMenus();//this is needed for disabling some of menu item + UpdateRecentFile(); + bidiFlag = true; + } + //new + killTimer(autoSaveTimer->timerId()); + autoSaveFlag=confDlg->ui.checkBoxAutoSave->isChecked(); + disconnect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSaveDocs())); + if (autoSaveFlag) + { + autoSaveInterval=confDlg->ui.spinBoxAutoSaveInterval->value(); + connect(autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSaveDocs())); + autoSaveTimer->start(autoSaveInterval*60000); + } completion=confDlg->ui.checkBoxCompletion->isChecked(); showline=confDlg->ui.checkBoxLinenumber->isChecked(); @@ -5341,14 +5676,81 @@ if (confDlg->exec()) currentEditorView()->editor->highlighter->setSpellChecker(spellChecker); currentEditorView()->editor->activateInlineSpell(inlinespellcheck); currentEditorView()->editor->highlighter->activateInlineSpell(inlinespellcheck); - if (wordwrap) {currentEditorView()->editor->setWordWrapMode(QTextOption::WordWrap);} + if (wordwrap) {currentEditorView()->editor->setWordWrapMode(/*QTextOption::WordWrap*/ QTextOption::WrapAtWordBoundaryOrAnywhere);} else {currentEditorView()->editor->setWordWrapMode(QTextOption::NoWrap);} if (completion) currentEditorView()->editor->setCompleter(completer); else currentEditorView()->editor->setCompleter(0); currentEditorView()->changeSettings(EditorFont,showline); currentEditorView()->editor->highlighter->setColors(colorMath,colorCommand,colorKeyword); - currentEditorView()->editor->clear(); +/* + currentEditorView()->editor->highlighter->rehighlight();//add by S. R. Alavizadeh + if (wrapFlag)//add by S. R. Alavizadeh//new + { + tmp = currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->clear(); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//new + currentEditorView()->editor->setPlainText( tmp ); + + if (autoBiDiEnabled) + addLRMToLatinWords(); + else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + + } + else + { + if (autoBiDiEnabled) + { + if (bidiFlag) + { + QTextCursor tc = currentEditorView()->editor->textCursor(); + tc.clearSelection();//select(QTextCursor::Document); + currentEditorView()->editor->setTextCursor(tc); + addLRMToLatinWords(); + } + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + } + else + { + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + disconnect(currentEditorView()->editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), currentEditorView()->editor, SLOT(visibleLines(int))); + if (bidiFlag) + { + tmp = currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->clear(); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//new + currentEditorView()->editor->setPlainText( tmp ); + } + } + } + + if (flagAutoLRM)//new + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); + else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); +*/ + //currentEditorView()->editor->clear(); + + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//add by S. R. Alavizadeh + currentEditorView()->editor->setPlainText( tmp ); + + //if (autoBiDiEnabled && bidiEnabled) + // { + // addLRMToLatinWords(); + // connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + // } + //else + // { + // disconnect(currentEditorView()->editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), currentEditorView()->editor, SLOT(visibleLines(int))); + // disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + // } + //if (flagAutoLRM && bidiEnabled)//add by S. R. Alavizadeh + // connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); + // + if (!bidiEnabled) unInitBiDi(currentEditorView());//new + else initBiDi(currentEditorView()); + if( MODIFIED ) currentEditorView()->editor->document()->setModified(TRUE ); else currentEditorView()->editor->document()->setModified( FALSE ); QApplication::restoreOverrideCursor(); @@ -5406,9 +5808,10 @@ for ( int i = 1; i < argc; ++i ) if (( arg == "-line" ) && (imimeData()->hasFormat("text/uri-list")) event->acceptProposedAction(); } +//void Texmaker::dropEvent(QDropEvent *event) +//{ +//QRegExp rx("file://(.*\\.(?:tex|bib|sty|cls|mp))"); +//QList uris=event->mimeData()->urls(); +//QString uri; +//for (int i = 0; i < uris.size(); ++i) +// { +// uri=uris.at(i).toString(); +// if (rx.exactMatch(uri)) load(rx.cap(1)); +// } +//event->acceptProposedAction(); +//} void Texmaker::dropEvent(QDropEvent *event) { -QRegExp rx("file://(.*\\.(?:tex|bib|sty|cls|mp))"); -QList uris=event->mimeData()->urls(); -QString uri; -for (int i = 0; i < uris.size(); ++i) +QRegExp rx("(.*\\.(?:tex|bib|sty|cls|mp))", Qt::CaseInsensitive); +QList urlList; +QString fn; +QFileInfo info; +if (event->mimeData()->hasUrls()) { - uri=uris.at(i).toString(); - if (rx.exactMatch(uri)) load(rx.cap(1));//uri.remove(0,8)); + urlList = event->mimeData()->urls(); // returns list of QUrls + // if just text was dropped, urlList is empty (size == 0) + if ( urlList.size() > 0) // if at least one QUrl is present in list + { + for (int i = 0; i < urlList.size(); ++i) + { + fn=urlList.at(i).toLocalFile(); + info.setFile( fn ); + if ( info.isFile() ) + { + if (rx.exactMatch(fn)) load(rx.cap(1)); + } + } + } } event->acceptProposedAction(); } - //*********************************** void Texmaker::SetMostUsedSymbols() { @@ -5667,3 +6094,1157 @@ modern_style=(action->text()=="Modern"); QMessageBox::information( this,"Texmaker",tr("The appearance setting will take effect after restarting the application.")); } +//////////////////Bidirectional/////////////////////// +//add by S. R. Alavizadeh +int Texmaker::OldNumOfLines() +{ +if ( !currentEditorView() ) return oldNumOfLines; +int tmp=currentEditorView()->editor->numoflines(); +if (newNumOfLines != tmp) + { + oldNumOfLines=newNumOfLines; + newNumOfLines=tmp; + } +return oldNumOfLines; +} + +//add by S. R. Alavizadeh +void Texmaker::editBiDiAll() +{ +if (!currentEditorView()) return; +currentEditorView()->editor->verticalScrollBar()->setValue(0);//new +currentEditorView()->editor->textCursor().clearSelection();//new +addLRMToLatinWords();//new +if (!autoBiDiEnabled) biDirector(1); +} + +//add by S. R. Alavizadeh +QString Texmaker::TeXtrimmed(QString text) +{ +text = text.simplified(); +text = text.remove(QChar(' '), Qt::CaseInsensitive); +text = text.remove(QChar('%'), Qt::CaseInsensitive); +text = text.remove(QChar(LRM), Qt::CaseInsensitive); + +if (!text.isEmpty()) + { + while ( text.at(0).direction() != QChar::DirAL && text.at(0).direction() != QChar::DirR && text.at(0).direction() != QChar::DirL ) + { + QChar firstChar = text.at(0); + text = text.remove(firstChar, Qt::CaseInsensitive); + if (text.isEmpty()) break; + } + } +return text; +} + +//add by S. R. Alavizadeh +void Texmaker::callBiDirector() +{ +biDirector(0); +} + +//add by S. R. Alavizadeh +void Texmaker::biDirector(int flag) +{ +if (bidiMode==3) // flagAutoNewLine) + return;//new +if (parenMatcherStarted) return; +if (!currentEditorView()) return; +disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +QTextEdit *editor = currentEditorView()->editor; +QTextCursor tCurrentCursor = editor->textCursor(); +int CurrentLinenum, CurrentCulNum; +QTextBlock currentBlock = tCurrentCursor.block(); +if ( !currentBlock.isValid() ) + { + if (autoBiDiEnabled) connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + else disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + return; + } +CurrentCulNum = tCurrentCursor.columnNumber(); +QString lineUnderTC = currentBlock.text(); +CurrentLinenum = currentEditorView()->editor->linefromblock(currentBlock)-1; +//QString toEnd = lineUnderTC.right(lineUnderTC.length()-(CurrentCulNum-1)); +//toEnd = TeXtrimmed(toEnd); +lineUnderTC = TeXtrimmed( lineUnderTC ); +if ( flag!=-1 && flag!=-2 ) + { + if ( flag==0 ) + { + if (oldNumOfLines >= newNumOfLines) + { + startcheck=CurrentLinenum; + endcheck=CurrentLinenum; + } + else + { + startcheck=CurrentLinenum-(newNumOfLines-oldNumOfLines); + endcheck=CurrentLinenum+(newNumOfLines-oldNumOfLines); + if (startcheck<0) startcheck=0; + if (endcheck>newNumOfLines-1) endcheck=newNumOfLines-1; + } + } + else + { + startcheck=0; + endcheck=newNumOfLines-1; + } + } +oldNumOfLines=newNumOfLines; + +if (endcheck-startcheck>=3500 && !flagBigDoc)//new// for Big document + { + flagBigDoc = true; + QMessageBox warnBigDoc; + warnBigDoc.setWindowTitle("Warning!"); + warnBigDoc.setText("This process may take a long time,maybe you want to disable\nauto bidirecting feature for load faster."); + QAbstractButton *disableBidi = warnBigDoc.addButton(tr("Disable"), QMessageBox::ActionRole); + warnBigDoc.setStandardButtons(QMessageBox::Cancel); + warnBigDoc.exec(); + if (warnBigDoc.clickedButton() == disableBidi) + { + autoBiDiEnabled = false; + return; + } + } + +//currentEditorView()->editor->document()->setUndoRedoEnabled(false, false);//only for my modified Qt + +QTextCursor tmpCursor = editor->textCursor(); +tmpCursor.setPosition(currentEditorView()->editor->getCursorPosition(startcheck,0),QTextCursor::MoveAnchor); +currentBlock = tmpCursor.block(); +if (endcheck-startcheck>100) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));//new +for (int i=startcheck;i<=endcheck;i++) + { + if (!currentBlock.isValid()) break; + + BlockData *thisBlockData = static_cast(currentBlock.userData()); + if (!thisBlockData) + { + thisBlockData = new BlockData; + thisBlockData->bidiState = false;//add by S. R. Alavizadeh + currentBlock.setUserData(thisBlockData); + } + if ( flag==-2 && thisBlockData->bidiState ) + { + currentBlock = currentBlock.next(); + tmpCursor.movePosition ( QTextCursor::NextBlock, QTextCursor::MoveAnchor ); + continue;//new + } + thisBlockData->bidiState = true; + + tmpCursor.joinPreviousEditBlock(); + lineUnderTC = TeXtrimmed( currentBlock.text() ); + if (bidiMode == 1) + { + if ( lineUnderTC.length() == 0 ) + { + LTR(tmpCursor); + currentBlock = currentBlock.next(); + tmpCursor.movePosition ( QTextCursor::NextBlock, QTextCursor::MoveAnchor ); + tmpCursor.endEditBlock(); + continue; + } + + if ( lineUnderTC.at(0).direction() == QChar::DirAL || lineUnderTC.at(0).direction() == QChar::DirR )//new//!lineUnderTC.at(0).toLatin1() ) + RTL(tmpCursor); + else + LTR(tmpCursor); + } + else + { + if (bidiMode == 2 ) + { + if ( lineUnderTC.length() == 0 ) + { + RTL(tmpCursor); + currentBlock = currentBlock.next(); + tmpCursor.movePosition ( QTextCursor::NextBlock, QTextCursor::MoveAnchor ); + tmpCursor.endEditBlock(); + continue; + } + while ( !(lineUnderTC.at(0).direction() == QChar::DirAL || lineUnderTC.at(0).direction() == QChar::DirR + || lineUnderTC.at(0).direction() == QChar::DirNSM) ) + { + QChar firstChar = lineUnderTC.at(0); + lineUnderTC.remove(firstChar, Qt::CaseInsensitive); + if ( lineUnderTC.isEmpty() ) break; + } + if ( !lineUnderTC.isEmpty() ) + RTL(tmpCursor); + else + LTR(tmpCursor); + } + } + + currentBlock = currentBlock.next(); + tmpCursor.movePosition ( QTextCursor::NextBlock, QTextCursor::MoveAnchor ); + tmpCursor.endEditBlock(); + } +editor->setTextCursor(tCurrentCursor); + +if (autoBiDiEnabled) + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +if (flagAutoLRM) + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +//currentEditorView()->editor->document()->setUndoRedoEnabled(true); +QApplication::restoreOverrideCursor(); +return; +} + +//add by S. R. Alavizadeh +QTextCursor Texmaker::RTL( QTextCursor tmpCursor ) +{ +if ( !currentEditorView() ) return tmpCursor; +QTextBlockFormat tmpBlockFormat = tmpCursor.blockFormat(); +tmpBlockFormat.setLayoutDirection( Qt::RightToLeft ); +tmpCursor.setBlockFormat( tmpBlockFormat ); +return tmpCursor; +} + +//add by S. R. Alavizadeh +QTextCursor Texmaker::LTR( QTextCursor tmpCursor ) +{ +if ( !currentEditorView() ) return tmpCursor; +QTextBlockFormat tmpBlockFormat = tmpCursor.blockFormat(); +tmpBlockFormat.setLayoutDirection( Qt::LeftToRight ); +tmpCursor.setBlockFormat( tmpBlockFormat ); +return tmpCursor; +} + +//add by S. R. Alavizadeh +void Texmaker::currentLineLTR() +{ +if ( !currentEditorView() ) return; +bool MODIFIED =currentEditorView()->editor->document()->isModified(); +QTextEdit *editor = currentEditorView()->editor; +QTextCursor tmpCursor = editor->textCursor(); +//new +QTextBlock currentBlock = tmpCursor.block(); +BlockData *thisBlockData = static_cast(currentBlock.userData()); +if (thisBlockData) thisBlockData->bidiState=false; +else + { + thisBlockData = new BlockData; + thisBlockData->bidiState = false; + currentBlock.setUserData(thisBlockData); + } +tmpCursor = LTR(tmpCursor); +editor->setTextCursor(tmpCursor); +currentEditorView()->editor->document()->setModified(MODIFIED); +} + +//add by S. R. Alavizadeh +void Texmaker::currentLineRTL() +{ +if ( !currentEditorView() ) return; +bool MODIFIED =currentEditorView()->editor->document()->isModified(); +QTextEdit *editor = currentEditorView()->editor; +QTextCursor tmpCursor = editor->textCursor(); +//new +QTextBlock currentBlock = tmpCursor.block(); +BlockData *thisBlockData = static_cast(currentBlock.userData()); +if (thisBlockData) thisBlockData->bidiState=false; +else + { + thisBlockData = new BlockData; + thisBlockData->bidiState = false; + currentBlock.setUserData(thisBlockData); + } +tmpCursor = RTL(tmpCursor); +editor->setTextCursor(tmpCursor); +currentEditorView()->editor->document()->setModified(MODIFIED); +} + +//add by S. R. Alavizadeh +void Texmaker::addLRMToLatinWords() +{ +if (!currentEditorView()) return; +bool MODIFIED = currentEditorView()->editor->document()->isModified();//new +disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//new +if (!bidiEnabled) return; +QString word, wholeDoc, tmpWord; +bool tmpFlag=false,selFlag=false; +int tmpBlockNum,prevWordFlag=-1,lastLatinIndex=-1; +QTextCursor curCursor = currentEditorView()->editor->textCursor(); +QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); +//QStringList keyWords = QString("\\bibitem,\\section,\\subsection,\\subsubsection,\\chapter,\\includegraphics,\\include,\\input,\\begin,\\end").split(","); +selFlag=curCursor.hasSelection(); +if (!ptdOpenFlag) //new + { + if (selFlag) + { + wholeDoc = curCursor.selectedText(); + } + else + { + wholeDoc = currentEditorView()->editor->toPlainText(); + } + wholeDoc = wholeDoc.remove(QChar(LRM), Qt::CaseInsensitive); + wholeDoc = wholeDoc.replace( "\n", " \n ", Qt::CaseInsensitive ); + QStringList splittedDoc = wholeDoc.split(" "); + + for (int i = 0; i < splittedDoc.size(); ++i) + { + int startIndex=0; + word = splittedDoc.at(i);//new + if (word=="\n") + { + if ( lastLatinIndex!=-1 ) + { + splittedDoc[lastLatinIndex] = splittedDoc[lastLatinIndex].append(QChar(LRM)); + lastLatinIndex=-1; + } + prevWordFlag = -1; + continue; + } + tmpWord = word; + tmpWord.remove("%",Qt::CaseInsensitive); + tmpWord.remove("(",Qt::CaseInsensitive); + tmpWord.remove("\\{",Qt::CaseInsensitive); + tmpWord.remove("{",Qt::CaseInsensitive); + tmpWord.remove("[",Qt::CaseInsensitive); + tmpWord.remove(")",Qt::CaseInsensitive); + tmpWord.remove("\\}",Qt::CaseInsensitive); + tmpWord.remove("}",Qt::CaseInsensitive); + tmpWord.remove("]",Qt::CaseInsensitive); + //new// + if ( tmpWord.isEmpty() ) continue; + + if ( word.at(0).isSpace() && word.size()>1) startIndex = 1; + if ( !currentEditorView()->editor->isItDirR(word.at(startIndex)) && !currentEditorView()->editor->isItDirR(word.at(word.size()-1)) )//new + { + if ( prevWordFlag==-1 ) + splittedDoc[i] = word.prepend(QChar(LRM)); + lastLatinIndex = i; + prevWordFlag = 1; + } + else + { + if ( currentEditorView()->editor->isItDirR(word.at(startIndex)) && currentEditorView()->editor->isItDirR(word.at(word.size()-1)) )//new + { + if ( lastLatinIndex!=-1 ) + { + splittedDoc[lastLatinIndex] = splittedDoc[lastLatinIndex].append(QChar(LRM)); + lastLatinIndex=-1; + } + prevWordFlag = -1; + //////////////////////////////////////////////// + //j=startIndex; + tmpWord = word; + while( tmpWord.at(0).direction()!=QChar::DirL )// && word.at(j).direction()!=QChar::DirAL && word.at(j).direction()!=QChar::DirRLE && word.at(j).direction()!=QChar::DirRLO ) + { + QChar firstChar = tmpWord.at(0); + tmpWord = tmpWord.remove(firstChar, Qt::CaseInsensitive); + if (tmpWord.isEmpty()) break; + } + if (!tmpWord.isEmpty()) + { + int je = word.size()-1; + while ( word.at(je).direction()==QChar::DirR || word.at(je).direction()==QChar::DirAL )//isItDirR(word.at(je)) ) + { + --je; + } + int js = startIndex; + while ( word.at(js).direction()==QChar::DirR || word.at(js).direction()==QChar::DirAL )//(isItDirR(word.at(js)) ) + { + ++js; + } + word.insert(je+1,QChar(LRM)); + word.insert(js,QChar(LRM)); + splittedDoc[i] = word; + } + /////////////////////////////////////////// + } + else + { + if ( currentEditorView()->editor->isItDirR(word.at(startIndex)) && !currentEditorView()->editor->isItDirR(word.at(word.size()-1)) )//new + { + if ( lastLatinIndex!=-1 ) + { + splittedDoc[lastLatinIndex] = splittedDoc[lastLatinIndex].append(QChar(LRM)); + } + int j = word.size()-1; + if ( !currentEditorView()->editor->isItDirR(word.at(j)) ) + { + --j; + while( word.at(j).direction()!=QChar::DirR && word.at(j).direction()!=QChar::DirAL && word.at(j).direction()!=QChar::DirRLE && word.at(j).direction()!=QChar::DirRLO && j>0 ) + --j; + } + if (word.at(j+1)!='}' && word.at(j+1)!=']' && word.at(j+1)!=')' ) + { + word.insert(j+1,QChar(LRM)); + splittedDoc[i] = word; + lastLatinIndex=i; + prevWordFlag = 1; + } + } + else + { + if ( !currentEditorView()->editor->isItDirR(word.at(startIndex)) && currentEditorView()->editor->isItDirR(word.at(word.size()-1)) )//new + { + if ( word.at(startIndex)=='%' ) continue; + int j = startIndex; + if ( !currentEditorView()->editor->isItDirR(word.at(j)) ) + { + ++j; + while( word.at(j).direction()!=QChar::DirR && word.at(j).direction()!=QChar::DirAL && word.at(j).direction()!=QChar::DirRLE && word.at(j).direction()!=QChar::DirRLO && jeditor->textCursor().beginEditBlock(); + currentEditorView()->editor->clear(); + currentEditorView()->editor->setPlainText( wholeDoc ); + currentEditorView()->editor->textCursor().endEditBlock(); + } + if (autoBiDiEnabled) + { + QApplication::restoreOverrideCursor(); + //new//biDirector(1); + currentEditorView()->editor->visibleLines(-1); + startcheck = currentEditorView()->editor->startLine; + endcheck = currentEditorView()->editor->endLine; + biDirector(-2); + } + } +else + { + currentEditorView()->editor->textCursor().beginEditBlock(); + QTextCursor tmpCursor = curCursor; + int endSel = tmpCursor.anchor(); + int startSel = tmpCursor.blockNumber(); + currentEditorView()->editor->textCursor().removeSelectedText(); + currentEditorView()->editor->textCursor().insertText(wholeDoc); + tmpCursor.setPosition( endSel, QTextCursor::MoveAnchor ); + currentEditorView()->editor->setTextCursor(tmpCursor); + endSel = tmpCursor.blockNumber(); + if (startSeleditor->textCursor().endEditBlock(); + if (autoBiDiEnabled) + { + QApplication::restoreOverrideCursor(); + biDirector(-1); + } + } +QApplication::restoreOverrideCursor(); +currentEditorView()->editor->document()->setModified( MODIFIED ); +QTextCursor tc(currentEditorView()->editor->document()); +currentEditorView()->editor->setTextCursor(tc); +if (flagAutoLRM) + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +} + +//add by S. R. Alavizadeh +void Texmaker::remLRMfromDocument() +{ +if (!currentEditorView()) return; +bool MODIFIED = currentEditorView()->editor->document()->isModified();//new +disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +QTextCursor curCursor = currentEditorView()->editor->textCursor(); +QTextCursor tmpCursor = curCursor; +QString tmp; +int startSel,endSel; +if (tmpCursor.hasSelection()) + { + startcheck = tmpCursor.position(); + endcheck = tmpCursor.anchor(); + tmp = tmpCursor.selectedText(); + startSel = tmpCursor.blockNumber(); + tmpCursor.setPosition( endcheck, QTextCursor::MoveAnchor ); + //currentEditorView()->editor->setTextCursor(tmpCursor); + endSel = tmpCursor.blockNumber(); + //curCursor.setPosition( startcheck, QTextCursor::KeepAnchor ); + //currentEditorView()->editor->setTextCursor(curCursor); + //tmp = tmp.remove(QChar(LRM), Qt::CaseInsensitive); + //Remove Unicode Control Characters + tmp.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + curCursor.beginEditBlock(); + curCursor.removeSelectedText(); + curCursor.insertText(tmp); + curCursor.endEditBlock(); + curCursor.clearSelection(); + currentEditorView()->editor->setTextCursor(curCursor); + if (startSel>endSel) + { + startcheck = endSel; + endcheck = startSel; + } + else + { + startcheck = startSel; + endcheck = endSel; + } + + if (autoBiDiEnabled) + biDirector(-1); + currentEditorView()->editor->document()->setModified( MODIFIED );//new + return; + } +tmp =currentEditorView()->editor->toPlainText(); + +//Remove Unicode Control Characters +tmp.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + +currentEditorView()->editor->textCursor().beginEditBlock(); +//currentEditorView()->editor->clear(); +currentEditorView()->editor->setPlainText( tmp ); +currentEditorView()->editor->textCursor().endEditBlock(); +if (autoBiDiEnabled) + biDirector(1); +currentEditorView()->editor->document()->setModified( MODIFIED );//new +} + +//add by S. R. Alavizadeh +void Texmaker::currentTabChanged() +{ +if ( !currentEditorView() ) return; +newNumOfLines=currentEditorView()->editor->numoflines(); +oldNumOfLines=newNumOfLines; +//new +if (autoBiDiEnabled) + { + currentEditorView()->editor->visibleLines(-1); + startcheck = currentEditorView()->editor->startLine; + endcheck = currentEditorView()->editor->endLine; + } + +} + +//add by S. R. Alavizadeh +void Texmaker::autoLRM(bool checked) +{ +flagAutoLRM=checked; +if (!currentEditorView()) return; +if (flagAutoLRM) + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); +else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); +} + +//add by S. R. Alavizadeh +//new +void Texmaker::autoBidi(bool checked) +{// if (!bidiEnabled) return; +autoBiDiEnabled=checked; +if (autoBiDiEnabled && bidiMode==4) + { + lastBiDiEnabledStatus=-1; + bidiMode=1; + disconnect(bidiModes, SIGNAL(triggered(QAction *)), this, SLOT(bidiModeToggle(QAction *))); + actFirstBiDiMode->setChecked(true); + connect(bidiModes, SIGNAL(triggered(QAction *)), this, SLOT(bidiModeToggle(QAction *))); + } +//QMessageBox::information(0,"autoBidi",tr("autoBiDi=*%1*--lastBiDi=*%2*").arg(autoBiDiEnabled).arg(lastBiDiEnabledStatus)); +//if (!currentEditorView()) return; +if (currentEditorView()) initBiDi(currentEditorView()); +//bool bidiFlag = true; + +//menuBar()->~QMenuBar(); +//setupMenus();//this is needed for disabling some of menu item +//UpdateRecentFile(); +//actRTL = new QAction(tr("Text Direction Right to Left"), this); +//actRTL->setShortcut(Qt::CTRL+Qt::ALT+Qt::Key_R); +//connect(actRTL, SIGNAL(triggered()), this, SLOT(currentLineRTL())); +if (autoBiDiEnabled && bidiEnabled) + { + actRTL->setVisible(false); + disconnect(actRTL,SIGNAL(triggered()), this, SLOT(currentLineRTL())); + } +else + { + actRTL->setVisible(true); + connect(actRTL,SIGNAL(triggered()), this, SLOT(currentLineRTL())); + } +// +//actLTR = new QAction(tr("Text Direction Left to Right"), this); +//actLTR->setShortcut(Qt::CTRL+Qt::ALT+Qt::Key_L); +//connect(actLTR, SIGNAL(triggered()), this, SLOT(currentLineLTR())); +if (autoBiDiEnabled && bidiEnabled) + { + actLTR->setVisible(false); + disconnect(actLTR,SIGNAL(triggered()), this, SLOT(currentLineLTR())); + } + else + { + actLTR->setVisible(true); + connect(actLTR,SIGNAL(triggered()), this, SLOT(currentLineLTR())); + } + +if (currentEditorView()) + { + LatexEditorView *temp = new LatexEditorView( EditorView,EditorFont,showline,colorMath,colorCommand,colorKeyword,inlinespellcheck,spell_ignored_words,spellChecker); + temp=currentEditorView(); + FilesMap::Iterator it; + for( it = filenames.begin(); it != filenames.end(); ++it ) + { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + EditorView->setCurrentIndex(EditorView->indexOf(it.key())); + bool MODIFIED =currentEditorView()->editor->document()->isModified(); + //QString tmp =currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->setSpellChecker(spellChecker); + //currentEditorView()->editor->highlighter->setSpellChecker(spellChecker); + //currentEditorView()->editor->activateInlineSpell(inlinespellcheck); + //currentEditorView()->editor->highlighter->activateInlineSpell(inlinespellcheck); + //if (wordwrap) {currentEditorView()->editor->setWordWrapMode(QTextOption::WordWrap);} + //else {currentEditorView()->editor->setWordWrapMode(QTextOption::NoWrap);} + //if (completion) currentEditorView()->editor->setCompleter(completer); + //else currentEditorView()->editor->setCompleter(0); + //currentEditorView()->changeSettings(EditorFont,showline); + //currentEditorView()->editor->highlighter->setColors(colorMath,colorCommand,colorKeyword); +/* + currentEditorView()->editor->highlighter->rehighlight();//add by S. R. Alavizadeh + if (wrapFlag)//add by S. R. Alavizadeh//new + { + tmp = currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->clear(); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//new + currentEditorView()->editor->setPlainText( tmp ); + + if (autoBiDiEnabled) + addLRMToLatinWords(); + else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + + } + else + { + if (autoBiDiEnabled) + { + if (bidiFlag) + { + QTextCursor tc = currentEditorView()->editor->textCursor(); + tc.clearSelection();//select(QTextCursor::Document); + currentEditorView()->editor->setTextCursor(tc); + addLRMToLatinWords(); + } + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + } + else + { + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + disconnect(currentEditorView()->editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), currentEditorView()->editor, SLOT(visibleLines(int))); + if (bidiFlag) + { + tmp = currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->clear(); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//new + currentEditorView()->editor->setPlainText( tmp ); + } + } + } + + if (flagAutoLRM)//new + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); + else + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); +*/ + ////currentEditorView()->editor->clear(); + + //disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//add by S. R. Alavizadeh + + //currentEditorView()->editor->setPlainText( tmp ); + QTextCursor tc(currentEditorView()->editor->document()); + currentEditorView()->editor->setTextCursor(tc); + if (autoBiDiEnabled) + { + //if (bidiFlag) + // { + //QTextCursor tc = currentEditorView()->editor->textCursor(); + //tc.clearSelection();//select(QTextCursor::Document); + //currentEditorView()->editor->setTextCursor(tc); + //currentEditorView()->editor->visibleLines(-1); + addLRMToLatinWords(); + // } + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + } + else + { + disconnect(currentEditorView()->editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), currentEditorView()->editor, SLOT(visibleLines(int))); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + QString tmp =currentEditorView()->editor->toPlainText(); + //currentEditorView()->editor->clear(); + + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping()));//add by S. R. Alavizadeh + + currentEditorView()->editor->setPlainText( tmp ); + if (flagAutoLRM)//add by S. R. Alavizadeh + connect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), currentEditorView()->editor, SLOT(addLRMinTyping())); + if( MODIFIED ) currentEditorView()->editor->document()->setModified(TRUE ); + else currentEditorView()->editor->document()->setModified( FALSE ); + //QTextCursor tc = currentEditorView()->editor->textCursor(); + //tc.select(QTextCursor::Document); + //LTR(tc); + //tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); + //currentEditorView()->editor->setTextCursor(tc); + } + QApplication::restoreOverrideCursor(); + } + EditorView->setCurrentIndex(EditorView->indexOf(temp)); + UpdateCaption(); + } +} +//add by S. R. Alavizadeh +void Texmaker::bidiStartToEnd() +{ +if (!currentEditorView()) return; +startcheck = currentEditorView()->editor->startLine; +endcheck = currentEditorView()->editor->endLine; +if (autoBiDiEnabled) biDirector(-2); +} + +//add by S. R. Alavizadeh +void Texmaker::bidiModeToggle(QAction *action) +{ +QString temp = action->text(); +if (action->text()=="&First Strong Character(LTR)") bidiMode = 1; +else if (action->text()=="&All Strong Character(RTL)") bidiMode = 2; +else if (action->text()=="RTL &Environment") bidiMode=4; +else bidiMode=3; + +if (bidiMode==3) + { + autoNewLine(true); + return; + } +else autoNewLine(false); +if (bidiMode==4) + { + if (autoBiDiEnabled) lastBiDiEnabledStatus=1; + else lastBiDiEnabledStatus=0; + EditorView->setLayoutDirection(Qt::RightToLeft); + autoBiDiEnabled=false; + disconnect(actAutoBiDi, SIGNAL(toggled(bool)), this, SLOT(autoBidi(bool))); + actAutoBiDi->setChecked(false);//new + connect(actAutoBiDi, SIGNAL(toggled(bool)), this, SLOT(autoBidi(bool))); + LatexEditorView *temp = new LatexEditorView( EditorView,EditorFont,showline,colorMath,colorCommand,colorKeyword); + temp=currentEditorView(); + FilesMap::Iterator it; + QTextCursor tmpCur; + for( it = filenames.begin(); it != filenames.end(); ++it ) + { + EditorView->setCurrentIndex(EditorView->indexOf(it.key())); + bool MODIFIED =currentEditorView()->editor->document()->isModified(); + disconnect(currentEditorView()->editor->verticalScrollBar(), SIGNAL( valueChanged( int ) ), currentEditorView()->editor, SLOT(visibleLines(int))); + disconnect(currentEditorView()->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); + + tmpCur=currentEditorView()->editor->textCursor(); + tmpCur.select(QTextCursor::Document); + RTL(tmpCur); + tmpCur.clearSelection(); + currentEditorView()->editor->setTextCursor(tmpCur); + if( MODIFIED ) currentEditorView()->editor->document()->setModified(TRUE ); + else currentEditorView()->editor->document()->setModified( FALSE ); + currentEditorView()->editor->verticalScrollBar()->setValue(0); + } + EditorView->setCurrentIndex(EditorView->indexOf(temp)); + UpdateCaption(); + return; + } +else + { + if (lastBiDiEnabledStatus!=-1) + { + if (lastBiDiEnabledStatus==1) autoBiDiEnabled=true; + else autoBiDiEnabled=false; + lastBiDiEnabledStatus=-1; + actAutoBiDi->setChecked(autoBiDiEnabled); + } + } + + if (currentEditorView() && autoBiDiEnabled) + { + LatexEditorView *temp = new LatexEditorView( EditorView,EditorFont,showline,colorMath,colorCommand,colorKeyword); + temp=currentEditorView(); + FilesMap::Iterator it; + for( it = filenames.begin(); it != filenames.end(); ++it ) + { + EditorView->setCurrentIndex(EditorView->indexOf(it.key())); + bool MODIFIED =currentEditorView()->editor->document()->isModified(); + currentEditorView()->editor->visibleLines(-1); + + + QTextBlock p = currentEditorView()->editor->document()->begin(); + while (p.isValid()) + { + BlockData *thisBlockData = static_cast(p.userData()); + if (!thisBlockData) + { + thisBlockData = new BlockData; + thisBlockData->bidiState = false;//add by S. R. Alavizadeh + p.setUserData(thisBlockData); + } + thisBlockData->bidiState = false; + p = p.next(); + } + startcheck = currentEditorView()->editor->startLine; + endcheck = currentEditorView()->editor->endLine; + biDirector(-2); + + if( MODIFIED ) + currentEditorView()->editor->document()->setModified(TRUE ); + else + currentEditorView()->editor->document()->setModified( FALSE ); + currentEditorView()->editor->verticalScrollBar()->setValue(0); + } + EditorView->setCurrentIndex(EditorView->indexOf(temp)); + UpdateCaption(); + } +} + + +//add by S. R. Alavizadeh +void Texmaker::aboutBidiPatch() + { + QString bidiDate="03 December 2009"; + QMessageBox aboutBidi(this); + QPixmap pixmap(":/images/logo128.png"); + aboutBidi.setIconPixmap(pixmap); + aboutBidi.setWindowTitle(tr("About BiDi Texmaker")); + aboutBidi.setText(tr("\nBi-Directional Patch\nAuthor: S. Razi Alavizadeh\nPatch Date: %1").arg(bidiDate) ); + aboutBidi.setDetailedText("Download Links:\nhttp://srazi.blogfa.com/page/biditexmaker.aspx\n\nFarsiLaTeX Group:\nhttp://groups.google.com/group/FarsiLaTeX\nhttp://www.parsilatex.com/"); + QAbstractButton *aboutQtButton = aboutBidi.addButton(tr("About Qt..."), QMessageBox::ActionRole); + aboutBidi.setStandardButtons(QMessageBox::Ok); + aboutBidi.exec(); + if (aboutBidi.clickedButton() == aboutQtButton) QMessageBox::aboutQt(this, tr("About Qt")); + } + +/* +//BUG in Qt4.5.0 //add by S. R. Alavizadeh +void Texmaker::editorNeedsFocus() +{ +if (currentEditorView()) + currentEditorView()->editor->setFocus();//add by S. R. Alavizadeh//BUG in Qt4.5.0 ID=250064 +} +*/ + + +//FarsiTeX file Import (for Persian users)//add by S. R. Alavizadeh +void Texmaker::ftx2Unicode() +{ +QString exeConvertorPath=""; +#if defined( Q_WS_X11 ) +QString pyConvertorPath=PREFIX"/share/texmaker/ftx2uni.py"; +#endif +#if defined( Q_WS_MACX ) +QString pyConvertorPath=QCoreApplication::applicationDirPath()+"/../Resources/ftx2uni.py"; +#endif +#if defined(Q_WS_WIN) +exeConvertorPath=QCoreApplication::applicationDirPath()+"/ftx2uni/ftx2uni.exe"; +QString pyConvertorPath=QCoreApplication::applicationDirPath()+"/ftx2uni.py"; +#endif +QString currentDir=QDir::homePath(); +if (!lastDocument.isEmpty()) + { + QFileInfo fi(lastDocument); + if (fi.exists() && fi.isReadable()) currentDir=fi.absolutePath(); + } +QStringList inputFTX = QFileDialog::getOpenFileNames(this,tr("Import FarsiTeX File"),currentDir,"FrasiTeX files (*.ftx)"); +for (int i=0;ieditor, SIGNAL(callSumatraForwadSearch()), this, SLOT(SumatraForwardSearch())); +flagBigDoc=false;//new +connect(edit->editor, SIGNAL(removeLRM()), this, SLOT(remLRMfromDocument())); +currentTabChanged(); +connect(edit->editor, SIGNAL( bidiVisibleLines() ), this, SLOT(bidiStartToEnd()));//new +connect(EditorView, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged())); +connect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(OldNumOfLines())); +if (autoBiDiEnabled) + addLRMToLatinWords();//new//biDirector(2); +else + disconnect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +if (flagAutoLRM) + connect(edit->editor->document(), SIGNAL(contentsChanged()), edit->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +else + disconnect(edit->editor->document(), SIGNAL(contentsChanged()), edit->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +} + +//add by S. Razi Alavizadeh +void Texmaker::unInitBiDi(LatexEditorView *edit) +{ +disconnect(edit->editor, SIGNAL(removeLRM()), this, SLOT(remLRMfromDocument())); +disconnect(edit->editor, SIGNAL( bidiVisibleLines() ), this, SLOT(bidiStartToEnd()));//new +disconnect(EditorView, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged())); +disconnect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(OldNumOfLines())); +disconnect(edit->editor->document(), SIGNAL(contentsChanged()), this, SLOT(callBiDirector())); +disconnect(edit->editor->document(), SIGNAL(contentsChanged()), edit->editor, SLOT(addLRMinTyping()));//Added By S. R. Alavizadeh +} + +//add by S. Razi Alavizadeh +void Texmaker::autoNewLine(bool checked) +{ +//flagAutoNewLine = checked; +if (checked) + { + flagAutoLRM = true; + EditorView->setLayoutDirection(Qt::RightToLeft); + //if (currentEditorView()) currentEditorView()->editor->setLayoutDirection(Qt::RightToLeft); + } +else + {EditorView->setLayoutDirection(Qt::LeftToRight);} +} + +//add by S. Razi Alavizadeh +void Texmaker::SumatraForwardSearch() +{ +QString TeXDocName; +if (singlemode) {TeXDocName=getName();} +else {TeXDocName=MasterName;} +if ( !TeXDocName.endsWith(".tex", Qt::CaseInsensitive) ) return; +QFileInfo SumtaraFS(QCoreApplication::applicationDirPath()+"/SumatraForwardsearch.exe"); +if (!SumtaraFS.exists()) return; +QString pdfFileName=TeXDocName.left(TeXDocName.size()-4)+".pdf"; +QString pdfFullName=pdfFileName; +pdfFileName.remove(0,pdfFullName.lastIndexOf(QChar('/'))+1); +TeXDocName=getName(); +pdfFullName.replace(QChar('/'),QChar('\\')); +TeXDocName.replace(QChar('/'),QChar('\\')); +QProcess ForwardSumatra; +QTextCursor tc=currentEditorView()->editor->textCursor(); +int lineNo = tc.blockNumber()+1;//(5*(((1+currentEditorView()->editor->numoflines())-tc.blockNumber())/(1+currentEditorView()->editor->numoflines())) ); +QString curLineNum=QString().number(lineNo); +//ForwardSumatra.startDetached(QCoreApplication::applicationDirPath()+"/SumatraForwardsearch.exe",QStringList()<< pdfFileName << getName() << curLineNum, QCoreApplication::applicationDirPath() ); +//ForwardSumatra.start(QCoreApplication::applicationDirPath()+"/SumatraForwardsearch.exe "+pdfFileName+" "+getName()+" "+curLineNum); +ForwardSumatra.startDetached(QCoreApplication::applicationDirPath()+"/SumatraForwardsearch.exe",QStringList()<< pdfFullName << TeXDocName << curLineNum << pdfFileName); +} + +//add by S. Razi Alavizadeh +void Texmaker::insertLTR() +{ + if (currentEditorView()) + { + if (!currentEditorView()->editor->textCursor().hasSelection()) + currentEditorView()->editor->contextMenuAddLRE(); + } +} + +//add by S. Razi Alavizadeh +void Texmaker::autoSaveDocs() +{ +if (currentEditorView()) + { + LatexEditorView *temp = new LatexEditorView( EditorView,EditorFont,showline,colorMath,colorCommand,colorKeyword,inlinespellcheck,spell_ignored_words,spellChecker); + temp=currentEditorView(); + FilesMap::Iterator it; + int i=1; + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + for( it = filenames.begin(); it != filenames.end(); ++it ) + { + EditorView->setCurrentIndex(EditorView->indexOf(it.key())); + if (!currentEditorView()->editor->document()->isModified()) continue; + QString curFileName, autoSaveFileName; + + if (getName() != "untitled" ) + { + curFileName = getName().right( getName().size()-getName().lastIndexOf(QChar('/'))-1 ); + autoSaveFileName= getName().left( getName().lastIndexOf(QChar('/'))+1 )+"~Texmaker-AutoSaved__"+curFileName; + } + else + { + curFileName = "~Texmaker-AutoSaved__untitled_"+QString().number(i)+".tex"; + autoSaveFileName=QDir::tempPath()+"/"+curFileName; + } + ++i; + QFile autoSaveFile( autoSaveFileName ); + if ( !autoSaveFile.open( QIODevice::WriteOnly ) ) + { + QMessageBox::warning( this,tr("Error"),tr("The \"auto save file\" could not be saved. Please check if you have write permission.")); + return; + } + QTextStream ts( &autoSaveFile ); + QTextCodec* codec = QTextCodec::codecForName(currentEditorView()->editor->getEncoding().toLatin1()); + ts.setCodec(codec ? codec : QTextCodec::codecForLocale()); + QString tmp = currentEditorView()->editor->toPlainText(); + //Remove Unicode Control Characters + tmp.remove(QChar(LRM)).remove(QChar(RLM)).remove(QChar(LRE)).remove(QChar(RLE)).remove(QChar(PDF)); + ts << tmp; + autoSaveFile.close(); + //savePtdFile(codec);//new + } + QApplication::restoreOverrideCursor(); + EditorView->setCurrentIndex(EditorView->indexOf(temp)); + UpdateCaption(); + currentEditorView()->editor->setFocus(); + } + +} + +//add by S. Razi Alavizadeh +void Texmaker::ptdSaveEnabled(bool checked) +{ +ptdSupportFlag=checked; +} + +//add by S. Razi Alavizadeh +void Texmaker::savePtdFile(QTextCodec* codec) +{ +QTextBlock p = currentEditorView()->editor->document()->begin(); +while (p.isValid()) + { + BlockData *thisBlockData = static_cast(p.userData()); + if (thisBlockData) + { + if (thisBlockData->bidiState) + p.setUserState(1); + else + p.setUserState(0); + } + else p.setUserState(0); + p = p.next(); + } +//QDateTime tempDateTime = QDateTime::fromString("2011122023:59:59","yyyyMMddhh:mm:ss"); +QDateTime fileLastModification=QFileInfo( *filenames.find( currentEditorView() ) ).lastModified(); +//int seconds=fileLastModification.secsTo(tempDateTime); +//new +QString ptdFileName=filenames.find( currentEditorView() ).value().left(filenames.find( currentEditorView() ).value().size()-4)+".ptd"; +QFile ptdFile( ptdFileName ); +if ( !ptdFile.open( QIODevice::WriteOnly ) ) + { + QMessageBox::warning( this,tr("Error"),tr("The PTD file could not be saved. Please check if you have write permission.")); + return; + } +QTextStream ptdTS( &ptdFile ); +ptdTS.setCodec(codec ? codec : QTextCodec::codecForLocale()); +QString tmpHtml=currentEditorView()->editor->document()->toHtml("utf-8"); +int index1=tmpHtml.indexOf("\n" << tmpHtml; +ptdFile.close(); +} + +//add by S. Razi Alavizadeh +QString Texmaker::openPtdFile(QString f) +{ +QString tmp=f; +QString ptdName=QFile( f ).fileName().left(QFile( f ).fileName().size()-4)+".ptd"; +QFile ptdFile(ptdName); +if (ptdFile.exists()) + { + if ( ptdFile.open( QIODevice::ReadOnly ) ) + { + QTextStream ptdTS( &ptdFile ); + QTextCodec* codec = QTextCodec::codecForName(input_encoding.toLatin1()); + if(!codec) codec = QTextCodec::codecForLocale(); + ptdTS.setCodec(codec); + //new//QString datedate=ptdTS.readLine(0).remove(QChar('%')).trimmed(); + QString datedate=ptdTS.readLine(0).trimmed();//new + QDateTime lMod=QFileInfo(f).lastModified(); + //new//QString lMOD_ST=lMod.toString("yyyyMMddhh:mm:ss");//.toLatin1().trimmed(); + QString lMOD_ST="";//.toLatin1().trimmed();//new + QDateTime tempDateTime= QDateTime::fromString( datedate /*ptdTS.readLine(0).remove(QChar('%'))*/, "yyyyMMddhh:mm:ss" ); + //tempDateTime.fromString( ptdTS.readLine(0).remove(QChar('%')), "yyyyMMddhh:mm:ss" ); + //= QDateTime::fromString( ptdTS.readLine(0).remove(QChar('%')), Qt::TextDate ); + QString tempDate=tempDateTime.toString("yyyyMMddhh:mm:ss").toLatin1().trimmed(); + //if ( tempDateTime == QFileInfo(f).lastModified() ) + //if ( tempDate == lMOD_ST ) + //QMessageBox::information(0,"File Not Modified",tr("datedate=*%1*\nlMOD_ST=*%2*").arg(datedate).arg(lMOD_ST)); + if ( datedate == lMOD_ST ) + { + tmp = QFile( f ).fileName().left(QFile( f ).fileName().size()-4)+".ptd"; + //QMessageBox::information(0,"File Not Modified",datedate /*ptdTS.readLine(0).remove(QChar('%')) */); + } /* else fn=f; */ + ptdFile.close(); + //edit->editor->setPlainText( ts.readAll() ); + } + } +return tmp; +} diff -rup texmaker-1.9.2-Original/texmaker.h texmaker-1.9.2-03DEC2009-Linux/texmaker.h --- texmaker-1.9.2-Original/texmaker.h 2009-06-01 17:41:52.000000000 +0430 +++ texmaker-1.9.2-03DEC2009-Linux/texmaker.h 2009-12-02 21:24:35.000000000 +0330 @@ -53,6 +53,9 @@ typedef QString Userlist[10]; typedef QString UserCd[5]; typedef int SymbolList[412]; +extern bool bidiEnabled; +extern int bidiMode; + class Texmaker : public QMainWindow { Q_OBJECT @@ -64,12 +67,19 @@ QString getName(); QFont EditorFont; QByteArray windowstate; +bool autoBiDiEnabled, flagBigDoc;//add by S. R. Alavizadeh +int oldNumOfLines, newNumOfLines, startcheck, endcheck, lastBiDiEnabledStatus;//, bidiMode;//add by S. R. Alavizadeh +QTimer *autoSaveTimer;//new//add by S. R. Alavizadeh + public slots: void load( const QString &f ); void setLine( const QString &line ); void ToggleMode(); void onOtherInstanceMessage(const QString &); // For messages for the single instance +int OldNumOfLines();//add by S. R. Alavizadeh +void currentTabChanged();//add by S. R. Alavizadeh + private: void setupMenus(); void setupToolBars(); @@ -77,6 +87,17 @@ void createStatusBar(); bool FileAlreadyOpen(QString f); void closeEvent(QCloseEvent *e); +void biDirector(int flag);//add by S. R. Alavizadeh [start] +void initBiDi(LatexEditorView *edit); +void unInitBiDi(LatexEditorView *edit); +void autoNewLine(bool); +void savePtdFile(QTextCodec* codec);//new +QString openPtdFile(QString f);//new +int autoSaveInterval;//new +bool autoSaveFlag, ptdSupportFlag, ptdOpenFlag;//new +QAction *actLTR, *actRTL, *actAutoBiDi, *actFirstBiDiMode; +QActionGroup *bidiModes;//add by S. R. Alavizadeh [end] + FilesMap filenames; KeysMap shortcuts, actionstext; //gui @@ -93,7 +114,7 @@ QVBoxLayout *OutputLayoutV; QHBoxLayout *OutputLayoutH, *LeftPanelLayout, *CentralLayout; QTableWidget *OutputTableWidget; //menu-toolbar -QMenu *fileMenu, *recentMenu, *editMenu, *toolMenu; +QMenu *fileMenu, *recentMenu, *editMenu, *toolMenu, *bidiMenu; QMenu *latex1Menu, *latex11Menu, *latex12Menu, *latex13Menu, *latex14Menu, *latex15Menu, *latex16Menu, *latex17Menu ; QMenu *math1Menu, *math11Menu, *math12Menu, *math13Menu, *math14Menu; QMenu *wizardMenu; @@ -329,6 +350,27 @@ void updateCompleter(); void updateTranslation(); void updateAppearance(); +//add by S. R. Alavizadeh for biDirectional support +void callBiDirector(); +void editBiDiAll(); +void addLRMToLatinWords(); +void remLRMfromDocument(); +QTextCursor RTL( QTextCursor tmpCursor ); +QTextCursor LTR( QTextCursor tmpCursor ); +void currentLineLTR(); +void currentLineRTL(); +QString TeXtrimmed(QString text); +void ftx2Unicode(); +void autoLRM(bool checked); +void autoBidi(bool checked);//new +void aboutBidiPatch(); +//void editorNeedsFocus();//BUG in Qt4.5.0 +void bidiStartToEnd(); +void bidiModeToggle(QAction *action); +void SumatraForwardSearch(); +void insertLTR(); +void autoSaveDocs();//new +void ptdSaveEnabled(bool checked);//new protected: void dragEnterEvent(QDragEnterEvent *event);