Skip to content

Commit cddae21

Browse files
committed
allow drag and right click of filename in symbol panel
use filesize to calculate tag update progress
1 parent 738bb63 commit cddae21

18 files changed

+422
-152
lines changed

Display/CEditor.cpp

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "Model/CConfigManager.h"
3131

3232
CEditor::CEditor(QWidget* parent)
33-
: QMainWindow(parent),
34-
findDlg_(this)
33+
: QMainWindow(parent),
34+
findDlg_(this)
3535
{
3636
setupUi(this);
3737

@@ -40,7 +40,7 @@ findDlg_(this)
4040
savedGeometry = CConfigManager::getInstance()->getValue("Editor", "geometry").toByteArray();
4141
this->restoreGeometry(savedGeometry);
4242

43-
connect(actionOpen, &QAction::triggered, this, &CEditor::openFile);
43+
connect(actionOpen, &QAction::triggered, this, &CEditor::openFile);
4444
connect(actionSave, &QAction::triggered, this, &CEditor::save);
4545
connect(actionSaveAs, &QAction::triggered, this, &CEditor::saveAs);
4646
connect(actionFind, &QAction::triggered, this, &CEditor::showFindDialog);
@@ -71,33 +71,33 @@ void CEditor::save()
7171

7272
void CEditor::saveAs()
7373
{
74-
QString fileName = QFileDialog::getSaveFileName(this, "Save File", filePathInTab(tabWidget->currentIndex()));
75-
if (fileName.isEmpty()) {
76-
return;
74+
QString fileName = QFileDialog::getSaveFileName(this, "Save File", filePathInTab(tabWidget->currentIndex()));
75+
if (fileName.isEmpty()) {
76+
return;
7777
}
7878

79-
saveFile(fileName);
79+
saveFile(fileName);
8080
}
8181

8282
void CEditor::saveFile(const QString &fileName)
8383
{
84-
QFile file(fileName);
85-
if (!file.open(QFile::WriteOnly)) {
86-
QMessageBox::warning(this, tr("Save file"),
87-
tr("Failed to write to file %1:\n%2.")
88-
.arg(fileName)
89-
.arg(file.errorString()));
90-
return;
91-
}
92-
93-
QTextStream fileOutput(&file);
94-
QApplication::setOverrideCursor(Qt::WaitCursor);
84+
QFile file(fileName);
85+
if (!file.open(QFile::WriteOnly)) {
86+
QMessageBox::warning(this, tr("Save file"),
87+
tr("Failed to write to file %1:\n%2.")
88+
.arg(fileName)
89+
.arg(file.errorString()));
90+
return;
91+
}
92+
93+
QTextStream fileOutput(&file);
94+
QApplication::setOverrideCursor(Qt::WaitCursor);
9595

9696
fileOutput << editorTabMap_[fileName].textEdit->text();
9797

98-
QApplication::restoreOverrideCursor();
98+
QApplication::restoreOverrideCursor();
9999

100-
statusBar()->showMessage(tr("File saved"), 2000);
100+
statusBar()->showMessage(tr("File saved"), 2000);
101101

102102
editorTabMap_[fileName].textEdit->setModified(false);
103103
setWindowModified(false);
@@ -117,6 +117,12 @@ void CEditor::findText(const QString& text, bool bMatchWholeWord, bool bCaseSens
117117
editorTabMap_[currentFileName].textEdit->findFirst(text, bRegularExpression, bCaseSensitive, bMatchWholeWord, true, true);
118118
}
119119

120+
void CEditor::loadFileWithLineNum(const QString& filePath, int lineNumber)
121+
{
122+
loadFile(filePath);
123+
editorTabMap_[filePath].textEdit->setFirstVisibleLine(lineNumber);
124+
}
125+
120126
void CEditor::loadFile(const QString& filePath)
121127
{
122128
if (editorTabMap_.contains(filePath)) { // load previous tab for existing file
@@ -158,11 +164,11 @@ void CEditor::loadFile(const QString& filePath)
158164
} else if (suffix == "v" || suffix == "vh" || suffix == "sv" || suffix == "svh") {
159165
lexer = new QsciLexerVerilog;
160166
} else {
161-
lexer = new QsciLexerCPP;
167+
lexer = new QsciLexerCPP;
162168
}
163169

164170
if (filename == "Makefile") {
165-
lexer = new QsciLexerMakefile;
171+
lexer = new QsciLexerMakefile;
166172
}
167173

168174
setEditorFont(lexer);
@@ -205,12 +211,12 @@ void CEditor::loadFile(const QString& filePath)
205211

206212
void CEditor::createActions(QsciScintilla* textEdit)
207213
{
208-
connect(actionCut, &QAction::triggered, textEdit, &QsciScintilla::cut);
209-
connect(actionCopy, &QAction::triggered, textEdit, &QsciScintilla::copy);
210-
connect(actionPaste, &QAction::triggered, textEdit, &QsciScintilla::paste);
214+
connect(actionCut, &QAction::triggered, textEdit, &QsciScintilla::cut);
215+
connect(actionCopy, &QAction::triggered, textEdit, &QsciScintilla::copy);
216+
connect(actionPaste, &QAction::triggered, textEdit, &QsciScintilla::paste);
211217

212-
connect(actionUndo, &QAction::triggered, textEdit, &QsciScintilla::undo);
213-
connect(actionRedo, &QAction::triggered, textEdit, &QsciScintilla::redo);
218+
connect(actionUndo, &QAction::triggered, textEdit, &QsciScintilla::undo);
219+
connect(actionRedo, &QAction::triggered, textEdit, &QsciScintilla::redo);
214220

215221
connect(textEdit, &QsciScintilla::textChanged, this, &CEditor::textEditModified);
216222
}
@@ -234,9 +240,9 @@ void CEditor::setEditorFont(QsciLexer* lexer)
234240
qDebug() << "editorFontSettingStr = " << editorFontSettingStr << endl;
235241

236242
if (editorFontSettingStr == "") {
237-
lexer->setFont(QApplication::font());
238-
} else {
239243
lexer->setFont(editorFont);
244+
} else {
245+
lexer->setFont(QApplication::font()); // using system default font
240246
}
241247
}
242248

@@ -247,8 +253,8 @@ void CEditor::saveWidgetPosition()
247253

248254
void CEditor::closeEvent(QCloseEvent *event)
249255
{
250-
saveWidgetPosition();
251-
event->accept();
256+
saveWidgetPosition();
257+
event->accept();
252258
}
253259

254260
void CEditor::tabChanged(int tabIndex) {
@@ -262,7 +268,7 @@ void CEditor::tabChanged(int tabIndex) {
262268
}
263269

264270
void CEditor::closeCurrentTab() {
265-
this->closeTab(tabWidget->currentIndex());
271+
this->closeTab(tabWidget->currentIndex());
266272
}
267273

268274
QString CEditor::filePathInTab(int tabIndex)
@@ -287,7 +293,7 @@ void CEditor::closeTab(int tabIndex)
287293

288294
qDebug() << "filePathRemoveFromMap = " << filePathRemoveFromMap;
289295

290-
tabWidget->removeTab(tabIndex);
296+
tabWidget->removeTab(tabIndex);
291297

292298
// close widget if tab count equals zero
293299
if (tabWidget->count() == 0) {

Display/CEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CEditor : public QMainWindow, private Ui::editor
2626
CEditor(QWidget* parent = 0);
2727

2828
virtual ~CEditor() {};
29+
void loadFileWithLineNum(const QString& filePath, int lineNumber);
2930
void loadFile(const QString& filePath);
3031

3132
private slots:

Display/CMainWindow.cpp

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ void CMainWindow::setSymbolFont(QFont symbolFont)
375375
QString symbolFontSize = QString::number(symbolFont.pointSize());
376376
QString lineHeight = QString::number(symbolFont.pointSize() / 3);
377377

378-
QString textDocumentSyleStr = QString("a {color: #0066FF; font-weight: bold; font-family: %1; text-decoration: none} functionsig {color: #33F000; font-weight:bold; font-family: %1;} code { display: table-row; font-family: Consolas; white-space: nowrap} linenum {color: #9999CC; font-family: %1} keyword {color: #00CCCC; font-weight:bold} spacesize {font-size: %3pt} body {background: #FAFAFA; font-size: %2pt}").arg(symbolFontFamily, symbolFontSize, lineHeight);
378+
QString textDocumentSyleStr = QString("a {color: #0066FF; font-weight: bold; font-family: %1; text-decoration: none} functionsig {color: #33F000; font-weight:bold; font-family: %1;} code {display: table-row; font-family: Consolas; white-space: nowrap} linenum {color: #9999CC; font-family: %1} keyword {color: #00CCCC; font-weight:bold} spacesize {font-size: %3pt} body {background: #FAFAFA; font-size: %2pt}").arg(symbolFontFamily, symbolFontSize, lineHeight);
379379

380380
textDocument_.setDefaultStyleSheet(textDocumentSyleStr);
381381
}
@@ -493,11 +493,12 @@ void CMainWindow::createActions()
493493

494494
connect(search_lineEdit, SIGNAL(returnPressed()), this, SLOT(on_searchButton_clicked()));
495495

496-
connect(CProjectManager::getInstance(), SIGNAL(projectMapUpdated()), this, SLOT(loadProjectList()));
497-
connect(CProjectManager::getInstance(), SIGNAL(groupMapUpdated()), this, SLOT(loadGroupList()));
496+
connect(CProjectManager::getInstance(), &CProjectManager::projectMapUpdated, this, &CMainWindow::loadProjectList);
497+
connect(CProjectManager::getInstance(), &CProjectManager::groupMapUpdated, this, &CMainWindow::loadGroupList);
498+
connect(CProjectManager::getInstance(), &CProjectManager::newProjectAdded, this, &CMainWindow::projectRebuildTag);
498499

499500
connect(&timeLine_, SIGNAL(frameChanged(int)), &progressBar_, SLOT(setValue(int)));
500-
connect(&projectUpdateThread_, SIGNAL(percentageCompleted(int)), this, SLOT(updateTagBuildProgress(int)));
501+
connect(&projectUpdateThread_, &CProjectUpdateThread::percentageCompleted, this, &CMainWindow::updateTagBuildProgress);
501502

502503
// update progress bar for cancelled tag build
503504
connect(&projectUpdateThread_, SIGNAL(cancelledTagBuild()), this, SLOT(updateCancelledTagBuild()));
@@ -593,7 +594,7 @@ void CMainWindow::createActions()
593594
connect(actionWebZoomOut, SIGNAL(triggered()), this, SLOT(webZoomOut()));
594595

595596
// connect for lauching editor from symbol panel
596-
connect(symbol_textBrowser, &CSearchTextEdit::linkActivated, this, &CMainWindow::launchEditor);
597+
connect(symbol_textBrowser, &CSearchTextEdit::linkActivated, this, &CMainWindow::launchEditorWithLineNum);
597598
}
598599

599600
void CMainWindow::on_newProjectButton_clicked()
@@ -669,7 +670,7 @@ void CMainWindow::on_updateProjectButton_clicked()
669670
projectItem.tagUpdateDateTime_ = currDateTime.toString("dd/MM/yyyy hh:mm:ss");
670671

671672
// tag last update date time updated so need update in project manager
672-
CProjectManager::getInstance()->updateProjectItem(projectItemName, projectItem);
673+
CProjectManager::getInstance()->updateProjectItem(false, projectItemName, projectItem);
673674

674675
statusBar()->showMessage("Updating tag for " + projectItem.name_ + "...");
675676

@@ -683,41 +684,46 @@ void CMainWindow::on_updateProjectButton_clicked()
683684
}
684685
}
685686

687+
void CMainWindow::projectRebuildTag(const QString projectItemName)
688+
{
689+
CProjectItem projectItem;
690+
QDateTime currDateTime;
691+
692+
projectItem = CProjectManager::getInstance()->getProjectItem(projectItemName);
693+
694+
QDir currentDir(QDir::currentPath());
695+
696+
// only update project if source directory exists
697+
if (currentDir.exists(projectItem.srcDir_)) {
698+
currDateTime = QDateTime::currentDateTime();
699+
projectItem.tagUpdateDateTime_ = currDateTime.toString("dd/MM/yyyy hh:mm:ss");
700+
701+
// tag last update date time updated so need update in project manager
702+
CProjectManager::getInstance()->updateProjectItem(false, projectItemName, projectItem);
703+
704+
statusBar()->showMessage("Rebuilding tag for " + projectItem.name_ + "...");
705+
706+
projectUpdateThread_.setRebuildTag(true);
707+
projectUpdateThread_.setCurrentProjectItem(projectItem);
708+
projectUpdateThread_.start(QThread::HighestPriority); // priority for update thread
709+
} else {
710+
QMessageBox::warning(this, "Load", "Cannot rebuilt project. Source directory doesn't exists.", QMessageBox::Ok);
711+
}
712+
}
713+
686714
void CMainWindow::on_rebuildTagProjectButton_clicked()
687715
{
688716
QStringList projectItemNameList = getSelectedProjectItemNameList();
689717
int projectSelected = projectItemNameList.size();
690718

691719
QString projectItemName;
692-
CProjectItem projectItem;
693-
QDateTime currDateTime;
694720

695721
if (projectSelected != 0) {
696722
if (projectSelected > 1) {
697723
QMessageBox::information(this, "Rebuild", "Only one project can be rebuilt each time", QMessageBox::Ok);
698724
} else {
699725
projectItemName = projectItemNameList.at(0);
700-
701-
projectItem = CProjectManager::getInstance()->getProjectItem(projectItemName);
702-
703-
QDir currentDir(QDir::currentPath());
704-
705-
// only update project if source directory exists
706-
if (currentDir.exists(projectItem.srcDir_)) {
707-
currDateTime = QDateTime::currentDateTime();
708-
projectItem.tagUpdateDateTime_ = currDateTime.toString("dd/MM/yyyy hh:mm:ss");
709-
710-
// tag last update date time updated so need update in project manager
711-
CProjectManager::getInstance()->updateProjectItem(projectItemName, projectItem);
712-
713-
statusBar()->showMessage("Rebuilding tag for " + projectItem.name_ + "...");
714-
715-
projectUpdateThread_.setRebuildTag(true);
716-
projectUpdateThread_.setCurrentProjectItem(projectItem);
717-
projectUpdateThread_.start(QThread::HighestPriority); // priority for update thread
718-
} else {
719-
QMessageBox::warning(this, "Load", "Cannot rebuilt project. Source directory doesn't exists.", QMessageBox::Ok);
720-
}
726+
projectRebuildTag(projectItemName);
721727
}
722728
}
723729
}
@@ -1197,6 +1203,8 @@ void CMainWindow::on_actionSetting_triggered()
11971203
QFont updatedSymbolFont = static_cast<CConfigDlg*> (dialog)->getSymbolDefaultFont();
11981204

11991205
setSymbolFont(updatedSymbolFont);
1206+
// update symbol panel
1207+
on_searchButton_clicked();
12001208
}
12011209
}
12021210

