RedPanda-CPP/RedPandaIDE/mainwindow.cpp

3150 lines
98 KiB
C++
Raw Normal View History

#include <windows.h>
2021-04-06 23:10:57 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2021-04-07 21:13:15 +08:00
#include "editorlist.h"
#include "editor.h"
2021-04-11 21:33:08 +08:00
#include "systemconsts.h"
#include "settings.h"
2021-06-24 20:43:09 +08:00
#include "qsynedit/Constants.h"
2021-07-23 13:22:05 +08:00
#include "debugger.h"
2021-08-01 23:24:37 +08:00
#include "widgets/cpudialog.h"
#include "widgets/filepropertiesdialog.h"
2021-09-11 11:42:20 +08:00
#include "project.h"
2021-09-16 23:51:05 +08:00
#include "projecttemplate.h"
#include "widgets/newprojectdialog.h"
2021-07-26 11:47:54 +08:00
2021-04-09 17:48:25 +08:00
#include <QCloseEvent>
2021-04-18 11:41:41 +08:00
#include <QComboBox>
#include <QDesktopServices>
#include <QDragEnterEvent>
2021-04-11 21:33:08 +08:00
#include <QFileDialog>
2021-08-01 01:06:43 +08:00
#include <QInputDialog>
#include <QLabel>
2021-06-25 12:40:11 +08:00
#include <QMessageBox>
2021-09-05 19:10:54 +08:00
#include <QMimeData>
2021-06-20 09:27:37 +08:00
#include <QTranslator>
2021-04-20 22:24:33 +08:00
#include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QTextCodec>
2021-04-20 22:24:33 +08:00
#include <QDebug>
#include "cpprefacter.h"
2021-04-16 22:04:48 +08:00
2021-08-03 23:55:57 +08:00
#include <widgets/searchdialog.h>
MainWindow* pMainWindow;
2021-04-06 23:10:57 +08:00
MainWindow::MainWindow(QWidget *parent)
2021-06-23 22:38:02 +08:00
: QMainWindow(parent),
ui(new Ui::MainWindow),
mSearchDialog(nullptr),
mQuitting(false),
mOpenClosingBottomPanel(false),
mOpenClosingLeftPanel(false),
mCheckSyntaxInBack(false),
mClosing(false),
mSystemTurnedOff(false)
2021-04-06 23:10:57 +08:00
{
ui->setupUi(this);
// status bar
2021-04-18 11:41:41 +08:00
mFileInfoStatus=new QLabel();
mFileEncodingStatus = new QLabel();
mFileModeStatus = new QLabel();
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileModeStatus->setStyleSheet("margin-left:10px; margin-right:10px");
2021-08-27 23:51:42 +08:00
ui->statusbar->insertPermanentWidget(0,mFileModeStatus);
ui->statusbar->insertPermanentWidget(0,mFileEncodingStatus);
ui->statusbar->insertPermanentWidget(0,mFileInfoStatus);
2021-04-07 21:13:15 +08:00
mEditorList = new EditorList(ui->EditorTabsLeft,
ui->EditorTabsRight,
ui->splitterEditorPanel,
2021-04-07 21:13:15 +08:00
ui->EditorPanel);
2021-09-11 11:42:20 +08:00
mProject = nullptr;
setAcceptDrops(true);
2021-04-07 21:13:15 +08:00
setupActions();
2021-04-07 22:44:08 +08:00
ui->EditorTabsRight->setVisible(false);
2021-04-18 11:41:41 +08:00
mCompilerSet = new QComboBox();
2021-06-24 20:43:09 +08:00
mCompilerSet->setMinimumWidth(200);
2021-04-18 11:41:41 +08:00
ui->toolbarCompilerSet->addWidget(mCompilerSet);
connect(mCompilerSet,QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &MainWindow::onCompilerSetChanged);
updateCompilerSet();
2021-04-20 22:24:33 +08:00
mCompilerManager = new CompilerManager(this);
2021-07-23 13:22:05 +08:00
mDebugger = new Debugger(this);
2021-04-24 15:57:45 +08:00
2021-07-25 00:26:13 +08:00
ui->tblBreakpoints->setModel(mDebugger->breakpointModel());
ui->tblStackTrace->setModel(mDebugger->backtraceModel());
2021-08-01 01:06:43 +08:00
ui->watchView->setModel(mDebugger->watchModel());
2021-07-25 00:26:13 +08:00
2021-04-24 15:57:45 +08:00
ui->actionIndent->setShortcut(Qt::Key_Tab);
ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier);
ui->tableIssues->setErrorColor(QColor("Red"));
ui->tableIssues->setWarningColor(QColor("Orange"));
2021-08-01 01:06:43 +08:00
2021-09-16 23:51:05 +08:00
mMenuNew = new QMenu();
mMenuNew->setTitle(tr("New"));
mMenuNew->addAction(ui->actionNew);
mMenuNew->addAction(ui->actionNew_Project);
ui->menuFile->insertMenu(ui->actionOpen,mMenuNew);
mMenuEncoding = new QMenu();
mMenuEncoding->setTitle(tr("File Encoding"));
mMenuEncoding->addAction(ui->actionAuto_Detect);
mMenuEncoding->addAction(ui->actionEncode_in_ANSI);
mMenuEncoding->addAction(ui->actionEncode_in_UTF_8);
mMenuEncoding->addSeparator();
mMenuEncoding->addAction(ui->actionConvert_to_ANSI);
mMenuEncoding->addAction(ui->actionConvert_to_UTF_8);
ui->menuEdit->insertMenu(ui->actionFoldAll,mMenuEncoding);
ui->menuEdit->insertSeparator(ui->actionFoldAll);
ui->actionAuto_Detect->setCheckable(true);
ui->actionEncode_in_ANSI->setCheckable(true);
ui->actionEncode_in_UTF_8->setCheckable(true);
mMenuRecentProjects = new QMenu();
mMenuRecentProjects->setTitle(tr("Recent Projects"));
ui->menuFile->insertMenu(ui->actionExit, mMenuRecentProjects);
2021-08-02 10:08:25 +08:00
mMenuRecentFiles = new QMenu();
mMenuRecentFiles->setTitle(tr("Recent Files"));
ui->menuFile->insertMenu(ui->actionExit, mMenuRecentFiles);
ui->menuFile->insertSeparator(ui->actionExit);
rebuildOpenedFileHisotryMenu();
2021-08-01 23:24:37 +08:00
mCPUDialog = nullptr;
2021-07-26 11:47:54 +08:00
updateProjectView();
updateEditorActions();
updateCaretActions();
2021-06-18 21:48:40 +08:00
applySettings();
applyUISettings();
2021-08-01 23:24:37 +08:00
connect(ui->debugConsole,&QConsole::commandInput,this,&MainWindow::onDebugCommandInput);
2021-08-02 22:21:50 +08:00
connect(ui->cbEvaluate->lineEdit(), &QLineEdit::returnPressed,
this, &MainWindow::onDebugEvaluateInput);
2021-08-05 12:31:53 +08:00
mSearchResultTreeModel = std::make_shared<SearchResultTreeModel>(&mSearchResultModel);
mSearchResultListModel = std::make_shared<SearchResultListModel>(&mSearchResultModel);
mSearchViewDelegate = std::make_shared<SearchResultTreeViewDelegate>(mSearchResultTreeModel);
2021-08-05 19:58:32 +08:00
ui->cbSearchHistory->setModel(mSearchResultListModel.get());
2021-08-05 12:31:53 +08:00
ui->searchView->setModel(mSearchResultTreeModel.get());
ui->searchView->setItemDelegate(mSearchViewDelegate.get());
2021-08-05 19:58:32 +08:00
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false);
2021-08-23 17:27:17 +08:00
//class browser
ui->classBrowser->setModel(&mClassBrowserModel);
2021-08-29 00:48:23 +08:00
connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged,
this, &MainWindow::onFileChanged);
mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
2021-08-29 00:48:23 +08:00
updateAppTitle();
2021-08-30 22:05:45 +08:00
connect(&mAutoSaveTimer, &QTimer::timeout,
this, &MainWindow::onAutoSaveTimeout);
resetAutoSaveTimer();
connect(ui->menuFile, &QMenu::aboutToShow,
this,&MainWindow::rebuildOpenedFileHisotryMenu);
connect(ui->menuProject, &QMenu::aboutToShow,
this, &MainWindow::updateProjectActions);
buildContextMenus();
2021-04-06 23:10:57 +08:00
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateForEncodingInfo() {
Editor * editor = mEditorList->getEditor();
if (editor!=NULL) {
mFileEncodingStatus->setText(
QString("%1(%2)")
.arg(QString(editor->encodingOption())
,QString(editor->fileEncoding())));
ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8);
} else {
mFileEncodingStatus->setText("");
ui->actionAuto_Detect->setChecked(false);
ui->actionEncode_in_ANSI->setChecked(false);
ui->actionEncode_in_UTF_8->setChecked(false);
}
2021-04-11 13:55:31 +08:00
}
void MainWindow::updateEditorSettings()
2021-04-11 13:55:31 +08:00
{
mEditorList->applySettings();
}
void MainWindow::updateEditorActions()
{
Editor* e = mEditorList->getEditor();
if (e==nullptr) {
ui->actionAuto_Detect->setEnabled(false);
ui->actionEncode_in_ANSI->setEnabled(false);
ui->actionEncode_in_UTF_8->setEnabled(false);
ui->actionConvert_to_ANSI->setEnabled(false);
ui->actionConvert_to_UTF_8->setEnabled(false);
ui->actionCopy->setEnabled(false);
ui->actionCut->setEnabled(false);
ui->actionFoldAll->setEnabled(false);
ui->actionIndent->setEnabled(false);
ui->actionPaste->setEnabled(false);
ui->actionRedo->setEnabled(false);
ui->actionSave->setEnabled(false);
ui->actionSaveAs->setEnabled(false);
ui->actionSelectAll->setEnabled(false);
ui->actionToggleComment->setEnabled(false);
ui->actionUnIndent->setEnabled(false);
ui->actionUndo->setEnabled(false);
ui->actionUnfoldAll->setEnabled(false);
2021-08-05 19:58:32 +08:00
ui->actionFind->setEnabled(false);
ui->actionReplace->setEnabled(false);
ui->actionFind_Next->setEnabled(false);
ui->actionFind_Previous->setEnabled(false);
2021-09-02 12:14:02 +08:00
//code
ui->actionReformat_Code->setEnabled(false);
ui->actionClose->setEnabled(false);
ui->actionClose_All->setEnabled(false);
} else {
ui->actionAuto_Detect->setEnabled(true);
ui->actionEncode_in_ANSI->setEnabled(true);
ui->actionEncode_in_UTF_8->setEnabled(true);
ui->actionConvert_to_ANSI->setEnabled(e->encodingOption()!=ENCODING_SYSTEM_DEFAULT && e->fileEncoding()!=ENCODING_SYSTEM_DEFAULT);
ui->actionConvert_to_UTF_8->setEnabled(e->encodingOption()!=ENCODING_UTF8 && e->fileEncoding()!=ENCODING_UTF8);
2021-07-01 19:44:38 +08:00
ui->actionCopy->setEnabled(e->selAvail());
ui->actionCut->setEnabled(e->selAvail());
ui->actionFoldAll->setEnabled(e->lines()->count()>0);
ui->actionIndent->setEnabled(!e->readOnly());
ui->actionPaste->setEnabled(!e->readOnly() && !QGuiApplication::clipboard()->text().isEmpty());
ui->actionRedo->setEnabled(e->canRedo());
ui->actionUndo->setEnabled(e->canUndo());
ui->actionSave->setEnabled(e->modified());
ui->actionSaveAs->setEnabled(true);
ui->actionSelectAll->setEnabled(e->lines()->count()>0);
ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnfoldAll->setEnabled(e->lines()->count()>0);
2021-07-01 19:44:38 +08:00
2021-08-05 19:58:32 +08:00
ui->actionFind->setEnabled(true);
ui->actionReplace->setEnabled(true);
ui->actionFind_Next->setEnabled(true);
ui->actionFind_Previous->setEnabled(true);
2021-09-02 12:14:02 +08:00
//code
ui->actionReformat_Code->setEnabled(true);
ui->actionClose->setEnabled(true);
ui->actionClose_All->setEnabled(true);
}
updateCompileActions();
}
void MainWindow::updateProjectActions()
{
bool hasProject = (mProject != nullptr);
2021-09-17 20:01:11 +08:00
ui->actionView_Makefile->setEnabled(hasProject);
ui->actionProject_New_File->setEnabled(hasProject);
ui->actionAdd_to_project->setEnabled(hasProject);
ui->actionRemove_from_project->setEnabled(hasProject && ui->projectView->selectionModel()->selectedIndexes().count()>0);
ui->actionMakeClean->setEnabled(hasProject);
ui->actionProject_options->setEnabled(hasProject);
ui->actionClose_Project->setEnabled(hasProject);
updateCompileActions();
}
2021-07-01 19:44:38 +08:00
void MainWindow::updateCompileActions()
{
bool hasProject = (mProject!=nullptr);
bool editorCanCompile = false;
2021-09-04 21:54:58 +08:00
Editor * e = mEditorList->getEditor();
if (e) {
FileType fileType = getFileType(e->filename());
if (fileType == FileType::CSource
|| fileType == FileType::CppSource)
editorCanCompile = true;
}
2021-09-04 21:54:58 +08:00
if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing()
|| (!hasProject && !editorCanCompile) ) {
2021-07-01 19:44:38 +08:00
ui->actionCompile->setEnabled(false);
ui->actionCompile_Run->setEnabled(false);
ui->actionRun->setEnabled(false);
ui->actionRebuild->setEnabled(false);
2021-08-01 12:02:28 +08:00
ui->actionDebug->setEnabled(false);
2021-07-01 19:44:38 +08:00
} else {
ui->actionCompile->setEnabled(true);
ui->actionCompile_Run->setEnabled(true);
ui->actionRun->setEnabled(true);
ui->actionRebuild->setEnabled(true);
2021-08-01 12:02:28 +08:00
ui->actionDebug->setEnabled(true);
2021-07-01 19:44:38 +08:00
}
2021-08-01 12:02:28 +08:00
ui->actionStep_Into->setEnabled(mDebugger->executing());
ui->actionStep_Out->setEnabled(mDebugger->executing());
ui->actionStep_Over->setEnabled(mDebugger->executing());
ui->actionContinue->setEnabled(mDebugger->executing());
ui->actionRun_To_Cursor->setEnabled(mDebugger->executing());
ui->actionStop_Execution->setEnabled(mCompilerManager->running() || mDebugger->executing());
//it's not a compile action, but put here for convinience
ui->actionSaveAll->setEnabled(mProject!=nullptr
|| mEditorList->pageCount()>0);
2021-07-01 19:44:38 +08:00
}
2021-06-20 14:30:47 +08:00
void MainWindow::updateEditorColorSchemes()
{
mEditorList->applyColorSchemes(pSettings->editor().colorScheme());
}
2021-06-18 21:48:40 +08:00
void MainWindow::applySettings()
{
changeTheme(pSettings->environment().theme());
QFont font(pSettings->environment().interfaceFont(),
pSettings->environment().interfaceFontSize());
2021-06-20 09:27:37 +08:00
font.setStyleStrategy(QFont::PreferAntialias);
QApplication * app = dynamic_cast<QApplication*>(QApplication::instance());
app->setFont(font);
2021-06-20 22:54:16 +08:00
this->setFont(font);
2021-08-01 23:24:37 +08:00
updateDebuggerSettings();
2021-06-18 21:48:40 +08:00
}
void MainWindow::applyUISettings()
{
const Settings::UI& settings = pSettings->ui();
restoreGeometry(settings.mainWindowGeometry());
restoreState(settings.mainWindowState());
//we can show/hide left/bottom panels here, cause mainwindow layout is not calculated
// ui->tabMessages->setCurrentIndex(settings.bottomPanelIndex());
// if (settings.bottomPanelOpenned()) {
// mBottomPanelHeight = settings.bottomPanelHeight();
// openCloseBottomPanel(true);
// } else {
// openCloseBottomPanel(false);
// mBottomPanelHeight = settings.bottomPanelHeight();
// }
// ui->tabInfos->setCurrentIndex(settings.leftPanelIndex());
// if (settings.leftPanelOpenned()) {
// mLeftPanelWidth = settings.leftPanelWidth();
// openCloseLeftPanel(true);
// } else {
// openCloseLeftPanel(false);
// mLeftPanelWidth = settings.leftPanelWidth();
// }
}
QFileSystemWatcher *MainWindow::fileSystemWatcher()
{
return &mFileSystemWatcher;
}
2021-07-26 00:22:08 +08:00
void MainWindow::removeActiveBreakpoints()
{
for (int i=0;i<mEditorList->pageCount();i++) {
Editor* e= (*mEditorList)[i];
e->removeBreakpointFocus();
}
}
2021-07-26 18:22:09 +08:00
void MainWindow::setActiveBreakpoint(QString FileName, int Line, bool setFocus)
{
removeActiveBreakpoints();
// Then active the current line in the current file
FileName.replace('/',QDir::separator());
Editor *e = mEditorList->getEditorByFilename(FileName);
if (e!=nullptr) {
e->setActiveBreakpointFocus(Line,setFocus);
}
if (setFocus) {
this->activateWindow();
}
}
2021-07-26 00:22:08 +08:00
void MainWindow::updateAppTitle()
{
2021-07-26 11:47:54 +08:00
QString appName("Red Panda Dev-C++");
Editor *e = mEditorList->getEditor();
QCoreApplication *app = QApplication::instance();
if (e && !e->inProject()) {
2021-09-11 11:42:20 +08:00
QString str;
2021-07-26 11:47:54 +08:00
if (e->modified())
str = e->filename() + " [*]";
else
str = e->filename();
if (mDebugger->executing()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Debugging"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Debugging"),appName));
2021-07-26 11:47:54 +08:00
} else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Running"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Running"),appName));
2021-07-26 11:47:54 +08:00
} else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
2021-09-11 11:42:20 +08:00
.arg(str,tr("Compiling"),appName));
2021-07-26 11:47:54 +08:00
} else {
this->setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
2021-07-26 11:47:54 +08:00
}
2021-09-11 11:42:20 +08:00
} else if (e && e->inProject() && mProject) {
QString str,str2;
if (mProject->modified())
str = mProject->name() + " [*]";
else
str = mProject->name();
if (e->modified())
str2 = extractFileName(e->filename()) + " [*]";
else
str2 = extractFileName(e->filename());
if (mDebugger->executing()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Debugging"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Debugging"),appName));
} else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Running"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Running"),appName));
} else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - %2 [%3] - %4 %5")
.arg(str,str2,
tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Compiling"),appName));
} else {
setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
}
} else if (mProject) {
QString str,str2;
if (mProject->modified())
str = mProject->name() + " [*]";
else
str = mProject->name();
if (mDebugger->executing()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,tr("Debugging"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Debugging"),appName));
} else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,tr("Running"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Running"),appName));
} else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(str,tr("Compiling"),appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3")
.arg(str,tr("Compiling"),appName));
} else {
this->setWindowTitle(QString("%1 - %2 %3")
.arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
}
} else {
setWindowTitle(QString("%1 %2").arg(appName,DEVCPP_VERSION));
2021-08-29 00:48:23 +08:00
app->setApplicationName(QString("%1").arg(appName));
2021-07-26 11:47:54 +08:00
}
}
void MainWindow::addDebugOutput(const QString &text)
{
if (text.isEmpty()) {
ui->debugConsole->addLine("");
} else {
ui->debugConsole->addText(text);
}
2021-07-26 00:22:08 +08:00
}
2021-07-30 23:28:58 +08:00
void MainWindow::changeDebugOutputLastline(const QString &test)
{
ui->debugConsole->changeLastLine(test);
}
2021-08-01 23:24:37 +08:00
void MainWindow::updateDebugEval(const QString &value)
{
ui->txtEvalOutput->clear();
ui->txtEvalOutput->appendPlainText(value);
}
2021-08-02 10:08:25 +08:00
void MainWindow::rebuildOpenedFileHisotryMenu()
{
mMenuRecentFiles->clear();
mMenuRecentProjects->clear();
foreach (QAction* action,mRecentFileActions) {
2021-08-02 10:08:25 +08:00
action->setParent(nullptr);
action->deleteLater();
}
mRecentFileActions.clear();
foreach (QAction* action,mRecentProjectActions) {
action->setParent(nullptr);
action->deleteLater();
}
mRecentProjectActions.clear();
2021-08-02 10:08:25 +08:00
if (pSettings->history().openedFiles().size()==0) {
mMenuRecentFiles->setEnabled(false);
} else {
mMenuRecentFiles->setEnabled(true);
for (const QString& filename: pSettings->history().openedFiles()) {
2021-08-02 10:08:25 +08:00
QAction* action = new QAction();
action->setText(filename);
connect(action, &QAction::triggered, [&filename,this](bool){
2021-08-02 10:08:25 +08:00
this->openFile(filename);
});
mRecentFileActions.append(action);
}
mMenuRecentFiles->addActions(mRecentFileActions);
}
if (pSettings->history().openedProjects().size()==0) {
mMenuRecentProjects->setEnabled(false);
} else {
mMenuRecentProjects->setEnabled(true);
for (const QString& filename: pSettings->history().openedProjects()) {
QAction* action = new QAction();
action->setText(filename);
connect(action, &QAction::triggered, [&filename,this](bool){
this->openProject(filename);
});
mRecentProjectActions.append(action);
}
mMenuRecentProjects->addActions(mRecentProjectActions);
}
2021-08-02 10:08:25 +08:00
}
2021-08-23 17:27:17 +08:00
void MainWindow::updateClassBrowserForEditor(Editor *editor)
{
if (!editor) {
mClassBrowserModel.setParser(nullptr);
mClassBrowserModel.setCurrentFile("");
2021-08-23 21:50:53 +08:00
mClassBrowserModel.clear();
2021-08-23 17:27:17 +08:00
return;
}
if (mQuitting)
return;
// if not devCodeCompletion.Enabled then
// Exit;
if ((mClassBrowserModel.currentFile() == editor->filename())
&& (mClassBrowserModel.parser() == editor->parser()))
return;
mClassBrowserModel.beginUpdate();
{
auto action = finally([this] {
mClassBrowserModel.endUpdate();
});
mClassBrowserModel.setParser(editor->parser());
// if e.InProject then begin
// ClassBrowser.StatementsType := devClassBrowsing.StatementsType;
// end else
// ClassBrowser.StatementsType := cbstFile;
mClassBrowserModel.setCurrentFile(editor->filename());
}
}
2021-08-30 22:05:45 +08:00
void MainWindow::resetAutoSaveTimer()
{
if (pSettings->editor().enableAutoSave()) {
//minute to milliseconds
mAutoSaveTimer.start(pSettings->editor().autoSaveInterval()*60*1000);
} else {
mAutoSaveTimer.stop();
}
}
2021-08-01 10:00:27 +08:00
QPlainTextEdit *MainWindow::txtLocals()
{
return ui->txtLocals;
}
void MainWindow::updateStatusbarForLineCol()
2021-06-07 11:02:03 +08:00
{
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
int col = e->charToColumn(e->caretY(),e->caretX());
QString msg = tr("Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5")
.arg(e->caretY(),4)
.arg(col,3)
.arg(e->selText().length(),6)
.arg(e->lines()->count(),4)
.arg(e->lines()->getTextLength(),6);
mFileInfoStatus->setText(msg);
} else {
mFileInfoStatus->setText("");
}
}
void MainWindow::updateForStatusbarModeInfo()
{
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
QString msg;
if (e->readOnly()) {
msg = tr("Read Only");
} else if (e->insertMode()) {
msg = tr("Insert");
} else {
msg = tr("Overwrite");
}
mFileModeStatus->setText(msg);
} else {
mFileModeStatus->setText("");
}
2021-06-07 11:02:03 +08:00
}
2021-08-30 22:05:45 +08:00
void MainWindow::updateStatusbarMessage(const QString &s)
2021-08-27 16:38:55 +08:00
{
2021-08-27 23:51:42 +08:00
ui->statusbar->showMessage(s);
2021-08-27 16:38:55 +08:00
}
2021-04-11 21:33:08 +08:00
void MainWindow::openFiles(const QStringList &files)
{
mEditorList->beginUpdate();
auto end = finally([this] {
this->mEditorList->endUpdate();
});
2021-09-11 09:21:44 +08:00
//Check if there is a project file in the list and open it
for (const QString& file:files) {
if (getFileType(file)==FileType::Project) {
openProject(file);
return;
}
}
//Didn't find a project? Open all files
for (const QString& file:files) {
2021-04-11 21:33:08 +08:00
openFile(file);
}
mEditorList->endUpdate();
}
void MainWindow::openFile(const QString &filename)
{
2021-04-29 20:54:44 +08:00
Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
2021-04-11 21:33:08 +08:00
if (editor!=nullptr) {
editor->activate();
2021-04-11 21:33:08 +08:00
return;
}
try {
2021-09-11 11:42:20 +08:00
pSettings->history().removeFile(filename);
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
false,false);
editor->activate();
this->updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
2021-04-11 21:33:08 +08:00
}
2021-09-11 11:42:20 +08:00
void MainWindow::openProject(const QString &filename)
{
if (!fileExists(filename)) {
return;
}
if (mProject) {
QString s;
if (mProject->name().isEmpty())
s = mProject->filename();
else
s = mProject->name();
if (QMessageBox::question(this,
tr("Close project"),
tr("Are you sure you want to close %1?")
.arg(s),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
closeProject(false);
} else {
return;
}
}
ui->tabProject->setVisible(true);
ui->tabInfos->setCurrentWidget(ui->tabProject);
openCloseLeftPanel(true);
// {
// LeftPageControl.ActivePage := LeftProjectSheet;
// fLeftPageControlChanged := False;
// ClassBrowser.TabVisible:= False;
// }
// Only update class browser once
mClassBrowserModel.beginUpdate();
{
auto action = finally([this]{
mClassBrowserModel.endUpdate();
});
2021-09-11 18:42:49 +08:00
mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN);
updateProjectView();
2021-09-11 18:42:49 +08:00
pSettings->history().removeProject(filename);
2021-09-11 11:42:20 +08:00
// // if project manager isn't open then open it
// if not devData.ShowLeftPages then
// actProjectManager.Execute;
2021-09-11 18:42:49 +08:00
//checkForDllProfiling();
updateAppTitle();
updateCompilerSet();
2021-09-11 11:42:20 +08:00
//parse the project
// UpdateClassBrowsing;
scanActiveProject(true);
mProject->doAutoOpen();
2021-09-11 11:42:20 +08:00
//update editor's inproject flag
for (int i=0;i<mProject->units().count();i++) {
PProjectUnit unit = mProject->units()[i];
Editor* e = mEditorList->getOpenedEditorByFilename(unit->fileName());
2021-09-11 11:42:20 +08:00
if (e) {
unit->setEditor(e);
unit->setEncoding(e->encodingOption());
e->setInProject(true);
} else {
unit->setEditor(nullptr);
2021-09-11 11:42:20 +08:00
}
}
Editor * e = mEditorList->getEditor();
if (e) {
checkSyntaxInBack(e);
}
updateClassBrowserForEditor(e);
2021-09-11 11:42:20 +08:00
}
updateForEncodingInfo();
}
2021-04-07 21:13:15 +08:00
void MainWindow::setupActions() {
}
2021-04-18 11:41:41 +08:00
void MainWindow::updateCompilerSet()
{
mCompilerSet->clear();
2021-06-07 11:02:03 +08:00
for (size_t i=0;i<pSettings->compilerSets().list().size();i++) {
2021-04-18 11:41:41 +08:00
mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
}
2021-09-11 11:42:20 +08:00
int index=pSettings->compilerSets().defaultIndex();
if (mProject) {
Editor *e = mEditorList->getEditor();
if ( !e || e->inProject()) {
index = mProject->options().compilerSet;
}
}
2021-04-18 11:41:41 +08:00
if (index < 0 || index>=mCompilerSet->count()) {
2021-09-11 11:42:20 +08:00
index = pSettings->compilerSets().defaultIndex();
2021-04-18 11:41:41 +08:00
}
mCompilerSet->setCurrentIndex(index);
}
2021-08-01 23:24:37 +08:00
void MainWindow::updateDebuggerSettings()
{
ui->debugConsole->setFont(QFont(
pSettings->debugger().fontName(),
pSettings->debugger().fontSize()));
}
2021-06-24 20:43:09 +08:00
void MainWindow::checkSyntaxInBack(Editor *e)
{
if (e==nullptr)
return;
2021-09-11 11:42:20 +08:00
if (!pSettings->editor().syntaxCheck()) {
return;
}
2021-06-24 20:43:09 +08:00
// if not devEditor.AutoCheckSyntax then
// Exit;
//not c or cpp file
if (!e->highlighter() || e->highlighter()->getName()!=SYN_HIGHLIGHTER_CPP)
return;
if (mCompilerManager->backgroundSyntaxChecking())
return;
if (mCompilerManager->compiling())
return;
2021-08-23 21:50:53 +08:00
if (!pSettings->compilerSets().defaultSet())
return;
2021-06-24 20:43:09 +08:00
if (mCheckSyntaxInBack)
return;
mCheckSyntaxInBack=true;
ui->tableIssues->clearIssues();
2021-09-12 22:45:00 +08:00
CompileTarget target =getCompileTarget();
if (target ==CompileTarget::Project) {
mCompilerManager->checkSyntax(e->filename(),e->lines()->text(),
e->fileEncoding() == ENCODING_ASCII, mProject);
} else {
mCompilerManager->checkSyntax(e->filename(),e->lines()->text(),
e->fileEncoding() == ENCODING_ASCII, nullptr);
}
2021-06-24 20:43:09 +08:00
// if not PrepareForCompile(cttStdin,True) then begin
// fCheckSyntaxInBack:=False;
// Exit;
// end;
// if e.InProject then begin
// if not assigned(MainForm.fProject) then
// Exit;
// fSyntaxChecker.Project := MainForm.fProject;
// end;
2021-06-25 12:40:11 +08:00
// fSyntaxChecker.CheckSyntax(True);
}
bool MainWindow::compile(bool rebuild)
{
2021-09-12 22:45:00 +08:00
CompileTarget target =getCompileTarget();
if (target == CompileTarget::Project) {
if (!mProject->saveUnits())
return false;
// Check if saves have been succesful
for (int i=0; i<mEditorList->pageCount();i++) {
Editor * e= (*(mEditorList))[i];
if (e->inProject() && e->modified())
2021-06-25 12:40:11 +08:00
return false;
}
2021-09-13 22:45:50 +08:00
ui->tableIssues->clearIssues();
2021-09-12 22:45:00 +08:00
// Increment build number automagically
if (mProject->options().versionInfo.autoIncBuildNr) {
mProject->incrementBuildNumber();
}
mProject->buildPrivateResource();
2021-09-13 22:45:50 +08:00
if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = mProject->executable();
}
updateCompileActions();
openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput);
mCompilerManager->compileProject(mProject,rebuild);
updateAppTitle();
2021-09-12 22:45:00 +08:00
} else {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
ui->tableIssues->clearIssues();
if (editor->modified()) {
if (!editor->save(false,false))
return false;
}
if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename());
}
updateCompileActions();
openCloseBottomPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput);
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
2021-09-13 22:45:50 +08:00
updateAppTitle();
2021-09-12 22:45:00 +08:00
return true;
2021-06-25 12:40:11 +08:00
}
}
return false;
}
void MainWindow::runExecutable(const QString &exeName,const QString &filename)
{
// Check if it exists
2021-09-07 10:28:40 +08:00
if (!fileExists(exeName)) {
2021-06-25 12:40:11 +08:00
if (ui->actionCompile_Run->isEnabled()) {
2021-07-26 22:29:47 +08:00
if (QMessageBox::question(this,tr("Confirm"),
2021-06-25 12:40:11 +08:00
tr("Source file is not compiled.")
+"<br /><br />"+tr("Compile now?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
ui->actionCompile_Run->trigger();
return;
}
} else {
QMessageBox::critical(this,"Error",
tr("Source file is not compiled."));
return;
}
} else {
if (!filename.isEmpty() && compareFileModifiedTime(filename,exeName)>=0) {
if (ui->actionCompile_Run->isEnabled()) {
if (QMessageBox::warning(this,tr("Confirm"),
tr("Source file is more recent than executable.")
+"<br /><br />"+tr("Recompile now?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
ui->actionCompile_Run->trigger();
return;
}
}
}
}
// Pause programs if they contain a console
// if devData.ConsolePause and ProgramHasConsole(FileToRun) then begin
// if fUseRunParams then
// Parameters := '"' + FileToRun + '" ' + fRunParams
// else
// Parameters := '"' + FileToRun + '"';
// FileToRun := devDirs.Exec + 'ConsolePauser.exe';
// end else begin
// if fUseRunParams then
// Parameters := fRunParams
// else
// Parameters := '';
// FileToRun := FileToRun;
// end;
2021-07-01 19:44:38 +08:00
updateCompileActions();
if (pSettings->executor().minimizeOnRun()) {
showMinimized();
}
2021-07-26 22:29:47 +08:00
updateAppTitle();
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
2021-06-25 12:40:11 +08:00
}
void MainWindow::runExecutable()
{
2021-09-13 22:45:50 +08:00
CompileTarget target =getCompileTarget();
if (target == CompileTarget::Project) {
runExecutable(mProject->executable(),mProject->filename());
} else {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
if (editor->modified()) {
if (!editor->save(false,false))
return;
}
QString exeName= getCompiledExecutableName(editor->filename());
runExecutable(exeName,editor->filename());
2021-06-25 12:40:11 +08:00
}
}
2021-06-24 20:43:09 +08:00
}
2021-07-23 13:22:05 +08:00
void MainWindow::debug()
{
if (mCompilerManager->compiling())
return;
Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
2021-07-26 22:29:47 +08:00
if (!compilerSet) {
QMessageBox::critical(pMainWindow,
tr("No compiler set"),
tr("No compiler set is configured.")+"<BR/>"+tr("Can't start debugging."));
2021-07-23 13:22:05 +08:00
return;
2021-07-26 22:29:47 +08:00
}
2021-07-23 13:22:05 +08:00
bool debugEnabled;
bool stripEnabled;
2021-07-25 13:03:46 +08:00
QString filePath;
QFileInfo debugFile;
2021-07-23 13:22:05 +08:00
switch(getCompileTarget()) {
case CompileTarget::Project:
break;
// cttProject: begin
// // Check if we enabled proper options
// DebugEnabled := fProject.GetCompilerOption('-g3') <> '0';
// StripEnabled := fProject.GetCompilerOption('-s') <> '0';
// // Ask the user if he wants to enable debugging...
// if (not DebugEnabled or StripEnabled) then begin
// if (MessageDlg(Lang[ID_MSG_NODEBUGSYMBOLS], mtConfirmation, [mbYes,
// mbNo], 0) = mrYes) then begin
// // Enable debugging, disable stripping
// fProject.SetCompilerOption('-g3', '1');
// fProject.SetCompilerOption('-s', '0');
// fCompSuccessAction := csaDebug;
// actRebuildExecute(nil);
// end;
// Exit;
// end;
// // Did we compile?
// if not FileExists(fProject.Executable) then begin
// if MessageDlg(Lang[ID_ERR_PROJECTNOTCOMPILEDSUGGEST], mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
// fCompSuccessAction := csaDebug;
// actCompileExecute(nil);
// end;
// Exit;
// end;
// // Did we choose a host application for our DLL?
// if fProject.Options.typ = dptDyn then begin
// if fProject.Options.HostApplication = '' then begin
// MessageDlg(Lang[ID_ERR_HOSTMISSING], mtWarning, [mbOK], 0);
// exit;
// end else if not FileExists(fProject.Options.HostApplication) then begin
// MessageDlg(Lang[ID_ERR_HOSTNOTEXIST], mtWarning, [mbOK], 0);
// exit;
// end;
// end;
// // Reset UI, remove invalid breakpoints
// PrepareDebugger;
// filepath := fProject.Executable;
2021-08-20 12:43:01 +08:00
// if (!mDebugger->start())
// return;
2021-07-23 13:22:05 +08:00
// fDebugger.SendCommand('file', '"' + StringReplace(filepath, '\', '/', [rfReplaceAll]) + '"');
// if fProject.Options.typ = dptDyn then
// fDebugger.SendCommand('exec-file', '"' + StringReplace(fProject.Options.HostApplication, '\', '/',
// [rfReplaceAll])
// + '"');
// for i:=0 to fProject.Units.Count-1 do begin
// fDebugger.SendCommand('dir', '"'+StringReplace(
// ExtractFilePath(fProject.Units[i].FileName),'\', '/',[rfReplaceAll])
// + '"');
// end;
// for i:=0 to fProject.Options.Includes.Count-1 do begin
// fDebugger.SendCommand('dir', '"'+StringReplace(
// fProject.Options.Includes[i],'\', '/',[rfReplaceAll])
// + '"');
// end;
// for i:=0 to fProject.Options.Libs.Count-1 do begin
// fDebugger.SendCommand('dir', '"'+StringReplace(
// fProject.Options.Includes[i],'\', '/',[rfReplaceAll])
// + '"');
// end;
// end;
case CompileTarget::File:
// Check if we enabled proper options
debugEnabled = compilerSet->getOptionValue("-g3")!='0';
2021-07-27 00:14:24 +08:00
stripEnabled = compilerSet->getOptionValue("-s")!='0';
2021-07-23 13:22:05 +08:00
// Ask the user if he wants to enable debugging...
if (((!debugEnabled) || stripEnabled) &&
(QMessageBox::question(this,
tr("Enable debugging"),
2021-07-27 00:14:24 +08:00
tr("You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now?")
2021-07-23 13:22:05 +08:00
) == QMessageBox::Yes)) {
// Enable debugging, disable stripping
compilerSet->setOption("-g3",'1');
compilerSet->setOption("-s",'0');
// Save changes to compiler set
pSettings->compilerSets().saveSet(pSettings->compilerSets().defaultIndex());
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
compile();
return;
}
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
// Did we saved?
if (e->modified()) {
// if file is modified,save it first
if (!e->save(false,false))
return;
}
// Did we compiled?
2021-07-25 13:03:46 +08:00
filePath = getCompiledExecutableName(e->filename());
debugFile.setFile(filePath);
if (!debugFile.exists()) {
2021-07-23 13:22:05 +08:00
if (QMessageBox::question(this,tr("Compile"),
tr("Source file is not compiled.")+"<BR /><BR />" + tr("Compile now?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
compile();
return;
}
} else {
2021-07-25 13:03:46 +08:00
if (compareFileModifiedTime(e->filename(),filePath)>=0) {
2021-07-23 13:22:05 +08:00
if (QMessageBox::question(this,tr("Compile"),
tr("Source file is more recent than executable.")+"<BR /><BR />" + tr("Recompile?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::Yes) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
compile();
return;
}
}
}
prepareDebugger();
2021-07-25 13:03:46 +08:00
mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
2021-08-20 12:43:01 +08:00
if (!mDebugger->start())
return;
2021-07-25 13:03:46 +08:00
mDebugger->sendCommand("file", QString("\"%1\"").arg(debugFile.filePath().replace('\\','/')));
2021-07-23 13:22:05 +08:00
}
break;
}
2021-08-01 12:02:28 +08:00
updateEditorActions();
2021-07-23 13:22:05 +08:00
// Add library folders
foreach (QString dir,compilerSet->libDirs()) {
2021-07-23 13:22:05 +08:00
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
foreach (QString dir,compilerSet->defaultLibDirs()) {
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
2021-07-25 13:03:46 +08:00
// Add include folders
foreach (QString dir,compilerSet->CIncludeDirs()) {
2021-07-25 13:03:46 +08:00
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
foreach (QString dir,compilerSet->CppIncludeDirs()) {
2021-07-25 13:03:46 +08:00
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
foreach (QString dir,compilerSet->defaultCIncludeDirs()) {
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
foreach (QString dir,compilerSet->defaultCppIncludeDirs()) {
mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/')));
}
2021-07-23 13:22:05 +08:00
// Add breakpoints and watch vars
2021-07-26 18:22:09 +08:00
// for i := 0 to fDebugger.WatchVarList.Count - 1 do
// fDebugger.AddWatchVar(i);
mDebugger->sendAllWatchvarsToDebugger();
2021-07-25 13:03:46 +08:00
mDebugger->sendAllBreakpointsToDebugger();
2021-07-23 13:22:05 +08:00
// Run the debugger
2021-07-25 13:03:46 +08:00
mDebugger->sendCommand("set", "width 0"); // don't wrap output, very annoying
mDebugger->sendCommand("set", "new-console on");
mDebugger->sendCommand("set", "confirm off");
mDebugger->sendCommand("cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory
if (!debugInferiorhasBreakpoint()) {
QString params;
switch(getCompileTarget()) {
case CompileTarget::None:
return;
case CompileTarget::File:
// if (mCompiler->useRunParams) {
// }
mDebugger->sendCommand("start",params);
2021-07-26 18:22:09 +08:00
mDebugger->updateDebugInfo();
2021-07-25 13:03:46 +08:00
break;
case CompileTarget::Project:
//params := '';
//if fCompiler.UseRunParams then
// params := params + ' ' + fProject.Options.CmdLineArgs;
//if fCompiler.UseInputFile then
// params := params + ' < "' + fCompiler.InputFile + '"';
//fDebugger.SendCommand('start', params);
//UpdateDebugInfo;
break;
}
} else {
QString params;
switch(getCompileTarget()) {
case CompileTarget::None:
return;
case CompileTarget::File:
// if (mCompiler->useRunParams) {
// }
mDebugger->sendCommand("run",params);
2021-07-26 18:22:09 +08:00
mDebugger->updateDebugInfo();
2021-07-25 13:03:46 +08:00
break;
case CompileTarget::Project:
//params := '';
//if fCompiler.UseRunParams then
// params := params + ' ' + fProject.Options.CmdLineArgs;
//if fCompiler.UseInputFile then
// params := params + ' < "' + fCompiler.InputFile + '"';
//fDebugger.SendCommand('run', params);
//UpdateDebugInfo;
break;
}
}
2021-07-23 13:22:05 +08:00
}
2021-08-05 19:58:32 +08:00
void MainWindow::showSearchPanel()
{
openCloseBottomPanel(true);
2021-08-05 19:58:32 +08:00
ui->tabMessages->setCurrentWidget(ui->tabSearch);
}
void MainWindow::openCloseBottomPanel(bool open)
2021-06-23 22:38:02 +08:00
{
// if Assigned(fReportToolWindow) then
// Exit;
if (mOpenClosingBottomPanel)
return;
mOpenClosingBottomPanel = true;
auto action = finally([this]{
mOpenClosingBottomPanel = false;
});
2021-06-23 22:38:02 +08:00
// Switch between open and close
if (open) {
QList<int> sizes = ui->splitterMessages->sizes();
int tabHeight = ui->tabMessages->tabBar()->height();
ui->tabMessages->setMinimumHeight(tabHeight+5);
int totalSize = sizes[0] + sizes[1];
sizes[1] = mBottomPanelHeight;
2021-06-23 22:38:02 +08:00
sizes[0] = std::max(1,totalSize - sizes[1]);
ui->splitterMessages->setSizes(sizes);
} else {
QList<int> sizes = ui->splitterMessages->sizes();
mBottomPanelHeight = sizes[1];
2021-06-23 22:38:02 +08:00
int totalSize = sizes[0] + sizes[1];
int tabHeight = ui->tabMessages->tabBar()->height();
ui->tabMessages->setMinimumHeight(tabHeight);
sizes[1] = tabHeight;
sizes[0] = std::max(1,totalSize - sizes[1]);
ui->splitterMessages->setSizes(sizes);
}
mBottomPanelOpenned = open;
2021-06-23 22:38:02 +08:00
QSplitterHandle* handle = ui->splitterMessages->handle(1);
handle->setEnabled(open);
}
void MainWindow::openCloseLeftPanel(bool open)
{
if (mOpenClosingLeftPanel)
return;
mOpenClosingLeftPanel = true;
auto action = finally([this]{
mOpenClosingLeftPanel = false;
});
// Switch between open and close
if (open) {
QList<int> sizes = ui->splitterInfos->sizes();
int tabWidth = ui->tabInfos->tabBar()->width();
ui->tabInfos->setMinimumWidth(tabWidth+5);
int totalSize = sizes[0] + sizes[1];
sizes[0] = mLeftPanelWidth;
sizes[1] = std::max(1,totalSize - sizes[0]);
ui->splitterInfos->setSizes(sizes);
} else {
QList<int> sizes = ui->splitterInfos->sizes();
mLeftPanelWidth = sizes[0];
int totalSize = sizes[0] + sizes[1];
int tabWidth = ui->tabInfos->tabBar()->width();
ui->tabInfos->setMinimumWidth(tabWidth);
sizes[0] = tabWidth;
sizes[1] = std::max(1,totalSize - sizes[0]);
ui->splitterInfos->setSizes(sizes);
}
mLeftPanelOpenned = open;
QSplitterHandle* handle = ui->splitterInfos->handle(1);
handle->setEnabled(open);
2021-06-23 22:38:02 +08:00
}
2021-07-23 13:22:05 +08:00
void MainWindow::prepareDebugger()
{
mDebugger->stop();
// Clear logs
ui->debugConsole->clear();
ui->txtEvalOutput->clear();
// Restore when no watch vars are shown
2021-07-26 18:22:09 +08:00
mDebugger->setLeftPageIndexBackup(ui->tabInfos->currentIndex());
2021-07-23 13:22:05 +08:00
// Focus on the debugging buttons
ui->tabInfos->setCurrentWidget(ui->tabWatch);
ui->tabMessages->setCurrentWidget(ui->tabDebug);
ui->debugViews->setCurrentWidget(ui->tabDebugConsole);
openCloseBottomPanel(true);
openCloseLeftPanel(true);
2021-07-23 13:22:05 +08:00
// Reset watch vars
// mDebugger->deleteWatchVars(false);
}
2021-08-30 22:05:45 +08:00
void MainWindow::doAutoSave(Editor *e)
{
if (!e)
return;
if (!e->modified())
return;
QString filename = e->filename();
QFileInfo fileInfo(filename);
QDir parent = fileInfo.absoluteDir();
QString baseName = fileInfo.completeBaseName();
QString suffix = fileInfo.suffix();
switch(pSettings->editor().autoSaveStrategy()) {
case assOverwrite:
break;
case assAppendUnixTimestamp:
filename = parent.filePath(
QString("%1.%2.%3")
.arg(baseName)
.arg(QDateTime::currentSecsSinceEpoch())
.arg(suffix));
break;
case assAppendFormatedTimeStamp: {
QDateTime time = QDateTime::currentDateTime();
filename = parent.filePath(
QString("%1.%2.%3")
.arg(baseName)
.arg(time.toString("yyyy.MM.dd.hh.mm.ss"))
.arg(suffix));
}
}
e->saveFile(filename);
}
//static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) {
// action->setParent(scopeWidget);
// action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
//}
QAction* MainWindow::createActionFor(
const QString& text,
QWidget* parent,
QKeySequence shortcut) {
QAction* action= new QAction(text,parent);
if (!shortcut.isEmpty())
action->setShortcut(shortcut);
action->setPriority(QAction::HighPriority);
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
parent->addAction(action);
return action;
}
2021-09-11 18:42:49 +08:00
void MainWindow::scanActiveProject(bool parse)
{
if (!mProject)
return;
//UpdateClassBrowsing;
if (parse) {
resetCppParser(mProject->cppParser());
mProject->resetParserProjectFiles();
parseFileList(mProject->cppParser());
} else {
mProject->resetParserProjectFiles();
};
}
void MainWindow::buildContextMenus()
{
2021-09-05 19:10:54 +08:00
//context menu signal for the watch view
ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->watchView,&QWidget::customContextMenuRequested,
this, &MainWindow::onWatchViewContextMenu);
2021-09-05 19:10:54 +08:00
//context menu signal for Editor's tabbar
ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsLeft->tabBar(),&QWidget::customContextMenuRequested,
2021-09-04 22:15:02 +08:00
this, &MainWindow::onEditorTabContextMenu);
ui->EditorTabsRight->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested,
2021-09-04 22:15:02 +08:00
this, &MainWindow::onEditorTabContextMenu);
2021-09-05 19:10:54 +08:00
//context menu signal for Compile Issue view
ui->tableIssues->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableIssues,&QWidget::customContextMenuRequested,
this, &MainWindow::onTableIssuesContextMenu);
mTableIssuesCopyAction = createActionFor(
tr("Copy"),
ui->tableIssues,
QKeySequence("Ctrl+C"));
connect(mTableIssuesCopyAction,&QAction::triggered,
[this](){
QModelIndex index = ui->tableIssues->selectionModel()->currentIndex();
PCompileIssue issue = ui->tableIssues->issue(index);
if (issue) {
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(issue->description);
}
});
mTableIssuesCopyAllAction = createActionFor(
tr("Copy all"),
ui->tableIssues,
QKeySequence("Ctrl+Shift+C"));
connect(mTableIssuesCopyAllAction,&QAction::triggered,
[this](){
2021-09-05 19:10:54 +08:00
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(
tr("Clear"),
ui->tableIssues);
connect(mTableIssuesClearAction,&QAction::triggered,
[this](){
ui->tableIssues->clearIssues();
});
//context menu signal for search view
ui->searchHistoryPanel->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->searchHistoryPanel, &QWidget::customContextMenuRequested,
this, &MainWindow::onSearchViewContextMenu);
mSearchViewClearAction = createActionFor(
tr("Remove this search"),
ui->searchHistoryPanel);
connect(mSearchViewClearAction, &QAction::triggered,
[this](){
int index = ui->cbSearchHistory->currentIndex();
if (index>=0) {
mSearchResultModel.removeSearchResults(index);
}
});
mSearchViewClearAllAction = createActionFor(
tr("Clear all searches"),
ui->searchHistoryPanel);
connect(mSearchViewClearAllAction,&QAction::triggered,
[this]() {
mSearchResultModel.clear();
});
//context menu signal for breakpoints view
ui->tblBreakpoints->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tblBreakpoints,&QWidget::customContextMenuRequested,
this, &MainWindow::onBreakpointsViewContextMenu);
mBreakpointViewPropertyAction = createActionFor(
tr("Breakpoint condition..."),
ui->tblBreakpoints);
connect(mBreakpointViewPropertyAction,&QAction::triggered,
[this](){
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(
tr("Remove all breakpoints"),
ui->tblBreakpoints);
connect(mBreakpointViewRemoveAllAction,&QAction::triggered,
[this](){
pMainWindow->debugger()->deleteBreakpoints();
});
}
void MainWindow::maximizeEditor()
{
if (mLeftPanelOpenned || mBottomPanelOpenned) {
openCloseBottomPanel(false);
openCloseLeftPanel(false);
} else {
openCloseBottomPanel(true);
openCloseLeftPanel(true);
}
}
void MainWindow::openShell(const QString &folder, const QString &shellCommand)
{
QProcess process;
process.setWorkingDirectory(folder);
process.setProgram(shellCommand);
process.setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments * args){
args->flags |= CREATE_NEW_CONSOLE;
args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; //
});
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH");
QStringList pathAdded;
if (pSettings->compilerSets().defaultSet()) {
foreach(const QString& dir, pSettings->compilerSets().defaultSet()->binDirs()) {
pathAdded.append(dir);
}
}
pathAdded.append(pSettings->dirs().app());
if (!path.isEmpty()) {
2021-09-17 19:58:37 +08:00
path= pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path;
} else {
path = pathAdded.join(PATH_SEPARATOR);
}
env.insert("PATH",path);
process.setProcessEnvironment(env);
process.startDetached();
}
2021-08-30 22:05:45 +08:00
void MainWindow::onAutoSaveTimeout()
{
if (!pSettings->editor().enableAutoSave())
return;
int updateCount = 0;
switch (pSettings->editor().autoSaveTarget()) {
case astCurrentFile: {
Editor *e = mEditorList->getEditor();
doAutoSave(e);
updateCount++;
}
break;
case astAllOpennedFiles:
for (int i=0;i<mEditorList->pageCount();i++) {
Editor *e = (*mEditorList)[i];
doAutoSave(e);
updateCount++;
}
break;
case astAllProjectFiles:
//todo: auto save project files
break;
}
updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount));
}
void MainWindow::onWatchViewContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(ui->actionAdd_Watch);
menu.addAction(ui->actionRemove_Watch);
menu.addAction(ui->actionRemove_All_Watches);
menu.addAction(ui->actionModify_Watch);
menu.exec(ui->watchView->mapToGlobal(pos));
}
void MainWindow::onTableIssuesContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mTableIssuesCopyAction);
menu.addAction(mTableIssuesCopyAllAction);
menu.addSeparator();
menu.addAction(mTableIssuesClearAction);
menu.exec(ui->tableIssues->mapToGlobal(pos));
}
void MainWindow::onSearchViewContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mSearchViewClearAction);
menu.addAction(mSearchViewClearAllAction);
menu.exec(ui->searchHistoryPanel->mapToGlobal(pos));
}
void MainWindow::onBreakpointsViewContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mBreakpointViewPropertyAction);
menu.addAction(mBreakpointViewRemoveAllAction);
menu.exec(ui->tblBreakpoints->mapToGlobal(pos));
}
void MainWindow::onEditorContextMenu(const QPoint &pos)
{
Editor * editor = mEditorList->getEditor();
if (!editor)
return;
QMenu menu(this);
BufferCoord p;
mEditorContextMenuPos = pos;
if (editor->GetPositionOfMouse(p)) {
//mouse on editing area
menu.addAction(ui->actionCompile_Run);
menu.addAction(ui->actionDebug);
menu.addSeparator();
2021-09-03 11:50:04 +08:00
menu.addAction(ui->actionGoto_Declaration);
menu.addAction(ui->actionGoto_Definition);
menu.addAction(ui->actionFind_references);
menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal);
menu.addSeparator();
menu.addAction(ui->actionReformat_Code);
menu.addSeparator();
menu.addAction(ui->actionCut);
menu.addAction(ui->actionCopy);
menu.addAction(ui->actionPaste);
menu.addAction(ui->actionSelectAll);
menu.addSeparator();
menu.addAction(ui->actionAdd_Watch);
menu.addAction(ui->actionToggle_Breakpoint);
menu.addAction(ui->actionClear_all_breakpoints);
menu.addSeparator();
menu.addAction(ui->actionFile_Properties);
//these actions needs parser
ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing());
ui->actionGoto_Definition->setEnabled(!editor->parser()->parsing());
ui->actionFind_references->setEnabled(!editor->parser()->parsing());
} else {
//mouse on gutter
int line;
if (!editor->GetLineOfMouse(line))
line=-1;
menu.addAction(ui->actionToggle_Breakpoint);
menu.addAction(ui->actionBreakpoint_property);
menu.addAction(ui->actionClear_all_breakpoints);
ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line));
}
menu.exec(editor->viewport()->mapToGlobal(pos));
}
2021-09-04 22:15:02 +08:00
void MainWindow::onEditorTabContextMenu(const QPoint &pos)
{
int index = ui->EditorTabsLeft->tabBar()->tabAt(pos);
if (index<0)
return;
ui->EditorTabsLeft->setCurrentIndex(index);
QMenu menu(this);
QTabBar* tabBar = ui->EditorTabsLeft->tabBar();
menu.addAction(ui->actionClose);
menu.addAction(ui->actionClose_All);
menu.addSeparator();
menu.addAction(ui->actionOpen_Containing_Folder);
menu.addAction(ui->actionOpen_Terminal);
menu.addSeparator();
menu.addAction(ui->actionFile_Properties);
2021-09-04 22:15:02 +08:00
menu.exec(tabBar->mapToGlobal(pos));
2021-09-04 22:15:02 +08:00
}
void MainWindow::prepareProjectForCompile()
{
if (!mProject)
return;
if (!mProject->saveUnits())
return;
// Check if saves have been succesful
for (int i=0; i<mEditorList->pageCount();i++) {
Editor * e= (*(mEditorList))[i];
if (e->inProject() && e->modified())
return;
}
mProject->buildPrivateResource();
}
2021-09-11 18:42:49 +08:00
void MainWindow::closeProject(bool refreshEditor)
{
// Stop executing program
on_actionStop_Execution_triggered();
// Only update file monitor once (and ignore updates)
bool oldBlock= mFileSystemWatcher.blockSignals(true);
{
auto action = finally([&,this]{
mFileSystemWatcher.blockSignals(oldBlock);
});
// TODO: should we save watches?
if (mProject->modified()) {
QString s;
if (mProject->name().isEmpty()) {
s = mProject->filename();
} else {
s = mProject->name();
}
if (mSystemTurnedOff) {
mProject->saveAll();
} else {
int answer = QMessageBox::question(
this,
tr("Save project"),
tr("The project '%1' has modifications.").arg(s)
+ "<br />"
+ tr("Do you want to save it?"),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Yes);
switch (answer) {
case QMessageBox::Yes:
mProject->saveAll();
break;
case QMessageBox::No:
mProject->setModified(false);
mProject->saveLayout();
break;
case QMessageBox::Cancel:
mProject->saveLayout();
return;
}
}
} else
mProject->saveLayout(); // always save layout, but not when SaveAll has been called
mClassBrowserModel.beginUpdate();
{
auto action2 = finally([this]{
mClassBrowserModel.endUpdate();
});
// Remember it
pSettings->history().addToOpenedProjects(mProject->filename());
mEditorList->beginUpdate();
{
auto action3 = finally([this]{
mEditorList->endUpdate();
});
mProject.reset();
if (!mQuitting && refreshEditor) {
//reset Class browsing
ui->tabInfos->setCurrentWidget(ui->tabStructure);
Editor * e = mEditorList->getEditor();
updateClassBrowserForEditor(e);
} else {
mClassBrowserModel.setParser(nullptr);
mClassBrowserModel.setCurrentFile("");
}
}
}
if (!mQuitting) {
// Clear error browser
ui->tableIssues->clearIssues();
updateProjectView();
2021-09-11 18:42:49 +08:00
}
}
}
void MainWindow::updateProjectView()
{
if (mProject) {
ui->projectView->setModel(mProject->model());
2021-09-17 13:35:50 +08:00
ui->projectView->expandAll();
openCloseLeftPanel(true);
ui->tabProject->setVisible(true);
ui->tabInfos->setCurrentWidget(ui->tabProject);
} else {
// Clear project browser
ui->projectView->setModel(nullptr);
ui->tabProject->setVisible(false);
}
updateProjectActions();
}
void MainWindow::onFileChanged(const QString &path)
{
Editor *e = mEditorList->getOpenedEditorByFilename(path);
if (e) {
2021-09-07 10:28:40 +08:00
if (fileExists(path)) {
e->activate();
if (QMessageBox::question(this,tr("Compile"),
tr("File '%1' was changed.").arg(path)+"<BR /><BR />" + tr("Reload its content from disk?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes) {
try {
e->loadFile();
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
}
} else {
if (QMessageBox::question(this,tr("Compile"),
tr("File '%1' was removed.").arg(path)+"<BR /><BR />" + tr("Keep it open?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::Yes) == QMessageBox::No) {
mEditorList->closeEditor(e);
} else {
e->setModified(true);
e->updateCaption();
}
}
}
}
const std::shared_ptr<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const
{
return mHeaderCompletionPopup;
}
const std::shared_ptr<CodeCompletionPopup> &MainWindow::completionPopup() const
{
return mCompletionPopup;
2021-07-23 13:22:05 +08:00
}
2021-08-03 23:55:57 +08:00
SearchDialog *MainWindow::searchDialog() const
{
return mSearchDialog;
}
2021-08-05 12:31:53 +08:00
SearchResultModel *MainWindow::searchResultModel()
{
return &mSearchResultModel;
}
2021-08-03 23:55:57 +08:00
EditorList *MainWindow::editorList() const
{
return mEditorList;
}
2021-08-01 09:13:38 +08:00
Debugger *MainWindow::debugger() const
{
return mDebugger;
}
2021-07-26 18:22:09 +08:00
CPUDialog *MainWindow::cpuDialog() const
2021-07-26 11:47:54 +08:00
{
return mCPUDialog;
}
2021-04-07 21:13:15 +08:00
void MainWindow::on_actionNew_triggered()
{
2021-06-20 09:27:37 +08:00
try {
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
editor->activate();
updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
2021-04-07 21:13:15 +08:00
}
2021-04-07 22:44:08 +08:00
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
{
Editor* editor = mEditorList->getEditor(index,ui->EditorTabsLeft);
mEditorList->closeEditor(editor);
}
void MainWindow::on_actionOpen_triggered()
{
2021-06-20 09:27:37 +08:00
try {
QString selectedFileFilter;
2021-09-11 18:42:49 +08:00
selectedFileFilter = pSystemConsts->defaultAllFileFilter();
2021-06-20 09:27:37 +08:00
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
&selectedFileFilter);
openFiles(files);
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
2021-04-07 22:44:08 +08:00
}
2021-04-09 17:48:25 +08:00
void MainWindow::closeEvent(QCloseEvent *event) {
Settings::UI& settings = pSettings->ui();
settings.setMainWindowState(saveState());
settings.setMainWindowGeometry(saveGeometry());
settings.setBottomPanelHeight(mBottomPanelHeight);
settings.setBottomPanelIndex(ui->tabMessages->currentIndex());
settings.setBottomPanelOpenned(mBottomPanelOpenned);
settings.setLeftPanelWidth(mLeftPanelWidth);
settings.setLeftPanelIndex(ui->tabInfos->currentIndex());
settings.setLeftPanelOpenned(mLeftPanelOpenned);
settings.save();
2021-06-10 09:34:59 +08:00
if (!mEditorList->closeAll(false)) {
2021-04-09 17:48:25 +08:00
event->ignore();
return ;
}
delete mEditorList;
event->accept();
return;
}
void MainWindow::showEvent(QShowEvent *event)
{
const Settings::UI& settings = pSettings->ui();
ui->tabMessages->setCurrentIndex(settings.bottomPanelIndex());
if (settings.bottomPanelOpenned()) {
mBottomPanelHeight = settings.bottomPanelHeight();
openCloseBottomPanel(true);
} else {
openCloseBottomPanel(false);
mBottomPanelHeight = settings.bottomPanelHeight();
}
ui->tabInfos->setCurrentIndex(settings.leftPanelIndex());
if (settings.leftPanelOpenned()) {
mLeftPanelWidth = settings.leftPanelWidth();
openCloseLeftPanel(true);
} else {
openCloseLeftPanel(false);
mLeftPanelWidth = settings.leftPanelWidth();
}
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls()){
event->acceptProposedAction();
}
}
void MainWindow::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls()) {
foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile())
continue;
2021-09-12 22:45:00 +08:00
QString file = url.toLocalFile();
if (getFileType(file)==FileType::Project) {
openProject(file);
return;
}
}
foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile())
continue;
QString file = url.toLocalFile();
openFile(file);
}
}
}
void MainWindow::on_actionSave_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
2021-06-20 09:27:37 +08:00
try {
editor->save();
2021-09-12 22:45:00 +08:00
if (editor->inProject() && (mProject))
mProject->saveAll();
2021-06-20 09:27:37 +08:00
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
}
}
void MainWindow::on_actionSaveAs_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
2021-06-20 09:27:37 +08:00
try {
editor->saveAs();
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
}
}
2021-04-16 22:04:48 +08:00
void MainWindow::on_actionOptions_triggered()
{
2021-09-11 18:42:49 +08:00
bool oldCodeCompletion = pSettings->codeCompletion().enabled();
PSettingsDialog settingsDialog = SettingsDialog::optionDialog();
settingsDialog->exec();
2021-09-11 18:42:49 +08:00
bool newCodeCompletion = pSettings->codeCompletion().enabled();
if (!oldCodeCompletion && newCodeCompletion) {
Editor *e = mEditorList->getEditor();
if (mProject && !e) {
scanActiveProject(true);
} else if (mProject && e && e->inProject()) {
scanActiveProject(true);
} else if (e) {
e->reparse();
}
}
2021-04-16 22:04:48 +08:00
}
2021-04-18 11:41:41 +08:00
void MainWindow::onCompilerSetChanged(int index)
{
if (index<0)
return;
pSettings->compilerSets().setDefaultIndex(index);
pSettings->compilerSets().saveDefaultIndex();
}
2021-04-20 22:24:33 +08:00
void MainWindow::onCompileLog(const QString &msg)
{
ui->txtCompilerOutput->appendPlainText(msg);
2021-09-17 19:58:37 +08:00
ui->txtCompilerOutput->ensureCursorVisible();
2021-04-20 22:24:33 +08:00
}
2021-04-24 15:57:45 +08:00
void MainWindow::onCompileIssue(PCompileIssue issue)
2021-04-20 22:24:33 +08:00
{
2021-04-24 15:57:45 +08:00
ui->tableIssues->addIssue(issue);
2021-06-23 22:38:02 +08:00
// Update tab caption
// if CompilerOutput.Items.Count = 1 then
// CompSheet.Caption := Lang[ID_SHEET_COMP] + ' (' + IntToStr(CompilerOutput.Items.Count) + ')';
if (issue->type == CompileIssueType::Error || issue->type ==
CompileIssueType::Warning) {
Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename);
if (e!=nullptr && (issue->line>0)) {
int line = issue->line;
if (line > e->lines()->count())
return;
int col = std::min(issue->column,e->lines()->getString(line-1).length()+1);
if (col < 1)
col = e->lines()->getString(line-1).length()+1;
e->addSyntaxIssues(line,col,issue->endColumn,issue->type,issue->description);
2021-06-23 22:38:02 +08:00
}
}
}
void MainWindow::onCompileFinished()
{
// Update tab caption
int i = ui->tabMessages->indexOf(ui->tabIssues);
if (i==-1)
return;
ui->tabMessages->setTabText(i, tr("Issues") +
QString(" (%1)").arg(ui->tableIssues->model()->rowCount()));
// Close it if there's nothing to show
if (mCheckSyntaxInBack) {
// check syntax in back, don't change message panel
} else if (
(ui->tableIssues->count() == 0)
// and (ResourceOutput.Items.Count = 0)
// and devData.AutoCloseProgress
) {
openCloseBottomPanel(false);
2021-06-23 22:38:02 +08:00
// Or open it if there is anything to show
} else {
if (ui->tableIssues->count() > 0) {
if (ui->tabMessages->currentIndex() != i) {
ui->tabMessages->setCurrentIndex(i);
}
// end else if (ResourceOutput.Items.Count > 0) then begin
// if MessageControl.ActivePage <> ResSheet then begin
// MessageControl.ActivePage := ResSheet;
// fMessageControlChanged := False;
// end;
// end;
openCloseBottomPanel(true);
2021-06-23 22:38:02 +08:00
}
}
Editor * e = mEditorList->getEditor();
if (e!=nullptr) {
2021-06-24 20:43:09 +08:00
e->invalidate();
2021-06-23 22:38:02 +08:00
}
// Jump to problem location, sorted by significance
if ((mCompilerManager->compileErrorCount() > 0) && (!mCheckSyntaxInBack)) {
// First try to find errors
for (int i=0;i<ui->tableIssues->count();i++) {
PCompileIssue issue = ui->tableIssues->issue(i);
if (issue->type == CompileIssueType::Error) {
if (e && e->filename() != issue->filename)
continue;
2021-06-23 22:38:02 +08:00
ui->tableIssues->selectRow(i);
QModelIndex index =ui->tableIssues->model()->index(i,0);
emit ui->tableIssues->doubleClicked(index);
break;
2021-06-23 22:38:02 +08:00
}
}
// Then try to find warnings
for (int i=0;i<ui->tableIssues->count();i++) {
PCompileIssue issue = ui->tableIssues->issue(i);
if (issue->type == CompileIssueType::Warning) {
if (e && e->filename() != issue->filename)
continue;
2021-06-23 22:38:02 +08:00
ui->tableIssues->selectRow(i);
QModelIndex index =ui->tableIssues->model()->index(i,0);
emit ui->tableIssues->doubleClicked(index);
2021-06-23 22:38:02 +08:00
}
}
// Then try to find anything with a line number...
// for I := 0 to CompilerOutput.Items.Count - 1 do begin
// if not SameStr(CompilerOutput.Items[I].Caption, '') then begin
// CompilerOutput.Selected := CompilerOutput.Items[I];
// CompilerOutput.Selected.MakeVisible(False);
// CompilerOutputDblClick(CompilerOutput);
// Exit;
// end;
// end;
// Then try to find a resource error
// if ResourceOutput.Items.Count > 0 then begin
// ResourceOutput.Selected := ResourceOutput.Items[0];
// ResourceOutput.Selected.MakeVisible(False);
// CompilerOutputDblClick(ResourceOutput);
// end;
2021-06-25 12:40:11 +08:00
} else {
if (mCompileSuccessionTask) {
switch (mCompileSuccessionTask->type) {
case MainWindow::CompileSuccessionTaskType::Run:
runExecutable(mCompileSuccessionTask->filename);
2021-07-23 13:22:05 +08:00
break;
case MainWindow::CompileSuccessionTaskType::Debug:
debug();
break;
2021-06-25 12:40:11 +08:00
}
2021-07-23 13:22:05 +08:00
mCompileSuccessionTask.reset();
2021-06-25 12:40:11 +08:00
}
2021-06-23 22:38:02 +08:00
}
mCheckSyntaxInBack=false;
2021-07-01 19:44:38 +08:00
updateCompileActions();
2021-07-26 22:29:47 +08:00
updateAppTitle();
2021-04-20 22:24:33 +08:00
}
void MainWindow::onCompileErrorOccured(const QString &reason)
{
QMessageBox::critical(this,tr("Compile Failed"),reason);
}
2021-06-25 12:40:11 +08:00
void MainWindow::onRunErrorOccured(const QString &reason)
{
QMessageBox::critical(this,tr("Run Failed"),reason);
}
void MainWindow::onRunFinished()
{
2021-07-01 19:44:38 +08:00
updateCompileActions();
if (pSettings->executor().minimizeOnRun()) {
showNormal();
}
2021-07-26 22:29:47 +08:00
updateAppTitle();
2021-06-25 12:40:11 +08:00
}
2021-08-01 23:24:37 +08:00
void MainWindow::cleanUpCPUDialog()
{
CPUDialog* ptr=mCPUDialog;
mCPUDialog=nullptr;
ptr->deleteLater();
}
void MainWindow::onDebugCommandInput(const QString &command)
{
if (mDebugger->executing()) {
mDebugger->sendCommand(command,"");
}
}
2021-04-20 22:24:33 +08:00
void MainWindow::on_actionCompile_triggered()
{
2021-06-25 12:40:11 +08:00
mCompileSuccessionTask.reset();
compile();
2021-04-20 22:24:33 +08:00
}
void MainWindow::on_actionRun_triggered()
{
2021-06-25 12:40:11 +08:00
runExecutable();
}
void MainWindow::on_actionUndo_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->undo();
}
}
void MainWindow::on_actionRedo_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->redo();
}
}
void MainWindow::on_actionCut_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->cutToClipboard();
}
}
void MainWindow::on_actionSelectAll_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->selectAll();
}
}
void MainWindow::on_actionCopy_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->copyToClipboard();
}
}
void MainWindow::on_actionPaste_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->pasteFromClipboard();
}
}
void MainWindow::on_actionIndent_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->tab();
}
}
void MainWindow::on_actionUnIndent_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-06-07 11:02:03 +08:00
editor->untab();
}
}
2021-04-24 15:57:45 +08:00
void MainWindow::on_actionToggleComment_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
editor->toggleComment();
2021-04-24 15:57:45 +08:00
}
}
void MainWindow::on_actionUnfoldAll_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-05-24 00:41:00 +08:00
//editor->clearFolds();
2021-04-24 15:57:45 +08:00
}
}
void MainWindow::on_actionFoldAll_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
2021-05-24 00:41:00 +08:00
//editor->clearFolds();
//editor->foldAll();
2021-04-24 15:57:45 +08:00
}
}
2021-04-29 20:54:44 +08:00
void MainWindow::on_tableIssues_doubleClicked(const QModelIndex &index)
{
PCompileIssue issue = ui->tableIssues->issue(index);
if (!issue)
return;
Editor * editor = mEditorList->getEditorByFilename(issue->filename);
if (editor == nullptr)
return;
editor->setCaretPositionAndActivate(issue->line,issue->column);
2021-04-29 20:54:44 +08:00
}
void MainWindow::on_actionEncode_in_ANSI_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
2021-06-20 09:27:37 +08:00
try {
editor->setEncodingOption(ENCODING_SYSTEM_DEFAULT);
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
}
void MainWindow::on_actionEncode_in_UTF_8_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
2021-06-20 09:27:37 +08:00
try {
editor->setEncodingOption(ENCODING_UTF8);
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
2021-06-20 09:27:37 +08:00
}
}
void MainWindow::on_actionAuto_Detect_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
editor->setEncodingOption(ENCODING_AUTO_DETECT);
}
void MainWindow::on_actionConvert_to_ANSI_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
if (QMessageBox::warning(this,tr("Confirm Convertion"),
tr("The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue?")
.arg(QString(QTextCodec::codecForLocale()->name())),
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes)
return;
editor->convertToEncoding(ENCODING_SYSTEM_DEFAULT);
}
void MainWindow::on_actionConvert_to_UTF_8_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
if (QMessageBox::warning(this,tr("Confirm Convertion"),
tr("The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue?")
.arg(ENCODING_UTF8),
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes)
return;
editor->convertToEncoding(ENCODING_UTF8);
}
2021-06-23 22:38:02 +08:00
void MainWindow::on_tabMessages_tabBarClicked(int index)
{
if (index == ui->tabMessages->currentIndex()) {
openCloseBottomPanel(!mBottomPanelOpenned);
}
}
void MainWindow::on_tabMessages_currentChanged(int index)
{
openCloseBottomPanel(true);
2021-06-23 22:38:02 +08:00
}
void MainWindow::on_tabMessages_tabBarDoubleClicked(int index)
{
}
2021-06-25 12:40:11 +08:00
void MainWindow::on_actionCompile_Run_triggered()
{
mCompileSuccessionTask = std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Run;
compile();
}
void MainWindow::on_actionRebuild_triggered()
{
mCompileSuccessionTask.reset();
compile(true);
}
void MainWindow::on_actionStop_Execution_triggered()
{
mCompilerManager->stopRun();
2021-08-01 12:02:28 +08:00
mDebugger->stop();
2021-06-25 12:40:11 +08:00
}
2021-07-20 15:16:52 +08:00
void MainWindow::on_actionDebug_triggered()
{
2021-07-23 13:22:05 +08:00
debug();
2021-07-20 15:16:52 +08:00
}
CompileTarget MainWindow::getCompileTarget()
{
// Check if the current file belongs to a project
CompileTarget target = CompileTarget::None;
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
// Treat makefiles as InProject files too
2021-09-12 22:45:00 +08:00
if (mProject
&& (e->inProject() || (mProject->makeFileName() == e->filename()))
) {
target = CompileTarget::Project;
} else {
target = CompileTarget::File;
}
// No editors have been opened. Check if a project is open
} else if (mProject) {
target = CompileTarget::Project;
2021-07-20 15:16:52 +08:00
}
return target;
}
2021-07-25 13:03:46 +08:00
bool MainWindow::debugInferiorhasBreakpoint()
{
Editor * e = mEditorList->getEditor();
if (e==nullptr)
return false;
if (!e->inProject()) {
for (const PBreakpoint& breakpoint:mDebugger->breakpointModel()->breakpoints()) {
2021-07-25 13:03:46 +08:00
if (e->filename() == breakpoint->filename) {
return true;
}
}
} else {
for (const PBreakpoint& breakpoint:mDebugger->breakpointModel()->breakpoints()) {
2021-07-25 13:03:46 +08:00
Editor* e1 = mEditorList->getOpenedEditorByFilename(breakpoint->filename);
if (e1->inProject()) {
return true;
}
}
}
return false;
}
2021-07-31 14:04:43 +08:00
void MainWindow::on_actionStep_Over_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("next", "");
mDebugger->updateDebugInfo();
2021-08-01 12:02:28 +08:00
mDebugger->refreshWatchVars();
2021-07-31 14:04:43 +08:00
}
}
void MainWindow::on_actionStep_Into_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("step", "");
mDebugger->updateDebugInfo();
2021-08-01 12:02:28 +08:00
mDebugger->refreshWatchVars();
2021-07-31 14:04:43 +08:00
}
}
void MainWindow::on_actionStep_Out_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("finish", "");
mDebugger->updateDebugInfo();
2021-08-01 12:02:28 +08:00
mDebugger->refreshWatchVars();
2021-07-31 14:04:43 +08:00
}
}
void MainWindow::on_actionRun_To_Cursor_triggered()
{
if (mDebugger->executing()) {
Editor *e=mEditorList->getEditor();
if (e!=nullptr) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("tbreak", QString(" %1").arg(e->caretY()));
mDebugger->sendCommand("continue", "");
mDebugger->updateDebugInfo();
2021-08-01 12:02:28 +08:00
mDebugger->refreshWatchVars();
2021-07-31 14:04:43 +08:00
}
}
}
void MainWindow::on_actionContinue_triggered()
{
if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars();
mDebugger->sendCommand("continue", "");
mDebugger->updateDebugInfo();
2021-08-01 12:02:28 +08:00
mDebugger->refreshWatchVars();
2021-07-31 14:04:43 +08:00
}
}
2021-08-01 01:06:43 +08:00
void MainWindow::on_actionAdd_Watch_triggered()
{
QString s = "";
Editor *e = mEditorList->getEditor();
if (e==nullptr)
return;
if (e->selAvail()) {
s = e->selText();
} else {
s = e->WordAtCursor();
}
bool isOk;
s=QInputDialog::getText(this,
tr("New Watch Expression"),
tr("Enter Watch Expression (it is recommended to use 'this->' for class members):"),
QLineEdit::Normal,
s,&isOk);
if (!isOk)
return;
s = s.trimmed();
if (!s.isEmpty()) {
mDebugger->addWatchVar(s);
}
}
2021-08-01 23:24:37 +08:00
void MainWindow::on_actionView_CPU_Window_triggered()
{
if (mCPUDialog==nullptr) {
mCPUDialog = new CPUDialog(this);
connect(mCPUDialog, &CPUDialog::closed, this, &MainWindow::cleanUpCPUDialog);
}
mCPUDialog->show();
}
2021-08-02 21:58:39 +08:00
void MainWindow::on_actionExit_triggered()
2021-08-01 23:24:37 +08:00
{
2021-08-02 21:58:39 +08:00
close();
2021-08-01 23:24:37 +08:00
}
2021-08-02 10:08:25 +08:00
2021-08-02 22:21:50 +08:00
void MainWindow::onDebugEvaluateInput()
2021-08-02 10:08:25 +08:00
{
2021-08-02 22:21:50 +08:00
QString s=ui->cbEvaluate->currentText().trimmed();
2021-08-02 21:58:39 +08:00
if (!s.isEmpty()) {
2021-08-29 22:08:43 +08:00
connect(mDebugger, &Debugger::evalValueReady,
this, &MainWindow::onEvalValueReady);
2021-08-02 21:58:39 +08:00
mDebugger->sendCommand("print",s,false);
}
2021-08-02 10:08:25 +08:00
}
2021-08-03 23:55:57 +08:00
2021-08-27 16:38:55 +08:00
void MainWindow::onParserProgress(const QString &fileName, int total, int current)
{
// Mention every 5% progress
int showStep = total / 20;
// For Total = 1, avoid division by zero
if (showStep == 0)
showStep = 1;
// Only show if needed (it's a very slow operation)
if (current ==1 || current % showStep==0) {
2021-08-30 22:05:45 +08:00
updateStatusbarMessage(tr("Parsing file %1 of %2: \"%3\"")
2021-08-27 16:38:55 +08:00
.arg(current).arg(total).arg(fileName));
}
}
void MainWindow::onStartParsing()
{
mParserTimer.restart();
}
void MainWindow::onEndParsing(int total, int)
{
2021-08-29 00:48:23 +08:00
double parseTime = mParserTimer.elapsed() / 1000.0;
2021-08-27 16:38:55 +08:00
double parsingFrequency;
if (total > 1) {
if (parseTime>0) {
parsingFrequency = total / parseTime;
} else {
parsingFrequency = 999;
}
2021-08-30 22:05:45 +08:00
updateStatusbarMessage(tr("Done parsing %1 files in %2 seconds")
2021-08-27 16:38:55 +08:00
.arg(total).arg(parseTime)
+ " "
+ tr("(%1 files per second)")
.arg(parsingFrequency));
} else {
2021-08-30 22:05:45 +08:00
updateStatusbarMessage(tr("Done parsing %1 files in %2 seconds")
2021-08-27 16:38:55 +08:00
.arg(total).arg(parseTime));
}
}
2021-08-29 22:08:43 +08:00
void MainWindow::onEvalValueReady(const QString &value)
{
updateDebugEval(value);
disconnect(mDebugger, &Debugger::evalValueReady,
this, &MainWindow::onEvalValueReady);
}
2021-08-03 23:55:57 +08:00
void MainWindow::on_actionFind_triggered()
{
Editor *e = mEditorList->getEditor();
if (!e)
return;
if (mSearchDialog==nullptr) {
mSearchDialog = new SearchDialog(this);
}
QString s = e->WordAtCursor();
mSearchDialog->find(s);
}
void MainWindow::on_actionFind_in_files_triggered()
{
2021-08-05 19:58:32 +08:00
if (mSearchDialog==nullptr) {
mSearchDialog = new SearchDialog(this);
}
Editor *e = mEditorList->getEditor();
if (e) {
QString s = e->WordAtCursor();
mSearchDialog->findInFiles(s);
} else {
mSearchDialog->findInFiles("");
}
2021-08-03 23:55:57 +08:00
}
void MainWindow::on_actionReplace_triggered()
{
2021-08-05 19:58:32 +08:00
Editor *e = mEditorList->getEditor();
if (!e)
return;
if (mSearchDialog==nullptr) {
mSearchDialog = new SearchDialog(this);
}
QString s = e->WordAtCursor();
mSearchDialog->replace(s,s);
2021-08-03 23:55:57 +08:00
}
void MainWindow::on_actionFind_Next_triggered()
{
Editor *e = mEditorList->getEditor();
if (e==nullptr)
return;
if (mSearchDialog==nullptr)
return;
2021-08-03 23:55:57 +08:00
mSearchDialog->findNext();
2021-08-03 23:55:57 +08:00
}
void MainWindow::on_actionFind_Previous_triggered()
{
Editor *e = mEditorList->getEditor();
if (e==nullptr)
return;
if (mSearchDialog==nullptr)
return;
2021-08-03 23:55:57 +08:00
mSearchDialog->findPrevious();
2021-08-03 23:55:57 +08:00
}
2021-08-05 19:58:32 +08:00
void MainWindow::on_cbSearchHistory_currentIndexChanged(int index)
{
mSearchResultModel.setCurrentIndex(index);
PSearchResults results = mSearchResultModel.results(index);
if (results && results->searchType == SearchType::Search) {
ui->btnSearchAgin->setEnabled(true);
} else {
ui->btnSearchAgin->setEnabled(false);
}
2021-08-05 19:58:32 +08:00
}
void MainWindow::on_btnSearchAgin_clicked()
{
if (mSearchDialog==nullptr) {
mSearchDialog = new SearchDialog(this);
}
PSearchResults results=mSearchResultModel.currentResults();
if (results){
mSearchDialog->findInFiles(results->keyword,
results->scope,
results->options);
}
}
void MainWindow::on_actionRemove_Watch_triggered()
{
QModelIndex index =ui->watchView->currentIndex();
QModelIndex parent;
while (true) {
parent = ui->watchView->model()->parent(index);
if (parent.isValid()) {
index=parent;
} else {
break;
}
}
mDebugger->removeWatchVar(index);
}
void MainWindow::on_actionRemove_All_Watches_triggered()
{
mDebugger->removeWatchVars(true);
}
void MainWindow::on_actionModify_Watch_triggered()
{
}
2021-09-02 12:14:02 +08:00
void MainWindow::on_actionReformat_Code_triggered()
{
Editor* e = mEditorList->getEditor();
if (e) {
e->reformat();
e->activate();
}
}
CaretList &MainWindow::caretList()
{
return mCaretList;
}
void MainWindow::updateCaretActions()
{
ui->actionBack->setEnabled(mCaretList.hasPrevious());
ui->actionForward->setEnabled(mCaretList.hasNext());
}
void MainWindow::on_actionBack_triggered()
{
PEditorCaret caret = mCaretList.gotoAndGetPrevious();
mCaretList.pause();
if (caret) {
caret->editor->setCaretPositionAndActivate(caret->line,caret->aChar);
}
mCaretList.unPause();
updateCaretActions();
}
void MainWindow::on_actionForward_triggered()
{
PEditorCaret caret = mCaretList.gotoAndGetNext();
mCaretList.pause();
if (caret) {
caret->editor->setCaretPositionAndActivate(caret->line,caret->aChar);
}
mCaretList.unPause();
updateCaretActions();
}
void MainWindow::on_tabInfos_tabBarClicked(int index)
{
if (index == ui->tabInfos->currentIndex()) {
openCloseLeftPanel(!mLeftPanelOpenned);
}
}
void MainWindow::on_splitterInfos_splitterMoved(int, int)
{
QList<int> sizes = ui->splitterInfos->sizes();
mLeftPanelWidth = sizes[0];
}
void MainWindow::on_splitterMessages_splitterMoved(int, int)
{
QList<int> sizes = ui->splitterMessages->sizes();
mBottomPanelHeight = sizes[1];
}
void MainWindow::on_EditorTabsLeft_tabBarDoubleClicked(int index)
{
maximizeEditor();
}
void MainWindow::on_actionClose_triggered()
{
mClosing = true;
Editor* e = mEditorList->getEditor();
if (e) {
mEditorList->closeEditor(e);
}
mClosing = false;
}
void MainWindow::on_actionClose_All_triggered()
{
mClosing = true;
mEditorList->closeAll(mSystemTurnedOff);
mClosing = false;
}
void MainWindow::on_actionMaximize_Editor_triggered()
{
maximizeEditor();
}
void MainWindow::on_actionNext_Editor_triggered()
{
mEditorList->selectNextPage();
}
void MainWindow::on_actionPrevious_Editor_triggered()
{
mEditorList->selectPreviousPage();
}
void MainWindow::on_actionToggle_Breakpoint_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mEditorContextMenuPos,line))
editor->toggleBreakpoint(line);
}
void MainWindow::on_actionClear_all_breakpoints_triggered()
{
Editor *e=mEditorList->getEditor();
if (!e)
return;
if (QMessageBox::question(this,
tr("Clear all breakpoints"),
tr("Do you really want to clear all breakpoints in this file?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes) {
e->clearBreakpoints();
}
}
void MainWindow::on_actionBreakpoint_property_triggered()
{
Editor * editor = mEditorList->getEditor();
int line;
if (editor && editor->PointToLine(mEditorContextMenuPos,line)) {
if (editor->hasBreakpoint(line))
editor->modifyBreakpointProperty(line);
}
}
2021-09-03 11:50:04 +08:00
void MainWindow::on_actionGoto_Declaration_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
2021-09-03 11:50:04 +08:00
editor->gotoDeclaration(pos);
}
}
void MainWindow::on_actionGoto_Definition_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
2021-09-03 11:50:04 +08:00
editor->gotoDefinition(pos);
}
}
void MainWindow::on_actionFind_references_triggered()
{
Editor * editor = mEditorList->getEditor();
BufferCoord pos;
if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) {
CppRefacter refactor;
refactor.findOccurence(editor,pos);
ui->tabMessages->setCurrentWidget(ui->tabSearch);
openCloseBottomPanel(true);
}
}
void MainWindow::on_actionOpen_Containing_Folder_triggered()
{
Editor* editor = mEditorList->getEditor();
if (editor) {
QFileInfo info(editor->filename());
if (!info.path().isEmpty()) {
QDesktopServices::openUrl(info.path());
}
}
}
void MainWindow::on_actionOpen_Terminal_triggered()
{
Editor* editor = mEditorList->getEditor();
if (editor) {
QFileInfo info(editor->filename());
if (!info.path().isEmpty()) {
openShell(info.path(),"cmd.exe");
}
}
}
void MainWindow::on_actionFile_Properties_triggered()
{
Editor* editor = mEditorList->getEditor();
if (editor) {
FilePropertiesDialog dialog(editor,this);
dialog.exec();
dialog.setParent(nullptr);
}
}
void MainWindow::on_searchView_doubleClicked(const QModelIndex &index)
{
QString filename;
int line;
int start;
if (mSearchResultTreeModel->getItemFileAndLineChar(
index,filename,line,start)) {
Editor *e = mEditorList->getEditorByFilename(filename);
if (e) {
e->setCaretPositionAndActivate(line,start);
}
}
}
void MainWindow::on_tblStackTrace_doubleClicked(const QModelIndex &index)
{
PTrace trace = mDebugger->backtraceModel()->backtrace(index.row());
if (trace) {
Editor *e = mEditorList->getEditorByFilename(trace->filename);
if (e) {
e->setCaretPositionAndActivate(trace->line,1);
}
}
}
void MainWindow::on_tblBreakpoints_doubleClicked(const QModelIndex &index)
{
PBreakpoint breakpoint = mDebugger->breakpointModel()->breakpoint(index.row());
if (breakpoint) {
Editor * e = mEditorList->getEditorByFilename(breakpoint->filename);
if (e) {
e->setCaretPositionAndActivate(breakpoint->line,1);
}
}
}
2021-09-11 18:42:49 +08:00
std::shared_ptr<Project> MainWindow::project()
{
return mProject;
}
2021-09-12 00:17:15 +08:00
void MainWindow::on_projectView_doubleClicked(const QModelIndex &index)
{
if (!index.isValid())
return;
FolderNode * node = static_cast<FolderNode*>(index.internalPointer());
if (!node)
return;
if (node->unitIndex>=0) {
mProject->openUnit(node->unitIndex);
}
}
2021-09-12 01:01:34 +08:00
void MainWindow::on_actionClose_Project_triggered()
{
mClosing = true;
closeProject(true);
mClosing = false;
}
2021-09-14 17:33:47 +08:00
void MainWindow::on_actionProject_options_triggered()
{
if (!mProject)
return;
QString oldName = mProject->name();
PSettingsDialog dialog = SettingsDialog::projectOptionDialog();
dialog->exec();
}
2021-09-16 23:51:05 +08:00
void MainWindow::on_actionNew_Project_triggered()
{
NewProjectDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
// Take care of the currently opened project
QString s;
if (mProject) {
if (mProject->name().isEmpty())
s = mProject->filename();
else
s = mProject->name();
// Ask if the user wants to close the current one. If not, abort
if (QMessageBox::question(this,
tr("New project"),
tr("Close %1 and start new project?").arg(s),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes)==QMessageBox::Yes) {
closeProject(false);
} else
return;
}
//Create the project folder
QDir dir(dialog.getLocation());
if (!dir.exists()) {
if (QMessageBox::question(this,
tr("Folder not exist"),
tr("Folder '%1' doesn't exist. Create it now?").arg(dialog.getLocation()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes) != QMessageBox::Yes) {
return;
}
if (!dir.mkpath(dialog.getLocation())) {
QMessageBox::critical(this,
tr("Can't create folder"),
tr("Failed to create folder '%1'.").arg(dialog.getLocation()),
QMessageBox::Yes);
return;
}
}
// if cbDefault.Checked then
// devData.DefCpp := rbCpp.Checked;
s = includeTrailingPathDelimiter(dialog.getLocation())
+ dialog.getProjectName() + "." + DEV_PROJECT_EXT;
if (fileExists(s)) {
QString saveName = QFileDialog::getSaveFileName(
this,
tr("Save new project as"),
dialog.getLocation(),
tr("Red panda Dev-C++ project file (*.dev)"));
if (!saveName.isEmpty()) {
s = saveName;
}
}
// Create an empty project
mProject = std::make_shared<Project>(s,dialog.getProjectName());
if (!mProject->assignTemplate(dialog.getTemplate())) {
mProject = nullptr;
QMessageBox::critical(this,
tr("New project fail"),
tr("Can't assign project template"),
QMessageBox::Ok);
}
mProject->saveAll();
updateProjectView();
2021-09-16 23:51:05 +08:00
}
}
void MainWindow::on_actionSaveAll_triggered()
{
2021-09-17 13:35:50 +08:00
// Pause the change notifier
bool oldBlock = mFileSystemWatcher.blockSignals(true);
auto action = finally([oldBlock,this] {
mFileSystemWatcher.blockSignals(oldBlock);
});
if (mProject) {
mProject->saveAll();
}
// Make changes to files
for (int i=0;i<mEditorList->pageCount();i++) {
Editor * e= (*mEditorList)[i];
if (e->modified() && !e->inProject()) {
if (!e->save())
break;
}
}
updateAppTitle();
}
2021-09-17 13:35:50 +08:00
void MainWindow::on_actionProject_New_File_triggered()
{
int idx = -1;
if (!mProject)
return;
QModelIndex current = ui->projectView->currentIndex();
FolderNode * node = nullptr;
if (current.isValid()) {
node = static_cast<FolderNode*>(current.internalPointer());
}
PProjectUnit newUnit = mProject->newUnit(
mProject->pointerToNode(node) );
idx = mProject->units().count()-1;
updateProjectView();
Editor * editor = mProject->openUnit(idx);
editor->setModified(true);
editor->activate();
}
void MainWindow::on_actionAdd_to_project_triggered()
{
if (!mProject)
return;
QFileDialog dialog(this,tr("Add to project"),
mProject->directory(),
pSystemConsts->defaultFileFilters().join(";;"));
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setOption(QFileDialog::DontConfirmOverwrite,true);
if (dialog.exec()) {
QModelIndex current = ui->projectView->currentIndex();
FolderNode * node = nullptr;
if (current.isValid()) {
node = static_cast<FolderNode*>(current.internalPointer());
}
PFolderNode folderNode = mProject->pointerToNode(node);
foreach (const QString& filename, dialog.selectedFiles()) {
mProject->addUnit(filename,folderNode,false);
mProject->cppParser()->addFileToScan(filename);
}
mProject->rebuildNodes();
parseFileList(mProject->cppParser());
updateProjectView();
}
}
2021-09-17 17:15:35 +08:00
void MainWindow::on_actionRemove_from_project_triggered()
{
if (!mProject)
return;
if (!ui->projectView->selectionModel()->hasSelection())
return;
mProject->model()->beginUpdate();
QSet<int> selected;
foreach (const QModelIndex& index, ui->projectView->selectionModel()->selectedIndexes()){
if (!index.isValid())
continue;
FolderNode * node = static_cast<FolderNode*>(index.internalPointer());
PFolderNode folderNode = mProject->pointerToNode(node);
2021-09-17 19:58:37 +08:00
if (!folderNode)
2021-09-17 17:15:35 +08:00
continue;
selected.insert(folderNode->unitIndex);
};
for (int i=mProject->units().count()-1;i>=0;i--) {
if (selected.contains(i)) {
mProject->removeEditor(i,true);
}
}
mProject->model()->endUpdate();
updateProjectView();
}
2021-09-17 19:58:37 +08:00
void MainWindow::on_actionView_Makefile_triggered()
{
if (!mProject)
return;
prepareProjectForCompile();
2021-09-17 19:58:37 +08:00
mCompilerManager->buildProjectMakefile(mProject);
openFile(mProject->makeFileName());
}
2021-09-17 19:58:37 +08:00
void MainWindow::on_actionMakeClean_triggered()
{
if (!mProject)
return;
prepareProjectForCompile();
mCompilerManager->cleanProject(mProject);
2021-09-17 19:58:37 +08:00
}