- enhancement: slightly reduce start up time

This commit is contained in:
Roy Qu 2022-03-27 16:07:51 +08:00
parent ac54496aeb
commit db4ca7254e
4 changed files with 465 additions and 325 deletions

View File

@ -6,6 +6,7 @@ Red Panda C++ Version 1.0.2
- change: test to use utf-8 as the default encoding (prepare to use libclang to implement parser) - change: test to use utf-8 as the default encoding (prepare to use libclang to implement parser)
- fix: auto syntax check use wrong charset, if a file in editing is not encoded with ANSI encoding - fix: auto syntax check use wrong charset, if a file in editing is not encoded with ANSI encoding
- enhancement: timeout for problem case test in - enhancement: timeout for problem case test in
- enhancement: slightly reduce start up time
Red Panda C++ Version 1.0.1 Red Panda C++ Version 1.0.1
- fix: only convert project icon file when it's filename doesn't end with ".ico" - fix: only convert project icon file when it's filename doesn't end with ".ico"

View File

@ -67,6 +67,7 @@
#include <QTextBlock> #include <QTextBlock>
#include <QTranslator> #include <QTranslator>
#include <QFileIconProvider> #include <QFileIconProvider>
#include <MainWindow.h>
#include "settingsdialog/settingsdialog.h" #include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h" #include "compiler/compilermanager.h"
@ -132,7 +133,6 @@ MainWindow::MainWindow(QWidget *parent)
mProjectProxyModel = new ProjectModelSortFilterProxy(this); mProjectProxyModel = new ProjectModelSortFilterProxy(this);
ui->projectView->setModel(mProjectProxyModel); ui->projectView->setModel(mProjectProxyModel);
mProjectProxyModel->setDynamicSortFilter(false); mProjectProxyModel->setDynamicSortFilter(false);
setupActions();
ui->EditorTabsRight->setVisible(false); ui->EditorTabsRight->setVisible(false);
mCompilerSet = new QComboBox(); mCompilerSet = new QComboBox();
@ -215,7 +215,6 @@ MainWindow::MainWindow(QWidget *parent)
// updateEditorActions(); // updateEditorActions();
// updateCaretActions(); // updateCaretActions();
connect(ui->debugConsole,&QConsole::commandInput,this,&MainWindow::onDebugCommandInput); connect(ui->debugConsole,&QConsole::commandInput,this,&MainWindow::onDebugCommandInput);
connect(ui->cbEvaluate->lineEdit(), &QLineEdit::returnPressed, connect(ui->cbEvaluate->lineEdit(), &QLineEdit::returnPressed,
this, &MainWindow::onDebugEvaluateInput); this, &MainWindow::onDebugEvaluateInput);
@ -1198,10 +1197,6 @@ void MainWindow::changeOptions(const QString &widgetName, const QString &groupNa
} }
void MainWindow::setupActions() {
}
void MainWindow::updateCompilerSet() void MainWindow::updateCompilerSet()
{ {
mCompilerSet->blockSignals(true); mCompilerSet->blockSignals(true);
@ -2234,62 +2229,19 @@ void MainWindow::buildContextMenus()
tr("Properties..."), tr("Properties..."),
ui->lstProblemSet ui->lstProblemSet
); );
connect(mProblem_Properties, &QAction::triggered, connect(mProblem_Properties, &QAction::triggered, this,
[this]() { &MainWindow::onProblemProperties);
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (!idx.isValid())
return;
POJProblem problem=mOJProblemSetModel.problem(idx.row());
if (!problem)
return;
OJProblemPropertyWidget dialog;
dialog.setName(problem->name);
dialog.setUrl(problem->url);
dialog.setDescription(problem->description);
if (dialog.exec() == QDialog::Accepted) {
problem->url = dialog.url();
problem->description = dialog.description();
if (problem == mOJProblemModel.problem()) {
updateProblemTitle();
}
}
});
mProblem_OpenSource=createActionFor( mProblem_OpenSource=createActionFor(
tr("Open Source File"), tr("Open Source File"),
ui->lstProblemSet ui->lstProblemSet
); );
connect(mProblem_OpenSource, &QAction::triggered, connect(mProblem_OpenSource, &QAction::triggered, this,
[this]() { &MainWindow::onProblemOpenSource);
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (!idx.isValid())
return;
POJProblem problem=mOJProblemSetModel.problem(idx.row());
if (!problem)
return;
if (!problem->answerProgram.isEmpty()) {
Editor * editor = editorList()->getEditorByFilename(problem->answerProgram);
if (editor) {
editor->activate();
}
}
});
//context menu signal for the Problem Set lable //context menu signal for the Problem Set lable
ui->lblProblemSet->setContextMenuPolicy(Qt::CustomContextMenu); ui->lblProblemSet->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->lblProblemSet, &QWidget::customContextMenuRequested, connect(ui->lblProblemSet, &QWidget::customContextMenuRequested,
[this] { this, &MainWindow::onLableProblemSetContextMenuRequested);
QString newName = QInputDialog::getText(
ui->lblProblemSet,
tr("Set Problem Set Name"),
tr("Problem Set Name:"),
QLineEdit::Normal,
ui->lblProblemSet->text());
newName = newName.trimmed();
if (!newName.isEmpty()){
mOJProblemSetModel.rename(newName);
ui->lblProblemSet->setText(mOJProblemSetModel.name());
}
});
//context menu signal for the watch view //context menu signal for the watch view
ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu); ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2304,48 +2256,18 @@ void MainWindow::buildContextMenus()
tr("Remove"), tr("Remove"),
ui->tableBookmark); ui->tableBookmark);
connect(mBookmark_Remove, &QAction::triggered, connect(mBookmark_Remove, &QAction::triggered,
[this]() { this, &MainWindow::onBookmarkRemove);
QModelIndex index = ui->tableBookmark->currentIndex();
if (index.isValid()) {
PBookmark bookmark = mBookmarkModel->bookmark(index.row());
if (bookmark) {
Editor * editor = mEditorList->getOpenedEditorByFilename(bookmark->filename);
if (editor) {
editor->removeBookmark(bookmark->line);
} else {
mBookmarkModel->removeBookmarkAt(index.row());
}
}
}
});
mBookmark_RemoveAll=createActionFor( mBookmark_RemoveAll=createActionFor(
tr("Remove All Bookmarks"), tr("Remove All Bookmarks"),
ui->tableBookmark); ui->tableBookmark);
connect(mBookmark_RemoveAll, &QAction::triggered, connect(mBookmark_RemoveAll, &QAction::triggered,
[this]() { this, &MainWindow::onBookmarkRemoveAll);
mBookmarkModel->clear();
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * editor = (*mEditorList)[i];
editor->clearBookmarks();
}
});
mBookmark_Modify=createActionFor( mBookmark_Modify=createActionFor(
tr("Modify Description"), tr("Modify Description"),
ui->tableBookmark); ui->tableBookmark);
connect(mBookmark_Modify, &QAction::triggered, connect(mBookmark_Modify, &QAction::triggered,
[this]() { this, &MainWindow::onBookmarkModify);
QModelIndex index = ui->tableBookmark->currentIndex();
if (index.isValid()) {
PBookmark bookmark = mBookmarkModel->bookmark(index.row());
if (bookmark) {
QString desc = QInputDialog::getText(ui->tableBookmark,tr("Bookmark Description"),
tr("Description:"),QLineEdit::Normal,
bookmark->description);
desc = desc.trimmed();
mBookmarkModel->updateDescription(bookmark->filename,bookmark->line,desc);
}
}
});
//context menu signal for the watch view //context menu signal for the watch view
ui->debugConsole->setContextMenuPolicy(Qt::CustomContextMenu); ui->debugConsole->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2356,40 +2278,29 @@ void MainWindow::buildContextMenus()
ui->debugConsole); ui->debugConsole);
mDebugConsole_ShowDetailLog->setCheckable(true); mDebugConsole_ShowDetailLog->setCheckable(true);
connect(mDebugConsole_ShowDetailLog, &QAction::toggled, connect(mDebugConsole_ShowDetailLog, &QAction::toggled,
[this]() { this, &MainWindow::onDebugConsoleShowDetailLog);
pSettings->debugger().setShowDetailLog(mDebugConsole_ShowDetailLog->isChecked());
pSettings->debugger().save();
});
mDebugConsole_Copy=createActionFor( mDebugConsole_Copy=createActionFor(
tr("Copy"), tr("Copy"),
ui->debugConsole, ui->debugConsole,
QKeySequence("Ctrl+C")); QKeySequence("Ctrl+C"));
connect(mDebugConsole_Copy, &QAction::triggered, connect(mDebugConsole_Copy, &QAction::triggered,
[this]() { this, &MainWindow::onDebugConsoleCopy);
ui->debugConsole->copy();
});
mDebugConsole_Paste=createActionFor( mDebugConsole_Paste=createActionFor(
tr("Paste"), tr("Paste"),
ui->debugConsole, ui->debugConsole,
QKeySequence("Ctrl+V")); QKeySequence("Ctrl+V"));
connect(mDebugConsole_Paste, &QAction::triggered, connect(mDebugConsole_Paste, &QAction::triggered,
[this]() { this, &MainWindow::onDebugConsolePaste);
ui->debugConsole->paste();
});
mDebugConsole_SelectAll=createActionFor( mDebugConsole_SelectAll=createActionFor(
tr("Select All"), tr("Select All"),
ui->debugConsole); ui->debugConsole);
connect(mDebugConsole_SelectAll, &QAction::triggered, connect(mDebugConsole_SelectAll, &QAction::triggered,
[this]() { this, &MainWindow::onDebugConsoleSelectAll);
ui->debugConsole->selectAll();
});
mDebugConsole_Clear=createActionFor( mDebugConsole_Clear=createActionFor(
tr("Clear"), tr("Clear"),
ui->debugConsole); ui->debugConsole);
connect(mDebugConsole_Clear, &QAction::triggered, connect(mDebugConsole_Clear, &QAction::triggered,
[this]() { this, &MainWindow::onDebugConsoleClear);
ui->debugConsole->clear();
});
//context menu signal for Editor's tabbar //context menu signal for Editor's tabbar
ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2415,34 +2326,20 @@ void MainWindow::buildContextMenus()
ui->tableIssues, ui->tableIssues,
QKeySequence("Ctrl+C")); QKeySequence("Ctrl+C"));
connect(mTableIssuesCopyAction,&QAction::triggered, connect(mTableIssuesCopyAction,&QAction::triggered,
[this](){ this, &MainWindow::onTableIssuesCopy);
QModelIndex index = ui->tableIssues->selectionModel()->currentIndex();
PCompileIssue issue = ui->tableIssues->issue(index);
if (issue) {
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(issue->description);
}
});
mTableIssuesCopyAllAction = createActionFor( mTableIssuesCopyAllAction = createActionFor(
tr("Copy all"), tr("Copy all"),
ui->tableIssues, ui->tableIssues,
QKeySequence("Ctrl+Shift+C")); QKeySequence("Ctrl+Shift+C"));
connect(mTableIssuesCopyAllAction,&QAction::triggered, connect(mTableIssuesCopyAllAction,&QAction::triggered,
[this](){ this, &MainWindow::onTableIssuesCopyAll);
QClipboard* clipboard=QGuiApplication::clipboard();
QMimeData * mimeData = new QMimeData();
mimeData->setText(ui->tableIssues->toTxt());
mimeData->setHtml(ui->tableIssues->toHtml());
clipboard->clear();
clipboard->setMimeData(mimeData);
});
mTableIssuesClearAction = createActionFor( mTableIssuesClearAction = createActionFor(
tr("Clear"), tr("Clear"),
ui->tableIssues); ui->tableIssues);
connect(mTableIssuesClearAction,&QAction::triggered, connect(mTableIssuesClearAction,&QAction::triggered,
[this](){ this, &MainWindow::onTableIssuesClear);
clearIssues();
});
//context menu signal for search view //context menu signal for search view
ui->searchHistoryPanel->setContextMenuPolicy(Qt::CustomContextMenu); ui->searchHistoryPanel->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2452,19 +2349,12 @@ void MainWindow::buildContextMenus()
tr("Remove this search"), tr("Remove this search"),
ui->searchHistoryPanel); ui->searchHistoryPanel);
connect(mSearchViewClearAction, &QAction::triggered, connect(mSearchViewClearAction, &QAction::triggered,
[this](){ this, &MainWindow::onSearchViewClear);
int index = ui->cbSearchHistory->currentIndex();
if (index>=0) {
mSearchResultModel.removeSearchResults(index);
}
});
mSearchViewClearAllAction = createActionFor( mSearchViewClearAllAction = createActionFor(
tr("Clear all searches"), tr("Clear all searches"),
ui->searchHistoryPanel); ui->searchHistoryPanel);
connect(mSearchViewClearAllAction,&QAction::triggered, connect(mSearchViewClearAllAction,&QAction::triggered,
[this]() { this, &MainWindow::onSearchViewClearAll);
mSearchResultModel.clear();
});
//context menu signal for breakpoints view //context menu signal for breakpoints view
ui->tblBreakpoints->setContextMenuPolicy(Qt::CustomContextMenu); ui->tblBreakpoints->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2474,55 +2364,18 @@ void MainWindow::buildContextMenus()
tr("Breakpoint condition..."), tr("Breakpoint condition..."),
ui->tblBreakpoints); ui->tblBreakpoints);
connect(mBreakpointViewPropertyAction,&QAction::triggered, connect(mBreakpointViewPropertyAction,&QAction::triggered,
[this](){ this, &MainWindow::onBreakpointViewProperty);
int index =ui->tblBreakpoints->selectionModel()->currentIndex().row();
PBreakpoint breakpoint = debugger()->breakpointModel()->breakpoint(
index
);
if (breakpoint) {
bool isOk;
QString s=QInputDialog::getText(this,
tr("Break point condition"),
tr("Enter the condition of the breakpoint:"),
QLineEdit::Normal,
breakpoint->condition,&isOk);
if (isOk) {
pMainWindow->debugger()->setBreakPointCondition(index,s);
}
}
});
mBreakpointViewRemoveAllAction = createActionFor( mBreakpointViewRemoveAllAction = createActionFor(
tr("Remove All Breakpoints"), tr("Remove All Breakpoints"),
ui->tblBreakpoints); ui->tblBreakpoints);
connect(mBreakpointViewRemoveAllAction,&QAction::triggered, connect(mBreakpointViewRemoveAllAction,&QAction::triggered,
[this](){ this, &MainWindow::onBreakpointViewRemoveAll);
pMainWindow->debugger()->deleteBreakpoints();
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * e = (*(mEditorList))[i];
if (e) {
e->resetBreakpoints();
}
}
});
mBreakpointViewRemoveAction = createActionFor( mBreakpointViewRemoveAction = createActionFor(
tr("Remove Breakpoint"), tr("Remove Breakpoint"),
ui->tblBreakpoints); ui->tblBreakpoints);
connect(mBreakpointViewRemoveAction,&QAction::triggered, connect(mBreakpointViewRemoveAction,&QAction::triggered,
[this](){ this, &MainWindow::onBreakpointRemove);
int index =ui->tblBreakpoints->selectionModel()->currentIndex().row();
PBreakpoint breakpoint = debugger()->breakpointModel()->breakpoint(index);
if (breakpoint) {
Editor * e = mEditorList->getOpenedEditorByFilename(breakpoint->filename);
if (e) {
if (e->hasBreakpoint(breakpoint->line))
e->toggleBreakpoint(breakpoint->line);
} else {
debugger()->breakpointModel()->removeBreakpoint(index);
}
}
});
//context menu signal for project view //context menu signal for project view
ui->projectView->setContextMenuPolicy(Qt::CustomContextMenu); ui->projectView->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2532,88 +2385,35 @@ void MainWindow::buildContextMenus()
tr("Rename File"), tr("Rename File"),
ui->projectView); ui->projectView);
connect(mProject_Rename_Unit, &QAction::triggered, connect(mProject_Rename_Unit, &QAction::triggered,
[this](){ this, &MainWindow::onProjectRenameUnit);
if (ui->projectView->currentIndex().isValid()) {
ui->projectView->edit(ui->projectView->currentIndex());
}
});
mProject_Add_Folder = createActionFor( mProject_Add_Folder = createActionFor(
tr("Add Folder"), tr("Add Folder"),
ui->projectView); ui->projectView);
connect(mProject_Add_Folder, &QAction::triggered, connect(mProject_Add_Folder, &QAction::triggered,
[this](){ this, &MainWindow::onProjectAddFolder);
if (!mProject)
return;
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
if (!current.isValid()) {
return;
}
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
PProjectModelNode folderNode = mProject->pointerToNode(node);
if (!folderNode)
folderNode = mProject->rootNode();
if (folderNode->unitIndex>=0)
return;
QString s=tr("New folder");
bool ok;
s = QInputDialog::getText(ui->projectView,
tr("Add Folder"),
tr("Folder name:"),
QLineEdit::Normal, s,
&ok).trimmed();
if (ok && !s.isEmpty()) {
QString path = mProject->getFolderPath(folderNode);
if (path.isEmpty()) {
mProject->addFolder(s);
} else {
mProject->addFolder(path + '/' +s);
}
mProject->saveOptions();
}
});
mProject_Rename_Folder = createActionFor( mProject_Rename_Folder = createActionFor(
tr("Rename Folder"), tr("Rename Folder"),
ui->projectView); ui->projectView);
connect(mProject_Rename_Folder, &QAction::triggered, connect(mProject_Rename_Folder, &QAction::triggered,
[this](){ this, &MainWindow::onProjectRenameFolder);
if (ui->projectView->currentIndex().isValid()) {
ui->projectView->edit(ui->projectView->currentIndex());
}
});
mProject_Remove_Folder = createActionFor( mProject_Remove_Folder = createActionFor(
tr("Remove Folder"), tr("Remove Folder"),
ui->projectView); ui->projectView);
connect(mProject_Remove_Folder, &QAction::triggered, connect(mProject_Remove_Folder, &QAction::triggered,
[this](){ this, &MainWindow::onProjectRemoveFolder);
if (!mProject)
return;
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
if (!current.isValid()) {
return;
}
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
PProjectModelNode folderNode = mProject->pointerToNode(node);
if (!folderNode)
return;
if (folderNode->unitIndex>=0)
return;
mProject->removeFolder(folderNode);
mProject->saveOptions();
});
mProject_SwitchFileSystemViewMode = createActionFor( mProject_SwitchFileSystemViewMode = createActionFor(
tr("Switch to normal view"), tr("Switch to normal view"),
ui->projectView); ui->projectView);
connect(mProject_SwitchFileSystemViewMode, &QAction::triggered, connect(mProject_SwitchFileSystemViewMode, &QAction::triggered,
[this](){ this, &MainWindow::onProjectSwitchFileSystemViewMode);
mProject->setModelType(ProjectModelType::FileSystem);
});
mProject_SwitchCustomViewMode = createActionFor( mProject_SwitchCustomViewMode = createActionFor(
tr("Switch to custom view"), tr("Switch to custom view"),
ui->projectView); ui->projectView);
connect(mProject_SwitchCustomViewMode, &QAction::triggered, connect(mProject_SwitchCustomViewMode, &QAction::triggered,
[this](){ this, &MainWindow::onProjectSwitchCustomViewMode);
mProject->setModelType(ProjectModelType::Custom);
});
//context menu signal for class browser //context menu signal for class browser
ui->tabStructure->setContextMenuPolicy(Qt::CustomContextMenu); ui->tabStructure->setContextMenuPolicy(Qt::CustomContextMenu);
@ -2645,50 +2445,17 @@ void MainWindow::buildContextMenus()
mClassBrowser_Sort_By_Type->setChecked(pSettings->ui().classBrowserSortType()); mClassBrowser_Sort_By_Type->setChecked(pSettings->ui().classBrowserSortType());
mClassBrowser_Show_Inherited->setChecked(pSettings->ui().classBrowserShowInherited()); mClassBrowser_Show_Inherited->setChecked(pSettings->ui().classBrowserShowInherited());
connect(mClassBrowser_Sort_By_Name, &QAction::toggled, connect(mClassBrowser_Sort_By_Name, &QAction::toggled,
[this](){ this, &MainWindow::onClassBrowserSortByName);
pSettings->ui().setClassBrowserSortAlpha(mClassBrowser_Sort_By_Name->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
});
connect(mClassBrowser_Sort_By_Type, &QAction::toggled, connect(mClassBrowser_Sort_By_Type, &QAction::toggled,
[this](){ this, &MainWindow::onClassBrowserSortByType);
pSettings->ui().setClassBrowserSortType(mClassBrowser_Sort_By_Type->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
});
connect(mClassBrowser_Show_Inherited, &QAction::toggled, connect(mClassBrowser_Show_Inherited, &QAction::toggled,
[this](){ this, &MainWindow::onClassBrowserShowInherited);
pSettings->ui().setClassBrowserShowInherited(mClassBrowser_Show_Inherited->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
});
connect(mClassBrowser_goto_definition,&QAction::triggered, connect(mClassBrowser_goto_definition,&QAction::triggered,
[this](){ this, &MainWindow::onClassBrowserGotoDefinition);
QModelIndex index = ui->classBrowser->currentIndex();
if (!index.isValid())
return ;
ClassBrowserNode * node = static_cast<ClassBrowserNode*>(index.internalPointer());
if (!node)
return ;
PStatement statement = node->statement;
if (!statement) {
return;
}
QString filename;
int line;
filename = statement->definitionFileName;
line = statement->definitionLine;
Editor* e = pMainWindow->editorList()->getEditorByFilename(filename);
if (e) {
e->setCaretPositionAndActivate(line,1);
}
});
connect(mClassBrowser_goto_declaration,&QAction::triggered, connect(mClassBrowser_goto_declaration,&QAction::triggered,
[this](){ this, &MainWindow::onClassBrowserGotoDeclaration);
on_classBrowser_doubleClicked(ui->classBrowser->currentIndex());
});
//toolbar for class browser //toolbar for class browser
mClassBrowserToolbar = new QWidget(); mClassBrowserToolbar = new QWidget();
@ -2752,60 +2519,25 @@ void MainWindow::buildContextMenus()
tr("Open in Editor"), tr("Open in Editor"),
ui->treeFiles); ui->treeFiles);
connect(mFilesView_Open, &QAction::triggered, connect(mFilesView_Open, &QAction::triggered,
[this]() { this, &MainWindow::onFilesViewOpen);
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
Editor *editor=mEditorList->getEditorByFilename(path);
if (editor)
editor->activate();
}
});
mFilesView_OpenWithExternal = createActionFor( mFilesView_OpenWithExternal = createActionFor(
tr("Open in External Program"), tr("Open in External Program"),
ui->treeFiles); ui->treeFiles);
connect(mFilesView_OpenWithExternal, &QAction::triggered, connect(mFilesView_OpenWithExternal, &QAction::triggered,
[this]() { this, &MainWindow::onFilesViewOpenWithExternal);
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
});
mFilesView_OpenInTerminal = createActionFor( mFilesView_OpenInTerminal = createActionFor(
tr("Open in Terminal"), tr("Open in Terminal"),
ui->treeFiles); ui->treeFiles);
mFilesView_OpenInTerminal->setIcon(ui->actionOpen_Terminal->icon()); mFilesView_OpenInTerminal->setIcon(ui->actionOpen_Terminal->icon());
connect(mFilesView_OpenInTerminal, &QAction::triggered, connect(mFilesView_OpenInTerminal, &QAction::triggered,
[this]() { this, &MainWindow::onFilesViewOpenInTerminal);
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo fileInfo(path);
#ifdef Q_OS_WIN
openShell(fileInfo.path(),"cmd.exe");
#else
openShell(fileInfo.path(),pSettings->environment().terminalPath());
#endif
}
});
mFilesView_OpenInExplorer = createActionFor( mFilesView_OpenInExplorer = createActionFor(
tr("Open in Windows Explorer"), tr("Open in Windows Explorer"),
ui->treeFiles); ui->treeFiles);
mFilesView_OpenInExplorer->setIcon(ui->actionOpen_Containing_Folder->icon()); mFilesView_OpenInExplorer->setIcon(ui->actionOpen_Containing_Folder->icon());
connect(mFilesView_OpenInExplorer, &QAction::triggered, connect(mFilesView_OpenInExplorer, &QAction::triggered,
[this]() { this, &MainWindow::onFilesViewOpenInExplorer);
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo info(path);
if (info.isFile()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode));
} else if (info.isDir()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(path),QUrl::TolerantMode));
}
}
});
//toolbar for files view //toolbar for files view
{ {
@ -3666,6 +3398,380 @@ void MainWindow::onFilesViewRemoveFiles()
} }
} }
void MainWindow::onProblemProperties()
{
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (!idx.isValid())
return;
POJProblem problem=mOJProblemSetModel.problem(idx.row());
if (!problem)
return;
OJProblemPropertyWidget dialog;
dialog.setName(problem->name);
dialog.setUrl(problem->url);
dialog.setDescription(problem->description);
if (dialog.exec() == QDialog::Accepted) {
problem->url = dialog.url();
problem->description = dialog.description();
if (problem == mOJProblemModel.problem()) {
updateProblemTitle();
}
}
}
void MainWindow::onProblemOpenSource()
{
QModelIndex idx = ui->lstProblemSet->currentIndex();
if (!idx.isValid())
return;
POJProblem problem=mOJProblemSetModel.problem(idx.row());
if (!problem)
return;
if (!problem->answerProgram.isEmpty()) {
Editor * editor = editorList()->getEditorByFilename(problem->answerProgram);
if (editor) {
editor->activate();
}
}
}
void MainWindow::onLableProblemSetContextMenuRequested()
{
QString newName = QInputDialog::getText(
ui->lblProblemSet,
tr("Set Problem Set Name"),
tr("Problem Set Name:"),
QLineEdit::Normal,
ui->lblProblemSet->text());
newName = newName.trimmed();
if (!newName.isEmpty()){
mOJProblemSetModel.rename(newName);
ui->lblProblemSet->setText(mOJProblemSetModel.name());
}
}
void MainWindow::onBookmarkRemove()
{
QModelIndex index = ui->tableBookmark->currentIndex();
if (index.isValid()) {
PBookmark bookmark = mBookmarkModel->bookmark(index.row());
if (bookmark) {
Editor * editor = mEditorList->getOpenedEditorByFilename(bookmark->filename);
if (editor) {
editor->removeBookmark(bookmark->line);
} else {
mBookmarkModel->removeBookmarkAt(index.row());
}
}
}
}
void MainWindow::onBookmarkRemoveAll()
{
mBookmarkModel->clear();
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * editor = (*mEditorList)[i];
editor->clearBookmarks();
}
}
void MainWindow::onBookmarkModify()
{
QModelIndex index = ui->tableBookmark->currentIndex();
if (index.isValid()) {
PBookmark bookmark = mBookmarkModel->bookmark(index.row());
if (bookmark) {
QString desc = QInputDialog::getText(ui->tableBookmark,tr("Bookmark Description"),
tr("Description:"),QLineEdit::Normal,
bookmark->description);
desc = desc.trimmed();
mBookmarkModel->updateDescription(bookmark->filename,bookmark->line,desc);
}
}
}
void MainWindow::onDebugConsoleShowDetailLog()
{
pSettings->debugger().setShowDetailLog(mDebugConsole_ShowDetailLog->isChecked());
pSettings->debugger().save();
}
void MainWindow::onDebugConsolePaste()
{
ui->debugConsole->paste();
}
void MainWindow::onDebugConsoleSelectAll()
{
ui->debugConsole->selectAll();
}
void MainWindow::onDebugConsoleCopy()
{
ui->debugConsole->copy();
}
void MainWindow::onDebugConsoleClear()
{
ui->debugConsole->clear();
}
void MainWindow::onFilesViewOpenInExplorer()
{
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo info(path);
if (info.isFile()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode));
} else if (info.isDir()){
QDesktopServices::openUrl(
QUrl("file:///"+
includeTrailingPathDelimiter(path),QUrl::TolerantMode));
}
}
}
void MainWindow::onFilesViewOpenInTerminal()
{
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty()) {
QFileInfo fileInfo(path);
#ifdef Q_OS_WIN
openShell(fileInfo.path(),"cmd.exe");
#else
openShell(fileInfo.path(),pSettings->environment().terminalPath());
#endif
}
}
void MainWindow::onFilesViewOpenWithExternal()
{
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
}
void MainWindow::onFilesViewOpen()
{
QString path = mFileSystemModel.filePath(ui->treeFiles->currentIndex());
if (!path.isEmpty() && QFileInfo(path).isFile()) {
Editor *editor=mEditorList->getEditorByFilename(path);
if (editor)
editor->activate();
}
}
void MainWindow::onClassBrowserGotoDeclaration()
{
on_classBrowser_doubleClicked(ui->classBrowser->currentIndex());
}
void MainWindow::onClassBrowserGotoDefinition()
{
QModelIndex index = ui->classBrowser->currentIndex();
if (!index.isValid())
return ;
ClassBrowserNode * node = static_cast<ClassBrowserNode*>(index.internalPointer());
if (!node)
return ;
PStatement statement = node->statement;
if (!statement) {
return;
}
QString filename;
int line;
filename = statement->definitionFileName;
line = statement->definitionLine;
Editor* e = pMainWindow->editorList()->getEditorByFilename(filename);
if (e) {
e->setCaretPositionAndActivate(line,1);
}
}
void MainWindow::onClassBrowserShowInherited()
{
pSettings->ui().setClassBrowserShowInherited(mClassBrowser_Show_Inherited->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
}
void MainWindow::onClassBrowserSortByType()
{
pSettings->ui().setClassBrowserSortType(mClassBrowser_Sort_By_Type->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
}
void MainWindow::onClassBrowserSortByName()
{
pSettings->ui().setClassBrowserSortAlpha(mClassBrowser_Sort_By_Name->isChecked());
pSettings->ui().save();
mClassBrowserModel.fillStatements();
}
void MainWindow::onProjectSwitchCustomViewMode()
{
mProject->setModelType(ProjectModelType::Custom);
}
void MainWindow::onProjectSwitchFileSystemViewMode()
{
mProject->setModelType(ProjectModelType::FileSystem);
}
void MainWindow::onProjectRemoveFolder()
{
if (!mProject)
return;
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
if (!current.isValid()) {
return;
}
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
PProjectModelNode folderNode = mProject->pointerToNode(node);
if (!folderNode)
return;
if (folderNode->unitIndex>=0)
return;
mProject->removeFolder(folderNode);
mProject->saveOptions();
}
void MainWindow::onProjectRenameFolder()
{
if (ui->projectView->currentIndex().isValid()) {
ui->projectView->edit(ui->projectView->currentIndex());
}
}
void MainWindow::onProjectAddFolder()
{
if (!mProject)
return;
QModelIndex current = mProjectProxyModel->mapToSource(ui->projectView->currentIndex());
if (!current.isValid()) {
return;
}
ProjectModelNode * node = static_cast<ProjectModelNode*>(current.internalPointer());
PProjectModelNode folderNode = mProject->pointerToNode(node);
if (!folderNode)
folderNode = mProject->rootNode();
if (folderNode->unitIndex>=0)
return;
QString s=tr("New folder");
bool ok;
s = QInputDialog::getText(ui->projectView,
tr("Add Folder"),
tr("Folder name:"),
QLineEdit::Normal, s,
&ok).trimmed();
if (ok && !s.isEmpty()) {
QString path = mProject->getFolderPath(folderNode);
if (path.isEmpty()) {
mProject->addFolder(s);
} else {
mProject->addFolder(path + '/' +s);
}
mProject->saveOptions();
}
}
void MainWindow::onProjectRenameUnit()
{
if (ui->projectView->currentIndex().isValid()) {
ui->projectView->edit(ui->projectView->currentIndex());
}
}
void MainWindow::onBreakpointRemove()
{
int index =ui->tblBreakpoints->selectionModel()->currentIndex().row();
PBreakpoint breakpoint = debugger()->breakpointModel()->breakpoint(index);
if (breakpoint) {
Editor * e = mEditorList->getOpenedEditorByFilename(breakpoint->filename);
if (e) {
if (e->hasBreakpoint(breakpoint->line))
e->toggleBreakpoint(breakpoint->line);
} else {
debugger()->breakpointModel()->removeBreakpoint(index);
}
}
}
void MainWindow::onBreakpointViewRemoveAll()
{
pMainWindow->debugger()->deleteBreakpoints();
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * e = (*(mEditorList))[i];
if (e) {
e->resetBreakpoints();
}
}
}
void MainWindow::onBreakpointViewProperty()
{
int index =ui->tblBreakpoints->selectionModel()->currentIndex().row();
PBreakpoint breakpoint = debugger()->breakpointModel()->breakpoint(
index
);
if (breakpoint) {
bool isOk;
QString s=QInputDialog::getText(this,
tr("Break point condition"),
tr("Enter the condition of the breakpoint:"),
QLineEdit::Normal,
breakpoint->condition,&isOk);
if (isOk) {
pMainWindow->debugger()->setBreakPointCondition(index,s);
}
}
}
void MainWindow::onSearchViewClearAll()
{
mSearchResultModel.clear();
}
void MainWindow::onSearchViewClear()
{
int index = ui->cbSearchHistory->currentIndex();
if (index>=0) {
mSearchResultModel.removeSearchResults(index);
}
}
void MainWindow::onTableIssuesClear()
{
clearIssues();
}
void MainWindow::onTableIssuesCopyAll()
{
QClipboard* clipboard=QGuiApplication::clipboard();
QMimeData * mimeData = new QMimeData();
mimeData->setText(ui->tableIssues->toTxt());
mimeData->setHtml(ui->tableIssues->toHtml());
clipboard->clear();
clipboard->setMimeData(mimeData);
}
void MainWindow::onTableIssuesCopy()
{
QModelIndex index = ui->tableIssues->selectionModel()->currentIndex();
PCompileIssue issue = ui->tableIssues->issue(index);
if (issue) {
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(issue->description);
}
}
void MainWindow::onEditorContextMenu(const QPoint& pos) void MainWindow::onEditorContextMenu(const QPoint& pos)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();

View File

@ -231,7 +231,6 @@ private:
void updateProjectView(); void updateProjectView();
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();
bool debugInferiorhasBreakpoint(); bool debugInferiorhasBreakpoint();
void setupActions();
void openCloseBottomPanel(bool open); void openCloseBottomPanel(bool open);
void openCloseLeftPanel(bool open); void openCloseLeftPanel(bool open);
void prepareDebugger(); void prepareDebugger();
@ -293,6 +292,40 @@ private slots:
void onFilesViewCreateFolder(); void onFilesViewCreateFolder();
void onFilesViewCreateFile(); void onFilesViewCreateFile();
void onFilesViewRemoveFiles(); void onFilesViewRemoveFiles();
void onProblemProperties();
void onProblemOpenSource();
void onLableProblemSetContextMenuRequested();
void onBookmarkRemove();
void onBookmarkRemoveAll();
void onBookmarkModify();
void onDebugConsoleShowDetailLog();
void onDebugConsolePaste();
void onDebugConsoleSelectAll();
void onDebugConsoleCopy();
void onDebugConsoleClear();
void onFilesViewOpenInExplorer();
void onFilesViewOpenInTerminal();
void onFilesViewOpenWithExternal();
void onFilesViewOpen();
void onClassBrowserGotoDeclaration();
void onClassBrowserGotoDefinition();
void onClassBrowserShowInherited();
void onClassBrowserSortByType();
void onClassBrowserSortByName();
void onProjectSwitchCustomViewMode();
void onProjectSwitchFileSystemViewMode();
void onProjectRemoveFolder();
void onProjectRenameFolder();
void onProjectAddFolder();
void onProjectRenameUnit();
void onBreakpointRemove();
void onBreakpointViewRemoveAll();
void onBreakpointViewProperty();
void onSearchViewClearAll();
void onSearchViewClear();
void onTableIssuesClear();
void onTableIssuesCopyAll();
void onTableIssuesCopy();
void on_actionNew_triggered(); void on_actionNew_triggered();

View File

@ -96,7 +96,6 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue)
void Settings::load() void Settings::load()
{ {
mCompilerSets.loadSets(); mCompilerSets.loadSets();
mEnvironment.load(); mEnvironment.load();
mEditor.load(); mEditor.load();
@ -108,7 +107,6 @@ void Settings::load()
mUI.load(); mUI.load();
mDirs.load(); mDirs.load();
mVCS.load(); mVCS.load();
} }
Settings::Dirs &Settings::dirs() Settings::Dirs &Settings::dirs()
@ -2953,7 +2951,8 @@ void Settings::Environment::doLoad()
//Appearence //Appearence
mTheme = stringValue("theme","dark"); mTheme = stringValue("theme","dark");
QString defaultFontName = "Segoe UI"; QString defaultFontName = "Segoe UI";
if (QLocale::system().name() == "zh_CN") { QString defaultLocaleName = QLocale::system().name();
if (defaultLocaleName == "zh_CN") {
QString fontName; QString fontName;
fontName = "Microsoft Yahei"; fontName = "Microsoft Yahei";
QFont font(fontName); QFont font(fontName);
@ -2963,12 +2962,11 @@ void Settings::Environment::doLoad()
} }
mInterfaceFont = stringValue("interface_font",defaultFontName); mInterfaceFont = stringValue("interface_font",defaultFontName);
mInterfaceFontSize = intValue("interface_font_size",12); mInterfaceFontSize = intValue("interface_font_size",12);
mLanguage = stringValue("language", QLocale::system().name()); mLanguage = stringValue("language", defaultLocaleName);
mIconSet = stringValue("icon_set","contrast"); mIconSet = stringValue("icon_set","contrast");
mUseCustomIconSet = boolValue("use_custom_icon_set", false); mUseCustomIconSet = boolValue("use_custom_icon_set", false);
mUseCustomTheme = boolValue("use_custom_theme", false); mUseCustomTheme = boolValue("use_custom_theme", false);
mCurrentFolder = stringValue("current_folder",QDir::currentPath()); mCurrentFolder = stringValue("current_folder",QDir::currentPath());
if (!fileExists(mCurrentFolder)) { if (!fileExists(mCurrentFolder)) {
mCurrentFolder = QDir::currentPath(); mCurrentFolder = QDir::currentPath();
@ -5255,13 +5253,14 @@ void Settings::VCS::validateGit()
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
return; return;
} }
QStringList args; mGitOk=true;
args.append("--version"); // QStringList args;
QString output = runAndGetOutput( // args.append("--version");
fileInfo.fileName(), // QString output = runAndGetOutput(
fileInfo.absolutePath(), // fileInfo.fileName(),
args); // fileInfo.absolutePath(),
mGitOk = output.startsWith("git version"); // args);
// mGitOk = output.startsWith("git version");
} }
bool Settings::VCS::gitOk() const bool Settings::VCS::gitOk() const
@ -5283,6 +5282,7 @@ void Settings::VCS::detectGitInPath()
if (dir.exists(GIT_PROGRAM)) { if (dir.exists(GIT_PROGRAM)) {
QString oldPath = mGitPath; QString oldPath = mGitPath;
setGitPath(dir.filePath(GIT_PROGRAM)); setGitPath(dir.filePath(GIT_PROGRAM));
validateGit();
if (mGitOk) { if (mGitOk) {
save(); save();
return; return;