@@ -1281,7 +1289,7 @@ void CMainWindow::closeEvent(QCloseEvent *event)
12811289
event->accept();
12821290
}
12831291

1284-
void CMainWindow::updateTagBuildProgress(int percentage)
1292+
void CMainWindow::updateTagBuildProgress(int percentage, QString indexingFileName)
12851293
{
12861294
// show the progress bar when pecentage completed >= 0
12871295
if (percentage >= 0) {
@@ -1291,6 +1299,10 @@ void CMainWindow::updateTagBuildProgress(int percentage)
12911299

12921300
progressBar_.setValue(percentage);
12931301

1302+
if (indexingFileName != "") {
1303+
statusBar()->showMessage("Indexing " + indexingFileName + "...");
1304+
}
1305+
12941306
// hide the progress bar when completed
12951307
if (percentage == 100) {
12961308
statusBar()->showMessage("Tag update completed.");
@@ -1690,6 +1702,14 @@ void CMainWindow::on_fileEditExternalPressed()
16901702

16911703
QString consoleCommnad = confManager_->getAppSettingValue("DefaultEditor").toString();
16921704

1705+
if (consoleCommnad == "") {
1706+
QMessageBox msgBox;
1707+
msgBox.setIcon(QMessageBox::Information);
1708+
msgBox.setText("External editor has not be defined. Please set it in Options -> Settings -> Main -> External Editor");
1709+
msgBox.exec();
1710+
return;
1711+
}
1712+
16931713
#ifdef Q_OS_WIN
16941714
editFilename = "\"" + selectedItemList.at(0) + "\"";
16951715
#else
@@ -1707,6 +1727,13 @@ void CMainWindow::on_fileEditExternalPressed()
17071727
}
17081728
}
17091729

1730+
void CMainWindow::launchEditorWithLineNum(const QString &fileName, int lineNum)
1731+
{
1732+
editor_.loadFileWithLineNum(fileName, lineNum);
1733+
editor_.show();
1734+
QApplication::setActiveWindow(static_cast<QMainWindow*> (&editor_));
1735+
}
1736+
17101737
void CMainWindow::launchEditor(const QString &fileName)
17111738
{
17121739
editor_.loadFile(fileName);

Display/CMainWindow.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ private slots:
5959
void on_newProjectButton_clicked();
6060
void on_loadProjectButton_clicked();
6161
void on_updateProjectButton_clicked();
62+
63+
void projectRebuildTag(const QString projectItemName);
6264
void on_rebuildTagProjectButton_clicked();
6365
void on_projectCopyPressed();
6466

@@ -89,6 +91,7 @@ private slots:
8991
void on_actionSetting_triggered();
9092
void on_actionFindReplaceDialog_triggered();
9193

94+
void launchEditorWithLineNum(const QString &fileName, int lineNum);
9295
void launchEditor(const QString &fileName);
9396
void on_fileListItemDoubleClicked();
9497
void on_fileEditExternalPressed();
@@ -102,7 +105,7 @@ private slots:
102105

103106
void wheelEvent(QWheelEvent *e);
104107

105-
void updateTagBuildProgress(int percentage);
108+
void updateTagBuildProgress(int percentage, QString indexingFileName);
106109
void updateCancelledTagBuild();
107110

108111
void updateProjectLoadProgress(int percentage);

0 commit comments

Comments
 (0)