void fileviewer::Next_ButtonClick(bool checked) { if (m_fileDataList.isEmpty()) { m_pushButtonPrev->setEnabled(false); m_pushButtonNext->setEnabled(false); return; } if((m_iter == m_fileDataList.end() - 1)|| (m_iter == m_fileDataList.end())) { m_pushButtonNext->setEnabled(false); return; } if (!checked) { QVector<filedata>::iterator it = m_iter; m_iter++; if (m_iter->compareFilenameOnly(*it)) { highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); } else { updateTextEdit(); } m_pushButtonPrev->setEnabled(m_iter != m_fileDataList.begin()); m_pushButtonNext->setEnabled(m_iter != m_fileDataList.end() - 1); } }
void fileviewer::Next_ButtonClick(bool checked) { if (!checked) { if (m_iter != m_fileDataList.begin()) { QVector<filedata>::iterator it = m_iter; m_iter--; m_file_idx--; if (m_iter->compareFilenameOnly(*it)) { // Same file different line m_textEditSource->highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); } else { // Different File updateTextEdit(); } m_comboBoxSearchPath->setCurrentIndex(m_file_idx); } checkFileStackButtons(); } }
void fileviewer::updateTextEdit(void) { if (m_iter == m_fileDataList.end()) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_textEditSource->clear(); QFile file(m_iter->filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QApplication::restoreOverrideCursor(); return; } QTextStream in(&file); int lang = enHighlightCPP; // default QRegExp rx1("\\.py$", Qt::CaseInsensitive); int pos = rx1.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightPython; QRegExp rx2("\\.java$", Qt::CaseInsensitive); pos = rx2.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJava; QRegExp rx3("\\.rb$", Qt::CaseInsensitive); pos = rx3.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightRuby; QRegExp rx4("\\.js$", Qt::CaseInsensitive); pos = rx4.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJavascript; m_currentlang = lang; setLexer(lang); QString alltext; while (!in.atEnd()) { alltext = in.readAll(); } m_textEditSource->setText(alltext); m_textEditSource->setMarginWidth(0, QString::number(m_textEditSource->lines() * 10)); highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); m_pushButtonGoToLine->setEnabled(true); m_pushButtonOpenInEditor->setEnabled(true); m_pushButtonTextShrink->setEnabled(true); m_pushButtonTextEnlarge->setEnabled(true); m_listWidgetFunc->clear(); if (m_iter->fileid < 0) {emit requestFuncList_filename(m_iter->filename);} else {emit requestFuncList_fileid(m_iter->fileid);} QApplication::restoreOverrideCursor(); }
void fileviewer::updateTextEdit(void) { if (!m_iter) return; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_textEditSource->clear(); m_highlighter->m_intAddlRulesMode = 0; //reset additional rules mode QFile file(m_iter->filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { QApplication::restoreOverrideCursor(); return; } QTextStream in(&file); int lang = enHighlightCPP; QRegExp rx1("\\.py$", Qt::CaseInsensitive); int pos = rx1.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightPython; QRegExp rx2("\\.java$", Qt::CaseInsensitive); pos = rx2.indexIn(m_iter->filename); if (pos != -1) lang = enHighlightJava; m_highlighter->m_intLanguage = lang; while (!in.atEnd()) { m_textEditSource->insertPlainText(in.readAll()); } m_textEditSource->highlightLine(m_iter->linenum.toInt()); updateFilePathLabel(); m_pushButtonGoToLine->setEnabled(true); m_pushButtonOpenInEditor->setEnabled(true); m_pushButtonTextShrink->setEnabled(true); m_pushButtonTextEnlarge->setEnabled(true); QApplication::restoreOverrideCursor(); }
void fileviewer::fileToBeOpened(QString filename, QString linenum) { filename.replace(QString("$HOME"), QDir::homePath()); #ifdef _WIN32 filename.replace("/", "\\"); #endif if (!(QFile::exists(filename))) { m_labelFilePath->setText(tr("File not found")); handleFileCannotBeOpenedCase(); return; } QFile file(filename); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { m_labelFilePath->setText(tr("File could not be opened")); handleFileCannotBeOpenedCase(); return; } file.close(); QFileInfo fi(filename); if ((m_DBtimestamp < fi.lastModified())&&(m_timestampMismatchWarned == false)) { m_timestampMismatchWarned = true; QMessageBox msgBox((QWidget*)mw); msgBox.setIcon(QMessageBox::Warning); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setText(tr("The source file to be viewed is newer than the CodeQuery database file. You are recommended to manually regenerate the CodeQuery database file.")); msgBox.exec(); } filedata fd(filename, linenum); if (m_fileDataList.isEmpty()) { m_fileDataList.push_back(fd); m_iter = m_fileDataList.end() - 1; m_pushButtonPrev->setEnabled(false); m_pushButtonNext->setEnabled(false); updateTextEdit(); return; } else if (m_iter == m_fileDataList.end()) { // previous file not found m_fileDataList.push_back(fd); m_iter = m_fileDataList.end() - 1; m_pushButtonPrev->setEnabled(m_iter != m_fileDataList.begin()); m_pushButtonNext->setEnabled(false); updateTextEdit(); } else if (m_iter->compare(fd)) { // the same filename and line number updateFilePathLabel(); return; } else if (m_iter->compareFilenameOnly(fd)) { // same file, different line number m_fileDataList.push_back(fd); m_iter = m_fileDataList.end() - 1; m_pushButtonPrev->setEnabled(true); m_pushButtonNext->setEnabled(false); highlightLine(fd.linenum.toInt()); updateFilePathLabel(); } else { // different file m_fileDataList.push_back(fd); m_iter = m_fileDataList.end() - 1; m_pushButtonPrev->setEnabled(true); m_pushButtonNext->setEnabled(false); updateTextEdit(); } QVector<filedata>::iterator it = m_fileDataList.begin(); while ((it != m_fileDataList.end() - 1)&&(it != m_fileDataList.end())) { if (it->compare(fd)) m_fileDataList.erase(it); else it++; } if (m_fileDataList.size() > 20) m_fileDataList.erase(m_fileDataList.begin()); }