2021-12-26 23:18:28 +08:00
/*
* Copyright ( C ) 2020 - 2022 Roy Qu ( royqh1979 @ gmail . com )
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
*/
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"
2021-04-08 10:29:21 +08:00
# include "editor.h"
2021-04-11 21:33:08 +08:00
# include "systemconsts.h"
# include "settings.h"
2023-01-11 16:22:26 +08:00
# include "qsynedit/constants.h"
2024-03-08 10:06:18 +08:00
# include "debugger/debugger.h"
2024-02-28 19:41:05 +08:00
# include "utils/escape.h"
# include "utils/parsearg.h"
2021-08-01 23:24:37 +08:00
# include "widgets/cpudialog.h"
2021-09-04 00:13:42 +08:00
# include "widgets/filepropertiesdialog.h"
2024-02-23 10:10:58 +08:00
# include "widgets/filenameeditdelegate.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"
2022-09-26 14:54:28 +08:00
# include <qt_utils/charsetinfo.h>
2021-10-03 23:12:20 +08:00
# include "widgets/aboutdialog.h"
2021-10-08 00:06:41 +08:00
# include "shortcutmanager.h"
2021-10-10 21:23:25 +08:00
# include "colorscheme.h"
2021-10-18 22:06:33 +08:00
# include "thememanager.h"
# include "widgets/darkfusionstyle.h"
2021-12-21 11:57:23 +08:00
# include "widgets/lightfusionstyle.h"
2021-11-01 20:44:08 +08:00
# include "problems/problemcasevalidator.h"
2022-12-11 19:47:43 +08:00
# include "problems/freeprojectsetformat.h"
2021-11-04 09:07:06 +08:00
# include "widgets/ojproblempropertywidget.h"
2021-12-20 09:36:18 +08:00
# include "iconsmanager.h"
2022-01-27 18:34:18 +08:00
# include "widgets/newclassdialog.h"
2022-02-01 16:17:28 +08:00
# include "widgets/newheaderdialog.h"
2023-12-22 18:03:29 +08:00
# ifdef ENABLE_LUA_ADDON
# include "addon/executor.h"
# include "addon/runtime.h"
# endif
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
# include "vcs/gitmanager.h"
2022-02-15 17:22:44 +08:00
# include "vcs/gitrepository.h"
2022-02-19 20:38:08 +08:00
# include "vcs/gitbranchdialog.h"
2022-02-20 21:47:57 +08:00
# include "vcs/gitmergedialog.h"
2022-02-21 23:35:28 +08:00
# include "vcs/gitlogdialog.h"
2022-02-24 11:07:37 +08:00
# include "vcs/gitremotedialog.h"
2022-02-25 11:07:30 +08:00
# include "vcs/gituserconfigdialog.h"
2023-08-08 14:41:23 +08:00
# endif
2022-02-21 11:37:29 +08:00
# include "widgets/infomessagebox.h"
2022-08-07 21:41:57 +08:00
# include "widgets/newtemplatedialog.h"
2022-10-17 23:23:05 +08:00
# include "visithistorymanager.h"
# include "widgets/projectalreadyopendialog.h"
2022-11-11 21:20:57 +08:00
# include "widgets/searchdialog.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>
2021-09-03 16:39:20 +08:00
# include <QDesktopServices>
2021-09-05 21:17:33 +08:00
# include <QDragEnterEvent>
2021-04-11 21:33:08 +08:00
# include <QFileDialog>
2021-08-01 01:06:43 +08:00
# include <QInputDialog>
2021-11-02 09:29:35 +08:00
# include <QJsonArray>
# include <QJsonDocument>
# include <QJsonObject>
2021-04-08 10:29:21 +08:00
# include <QLabel>
2021-10-04 11:07:35 +08:00
# include <QLineEdit>
2021-06-25 12:40:11 +08:00
# include <QMessageBox>
2021-09-05 19:10:54 +08:00
# include <QMimeData>
2022-01-26 21:36:31 +08:00
# include <QScreen>
2023-07-03 14:06:26 +08:00
# include <QStyleFactory>
2021-11-02 09:29:35 +08:00
# include <QTcpSocket>
2021-12-09 11:22:28 +08:00
# include <QTemporaryFile>
2021-11-02 19:26:11 +08:00
# include <QTextBlock>
2021-06-20 09:27:37 +08:00
# include <QTranslator>
2022-02-11 20:19:48 +08:00
# include <QFileIconProvider>
2022-07-24 10:02:36 +08:00
# include <QMimeDatabase>
# include <QMimeType>
2022-12-17 17:20:33 +08:00
# include <QToolTip>
2023-03-14 17:49:36 +08:00
# include <QCompleter>
2022-12-17 17:20:33 +08:00
2022-04-02 18:22:29 +08:00
# include "mainwindow.h"
2022-03-29 18:06:24 +08:00
# include <QScrollBar>
2022-03-29 21:41:02 +08:00
# include <QTextDocumentFragment>
2021-04-08 10:29:21 +08:00
2021-04-20 22:24:33 +08:00
# include "settingsdialog/settingsdialog.h"
# include "compiler/compilermanager.h"
2021-06-12 22:36:23 +08:00
# include <QGuiApplication>
# include <QClipboard>
# include <QMessageBox>
# include <QTextCodec>
2021-09-03 16:39:20 +08:00
# include "cpprefacter.h"
2021-04-16 22:04:48 +08:00
2022-04-08 17:22:24 +08:00
# include "widgets/newprojectunitdialog.h"
2022-11-11 21:20:57 +08:00
# include "widgets/searchinfiledialog.h"
2021-08-03 23:55:57 +08:00
2021-12-24 23:18:20 +08:00
# ifdef Q_OS_WIN
# include <windows.h>
# endif
2024-02-22 10:30:41 +08:00
static const char * Translation [ ] =
{
QT_TRANSLATE_NOOP ( " QFileSystemModel " , " <b>The name \" %1 \" cannot be used.</b><p>Try using another name, with fewer characters or no punctuation marks. " )
} ;
2021-12-24 23:18:20 +08:00
2021-11-25 10:18:21 +08:00
static int findTabIndex ( QTabWidget * tabWidget , QWidget * w ) {
for ( int i = 0 ; i < tabWidget - > count ( ) ; i + + ) {
if ( w = = tabWidget - > widget ( i ) )
return i ;
2023-07-04 17:19:29 +08:00
}
2021-11-25 10:18:21 +08:00
return - 1 ;
}
2021-04-08 10:29:21 +08:00
MainWindow * pMainWindow ;
2021-04-06 23:10:57 +08:00
MainWindow : : MainWindow ( QWidget * parent )
2023-02-24 12:17:30 +08:00
: QMainWindow { parent } ,
ui { new Ui : : MainWindow } ,
mFullInitialized { false } ,
mSearchInFilesDialog { nullptr } ,
mSearchDialog { nullptr } ,
mQuitting { false } ,
2023-08-11 13:49:09 +08:00
mOpeningFiles { false } ,
mOpeningProject { false } ,
2023-02-24 12:17:30 +08:00
mClosingProject { false } ,
mCheckSyntaxInBack { false } ,
mShouldRemoveAllSettings { false } ,
mClosing { false } ,
mClosingAll { false } ,
mOpenningFiles { false } ,
mSystemTurnedOff { false } ,
mCompileIssuesState { CompileIssuesState : : None }
2021-04-06 23:10:57 +08:00
{
ui - > setupUi ( this ) ;
2023-08-19 18:01:16 +08:00
ui - > cbProblemCaseValidateType - > blockSignals ( true ) ;
ui - > cbProblemCaseValidateType - > addItem ( tr ( " Exact " ) ) ;
ui - > cbProblemCaseValidateType - > addItem ( tr ( " Ignore leading/trailing spaces " ) ) ;
ui - > cbProblemCaseValidateType - > addItem ( tr ( " Ignore spaces " ) ) ;
ui - > cbProblemCaseValidateType - > blockSignals ( false ) ;
2022-01-27 23:48:46 +08:00
addActions ( this - > findChildren < QAction * > ( QString ( ) , Qt : : FindChildrenRecursively ) ) ;
2022-12-17 17:20:33 +08:00
//custom actions
createCustomActions ( ) ;
2021-04-08 10:29:21 +08:00
// status bar
2022-10-10 18:05:18 +08:00
//statusBar takes the owner ships
2021-04-18 11:41:41 +08:00
mFileInfoStatus = new QLabel ( ) ;
2021-10-15 10:23:46 +08:00
mFileEncodingStatus = new LabelWithMenu ( ) ;
2021-06-12 22:36:23 +08:00
mFileModeStatus = new QLabel ( ) ;
2022-10-10 18:05:18 +08:00
2023-01-04 11:01:34 +08:00
mFileInfoStatus - > setStyleSheet ( " margin-left:5px; margin-right:5px " ) ;
mFileEncodingStatus - > setStyleSheet ( " margin-left:5px; margin-right:5px " ) ;
mFileModeStatus - > setStyleSheet ( " margin-left:5px; margin-right:5px " ) ;
2021-11-09 21:22:50 +08:00
prepareTabInfosData ( ) ;
prepareTabMessagesData ( ) ;
2021-08-27 23:51:42 +08:00
ui - > statusbar - > insertPermanentWidget ( 0 , mFileModeStatus ) ;
ui - > statusbar - > insertPermanentWidget ( 0 , mFileEncodingStatus ) ;
ui - > statusbar - > insertPermanentWidget ( 0 , mFileInfoStatus ) ;
2022-10-10 18:05:18 +08:00
//delete in the destructor
2021-04-07 21:13:15 +08:00
mEditorList = new EditorList ( ui - > EditorTabsLeft ,
ui - > EditorTabsRight ,
2021-06-24 16:05:19 +08:00
ui - > splitterEditorPanel ,
2021-04-07 21:13:15 +08:00
ui - > EditorPanel ) ;
2022-01-02 10:37:00 +08:00
connect ( mEditorList , & EditorList : : editorRenamed ,
this , & MainWindow : : onEditorRenamed ) ;
2021-11-02 23:47:51 +08:00
connect ( mEditorList , & EditorList : : editorClosed ,
this , & MainWindow : : onEditorClosed ) ;
2021-09-11 11:42:20 +08:00
mProject = nullptr ;
2022-10-10 18:05:18 +08:00
//delete in the destructor
mProjectProxyModel = new ProjectModelSortFilterProxy ( ) ;
QItemSelectionModel * m = ui - > projectView - > selectionModel ( ) ;
2022-01-08 08:52:50 +08:00
ui - > projectView - > setModel ( mProjectProxyModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2022-01-08 08:52:50 +08:00
mProjectProxyModel - > setDynamicSortFilter ( false ) ;
2021-04-07 22:44:08 +08:00
ui - > EditorTabsRight - > setVisible ( false ) ;
2021-04-18 11:41:41 +08:00
2022-10-17 23:23:05 +08:00
mVisitHistoryManager = std : : make_shared < VisitHistoryManager > (
includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_HISTORY_FILE ) ;
mVisitHistoryManager - > load ( ) ;
2022-10-10 18:05:18 +08:00
//toolbar takes the owner
2021-04-18 11:41:41 +08:00
mCompilerSet = new QComboBox ( ) ;
2021-06-24 20:43:09 +08:00
mCompilerSet - > setMinimumWidth ( 200 ) ;
2022-04-18 16:17:06 +08:00
mCompilerSet - > setSizeAdjustPolicy ( QComboBox : : AdjustToContents ) ;
2022-05-07 07:53:16 +08:00
ui - > toolbarCompilerSet - > insertWidget ( ui - > actionCompiler_Options , mCompilerSet ) ;
ui - > toolbarCompilerSet - > insertSeparator ( ui - > actionCompiler_Options ) ;
2021-04-18 11:41:41 +08:00
connect ( mCompilerSet , QOverload < int > : : of ( & QComboBox : : currentIndexChanged ) ,
this , & MainWindow : : onCompilerSetChanged ) ;
2021-11-12 02:20:13 +08:00
//updateCompilerSet();
2021-04-20 22:24:33 +08:00
2022-10-10 18:05:18 +08:00
mCompilerManager = std : : make_shared < CompilerManager > ( ) ;
mDebugger = std : : make_shared < Debugger > ( ) ;
2021-04-24 15:57:45 +08:00
2022-10-10 18:05:18 +08:00
m = ui - > tblBreakpoints - > selectionModel ( ) ;
2022-10-16 23:10:57 +08:00
ui - > tblBreakpoints - > setModel ( mDebugger - > breakpointModel ( ) . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
m = ui - > tblStackTrace - > selectionModel ( ) ;
2022-10-16 23:10:57 +08:00
ui - > tblStackTrace - > setModel ( mDebugger - > backtraceModel ( ) . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
m = ui - > watchView - > selectionModel ( ) ;
2022-10-16 23:10:57 +08:00
ui - > watchView - > setModel ( mDebugger - > watchModel ( ) . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
m = ui - > tblMemoryView - > selectionModel ( ) ;
2022-10-16 23:10:57 +08:00
ui - > tblMemoryView - > setModel ( mDebugger - > memoryModel ( ) . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2022-03-29 09:43:24 +08:00
2022-01-11 22:29:03 +08:00
ui - > tblMemoryView - > horizontalHeader ( ) - > setSectionResizeMode ( QHeaderView : : ResizeToContents ) ;
2021-07-25 00:26:13 +08:00
2021-10-22 07:42:51 +08:00
try {
2022-10-16 23:10:57 +08:00
mDebugger - > loadForNonproject ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_DEBUGGER_FILE ) ;
2021-10-22 07:42:51 +08:00
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2021-10-02 13:29:45 +08:00
// ui->actionIndent->setShortcut(Qt::Key_Tab);
// ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier);
2021-04-24 15:57:45 +08:00
2022-10-10 18:05:18 +08:00
//mainmenu takes the owner
2021-09-16 23:51:05 +08:00
mMenuNew = new QMenu ( ) ;
mMenuNew - > setTitle ( tr ( " New " ) ) ;
mMenuNew - > addAction ( ui - > actionNew ) ;
2023-02-12 22:33:34 +08:00
mMenuNew - > addAction ( ui - > actionNew_GAS_File ) ;
2023-03-04 12:47:49 +08:00
mMenuNew - > addAction ( ui - > actionNew_Text_File ) ;
2021-09-16 23:51:05 +08:00
mMenuNew - > addAction ( ui - > actionNew_Project ) ;
2022-02-01 16:17:28 +08:00
mMenuNew - > addSeparator ( ) ;
2022-08-07 21:41:57 +08:00
mMenuNew - > addAction ( ui - > actionNew_Template ) ;
mMenuNew - > addSeparator ( ) ;
2022-02-01 16:17:28 +08:00
mMenuNew - > addAction ( ui - > actionNew_Class ) ;
mMenuNew - > addAction ( ui - > actionNew_Header ) ;
2021-09-16 23:51:05 +08:00
ui - > menuFile - > insertMenu ( ui - > actionOpen , mMenuNew ) ;
2021-09-28 22:26:12 +08:00
2022-01-27 23:48:46 +08:00
2021-10-12 09:47:58 +08:00
mMenuExport = new QMenu ( tr ( " Export " ) ) ;
mMenuExport - > addAction ( ui - > actionExport_As_RTF ) ;
mMenuExport - > addAction ( ui - > actionExport_As_HTML ) ;
ui - > menuFile - > insertMenu ( ui - > actionPrint , mMenuExport ) ;
2021-09-28 22:26:12 +08:00
buildEncodingMenu ( ) ;
2021-06-12 22:36:23 +08:00
2021-09-17 21:33:19 +08:00
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-10-03 09:57:19 +08:00
mMenuInsertCodeSnippet = new QMenu ( ) ;
2021-10-15 10:23:46 +08:00
mMenuInsertCodeSnippet - > setTitle ( tr ( " Insert Snippet " ) ) ;
2022-12-16 11:10:46 +08:00
ui - > menuCode - > insertMenu ( ui - > actionTrim_trailing_spaces , mMenuInsertCodeSnippet ) ;
ui - > menuCode - > insertSeparator ( ui - > actionTrim_trailing_spaces ) ;
2021-10-03 09:57:19 +08:00
connect ( mMenuInsertCodeSnippet , & QMenu : : aboutToShow ,
2021-10-04 11:07:35 +08:00
this , & MainWindow : : onShowInsertCodeSnippetMenu ) ;
2021-10-03 09:57:19 +08:00
2021-08-01 23:24:37 +08:00
mCPUDialog = nullptr ;
2021-07-26 11:47:54 +08:00
2021-12-22 11:07:56 +08:00
// applySettings();
// applyUISettings();
// updateProjectView();
// updateEditorActions();
// updateCaretActions();
2021-06-24 16:05:19 +08:00
2023-03-14 17:49:36 +08:00
ui - > cbReplaceInHistory - > completer ( ) - > setCaseSensitivity ( Qt : : CaseSensitive ) ;
ui - > cbEvaluate - > completer ( ) - > setCaseSensitivity ( Qt : : CaseSensitive ) ;
ui - > cbMemoryAddress - > completer ( ) - > setCaseSensitivity ( Qt : : CaseSensitive ) ;
ui - > cbFilesPath - > completer ( ) - > setCaseSensitivity ( Qt : : CaseInsensitive ) ;
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-09-29 22:55:53 +08:00
connect ( ui - > cbMemoryAddress - > lineEdit ( ) , & QLineEdit : : returnPressed ,
this , & MainWindow : : onDebugMemoryAddressInput ) ;
2021-08-05 12:31:53 +08:00
2021-10-03 17:18:43 +08:00
mTodoParser = std : : make_shared < TodoParser > ( ) ;
2021-09-30 11:20:43 +08:00
mSymbolUsageManager = std : : make_shared < SymbolUsageManager > ( ) ;
2021-10-22 07:42:51 +08:00
try {
mSymbolUsageManager - > load ( ) ;
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2021-09-30 12:52:22 +08:00
mCodeSnippetManager = std : : make_shared < CodeSnippetsManager > ( ) ;
2021-10-22 07:42:51 +08:00
try {
mCodeSnippetManager - > load ( ) ;
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2021-10-08 00:06:41 +08:00
mToolsManager = std : : make_shared < ToolsManager > ( ) ;
2021-10-22 07:42:51 +08:00
try {
mToolsManager - > load ( ) ;
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2021-10-21 17:31:25 +08:00
mBookmarkModel = std : : make_shared < BookmarkModel > ( ) ;
2021-10-22 07:42:51 +08:00
try {
2022-10-11 21:51:33 +08:00
mBookmarkModel - > loadBookmarks ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
2021-10-21 17:31:25 +08:00
+ DEV_BOOKMARK_FILE ) ;
2021-10-22 07:42:51 +08:00
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2022-10-10 18:05:18 +08:00
m = ui - > tableBookmark - > selectionModel ( ) ;
2021-10-21 17:31:25 +08:00
ui - > tableBookmark - > setModel ( mBookmarkModel . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
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 ) ;
2022-10-10 18:05:18 +08:00
2021-08-05 19:58:32 +08:00
ui - > cbSearchHistory - > setModel ( mSearchResultListModel . get ( ) ) ;
2022-10-10 18:05:18 +08:00
m = ui - > searchView - > selectionModel ( ) ;
2021-08-05 12:31:53 +08:00
ui - > searchView - > setModel ( mSearchResultTreeModel . get ( ) ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2021-08-05 12:31:53 +08:00
ui - > searchView - > setItemDelegate ( mSearchViewDelegate . get ( ) ) ;
2022-10-10 18:05:18 +08:00
m = ui - > tableTODO - > selectionModel ( ) ;
2021-10-03 17:18:43 +08:00
ui - > tableTODO - > setModel ( & mTodoModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2021-08-05 19:58:32 +08:00
connect ( mSearchResultTreeModel . get ( ) , & QAbstractItemModel : : modelReset ,
ui - > searchView , & QTreeView : : expandAll ) ;
ui - > replacePanel - > setVisible ( false ) ;
2021-11-02 01:07:37 +08:00
ui - > tabProblem - > setEnabled ( false ) ;
2021-08-23 17:27:17 +08:00
2021-11-02 09:29:35 +08:00
//problem set
2021-11-01 20:44:08 +08:00
mOJProblemSetNameCounter = 1 ;
2021-11-01 00:40:11 +08:00
mOJProblemSetModel . rename ( tr ( " Problem Set %1 " ) . arg ( mOJProblemSetNameCounter ) ) ;
2022-11-14 19:10:32 +08:00
2022-10-10 18:05:18 +08:00
m = ui - > lstProblemSet - > selectionModel ( ) ;
2021-11-01 00:40:11 +08:00
ui - > lstProblemSet - > setModel ( & mOJProblemSetModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2022-11-14 19:10:32 +08:00
2022-10-10 18:05:18 +08:00
m = ui - > tblProblemCases - > selectionModel ( ) ;
2022-03-29 18:06:24 +08:00
ui - > tblProblemCases - > setModel ( & mOJProblemModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2021-11-01 00:40:11 +08:00
connect ( ui - > lstProblemSet - > selectionModel ( ) ,
& QItemSelectionModel : : currentRowChanged ,
this , & MainWindow : : onProblemSetIndexChanged ) ;
2022-03-29 18:06:24 +08:00
connect ( ui - > tblProblemCases - > selectionModel ( ) ,
2021-11-01 00:40:11 +08:00
& QItemSelectionModel : : currentRowChanged ,
this , & MainWindow : : onProblemCaseIndexChanged ) ;
2021-11-02 01:07:37 +08:00
connect ( & mOJProblemSetModel , & OJProblemSetModel : : problemNameChanged ,
this , & MainWindow : : onProblemNameChanged ) ;
ui - > pbProblemCases - > setVisible ( false ) ;
2021-11-02 09:29:35 +08:00
connect ( & mTcpServer , & QTcpServer : : newConnection ,
this , & MainWindow : : onNewProblemConnection ) ;
2021-11-01 00:40:11 +08:00
2022-01-01 17:24:18 +08:00
connect ( & mOJProblemModel , & OJProblemModel : : dataChanged ,
this , & MainWindow : : updateProblemTitle ) ;
2022-11-14 19:10:32 +08:00
try {
int currentIndex = - 1 ;
mOJProblemSetModel . load ( currentIndex ) ;
if ( currentIndex > = 0 ) {
QModelIndex index = mOJProblemSetModel . index ( currentIndex , 0 ) ;
ui - > lstProblemSet - > setCurrentIndex ( index ) ;
ui - > lstProblemSet - > scrollTo ( index ) ;
}
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2022-01-01 17:24:18 +08:00
2021-10-22 15:02:54 +08:00
//files view
2022-10-10 18:05:18 +08:00
m = ui - > treeFiles - > selectionModel ( ) ;
2021-10-22 07:42:51 +08:00
ui - > treeFiles - > setModel ( & mFileSystemModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2022-07-06 19:44:44 +08:00
connect ( & mFileSystemModel , & QFileSystemModel : : layoutChanged ,
this , & MainWindow : : onFileSystemModelLayoutChanged , Qt : : QueuedConnection ) ;
2022-02-08 16:36:20 +08:00
mFileSystemModel . setReadOnly ( false ) ;
2022-02-15 00:01:50 +08:00
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
2022-02-28 22:40:09 +08:00
mFileSystemModel . setNameFilters ( pSystemConsts - > defaultFileNameFilters ( ) ) ;
2022-07-07 20:08:58 +08:00
mFileSystemModel . setNameFilterDisables ( true ) ;
2022-03-11 20:51:33 +08:00
//setFilesViewRoot(pSettings->environment().currentFolder());
2021-10-22 15:02:54 +08:00
for ( int i = 1 ; i < mFileSystemModel . columnCount ( ) ; i + + ) {
ui - > treeFiles - > hideColumn ( i ) ;
}
2024-02-23 10:10:58 +08:00
FilenameEditDelegate * filenameEditDelegate = new FilenameEditDelegate ( ui - > treeFiles ) ;
ui - > treeFiles - > setItemDelegate ( filenameEditDelegate ) ;
2022-02-11 20:19:48 +08:00
connect ( ui - > cbFilesPath - > lineEdit ( ) , & QLineEdit : : returnPressed ,
this , & MainWindow : : onFilesViewPathChanged ) ;
2022-02-11 20:29:02 +08:00
connect ( ui - > cbFilesPath , QOverload < int > : : of ( & QComboBox : : currentIndexChanged ) ,
this , & MainWindow : : onFilesViewPathChanged ) ;
2021-10-22 15:02:54 +08:00
2021-08-23 17:27:17 +08:00
//class browser
2022-01-27 18:34:18 +08:00
ui - > classBrowser - > setUniformRowHeights ( true ) ;
2022-10-10 18:05:18 +08:00
m = ui - > classBrowser - > selectionModel ( ) ;
2021-08-23 17:27:17 +08:00
ui - > classBrowser - > setModel ( & mClassBrowserModel ) ;
2022-10-10 18:05:18 +08:00
delete m ;
2021-08-29 00:48:23 +08:00
2022-10-23 16:31:05 +08:00
connect ( & mClassBrowserModel , & ClassBrowserModel : : refreshStarted ,
this , & MainWindow : : onClassBrowserRefreshStart ) ;
connect ( & mClassBrowserModel , & ClassBrowserModel : : refreshEnd ,
this , & MainWindow : : onClassBrowserRefreshEnd ) ;
2021-08-31 14:40:41 +08:00
connect ( & mFileSystemWatcher , & QFileSystemWatcher : : fileChanged ,
this , & MainWindow : : onFileChanged ) ;
2023-03-19 20:51:12 +08:00
connect ( & mFileSystemWatcher , & QFileSystemWatcher : : directoryChanged ,
this , & MainWindow : : onDirChanged ) ;
2021-08-31 14:40:41 +08:00
2021-10-10 21:23:25 +08:00
mStatementColors = std : : make_shared < QHash < StatementKind , PColorSchemeItem > > ( ) ;
2021-08-29 10:29:56 +08:00
mCompletionPopup = std : : make_shared < CodeCompletionPopup > ( ) ;
2021-09-25 23:12:36 +08:00
mCompletionPopup - > setColors ( mStatementColors ) ;
2021-08-29 10:29:56 +08:00
mHeaderCompletionPopup = std : : make_shared < HeaderCompletionPopup > ( ) ;
2021-09-24 11:41:14 +08:00
mFunctionTip = std : : make_shared < FunctionTooltipWidget > ( ) ;
2021-08-29 10:29:56 +08:00
2021-09-25 23:12:36 +08:00
mClassBrowserModel . setColors ( mStatementColors ) ;
2021-08-30 22:05:45 +08:00
connect ( & mAutoSaveTimer , & QTimer : : timeout ,
this , & MainWindow : : onAutoSaveTimeout ) ;
resetAutoSaveTimer ( ) ;
2021-08-31 11:13:12 +08:00
2021-09-03 00:26:49 +08:00
connect ( ui - > menuFile , & QMenu : : aboutToShow ,
this , & MainWindow : : rebuildOpenedFileHisotryMenu ) ;
2021-09-17 21:33:19 +08:00
connect ( ui - > menuProject , & QMenu : : aboutToShow ,
this , & MainWindow : : updateProjectActions ) ;
2023-02-27 20:08:24 +08:00
# ifdef ARCH_X86
2023-02-26 17:50:03 +08:00
ui - > actionIA_32_Assembly_Language_Reference_Manual - > setVisible ( true ) ;
ui - > actionx86_Assembly_Language_Reference_Manual - > setVisible ( false ) ;
2023-02-27 20:08:24 +08:00
# elif defined(ARCH_X86_64)
2023-03-05 08:56:11 +08:00
ui - > actionIA_32_Assembly_Language_Reference_Manual - > setVisible ( false ) ;
2023-02-26 17:50:03 +08:00
ui - > actionx86_Assembly_Language_Reference_Manual - > setVisible ( true ) ;
2023-02-27 20:08:24 +08:00
# else
2023-02-26 17:50:03 +08:00
ui - > actionIA_32_Assembly_Language_Reference_Manual - > setVisible ( false ) ;
ui - > actionx86_Assembly_Language_Reference_Manual - > setVisible ( false ) ;
2023-02-27 20:08:24 +08:00
# endif
2021-10-18 23:44:02 +08:00
ui - > actionEGE_Manual - > setVisible ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) ;
2023-07-02 11:09:34 +08:00
ui - > actionOI_Wiki - > setVisible ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) ;
ui - > actionTurtle_Graphics_Manual - > setVisible ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) ;
2023-01-16 15:42:03 +08:00
ui - > actionDocument - > setVisible ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) ;
2021-10-03 09:57:19 +08:00
2022-03-15 12:29:56 +08:00
connect ( ui - > EditorTabsLeft , & EditorsTabWidget : : middleButtonClicked ,
this , & MainWindow : : on_EditorTabsLeft_tabCloseRequested ) ;
connect ( ui - > EditorTabsRight , & EditorsTabWidget : : middleButtonClicked ,
this , & MainWindow : : on_EditorTabsRight_tabCloseRequested ) ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2023-08-11 13:49:09 +08:00
//git menu
2022-02-15 00:01:50 +08:00
connect ( ui - > menuGit , & QMenu : : aboutToShow ,
this , & MainWindow : : updateVCSActions ) ;
2023-08-08 14:41:23 +08:00
# endif
2022-12-17 11:37:33 +08:00
initToolButtons ( ) ;
2021-08-31 11:13:12 +08:00
buildContextMenus ( ) ;
2021-12-22 11:07:56 +08:00
updateAppTitle ( ) ;
2022-01-26 21:36:31 +08:00
//applySettings();
2021-12-22 11:07:56 +08:00
applyUISettings ( ) ;
2022-05-22 14:31:13 +08:00
initDocks ( ) ;
2021-12-22 11:07:56 +08:00
updateProjectView ( ) ;
updateEditorActions ( ) ;
updateCaretActions ( ) ;
2021-09-25 23:12:36 +08:00
updateEditorColorSchemes ( ) ;
2021-10-06 23:19:18 +08:00
updateShortcuts ( ) ;
2021-10-08 00:06:41 +08:00
updateTools ( ) ;
2021-12-21 11:57:23 +08:00
updateEditorSettings ( ) ;
2022-10-11 21:51:33 +08:00
//updateEditorBookmarks();
2021-04-06 23:10:57 +08:00
}
MainWindow : : ~ MainWindow ( )
{
2022-12-05 12:04:48 +08:00
mQuitting = true ;
2023-03-19 20:51:12 +08:00
if ( mProject )
mProject = nullptr ;
2022-10-10 18:05:18 +08:00
delete mProjectProxyModel ;
2021-09-26 19:40:52 +08:00
delete mEditorList ;
2021-04-06 23:10:57 +08:00
delete ui ;
}
2022-10-24 10:58:30 +08:00
void MainWindow : : updateForEncodingInfo ( bool clear )
{
2021-04-08 10:29:21 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-24 10:58:30 +08:00
updateForEncodingInfo ( editor , clear ) ;
}
void MainWindow : : updateForEncodingInfo ( const Editor * editor , bool clear ) {
2022-10-26 09:33:45 +08:00
if ( ! clear & & editor ! = nullptr ) {
2021-09-28 22:26:12 +08:00
if ( editor - > encodingOption ( ) ! = editor - > fileEncoding ( ) ) {
mFileEncodingStatus - > setText (
2023-01-04 11:01:34 +08:00
QString ( " %1(%2) " )
2021-09-28 22:26:12 +08:00
. arg ( QString ( editor - > encodingOption ( ) )
, QString ( editor - > fileEncoding ( ) ) ) ) ;
} else {
mFileEncodingStatus - > setText (
2023-01-04 11:01:34 +08:00
QString ( " %1 " )
2021-09-28 22:26:12 +08:00
. arg ( QString ( editor - > encodingOption ( ) ) )
) ;
}
2023-01-24 10:21:19 +08:00
//ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
2021-06-12 22:36:23 +08:00
ui - > actionEncode_in_ANSI - > setChecked ( editor - > encodingOption ( ) = = ENCODING_SYSTEM_DEFAULT ) ;
ui - > actionEncode_in_UTF_8 - > setChecked ( editor - > encodingOption ( ) = = ENCODING_UTF8 ) ;
2022-09-21 09:31:01 +08:00
ui - > actionEncode_in_UTF_8_BOM - > setChecked ( editor - > encodingOption ( ) = = ENCODING_UTF8_BOM ) ;
2021-06-12 22:36:23 +08:00
} else {
mFileEncodingStatus - > setText ( " " ) ;
2023-01-24 10:21:19 +08:00
//ui->actionAuto_Detect->setChecked(false);
2021-06-12 22:36:23 +08:00
ui - > actionEncode_in_ANSI - > setChecked ( false ) ;
ui - > actionEncode_in_UTF_8 - > setChecked ( false ) ;
2022-05-06 15:23:41 +08:00
ui - > actionEncode_in_UTF_8_BOM - > setChecked ( false ) ;
2021-04-08 10:29:21 +08:00
}
2021-04-11 13:55:31 +08:00
}
2022-10-24 10:58:30 +08:00
void MainWindow : : updateStatusbarForLineCol ( bool clear )
{
Editor * e = mEditorList - > getEditor ( ) ;
updateStatusbarForLineCol ( e , clear ) ;
}
2021-06-12 22:36:23 +08:00
void MainWindow : : updateEditorSettings ( )
2021-04-11 13:55:31 +08:00
{
2022-12-20 11:01:04 +08:00
pIconsManager - > updateEditorGuttorIcons (
pSettings - > environment ( ) . iconSet ( ) ,
calIconSize ( pSettings - > editor ( ) . fontName ( ) , pSettings - > editor ( ) . fontSize ( ) )
) ;
2021-06-12 22:36:23 +08:00
mEditorList - > applySettings ( ) ;
}
2022-10-11 21:51:33 +08:00
void MainWindow : : updateEditorBookmarks ( )
{
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
e - > resetBookmarks ( ) ;
}
}
2022-10-17 23:23:05 +08:00
void MainWindow : : updateEditorBreakpoints ( )
{
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
e - > resetBreakpoints ( ) ;
}
}
2021-06-12 22:36:23 +08:00
void MainWindow : : updateEditorActions ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
2022-10-24 10:58:30 +08:00
updateEditorActions ( e ) ;
}
void MainWindow : : updateEditorActions ( const Editor * e )
{
2023-01-03 21:43:45 +08:00
//it's not a compile action, but put here for convinience
ui - > actionSaveAll - > setEnabled (
( mProject ! = nullptr | | mEditorList - > pageCount ( ) > 0 ) ) ;
2024-03-13 11:04:51 +08:00
if ( e = = nullptr | | ! e - > hasFocus ( ) ) {
2021-06-12 22:36:23 +08:00
ui - > actionAuto_Detect - > setEnabled ( false ) ;
ui - > actionEncode_in_ANSI - > setEnabled ( false ) ;
ui - > actionEncode_in_UTF_8 - > setEnabled ( false ) ;
2022-05-06 15:23:41 +08:00
ui - > actionEncode_in_UTF_8_BOM - > setEnabled ( false ) ;
2022-03-12 17:37:53 +08:00
mMenuEncoding - > setEnabled ( false ) ;
2021-06-12 22:36:23 +08:00
ui - > actionConvert_to_ANSI - > setEnabled ( false ) ;
ui - > actionConvert_to_UTF_8 - > setEnabled ( false ) ;
2022-05-06 15:23:41 +08:00
ui - > actionConvert_to_UTF_8_BOM - > setEnabled ( false ) ;
2021-06-12 22:36:23 +08:00
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 ) ;
2021-10-12 09:47:58 +08:00
ui - > actionExport_As_HTML - > setEnabled ( false ) ;
ui - > actionExport_As_RTF - > setEnabled ( false ) ;
2021-10-07 07:52:20 +08:00
ui - > actionPrint - > setEnabled ( false ) ;
2021-06-12 22:36:23 +08:00
ui - > actionToggleComment - > setEnabled ( false ) ;
2022-10-18 19:09:46 +08:00
ui - > actionToggle_Block_Comment - > setEnabled ( false ) ;
2021-06-12 22:36:23 +08:00
ui - > actionUnIndent - > setEnabled ( false ) ;
ui - > actionUndo - > setEnabled ( false ) ;
ui - > actionUnfoldAll - > setEnabled ( false ) ;
2021-11-23 10:32:33 +08:00
ui - > actionDelete_Line - > setEnabled ( false ) ;
ui - > actionDelete_Word - > setEnabled ( false ) ;
ui - > actionDuplicate_Line - > setEnabled ( false ) ;
ui - > actionDelete_to_BOL - > setEnabled ( false ) ;
ui - > actionDelete_to_EOL - > setEnabled ( false ) ;
2022-10-18 19:09:46 +08:00
ui - > actionDelete_to_Word_End - > setEnabled ( false ) ;
ui - > actionDelete_Last_Word - > setEnabled ( false ) ;
2024-03-13 11:04:51 +08:00
ui - > menuMove_Caret - > setEnabled ( false ) ;
ui - > actionPage_Up - > setEnabled ( false ) ;
ui - > actionPage_Down - > setEnabled ( false ) ;
ui - > actionGoto_Line_Start - > setEnabled ( false ) ;
ui - > actionGoto_Line_End - > setEnabled ( false ) ;
ui - > actionGoto_File_Start - > setEnabled ( false ) ;
ui - > actionGoto_File_End - > setEnabled ( false ) ;
ui - > actionGoto_Page_Start - > setEnabled ( false ) ;
ui - > actionGoto_Page_End - > setEnabled ( false ) ;
ui - > actionSelectAll - > setEnabled ( false ) ;
ui - > actionSelect_Word - > setEnabled ( false ) ;
ui - > actionMove_Selection_Up - > setEnabled ( false ) ;
ui - > actionMove_Selection_Down - > setEnabled ( false ) ;
ui - > actionPage_Up_and_Select - > setEnabled ( false ) ;
ui - > actionPage_Down_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_Line_Start_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_Line_End_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_File_Start_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_File_End_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_Page_Start_and_Select - > setEnabled ( false ) ;
ui - > actionGoto_Page_End_and_Select - > setEnabled ( false ) ;
2021-11-23 10:32:33 +08:00
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 ) ;
2021-09-02 20:12:16 +08:00
ui - > actionClose - > setEnabled ( false ) ;
ui - > actionClose_All - > setEnabled ( false ) ;
2023-06-13 17:16:09 +08:00
ui - > actionClose_Others - > setEnabled ( false ) ;
2021-10-21 17:31:25 +08:00
ui - > actionAdd_bookmark - > setEnabled ( false ) ;
ui - > actionRemove_Bookmark - > setEnabled ( false ) ;
ui - > actionModify_Bookmark_Description - > setEnabled ( false ) ;
2021-10-22 15:02:54 +08:00
2024-03-13 11:04:51 +08:00
ui - > actionMatch_Bracket - > setEnabled ( false ) ;
2022-07-21 15:28:07 +08:00
ui - > actionGo_to_Line - > setEnabled ( false ) ;
2024-03-13 11:04:51 +08:00
ui - > actionGoto_block_start - > setEnabled ( false ) ;
ui - > actionGoto_block_end - > setEnabled ( false ) ;
ui - > actionTrim_trailing_spaces - > setEnabled ( false ) ;
mMenuInsertCodeSnippet - > setEnabled ( false ) ;
ui - > actionRename_Symbol - > setEnabled ( false ) ;
2021-10-22 15:02:54 +08:00
ui - > actionLocate_in_Files_View - > setEnabled ( false ) ;
2023-01-02 16:50:30 +08:00
ui - > actionToggle_Readonly - > setEnabled ( false ) ;
2023-01-07 20:04:51 +08:00
ui - > actionGoto_Declaration - > setEnabled ( false ) ;
ui - > actionGoto_Definition - > setEnabled ( false ) ;
ui - > actionFind_references - > setEnabled ( false ) ;
2023-03-03 09:04:26 +08:00
ui - > actionMove_To_Other_View - > setEnabled ( false ) ;
2021-06-12 22:36:23 +08:00
} else {
ui - > actionAuto_Detect - > setEnabled ( true ) ;
ui - > actionEncode_in_ANSI - > setEnabled ( true ) ;
ui - > actionEncode_in_UTF_8 - > setEnabled ( true ) ;
2022-05-06 15:23:41 +08:00
ui - > actionEncode_in_UTF_8_BOM - > setEnabled ( true ) ;
2022-03-12 17:37:53 +08:00
mMenuEncoding - > setEnabled ( true ) ;
2022-02-15 00:01:50 +08:00
ui - > actionConvert_to_ANSI - > setEnabled ( e - > encodingOption ( ) ! = ENCODING_SYSTEM_DEFAULT
& & e - > fileEncoding ( ) ! = ENCODING_SYSTEM_DEFAULT ) ;
2021-06-12 22:36:23 +08:00
ui - > actionConvert_to_UTF_8 - > setEnabled ( e - > encodingOption ( ) ! = ENCODING_UTF8 & & e - > fileEncoding ( ) ! = ENCODING_UTF8 ) ;
2022-05-06 15:23:41 +08:00
ui - > actionConvert_to_UTF_8_BOM - > setEnabled ( e - > encodingOption ( ) ! = ENCODING_UTF8_BOM & & e - > fileEncoding ( ) ! = ENCODING_UTF8_BOM ) ;
2021-07-01 19:44:38 +08:00
2023-03-09 11:19:57 +08:00
ui - > actionCopy - > setEnabled ( true ) ;
2022-07-02 17:59:07 +08:00
ui - > actionCut - > setEnabled ( true ) ;
2022-04-19 21:18:41 +08:00
ui - > actionFoldAll - > setEnabled ( e - > document ( ) - > count ( ) > 0 ) ;
2021-06-12 22:36:23 +08:00
ui - > actionIndent - > setEnabled ( ! e - > readOnly ( ) ) ;
2022-12-11 19:47:43 +08:00
ui - > actionPaste - > setEnabled ( ! e - > readOnly ( ) ) ;
2021-06-12 22:36:23 +08:00
ui - > actionRedo - > setEnabled ( e - > canRedo ( ) ) ;
ui - > actionUndo - > setEnabled ( e - > canUndo ( ) ) ;
2021-11-01 23:14:17 +08:00
ui - > actionSave - > setEnabled ( ! e - > readOnly ( ) ) ;
2021-06-12 22:36:23 +08:00
ui - > actionSaveAs - > setEnabled ( true ) ;
2021-10-12 09:47:58 +08:00
ui - > actionExport_As_HTML - > setEnabled ( true ) ;
ui - > actionExport_As_RTF - > setEnabled ( true ) ;
2021-10-07 07:52:20 +08:00
ui - > actionPrint - > setEnabled ( true ) ;
2022-04-19 21:18:41 +08:00
ui - > actionToggleComment - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
2022-10-18 19:09:46 +08:00
ui - > actionToggle_Block_Comment - > setEnabled ( ! e - > readOnly ( ) & & e - > selAvail ( ) ) ;
2022-04-19 21:18:41 +08:00
ui - > actionUnIndent - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionUnfoldAll - > setEnabled ( e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_Line - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_Word - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDuplicate_Line - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_to_BOL - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_to_EOL - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
2022-10-18 19:09:46 +08:00
ui - > actionDelete_to_Word_End - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_Last_Word - > setEnabled ( ! e - > readOnly ( ) & & e - > document ( ) - > count ( ) > 0 ) ;
2024-03-13 11:04:51 +08:00
ui - > menuMove_Caret - > setEnabled ( true ) ;
ui - > actionPage_Up - > setEnabled ( true ) ;
ui - > actionPage_Down - > setEnabled ( true ) ;
ui - > actionGoto_Line_Start - > setEnabled ( true ) ;
ui - > actionGoto_Line_End - > setEnabled ( true ) ;
ui - > actionGoto_File_Start - > setEnabled ( true ) ;
ui - > actionGoto_File_End - > setEnabled ( true ) ;
ui - > actionGoto_Page_Start - > setEnabled ( true ) ;
ui - > actionGoto_Page_End - > setEnabled ( true ) ;
ui - > actionSelectAll - > setEnabled ( e - > document ( ) - > count ( ) > 0 ) ;
ui - > actionSelect_Word - > setEnabled ( true ) ;
ui - > actionMove_Selection_Up - > setEnabled ( true ) ;
ui - > actionMove_Selection_Down - > setEnabled ( true ) ;
ui - > actionPage_Up_and_Select - > setEnabled ( true ) ;
ui - > actionPage_Down_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_Line_Start_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_Line_End_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_File_Start_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_File_End_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_Page_Start_and_Select - > setEnabled ( true ) ;
ui - > actionGoto_Page_End_and_Select - > setEnabled ( true ) ;
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
2023-02-18 22:09:14 +08:00
ui - > actionReformat_Code - > setEnabled ( isCFile ( e - > filename ( ) ) | | isHFile ( e - > filename ( ) ) ) ;
2021-09-02 12:14:02 +08:00
2021-09-02 20:12:16 +08:00
ui - > actionClose - > setEnabled ( true ) ;
ui - > actionClose_All - > setEnabled ( true ) ;
2023-06-13 17:16:09 +08:00
ui - > actionClose_Others - > setEnabled ( mEditorList - > pageCount ( ) > 1 ) ;
2021-10-21 17:31:25 +08:00
int line = e - > caretY ( ) ;
2022-04-19 21:18:41 +08:00
ui - > actionAdd_bookmark - > setEnabled ( e - > document ( ) - > count ( ) > 0 & & ! e - > hasBookmark ( line ) ) ;
2021-10-21 17:31:25 +08:00
ui - > actionRemove_Bookmark - > setEnabled ( e - > hasBookmark ( line ) ) ;
ui - > actionModify_Bookmark_Description - > setEnabled ( e - > hasBookmark ( line ) ) ;
2021-10-22 15:02:54 +08:00
2024-03-13 11:04:51 +08:00
ui - > actionMatch_Bracket - > setEnabled ( true ) ;
2023-01-02 16:50:30 +08:00
ui - > actionGo_to_Line - > setEnabled ( true ) ;
2024-03-13 11:04:51 +08:00
ui - > actionGoto_block_start - > setEnabled ( true ) ;
ui - > actionGoto_block_end - > setEnabled ( true ) ;
ui - > actionTrim_trailing_spaces - > setEnabled ( true ) ;
mMenuInsertCodeSnippet - > setEnabled ( true ) ;
ui - > actionRename_Symbol - > setEnabled ( true ) ;
2021-10-22 15:02:54 +08:00
ui - > actionLocate_in_Files_View - > setEnabled ( ! e - > isNew ( ) ) ;
2023-01-02 16:50:30 +08:00
ui - > actionToggle_Readonly - > setEnabled ( ! e - > modified ( ) ) ;
2023-01-07 20:04:51 +08:00
//these actions needs parser
ui - > actionGoto_Declaration - > setEnabled ( e - > parser ( ) ! = nullptr ) ;
ui - > actionGoto_Definition - > setEnabled ( e - > parser ( ) ! = nullptr ) ;
ui - > actionFind_references - > setEnabled ( e - > parser ( ) ! = nullptr ) ;
2023-03-03 09:04:26 +08:00
ui - > actionMove_To_Other_View - > setEnabled ( editorList ( ) - > pageCount ( ) > 1 ) ;
2021-10-21 17:31:25 +08:00
}
2021-09-02 20:12:16 +08:00
2022-12-17 17:20:33 +08:00
updateCompileActions ( e ) ;
updateCompilerSet ( e ) ;
2021-04-08 10:29:21 +08:00
}
2022-10-24 10:58:30 +08:00
2021-09-17 09:56:52 +08:00
void MainWindow : : updateProjectActions ( )
{
bool hasProject = ( mProject ! = nullptr ) ;
2022-08-07 21:41:57 +08:00
ui - > actionNew_Template - > setEnabled ( hasProject ) ;
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 ) ;
2021-09-17 21:33:19 +08:00
ui - > actionRemove_from_project - > setEnabled ( hasProject & & ui - > projectView - > selectionModel ( ) - > selectedIndexes ( ) . count ( ) > 0 ) ;
ui - > actionMakeClean - > setEnabled ( hasProject ) ;
2021-09-17 09:56:52 +08:00
ui - > actionProject_options - > setEnabled ( hasProject ) ;
ui - > actionClose_Project - > setEnabled ( hasProject ) ;
2022-01-27 18:46:37 +08:00
ui - > actionNew_Class - > setEnabled ( hasProject ) ;
2022-02-01 16:17:28 +08:00
ui - > actionNew_Header - > setEnabled ( hasProject ) ;
2021-09-18 10:47:35 +08:00
ui - > actionProject_Open_Folder_In_Explorer - > setEnabled ( hasProject ) ;
ui - > actionProject_Open_In_Terminal - > setEnabled ( hasProject ) ;
2021-09-17 09:56:52 +08:00
updateCompileActions ( ) ;
}
2022-12-17 17:20:33 +08:00
void MainWindow : : updateCompileActions ( ) {
updateCompileActions ( mEditorList - > getEditor ( ) ) ;
}
void MainWindow : : updateCompileActions ( const Editor * e )
2021-07-01 19:44:38 +08:00
{
2023-01-03 21:43:45 +08:00
if ( mCompilerManager - > compiling ( )
//|| mCompilerManager->backgroundSyntaxChecking()
| | mCompilerManager - > running ( ) | | mDebugger - > executing ( ) ) {
2021-07-01 19:44:38 +08:00
ui - > actionCompile - > setEnabled ( false ) ;
ui - > actionRun - > setEnabled ( false ) ;
ui - > actionRebuild - > setEnabled ( false ) ;
2022-12-01 22:10:44 +08:00
ui - > actionGenerate_Assembly - > setEnabled ( false ) ;
2021-08-01 12:02:28 +08:00
ui - > actionDebug - > setEnabled ( false ) ;
2022-12-31 09:36:50 +08:00
mProblem_RunAllCases - > setEnabled ( false ) ;
2021-07-01 19:44:38 +08:00
} else {
2022-12-16 11:10:46 +08:00
bool forProject = false ;
bool canRun = false ;
2023-08-14 12:22:24 +08:00
bool canDebug = false ;
2022-12-16 18:27:10 +08:00
bool canCompile = false ;
2022-12-28 16:39:18 +08:00
bool canGenerateAssembly = false ;
2023-08-14 12:22:24 +08:00
Settings : : PCompilerSet set = pSettings - > compilerSets ( ) . getSet ( mCompilerSet - > currentIndex ( ) ) ;
if ( set ) {
if ( e ) {
if ( ! e - > inProject ( ) ) {
FileType fileType = getFileType ( e - > filename ( ) ) ;
switch ( fileType ) {
case FileType : : CSource :
canCompile = set - > canCompileC ( ) ;
2023-10-25 00:34:29 +08:00
//qDebug()<<(int)set->compilerType();
2023-08-14 12:22:24 +08:00
# ifdef ENABLE_SDCC
if ( set - > compilerType ( ) ! = CompilerType : : SDCC )
# endif
{
canGenerateAssembly = canCompile ;
canRun = canCompile ;
}
2023-10-25 00:34:29 +08:00
//qDebug()<<canCompile<<canRun;
2023-08-14 12:22:24 +08:00
canDebug = set - > canDebug ( ) ;
break ;
case FileType : : CppSource :
canCompile = set - > canCompileCPP ( ) ;
canGenerateAssembly = canCompile ;
canRun = canCompile ;
canDebug = set - > canDebug ( ) ;
break ;
case FileType : : GAS :
if ( set - > compilerType ( ) = = CompilerType : : GCC ) {
canCompile = true ;
canRun = canCompile ;
canDebug = set - > canDebug ( ) ;
}
break ;
}
} else {
forProject = ( mProject ! = nullptr ) ;
2022-12-16 11:10:46 +08:00
}
2023-08-14 12:22:24 +08:00
} else {
forProject = ( mProject ! = nullptr ) ;
2022-12-16 11:10:46 +08:00
}
2023-08-14 12:22:24 +08:00
if ( forProject ) {
canCompile = true ;
canRun = ( mProject - > options ( ) . type ! = ProjectType : : DynamicLib )
& & ( mProject - > options ( ) . type ! = ProjectType : : StaticLib ) ;
canDebug = set - > canDebug ( ) & & canRun ;
if ( e ) {
FileType fileType = getFileType ( e - > filename ( ) ) ;
if ( fileType = = FileType : : CSource
| | fileType = = FileType : : CppSource ) {
canGenerateAssembly = true ;
}
2022-12-28 16:39:18 +08:00
}
}
2022-12-16 11:10:46 +08:00
}
2022-12-16 18:27:10 +08:00
ui - > actionCompile - > setEnabled ( canCompile ) ;
2022-11-30 21:05:08 +08:00
ui - > actionRun - > setEnabled ( canRun ) ;
2022-12-16 18:27:10 +08:00
ui - > actionRebuild - > setEnabled ( canCompile ) ;
2022-12-28 16:39:18 +08:00
ui - > actionGenerate_Assembly - > setEnabled ( canGenerateAssembly ) ;
2023-08-14 12:22:24 +08:00
ui - > actionDebug - > setEnabled ( canDebug ) ;
2022-12-31 09:36:50 +08:00
mProblem_RunAllCases - > setEnabled ( canRun & & mOJProblemModel . count ( ) > 0 ) ;
2021-07-01 19:44:38 +08:00
}
2021-09-28 22:26:12 +08:00
if ( ! mDebugger - > executing ( ) ) {
disableDebugActions ( ) ;
}
2021-08-01 12:02:28 +08:00
ui - > actionStop_Execution - > setEnabled ( mCompilerManager - > running ( ) | | mDebugger - > executing ( ) ) ;
2021-09-17 09:56:52 +08:00
2023-01-03 21:43:45 +08:00
2021-07-01 19:44:38 +08:00
}
2021-06-20 14:30:47 +08:00
void MainWindow : : updateEditorColorSchemes ( )
{
2021-10-31 00:08:20 +08:00
if ( ! mStatementColors )
return ;
mStatementColors - > clear ( ) ;
2021-06-20 14:30:47 +08:00
mEditorList - > applyColorSchemes ( pSettings - > editor ( ) . colorScheme ( ) ) ;
2021-09-25 23:12:36 +08:00
QString schemeName = pSettings - > editor ( ) . colorScheme ( ) ;
2021-11-07 22:34:19 +08:00
pColorManager - > updateStatementColors ( mStatementColors , schemeName ) ;
2021-09-25 23:12:36 +08:00
//color for code completion popup
PColorSchemeItem item ;
2022-06-20 21:43:42 +08:00
QColor localHeaderColor = palette ( ) . color ( QPalette : : Text ) ;
QColor systemHeaderColor = palette ( ) . color ( QPalette : : Text ) ;
QColor projectHeaderColor = palette ( ) . color ( QPalette : : Text ) ;
QColor headerFolderColor = palette ( ) . color ( QPalette : : Text ) ;
2021-10-31 00:08:20 +08:00
QColor baseColor = palette ( ) . color ( QPalette : : Base ) ;
2021-09-25 23:12:36 +08:00
item = pColorManager - > getItem ( schemeName , SYNS_AttrPreprocessor ) ;
2021-11-02 23:47:51 +08:00
if ( item ) {
2022-06-20 21:43:42 +08:00
localHeaderColor = item - > foreground ( ) ;
}
item = pColorManager - > getItem ( schemeName , SYNS_AttrPreprocessor ) ;
if ( item ) {
systemHeaderColor = item - > foreground ( ) ;
}
item = pColorManager - > getItem ( schemeName , SYNS_AttrString ) ;
if ( item ) {
projectHeaderColor = item - > foreground ( ) ;
}
item = pColorManager - > getItem ( schemeName , SYNS_AttrStringEscapeSequences ) ;
if ( item ) {
headerFolderColor = item - > foreground ( ) ;
2021-09-25 23:12:36 +08:00
}
2021-11-02 19:26:11 +08:00
item = pColorManager - > getItem ( schemeName , COLOR_SCHEME_ERROR ) ;
if ( item & & haveGoodContrast ( item - > foreground ( ) , baseColor ) ) {
mErrorColor = item - > foreground ( ) ;
} else {
mErrorColor = palette ( ) . color ( QPalette : : Text ) ;
}
ui - > tableIssues - > setErrorColor ( mErrorColor ) ;
item = pColorManager - > getItem ( schemeName , COLOR_SCHEME_WARNING ) ;
if ( item & & haveGoodContrast ( item - > foreground ( ) , baseColor ) ) {
ui - > tableIssues - > setWarningColor ( item - > foreground ( ) ) ;
} else {
ui - > tableIssues - > setWarningColor ( palette ( ) . color ( QPalette : : Text ) ) ;
}
2021-11-04 00:54:20 +08:00
item = pColorManager - > getItem ( schemeName , COLOR_SCHEME_TEXT ) ;
if ( item ) {
QPalette pal = palette ( ) ;
pal . setColor ( QPalette : : Base , item - > background ( ) ) ;
pal . setColor ( QPalette : : Text , item - > foreground ( ) ) ;
mCompletionPopup - > setPalette ( pal ) ;
mHeaderCompletionPopup - > setPalette ( pal ) ;
2021-11-04 00:57:43 +08:00
ui - > classBrowser - > setPalette ( pal ) ;
2022-06-14 09:09:35 +08:00
ui - > txtProblemCaseInput - > setPalette ( pal ) ;
ui - > txtProblemCaseExpected - > setPalette ( pal ) ;
ui - > txtProblemCaseOutput - > setPalette ( pal ) ;
2021-11-04 00:54:20 +08:00
} else {
QPalette pal = palette ( ) ;
mCompletionPopup - > setPalette ( pal ) ;
mHeaderCompletionPopup - > setPalette ( pal ) ;
2021-11-04 00:57:43 +08:00
ui - > classBrowser - > setPalette ( pal ) ;
2022-06-14 09:09:35 +08:00
ui - > txtProblemCaseInput - > setPalette ( pal ) ;
ui - > txtProblemCaseExpected - > setPalette ( pal ) ;
ui - > txtProblemCaseOutput - > setPalette ( pal ) ;
}
item = pColorManager - > getItem ( schemeName , COLOR_SCHEME_GUTTER ) ;
if ( item ) {
ui - > txtProblemCaseInput - > setLineNumberAreaForeground ( item - > foreground ( ) ) ;
ui - > txtProblemCaseInput - > setLineNumberAreaBackground ( item - > background ( ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaForeground ( item - > foreground ( ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaBackground ( item - > background ( ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaForeground ( item - > foreground ( ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaBackground ( item - > background ( ) ) ;
} else {
QPalette pal = palette ( ) ;
ui - > txtProblemCaseInput - > setLineNumberAreaForeground ( pal . color ( QPalette : : ButtonText ) ) ;
ui - > txtProblemCaseInput - > setLineNumberAreaBackground ( pal . color ( QPalette : : Button ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaForeground ( pal . color ( QPalette : : ButtonText ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaBackground ( pal . color ( QPalette : : Button ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaForeground ( pal . color ( QPalette : : ButtonText ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaBackground ( pal . color ( QPalette : : Button ) ) ;
}
item = pColorManager - > getItem ( schemeName , COLOR_SCHEME_GUTTER_ACTIVE_LINE ) ;
if ( item ) {
ui - > txtProblemCaseInput - > setLineNumberAreaCurrentLine ( item - > foreground ( ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaCurrentLine ( item - > foreground ( ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaCurrentLine ( item - > foreground ( ) ) ;
} else {
QPalette pal = palette ( ) ;
ui - > txtProblemCaseInput - > setLineNumberAreaCurrentLine ( pal . color ( QPalette : : ButtonText ) ) ;
ui - > txtProblemCaseOutput - > setLineNumberAreaCurrentLine ( pal . color ( QPalette : : ButtonText ) ) ;
ui - > txtProblemCaseExpected - > setLineNumberAreaCurrentLine ( pal . color ( QPalette : : ButtonText ) ) ;
2021-11-04 00:54:20 +08:00
}
2022-06-20 21:43:42 +08:00
mHeaderCompletionPopup - > setSuggestionColor ( localHeaderColor ,
projectHeaderColor ,
systemHeaderColor ,
headerFolderColor ) ;
2021-06-20 14:30:47 +08:00
}
2021-06-18 21:48:40 +08:00
void MainWindow : : applySettings ( )
{
2021-10-18 22:06:33 +08:00
ThemeManager themeManager ;
2022-01-28 16:13:20 +08:00
if ( pSettings - > environment ( ) . useCustomTheme ( ) ) {
themeManager . prepareCustomeTheme ( ) ;
}
themeManager . setUseCustomTheme ( pSettings - > environment ( ) . useCustomTheme ( ) ) ;
try {
PAppTheme appTheme = themeManager . theme ( pSettings - > environment ( ) . theme ( ) ) ;
2023-12-22 18:03:29 +08:00
const QString & style = appTheme - > style ( ) ;
if ( style = = " RedPandaDarkFusion " )
QApplication : : setStyle ( new DarkFusionStyle ( ) ) ; //app takes the onwership
else if ( style = = " RedPandaLightFusion " )
QApplication : : setStyle ( new LightFusionStyle ( ) ) ; //app takes the onwership
else
QApplication : : setStyle ( style ) ;
2022-01-28 16:13:20 +08:00
qApp - > setPalette ( appTheme - > palette ( ) ) ;
//fix for qstatusbar bug
mFileEncodingStatus - > setPalette ( appTheme - > palette ( ) ) ;
mFileModeStatus - > setPalette ( appTheme - > palette ( ) ) ;
mFileInfoStatus - > setPalette ( appTheme - > palette ( ) ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this ,
tr ( " Load Theme Error " ) ,
e . reason ( ) ) ;
}
2023-12-22 18:03:29 +08:00
# ifdef ENABLE_LUA_ADDON
catch ( AddOn : : LuaError e ) {
QMessageBox : : critical ( this ,
tr ( " Load Theme Error " ) ,
e . reason ( ) ) ;
}
# endif
2022-01-28 16:13:20 +08:00
2021-10-31 00:08:20 +08:00
updateEditorColorSchemes ( ) ;
2021-10-18 22:06:33 +08:00
2021-12-16 19:14:14 +08:00
QFont font ( pSettings - > environment ( ) . interfaceFont ( ) ) ;
2021-12-17 09:05:01 +08:00
font . setPixelSize ( pointToPixel ( pSettings - > environment ( ) . interfaceFontSize ( ) ) ) ;
2021-06-20 09:27:37 +08:00
font . setStyleStrategy ( QFont : : PreferAntialias ) ;
2021-10-18 22:06:33 +08:00
qApp - > setFont ( font ) ;
2021-06-20 22:54:16 +08:00
this - > setFont ( font ) ;
2022-01-26 21:36:31 +08:00
for ( QWidget * p : findChildren < QWidget * > ( ) ) {
2023-01-03 22:34:38 +08:00
if ( mCPUDialog & & ( p = = mCPUDialog | | mCPUDialog - > isAncestorOf ( p ) ) )
continue ;
2022-01-26 21:36:31 +08:00
p - > setFont ( font ) ;
}
2022-01-27 12:08:57 +08:00
if ( pSettings - > environment ( ) . useCustomIconSet ( ) ) {
2022-01-28 19:30:50 +08:00
QString customIconSetFolder = pSettings - > dirs ( ) . config ( Settings : : Dirs : : DataType : : IconSet ) ;
pIconsManager - > prepareCustomIconSet ( customIconSetFolder ) ;
pIconsManager - > setIconSetsFolder ( customIconSetFolder ) ;
2022-01-27 12:08:57 +08:00
}
2022-12-20 11:01:04 +08:00
pIconsManager - > updateParserIcons (
pSettings - > environment ( ) . iconSet ( ) ,
calIconSize (
pSettings - > environment ( ) . interfaceFont ( ) ,
pSettings - > environment ( ) . interfaceFontSize ( ) ) ) ;
2021-11-02 09:29:35 +08:00
2021-12-16 19:14:14 +08:00
QFont caseEditorFont ( pSettings - > executor ( ) . caseEditorFontName ( ) ) ;
2021-12-17 09:05:01 +08:00
caseEditorFont . setPixelSize ( pointToPixel ( pSettings - > executor ( ) . caseEditorFontSize ( ) ) ) ;
2021-12-15 19:12:16 +08:00
font . setStyleStrategy ( QFont : : PreferAntialias ) ;
ui - > txtProblemCaseInput - > setFont ( caseEditorFont ) ;
2022-03-29 21:41:02 +08:00
ui - > lblProblemCaseInput - > setFont ( caseEditorFont ) ;
2021-12-15 19:12:16 +08:00
ui - > txtProblemCaseOutput - > setFont ( caseEditorFont ) ;
2022-03-29 21:41:02 +08:00
ui - > lblProblemCaseOutput - > setFont ( caseEditorFont ) ;
2021-12-15 19:12:16 +08:00
ui - > txtProblemCaseExpected - > setFont ( caseEditorFont ) ;
2022-03-29 21:41:02 +08:00
ui - > lblProblemCaseExpected - > setFont ( caseEditorFont ) ;
2021-12-15 19:12:16 +08:00
2021-11-02 13:12:36 +08:00
mTcpServer . close ( ) ;
if ( pSettings - > executor ( ) . enableProblemSet ( ) ) {
if ( pSettings - > executor ( ) . enableCompetitiveCompanion ( ) ) {
if ( ! mTcpServer . listen ( QHostAddress : : LocalHost , pSettings - > executor ( ) . competivieCompanionPort ( ) ) ) {
2021-11-04 09:07:06 +08:00
// QMessageBox::critical(nullptr,
// tr("Listen failed"),
2021-11-19 07:52:36 +08:00
// tr("Can't listen to port %1 form Competitive Companion.").arg(10045)
2021-11-04 09:07:06 +08:00
// + "<BR/>"
// +tr("You can turn off competitive companion support in the Problem Set options.")
// + "<BR/>"
// +tr("Or You can choose a different port number and try again."));
2021-11-02 13:12:36 +08:00
}
}
2021-11-02 09:29:35 +08:00
}
2022-03-22 15:44:27 +08:00
showHideInfosTab ( ui - > tabProblemSet , pSettings - > ui ( ) . showProblemSet ( )
& & pSettings - > executor ( ) . enableProblemSet ( ) ) ;
showHideMessagesTab ( ui - > tabProblem , pSettings - > ui ( ) . showProblem ( )
& & pSettings - > executor ( ) . enableProblemSet ( ) ) ;
2023-08-19 18:01:16 +08:00
ui - > cbProblemCaseValidateType - > setCurrentIndex ( ( int ) ( pSettings - > executor ( ) . problemCaseValidateType ( ) ) ) ;
2024-01-18 16:14:36 +08:00
if ( mDebugger ! = nullptr )
ui - > actionInterrupt - > setVisible ( mDebugger - > useDebugServer ( ) ) ;
2021-12-24 09:17:28 +08:00
//icon sets for editors
updateEditorSettings ( ) ;
2021-08-01 23:24:37 +08:00
updateDebuggerSettings ( ) ;
2021-12-21 11:57:23 +08:00
updateActionIcons ( ) ;
2022-02-11 21:53:47 +08:00
//icon sets for files view
2022-12-20 11:01:04 +08:00
pIconsManager - > updateFileSystemIcons (
pSettings - > environment ( ) . iconSet ( ) ,
calIconSize (
pSettings - > environment ( ) . interfaceFont ( ) ,
pSettings - > environment ( ) . interfaceFontSize ( ) ) ) ;
2022-03-11 20:51:33 +08:00
if ( ! mFileSystemModel . rootPath ( ) . isEmpty ( ) & & mFileSystemModel . rootPath ( ) ! = " . " )
setFilesViewRoot ( pSettings - > environment ( ) . currentFolder ( ) ) ;
2022-02-11 21:53:47 +08:00
// for (int i=0;i<ui->cbFilesPath->count();i++) {
// ui->cbFilesPath->setItemIcon(i,pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT));
// }
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
ui - > menuGit - > menuAction ( ) - > setVisible ( pSettings - > vcs ( ) . gitOk ( ) ) ;
2023-08-08 14:41:23 +08:00
# else
ui - > menuGit - > menuAction ( ) - > setVisible ( false ) ;
# endif
2022-05-23 22:36:22 +08:00
stretchExplorerPanel ( ! ui - > tabExplorer - > isShrinked ( ) ) ;
stretchMessagesPanel ( ! ui - > tabMessages - > isShrinked ( ) ) ;
2021-06-18 21:48:40 +08:00
}
2021-09-02 16:35:28 +08:00
void MainWindow : : applyUISettings ( )
{
const Settings : : UI & settings = pSettings - > ui ( ) ;
2023-01-12 16:53:00 +08:00
ui - > chkOpenFileInEditors - > setChecked ( settings . openEditorsWhenReplace ( ) ) ;
2021-09-02 16:35:28 +08:00
restoreGeometry ( settings . mainWindowGeometry ( ) ) ;
restoreState ( settings . mainWindowState ( ) ) ;
2021-11-09 21:22:50 +08:00
ui - > actionTool_Window_Bars - > setChecked ( settings . showToolWindowBars ( ) ) ;
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setVisible ( settings . showToolWindowBars ( ) ) ;
2021-11-09 21:22:50 +08:00
ui - > tabMessages - > setVisible ( settings . showToolWindowBars ( ) ) ;
ui - > actionStatus_Bar - > setChecked ( settings . showStatusBar ( ) ) ;
ui - > statusbar - > setVisible ( settings . showStatusBar ( ) ) ;
ui - > actionProject - > setChecked ( settings . showProject ( ) ) ;
showHideInfosTab ( ui - > tabProject , settings . showProject ( ) ) ;
ui - > actionWatch - > setChecked ( settings . showWatch ( ) ) ;
showHideInfosTab ( ui - > tabWatch , settings . showWatch ( ) ) ;
ui - > actionStructure - > setChecked ( settings . showStructure ( ) ) ;
showHideInfosTab ( ui - > tabStructure , settings . showStructure ( ) ) ;
ui - > actionFiles - > setChecked ( settings . showFiles ( ) ) ;
showHideInfosTab ( ui - > tabFiles , settings . showFiles ( ) ) ;
ui - > actionProblem_Set - > setChecked ( settings . showProblemSet ( ) ) ;
2021-11-19 07:52:36 +08:00
showHideInfosTab ( ui - > tabProblemSet , settings . showProblemSet ( )
& & pSettings - > executor ( ) . enableProblemSet ( ) ) ;
2021-11-09 21:22:50 +08:00
ui - > actionIssues - > setChecked ( settings . showIssues ( ) ) ;
showHideMessagesTab ( ui - > tabIssues , settings . showIssues ( ) ) ;
2022-02-10 12:03:56 +08:00
ui - > actionTools_Output - > setChecked ( settings . showCompileLog ( ) ) ;
showHideMessagesTab ( ui - > tabToolsOutput , settings . showCompileLog ( ) ) ;
2021-11-09 21:22:50 +08:00
ui - > actionDebug_Window - > setChecked ( settings . showDebug ( ) ) ;
showHideMessagesTab ( ui - > tabDebug , settings . showDebug ( ) ) ;
ui - > actionSearch - > setChecked ( settings . showSearch ( ) ) ;
showHideMessagesTab ( ui - > tabSearch , settings . showSearch ( ) ) ;
ui - > actionTODO - > setChecked ( settings . showTODO ( ) ) ;
showHideMessagesTab ( ui - > tabTODO , settings . showTODO ( ) ) ;
ui - > actionBookmark - > setChecked ( settings . showBookmark ( ) ) ;
showHideMessagesTab ( ui - > tabBookmark , settings . showBookmark ( ) ) ;
ui - > actionProblem - > setChecked ( settings . showProblem ( ) ) ;
2021-11-19 07:52:36 +08:00
showHideMessagesTab ( ui - > tabProblem , settings . showProblem ( )
& & pSettings - > executor ( ) . enableProblemSet ( ) ) ;
2022-05-22 14:31:13 +08:00
ui - > tabMessages - > setBeforeShrinkSize ( settings . messagesTabsSize ( ) ) ;
ui - > tabExplorer - > setBeforeShrinkSize ( settings . explorerTabsSize ( ) ) ;
if ( settings . shrinkMessagesTabs ( ) )
ui - > tabMessages - > setShrinkedFlag ( true ) ;
if ( settings . shrinkExplorerTabs ( ) )
ui - > tabExplorer - > setShrinkedFlag ( true ) ;
2021-09-02 16:35:28 +08:00
}
2021-08-31 14:40:41 +08:00
QFileSystemWatcher * MainWindow : : fileSystemWatcher ( )
{
return & mFileSystemWatcher ;
}
2022-05-22 14:31:13 +08:00
void MainWindow : : initDocks ( )
{
ui - > dockExplorer - > setMinimumSize ( 0 , 0 ) ;
ui - > dockMessages - > setMinimumSize ( 0 , 0 ) ;
setDockExplorerToArea ( dockWidgetArea ( ui - > dockExplorer ) ) ;
setDockMessagesToArea ( dockWidgetArea ( ui - > dockMessages ) ) ;
}
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 ( ) ;
}
}
2023-01-22 22:19:19 +08:00
void MainWindow : : setActiveBreakpoint ( QString fileName , int Line , bool setFocus )
2021-07-26 18:22:09 +08:00
{
removeActiveBreakpoints ( ) ;
// Then active the current line in the current file
2023-01-22 22:19:19 +08:00
Editor * e = openFile ( fileName ) ;
2021-07-26 18:22:09 +08:00
if ( e ! = nullptr ) {
e - > setActiveBreakpointFocus ( Line , setFocus ) ;
2023-03-03 17:20:33 +08:00
if ( setFocus ) {
activateWindow ( ) ;
}
} else {
2024-03-11 13:13:53 +08:00
// showCPUInfoDialog();
2021-07-26 18:22:09 +08:00
}
2023-03-03 17:20:33 +08:00
return ;
2021-07-26 18:22:09 +08:00
}
2022-07-04 11:39:06 +08:00
void MainWindow : : updateDPI ( int oldDPI , int /*newDPI*/ )
2022-01-24 18:37:16 +08:00
{
2022-03-02 15:17:09 +08:00
//applySettings();
2022-02-20 22:36:12 +08:00
if ( oldDPI < 1 )
oldDPI = 1 ;
2022-01-24 18:37:16 +08:00
}
2022-02-15 17:22:44 +08:00
void MainWindow : : onFileSaved ( const QString & path , bool inProject )
{
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 21:39:17 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) ) {
2022-02-16 16:27:09 +08:00
QString branch ;
if ( inProject & & mProject & & mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasRepository ( branch ) ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcon ( path ) ;
2022-02-15 21:39:17 +08:00
}
QModelIndex index = mFileSystemModel . index ( path ) ;
if ( index . isValid ( ) ) {
2022-02-16 16:27:09 +08:00
if ( ! inProject ) {
if ( ( isCFile ( path ) | | isHFile ( path ) )
& & ! mFileSystemModelIconProvider . VCSRepository ( ) - > isFileInRepository ( path ) ) {
2022-02-25 11:07:30 +08:00
QString output ;
mFileSystemModelIconProvider . VCSRepository ( ) - > add ( extractRelativePath ( mFileSystemModelIconProvider . VCSRepository ( ) - > folder ( ) , path ) , output ) ;
2022-02-16 16:27:09 +08:00
}
}
2022-02-21 09:48:04 +08:00
// qDebug()<<"update icon provider";
2022-02-15 21:39:17 +08:00
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
ui - > treeFiles - > update ( index ) ;
}
2022-02-15 17:22:44 +08:00
}
2023-08-08 14:41:23 +08:00
# endif
2022-08-24 17:05:16 +08:00
//updateForEncodingInfo();
2022-02-15 17:22:44 +08:00
}
2022-12-20 11:01:04 +08:00
int MainWindow : : calIconSize ( const QString & fontName , int fontPointSize )
{
QFont font ( fontName , fontPointSize ) ;
QFontMetrics metrics ( font ) ;
return metrics . ascent ( ) ;
}
2023-02-26 08:31:13 +08:00
void MainWindow : : hideAllSearchDialogs ( )
{
if ( mSearchDialog )
mSearchDialog - > hide ( ) ;
if ( mSearchInFilesDialog )
mSearchInFilesDialog - > hide ( ) ;
}
2022-11-11 21:20:57 +08:00
void MainWindow : : prepareSearchDialog ( )
{
if ( ! mSearchDialog )
mSearchDialog = new SearchDialog ( this ) ;
}
2023-02-26 08:31:13 +08:00
void MainWindow : : prepareSearchInFilesDialog ( )
{
if ( mSearchInFilesDialog = = nullptr ) {
mSearchInFilesDialog = new SearchInFileDialog ( this ) ;
}
}
2021-07-26 00:22:08 +08:00
void MainWindow : : updateAppTitle ( )
{
2021-07-26 11:47:54 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
2022-10-24 10:58:30 +08:00
updateAppTitle ( e ) ;
}
void MainWindow : : updateAppTitle ( const Editor * e )
{
QString appName = tr ( " Red Panda C++ " ) ;
2024-03-03 17:32:10 +08:00
# ifdef APP_VERSION_SUFFIX
appName + = tr ( " %1 Version " ) . arg ( APP_VERSION_SUFFIX ) ;
# endif
2021-07-26 11:47:54 +08:00
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 ( ) ) {
2021-08-29 10:14:07 +08:00
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Debugging " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-08-29 10:14:07 +08:00
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 ( ) ) {
2021-08-29 10:14:07 +08:00
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Running " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-08-29 10:14:07 +08:00
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 ( ) ) {
2021-08-29 10:14:07 +08:00
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Compiling " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-08-29 10:14:07 +08:00
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 {
2021-08-29 10:14:07 +08:00
this - > setWindowTitle ( QString ( " %1 - %2 %3 " )
2022-01-05 09:08:44 +08:00
. arg ( str , appName , REDPANDA_CPP_VERSION ) ) ;
2021-08-29 10:14:07 +08:00
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 ,
2022-01-05 09:08:44 +08:00
tr ( " Debugging " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
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 ,
2022-01-05 09:08:44 +08:00
tr ( " Running " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
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 ,
2022-01-05 09:08:44 +08:00
tr ( " Compiling " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Compiling " ) , appName ) ) ;
} else {
setWindowTitle ( QString ( " %1 - %2 %3 " )
2022-01-05 09:08:44 +08:00
. arg ( str , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
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 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Debugging " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Debugging " ) , appName ) ) ;
} else if ( mCompilerManager - > running ( ) ) {
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Running " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Running " ) , appName ) ) ;
} else if ( mCompilerManager - > compiling ( ) ) {
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2022-01-05 09:08:44 +08:00
. arg ( str , tr ( " Compiling " ) , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Compiling " ) , appName ) ) ;
} else {
this - > setWindowTitle ( QString ( " %1 - %2 %3 " )
2022-01-05 09:08:44 +08:00
. arg ( str , appName , REDPANDA_CPP_VERSION ) ) ;
2021-09-11 11:42:20 +08:00
app - > setApplicationName ( QString ( " %1 - %2 " )
. arg ( str , appName ) ) ;
}
} else {
2022-01-05 09:08:44 +08:00
setWindowTitle ( QString ( " %1 %2 " ) . arg ( appName , REDPANDA_CPP_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 )
{
2021-11-25 23:41:40 +08:00
if ( ! pSettings - > debugger ( ) . enableDebugConsole ( ) )
return ;
2021-07-26 11:47:54 +08:00
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-09-29 22:55:53 +08:00
ui - > txtEvalOutput - > moveCursor ( QTextCursor : : Start ) ;
2021-08-01 23:24:37 +08:00
}
2021-08-02 10:08:25 +08:00
void MainWindow : : rebuildOpenedFileHisotryMenu ( )
{
mMenuRecentFiles - > clear ( ) ;
2021-09-17 21:33:19 +08:00
mMenuRecentProjects - > clear ( ) ;
2022-10-17 23:23:05 +08:00
if ( mVisitHistoryManager - > files ( ) . count ( ) = = 0 ) {
2021-08-02 10:08:25 +08:00
mMenuRecentFiles - > setEnabled ( false ) ;
} else {
mMenuRecentFiles - > setEnabled ( true ) ;
2022-10-17 23:23:05 +08:00
foreach ( const PVisitRecord & record , mVisitHistoryManager - > files ( ) ) {
QString filename = record - > filename ;
2022-10-10 18:05:18 +08:00
//menu takes the ownership
2021-10-08 00:06:41 +08:00
QAction * action = new QAction ( filename , mMenuRecentFiles ) ;
2022-10-17 23:23:05 +08:00
connect ( action , & QAction : : triggered , [ filename , this ] ( bool ) {
2021-11-08 21:19:48 +08:00
openFile ( filename ) ;
2021-08-02 10:08:25 +08:00
} ) ;
2021-10-08 00:06:41 +08:00
mMenuRecentFiles - > addAction ( action ) ;
2021-08-02 10:08:25 +08:00
}
2022-02-23 13:17:57 +08:00
mMenuRecentFiles - > addSeparator ( ) ;
2022-10-10 18:05:18 +08:00
//menu takes the ownership
2022-02-23 13:17:57 +08:00
QAction * action = new QAction ( tr ( " Clear History " ) , mMenuRecentFiles ) ;
2022-10-17 23:23:05 +08:00
connect ( action , & QAction : : triggered , [ this ] ( bool ) {
mVisitHistoryManager - > clearFiles ( ) ;
2022-02-23 13:17:57 +08:00
} ) ;
mMenuRecentFiles - > addAction ( action ) ;
2021-08-02 10:08:25 +08:00
}
2021-09-17 21:33:19 +08:00
2022-10-17 23:23:05 +08:00
if ( mVisitHistoryManager - > projects ( ) . count ( ) = = 0 ) {
2021-09-17 21:33:19 +08:00
mMenuRecentProjects - > setEnabled ( false ) ;
} else {
mMenuRecentProjects - > setEnabled ( true ) ;
2022-10-17 23:23:05 +08:00
foreach ( const PVisitRecord & record , mVisitHistoryManager - > projects ( ) ) {
QString filename = record - > filename ;
2022-10-10 18:05:18 +08:00
//menu takes the ownership
2021-10-08 00:06:41 +08:00
QAction * action = new QAction ( filename , mMenuRecentProjects ) ;
2022-10-17 23:23:05 +08:00
connect ( action , & QAction : : triggered , [ filename , this ] ( bool ) {
2022-11-07 21:44:12 +08:00
openProject ( filename ) ;
2021-09-17 21:33:19 +08:00
} ) ;
2021-10-08 00:06:41 +08:00
mMenuRecentProjects - > addAction ( action ) ;
2021-09-17 21:33:19 +08:00
}
2022-02-23 13:17:57 +08:00
mMenuRecentProjects - > addSeparator ( ) ;
2022-10-10 18:05:18 +08:00
//menu takes the ownership
2022-02-23 13:17:57 +08:00
QAction * action = new QAction ( tr ( " Clear History " ) , mMenuRecentProjects ) ;
2022-10-17 23:23:05 +08:00
connect ( action , & QAction : : triggered , [ this ] ( bool ) {
mVisitHistoryManager - > clearProjects ( ) ;
2022-02-23 13:17:57 +08:00
} ) ;
mMenuRecentProjects - > addAction ( action ) ;
2021-09-17 21:33:19 +08:00
}
2021-08-02 10:08:25 +08:00
}
2021-08-23 17:27:17 +08:00
void MainWindow : : updateClassBrowserForEditor ( Editor * editor )
{
2022-11-07 11:24:23 +08:00
2022-10-23 15:22:26 +08:00
if ( mQuitting ) {
2022-11-07 11:24:23 +08:00
mClassBrowserModel . beginUpdate ( ) ;
2021-08-23 17:27:17 +08:00
mClassBrowserModel . setParser ( nullptr ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
2022-11-07 11:24:23 +08:00
mClassBrowserModel . endUpdate ( ) ;
2021-08-23 17:27:17 +08:00
return ;
}
2022-10-23 15:22:26 +08:00
if ( editor ) {
if ( ( mClassBrowserModel . currentFile ( ) = = editor - > filename ( ) )
& & ( mClassBrowserModel . parser ( ) = = editor - > parser ( ) ) )
return ;
if ( mClassBrowserModel . parser ( ) = = editor - > parser ( ) & & mClassBrowserModel . classBrowserType ( ) = = ProjectClassBrowserType : : WholeProject ) {
mClassBrowserModel . setCurrentFile ( editor - > filename ( ) ) ;
2021-08-23 17:27:17 +08:00
return ;
2022-10-23 15:22:26 +08:00
}
2021-08-23 17:27:17 +08:00
2022-10-23 18:39:15 +08:00
if ( editor - > inProject ( ) & & ! mProject ) {
//project is in creation
mClassBrowserModel . setCurrentFile ( editor - > filename ( ) ) ;
return ;
}
2022-10-23 15:22:26 +08:00
mClassBrowserModel . beginUpdate ( ) ;
2021-08-23 17:27:17 +08:00
mClassBrowserModel . setParser ( editor - > parser ( ) ) ;
2022-10-23 15:22:26 +08:00
if ( editor - > inProject ( ) ) {
mClassBrowserModel . setClassBrowserType ( mProject - > options ( ) . classBrowserType ) ;
2022-10-23 21:42:11 +08:00
} else {
2022-10-23 15:22:26 +08:00
mClassBrowserModel . setClassBrowserType ( ProjectClassBrowserType : : CurrentFile ) ;
2022-10-23 21:42:11 +08:00
}
2021-08-23 17:27:17 +08:00
mClassBrowserModel . setCurrentFile ( editor - > filename ( ) ) ;
2022-10-23 15:22:26 +08:00
mClassBrowserModel . endUpdate ( ) ;
} else if ( mProject ) {
if ( mClassBrowserModel . parser ( ) = = mProject - > cppParser ( ) ) {
2022-11-07 11:24:23 +08:00
mClassBrowserModel . beginUpdate ( ) ;
2022-10-23 15:22:26 +08:00
mClassBrowserModel . setCurrentFile ( " " ) ;
2022-11-07 11:24:23 +08:00
mClassBrowserModel . endUpdate ( ) ;
2022-10-23 15:22:26 +08:00
return ;
}
mClassBrowserModel . beginUpdate ( ) ;
mClassBrowserModel . setParser ( mProject - > cppParser ( ) ) ;
mClassBrowserModel . setClassBrowserType ( mProject - > options ( ) . classBrowserType ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
mClassBrowserModel . endUpdate ( ) ;
} else {
2022-11-07 11:24:23 +08:00
mClassBrowserModel . beginUpdate ( ) ;
2022-10-23 15:22:26 +08:00
mClassBrowserModel . setParser ( nullptr ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
2022-11-07 11:24:23 +08:00
mClassBrowserModel . endUpdate ( ) ;
2022-10-23 15:22:26 +08:00
return ;
2021-08-23 17:27:17 +08:00
}
}
2021-08-30 22:05:45 +08:00
void MainWindow : : resetAutoSaveTimer ( )
{
if ( pSettings - > editor ( ) . enableAutoSave ( ) ) {
2021-11-12 12:40:47 +08:00
mAutoSaveTimer . stop ( ) ;
2021-08-30 22:05:45 +08:00
//minute to milliseconds
mAutoSaveTimer . start ( pSettings - > editor ( ) . autoSaveInterval ( ) * 60 * 1000 ) ;
2021-11-12 12:40:47 +08:00
onAutoSaveTimeout ( ) ;
2021-08-30 22:05:45 +08:00
} else {
mAutoSaveTimer . stop ( ) ;
}
}
2021-10-06 23:19:18 +08:00
void MainWindow : : updateShortcuts ( )
{
ShortcutManager manager ;
manager . load ( ) ;
2022-06-13 15:44:59 +08:00
manager . applyTo ( listShortCutableActions ( ) ) ;
2021-10-06 23:19:18 +08:00
}
2021-08-01 10:00:27 +08:00
QPlainTextEdit * MainWindow : : txtLocals ( )
{
return ui - > txtLocals ;
}
2021-12-24 23:18:20 +08:00
QMenuBar * MainWindow : : menuBar ( ) const
{
return ui - > menubar ;
}
2022-10-24 10:58:30 +08:00
void MainWindow : : updateStatusbarForLineCol ( const Editor * e , bool clear )
2021-06-07 11:02:03 +08:00
{
2022-03-12 17:37:53 +08:00
if ( ! clear & & e ! = nullptr ) {
2023-10-18 14:37:31 +08:00
QString msg ;
if ( e - > selAvail ( ) ) {
2024-02-26 15:15:26 +08:00
msg = tr ( " Line: %1/%2 Char: %3/%4 Sel:%5 " )
. arg ( e - > caretY ( ) )
. arg ( e - > document ( ) - > count ( ) )
. arg ( e - > caretX ( ) )
. arg ( e - > lineText ( ) . length ( ) )
. arg ( e - > selText ( ) . length ( ) ) ;
2023-10-18 14:37:31 +08:00
} else {
2024-02-26 15:15:26 +08:00
msg = tr ( " Line: %1/%2 Char: %3/%4 " )
. arg ( e - > caretY ( ) )
. arg ( e - > document ( ) - > count ( ) )
. arg ( e - > caretX ( ) )
. arg ( e - > lineText ( ) . length ( ) ) ;
2023-10-18 14:37:31 +08:00
}
2021-06-12 22:36:23 +08:00
mFileInfoStatus - > setText ( msg ) ;
} else {
mFileInfoStatus - > setText ( " " ) ;
}
}
2022-03-12 17:37:53 +08:00
void MainWindow : : updateForStatusbarModeInfo ( bool clear )
2021-06-12 22:36:23 +08:00
{
Editor * e = mEditorList - > getEditor ( ) ;
2022-10-24 10:58:30 +08:00
updateForStatusbarModeInfo ( e , clear ) ;
}
void MainWindow : : updateForStatusbarModeInfo ( const Editor * e , bool clear )
{
2022-03-12 17:37:53 +08:00
if ( ! clear & & e ! = nullptr ) {
2021-06-12 22:36:23 +08:00
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
}
2022-10-24 20:01:46 +08:00
void MainWindow : : setProjectCurrentFile ( const QString & filename )
{
if ( ! mProject )
return ;
PProjectUnit unit = mProject - > findUnit ( filename ) ;
if ( ! unit )
return ;
QModelIndex index = mProject - > model ( ) - > getNodeIndex ( unit - > node ( ) . get ( ) ) ;
if ( index . isValid ( ) ) {
2022-12-06 22:51:59 +08:00
index = mProjectProxyModel - > mapFromSource ( index ) ;
2022-10-24 20:01:46 +08:00
ui - > projectView - > expand ( index ) ;
ui - > projectView - > setCurrentIndex ( index ) ;
}
}
2021-04-11 21:33:08 +08:00
void MainWindow : : openFiles ( const QStringList & files )
{
2023-08-11 13:49:09 +08:00
mOpeningFiles = true ;
auto action = finally ( [ this ] {
mOpeningFiles = false ;
} ) ;
2021-04-11 21:33:08 +08:00
mEditorList - > beginUpdate ( ) ;
2021-11-08 21:19:48 +08:00
mOpenningFiles = true ;
2021-04-12 00:00:29 +08:00
auto end = finally ( [ this ] {
this - > mEditorList - > endUpdate ( ) ;
2021-11-08 21:19:48 +08:00
mOpenningFiles = false ;
2021-04-12 00:00:29 +08:00
} ) ;
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
2022-08-24 17:05:16 +08:00
for ( int i = 0 ; i < files . length ( ) - 1 ; i + + ) {
openFile ( files [ i ] , false ) ;
}
if ( files . length ( ) > 0 ) {
openFile ( files . last ( ) , true ) ;
2021-04-11 21:33:08 +08:00
}
mEditorList - > endUpdate ( ) ;
2022-08-24 17:05:16 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
2023-08-11 13:49:09 +08:00
if ( e ) {
e - > reparse ( false ) ;
e - > checkSyntaxInBack ( ) ;
e - > reparseTodo ( ) ;
2022-08-24 17:05:16 +08:00
e - > activate ( ) ;
2023-08-11 13:49:09 +08:00
}
2021-04-11 21:33:08 +08:00
}
2023-06-16 17:57:24 +08:00
Editor * MainWindow : : openFile ( QString filename , bool activate , QTabWidget * page )
2021-04-11 21:33:08 +08:00
{
2023-01-24 10:21:19 +08:00
if ( ! fileExists ( filename ) )
2022-10-18 23:22:29 +08:00
return nullptr ;
2023-06-16 17:57:24 +08:00
QFileInfo info = QFileInfo ( filename ) ;
if ( info . isAbsolute ( ) )
filename = info . absoluteFilePath ( ) ;
2021-04-29 20:54:44 +08:00
Editor * editor = mEditorList - > getOpenedEditorByFilename ( filename ) ;
2021-04-11 21:33:08 +08:00
if ( editor ! = nullptr ) {
2022-08-24 17:05:16 +08:00
if ( activate ) {
editor - > activate ( ) ;
}
2022-10-17 23:23:05 +08:00
return editor ;
2021-04-11 21:33:08 +08:00
}
2021-08-31 14:40:41 +08:00
try {
2022-10-17 23:23:05 +08:00
Editor * oldEditor = nullptr ;
if ( mEditorList - > pageCount ( ) = = 1 ) {
oldEditor = mEditorList - > getEditor ( 0 ) ;
if ( ! oldEditor - > isNew ( ) | | oldEditor - > modified ( ) ) {
oldEditor = nullptr ;
}
}
//mVisitHistoryManager->removeFile(filename);
2022-01-18 12:41:11 +08:00
PProjectUnit unit ;
if ( mProject ) {
2022-10-01 08:54:44 +08:00
unit = mProject - > findUnit ( filename ) ;
2022-01-18 12:41:11 +08:00
}
bool inProject = ( mProject & & unit ) ;
2022-03-12 17:37:53 +08:00
QByteArray encoding = unit ? unit - > encoding ( ) :
( pSettings - > editor ( ) . autoDetectFileEncoding ( ) ? ENCODING_AUTO_DETECT : pSettings - > editor ( ) . defaultEncoding ( ) ) ;
2022-10-09 22:19:18 +08:00
Project * pProject = ( inProject ? mProject . get ( ) : nullptr ) ;
2023-02-07 10:46:06 +08:00
if ( pProject & & encoding = = ENCODING_PROJECT )
encoding = pProject - > options ( ) . encoding ;
2022-01-24 09:24:43 +08:00
editor = mEditorList - > newEditor ( filename , encoding ,
2022-10-09 22:19:18 +08:00
pProject , false , page ) ;
2022-02-01 16:17:28 +08:00
// if (mProject) {
// mProject->associateEditorToUnit(editor,unit);
// }
2022-08-24 17:05:16 +08:00
if ( activate ) {
editor - > activate ( ) ;
}
2022-10-17 23:23:05 +08:00
if ( mEditorList - > pageCount ( ) > 1 & & oldEditor )
mEditorList - > closeEditor ( oldEditor ) ;
2022-08-24 17:05:16 +08:00
// editor->activate();
2022-10-17 23:23:05 +08:00
return editor ;
2021-08-31 14:40:41 +08:00
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
2022-10-17 23:23:05 +08:00
return nullptr ;
2021-04-11 21:33:08 +08:00
}
2023-06-16 17:57:24 +08:00
void MainWindow : : openProject ( QString filename , bool openFiles )
2021-09-11 11:42:20 +08:00
{
2023-08-11 13:49:09 +08:00
mOpeningProject = true ;
auto action = finally ( [ this ] {
mOpeningProject = false ;
} ) ;
2021-09-11 11:42:20 +08:00
if ( ! fileExists ( filename ) ) {
return ;
}
2023-06-16 17:57:24 +08:00
QFileInfo info = QFileInfo ( filename ) ;
if ( info . isAbsolute ( ) )
filename = info . absoluteFilePath ( ) ;
2022-10-17 23:23:05 +08:00
Editor * oldEditor = nullptr ;
2021-09-11 11:42:20 +08:00
if ( mProject ) {
2022-10-17 23:23:05 +08:00
if ( mProject - > filename ( ) = = filename )
return ;
ProjectAlreadyOpenDialog dlg ;
if ( dlg . exec ( ) ! = QDialog : : Accepted )
return ;
if ( dlg . openType ( ) = = ProjectAlreadyOpenDialog : : OpenType : : ThisWindow ) {
2021-09-11 11:42:20 +08:00
closeProject ( false ) ;
} else {
2022-10-17 23:23:05 +08:00
QProcess process ;
process . setProgram ( QApplication : : instance ( ) - > applicationFilePath ( ) ) ;
process . setWorkingDirectory ( QDir : : currentPath ( ) ) ;
QStringList args ;
args . append ( " -ns " ) ;
args . append ( filename ) ;
process . setArguments ( args ) ;
process . startDetached ( ) ;
2021-09-11 11:42:20 +08:00
return ;
}
2022-10-17 23:23:05 +08:00
} else {
if ( mEditorList - > pageCount ( ) = = 1 ) {
oldEditor = mEditorList - > getEditor ( 0 ) ;
if ( ! oldEditor - > isNew ( ) | | oldEditor - > modified ( ) ) {
oldEditor = nullptr ;
}
}
2021-09-11 11:42:20 +08:00
}
2022-10-17 23:23:05 +08:00
//ui->tabProject->setVisible(true);
//stretchExplorerPanel(true);
if ( openFiles )
ui - > tabExplorer - > setCurrentWidget ( ui - > tabProject ) ;
2021-09-11 11:42:20 +08:00
// Only update class browser once
mClassBrowserModel . beginUpdate ( ) ;
2022-10-11 21:51:33 +08:00
mProject = Project : : load ( filename , mEditorList , & mFileSystemWatcher ) ;
updateProjectView ( ) ;
ui - > projectView - > expand (
mProjectProxyModel - > mapFromSource (
mProject - > model ( ) - > rootIndex ( ) ) ) ;
2022-10-17 23:23:05 +08:00
//mVisitHistoryManager->removeProject(filename);
2021-09-11 11:42:20 +08:00
2022-10-11 21:51:33 +08:00
// // if project manager isn't open then open it
// if not devData.ShowLeftPages then
// actProjectManager.Execute;
//checkForDllProfiling();
2021-09-11 11:42:20 +08:00
2022-10-11 21:51:33 +08:00
//parse the project
// UpdateClassBrowsing;
2022-10-09 22:19:18 +08:00
2022-10-11 21:51:33 +08:00
scanActiveProject ( true ) ;
2021-09-11 11:42:20 +08:00
2022-10-11 21:51:33 +08:00
mBookmarkModel - > setIsForProject ( true ) ;
mBookmarkModel - > loadProjectBookmarks (
changeFileExt ( mProject - > filename ( ) , PROJECT_BOOKMARKS_EXT ) ,
mProject - > directory ( ) ) ;
2022-10-16 23:10:57 +08:00
mDebugger - > setIsForProject ( true ) ;
mDebugger - > loadForProject (
changeFileExt ( mProject - > filename ( ) , PROJECT_DEBUG_EXT ) ,
mProject - > directory ( ) ) ;
2022-10-22 23:29:12 +08:00
mTodoModel . setIsForProject ( true ) ;
2022-11-07 21:44:12 +08:00
if ( pSettings - > editor ( ) . parseTodos ( ) )
mTodoParser - > parseFiles ( mProject - > unitFiles ( ) ) ;
2021-09-17 09:56:52 +08:00
2022-10-11 21:51:33 +08:00
if ( openFiles ) {
PProjectUnit unit = mProject - > doAutoOpen ( ) ;
setProjectViewCurrentUnit ( unit ) ;
}
//update editor's inproject flag
foreach ( PProjectUnit unit , mProject - > unitList ( ) ) {
Editor * e = mEditorList - > getOpenedEditorByFilename ( unit - > fileName ( ) ) ;
mProject - > associateEditorToUnit ( e , unit ) ;
if ( e )
e - > resetBookmarks ( ) ;
}
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
checkSyntaxInBack ( e ) ;
2021-09-11 11:42:20 +08:00
}
2022-10-11 21:51:33 +08:00
updateAppTitle ( ) ;
updateCompilerSet ( ) ;
updateClassBrowserForEditor ( e ) ;
mClassBrowserModel . endUpdate ( ) ;
2022-10-17 23:23:05 +08:00
if ( oldEditor )
mEditorList - > closeEditor ( oldEditor ) ;
2022-11-07 21:44:12 +08:00
setupSlotsForProject ( ) ;
2022-08-24 17:05:16 +08:00
//updateForEncodingInfo();
2021-09-11 11:42:20 +08:00
}
2021-10-24 17:31:20 +08:00
void MainWindow : : changeOptions ( const QString & widgetName , const QString & groupName )
{
PSettingsDialog settingsDialog = SettingsDialog : : optionDialog ( ) ;
if ( ! groupName . isEmpty ( ) ) {
settingsDialog - > setCurrentWidget ( widgetName , groupName ) ;
}
settingsDialog - > exec ( ) ;
if ( settingsDialog - > appShouldQuit ( ) ) {
mShouldRemoveAllSettings = true ;
close ( ) ;
return ;
}
2023-01-19 11:08:32 +08:00
if ( mProject ) {
2022-03-22 19:08:26 +08:00
scanActiveProject ( true ) ;
2021-10-24 17:31:20 +08:00
}
2023-01-19 11:08:32 +08:00
reparseNonProjectEditors ( ) ;
// Editor *e = mEditorList->getEditor();
// if (mProject && !e) {
// scanActiveProject(true);
// } else if (mProject && e && e->inProject()) {
// scanActiveProject(true);
// } else if (e) {
// reparseNonProjectEditors();
// }
2021-10-24 17:31:20 +08:00
}
2023-04-02 22:53:02 +08:00
void MainWindow : : changeProjectOptions ( const QString & widgetName , const QString & groupName )
{
if ( ! mProject )
return ;
// int oldCompilerSet = mProject->options().compilerSet;
QString oldName = mProject - > name ( ) ;
PSettingsDialog dialog = SettingsDialog : : projectOptionDialog ( ) ;
if ( ! groupName . isEmpty ( ) ) {
dialog - > setCurrentWidget ( widgetName , groupName ) ;
}
dialog - > exec ( ) ;
updateCompilerSet ( ) ;
}
2021-04-18 11:41:41 +08:00
void MainWindow : : updateCompilerSet ( )
2022-12-17 17:20:33 +08:00
{
updateCompilerSet ( mEditorList - > getEditor ( ) ) ;
}
void MainWindow : : updateCompilerSet ( const Editor * e )
2021-04-18 11:41:41 +08:00
{
2021-09-19 14:28:30 +08:00
mCompilerSet - > blockSignals ( true ) ;
2021-04-18 11:41:41 +08:00
mCompilerSet - > clear ( ) ;
2022-03-11 20:51:33 +08:00
for ( size_t i = 0 ; i < pSettings - > compilerSets ( ) . size ( ) ; i + + ) {
mCompilerSet - > addItem ( pSettings - > compilerSets ( ) . getSet ( i ) - > name ( ) ) ;
2021-04-18 11:41:41 +08:00
}
2021-09-11 11:42:20 +08:00
int index = pSettings - > compilerSets ( ) . defaultIndex ( ) ;
if ( mProject ) {
if ( ! e | | e - > inProject ( ) ) {
index = mProject - > options ( ) . compilerSet ;
2024-03-04 16:01:23 +08:00
} else if ( e - > syntaxer ( ) - > language ( ) = = QSynedit : : ProgrammingLanguage : : Makefile
2022-12-11 19:47:43 +08:00
& & mProject - > directory ( ) = = extractFileDir ( e - > filename ( ) ) ) {
index = mProject - > options ( ) . compilerSet ;
2021-09-11 11:42:20 +08:00
}
2022-12-11 19:47:43 +08:00
2022-10-26 08:45:18 +08:00
if ( index < 0 | | index > = mCompilerSet - > count ( ) ) {
index = pSettings - > compilerSets ( ) . defaultIndex ( ) ;
}
2021-04-18 11:41:41 +08:00
}
mCompilerSet - > setCurrentIndex ( index ) ;
2021-09-19 14:28:30 +08:00
mCompilerSet - > blockSignals ( false ) ;
mCompilerSet - > update ( ) ;
2021-04-18 11:41:41 +08:00
}
2021-08-01 23:24:37 +08:00
void MainWindow : : updateDebuggerSettings ( )
{
2021-12-16 19:14:14 +08:00
QFont font ( pSettings - > debugger ( ) . fontName ( ) ) ;
2021-12-17 09:05:01 +08:00
font . setPixelSize ( pointToPixel ( pSettings - > debugger ( ) . fontSize ( ) ) ) ;
2021-11-06 19:31:16 +08:00
ui - > debugConsole - > setFont ( font ) ;
2022-01-11 22:29:03 +08:00
ui - > tblMemoryView - > setFont ( font ) ;
//ui->txtMemoryView->setFont(font);
2021-11-06 19:31:16 +08:00
ui - > txtLocals - > setFont ( font ) ;
2021-11-25 10:18:21 +08:00
int idx = findTabIndex ( ui - > debugViews , ui - > tabDebugConsole ) ;
if ( idx > = 0 ) {
if ( ! pSettings - > debugger ( ) . enableDebugConsole ( ) ) {
ui - > debugViews - > removeTab ( idx ) ;
}
} else {
if ( pSettings - > debugger ( ) . enableDebugConsole ( ) ) {
ui - > debugViews - > insertTab ( 0 , ui - > tabDebugConsole , tr ( " Debug Console " ) ) ;
}
}
2021-08-01 23:24:37 +08:00
}
2021-12-21 11:57:23 +08:00
void MainWindow : : updateActionIcons ( )
{
2022-12-20 11:01:04 +08:00
int size = calIconSize (
pSettings - > environment ( ) . interfaceFont ( ) ,
pSettings - > environment ( ) . interfaceFontSize ( ) ) * pSettings - > environment ( ) . iconZoomFactor ( ) ;
2021-12-24 09:17:28 +08:00
pIconsManager - > updateActionIcons ( pSettings - > environment ( ) . iconSet ( ) , size ) ;
2021-12-21 11:57:23 +08:00
QSize iconSize ( size , size ) ;
ui - > toolbarMain - > setIconSize ( iconSize ) ;
ui - > toolbarCode - > setIconSize ( iconSize ) ;
ui - > toolbarCompile - > setIconSize ( iconSize ) ;
ui - > toolbarDebug - > setIconSize ( iconSize ) ;
2023-07-03 14:06:26 +08:00
ui - > toolbarCompilerSet - > setIconSize ( iconSize ) ;
2021-12-22 18:55:36 +08:00
for ( QToolButton * btn : mClassBrowserToolbar - > findChildren < QToolButton * > ( ) ) {
btn - > setIconSize ( iconSize ) ;
}
2022-02-11 20:19:48 +08:00
for ( QToolButton * btn : ui - > panelFiles - > findChildren < QToolButton * > ( ) ) {
2021-12-22 18:55:36 +08:00
btn - > setIconSize ( iconSize ) ;
}
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setIconSize ( iconSize ) ;
2021-12-22 18:55:36 +08:00
ui - > tabMessages - > setIconSize ( iconSize ) ;
2021-12-22 19:54:06 +08:00
ui - > EditorTabsLeft - > setIconSize ( iconSize ) ;
ui - > EditorTabsRight - > setIconSize ( iconSize ) ;
2021-12-21 19:13:47 +08:00
2021-12-23 00:24:52 +08:00
ui - > actionNew - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_NEW ) ) ;
ui - > actionNew_Project - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_NEW ) ) ;
ui - > actionOpen - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_OPEN ) ) ;
2022-01-28 16:13:20 +08:00
ui - > actionOpen_Folder - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_OPEN_FOLDER ) ) ;
2021-12-23 00:24:52 +08:00
ui - > actionSave - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_SAVE ) ) ;
ui - > actionSaveAs - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_SAVE_AS ) ) ;
ui - > actionSaveAll - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_SAVE_ALL ) ) ;
ui - > actionClose - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_CLOSE ) ) ;
ui - > actionClose_Project - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_CLOSE ) ) ;
ui - > actionClose_All - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_CLOSE_ALL ) ) ;
2023-06-13 17:16:09 +08:00
ui - > actionClose_Others - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_CLOSE_ALL ) ) ;
2021-12-23 00:24:52 +08:00
ui - > actionPrint - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_PRINT ) ) ;
ui - > actionUndo - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_UNDO ) ) ;
ui - > actionRedo - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_REDO ) ) ;
ui - > actionCut - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_CUT ) ) ;
ui - > actionCopy - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_COPY ) ) ;
ui - > actionPaste - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_PASTE ) ) ;
ui - > actionIndent - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_INDENT ) ) ;
ui - > actionUnIndent - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_UNINDENT ) ) ;
ui - > actionFind - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SEARCH ) ) ;
ui - > actionReplace - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_REPLACE ) ) ;
ui - > actionFind_in_files - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SEARCH_IN_FILES ) ) ;
ui - > actionBack - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_BACK ) ) ;
ui - > actionForward - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_FORWARD ) ) ;
ui - > actionAdd_bookmark - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_ADD_BOOKMARK ) ) ;
ui - > actionRemove_Bookmark - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_REMOVE_BOOKMARK ) ) ;
ui - > actionReformat_Code - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_REFORMAT ) ) ;
ui - > actionProject_New_File - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_NEW_FILE ) ) ;
ui - > actionAdd_to_project - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_ADD_FILE ) ) ;
ui - > actionRemove_from_project - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_REMOVE_FILE ) ) ;
ui - > actionProject_Open_Folder_In_Explorer - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_FOLDER ) ) ;
ui - > actionProject_Open_In_Terminal - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_TERM ) ) ;
ui - > actionMakeClean - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
ui - > actionProject_options - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_PROPERTIES ) ) ;
ui - > actionCompile - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_COMPILE ) ) ;
ui - > actionRun - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_RUN ) ) ;
ui - > actionRebuild - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_REBUILD ) ) ;
ui - > actionRun_Parameters - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_OPTIONS ) ) ;
ui - > actionDebug - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_DEBUG ) ) ;
2021-12-27 10:59:04 +08:00
ui - > actionInterrupt - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_INTERRUPT ) ) ;
2021-12-23 00:24:52 +08:00
ui - > actionStep_Over - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_STEP_OVER ) ) ;
ui - > actionStep_Into - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_STEP_INTO ) ) ;
ui - > actionStep_Out - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_STEP_OUT ) ) ;
ui - > actionRun_To_Cursor - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_RUN_TO_CURSOR ) ) ;
ui - > actionContinue - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_CONTINUE ) ) ;
ui - > actionStop_Execution - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_STOP ) ) ;
ui - > actionAdd_Watch - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_ADD_WATCH ) ) ;
ui - > actionRemove_Watch - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_REMOVE_WATCH ) ) ;
ui - > actionRemove_All_Watches - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
2022-05-06 15:48:17 +08:00
ui - > actionCompiler_Options - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_COMPILE_OPTIONS ) ) ;
2021-12-23 00:24:52 +08:00
ui - > actionOptions - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_GEAR ) ) ;
ui - > actionMaximize_Editor - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_MAXIMUM ) ) ;
ui - > actionNext_Editor - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_FORWARD ) ) ;
ui - > actionPrevious_Editor - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_BACK ) ) ;
ui - > actionAbout - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_HELP_ABOUT ) ) ;
2021-12-22 11:07:56 +08:00
//editor context menu
2021-12-23 00:24:52 +08:00
ui - > actionOpen_Containing_Folder - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_FOLDER ) ) ;
ui - > actionOpen_Terminal - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_TERM ) ) ;
ui - > actionFile_Properties - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_PROPERTIES ) ) ;
ui - > actionLocate_in_Files_View - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_LOCATE ) ) ;
2021-12-22 11:07:56 +08:00
//bookmark context menu
2021-12-23 00:24:52 +08:00
mBookmark_Remove - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_REMOVE_BOOKMARK ) ) ;
mBookmark_RemoveAll - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
2021-12-22 11:07:56 +08:00
//issues context menu
2021-12-23 00:24:52 +08:00
mTableIssuesCopyAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_COPY ) ) ;
mTableIssuesClearAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
2021-12-22 11:07:56 +08:00
//search context menu
2021-12-23 00:24:52 +08:00
mSearchViewClearAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CROSS ) ) ;
mSearchViewClearAllAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
2021-12-22 11:07:56 +08:00
//breakpoint context menu
//mBreakpointViewPropertyAction
2021-12-23 00:24:52 +08:00
mBreakpointViewRemoveAllAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
mBreakpointViewRemoveAction - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CROSS ) ) ;
2021-12-22 11:07:56 +08:00
2022-02-10 12:03:56 +08:00
//Tools Output
2021-12-22 18:55:36 +08:00
//classbrowser
2021-12-23 00:24:52 +08:00
mClassBrowser_Sort_By_Name - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SORT_BY_NAME ) ) ;
mClassBrowser_Sort_By_Type - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SORT_BY_TYPE ) ) ;
mClassBrowser_Show_Inherited - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SHOW_INHERITED ) ) ;
2021-12-22 18:55:36 +08:00
//debug console
2021-12-23 00:24:52 +08:00
mDebugConsole_Copy - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_COPY ) ) ;
mDebugConsole_Paste - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_PASTE ) ) ;
mDebugConsole_Clear - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CLEAN ) ) ;
2021-12-22 18:55:36 +08:00
//file view
2021-12-23 00:24:52 +08:00
mFilesView_Open - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_OPEN ) ) ;
mFilesView_OpenInTerminal - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_TERM ) ) ;
mFilesView_OpenInExplorer - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_FOLDER ) ) ;
2022-02-28 22:40:09 +08:00
ui - > actionFilesView_Hide_Non_Support_Files - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_FILTER ) ) ;
2021-12-22 18:55:36 +08:00
//problem view
2022-12-17 11:37:33 +08:00
mProblemSet_New - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_SET ) ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_AddProblem - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_ADD ) ) ;
mProblemSet_RemoveProblem - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_CROSS ) ) ;
2022-12-17 11:37:33 +08:00
mProblemSet_Save - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_SAVE_AS ) ) ;
mProblemSet_Load - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_FILE_OPEN_FOLDER ) ) ;
mProblemSet_ImportFPS - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_BACK ) ) ;
mProblemSet_ExportFPS - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_CODE_FORWARD ) ) ;
2021-12-23 00:24:52 +08:00
2022-12-17 13:34:11 +08:00
mProblem_AddCase - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_ADD ) ) ;
mProblem_RemoveCases - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_REMOVE ) ) ;
mProblem_OpenAnswer - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_EDIT_SOURCE ) ) ;
mProblem_RunAllCases - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_RUN_CASES ) ) ;
mProblem_CaseValidationOptions - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_MISC_GEAR ) ) ;
2021-12-23 00:24:52 +08:00
2022-03-29 18:06:24 +08:00
pIconsManager - > setIcon ( ui - > btnProblemCaseClearInputFileName , IconsManager : : ACTION_MISC_CLEAN ) ;
pIconsManager - > setIcon ( ui - > btnProblemCaseInputFileName , IconsManager : : ACTION_MISC_FOLDER ) ;
pIconsManager - > setIcon ( ui - > btnProblemCaseClearExpectedOutputFileName , IconsManager : : ACTION_MISC_CLEAN ) ;
pIconsManager - > setIcon ( ui - > btnProblemCaseExpectedOutputFileName , IconsManager : : ACTION_MISC_FOLDER ) ;
2021-12-23 00:24:52 +08:00
mProblem_Properties - > setIcon ( pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_PROPERTIES ) ) ;
2021-12-22 18:55:36 +08:00
2022-05-22 14:31:13 +08:00
int idx = ui - > tabExplorer - > indexOf ( ui - > tabWatch ) ;
2021-12-22 11:07:56 +08:00
if ( idx > = 0 )
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_ADD_WATCH ) ) ;
idx = ui - > tabExplorer - > indexOf ( ui - > tabProject ) ;
2021-12-22 11:07:56 +08:00
if ( idx > = 0 )
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_PROJECT_NEW ) ) ;
idx = ui - > tabExplorer - > indexOf ( ui - > tabFiles ) ;
2021-12-22 18:55:36 +08:00
if ( idx > = 0 )
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_FILES ) ) ;
idx = ui - > tabExplorer - > indexOf ( ui - > tabStructure ) ;
2021-12-22 18:55:36 +08:00
if ( idx > = 0 )
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_CLASSBROWSER ) ) ;
idx = ui - > tabExplorer - > indexOf ( ui - > tabProblemSet ) ;
2021-12-22 18:55:36 +08:00
if ( idx > = 0 )
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_SET ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabIssues ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_COMPILE ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabDebug ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_RUN_DEBUG ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabSearch ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_EDIT_SEARCH ) ) ;
2022-02-10 12:03:56 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabToolsOutput ) ;
2021-12-22 18:55:36 +08:00
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_COMPILELOG ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabTODO ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_TODO ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabBookmark ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_VIEW_BOOKMARK ) ) ;
2021-12-22 18:55:36 +08:00
idx = ui - > tabMessages - > indexOf ( ui - > tabProblem ) ;
if ( idx > = 0 )
2021-12-23 00:24:52 +08:00
ui - > tabMessages - > setTabIcon ( idx , pIconsManager - > getIcon ( IconsManager : : ACTION_PROBLEM_PROBLEM ) ) ;
2021-12-21 11:57:23 +08:00
}
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 ;
}
2023-02-27 08:53:39 +08:00
2021-06-24 20:43:09 +08:00
//not c or cpp file
2023-02-24 12:17:30 +08:00
FileType fileType = getFileType ( e - > filename ( ) ) ;
if ( fileType ! = FileType : : CSource
& & fileType ! = FileType : : CppSource
& & fileType ! = FileType : : CHeader
& & fileType ! = FileType : : CppHeader
2023-02-27 08:53:39 +08:00
& & fileType ! = FileType : : GAS
2023-02-24 12:17:30 +08:00
)
return ;
2021-06-24 20:43:09 +08:00
if ( mCompilerManager - > backgroundSyntaxChecking ( ) )
return ;
if ( mCompilerManager - > compiling ( ) )
return ;
if ( mCheckSyntaxInBack )
return ;
2023-02-24 12:17:30 +08:00
if ( mCompileIssuesState = = CompileIssuesState : : ProjectCompilationResultFilled
| | mCompileIssuesState = = CompileIssuesState : : ProjectCompiling ) {
if ( e - > inProject ( ) & & mProject ) {
if ( ! e - > modified ( ) )
return ;
}
}
2021-06-24 20:43:09 +08:00
mCheckSyntaxInBack = true ;
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-09-12 22:45:00 +08:00
CompileTarget target = getCompileTarget ( ) ;
if ( target = = CompileTarget : : Project ) {
2023-08-13 14:46:53 +08:00
int index = mProject - > options ( ) . compilerSet ;
Settings : : PCompilerSet set = pSettings - > compilerSets ( ) . getSet ( index ) ;
if ( ! set | | ! CompilerInfoManager : : supportSyntaxCheck ( set - > compilerType ( ) ) )
return ;
2022-03-27 11:44:52 +08:00
mCompilerManager - > checkSyntax ( e - > filename ( ) , e - > fileEncoding ( ) , e - > text ( ) , mProject ) ;
2021-09-12 22:45:00 +08:00
} else {
2023-08-13 14:46:53 +08:00
Settings : : PCompilerSet set = pSettings - > compilerSets ( ) . defaultSet ( ) ;
if ( ! set | | ! CompilerInfoManager : : supportSyntaxCheck ( set - > compilerType ( ) ) )
return ;
2022-03-27 11:44:52 +08:00
mCompilerManager - > checkSyntax ( e - > filename ( ) , e - > fileEncoding ( ) , e - > text ( ) , nullptr ) ;
2021-09-12 22:45:00 +08:00
}
2021-06-25 12:40:11 +08:00
}
2023-01-03 21:43:45 +08:00
bool MainWindow : : parsing ( )
{
if ( mProject & & mProject - > cppParser ( ) & & mProject - > cppParser ( ) - > parsing ( ) )
return true ;
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * editor = ( * mEditorList ) [ i ] ;
if ( editor - > parser ( ) & & editor - > parser ( ) - > parsing ( ) )
return true ;
}
return false ;
}
2022-12-01 22:10:44 +08:00
bool MainWindow : : compile ( bool rebuild , CppCompileType compileType )
2021-06-25 12:40:11 +08:00
{
2021-12-23 17:07:27 +08:00
mCompilerManager - > stopPausing ( ) ;
2021-09-12 22:45:00 +08:00
CompileTarget target = getCompileTarget ( ) ;
2022-12-28 16:39:18 +08:00
if ( target = = CompileTarget : : Project & & compileType = = CppCompileType : : Normal ) {
2023-03-12 09:19:02 +08:00
QStringList missedUnits ;
foreach ( const PProjectUnit & unit , mProject - > unitList ( ) ) {
if ( ! fileExists ( unit - > fileName ( ) ) ) {
missedUnits . append (
extractRelativePath (
mProject - > directory ( ) ,
unit - > fileName ( ) ) ) ;
}
}
if ( ! missedUnits . empty ( ) ) {
ui - > actionProject - > setChecked ( true ) ;
showHideInfosTab ( ui - > tabProject , true ) ;
ui - > tabExplorer - > setCurrentWidget ( ui - > tabProject ) ;
QString s = missedUnits . join ( " <br/> " ) ;
QMessageBox : : critical ( this ,
tr ( " Missing Project Files " ) ,
tr ( " The following files is missing, can't build the project: " )
+ " <br/><br/> "
+ s ) ;
return false ;
}
2022-10-21 12:43:02 +08:00
if ( mProject - > modified ( ) ) {
2021-11-23 10:32:33 +08:00
mProject - > saveAll ( ) ;
2022-10-21 12:43:02 +08:00
}
mEditorList - > saveAll ( ) ;
2021-10-25 09:31:58 +08:00
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 ) {
2022-06-16 21:34:31 +08:00
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
2022-10-12 19:48:35 +08:00
mCompileSuccessionTask - > isExecutable = true ;
2021-09-13 22:45:50 +08:00
}
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2022-02-10 12:03:56 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabToolsOutput ) ;
2021-09-13 22:45:50 +08:00
mCompilerManager - > compileProject ( mProject , rebuild ) ;
2022-02-03 20:48:11 +08:00
updateCompileActions ( ) ;
2021-09-13 22:45:50 +08:00
updateAppTitle ( ) ;
2021-09-12 22:45:00 +08:00
} else {
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-11-02 23:47:51 +08:00
if ( editor - > modified ( ) | | editor - > isNew ( ) ) {
2021-09-12 22:45:00 +08:00
if ( ! editor - > save ( false , false ) )
return false ;
}
if ( mCompileSuccessionTask ) {
2022-12-28 16:39:18 +08:00
Settings : : PCompilerSet compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
if ( editor - > inProject ( ) )
compilerSet = pSettings - > compilerSets ( ) . getSet ( mProject - > options ( ) . compilerSet ) ;
2022-10-12 19:48:35 +08:00
if ( compilerSet ) {
2022-12-01 22:10:44 +08:00
Settings : : CompilerSet : : CompilationStage stage ;
switch ( compileType ) {
case CppCompileType : : GenerateAssemblyOnly :
stage = Settings : : CompilerSet : : CompilationStage : : CompilationProperOnly ;
break ;
case CppCompileType : : PreprocessOnly :
stage = Settings : : CompilerSet : : CompilationStage : : PreprocessingOnly ;
break ;
default :
stage = compilerSet - > compilationStage ( ) ;
break ;
}
mCompileSuccessionTask - > execName = compilerSet - > getOutputFilename ( editor - > filename ( ) , stage ) ;
mCompileSuccessionTask - > isExecutable = compilerSet - > isOutputExecutable ( stage ) ;
2022-10-12 19:48:35 +08:00
} else {
mCompileSuccessionTask - > execName = changeFileExt ( editor - > filename ( ) , DEFAULT_EXECUTABLE_SUFFIX ) ;
mCompileSuccessionTask - > isExecutable = true ;
}
2022-12-01 22:10:44 +08:00
if ( ! mCompileSuccessionTask - > isExecutable ) {
Editor * editor = mEditorList - > getOpenedEditorByFilename ( mCompileSuccessionTask - > execName ) ;
if ( editor )
mEditorList - > closeEditor ( editor , false , true ) ;
}
2021-09-12 22:45:00 +08:00
}
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2022-02-10 12:03:56 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabToolsOutput ) ;
2022-12-01 22:10:44 +08:00
mCompilerManager - > compile ( editor - > filename ( ) , editor - > fileEncoding ( ) , rebuild , compileType ) ;
2022-02-03 20:48:11 +08:00
updateCompileActions ( ) ;
2021-09-13 22:45:50 +08:00
updateAppTitle ( ) ;
2021-06-25 12:40:11 +08:00
}
}
2023-03-12 09:19:02 +08:00
return true ;
2021-06-25 12:40:11 +08:00
}
2022-06-16 21:34:31 +08:00
void MainWindow : : runExecutable (
const QString & exeName ,
const QString & filename ,
RunType runType ,
const QStringList & binDirs )
2021-06-25 12:40:11 +08:00
{
2021-12-23 17:07:27 +08:00
mCompilerManager - > stopPausing ( ) ;
2021-06-25 12:40:11 +08:00
// Check if it exists
2021-09-07 10:28:40 +08:00
if ( ! fileExists ( exeName ) ) {
2023-02-17 09:18:39 +08:00
if ( ui - > actionCompile - > isEnabled ( ) ) {
2023-02-14 23:42:11 +08:00
doCompileRun ( runType ) ;
2021-10-12 09:47:58 +08:00
return ;
2021-06-25 12:40:11 +08:00
} else {
QMessageBox : : critical ( this , " Error " ,
tr ( " Source file is not compiled. " ) ) ;
return ;
}
} else {
2023-10-15 16:28:55 +08:00
if ( ! filename . isEmpty ( ) & &
( compareFileModifiedTime ( filename , exeName ) > = 0
| | compareFileModifiedTime ( exeName , pSettings - > compilerSets ( ) . defaultIndexTimestamp ( ) ) < = 0 ) ) {
2023-02-14 23:42:11 +08:00
doCompileRun ( runType ) ;
return ;
2021-06-25 12:40:11 +08:00
}
}
2021-10-24 23:13:00 +08:00
QString params ;
2021-09-19 17:59:03 +08:00
if ( pSettings - > executor ( ) . useParams ( ) ) {
2021-10-24 23:13:00 +08:00
params = pSettings - > executor ( ) . params ( ) ;
2021-09-19 17:59:03 +08:00
}
2021-11-01 20:44:08 +08:00
if ( runType = = RunType : : Normal ) {
if ( pSettings - > executor ( ) . minimizeOnRun ( ) ) {
showMinimized ( ) ;
}
2022-06-16 21:34:31 +08:00
mCompilerManager - > run ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) , binDirs ) ;
2021-11-01 20:44:08 +08:00
} else if ( runType = = RunType : : ProblemCases ) {
POJProblem problem = mOJProblemModel . problem ( ) ;
if ( problem ) {
mCompilerManager - > runProblem ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) ,
2022-12-13 08:49:20 +08:00
problem - > cases ,
problem ) ;
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2021-11-02 01:07:37 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabProblem ) ;
2021-11-01 20:44:08 +08:00
}
} else if ( runType = = RunType : : CurrentProblemCase ) {
2022-03-29 18:06:24 +08:00
QModelIndex index = ui - > tblProblemCases - > currentIndex ( ) ;
2021-11-01 20:44:08 +08:00
if ( index . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( index . row ( ) ) ;
2022-12-13 08:49:20 +08:00
POJProblem problem = mOJProblemModel . problem ( ) ;
2021-11-01 20:44:08 +08:00
mCompilerManager - > runProblem ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) ,
2022-12-13 08:49:20 +08:00
problemCase ,
problem ) ;
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2021-11-02 01:07:37 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabProblem ) ;
2021-11-01 20:44:08 +08:00
}
}
2021-12-15 19:12:16 +08:00
updateCompileActions ( ) ;
2021-11-01 20:44:08 +08:00
updateAppTitle ( ) ;
2021-06-25 12:40:11 +08:00
}
2021-11-01 20:44:08 +08:00
void MainWindow : : runExecutable ( RunType runType )
2021-06-25 12:40:11 +08:00
{
2021-09-13 22:45:50 +08:00
CompileTarget target = getCompileTarget ( ) ;
if ( target = = CompileTarget : : Project ) {
2022-06-16 21:34:31 +08:00
QStringList binDirs = mProject - > binDirs ( ) ;
2022-10-25 19:09:46 +08:00
QFileInfo execInfo ( mProject - > executable ( ) ) ;
QDateTime execModTime = execInfo . lastModified ( ) ;
2023-03-02 18:15:31 +08:00
if ( execInfo . exists ( ) & & mProject - > modifiedSince ( execModTime ) ) {
//if project options changed, or units added/removed
//mProject->saveAll();
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
2023-03-26 12:34:11 +08:00
mCompileSuccessionTask - > type = runTypeToCompileSuccessionTaskType ( runType ) ;
2023-03-02 18:15:31 +08:00
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
mCompileSuccessionTask - > isExecutable = true ;
mCompileSuccessionTask - > binDirs = binDirs ;
compile ( true ) ;
return ;
}
2023-03-01 18:46:43 +08:00
if ( execInfo . exists ( ) & & mProject - > unitsModifiedSince ( execModTime ) ) {
2023-03-02 18:15:31 +08:00
//if units modified;
2022-10-21 12:43:02 +08:00
//mProject->saveAll();
2021-11-23 10:32:33 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
2023-03-26 12:34:11 +08:00
mCompileSuccessionTask - > type = runTypeToCompileSuccessionTaskType ( runType ) ;
2022-06-16 21:34:31 +08:00
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
2022-10-12 19:48:35 +08:00
mCompileSuccessionTask - > isExecutable = true ;
2022-06-16 21:34:31 +08:00
mCompileSuccessionTask - > binDirs = binDirs ;
2021-11-23 10:32:33 +08:00
compile ( ) ;
return ;
}
2022-06-16 21:34:31 +08:00
runExecutable ( mProject - > executable ( ) , mProject - > filename ( ) , runType ,
binDirs ) ;
2021-09-13 22:45:50 +08:00
} else {
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-11-02 23:47:51 +08:00
if ( editor - > modified ( ) | | editor - > isNew ( ) ) {
2021-09-13 22:45:50 +08:00
if ( ! editor - > save ( false , false ) )
return ;
}
2022-06-16 21:34:31 +08:00
QStringList binDirs = getDefaultCompilerSetBinDirs ( ) ;
2022-10-12 19:48:35 +08:00
QString exeName ;
Settings : : PCompilerSet compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
bool isExecutable ;
if ( compilerSet ) {
exeName = compilerSet - > getOutputFilename ( editor - > filename ( ) ) ;
2022-12-01 22:10:44 +08:00
isExecutable = compilerSet - > isOutputExecutable ( ) ;
2022-10-12 19:48:35 +08:00
} else {
exeName = changeFileExt ( editor - > filename ( ) , DEFAULT_EXECUTABLE_SUFFIX ) ;
isExecutable = true ;
}
if ( isExecutable )
runExecutable ( exeName , editor - > filename ( ) , runType , binDirs ) ;
else if ( runType = = RunType : : Normal ) {
if ( fileExists ( exeName ) )
openFile ( exeName ) ;
} else {
QMessageBox : : critical ( this , tr ( " Wrong Compiler Settings " ) ,
tr ( " Compiler is set not to generate executable. " ) + " <BR/><BR/> "
+ tr ( " We need the executabe to run problem case. " ) ) ;
return ;
}
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 ;
2021-12-23 17:07:27 +08:00
mCompilerManager - > stopPausing ( ) ;
2021-07-23 13:22:05 +08:00
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 ;
2022-06-16 21:34:31 +08:00
QStringList binDirs ;
2023-02-22 08:59:00 +08:00
QSet < QString > unitFiles ;
2021-07-23 13:22:05 +08:00
switch ( getCompileTarget ( ) ) {
2024-03-10 21:25:24 +08:00
case CompileTarget : : Project : {
2023-02-18 12:08:03 +08:00
compilerSet = pSettings - > compilerSets ( ) . getSet ( mProject - > options ( ) . compilerSet ) ;
if ( ! compilerSet )
compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
2022-06-16 21:34:31 +08:00
binDirs = mProject - > binDirs ( ) ;
2021-09-18 11:32:38 +08:00
// Check if we enabled proper options
2022-05-14 11:21:59 +08:00
debugEnabled = mProject - > getCompileOption ( CC_CMD_OPT_DEBUG_INFO ) = = COMPILER_OPTION_ON ;
stripEnabled = mProject - > getCompileOption ( LINK_CMD_OPT_STRIP_EXE ) = = COMPILER_OPTION_ON ;
2023-04-02 22:53:02 +08:00
if ( stripEnabled & & ! debugEnabled ) {
if ( QMessageBox : : question ( this ,
tr ( " Correct compile settings for debug " ) ,
tr ( " The generated executable won't have debug symbol infos, and can't be debugged. " )
2023-02-18 12:08:03 +08:00
+ " <BR /><BR /> "
2023-04-02 22:53:02 +08:00
+ tr ( " If you are using the Release compiler set, please use choose the Debug version from toolbar. " )
2023-02-18 12:08:03 +08:00
+ " <BR /><BR /> "
2023-04-02 22:53:02 +08:00
+ tr ( " Or you can manually change the following settings in the options dialog's compiler set page: " )
+ " <BR /> "
+ tr ( " - Turned on the \" Generate debug info (-g3) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Strip executable (-s) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Optimization level (-O) \" option or set it to \" Debug (-Og) \" . " )
+ " <BR /><BR /> "
2023-04-03 09:39:45 +08:00
+ tr ( " You should recompile after change the compiler set or it's settings. " )
+ " <BR /><BR /> "
2023-04-02 22:53:02 +08:00
+ tr ( " Do you want to mannually change the compiler set settings now? " )
) = = QMessageBox : : Yes ) {
changeProjectOptions (
SettingsDialog : : tr ( " Compiler Set " ) ,
SettingsDialog : : tr ( " Project " )
) ;
2022-12-16 11:10:46 +08:00
}
2021-09-18 11:32:38 +08:00
return ;
}
2023-02-11 11:31:54 +08:00
2021-09-18 19:30:16 +08:00
// Did we compile?
if ( ! fileExists ( mProject - > executable ( ) ) ) {
2023-02-14 23:42:11 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
mCompileSuccessionTask - > isExecutable = true ;
mCompileSuccessionTask - > binDirs = binDirs ;
compile ( ) ;
2021-09-18 19:30:16 +08:00
return ;
}
2023-02-11 11:31:54 +08:00
{
QFileInfo execInfo ( mProject - > executable ( ) ) ;
QDateTime execModTime = execInfo . lastModified ( ) ;
2023-03-02 18:15:31 +08:00
if ( execInfo . exists ( ) & & mProject - > modifiedSince ( execModTime ) ) {
//if project options changed, or units added/removed
2023-02-11 11:31:54 +08:00
//mProject->saveAll();
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
mCompileSuccessionTask - > isExecutable = true ;
mCompileSuccessionTask - > binDirs = binDirs ;
2023-03-01 18:46:43 +08:00
compile ( true ) ;
2023-02-11 11:31:54 +08:00
return ;
}
2023-03-02 18:15:31 +08:00
if ( execInfo . exists ( ) & & mProject - > unitsModifiedSince ( execModTime ) ) {
//if units modified
//mProject->saveAll();
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
mCompileSuccessionTask - > execName = mProject - > executable ( ) ;
mCompileSuccessionTask - > isExecutable = true ;
mCompileSuccessionTask - > binDirs = binDirs ;
compile ( ) ;
return ;
}
2023-02-11 11:31:54 +08:00
}
2021-09-18 19:30:16 +08:00
// Did we choose a host application for our DLL?
if ( mProject - > options ( ) . type = = ProjectType : : DynamicLib ) {
if ( mProject - > options ( ) . hostApplication . isEmpty ( ) ) {
QMessageBox : : critical ( this ,
tr ( " Host applcation missing " ) ,
tr ( " DLL project needs a host application to run. " )
+ " <br /> "
+ tr ( " But it's missing. " ) ,
QMessageBox : : Ok ) ;
return ;
2021-09-18 22:37:07 +08:00
} else if ( ! fileExists ( mProject - > options ( ) . hostApplication ) ) {
QMessageBox : : critical ( this ,
tr ( " Host application not exists " ) ,
tr ( " Host application file '%1' doesn't exist. " )
. arg ( mProject - > options ( ) . hostApplication ) ,
QMessageBox : : Ok ) ;
return ;
2021-09-18 19:30:16 +08:00
}
}
// Reset UI, remove invalid breakpoints
prepareDebugger ( ) ;
filePath = mProject - > executable ( ) ;
2021-07-23 13:22:05 +08:00
2021-09-18 19:30:16 +08:00
// mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
2021-07-23 13:22:05 +08:00
2023-02-22 08:59:00 +08:00
foreach ( const PProjectUnit & unit , mProject - > unitList ( ) ) {
2023-02-22 10:39:20 +08:00
if ( fileExists ( unit - > fileName ( ) ) )
unitFiles . insert ( unit - > fileName ( ) ) ;
2023-02-22 08:59:00 +08:00
}
mDebugger - > deleteInvalidProjectBreakpoints ( unitFiles ) ;
2024-03-10 21:25:24 +08:00
bool inferiorHasSymbols { true } ;
QString inferior { filePath } ;
2021-09-18 19:30:16 +08:00
if ( mProject - > options ( ) . type = = ProjectType : : DynamicLib ) {
2024-03-10 21:25:24 +08:00
inferior = mProject - > options ( ) . hostApplication ;
inferiorHasSymbols = false ;
}
inferior . replace ( ' \\ ' , ' / ' ) ;
if ( ! mDebugger - > startClient (
mProject - > options ( ) . compilerSet ,
inferior ,
inferiorHasSymbols ,
debugInferiorhasBreakpoint ( ) ,
binDirs
) )
return ;
2021-10-09 11:33:23 +08:00
2024-03-10 21:25:24 +08:00
mDebugger - > includeOrSkipDirsInSymbolSearch (
mProject - > options ( ) . includeDirs ,
pSettings - > debugger ( ) . skipProjectLibraries ( ) ) ;
mDebugger - > includeOrSkipDirsInSymbolSearch (
mProject - > options ( ) . libDirs ,
pSettings - > debugger ( ) . skipProjectLibraries ( ) ) ;
}
2021-09-18 19:30:16 +08:00
break ;
2021-10-20 18:05:43 +08:00
case CompileTarget : : File : {
2022-10-12 19:48:35 +08:00
binDirs = compilerSet - > binDirs ( ) ;
2022-06-16 21:34:31 +08:00
2021-10-20 18:05:43 +08:00
// Check if we enabled proper options
2022-05-14 11:21:59 +08:00
debugEnabled = compilerSet - > getCompileOptionValue ( CC_CMD_OPT_DEBUG_INFO ) = = COMPILER_OPTION_ON ;
stripEnabled = compilerSet - > getCompileOptionValue ( LINK_CMD_OPT_STRIP_EXE ) = = COMPILER_OPTION_ON ;
2023-04-02 22:53:02 +08:00
if ( stripEnabled & & ! debugEnabled ) {
if ( QMessageBox : : question ( this ,
tr ( " Correct compile settings for debug " ) ,
2023-04-03 09:39:45 +08:00
tr ( " The generated executable won't have debug symbol infos, and can't be debugged. " )
+ " <BR /><BR /> "
+ tr ( " If you are using the Release compiler set, please use choose the Debug version from toolbar. " )
+ " <BR /><BR /> "
+ tr ( " Or you can manually change the following settings in the options dialog's compiler set page: " )
+ " <BR /> "
+ tr ( " - Turned on the \" Generate debug info (-g3) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Strip executable (-s) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Optimization level (-O) \" option or set it to \" Debug (-Og) \" . " )
+ " <BR /><BR /> "
+ tr ( " You should recompile after change the compiler set or it's settings. " )
+ " <BR /><BR /> "
2023-04-02 22:53:02 +08:00
+ tr ( " Do you want to mannually change the compiler set settings now? " )
) = = QMessageBox : : Yes ) {
changeOptions (
SettingsDialog : : tr ( " Compiler Set " ) ,
SettingsDialog : : tr ( " Compiler " )
) ;
2022-12-16 11:10:46 +08:00
}
2021-10-20 18:05:43 +08:00
return ;
2021-07-23 13:22:05 +08:00
}
2021-10-20 18:05:43 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ! = nullptr ) {
// Did we saved?
2021-11-02 23:47:51 +08:00
if ( e - > modified ( ) | | e - > isNew ( ) ) {
2021-10-20 18:05:43 +08:00
// if file is modified,save it first
if ( ! e - > save ( false , false ) )
return ;
2021-07-23 13:22:05 +08:00
}
2021-10-20 18:05:43 +08:00
// Did we compiled?
2022-10-12 19:48:35 +08:00
Settings : : PCompilerSet compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
bool isExecutable ;
if ( compilerSet ) {
filePath = compilerSet - > getOutputFilename ( e - > filename ( ) ) ;
2022-12-01 22:10:44 +08:00
isExecutable = compilerSet - > isOutputExecutable ( ) ;
2022-10-12 19:48:35 +08:00
} else {
filePath = changeFileExt ( e - > filename ( ) , DEFAULT_EXECUTABLE_SUFFIX ) ;
isExecutable = true ;
}
if ( ! isExecutable ) {
QMessageBox : : warning (
this ,
tr ( " Wrong Compiler Settings " ) ,
tr ( " Compiler is set not to generate executable. " ) + " <BR /><BR /> "
+ tr ( " Please correct this before start debugging " ) ) ;
compile ( ) ;
return ;
}
2021-10-20 18:05:43 +08:00
debugFile . setFile ( filePath ) ;
if ( ! debugFile . exists ( ) ) {
2023-02-17 09:11:52 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
mCompileSuccessionTask - > binDirs = binDirs ;
compile ( ) ;
return ;
2023-10-15 16:28:55 +08:00
} else if (
compareFileModifiedTime ( e - > filename ( ) , filePath ) > = 0
| | compareFileModifiedTime ( filePath , pSettings - > compilerSets ( ) . defaultIndexTimestamp ( ) ) < = 0 ) {
2023-02-17 09:11:52 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
mCompileSuccessionTask - > binDirs = binDirs ;
compile ( ) ;
return ;
2021-07-23 13:22:05 +08:00
}
2021-10-20 18:05:43 +08:00
prepareDebugger ( ) ;
2021-12-25 18:09:50 +08:00
QString filePath = debugFile . filePath ( ) . replace ( ' \\ ' , ' / ' ) ;
2024-03-10 21:25:24 +08:00
if ( ! mDebugger - > startClient (
pSettings - > compilerSets ( ) . defaultIndex ( ) ,
filePath ,
true ,
debugInferiorhasBreakpoint ( ) ,
binDirs ,
e - > filename ( ) ) )
2021-10-20 18:05:43 +08:00
return ;
}
2021-07-23 13:22:05 +08:00
}
break ;
2021-10-20 18:05:43 +08:00
default :
2021-11-02 23:47:51 +08:00
//don't compile
updateEditorActions ( ) ;
return ;
2021-07-23 13:22:05 +08:00
}
2021-08-01 12:02:28 +08:00
updateEditorActions ( ) ;
2021-07-23 13:22:05 +08:00
2024-03-10 21:25:24 +08:00
mDebugger - > runInferior ( ) ;
2021-07-23 13:22:05 +08:00
}
2021-10-04 12:49:55 +08:00
void MainWindow : : showSearchPanel ( bool showReplace )
2021-08-05 19:58:32 +08:00
{
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2021-10-04 12:49:55 +08:00
showSearchReplacePanel ( showReplace ) ;
2021-08-05 19:58:32 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabSearch ) ;
}
2021-11-25 09:05:45 +08:00
void MainWindow : : showCPUInfoDialog ( )
{
if ( mCPUDialog = = nullptr ) {
2022-10-10 18:05:18 +08:00
//main window takes the owner
mCPUDialog = new CPUDialog ( this ) ;
2021-11-25 09:05:45 +08:00
connect ( mCPUDialog , & CPUDialog : : closed , this , & MainWindow : : cleanUpCPUDialog ) ;
2021-12-23 09:17:27 +08:00
updateCompileActions ( ) ;
2021-11-25 09:05:45 +08:00
}
mCPUDialog - > show ( ) ;
}
2022-05-22 14:31:13 +08:00
static void setDockMovable ( QDockWidget * dock , bool movable ) {
if ( movable ) {
dock - > setFeatures ( dock - > features ( ) | QDockWidget : : DockWidgetMovable ) ;
} else {
dock - > setFeatures ( dock - > features ( ) & ~ QDockWidget : : DockWidgetMovable ) ;
}
}
2022-05-23 22:36:22 +08:00
void MainWindow : : stretchMessagesPanel ( bool open )
2021-06-23 22:38:02 +08:00
{
2022-05-22 14:31:13 +08:00
//ui->dockMessages->setVisible(open);
ui - > tabMessages - > setShrinked ( ! open ) ;
if ( open ) {
resizeDocks ( { ui - > dockMessages } ,
{ ui - > tabMessages - > beforeShrinkWidthOrHeight ( ) } ,
ui - > tabMessages - > shrinkOrientation ( ) ) ;
}
setDockMovable ( ui - > dockMessages , open ) ;
2021-09-02 19:36:16 +08:00
}
2022-05-21 10:44:39 +08:00
2022-05-23 22:36:22 +08:00
void MainWindow : : stretchExplorerPanel ( bool open )
2021-09-02 19:36:16 +08:00
{
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setShrinked ( ! open ) ;
if ( open ) {
resizeDocks ( { ui - > dockExplorer } ,
{ ui - > tabExplorer - > beforeShrinkWidthOrHeight ( ) } ,
ui - > tabExplorer - > shrinkOrientation ( ) ) ;
}
setDockMovable ( ui - > dockExplorer , 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 ( ) ;
2021-11-25 23:41:40 +08:00
if ( pSettings - > debugger ( ) . enableDebugConsole ( ) ) {
2021-10-02 17:01:08 +08:00
ui - > debugConsole - > addLine ( " (gdb) " ) ;
}
2021-07-23 13:22:05 +08:00
ui - > txtEvalOutput - > clear ( ) ;
// Restore when no watch vars are shown
2022-05-22 14:31:13 +08:00
mDebugger - > setLeftPageIndexBackup ( ui - > tabExplorer - > currentIndex ( ) ) ;
2021-07-23 13:22:05 +08:00
// Focus on the debugging buttons
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setCurrentWidget ( ui - > tabWatch ) ;
2021-07-23 13:22:05 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabDebug ) ;
2021-10-27 16:58:30 +08:00
ui - > debugViews - > setCurrentWidget ( ui - > tabLocals ) ;
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
stretchExplorerPanel ( true ) ;
2021-07-23 13:22:05 +08:00
// Reset watch vars
2021-08-29 10:29:56 +08:00
// mDebugger->deleteWatchVars(false);
}
2021-08-30 22:05:45 +08:00
void MainWindow : : doAutoSave ( Editor * e )
{
2021-11-12 12:40:47 +08:00
if ( ! e | | ! e - > canAutoSave ( ) )
2021-08-30 22:05:45 +08:00
return ;
QString filename = e - > filename ( ) ;
2021-11-12 12:40:47 +08:00
try {
QFileInfo fileInfo ( filename ) ;
QDir parent = fileInfo . absoluteDir ( ) ;
QString baseName = fileInfo . completeBaseName ( ) ;
QString suffix = fileInfo . suffix ( ) ;
switch ( pSettings - > editor ( ) . autoSaveStrategy ( ) ) {
case assOverwrite :
2023-01-26 11:33:27 +08:00
e - > save ( ) ;
2021-11-12 12:40:47 +08:00
return ;
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 ) ) ;
}
}
if ( e - > isNew ( ) ) {
e - > saveAs ( ) ;
} else {
e - > saveFile ( filename ) ;
e - > setCanAutoSave ( false ) ;
}
} catch ( FileError & error ) {
QMessageBox : : critical ( e ,
tr ( " Auto Save Error " ) ,
tr ( " Auto save \" %1 \" to \" %2 \" failed:%3 " )
. arg ( e - > filename ( ) , filename , error . reason ( ) ) ) ;
2021-08-30 22:05:45 +08:00
}
}
2022-12-17 11:37:33 +08:00
void MainWindow : : createCustomActions ( )
{
// action for problem set
2022-12-17 13:34:11 +08:00
mProblemSet_New = createAction (
2022-12-17 11:37:33 +08:00
tr ( " New Problem Set " ) ,
ui - > tabProblemSet
) ;
connect ( mProblemSet_New , & QAction : : triggered ,
this , & MainWindow : : onNewProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_Rename = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Rename Problem Set " ) ,
ui - > tabProblemSet
) ;
connect ( mProblemSet_Rename , & QAction : : triggered ,
this , & MainWindow : : onRenameProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_Save = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Save Problem Set " ) ,
ui - > tabProblemSet
) ;
connect ( mProblemSet_Save , & QAction : : triggered ,
this , & MainWindow : : onSaveProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_Load = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Load Problem Set " ) ,
ui - > tabProblemSet ) ;
connect ( mProblemSet_Load , & QAction : : triggered ,
this , & MainWindow : : onLoadProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_ImportFPS = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Import FPS Problem Set " ) ,
ui - > tabProblemSet ) ;
connect ( mProblemSet_ImportFPS , & QAction : : triggered ,
this , & MainWindow : : onImportFPSProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_ExportFPS = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Export FPS Problem Set " ) ,
ui - > tabProblemSet ) ;
connect ( mProblemSet_ExportFPS , & QAction : : triggered ,
this , & MainWindow : : onExportFPSProblemSet ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_AddProblem = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Add Problem " ) ,
ui - > tabProblemSet ) ;
2022-12-17 13:34:11 +08:00
connect ( mProblemSet_AddProblem , & QAction : : triggered ,
2022-12-17 11:37:33 +08:00
this , & MainWindow : : onAddProblem ) ;
2022-12-17 13:34:11 +08:00
mProblemSet_RemoveProblem = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove Problem " ) ,
ui - > tabProblemSet ) ;
2022-12-17 13:34:11 +08:00
connect ( mProblemSet_RemoveProblem , & QAction : : triggered ,
2022-12-17 11:37:33 +08:00
this , & MainWindow : : onRemoveProblem ) ;
2022-12-17 13:34:11 +08:00
//problem
mProblem_OpenSource = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Open Source File " ) ,
2022-12-17 13:34:11 +08:00
ui - > tabProblemSet
2022-12-17 11:37:33 +08:00
) ;
connect ( mProblem_OpenSource , & QAction : : triggered , this ,
& MainWindow : : onProblemOpenSource ) ;
2022-12-17 13:34:11 +08:00
mProblem_Rename = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Rename Problem " ) ,
2022-12-17 13:34:11 +08:00
ui - > tabProblemSet
2022-12-17 11:37:33 +08:00
) ;
connect ( mProblem_Rename , & QAction : : triggered , this ,
& MainWindow : : onProblemRename ) ;
2022-12-17 13:34:11 +08:00
mProblem_GotoUrl = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Goto Url " ) ,
2022-12-17 13:34:11 +08:00
ui - > tabProblemSet
2022-12-17 11:37:33 +08:00
) ;
connect ( mProblem_GotoUrl , & QAction : : triggered , this ,
& MainWindow : : onProblemGotoUrl ) ;
2022-12-17 13:34:11 +08:00
mProblem_Properties = createAction (
tr ( " Properties... " ) ,
ui - > tabProblemSet
2022-12-17 11:37:33 +08:00
) ;
2022-12-17 13:34:11 +08:00
connect ( mProblem_Properties , & QAction : : triggered , this ,
& MainWindow : : onProblemProperties ) ;
//problem cases (buttons)
mProblem_AddCase = createAction (
tr ( " Add Problem Case " ) ,
ui - > tabProblem ) ;
connect ( mProblem_AddCase , & QAction : : triggered , this ,
& MainWindow : : onAddProblemCase ) ;
mProblem_RemoveCases = createAction (
tr ( " Remove Problem Case " ) ,
ui - > tabProblem ) ;
connect ( mProblem_RemoveCases , & QAction : : triggered , this ,
& MainWindow : : onRemoveProblemCases ) ;
mProblem_OpenAnswer = createAction (
tr ( " Open Anwser Source File " ) ,
ui - > tabProblem ) ;
connect ( mProblem_OpenAnswer , & QAction : : triggered , this ,
& MainWindow : : onOpenProblemAnswerFile ) ;
mProblem_CaseValidationOptions = createAction (
tr ( " Problem Cases Validation Options " ) ,
ui - > tabProblem ) ;
connect ( mProblem_CaseValidationOptions , & QAction : : triggered , this ,
& MainWindow : : onOpenCaseValidationOptions ) ;
// problem case run
mProblem_RunAllCases = createShortcutCustomableAction (
tr ( " Run All Cases " ) ,
" Problem_RunAllCases " ) ;
2022-12-17 11:37:33 +08:00
connect ( mProblem_RunAllCases , & QAction : : triggered , this ,
2022-12-31 09:36:50 +08:00
& MainWindow : : onProblemRunAllCases ) ;
2022-12-17 11:37:33 +08:00
2022-12-17 13:34:11 +08:00
mProblem_RunCurrentCase = createShortcutCustomableAction (
2022-12-17 11:37:33 +08:00
tr ( " Run Current Case " ) ,
2022-12-17 13:34:11 +08:00
" Problem_RunCurrentCases " ) ;
2022-12-17 11:37:33 +08:00
connect ( mProblem_RunCurrentCase , & QAction : : triggered , this ,
& MainWindow : : onProblemRunCurrentCase ) ;
2022-12-17 13:34:11 +08:00
mProblem_batchSetCases = createShortcutCustomableAction (
2022-12-17 11:37:33 +08:00
tr ( " Batch Set Cases " ) ,
2022-12-17 13:34:11 +08:00
" Problem_BatchSetCases " ) ;
2022-12-17 11:37:33 +08:00
connect ( mProblem_batchSetCases , & QAction : : triggered , this ,
& MainWindow : : onProblemBatchSetCases ) ;
//Bookmark
ui - > tableBookmark - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2022-12-17 13:34:11 +08:00
mBookmark_Remove = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove " ) ,
ui - > tableBookmark ) ;
connect ( mBookmark_Remove , & QAction : : triggered ,
this , & MainWindow : : onBookmarkRemove ) ;
2022-12-17 13:34:11 +08:00
mBookmark_RemoveAll = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove All Bookmarks " ) ,
ui - > tableBookmark ) ;
connect ( mBookmark_RemoveAll , & QAction : : triggered ,
this , & MainWindow : : onBookmarkRemoveAll ) ;
2022-12-17 13:34:11 +08:00
mBookmark_Modify = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Modify Description " ) ,
ui - > tableBookmark ) ;
connect ( mBookmark_Modify , & QAction : : triggered ,
this , & MainWindow : : onBookmarkModify ) ;
//watch view
2022-12-17 13:34:11 +08:00
mDebugConsole_ShowDetailLog = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Show detail debug logs " ) ,
ui - > debugConsole ) ;
mDebugConsole_ShowDetailLog - > setCheckable ( true ) ;
connect ( mDebugConsole_ShowDetailLog , & QAction : : toggled ,
this , & MainWindow : : onDebugConsoleShowDetailLog ) ;
2022-12-17 13:34:11 +08:00
mDebugConsole_Copy = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Copy " ) ,
ui - > debugConsole ,
QKeySequence ( " Ctrl+C " ) ) ;
connect ( mDebugConsole_Copy , & QAction : : triggered ,
this , & MainWindow : : onDebugConsoleCopy ) ;
2022-12-17 13:34:11 +08:00
mDebugConsole_Paste = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Paste " ) ,
ui - > debugConsole ,
QKeySequence ( " Ctrl+V " ) ) ;
connect ( mDebugConsole_Paste , & QAction : : triggered ,
this , & MainWindow : : onDebugConsolePaste ) ;
2022-12-17 13:34:11 +08:00
mDebugConsole_SelectAll = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Select All " ) ,
ui - > debugConsole ) ;
connect ( mDebugConsole_SelectAll , & QAction : : triggered ,
this , & MainWindow : : onDebugConsoleSelectAll ) ;
2022-12-17 13:34:11 +08:00
mDebugConsole_Clear = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Clear " ) ,
ui - > debugConsole ) ;
connect ( mDebugConsole_Clear , & QAction : : triggered ,
this , & MainWindow : : onDebugConsoleClear ) ;
//compile issues
2022-12-17 13:34:11 +08:00
mTableIssuesCopyAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Copy " ) ,
ui - > tableIssues ,
QKeySequence ( " Ctrl+C " ) ) ;
connect ( mTableIssuesCopyAction , & QAction : : triggered ,
this , & MainWindow : : onTableIssuesCopy ) ;
2022-12-17 13:34:11 +08:00
mTableIssuesCopyAllAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Copy all " ) ,
ui - > tableIssues ,
QKeySequence ( " Ctrl+Shift+C " ) ) ;
connect ( mTableIssuesCopyAllAction , & QAction : : triggered ,
this , & MainWindow : : onTableIssuesCopyAll ) ;
2022-12-17 13:34:11 +08:00
mTableIssuesClearAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Clear " ) ,
ui - > tableIssues ) ;
connect ( mTableIssuesClearAction , & QAction : : triggered ,
this , & MainWindow : : onTableIssuesClear ) ;
//search
2022-12-17 13:34:11 +08:00
mSearchViewClearAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove this search " ) ,
ui - > searchHistoryPanel ) ;
connect ( mSearchViewClearAction , & QAction : : triggered ,
this , & MainWindow : : onSearchViewClear ) ;
2022-12-17 13:34:11 +08:00
mSearchViewClearAllAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Clear all searches " ) ,
ui - > searchHistoryPanel ) ;
connect ( mSearchViewClearAllAction , & QAction : : triggered ,
this , & MainWindow : : onSearchViewClearAll ) ;
//breakpoints
2022-12-17 13:34:11 +08:00
mBreakpointViewPropertyAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Breakpoint condition... " ) ,
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewPropertyAction , & QAction : : triggered ,
this , & MainWindow : : onBreakpointViewProperty ) ;
2022-12-17 13:34:11 +08:00
mBreakpointViewRemoveAllAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove All Breakpoints " ) ,
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewRemoveAllAction , & QAction : : triggered ,
this , & MainWindow : : onBreakpointViewRemoveAll ) ;
2022-12-17 13:34:11 +08:00
mBreakpointViewRemoveAction = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove Breakpoint " ) ,
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewRemoveAction , & QAction : : triggered ,
this , & MainWindow : : onBreakpointRemove ) ;
//project
2022-12-17 13:34:11 +08:00
mProject_Rename_Unit = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Rename File " ) ,
ui - > projectView ) ;
connect ( mProject_Rename_Unit , & QAction : : triggered ,
this , & MainWindow : : onProjectRenameUnit ) ;
2022-12-17 13:34:11 +08:00
mProject_Add_Folder = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Add Folder " ) ,
ui - > projectView ) ;
connect ( mProject_Add_Folder , & QAction : : triggered ,
this , & MainWindow : : onProjectAddFolder ) ;
2022-12-17 13:34:11 +08:00
mProject_Rename_Folder = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Rename Folder " ) ,
ui - > projectView ) ;
connect ( mProject_Rename_Folder , & QAction : : triggered ,
this , & MainWindow : : onProjectRenameFolder ) ;
2022-12-17 13:34:11 +08:00
mProject_Remove_Folder = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Remove Folder " ) ,
ui - > projectView ) ;
connect ( mProject_Remove_Folder , & QAction : : triggered ,
this , & MainWindow : : onProjectRemoveFolder ) ;
2022-12-17 13:34:11 +08:00
mProject_SwitchFileSystemViewMode = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Switch to normal view " ) ,
ui - > projectView ) ;
connect ( mProject_SwitchFileSystemViewMode , & QAction : : triggered ,
this , & MainWindow : : onProjectSwitchFileSystemViewMode ) ;
2022-12-17 13:34:11 +08:00
mProject_SwitchCustomViewMode = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Switch to custom view " ) ,
ui - > projectView ) ;
connect ( mProject_SwitchCustomViewMode , & QAction : : triggered ,
this , & MainWindow : : onProjectSwitchCustomViewMode ) ;
//browser
2022-12-17 13:34:11 +08:00
mClassBrowser_Sort_By_Type = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Sort By Type " ) ,
ui - > tabStructure ) ;
mClassBrowser_Sort_By_Type - > setCheckable ( true ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_Sort_By_Name = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Sort alphabetically " ) ,
ui - > tabStructure ) ;
mClassBrowser_Sort_By_Name - > setCheckable ( true ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_Show_Inherited = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Show inherited members " ) ,
ui - > tabStructure ) ;
mClassBrowser_Show_Inherited - > setCheckable ( true ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_goto_declaration = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Goto declaration " ) ,
ui - > tabStructure ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_goto_definition = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Goto definition " ) ,
ui - > tabStructure ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_Show_CurrentFile = createAction (
2022-12-17 11:37:33 +08:00
tr ( " In current file " ) ,
ui - > tabStructure ) ;
mClassBrowser_Show_CurrentFile - > setCheckable ( true ) ;
2022-12-17 13:34:11 +08:00
mClassBrowser_Show_WholeProject = createAction (
2022-12-17 11:37:33 +08:00
tr ( " In current project " ) ,
ui - > tabStructure ) ;
mClassBrowser_Show_WholeProject - > setCheckable ( true ) ;
mClassBrowser_Sort_By_Name - > setChecked ( pSettings - > ui ( ) . classBrowserSortAlpha ( ) ) ;
mClassBrowser_Sort_By_Type - > setChecked ( pSettings - > ui ( ) . classBrowserSortType ( ) ) ;
mClassBrowser_Show_Inherited - > setChecked ( pSettings - > ui ( ) . classBrowserShowInherited ( ) ) ;
connect ( mClassBrowser_Sort_By_Name , & QAction : : toggled ,
this , & MainWindow : : onClassBrowserSortByName ) ;
connect ( mClassBrowser_Sort_By_Type , & QAction : : toggled ,
this , & MainWindow : : onClassBrowserSortByType ) ;
connect ( mClassBrowser_Show_Inherited , & QAction : : toggled ,
this , & MainWindow : : onClassBrowserShowInherited ) ;
connect ( mClassBrowser_goto_definition , & QAction : : triggered ,
this , & MainWindow : : onClassBrowserGotoDefinition ) ;
connect ( mClassBrowser_goto_declaration , & QAction : : triggered ,
this , & MainWindow : : onClassBrowserGotoDeclaration ) ;
connect ( mClassBrowser_Show_CurrentFile , & QAction : : triggered ,
this , & MainWindow : : onClassBrowserChangeScope ) ;
connect ( mClassBrowser_Show_WholeProject , & QAction : : triggered ,
this , & MainWindow : : onClassBrowserChangeScope ) ;
//Files view
2022-12-17 13:34:11 +08:00
mFilesView_CreateFolder = createAction (
2022-12-17 11:37:33 +08:00
tr ( " New Folder " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_CreateFolder , & QAction : : triggered ,
this , & MainWindow : : onFilesViewCreateFolder ) ;
2022-12-17 13:34:11 +08:00
mFilesView_CreateFile = createAction (
2022-12-17 11:37:33 +08:00
tr ( " New File " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_CreateFile , & QAction : : triggered ,
this , & MainWindow : : onFilesViewCreateFile ) ;
2022-12-17 13:34:11 +08:00
mFilesView_Rename = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Rename " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_Rename , & QAction : : triggered ,
this , & MainWindow : : onFilesViewRename ) ;
2022-12-17 13:34:11 +08:00
mFilesView_RemoveFile = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Delete " ) ,
2024-03-04 20:40:13 +08:00
ui - > treeFiles ,
Qt : : Key_Delete ,
Qt : : WidgetShortcut ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_RemoveFile , & QAction : : triggered ,
this , & MainWindow : : onFilesViewRemoveFiles ) ;
2024-03-04 20:40:13 +08:00
2022-12-17 13:34:11 +08:00
mFilesView_Open = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Open in Editor " ) ,
2024-03-04 20:40:13 +08:00
ui - > treeFiles ,
Qt : : Key_Return ,
Qt : : WidgetShortcut ) ;
mFilesView_Open - > setShortcuts (
{ Qt : : Key_Return , Qt : : Key_Enter } ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_Open , & QAction : : triggered ,
this , & MainWindow : : onFilesViewOpen ) ;
2022-12-17 13:34:11 +08:00
mFilesView_OpenWithExternal = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Open in External Program " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
connect ( mFilesView_OpenWithExternal , & QAction : : triggered ,
this , & MainWindow : : onFilesViewOpenWithExternal ) ;
2024-03-04 20:40:13 +08:00
2022-12-17 13:34:11 +08:00
mFilesView_OpenInTerminal = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Open in Terminal " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
mFilesView_OpenInTerminal - > setIcon ( ui - > actionOpen_Terminal - > icon ( ) ) ;
connect ( mFilesView_OpenInTerminal , & QAction : : triggered ,
this , & MainWindow : : onFilesViewOpenInTerminal ) ;
2024-03-04 20:40:13 +08:00
2022-12-17 13:34:11 +08:00
mFilesView_OpenInExplorer = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Open in Windows Explorer " ) ,
2024-03-04 21:11:26 +08:00
ui - > treeFiles ) ;
2022-12-17 11:37:33 +08:00
mFilesView_OpenInExplorer - > setIcon ( ui - > actionOpen_Containing_Folder - > icon ( ) ) ;
connect ( mFilesView_OpenInExplorer , & QAction : : triggered ,
this , & MainWindow : : onFilesViewOpenInExplorer ) ;
//Tools output
2022-12-17 13:34:11 +08:00
mToolsOutput_Clear = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Clear " ) ,
ui - > txtToolsOutput ) ;
connect ( mToolsOutput_Clear , & QAction : : triggered ,
this , & MainWindow : : onToolsOutputClear ) ;
2022-12-17 13:34:11 +08:00
mToolsOutput_Copy = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Copy " ) ,
ui - > txtToolsOutput ) ;
mToolsOutput_Copy - > setShortcut ( QKeySequence ( " Ctrl+C " ) ) ;
connect ( mToolsOutput_Copy , & QAction : : triggered ,
this , & MainWindow : : onToolsOutputCopy ) ;
2022-12-17 13:34:11 +08:00
mToolsOutput_SelectAll = createAction (
2022-12-17 11:37:33 +08:00
tr ( " Select All " ) ,
ui - > txtToolsOutput ) ;
connect ( mToolsOutput_SelectAll , & QAction : : triggered ,
this , & MainWindow : : onToolsOutputSelectAll ) ;
}
void MainWindow : : initToolButtons ( )
{
2022-12-17 13:34:11 +08:00
//problem set toolbuttons
2022-12-17 11:37:33 +08:00
ui - > btnNewProblemSet - > setDefaultAction ( mProblemSet_New ) ;
ui - > btnSaveProblemSet - > setDefaultAction ( mProblemSet_Save ) ;
ui - > btnLoadProblemSet - > setDefaultAction ( mProblemSet_Load ) ;
ui - > btnImportFPS - > setDefaultAction ( mProblemSet_ImportFPS ) ;
ui - > btnExportFPS - > setDefaultAction ( mProblemSet_ExportFPS ) ;
2022-12-17 13:34:11 +08:00
ui - > btnAddProblem - > setDefaultAction ( mProblemSet_AddProblem ) ;
ui - > btnRemoveProblem - > setDefaultAction ( mProblemSet_RemoveProblem ) ;
//problem toolbuttons
ui - > btnAddProblemCase - > setDefaultAction ( mProblem_AddCase ) ;
ui - > btnRemoveProblemCase - > setDefaultAction ( mProblem_RemoveCases ) ;
ui - > btnOpenProblemAnswer - > setDefaultAction ( mProblem_OpenAnswer ) ;
ui - > btnCaseValidateOptions - > setDefaultAction ( mProblem_CaseValidationOptions ) ;
ui - > btnRunAllProblemCases - > setDefaultAction ( mProblem_RunAllCases ) ;
2022-12-17 11:37:33 +08:00
//toolbar for class browser
mClassBrowserToolbar = new QWidget ( ) ;
{
QVBoxLayout * layout = dynamic_cast < QVBoxLayout * > ( ui - > tabStructure - > layout ( ) ) ;
layout - > insertWidget ( 0 , mClassBrowserToolbar ) ;
QHBoxLayout * hlayout = new QHBoxLayout ( ) ;
hlayout - > setContentsMargins ( 2 , 2 , 2 , 2 ) ;
mClassBrowserToolbar - > setLayout ( hlayout ) ;
QToolButton * toolButton ;
2022-12-20 11:01:04 +08:00
int size = calIconSize (
pSettings - > environment ( ) . interfaceFont ( ) ,
pSettings - > environment ( ) . interfaceFontSize ( ) ) * pSettings - > environment ( ) . iconZoomFactor ( ) ;
2022-12-17 11:37:33 +08:00
QSize iconSize ( size , size ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( mClassBrowser_Sort_By_Type ) ;
hlayout - > addWidget ( toolButton ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( mClassBrowser_Sort_By_Name ) ;
hlayout - > addWidget ( toolButton ) ;
QFrame * vLine = new QFrame ( ) ;
vLine - > setFrameShape ( QFrame : : VLine ) ;
vLine - > setFrameShadow ( QFrame : : Sunken ) ;
hlayout - > addWidget ( vLine ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( mClassBrowser_Show_Inherited ) ;
hlayout - > addWidget ( toolButton ) ;
hlayout - > addStretch ( ) ;
}
//toolbar for files view
{
QHBoxLayout * hlayout = dynamic_cast < QHBoxLayout * > ( ui - > panelFiles - > layout ( ) ) ;
QToolButton * toolButton ;
2022-12-20 11:01:04 +08:00
int size = calIconSize (
pSettings - > environment ( ) . interfaceFont ( ) ,
pSettings - > environment ( ) . interfaceFontSize ( ) ) * pSettings - > environment ( ) . iconZoomFactor ( ) ;
2022-12-17 11:37:33 +08:00
QSize iconSize ( size , size ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( ui - > actionOpen_Folder ) ;
hlayout - > addWidget ( toolButton ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( ui - > actionLocate_in_Files_View ) ;
hlayout - > addWidget ( toolButton ) ;
QFrame * vLine = new QFrame ( ) ;
vLine - > setFrameShape ( QFrame : : VLine ) ;
vLine - > setFrameShadow ( QFrame : : Sunken ) ;
hlayout - > addWidget ( vLine ) ;
toolButton = new QToolButton ;
toolButton - > setIconSize ( iconSize ) ;
toolButton - > setDefaultAction ( ui - > actionFilesView_Hide_Non_Support_Files ) ;
ui - > actionFilesView_Hide_Non_Support_Files - > setChecked ( pSettings - > environment ( ) . hideNonSupportFilesInFileView ( ) ) ;
hlayout - > addWidget ( toolButton ) ;
}
}
2021-09-05 13:51:07 +08:00
//static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) {
// action->setParent(scopeWidget);
// action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
//}
2022-12-17 13:34:11 +08:00
QAction * MainWindow : : createAction (
2021-09-05 13:51:07 +08:00
const QString & text ,
QWidget * parent ,
2024-03-04 20:40:13 +08:00
QKeySequence shortcut ,
Qt : : ShortcutContext shortcutContext ) {
2021-09-05 13:51:07 +08:00
QAction * action = new QAction ( text , parent ) ;
if ( ! shortcut . isEmpty ( ) )
action - > setShortcut ( shortcut ) ;
action - > setPriority ( QAction : : HighPriority ) ;
2024-03-04 20:40:13 +08:00
action - > setShortcutContext ( shortcutContext ) ;
2021-09-05 13:51:07 +08:00
parent - > addAction ( action ) ;
return action ;
}
2021-09-11 18:42:49 +08:00
2022-12-17 13:34:11 +08:00
QAction * MainWindow : : createShortcutCustomableAction ( const QString & text , const QString & objectName , QKeySequence shortcut )
{
QAction * action = createAction ( text , this , shortcut ) ;
action - > setObjectName ( objectName ) ;
return action ;
}
2021-09-11 18:42:49 +08:00
void MainWindow : : scanActiveProject ( bool parse )
{
if ( ! mProject )
return ;
2022-10-09 22:19:18 +08:00
if ( ! pSettings - > codeCompletion ( ) . enabled ( ) )
return ;
if ( ! mProject - > cppParser ( ) - > enabled ( ) )
return ;
2022-03-22 19:08:26 +08:00
2021-09-11 18:42:49 +08:00
//UpdateClassBrowsing;
if ( parse ) {
2022-10-18 12:24:59 +08:00
resetCppParser ( mProject - > cppParser ( ) , mProject - > options ( ) . compilerSet ) ;
2021-09-11 18:42:49 +08:00
mProject - > resetParserProjectFiles ( ) ;
parseFileList ( mProject - > cppParser ( ) ) ;
} else {
mProject - > resetParserProjectFiles ( ) ;
} ;
}
2021-10-21 17:31:25 +08:00
void MainWindow : : onBookmarkContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
menu . addAction ( mBookmark_Remove ) ;
menu . addAction ( mBookmark_RemoveAll ) ;
menu . addAction ( mBookmark_Modify ) ;
menu . exec ( ui - > tableBookmark - > mapToGlobal ( pos ) ) ;
}
2023-02-12 22:33:34 +08:00
bool MainWindow : : saveLastOpens ( )
2021-09-27 13:01:01 +08:00
{
2021-09-27 20:17:24 +08:00
QString filename = includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) ) + DEV_LASTOPENS_FILE ;
2022-10-17 23:23:05 +08:00
QJsonObject rootObj ;
2021-09-27 20:17:24 +08:00
if ( mProject ) {
2022-10-17 23:23:05 +08:00
rootObj [ " lastProject " ] = mProject - > filename ( ) ;
2021-09-27 20:17:24 +08:00
}
2022-10-17 23:23:05 +08:00
QJsonArray filesArray ;
2021-09-27 20:17:24 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * editor = ( * mEditorList ) [ i ] ;
2022-10-17 23:23:05 +08:00
QJsonObject fileObj ;
2023-02-12 22:33:34 +08:00
if ( editor - > isNew ( ) ) {
if ( ! editor - > modified ( ) )
continue ;
QMessageBox : : StandardButton reply ;
reply = QMessageBox : : question ( editor , QObject : : tr ( " Save " ) ,
QString ( QObject : : tr ( " Save changes to %1? " ) ) . arg ( editor - > filename ( ) ) ,
QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : Yes | QMessageBox : : Cancel ) ;
if ( reply = = QMessageBox : : No ) {
editor - > setModified ( false ) ;
continue ;
} else if ( reply = = QMessageBox : : Yes ) {
if ( ! editor - > save ( false , false ) ) {
return false ;
}
} else {
return false ;
}
}
2022-10-17 23:23:05 +08:00
fileObj [ " filename " ] = editor - > filename ( ) ;
fileObj [ " onLeft " ] = ( editor - > pageControl ( ) ! = mEditorList - > rightPageWidget ( ) ) ;
fileObj [ " focused " ] = editor - > hasFocus ( ) ;
fileObj [ " caretX " ] = editor - > caretX ( ) ;
fileObj [ " caretY " ] = editor - > caretY ( ) ;
fileObj [ " topLine " ] = editor - > topLine ( ) ;
2024-02-23 17:51:38 +08:00
fileObj [ " left " ] = editor - > leftPos ( ) ;
2022-10-17 23:23:05 +08:00
filesArray . append ( fileObj ) ;
}
rootObj [ " files " ] = filesArray ;
QJsonDocument doc ;
doc . setObject ( rootObj ) ;
QByteArray json = doc . toJson ( ) ;
2023-02-13 19:21:11 +08:00
QFile file ( filename ) ;
if ( ! file . open ( QFile : : WriteOnly | QFile : : Truncate ) ) {
QMessageBox : : critical ( this ,
tr ( " Save last open info error " ) ,
tr ( " Can't open last open information file '%1' for write! " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
return true ;
}
2022-10-17 23:23:05 +08:00
if ( file . write ( doc . toJson ( ) ) ! = json . count ( ) ) {
2021-09-27 20:17:24 +08:00
QMessageBox : : critical ( this ,
tr ( " Save last open info error " ) ,
tr ( " Can't save last open info file '%1' " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
2023-02-12 22:33:34 +08:00
return true ;
2021-09-27 20:17:24 +08:00
}
2022-10-17 23:23:05 +08:00
file . close ( ) ;
2023-02-12 22:33:34 +08:00
return true ;
2021-09-27 13:01:01 +08:00
}
void MainWindow : : loadLastOpens ( )
{
2023-08-11 13:49:09 +08:00
mOpeningFiles = true ;
auto action = finally ( [ this ] {
mOpeningFiles = false ;
} ) ;
2021-09-27 20:17:24 +08:00
QString filename = includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) ) + DEV_LASTOPENS_FILE ;
if ( ! fileExists ( filename ) )
return ;
2022-10-17 23:23:05 +08:00
QFile file ( filename ) ;
if ( ! file . open ( QFile : : ReadOnly ) ) {
2021-09-27 20:17:24 +08:00
QMessageBox : : critical ( this ,
tr ( " Load last open info error " ) ,
tr ( " Can't load last open info file '%1' " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
return ;
}
2022-10-17 23:23:05 +08:00
QJsonParseError error ;
QJsonDocument doc = QJsonDocument : : fromJson ( file . readAll ( ) , & error ) ;
if ( error . error ! = QJsonParseError : : NoError ) {
QMessageBox : : critical ( this ,
tr ( " Load last open info error " ) ,
tr ( " Can't load last open info file '%1' " )
. arg ( filename ) + " : <BR/> "
+ QString ( " %1 " ) . arg ( error . errorString ( ) ) ,
QMessageBox : : Ok ) ;
return ;
}
QJsonObject rootObj = doc . object ( ) ;
QString projectFilename = rootObj [ " lastProject " ] . toString ( ) ;
if ( ! projectFilename . isEmpty ( ) ) {
2022-01-13 16:47:48 +08:00
openProject ( projectFilename , false ) ;
}
2022-10-17 23:23:05 +08:00
QJsonArray filesArray = rootObj [ " files " ] . toArray ( ) ;
2022-01-13 16:47:48 +08:00
Editor * focusedEditor = nullptr ;
2022-10-17 23:23:05 +08:00
for ( int i = 0 ; i < filesArray . count ( ) ; i + + ) {
QJsonObject fileObj = filesArray [ i ] . toObject ( ) ;
QString editorFilename = fileObj [ " filename " ] . toString ( " " ) ;
2021-09-27 20:17:24 +08:00
if ( ! fileExists ( editorFilename ) )
continue ;
2022-10-17 23:23:05 +08:00
bool onLeft = fileObj [ " onLeft " ] . toBool ( ) ;
2021-10-20 18:05:43 +08:00
QTabWidget * page ;
if ( onLeft )
page = mEditorList - > leftPageWidget ( ) ;
else
page = mEditorList - > rightPageWidget ( ) ;
2022-01-18 12:41:11 +08:00
PProjectUnit unit ;
2022-01-13 17:15:57 +08:00
if ( mProject ) {
2022-10-01 08:54:44 +08:00
unit = mProject - > findUnit ( editorFilename ) ;
2022-01-13 17:15:57 +08:00
}
2022-01-18 12:41:11 +08:00
bool inProject = ( mProject & & unit ) ;
2022-03-12 17:37:53 +08:00
QByteArray encoding = unit ? unit - > encoding ( ) :
( pSettings - > editor ( ) . autoDetectFileEncoding ( ) ? ENCODING_AUTO_DETECT : pSettings - > editor ( ) . defaultEncoding ( ) ) ;
2022-10-09 22:19:18 +08:00
Project * pProject = ( inProject ? mProject . get ( ) : nullptr ) ;
2023-02-07 10:46:06 +08:00
if ( pProject & & encoding = = ENCODING_PROJECT )
encoding = pProject - > options ( ) . encoding ;
2022-10-09 22:19:18 +08:00
Editor * editor = mEditorList - > newEditor ( editorFilename , encoding , pProject , false , page ) ;
2022-10-08 23:30:30 +08:00
if ( inProject & & editor ) {
mProject - > loadUnitLayout ( editor ) ;
}
2022-01-18 12:41:11 +08:00
// if (mProject) {
2022-02-01 16:17:28 +08:00
// mProject->associateEditorToUnit(editor,unit);
2022-01-18 12:41:11 +08:00
// }
2022-02-01 16:17:28 +08:00
if ( ! editor )
continue ;
2022-09-25 09:55:18 +08:00
QSynedit : : BufferCoord pos ;
2022-10-17 23:23:05 +08:00
pos . ch = fileObj [ " caretX " ] . toInt ( 1 ) ;
pos . line = fileObj [ " caretY " ] . toInt ( 1 ) ;
2021-09-27 20:17:24 +08:00
editor - > setCaretXY ( pos ) ;
editor - > setTopLine (
2022-10-17 23:23:05 +08:00
fileObj [ " topLine " ] . toInt ( 1 )
2021-09-27 20:17:24 +08:00
) ;
2024-02-23 17:51:38 +08:00
editor - > setLeftPos (
fileObj [ " left " ] . toInt ( 1 )
2021-09-27 20:17:24 +08:00
) ;
2022-10-17 23:23:05 +08:00
if ( fileObj [ " focused " ] . toBool ( false ) )
2021-09-27 20:17:24 +08:00
focusedEditor = editor ;
2022-10-17 23:23:05 +08:00
//mVisitHistoryManager->removeFile(editorFilename);
2021-09-27 20:17:24 +08:00
}
2022-10-11 21:51:33 +08:00
if ( mProject & & mEditorList - > pageCount ( ) = = 0 ) {
2022-10-09 22:19:18 +08:00
mProject - > doAutoOpen ( ) ;
2022-10-11 21:51:33 +08:00
updateEditorBookmarks ( ) ;
2022-10-17 23:23:05 +08:00
updateEditorBreakpoints ( ) ;
2022-10-11 21:51:33 +08:00
}
2022-10-17 23:23:05 +08:00
if ( mEditorList - > pageCount ( ) > 0 ) {
2021-09-27 20:17:24 +08:00
updateEditorActions ( ) ;
2022-08-24 17:05:16 +08:00
//updateForEncodingInfo();
2021-09-27 20:17:24 +08:00
}
2023-08-11 13:49:09 +08:00
if ( ! focusedEditor ) {
focusedEditor = mEditorList - > getEditor ( ) ;
}
if ( focusedEditor ) {
focusedEditor - > reparse ( false ) ;
focusedEditor - > checkSyntaxInBack ( ) ;
focusedEditor - > reparseTodo ( ) ;
2021-09-27 20:17:24 +08:00
focusedEditor - > activate ( ) ;
2023-08-11 13:49:09 +08:00
}
2021-09-27 13:01:01 +08:00
}
2021-10-08 00:06:41 +08:00
void MainWindow : : updateTools ( )
{
ui - > menuTools - > clear ( ) ;
ui - > menuTools - > addAction ( ui - > actionOptions ) ;
if ( ! mToolsManager - > tools ( ) . isEmpty ( ) ) {
ui - > menuTools - > addSeparator ( ) ;
foreach ( const PToolItem & item , mToolsManager - > tools ( ) ) {
2021-12-09 21:04:53 +08:00
QAction * action = new QAction ( item - > title , ui - > menuTools ) ;
2021-10-08 00:06:41 +08:00
connect ( action , & QAction : : triggered ,
2021-12-09 08:10:14 +08:00
[ item ] ( ) {
2024-02-28 19:41:05 +08:00
QMap < QString , QString > macros = devCppMacroVariables ( ) ;
QString program = parseMacros ( item - > program , macros ) ;
QString workDir = parseMacros ( item - > workingDirectory , macros ) ;
QStringList params = parseArguments ( item - > parameters , macros , true ) ;
2021-12-09 11:22:28 +08:00
if ( ! program . endsWith ( " .bat " , Qt : : CaseInsensitive ) ) {
QTemporaryFile file ( QDir : : tempPath ( ) + QDir : : separator ( ) + " XXXXXX.bat " ) ;
file . setAutoRemove ( false ) ;
if ( file . open ( ) ) {
2024-02-28 19:41:05 +08:00
file . write ( escapeCommandForPlatformShell (
" cd " , { " /d " , localizePath ( workDir ) }
) . toLocal8Bit ( ) + LINE_BREAKER ) ;
file . write ( escapeCommandForPlatformShell ( program , params ) . toLocal8Bit ( )
2021-12-09 11:22:28 +08:00
+ LINE_BREAKER ) ;
file . close ( ) ;
if ( item - > pauseAfterExit ) {
executeFile (
2022-12-30 09:06:39 +08:00
includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appLibexecDir ( ) ) + CONSOLE_PAUSER ,
2024-02-28 19:41:05 +08:00
{ " 1 " , localizePath ( file . fileName ( ) ) } ,
2021-12-09 11:22:28 +08:00
workDir , file . fileName ( ) ) ;
} else {
executeFile (
file . fileName ( ) ,
2024-02-28 19:41:05 +08:00
{ } ,
2021-12-09 11:22:28 +08:00
workDir , file . fileName ( ) ) ;
}
}
2021-12-09 08:10:14 +08:00
} else {
2021-12-09 09:27:46 +08:00
if ( item - > pauseAfterExit ) {
executeFile (
2022-12-30 09:06:39 +08:00
includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appLibexecDir ( ) ) + CONSOLE_PAUSER ,
2024-02-28 19:41:05 +08:00
QStringList { " 1 " , program } + params ,
2021-12-09 11:22:28 +08:00
workDir , " " ) ;
2021-12-09 09:27:46 +08:00
} else {
executeFile (
program ,
2021-12-09 11:22:28 +08:00
params ,
workDir , " " ) ;
2021-12-09 09:27:46 +08:00
}
2021-12-09 08:10:14 +08:00
}
2021-12-09 11:22:28 +08:00
2021-10-08 00:06:41 +08:00
} ) ;
ui - > menuTools - > addAction ( action ) ;
}
}
}
2023-02-12 22:33:34 +08:00
void MainWindow : : newEditor ( const QString & suffix )
2021-10-03 09:57:19 +08:00
{
try {
2023-08-11 17:09:30 +08:00
QString filename ;
do {
filename = QString ( " untitled%1 " ) . arg ( getNewFileNumber ( ) ) ;
if ( suffix . isEmpty ( ) ) {
2023-08-13 14:46:53 +08:00
if ( pSettings - > editor ( ) . defaultFileCpp ( ) ) {
Settings : : PCompilerSet compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
if ( compilerSet & & ! compilerSet - > canCompileCPP ( ) ) {
filename + = " .c " ;
} else {
filename + = " .cpp " ;
}
} else
2023-08-11 17:09:30 +08:00
filename + = " .c " ;
} else
filename + = " . " + suffix ;
} while ( mEditorList - > hasFilename ( filename ) ) ;
2023-02-12 22:33:34 +08:00
Editor * editor = mEditorList - > newEditor ( filename ,
2022-03-12 17:37:53 +08:00
pSettings - > editor ( ) . defaultEncoding ( ) ,
2022-10-09 22:19:18 +08:00
nullptr , true ) ;
2021-10-03 09:57:19 +08:00
editor - > activate ( ) ;
2022-08-24 17:05:16 +08:00
//updateForEncodingInfo();
2021-10-03 09:57:19 +08:00
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
}
2021-08-31 11:13:12 +08:00
void MainWindow : : buildContextMenus ( )
{
2022-12-17 11:37:33 +08:00
2021-11-04 09:07:06 +08:00
//context menu signal for the problem list view
ui - > lstProblemSet - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > lstProblemSet , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onLstProblemSetContextMenu ) ;
2022-12-13 08:49:20 +08:00
2022-12-17 11:37:33 +08:00
//context menu signal for the problem cases list view
2022-03-30 19:28:46 +08:00
ui - > tblProblemCases - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tblProblemCases , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onTableProblemCasesContextMenu ) ;
2021-11-06 16:22:26 +08:00
2021-09-05 19:10:54 +08:00
//context menu signal for the watch view
2021-09-03 00:26:49 +08:00
ui - > watchView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > watchView , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onWatchViewContextMenu ) ;
2021-09-05 13:51:07 +08:00
2021-10-21 17:31:25 +08:00
//context menu signal for the bookmark view
ui - > tableBookmark - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tableBookmark , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onBookmarkContextMenu ) ;
2022-12-17 11:37:33 +08:00
//context menu signal for the debug console
ui - > debugConsole - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > debugConsole , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onDebugConsoleContextMenu ) ;
2021-10-02 17:01:08 +08:00
2021-09-05 19:10:54 +08:00
//context menu signal for Editor's tabbar
2021-09-05 05:01:31 +08:00
ui - > EditorTabsLeft - > tabBar ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2021-10-02 21:46:34 +08:00
connect ( ui - > EditorTabsLeft - > tabBar ( ) ,
& QWidget : : customContextMenuRequested ,
this ,
2021-10-13 11:32:59 +08:00
& MainWindow : : onEditorLeftTabContextMenu
2021-10-02 21:46:34 +08:00
) ;
2021-09-05 05:01:31 +08:00
ui - > EditorTabsRight - > tabBar ( ) - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2021-10-02 21:46:34 +08:00
connect ( ui - > EditorTabsRight - > tabBar ( ) ,
& QWidget : : customContextMenuRequested ,
this ,
2021-10-13 11:32:59 +08:00
& MainWindow : : onEditorRightTabContextMenu
2021-10-02 21:46:34 +08:00
) ;
2021-09-03 00:26:49 +08:00
2021-09-05 19:10:54 +08:00
//context menu signal for Compile Issue view
2021-09-05 13:51:07 +08:00
ui - > tableIssues - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tableIssues , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onTableIssuesContextMenu ) ;
2021-09-05 21:05:38 +08:00
//context menu signal for search view
2022-12-17 11:37:33 +08:00
ui - > tabSearch - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tabSearch , & QWidget : : customContextMenuRequested ,
2021-09-05 21:05:38 +08:00
this , & MainWindow : : onSearchViewContextMenu ) ;
2021-09-05 22:16:54 +08:00
//context menu signal for breakpoints view
ui - > tblBreakpoints - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tblBreakpoints , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onBreakpointsViewContextMenu ) ;
2021-09-17 22:58:58 +08:00
//context menu signal for project view
ui - > projectView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > projectView , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onProjectViewContextMenu ) ;
2021-09-26 12:19:46 +08:00
//context menu signal for class browser
2021-09-26 16:25:17 +08:00
ui - > tabStructure - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > tabStructure , & QWidget : : customContextMenuRequested ,
2021-09-26 12:19:46 +08:00
this , & MainWindow : : onClassBrowserContextMenu ) ;
2021-10-15 10:23:46 +08:00
//menu for statusbar
mFileEncodingStatus - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( mFileEncodingStatus , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onFileEncodingContextMenu ) ;
2021-10-22 07:42:51 +08:00
2021-10-22 15:02:54 +08:00
//menu for files view
ui - > treeFiles - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > treeFiles , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onFilesViewContextMenu ) ;
2022-02-08 16:36:20 +08:00
2022-02-10 12:03:56 +08:00
//context menu signal for class browser
ui - > txtToolsOutput - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > txtToolsOutput , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onToolsOutputContextMenu ) ;
2021-08-31 11:13:12 +08:00
}
2021-09-28 22:26:12 +08:00
void MainWindow : : buildEncodingMenu ( )
{
QMenu * menuCharsets = new QMenu ( ) ;
menuCharsets - > setTitle ( tr ( " Character sets " ) ) ;
QStringList languages = pCharsetInfoManager - > languageNames ( ) ;
foreach ( const QString & langName , languages ) {
QMenu * menuLang = new QMenu ( ) ;
menuLang - > setTitle ( langName ) ;
menuCharsets - > addMenu ( menuLang ) ;
QList < PCharsetInfo > charInfos = pCharsetInfoManager - > findCharsetsByLanguageName ( langName ) ;
connect ( menuLang , & QMenu : : aboutToShow ,
[ langName , menuLang , this ] ( ) {
menuLang - > clear ( ) ;
Editor * editor = mEditorList - > getEditor ( ) ;
QList < PCharsetInfo > charInfos = pCharsetInfoManager - > findCharsetsByLanguageName ( langName ) ;
foreach ( const PCharsetInfo & info , charInfos ) {
QAction * action = new QAction ( info - > name ) ;
action - > setCheckable ( true ) ;
if ( editor )
action - > setChecked ( info - > name = = editor - > encodingOption ( ) ) ;
connect ( action , & QAction : : triggered ,
[ info , this ] ( ) {
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor = = nullptr )
return ;
try {
editor - > setEncodingOption ( info - > name ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
} ) ;
menuLang - > addAction ( action ) ;
}
} ) ;
}
mMenuEncoding = new QMenu ( ) ;
mMenuEncoding - > setTitle ( tr ( " File Encoding " ) ) ;
2023-01-24 11:31:30 +08:00
mMenuEncoding - > addAction ( ui - > actionAuto_Detect ) ;
2021-09-28 22:26:12 +08:00
mMenuEncoding - > addAction ( ui - > actionEncode_in_ANSI ) ;
mMenuEncoding - > addAction ( ui - > actionEncode_in_UTF_8 ) ;
2022-05-06 15:23:41 +08:00
mMenuEncoding - > addAction ( ui - > actionEncode_in_UTF_8_BOM ) ;
2021-09-28 22:26:12 +08:00
mMenuEncoding - > addMenu ( menuCharsets ) ;
mMenuEncoding - > addSeparator ( ) ;
mMenuEncoding - > addAction ( ui - > actionConvert_to_ANSI ) ;
mMenuEncoding - > addAction ( ui - > actionConvert_to_UTF_8 ) ;
2022-05-06 15:23:41 +08:00
mMenuEncoding - > addAction ( ui - > actionConvert_to_UTF_8_BOM ) ;
2021-09-28 22:26:12 +08:00
2022-03-13 20:54:50 +08:00
QList < PCharsetInfo > charsetsForLocale = pCharsetInfoManager - > findCharsetByLocale ( pCharsetInfoManager - > localeName ( ) ) ;
foreach ( const PCharsetInfo & charset , charsetsForLocale ) {
QAction * action = new QAction (
tr ( " Convert to %1 " ) . arg ( QString ( charset - > name ) ) ) ;
connect ( action , & QAction : : triggered ,
[ charset , this ] ( ) {
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 ( charset - > name ) ) ,
QMessageBox : : Yes , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
editor - > convertToEncoding ( charset - > name ) ;
} ) ;
mMenuEncoding - > addAction ( action ) ;
}
2021-09-28 22:26:12 +08:00
ui - > menuEdit - > insertMenu ( ui - > actionFoldAll , mMenuEncoding ) ;
ui - > menuEdit - > insertSeparator ( ui - > actionFoldAll ) ;
2023-01-24 10:21:19 +08:00
//ui->actionAuto_Detect->setCheckable(true);
2021-09-28 22:26:12 +08:00
ui - > actionEncode_in_ANSI - > setCheckable ( true ) ;
ui - > actionEncode_in_UTF_8 - > setCheckable ( true ) ;
2022-05-06 15:23:41 +08:00
ui - > actionEncode_in_UTF_8_BOM - > setCheckable ( true ) ;
2021-09-28 22:26:12 +08:00
}
2023-01-04 11:01:34 +08:00
void MainWindow : : buildNewlineMenu ( )
{
mMenuNewline = new QMenu ( this ) ;
mMenuNewline - > setTitle ( tr ( " Newline " ) ) ;
}
2021-09-02 20:12:16 +08:00
void MainWindow : : maximizeEditor ( )
{
2022-05-22 14:31:13 +08:00
if ( ui - > tabExplorer - > isShrinked ( ) & & ui - > tabExplorer - > isShrinked ( ) ) {
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
stretchExplorerPanel ( true ) ;
2021-09-02 20:12:16 +08:00
} else {
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( false ) ;
stretchExplorerPanel ( false ) ;
2021-09-02 20:12:16 +08:00
}
}
2022-06-16 21:34:31 +08:00
QStringList MainWindow : : getBinDirsForCurrentEditor ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
if ( e - > inProject ( ) & & mProject ) {
return mProject - > binDirs ( ) ;
} else {
return getDefaultCompilerSetBinDirs ( ) ;
}
} else if ( mProject ) {
return mProject - > binDirs ( ) ;
}
return QStringList ( ) ;
}
QStringList MainWindow : : getDefaultCompilerSetBinDirs ( )
{
if ( pSettings - > compilerSets ( ) . defaultSet ( ) )
return pSettings - > compilerSets ( ) . defaultSet ( ) - > binDirs ( ) ;
return QStringList ( ) ;
}
void MainWindow : : openShell ( const QString & folder , const QString & shellCommand , const QStringList & binDirs )
2021-09-03 16:39:20 +08:00
{
QProcess process ;
process . setWorkingDirectory ( folder ) ;
process . setProgram ( shellCommand ) ;
2021-12-24 23:18:20 +08:00
# ifdef Q_OS_WIN
2021-09-03 16:39:20 +08:00
process . setCreateProcessArgumentsModifier ( [ ] ( QProcess : : CreateProcessArguments * args ) {
args - > flags | = CREATE_NEW_CONSOLE ;
args - > startupInfo - > dwFlags & = ~ STARTF_USESTDHANDLES ; //
} ) ;
QProcessEnvironment env = QProcessEnvironment : : systemEnvironment ( ) ;
QString path = env . value ( " PATH " ) ;
2021-09-14 12:10:43 +08:00
QStringList pathAdded ;
2022-06-16 21:34:31 +08:00
pathAdded . append ( binDirs ) ;
2021-12-26 15:08:54 +08:00
pathAdded . append ( pSettings - > dirs ( ) . appDir ( ) ) ;
2021-09-14 12:10:43 +08:00
if ( ! path . isEmpty ( ) ) {
2021-09-17 19:58:37 +08:00
path = pathAdded . join ( PATH_SEPARATOR ) + PATH_SEPARATOR + path ;
2021-09-14 12:10:43 +08:00
} else {
path = pathAdded . join ( PATH_SEPARATOR ) ;
}
2021-09-03 16:39:20 +08:00
env . insert ( " PATH " , path ) ;
process . setProcessEnvironment ( env ) ;
2023-09-27 13:57:39 +08:00
# endif
2021-09-03 16:39:20 +08:00
process . startDetached ( ) ;
}
2021-08-30 22:05:45 +08:00
void MainWindow : : onAutoSaveTimeout ( )
{
2021-10-17 21:09:50 +08:00
if ( mQuitting )
return ;
2021-08-30 22:05:45 +08:00
if ( ! pSettings - > editor ( ) . enableAutoSave ( ) )
return ;
2023-01-26 11:33:27 +08:00
mAutoSaveTimer . stop ( ) ;
{
auto action = finally ( [ this ] {
mAutoSaveTimer . start ( pSettings - > editor ( ) . autoSaveInterval ( ) * 60 * 1000 ) ;
} ) ;
int updateCount = 0 ;
switch ( pSettings - > editor ( ) . autoSaveTarget ( ) ) {
case astCurrentFile : {
Editor * e = mEditorList - > getEditor ( ) ;
2021-08-30 22:05:45 +08:00
doAutoSave ( e ) ;
updateCount + + ;
}
2023-01-26 11:33:27 +08:00
break ;
case astAllOpennedFiles :
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
doAutoSave ( e ) ;
updateCount + + ;
}
break ;
case astAllProjectFiles :
if ( ! mProject )
2021-10-17 21:09:50 +08:00
return ;
2023-01-26 11:33:27 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( ! e - > inProject ( ) )
return ;
doAutoSave ( e ) ;
updateCount + + ;
}
//todo: auto save project files
break ;
2021-10-17 21:09:50 +08:00
}
2023-01-26 11:33:27 +08:00
updateStatusbarMessage ( tr ( " %1 files autosaved " ) . arg ( updateCount ) ) ;
2021-08-30 22:05:45 +08:00
}
}
2021-09-03 00:26:49 +08:00
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 ) ) ;
}
2021-09-05 13:51:07 +08:00
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 ) ) ;
}
2021-09-05 21:05:38 +08:00
void MainWindow : : onSearchViewContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
menu . addAction ( mSearchViewClearAction ) ;
menu . addAction ( mSearchViewClearAllAction ) ;
2022-12-17 11:37:33 +08:00
mSearchViewClearAction - > setEnabled ( ui - > cbSearchHistory - > currentIndex ( ) > 0 ) ;
mSearchViewClearAction - > setEnabled ( mSearchResultListModel - > rowCount ( QModelIndex ( ) ) > 0 ) ;
2021-09-05 21:05:38 +08:00
menu . exec ( ui - > searchHistoryPanel - > mapToGlobal ( pos ) ) ;
}
2021-09-05 22:16:54 +08:00
void MainWindow : : onBreakpointsViewContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
menu . addAction ( mBreakpointViewPropertyAction ) ;
menu . addAction ( mBreakpointViewRemoveAllAction ) ;
2021-10-27 16:58:30 +08:00
menu . addAction ( mBreakpointViewRemoveAction ) ;
mBreakpointViewPropertyAction - > setEnabled ( ui - > tblBreakpoints - > currentIndex ( ) . isValid ( ) ) ;
mBreakpointViewRemoveAction - > setEnabled ( ui - > tblBreakpoints - > currentIndex ( ) . isValid ( ) ) ;
2021-09-05 22:16:54 +08:00
menu . exec ( ui - > tblBreakpoints - > mapToGlobal ( pos ) ) ;
}
2021-09-17 22:58:58 +08:00
void MainWindow : : onProjectViewContextMenu ( const QPoint & pos )
{
if ( ! mProject )
return ;
bool onFolder = false ;
bool onUnit = false ;
bool onRoot = false ;
bool folderEmpty = false ;
2022-02-15 21:39:17 +08:00
bool multiSelection = ui - > projectView - > selectionModel ( ) - > selectedRows ( ) . count ( ) > 1 ;
2022-01-08 08:52:50 +08:00
QModelIndex current = mProjectProxyModel - > mapToSource ( ui - > projectView - > selectionModel ( ) - > currentIndex ( ) ) ;
2021-09-17 22:58:58 +08:00
if ( current . isValid ( ) & & mProject ) {
2022-02-08 00:24:08 +08:00
ProjectModelNode * node = static_cast < ProjectModelNode * > ( current . internalPointer ( ) ) ;
PProjectModelNode pNode = mProject - > pointerToNode ( node ) ;
2021-09-17 22:58:58 +08:00
if ( pNode ) {
2022-10-08 23:30:30 +08:00
onFolder = ( ! pNode - > isUnit ) ;
onUnit = ( pNode - > isUnit ) ;
2021-09-18 10:47:35 +08:00
onRoot = false ;
2021-09-17 22:58:58 +08:00
if ( onFolder & & ! onRoot ) {
folderEmpty = pNode - > children . isEmpty ( ) ;
}
2021-09-18 10:47:35 +08:00
} else {
onFolder = true ;
onRoot = true ;
2021-09-17 22:58:58 +08:00
}
}
2022-02-15 00:01:50 +08:00
2021-09-17 22:58:58 +08:00
QMenu menu ( this ) ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
QMenu vcsMenu ( this ) ;
2023-08-08 14:41:23 +08:00
QString branch ;
GitManager vcsManager ;
bool hasRepository = vcsManager . hasRepository ( mProject - > folder ( ) , branch ) ;
# endif
2021-09-17 22:58:58 +08:00
updateProjectActions ( ) ;
menu . addAction ( ui - > actionProject_New_File ) ;
2022-02-01 16:17:28 +08:00
menu . addAction ( ui - > actionNew_Class ) ;
menu . addAction ( ui - > actionNew_Header ) ;
2021-09-17 22:58:58 +08:00
menu . addAction ( ui - > actionAdd_to_project ) ;
2021-09-18 10:47:35 +08:00
if ( ! onFolder ) {
menu . addAction ( ui - > actionRemove_from_project ) ;
}
2022-02-15 21:39:17 +08:00
if ( onUnit & & ! multiSelection ) {
2021-09-17 22:58:58 +08:00
menu . addAction ( mProject_Rename_Unit ) ;
}
menu . addSeparator ( ) ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) ) {
if ( hasRepository ) {
menu . addMenu ( & vcsMenu ) ;
} else {
ui - > actionGit_Create_Repository - > setEnabled ( true ) ;
menu . addAction ( ui - > actionGit_Create_Repository ) ;
}
menu . addSeparator ( ) ;
}
2023-08-08 14:41:23 +08:00
# endif
2022-02-08 12:33:10 +08:00
if ( onFolder & & mProject - > modelType ( ) = = ProjectModelType : : Custom ) {
2021-09-17 22:58:58 +08:00
menu . addAction ( mProject_Add_Folder ) ;
if ( ! onRoot ) {
menu . addAction ( mProject_Rename_Folder ) ;
if ( folderEmpty ) {
menu . addAction ( mProject_Remove_Folder ) ;
}
}
menu . addSeparator ( ) ;
}
2021-09-18 10:47:35 +08:00
menu . addAction ( ui - > actionProject_Open_Folder_In_Explorer ) ;
menu . addAction ( ui - > actionProject_Open_In_Terminal ) ;
menu . addSeparator ( ) ;
2022-02-08 12:33:10 +08:00
if ( mProject - > modelType ( ) = = ProjectModelType : : Custom ) {
menu . addAction ( mProject_SwitchFileSystemViewMode ) ;
} else {
menu . addAction ( mProject_SwitchCustomViewMode ) ;
}
2021-09-17 22:58:58 +08:00
menu . addAction ( ui - > actionProject_options ) ;
2022-02-23 13:17:57 +08:00
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionClose_Project ) ;
2021-09-17 22:58:58 +08:00
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) & & hasRepository ) {
2022-02-21 11:37:29 +08:00
mProject - > model ( ) - > iconProvider ( ) - > update ( ) ;
2022-02-15 21:39:17 +08:00
vcsMenu . setTitle ( tr ( " Version Control " ) ) ;
if ( ui - > projectView - > selectionModel ( ) - > hasSelection ( ) ) {
bool shouldAdd = true ;
foreach ( const QModelIndex & index , ui - > projectView - > selectionModel ( ) - > selectedRows ( ) ) {
if ( ! index . isValid ( ) ) {
shouldAdd = false ;
break ;
}
QModelIndex realIndex = mProjectProxyModel - > mapToSource ( index ) ;
ProjectModelNode * node = static_cast < ProjectModelNode * > ( realIndex . internalPointer ( ) ) ;
2022-10-08 23:30:30 +08:00
if ( ! node | | ! node - > isUnit ) {
2022-02-15 21:39:17 +08:00
shouldAdd = false ;
break ;
}
2022-10-08 23:30:30 +08:00
PProjectUnit pUnit = node - > pUnit . lock ( ) ;
2022-02-15 21:39:17 +08:00
if ( mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > isFileInRepository (
pUnit - > fileName ( )
2022-02-21 11:37:29 +08:00
)
& &
! mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > isFileConflicting (
pUnit - > fileName ( )
) ) {
2022-02-15 21:39:17 +08:00
shouldAdd = false ;
break ;
}
}
if ( shouldAdd )
vcsMenu . addAction ( ui - > actionGit_Add_Files ) ;
}
2022-02-24 11:07:37 +08:00
vcsMenu . addAction ( ui - > actionGit_Remotes ) ;
2022-02-21 23:35:28 +08:00
vcsMenu . addAction ( ui - > actionGit_Log ) ;
2022-02-19 20:38:08 +08:00
vcsMenu . addAction ( ui - > actionGit_Branch ) ;
2022-02-20 21:47:57 +08:00
vcsMenu . addAction ( ui - > actionGit_Merge ) ;
2022-02-15 00:01:50 +08:00
vcsMenu . addAction ( ui - > actionGit_Commit ) ;
2022-02-15 21:39:17 +08:00
vcsMenu . addAction ( ui - > actionGit_Restore ) ;
2022-02-15 00:01:50 +08:00
2023-08-08 14:41:23 +08:00
bool canBranch = false ;
canBranch = ! mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasChangedFiles ( )
2022-02-21 09:48:04 +08:00
& & ! mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasStagedFiles ( ) ;
2022-02-21 23:35:28 +08:00
ui - > actionGit_Branch - > setEnabled ( canBranch ) ;
2022-02-20 21:47:57 +08:00
ui - > actionGit_Merge - > setEnabled ( canBranch ) ;
2022-02-21 23:35:28 +08:00
ui - > actionGit_Commit - > setEnabled ( true ) ;
2022-02-24 11:07:37 +08:00
ui - > actionGit_Remotes - > setEnabled ( true ) ;
2022-02-21 23:35:28 +08:00
ui - > actionGit_Log - > setEnabled ( true ) ;
2022-02-15 21:39:17 +08:00
ui - > actionGit_Restore - > setEnabled ( true ) ;
// vcsMenu.addAction(ui->actionGit_Reset);
// vcsMenu.addAction(ui->actionGit_Revert);
// ui->actionGit_Reset->setEnabled(true);
// ui->actionGit_Revert->setEnabled(true);
2022-02-15 00:01:50 +08:00
}
2023-08-08 14:41:23 +08:00
# endif
2021-09-17 22:58:58 +08:00
menu . exec ( ui - > projectView - > mapToGlobal ( pos ) ) ;
}
2021-09-26 16:25:17 +08:00
void MainWindow : : onClassBrowserContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
bool canGoto = false ;
QModelIndex index = ui - > classBrowser - > currentIndex ( ) ;
if ( index . isValid ( ) ) {
ClassBrowserNode * node = static_cast < ClassBrowserNode * > ( index . internalPointer ( ) ) ;
if ( node ) {
PStatement statement = node - > statement ;
if ( statement ) {
canGoto = true ;
}
}
}
mClassBrowser_goto_declaration - > setEnabled ( canGoto ) ;
mClassBrowser_goto_definition - > setEnabled ( canGoto ) ;
menu . addAction ( mClassBrowser_goto_declaration ) ;
menu . addAction ( mClassBrowser_goto_definition ) ;
menu . addSeparator ( ) ;
menu . addAction ( mClassBrowser_Sort_By_Name ) ;
menu . addAction ( mClassBrowser_Sort_By_Type ) ;
menu . addAction ( mClassBrowser_Show_Inherited ) ;
2022-10-23 15:22:26 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
2022-11-07 11:24:23 +08:00
if ( ( editor & & editor - > inProject ( ) ) | | mProject ) {
2022-10-23 15:22:26 +08:00
menu . addSeparator ( ) ;
menu . addAction ( mClassBrowser_Show_CurrentFile ) ;
menu . addAction ( mClassBrowser_Show_WholeProject ) ;
2022-11-07 11:24:23 +08:00
2022-10-23 15:22:26 +08:00
if ( mProject ) {
mClassBrowser_Show_CurrentFile - > setChecked ( mProject - > options ( ) . classBrowserType = = ProjectClassBrowserType : : CurrentFile ) ;
mClassBrowser_Show_WholeProject - > setChecked ( mProject - > options ( ) . classBrowserType = = ProjectClassBrowserType : : WholeProject ) ;
}
}
2021-09-26 16:25:17 +08:00
menu . exec ( ui - > projectView - > mapToGlobal ( pos ) ) ;
}
2021-10-02 17:01:08 +08:00
void MainWindow : : onDebugConsoleContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
2021-11-25 10:18:21 +08:00
bool oldBlock = mDebugConsole_ShowDetailLog - > blockSignals ( true ) ;
mDebugConsole_ShowDetailLog - > setChecked ( pSettings - > debugger ( ) . showDetailLog ( ) ) ;
mDebugConsole_ShowDetailLog - > blockSignals ( oldBlock ) ;
2021-10-02 17:01:08 +08:00
menu . addAction ( mDebugConsole_Copy ) ;
menu . addAction ( mDebugConsole_Paste ) ;
menu . addAction ( mDebugConsole_SelectAll ) ;
menu . addAction ( mDebugConsole_Clear ) ;
menu . addSeparator ( ) ;
2021-11-25 10:18:21 +08:00
menu . addAction ( mDebugConsole_ShowDetailLog ) ;
2021-10-02 17:01:08 +08:00
menu . exec ( ui - > debugConsole - > mapToGlobal ( pos ) ) ;
}
2021-10-15 10:23:46 +08:00
void MainWindow : : onFileEncodingContextMenu ( const QPoint & pos )
{
mMenuEncoding - > exec ( mFileEncodingStatus - > mapToGlobal ( pos ) ) ;
}
2021-10-22 15:02:54 +08:00
void MainWindow : : onFilesViewContextMenu ( const QPoint & pos )
{
2023-08-08 14:41:23 +08:00
QMenu menu ( this ) ;
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
GitManager vcsManager ;
QString branch ;
bool hasRepository = vcsManager . hasRepository ( pSettings - > environment ( ) . currentFolder ( ) , branch ) ;
QMenu vcsMenu ( this ) ;
2023-08-08 14:41:23 +08:00
# endif
2021-10-22 15:02:54 +08:00
menu . addAction ( ui - > actionOpen_Folder ) ;
menu . addSeparator ( ) ;
2022-02-08 16:36:20 +08:00
menu . addAction ( mFilesView_CreateFolder ) ;
2022-03-17 10:46:24 +08:00
menu . addAction ( mFilesView_CreateFile ) ;
2022-06-12 15:48:19 +08:00
menu . addAction ( mFilesView_RemoveFile ) ;
menu . addAction ( mFilesView_Rename ) ;
2022-02-08 16:36:20 +08:00
menu . addSeparator ( ) ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) ) {
if ( hasRepository ) {
menu . addMenu ( & vcsMenu ) ;
} else {
ui - > actionGit_Create_Repository - > setEnabled ( true ) ;
menu . addAction ( ui - > actionGit_Create_Repository ) ;
}
menu . addSeparator ( ) ;
}
2023-08-08 14:41:23 +08:00
# endif
2021-10-22 15:02:54 +08:00
menu . addAction ( mFilesView_Open ) ;
menu . addAction ( mFilesView_OpenWithExternal ) ;
menu . addSeparator ( ) ;
menu . addAction ( mFilesView_OpenInTerminal ) ;
menu . addAction ( mFilesView_OpenInExplorer ) ;
2022-02-28 22:40:09 +08:00
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionFilesView_Hide_Non_Support_Files ) ;
2021-10-22 15:02:54 +08:00
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
QFileInfo info ( path ) ;
mFilesView_Open - > setEnabled ( info . isFile ( ) ) ;
mFilesView_OpenWithExternal - > setEnabled ( info . isFile ( ) ) ;
mFilesView_OpenInTerminal - > setEnabled ( ! path . isEmpty ( ) ) ;
mFilesView_OpenInExplorer - > setEnabled ( ! path . isEmpty ( ) ) ;
2022-06-12 15:48:19 +08:00
mFilesView_Rename - > setEnabled ( ! path . isEmpty ( ) ) ;
mFilesView_RemoveFile - > setEnabled ( ! path . isEmpty ( ) | | ! ui - > treeFiles - > selectionModel ( ) - > selectedRows ( ) . isEmpty ( ) ) ;
2022-02-15 00:01:50 +08:00
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) & & hasRepository ) {
2022-02-21 11:37:29 +08:00
mFileSystemModelIconProvider . update ( ) ;
2022-02-15 21:39:17 +08:00
vcsMenu . setTitle ( tr ( " Version Control " ) ) ;
if ( ui - > treeFiles - > selectionModel ( ) - > hasSelection ( ) ) {
bool shouldAdd = true ;
foreach ( const QModelIndex & index , ui - > treeFiles - > selectionModel ( ) - > selectedRows ( ) ) {
if ( mFileSystemModelIconProvider . VCSRepository ( ) - > isFileInRepository (
mFileSystemModel . fileInfo ( index )
2022-02-21 11:37:29 +08:00
) & &
! mFileSystemModelIconProvider . VCSRepository ( ) - > isFileConflicting (
mFileSystemModel . fileInfo ( index )
)
) {
2022-02-15 21:39:17 +08:00
shouldAdd = false ;
break ;
}
}
if ( shouldAdd )
vcsMenu . addAction ( ui - > actionGit_Add_Files ) ;
}
2022-02-24 11:07:37 +08:00
vcsMenu . addAction ( ui - > actionGit_Remotes ) ;
2022-02-21 23:35:28 +08:00
vcsMenu . addAction ( ui - > actionGit_Log ) ;
2022-02-19 20:38:08 +08:00
vcsMenu . addAction ( ui - > actionGit_Branch ) ;
2022-02-20 21:47:57 +08:00
vcsMenu . addAction ( ui - > actionGit_Merge ) ;
2022-02-15 00:01:50 +08:00
vcsMenu . addAction ( ui - > actionGit_Commit ) ;
2022-02-15 21:39:17 +08:00
vcsMenu . addAction ( ui - > actionGit_Restore ) ;
2022-02-15 00:01:50 +08:00
2022-02-20 21:47:57 +08:00
bool canBranch = ! mFileSystemModelIconProvider . VCSRepository ( ) - > hasChangedFiles ( )
2022-02-21 09:48:04 +08:00
& & ! mFileSystemModelIconProvider . VCSRepository ( ) - > hasStagedFiles ( ) ;
2022-02-20 21:47:57 +08:00
ui - > actionGit_Branch - > setEnabled ( canBranch ) ;
ui - > actionGit_Merge - > setEnabled ( canBranch ) ;
2022-02-21 23:35:28 +08:00
ui - > actionGit_Log - > setEnabled ( true ) ;
2022-02-24 11:07:37 +08:00
ui - > actionGit_Remotes - > setEnabled ( true ) ;
2022-02-15 00:01:50 +08:00
ui - > actionGit_Commit - > setEnabled ( true ) ;
2022-02-15 21:39:17 +08:00
ui - > actionGit_Restore - > setEnabled ( true ) ;
// vcsMenu.addAction(ui->actionGit_Reset);
// vcsMenu.addAction(ui->actionGit_Revert);
// ui->actionGit_Reset->setEnabled(true);
// ui->actionGit_Revert->setEnabled(true);
2022-02-15 00:01:50 +08:00
}
2023-08-08 14:41:23 +08:00
# endif
2021-10-22 15:02:54 +08:00
menu . exec ( ui - > treeFiles - > mapToGlobal ( pos ) ) ;
}
2021-11-04 09:07:06 +08:00
void MainWindow : : onLstProblemSetContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
2021-11-06 14:49:11 +08:00
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
2021-11-04 09:07:06 +08:00
mProblem_Properties - > setEnabled ( idx . isValid ( ) ) ;
2022-12-13 08:49:20 +08:00
mProblem_Rename - > setEnabled ( idx . isValid ( ) ) ;
2022-12-17 11:37:33 +08:00
menu . addAction ( mProblemSet_Rename ) ;
menu . addAction ( mProblemSet_New ) ;
menu . addAction ( mProblemSet_Load ) ;
menu . addAction ( mProblemSet_Save ) ;
menu . addAction ( mProblemSet_ImportFPS ) ;
menu . addAction ( mProblemSet_ExportFPS ) ;
2022-12-17 13:34:11 +08:00
menu . addAction ( mProblemSet_AddProblem ) ;
menu . addAction ( mProblemSet_RemoveProblem ) ;
2022-12-17 11:37:33 +08:00
menu . addSeparator ( ) ;
2022-12-13 08:49:20 +08:00
menu . addAction ( mProblem_Rename ) ;
menu . addAction ( mProblem_GotoUrl ) ;
2021-11-06 14:49:11 +08:00
if ( idx . isValid ( ) ) {
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
QMenu * menuSetAnswer = new QMenu ( & menu ) ;
QActionGroup * actionGroup = new QActionGroup ( menuSetAnswer ) ;
bool answerFound = false ;
menuSetAnswer - > setTitle ( tr ( " Set answer to... " ) ) ;
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
QString filename = e - > filename ( ) ;
QAction * action = new QAction ( filename , menuSetAnswer ) ;
action - > setCheckable ( true ) ;
action - > setActionGroup ( actionGroup ) ;
if ( filename . compare ( problem - > answerProgram , PATH_SENSITIVITY ) = = 0 ) {
action - > setChecked ( true ) ;
answerFound = true ;
}
menuSetAnswer - > addAction ( action ) ;
}
if ( ! answerFound & & ! problem - > answerProgram . isEmpty ( ) ) {
QAction * action = new QAction ( problem - > answerProgram , menuSetAnswer ) ;
action - > setCheckable ( true ) ;
action - > setChecked ( true ) ;
action - > setActionGroup ( actionGroup ) ;
menuSetAnswer - > addAction ( action ) ;
}
connect ( actionGroup , & QActionGroup : : triggered ,
[ problem , this ] ( QAction * action ) {
if ( action - > text ( ) . compare ( problem - > answerProgram , PATH_SENSITIVITY )
! = 0 )
problem - > answerProgram = action - > text ( ) ;
else
problem - > answerProgram = " " ;
if ( problem = = mOJProblemModel . problem ( ) ) {
ui - > btnOpenProblemAnswer - > setEnabled ( ! problem - > answerProgram . isEmpty ( ) ) ;
}
} ) ;
QAction * action = new QAction ( tr ( " select other file... " ) , menuSetAnswer ) ;
connect ( action , & QAction : : triggered ,
[ problem , this ] ( ) {
QString filename = QFileDialog : : getOpenFileName (
this ,
tr ( " Select Answer Source File " ) ,
QString ( ) ,
2022-04-06 22:24:40 +08:00
tr ( " C/C++ Source Files (*.c *.cpp *.cc *.cxx) " ) ,
nullptr ) ;
2021-11-06 14:49:11 +08:00
if ( ! filename . isEmpty ( ) ) {
QDir : : setCurrent ( extractFileDir ( filename ) ) ;
problem - > answerProgram = filename ;
if ( problem = = mOJProblemModel . problem ( ) ) {
ui - > btnOpenProblemAnswer - > setEnabled ( ! problem - > answerProgram . isEmpty ( ) ) ;
}
}
} ) ;
menuSetAnswer - > addAction ( action ) ;
menu . addMenu ( menuSetAnswer ) ;
2022-12-13 08:49:20 +08:00
mProblem_GotoUrl - > setEnabled ( ! problem - > url . isEmpty ( ) ) ;
2022-01-01 21:04:17 +08:00
mProblem_OpenSource - > setEnabled ( ! problem - > answerProgram . isEmpty ( ) ) ;
2022-12-13 08:49:20 +08:00
} else {
mProblem_GotoUrl - > setEnabled ( false ) ;
mProblem_OpenSource - > setEnabled ( false ) ;
2021-11-06 14:49:11 +08:00
}
2022-01-01 21:04:17 +08:00
menu . addAction ( mProblem_OpenSource ) ;
2021-11-06 14:49:11 +08:00
menu . addAction ( mProblem_Properties ) ;
2021-11-04 09:07:06 +08:00
menu . exec ( ui - > lstProblemSet - > mapToGlobal ( pos ) ) ;
}
2022-03-30 19:28:46 +08:00
void MainWindow : : onTableProblemCasesContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
2022-12-17 17:20:33 +08:00
menu . addAction ( mProblem_AddCase ) ;
menu . addAction ( mProblem_RemoveCases ) ;
2022-04-16 20:39:09 +08:00
menu . addAction ( mProblem_batchSetCases ) ;
menu . addSeparator ( ) ;
2022-03-30 19:28:46 +08:00
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
menu . addAction ( mProblem_RunAllCases ) ;
menu . addAction ( mProblem_RunCurrentCase ) ;
2022-12-17 17:20:33 +08:00
menu . addAction ( mProblem_CaseValidationOptions ) ;
2022-12-17 13:40:13 +08:00
mProblem_RunAllCases - > setEnabled ( mOJProblemModel . count ( ) > 0 & & ui - > actionRun - > isEnabled ( ) ) ;
mProblem_RunCurrentCase - > setEnabled ( idx . isValid ( ) & & ui - > actionRun - > isEnabled ( ) ) ;
2022-03-30 19:28:46 +08:00
menu . exec ( ui - > tblProblemCases - > mapToGlobal ( pos ) ) ;
}
2022-02-10 12:03:56 +08:00
void MainWindow : : onToolsOutputContextMenu ( const QPoint & pos )
{
QMenu menu ( this ) ;
menu . addAction ( mToolsOutput_Copy ) ;
menu . addAction ( mToolsOutput_SelectAll ) ;
menu . addSeparator ( ) ;
menu . addAction ( mToolsOutput_Clear ) ;
menu . exec ( ui - > txtToolsOutput - > mapToGlobal ( pos ) ) ;
}
2021-11-02 19:26:11 +08:00
void MainWindow : : onProblemSetIndexChanged ( const QModelIndex & current , const QModelIndex & /* previous */ )
2021-11-01 00:40:11 +08:00
{
QModelIndex idx = current ;
if ( ! idx . isValid ( ) ) {
2022-12-17 17:20:33 +08:00
mProblemSet_RemoveProblem - > setEnabled ( false ) ;
2021-11-02 01:07:37 +08:00
mOJProblemModel . setProblem ( nullptr ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseExpected - > clearAll ( ) ;
ui - > txtProblemCaseInput - > clearAll ( ) ;
ui - > txtProblemCaseOutput - > clearAll ( ) ;
2021-11-02 01:07:37 +08:00
ui - > tabProblem - > setEnabled ( false ) ;
2021-11-02 09:29:35 +08:00
ui - > lblProblem - > clear ( ) ;
2021-11-04 09:07:06 +08:00
ui - > lblProblem - > setToolTip ( " " ) ;
2021-11-06 14:49:11 +08:00
ui - > tabProblem - > setEnabled ( false ) ;
2021-11-01 00:40:11 +08:00
} else {
2022-12-17 17:20:33 +08:00
mProblemSet_RemoveProblem - > setEnabled ( true ) ;
2021-11-01 00:40:11 +08:00
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
2023-05-03 12:55:19 +08:00
if ( mFullInitialized ) {
if ( problem & & ! problem - > answerProgram . isEmpty ( ) ) {
openFile ( problem - > answerProgram ) ;
}
2022-01-02 10:37:00 +08:00
}
2021-11-01 00:40:11 +08:00
mOJProblemModel . setProblem ( problem ) ;
2022-01-01 17:24:18 +08:00
updateProblemTitle ( ) ;
2021-11-27 15:43:47 +08:00
if ( mOJProblemModel . count ( ) > 0 ) {
2022-03-29 18:06:24 +08:00
ui - > tblProblemCases - > setCurrentIndex ( mOJProblemModel . index ( 0 , 0 ) ) ;
2021-11-27 15:43:47 +08:00
} else {
onProblemCaseIndexChanged ( QModelIndex ( ) , QModelIndex ( ) ) ;
}
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2021-11-01 00:40:11 +08:00
ui - > tabMessages - > setCurrentWidget ( ui - > tabProblem ) ;
2021-11-02 01:07:37 +08:00
ui - > tabProblem - > setEnabled ( true ) ;
2021-11-06 14:49:11 +08:00
ui - > btnOpenProblemAnswer - > setEnabled ( ! problem - > answerProgram . isEmpty ( ) ) ;
2021-11-01 00:40:11 +08:00
}
}
void MainWindow : : onProblemCaseIndexChanged ( const QModelIndex & current , const QModelIndex & previous )
{
QModelIndex idx = current ;
if ( previous . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( previous . row ( ) ) ;
problemCase - > input = ui - > txtProblemCaseInput - > toPlainText ( ) ;
problemCase - > expected = ui - > txtProblemCaseExpected - > toPlainText ( ) ;
}
if ( idx . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( problemCase ) {
2022-12-17 17:20:33 +08:00
mProblem_RemoveCases - > setEnabled ( true ) ;
2022-12-31 09:36:50 +08:00
mProblem_RunAllCases - > setEnabled ( ui - > actionRun - > isEnabled ( ) ) ;
2022-03-29 18:06:24 +08:00
fillProblemCaseInputAndExpected ( problemCase ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseOutput - > clearAll ( ) ;
2022-02-04 19:19:35 +08:00
ui - > txtProblemCaseOutput - > setPlainText ( problemCase - > output ) ;
2021-11-02 19:26:11 +08:00
updateProblemCaseOutput ( problemCase ) ;
2021-11-01 00:40:11 +08:00
return ;
}
}
2022-03-29 18:06:24 +08:00
ui - > btnProblemCaseClearInputFileName - > setVisible ( false ) ;
ui - > btnProblemCaseInputFileName - > setEnabled ( false ) ;
ui - > txtProblemCaseInputFileName - > clear ( ) ;
ui - > txtProblemCaseInputFileName - > setToolTip ( " " ) ;
ui - > btnProblemCaseClearExpectedOutputFileName - > setVisible ( false ) ;
ui - > btnProblemCaseExpectedOutputFileName - > setEnabled ( false ) ;
ui - > txtProblemCaseExpectedOutputFileName - > clear ( ) ;
ui - > txtProblemCaseExpectedOutputFileName - > setToolTip ( " " ) ;
2022-12-17 17:20:33 +08:00
mProblem_RemoveCases - > setEnabled ( false ) ;
2022-12-31 09:36:50 +08:00
mProblem_RunAllCases - > setEnabled ( false ) ;
2022-03-29 18:06:24 +08:00
ui - > txtProblemCaseInputFileName - > clear ( ) ;
ui - > btnProblemCaseInputFileName - > setEnabled ( false ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseInput - > clearAll ( ) ;
2021-11-01 00:40:11 +08:00
ui - > txtProblemCaseInput - > setReadOnly ( true ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseExpected - > clearAll ( ) ;
2021-11-01 00:40:11 +08:00
ui - > txtProblemCaseExpected - > setReadOnly ( true ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseOutput - > clearAll ( ) ;
2022-03-29 21:41:02 +08:00
ui - > lblProblemCaseExpected - > clear ( ) ;
ui - > lblProblemCaseOutput - > clear ( ) ;
ui - > lblProblemCaseInput - > clear ( ) ;
2021-11-01 00:40:11 +08:00
}
2021-11-02 01:07:37 +08:00
void MainWindow : : onProblemNameChanged ( int index )
{
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( idx . isValid ( ) & & index = = idx . row ( ) ) {
2022-01-01 17:24:18 +08:00
updateProblemTitle ( ) ;
2021-11-02 01:07:37 +08:00
}
}
2022-03-30 19:28:46 +08:00
void MainWindow : : onProblemRunCurrentCase ( )
{
2022-06-13 16:31:41 +08:00
if ( ! ui - > tblProblemCases - > currentIndex ( ) . isValid ( ) )
return ;
showHideMessagesTab ( ui - > tabProblem , ui - > actionProblem ) ;
2022-03-30 19:28:46 +08:00
applyCurrentProblemCaseChanges ( ) ;
2022-10-12 19:48:35 +08:00
2022-03-30 19:28:46 +08:00
runExecutable ( RunType : : CurrentProblemCase ) ;
}
2022-04-16 20:39:09 +08:00
void MainWindow : : onProblemBatchSetCases ( )
{
2022-06-13 16:31:41 +08:00
showHideMessagesTab ( ui - > tabProblem , ui - > actionProblem ) ;
2022-04-16 20:43:58 +08:00
if ( mOJProblemModel . count ( ) > 0 & & QMessageBox : : question ( this , tr ( " Batch Set Cases " ) ,
2022-04-16 20:39:09 +08:00
tr ( " This operation will remove all cases for the current problem. " )
+ " <br /> "
+ tr ( " Do you really want to do that? " ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2022-04-16 20:43:58 +08:00
QString folder = QDir : : currentPath ( ) ;
if ( ! mOJProblemSetModel . exportFilename ( ) . isEmpty ( ) )
folder = extractFileDir ( mOJProblemSetModel . exportFilename ( ) ) ;
2022-04-16 20:39:09 +08:00
QStringList files = QFileDialog : : getOpenFileNames (
this ,
tr ( " Choose input files " ) ,
2022-04-16 20:43:58 +08:00
folder ,
2022-04-16 20:39:09 +08:00
tr ( " Input data files (*.in) " ) ) ;
if ( files . isEmpty ( ) )
return ;
mOJProblemModel . removeCases ( ) ;
foreach ( const QString & filename , files ) {
POJProblemCase problemCase = std : : make_shared < OJProblemCase > ( ) ;
problemCase - > name = QFileInfo ( filename ) . baseName ( ) ;
problemCase - > testState = ProblemCaseTestState : : NotTested ;
problemCase - > inputFileName = filename ;
2022-04-26 22:08:46 +08:00
QString expectedFileName ;
expectedFileName = filename . mid ( 0 , filename . length ( ) - 2 ) + " ans " ;
if ( fileExists ( expectedFileName ) ) {
2022-04-16 20:39:09 +08:00
problemCase - > expectedOutputFileName = expectedFileName ;
2022-04-26 22:08:46 +08:00
} else {
expectedFileName = filename . mid ( 0 , filename . length ( ) - 2 ) + " out " ;
if ( fileExists ( expectedFileName ) )
problemCase - > expectedOutputFileName = expectedFileName ;
}
2022-04-16 20:39:09 +08:00
mOJProblemModel . addCase ( problemCase ) ;
}
}
2021-11-02 09:29:35 +08:00
void MainWindow : : onNewProblemConnection ( )
{
QTcpSocket * clientConnection = mTcpServer . nextPendingConnection ( ) ;
2021-11-06 10:36:25 +08:00
connect ( clientConnection , & QAbstractSocket : : disconnected ,
2021-11-02 09:29:35 +08:00
clientConnection , & QObject : : deleteLater ) ;
QByteArray content ;
2021-11-06 10:36:25 +08:00
int unreadCount = 0 ;
2021-11-02 09:29:35 +08:00
while ( clientConnection - > state ( ) = = QTcpSocket : : ConnectedState ) {
2021-11-06 10:36:25 +08:00
clientConnection - > waitForReadyRead ( 100 ) ;
QByteArray readed = clientConnection - > readAll ( ) ;
if ( readed . isEmpty ( ) ) {
unreadCount + + ;
if ( ! content . isEmpty ( ) | | unreadCount > 30 )
break ;
} else {
unreadCount = 0 ;
}
content + = readed ;
2021-11-02 09:29:35 +08:00
}
content + = clientConnection - > readAll ( ) ;
2021-11-06 10:36:25 +08:00
clientConnection - > write ( " HTTP/1.1 200 OK " ) ;
clientConnection - > disconnectFromHost ( ) ;
// qDebug()<<"---------";
// qDebug()<<content;
2021-11-02 09:29:35 +08:00
content = getHTTPBody ( content ) ;
2021-11-06 10:36:25 +08:00
// qDebug()<<"*********";
// qDebug()<<content;
if ( content . isEmpty ( ) ) {
return ;
}
2021-11-02 09:29:35 +08:00
QJsonParseError error ;
QJsonDocument doc = QJsonDocument : : fromJson ( content , & error ) ;
if ( error . error ! = QJsonParseError : : NoError ) {
qDebug ( ) < < " Read http content failed! " ;
qDebug ( ) < < error . errorString ( ) ;
return ;
}
QJsonObject obj = doc . object ( ) ;
QString name = obj [ " name " ] . toString ( ) ;
if ( ! mOJProblemSetModel . problemNameUsed ( name ) ) {
POJProblem problem = std : : make_shared < OJProblem > ( ) ;
problem - > name = name ;
problem - > url = obj [ " url " ] . toString ( ) ;
QJsonArray caseArray = obj [ " tests " ] . toArray ( ) ;
foreach ( const QJsonValue & val , caseArray ) {
QJsonObject caseObj = val . toObject ( ) ;
POJProblemCase problemCase = std : : make_shared < OJProblemCase > ( ) ;
problemCase - > testState = ProblemCaseTestState : : NotTested ;
problemCase - > name = tr ( " Problem Case %1 " ) . arg ( problem - > cases . count ( ) + 1 ) ;
2022-12-24 12:08:13 +08:00
if ( pSettings - > executor ( ) . convertHTMLToTextForInput ( ) ) {
QTextDocument doc ;
doc . setHtml ( caseObj [ " input " ] . toString ( ) ) ;
problemCase - > input = doc . toPlainText ( ) ;
} else
problemCase - > input = caseObj [ " input " ] . toString ( ) ;
if ( pSettings - > executor ( ) . convertHTMLToTextForExpected ( ) ) {
QTextDocument doc ;
doc . setHtml ( caseObj [ " output " ] . toString ( ) ) ;
problemCase - > expected = doc . toPlainText ( ) ;
} else
problemCase - > expected = caseObj [ " output " ] . toString ( ) ;
2021-11-02 09:29:35 +08:00
problem - > cases . append ( problemCase ) ;
}
mOJProblemSetModel . addProblem ( problem ) ;
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setCurrentWidget ( ui - > tabProblemSet ) ;
2021-11-06 10:58:18 +08:00
ui - > lstProblemSet - > setCurrentIndex ( mOJProblemSetModel . index (
mOJProblemSetModel . count ( ) - 1
, 0 ) ) ;
2022-04-01 21:09:24 +08:00
if ( isMinimized ( ) )
showNormal ( ) ;
2021-11-06 10:58:18 +08:00
raise ( ) ; // for mac OS?
activateWindow ( ) ;
2021-11-02 09:29:35 +08:00
}
}
2022-01-01 17:24:18 +08:00
void MainWindow : : updateProblemTitle ( )
{
ui - > lblProblem - > setText ( mOJProblemModel . getTitle ( ) ) ;
ui - > lblProblem - > setToolTip ( mOJProblemModel . getTooltip ( ) ) ;
}
2021-11-02 23:47:51 +08:00
void MainWindow : : onEditorClosed ( )
{
if ( mQuitting )
return ;
updateEditorActions ( ) ;
updateAppTitle ( ) ;
}
2022-02-10 12:03:56 +08:00
void MainWindow : : onToolsOutputClear ( )
{
ui - > txtToolsOutput - > clear ( ) ;
}
void MainWindow : : onToolsOutputCopy ( )
{
ui - > txtToolsOutput - > copy ( ) ;
}
void MainWindow : : onToolsOutputSelectAll ( )
{
ui - > txtToolsOutput - > selectAll ( ) ;
}
2021-10-03 09:57:19 +08:00
void MainWindow : : onShowInsertCodeSnippetMenu ( )
{
mMenuInsertCodeSnippet - > clear ( ) ;
QList < PCodeSnippet > snippets ;
foreach ( const PCodeSnippet & snippet , mCodeSnippetManager - > snippets ( ) ) {
if ( snippet - > section > = 0 & & ! snippet - > caption . isEmpty ( ) )
snippets . append ( snippet ) ;
}
if ( snippets . isEmpty ( ) )
return ;
std : : sort ( snippets . begin ( ) , snippets . end ( ) , [ ] ( const PCodeSnippet & s1 , const PCodeSnippet & s2 ) {
return s1 - > section < s2 - > section ;
} ) ;
int section = 0 ;
int sectionCount = 0 ;
int count = 0 ;
bool sectionNotEmpty = false ;
foreach ( const PCodeSnippet & snippet , snippets ) {
if ( snippet - > section > section & & sectionCount < 6 ) {
section = snippet - > section ;
sectionCount + + ;
if ( sectionNotEmpty )
mMenuInsertCodeSnippet - > addSeparator ( ) ;
}
QAction * action = mMenuInsertCodeSnippet - > addAction ( snippet - > caption ) ;
connect ( action , & QAction : : triggered ,
[ snippet , this ] ( ) {
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
editor - > insertCodeSnippet ( snippet - > code ) ;
}
} ) ;
sectionNotEmpty = true ;
count + + ;
if ( count > 15 )
break ;
}
}
2022-10-25 22:10:38 +08:00
void MainWindow : : onFilesViewCreateFolderFolderLoaded ( const QString & path )
{
2024-02-22 14:19:17 +08:00
if ( mFilesViewNewCreatedFolder . isEmpty ( ) & & mFilesViewNewCreatedFile . isEmpty ( ) )
2022-10-25 22:10:38 +08:00
return ;
2024-02-22 14:19:17 +08:00
if ( path ! = extractFilePath ( mFilesViewNewCreatedFolder ) & & path ! = extractFilePath ( mFilesViewNewCreatedFile ) )
2022-10-25 22:10:38 +08:00
return ;
disconnect ( & mFileSystemModel , & QFileSystemModel : : directoryLoaded ,
this , & MainWindow : : onFilesViewCreateFolderFolderLoaded ) ;
2024-02-22 14:19:17 +08:00
QModelIndex newIndex = mFileSystemModel . index ( mFilesViewNewCreatedFolder . isEmpty ( ) ? mFilesViewNewCreatedFile : mFilesViewNewCreatedFolder ) ;
2022-10-25 22:10:38 +08:00
if ( newIndex . isValid ( ) ) {
ui - > treeFiles - > setCurrentIndex ( newIndex ) ;
ui - > treeFiles - > edit ( newIndex ) ;
}
mFilesViewNewCreatedFolder = " " ;
}
2022-02-08 16:36:20 +08:00
void MainWindow : : onFilesViewCreateFolder ( )
{
QModelIndex index = ui - > treeFiles - > currentIndex ( ) ;
2022-07-06 18:16:25 +08:00
QModelIndex parentIndex ;
2022-02-08 16:36:20 +08:00
QDir dir ;
2022-03-15 15:34:34 +08:00
if ( index . isValid ( )
& & ui - > treeFiles - > selectionModel ( ) - > isSelected ( index ) ) {
2022-07-06 18:16:25 +08:00
if ( mFileSystemModel . isDir ( index ) ) {
2022-02-08 16:36:20 +08:00
dir = QDir ( mFileSystemModel . fileInfo ( index ) . absoluteFilePath ( ) ) ;
2022-07-06 18:16:25 +08:00
parentIndex = index ;
} else {
2022-02-08 16:36:20 +08:00
dir = mFileSystemModel . fileInfo ( index ) . absoluteDir ( ) ;
2022-07-06 18:16:25 +08:00
parentIndex = mFileSystemModel . index ( dir . absolutePath ( ) ) ;
}
2022-10-25 22:10:38 +08:00
//ui->treeFiles->expand(index);
2022-02-08 16:36:20 +08:00
} else {
dir = mFileSystemModel . rootDirectory ( ) ;
2022-07-23 15:41:19 +08:00
parentIndex = mFileSystemModel . index ( dir . absolutePath ( ) ) ;
2022-02-08 16:36:20 +08:00
}
QString folderName = tr ( " New Folder " ) ;
int count = 0 ;
while ( dir . exists ( folderName ) ) {
count + + ;
2022-03-15 15:34:34 +08:00
folderName = tr ( " New Folder %1 " ) . arg ( count ) ;
2022-02-08 16:36:20 +08:00
}
2022-07-06 18:16:25 +08:00
QModelIndex newIndex = mFileSystemModel . mkdir ( parentIndex , folderName ) ;
2022-10-25 22:10:38 +08:00
if ( newIndex . isValid ( ) ) {
if ( ui - > treeFiles - > isExpanded ( parentIndex ) ) {
ui - > treeFiles - > setCurrentIndex ( newIndex ) ;
ui - > treeFiles - > edit ( newIndex ) ;
} else {
connect ( & mFileSystemModel , & QFileSystemModel : : directoryLoaded ,
this , & MainWindow : : onFilesViewCreateFolderFolderLoaded ) ;
ui - > treeFiles - > expand ( parentIndex ) ;
mFilesViewNewCreatedFolder = mFileSystemModel . filePath ( newIndex ) ;
}
}
2022-02-08 16:36:20 +08:00
}
2022-03-17 10:46:24 +08:00
void MainWindow : : onFilesViewCreateFile ( )
{
QModelIndex index = ui - > treeFiles - > currentIndex ( ) ;
QDir dir ;
if ( index . isValid ( )
& & ui - > treeFiles - > selectionModel ( ) - > isSelected ( index ) ) {
if ( mFileSystemModel . isDir ( index ) )
dir = QDir ( mFileSystemModel . fileInfo ( index ) . absoluteFilePath ( ) ) ;
else
dir = mFileSystemModel . fileInfo ( index ) . absoluteDir ( ) ;
} else {
dir = mFileSystemModel . rootDirectory ( ) ;
}
QString suffix ;
if ( pSettings - > editor ( ) . defaultFileCpp ( ) )
suffix = " .cpp " ;
else
suffix = " .c " ;
2022-10-30 11:58:42 +08:00
QString fileName = QString ( " untitled " ) + suffix ;
2022-03-17 10:46:24 +08:00
int count = 0 ;
while ( dir . exists ( fileName ) ) {
count + + ;
2022-10-30 11:58:42 +08:00
fileName = QString ( " untitled%1 " ) . arg ( count ) + suffix ;
2022-03-17 10:46:24 +08:00
}
QFile file ( dir . filePath ( fileName ) ) ;
2023-10-21 13:38:12 +08:00
# if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
2022-03-17 10:46:24 +08:00
file . open ( QFile : : NewOnly ) ;
2023-10-21 13:38:12 +08:00
# else
// workaround: try create but do not truncate
file . open ( QFile : : ReadWrite ) ;
# endif
2024-02-22 14:19:17 +08:00
file . close ( ) ;
QModelIndex newIndex = mFileSystemModel . index ( dir . filePath ( fileName ) ) ;
connect ( & mFileSystemModel , & QFileSystemModel : : directoryLoaded ,
this , & MainWindow : : onFilesViewCreateFolderFolderLoaded ) ;
ui - > treeFiles - > expand ( index ) ;
mFilesViewNewCreatedFile = mFileSystemModel . filePath ( newIndex ) ;
2022-03-17 10:46:24 +08:00
}
2022-02-08 16:48:50 +08:00
void MainWindow : : onFilesViewRemoveFiles ( )
2022-02-08 16:36:20 +08:00
{
2022-02-08 16:48:50 +08:00
QModelIndexList indexList = ui - > treeFiles - > selectionModel ( ) - > selectedRows ( ) ;
if ( indexList . isEmpty ( ) ) {
QModelIndex index = ui - > treeFiles - > currentIndex ( ) ;
if ( QMessageBox : : question ( ui - > treeFiles , tr ( " Delete " )
, tr ( " Do you really want to delete %1? " ) . arg ( mFileSystemModel . fileName ( index ) ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ! = QMessageBox : : Yes )
2022-02-08 16:36:20 +08:00
return ;
2022-02-08 16:48:50 +08:00
doFilesViewRemoveFile ( index ) ;
2023-06-29 00:27:06 +08:00
} else if ( indexList . count ( ) = = 1 ) {
QModelIndex index = indexList [ 0 ] ;
if ( QMessageBox : : question ( ui - > treeFiles , tr ( " Delete " )
, tr ( " Do you really want to delete %1? " ) . arg ( mFileSystemModel . fileName ( index ) ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
doFilesViewRemoveFile ( index ) ;
2022-02-08 16:36:20 +08:00
} else {
2022-02-08 16:48:50 +08:00
if ( QMessageBox : : question ( ui - > treeFiles , tr ( " Delete " )
, tr ( " Do you really want to delete %1 files? " ) . arg ( indexList . count ( ) ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
foreach ( const QModelIndex & index , indexList ) {
doFilesViewRemoveFile ( index ) ;
}
2022-02-08 16:36:20 +08:00
}
}
2022-06-12 15:48:19 +08:00
void MainWindow : : onFilesViewRename ( ) {
QModelIndex index = ui - > treeFiles - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
ui - > treeFiles - > edit ( index ) ;
}
2022-03-27 16:07:51 +08:00
void MainWindow : : onProblemProperties ( )
{
2022-06-13 16:31:41 +08:00
showHideMessagesTab ( ui - > tabProblem , ui - > actionProblem ) ;
2022-03-27 16:07:51 +08:00
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( ! idx . isValid ( ) )
return ;
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
if ( ! problem )
return ;
OJProblemPropertyWidget dialog ;
2022-12-13 08:49:20 +08:00
dialog . loadFromProblem ( problem ) ;
2022-03-27 16:07:51 +08:00
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
2022-12-13 08:49:20 +08:00
dialog . saveToProblem ( problem ) ;
2022-03-27 16:07:51 +08:00
}
}
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 ( ) ) {
2022-10-18 12:46:51 +08:00
openFile ( problem - > answerProgram ) ;
2022-03-27 16:07:51 +08:00
}
}
2022-12-13 08:49:20 +08:00
void MainWindow : : onProblemRename ( )
{
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( ! idx . isValid ( ) )
return ;
ui - > lstProblemSet - > edit ( idx ) ;
}
void MainWindow : : onProblemGotoUrl ( )
{
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( ! idx . isValid ( ) )
return ;
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
if ( ! problem )
return ;
if ( ! problem - > url . isEmpty ( ) ) {
QDesktopServices : : openUrl ( problem - > url ) ;
}
}
2022-12-17 11:37:33 +08:00
void MainWindow : : onRenameProblemSet ( )
2022-03-27 16:07:51 +08:00
{
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 ) ;
2022-10-11 21:51:33 +08:00
if ( editor & & editor - > inProject ( ) = = mBookmarkModel - > isForProject ( ) ) {
2022-03-27 16:07:51 +08:00
editor - > removeBookmark ( bookmark - > line ) ;
}
2022-10-11 21:51:33 +08:00
mBookmarkModel - > removeBookmarkAt ( index . row ( ) ) ;
2022-03-27 16:07:51 +08:00
}
}
}
void MainWindow : : onBookmarkRemoveAll ( )
{
2022-10-11 21:51:33 +08:00
mBookmarkModel - > clear ( mBookmarkModel - > isForProject ( ) ) ;
2022-03-27 16:07:51 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * editor = ( * mEditorList ) [ i ] ;
2022-10-11 21:51:33 +08:00
if ( editor - > inProject ( ) = = mBookmarkModel - > isForProject ( ) )
editor - > clearBookmarks ( ) ;
2022-03-27 16:07:51 +08:00
}
}
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 ( ) ) {
2023-03-23 22:33:04 +08:00
openFileFolderInExplorer ( path ) ;
2022-03-27 16:07:51 +08:00
}
}
void MainWindow : : onFilesViewOpenInTerminal ( )
{
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
if ( ! path . isEmpty ( ) ) {
QFileInfo fileInfo ( path ) ;
# ifdef Q_OS_WIN
2022-06-16 21:34:31 +08:00
openShell ( fileInfo . path ( ) , " cmd.exe " , getDefaultCompilerSetBinDirs ( ) ) ;
2022-03-27 16:07:51 +08:00
# else
2023-09-25 10:15:07 +08:00
openShell ( fileInfo . path ( ) , pSettings - > environment ( ) . terminalPath ( ) , getDefaultCompilerSetBinDirs ( ) ) ;
2022-03-27 16:07:51 +08:00
# 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 ( ) ) {
2022-06-12 15:48:19 +08:00
if ( getFileType ( path ) = = FileType : : Project ) {
openProject ( path ) ;
} else {
openFile ( path ) ;
}
2022-03-27 16:07:51 +08:00
}
}
void MainWindow : : onClassBrowserGotoDeclaration ( )
{
2022-10-23 15:22:26 +08:00
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 - > fileName ;
line = statement - > line ;
Editor * e = openFile ( filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( line , 1 ) ;
}
2022-03-27 16:07:51 +08:00
}
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 ;
2022-10-18 12:46:51 +08:00
Editor * e = openFile ( filename ) ;
2022-03-27 16:07:51 +08:00
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 ( ) ;
}
2022-10-23 15:22:26 +08:00
void MainWindow : : onClassBrowserChangeScope ( )
{
if ( ! mProject )
return ;
ProjectClassBrowserType classBrowserType ;
if ( mProject - > options ( ) . classBrowserType = = ProjectClassBrowserType : : CurrentFile ) {
classBrowserType = ProjectClassBrowserType : : WholeProject ;
} else {
classBrowserType = ProjectClassBrowserType : : CurrentFile ;
}
mProject - > options ( ) . classBrowserType = classBrowserType ;
mProject - > saveOptions ( ) ;
Editor * editor = mEditorList - > getEditor ( ) ;
2022-11-07 11:24:23 +08:00
if ( ( ! editor | | editor - > inProject ( ) ) & &
2022-10-23 15:22:26 +08:00
mClassBrowserModel . classBrowserType ( ) ! = classBrowserType ) {
mClassBrowserModel . setClassBrowserType ( classBrowserType ) ;
}
}
2022-10-23 16:31:05 +08:00
void MainWindow : : onClassBrowserRefreshStart ( )
{
mClassBrowserCurrentStatement = " " ;
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 ;
}
2022-10-23 21:42:11 +08:00
mClassBrowserCurrentStatement = QString ( " %1+%2+%3 " )
. arg ( statement - > fullName )
. arg ( statement - > noNameArgs )
. arg ( ( int ) statement - > kind ) ;
2022-10-23 16:31:05 +08:00
}
void MainWindow : : onClassBrowserRefreshEnd ( )
{
QModelIndex index = mClassBrowserModel . modelIndexForStatement ( mClassBrowserCurrentStatement ) ;
if ( index . isValid ( ) ) {
2022-10-23 16:43:26 +08:00
ui - > classBrowser - > expand ( index ) ;
2022-10-23 16:31:05 +08:00
ui - > classBrowser - > setCurrentIndex ( index ) ;
}
}
2022-03-27 16:07:51 +08:00
void MainWindow : : onProjectSwitchCustomViewMode ( )
{
mProject - > setModelType ( ProjectModelType : : Custom ) ;
2022-10-02 23:32:33 +08:00
ui - > projectView - > expand (
mProjectProxyModel - > mapFromSource (
mProject - > model ( ) - > rootIndex ( ) ) ) ;
2022-03-27 16:07:51 +08:00
}
void MainWindow : : onProjectSwitchFileSystemViewMode ( )
{
mProject - > setModelType ( ProjectModelType : : FileSystem ) ;
2022-10-02 23:32:33 +08:00
ui - > projectView - > expand (
mProjectProxyModel - > mapFromSource (
mProject - > model ( ) - > rootIndex ( ) ) ) ;
2022-03-27 16:07:51 +08:00
}
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 ;
2022-10-08 23:30:30 +08:00
if ( folderNode - > isUnit )
2022-03-27 16:07:51 +08:00
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 ( ) ;
2022-10-08 23:30:30 +08:00
if ( folderNode - > isUnit )
2022-03-27 16:07:51 +08:00
return ;
QString s = tr ( " New folder " ) ;
2022-10-02 23:32:33 +08:00
int i = 1 ;
while ( fileExists ( s ) ) {
s = tr ( " New folder " ) + QString ( " %1 " ) . arg ( i ) ;
i + + ;
}
2022-03-27 16:07:51 +08:00
bool ok ;
s = QInputDialog : : getText ( ui - > projectView ,
tr ( " Add Folder " ) ,
tr ( " Folder name: " ) ,
QLineEdit : : Normal , s ,
& ok ) . trimmed ( ) ;
if ( ok & & ! s . isEmpty ( ) ) {
2022-10-02 23:32:33 +08:00
PProjectModelNode node = mProject - > addFolder ( folderNode , s ) ;
mProject - > saveAll ( ) ;
setProjectViewCurrentNode ( node ) ;
updateProjectView ( ) ;
2022-03-27 16:07:51 +08:00
}
}
void MainWindow : : onProjectRenameUnit ( )
{
if ( ui - > projectView - > currentIndex ( ) . isValid ( ) ) {
ui - > projectView - > edit ( ui - > projectView - > currentIndex ( ) ) ;
}
}
void MainWindow : : onBreakpointRemove ( )
{
int index = ui - > tblBreakpoints - > selectionModel ( ) - > currentIndex ( ) . row ( ) ;
2022-10-16 23:10:57 +08:00
PBreakpoint breakpoint = debugger ( ) - > breakpointModel ( ) - > breakpoint ( index , debugger ( ) - > isForProject ( ) ) ;
2022-03-27 16:07:51 +08:00
if ( breakpoint ) {
Editor * e = mEditorList - > getOpenedEditorByFilename ( breakpoint - > filename ) ;
if ( e ) {
if ( e - > hasBreakpoint ( breakpoint - > line ) )
e - > toggleBreakpoint ( breakpoint - > line ) ;
} else {
2022-10-16 23:10:57 +08:00
debugger ( ) - > breakpointModel ( ) - > removeBreakpoint ( index , debugger ( ) - > isForProject ( ) ) ;
2022-03-27 16:07:51 +08:00
}
}
}
void MainWindow : : onBreakpointViewRemoveAll ( )
{
2022-10-16 23:10:57 +08:00
debugger ( ) - > deleteBreakpoints ( debugger ( ) - > isForProject ( ) ) ;
2022-03-27 16:07:51 +08:00
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 (
2022-10-16 23:10:57 +08:00
index ,
debugger ( ) - > isForProject ( )
2022-03-27 16:07:51 +08:00
) ;
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 ) {
2022-10-16 23:10:57 +08:00
pMainWindow - > debugger ( ) - > setBreakPointCondition ( index , s , debugger ( ) - > isForProject ( ) ) ;
2022-03-27 16:07:51 +08:00
}
}
}
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 ) ;
}
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onEditorContextMenu ( const QPoint & pos )
2021-09-03 00:26:49 +08:00
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! editor )
return ;
2023-02-18 16:20:07 +08:00
FileType fileType = getFileType ( editor - > filename ( ) ) ;
bool canDebug = ( fileType = = FileType : : CSource
| | fileType = = FileType : : CHeader
| | fileType = = FileType : : CppSource
| | fileType = = FileType : : CppHeader
| | fileType = = FileType : : GAS
) ;
2021-09-03 00:26:49 +08:00
QMenu menu ( this ) ;
2022-09-25 09:55:18 +08:00
QSynedit : : BufferCoord p ;
2021-09-05 05:01:31 +08:00
mEditorContextMenuPos = pos ;
2021-10-21 17:31:25 +08:00
int line ;
2021-09-20 15:57:48 +08:00
if ( editor - > getPositionOfMouse ( p ) ) {
2022-07-04 10:01:40 +08:00
line = p . line ;
2022-11-05 19:39:33 +08:00
if ( ! switchHeaderSourceTarget ( editor ) . isEmpty ( ) ) {
menu . addAction ( ui - > actionSwitchHeaderSource ) ;
menu . addSeparator ( ) ;
}
2021-09-03 10:30:08 +08:00
//mouse on editing area
2023-02-18 16:20:07 +08:00
if ( canDebug ) {
menu . addAction ( ui - > actionRun ) ;
menu . addAction ( ui - > actionDebug ) ;
2022-11-06 09:43:28 +08:00
menu . addSeparator ( ) ;
2023-02-18 16:20:07 +08:00
}
if ( editor - > parser ( ) & & editor - > parser ( ) - > enabled ( ) ) {
2022-11-06 09:43:28 +08:00
menu . addAction ( ui - > actionGoto_Declaration ) ;
menu . addAction ( ui - > actionGoto_Definition ) ;
menu . addAction ( ui - > actionFind_references ) ;
2023-02-18 16:20:07 +08:00
menu . addSeparator ( ) ;
2022-11-06 09:43:28 +08:00
}
2021-09-03 16:39:20 +08:00
menu . addAction ( ui - > actionOpen_Containing_Folder ) ;
menu . addAction ( ui - > actionOpen_Terminal ) ;
2021-10-22 15:02:54 +08:00
menu . addAction ( ui - > actionLocate_in_Files_View ) ;
2021-09-03 20:55:14 +08:00
menu . addSeparator ( ) ;
2022-12-16 11:10:46 +08:00
menu . addAction ( ui - > actionTrim_trailing_spaces ) ;
2021-09-03 20:55:14 +08:00
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 ( ) ;
2023-02-18 16:20:07 +08:00
if ( canDebug ) {
menu . addAction ( ui - > actionAdd_Watch ) ;
2023-03-03 17:20:33 +08:00
menu . addAction ( ui - > actionAdd_Watchpoint ) ;
2023-02-18 16:20:07 +08:00
menu . addAction ( ui - > actionToggle_Breakpoint ) ;
menu . addAction ( ui - > actionClear_all_breakpoints ) ;
menu . addSeparator ( ) ;
}
2021-10-21 17:31:25 +08:00
menu . addAction ( ui - > actionAdd_bookmark ) ;
menu . addAction ( ui - > actionRemove_Bookmark ) ;
menu . addAction ( ui - > actionModify_Bookmark_Description ) ;
menu . addSeparator ( ) ;
2022-07-21 15:28:07 +08:00
menu . addAction ( ui - > actionGo_to_Line ) ;
menu . addSeparator ( ) ;
2021-09-04 00:13:42 +08:00
menu . addAction ( ui - > actionFile_Properties ) ;
2021-09-03 10:30:08 +08:00
} else {
//mouse on gutter
2021-10-21 17:31:25 +08:00
2021-09-20 15:57:48 +08:00
if ( ! editor - > getLineOfMouse ( line ) )
2021-09-03 10:30:08 +08:00
line = - 1 ;
2023-02-18 16:20:07 +08:00
if ( canDebug ) {
menu . addAction ( ui - > actionToggle_Breakpoint ) ;
menu . addAction ( ui - > actionBreakpoint_property ) ;
menu . addAction ( ui - > actionClear_all_breakpoints ) ;
menu . addSeparator ( ) ;
}
2021-10-21 17:31:25 +08:00
menu . addAction ( ui - > actionAdd_bookmark ) ;
menu . addAction ( ui - > actionRemove_Bookmark ) ;
menu . addAction ( ui - > actionModify_Bookmark_Description ) ;
2022-07-21 15:28:07 +08:00
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionGo_to_Line ) ;
2021-10-21 17:31:25 +08:00
}
2021-10-22 15:02:54 +08:00
ui - > actionLocate_in_Files_View - > setEnabled ( ! editor - > isNew ( ) ) ;
2021-10-21 17:31:25 +08:00
ui - > actionBreakpoint_property - > setEnabled ( editor - > hasBreakpoint ( line ) ) ;
ui - > actionAdd_bookmark - > setEnabled (
2022-04-19 21:18:41 +08:00
line > = 0 & & editor - > document ( ) - > count ( ) > 0
2021-10-24 12:37:00 +08:00
& & ! editor - > hasBookmark ( line )
2021-10-21 17:31:25 +08:00
) ;
2021-10-22 16:56:27 +08:00
ui - > actionRemove_Bookmark - > setEnabled ( editor - > hasBookmark ( line ) ) ;
ui - > actionModify_Bookmark_Description - > setEnabled ( editor - > hasBookmark ( line ) ) ;
2021-09-03 00:26:49 +08:00
menu . exec ( editor - > viewport ( ) - > mapToGlobal ( pos ) ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onEditorRightTabContextMenu ( const QPoint & pos )
2021-09-04 22:15:02 +08:00
{
2021-10-13 11:32:59 +08:00
onEditorTabContextMenu ( ui - > EditorTabsRight , pos ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onEditorLeftTabContextMenu ( const QPoint & pos )
2021-10-13 11:32:59 +08:00
{
onEditorTabContextMenu ( ui - > EditorTabsLeft , pos ) ;
}
void MainWindow : : onEditorTabContextMenu ( QTabWidget * tabWidget , const QPoint & pos )
{
int index = tabWidget - > tabBar ( ) - > tabAt ( pos ) ;
2021-09-05 05:01:31 +08:00
if ( index < 0 )
return ;
2021-10-13 11:32:59 +08:00
tabWidget - > setCurrentIndex ( index ) ;
2021-09-05 05:01:31 +08:00
QMenu menu ( this ) ;
2021-10-13 11:32:59 +08:00
QTabBar * tabBar = tabWidget - > tabBar ( ) ;
2023-01-01 08:32:33 +08:00
Editor * editor = dynamic_cast < Editor * > ( tabWidget - > widget ( index ) ) ;
if ( ! switchHeaderSourceTarget ( editor ) . isEmpty ( ) ) {
menu . addAction ( ui - > actionSwitchHeaderSource ) ;
menu . addSeparator ( ) ;
}
2021-09-05 05:01:31 +08:00
menu . addAction ( ui - > actionClose ) ;
menu . addAction ( ui - > actionClose_All ) ;
2023-06-13 17:16:09 +08:00
menu . addAction ( ui - > actionClose_Others ) ;
2021-09-05 05:01:31 +08:00
menu . addSeparator ( ) ;
2023-01-02 16:50:30 +08:00
menu . addAction ( ui - > actionToggle_Readonly ) ;
menu . addSeparator ( ) ;
2021-09-05 05:01:31 +08:00
menu . addAction ( ui - > actionOpen_Containing_Folder ) ;
menu . addAction ( ui - > actionOpen_Terminal ) ;
2021-10-22 15:02:54 +08:00
menu . addAction ( ui - > actionLocate_in_Files_View ) ;
2021-09-05 05:01:31 +08:00
menu . addSeparator ( ) ;
2021-10-13 11:32:59 +08:00
menu . addAction ( ui - > actionMove_To_Other_View ) ;
menu . addSeparator ( ) ;
2021-09-05 05:01:31 +08:00
menu . addAction ( ui - > actionFile_Properties ) ;
2021-10-22 15:02:54 +08:00
if ( editor ) {
ui - > actionLocate_in_Files_View - > setEnabled ( ! editor - > isNew ( ) ) ;
}
2021-09-05 05:01:31 +08:00
menu . exec ( tabBar - > mapToGlobal ( pos ) ) ;
2021-09-04 22:15:02 +08:00
}
2021-09-19 14:28:30 +08:00
void MainWindow : : disableDebugActions ( )
{
2021-12-27 10:59:04 +08:00
ui - > actionInterrupt - > setEnabled ( false ) ;
2021-09-19 14:28:30 +08:00
ui - > actionStep_Into - > setEnabled ( false ) ;
ui - > actionStep_Over - > setEnabled ( false ) ;
ui - > actionStep_Out - > setEnabled ( false ) ;
ui - > actionRun_To_Cursor - > setEnabled ( false ) ;
ui - > actionContinue - > setEnabled ( false ) ;
2023-03-03 17:20:33 +08:00
ui - > actionAdd_Watchpoint - > setEnabled ( false ) ;
2021-09-19 14:28:30 +08:00
ui - > cbEvaluate - > setEnabled ( false ) ;
2021-09-29 22:55:53 +08:00
ui - > cbMemoryAddress - > setEnabled ( false ) ;
2021-12-16 10:46:38 +08:00
if ( mCPUDialog ) {
mCPUDialog - > updateButtonStates ( false ) ;
}
2021-09-19 14:28:30 +08:00
}
void MainWindow : : enableDebugActions ( )
{
2024-01-18 16:14:36 +08:00
ui - > actionInterrupt - > setEnabled ( mDebugger - > useDebugServer ( ) & & mDebugger - > inferiorRunning ( ) ) ;
2021-11-24 21:22:01 +08:00
ui - > actionStep_Into - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > actionStep_Over - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > actionStep_Out - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > actionRun_To_Cursor - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
2022-01-03 20:18:53 +08:00
ui - > actionContinue - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
2023-03-03 17:20:33 +08:00
ui - > actionAdd_Watchpoint - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
2021-11-24 21:22:01 +08:00
ui - > cbEvaluate - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > cbMemoryAddress - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
2021-12-16 10:46:38 +08:00
if ( mCPUDialog ) {
mCPUDialog - > updateButtonStates ( true ) ;
}
2021-09-19 14:28:30 +08:00
}
2023-02-18 12:08:03 +08:00
void MainWindow : : stopDebugForNoSymbolTable ( )
{
mDebugger - > stop ( ) ;
2023-04-02 22:53:02 +08:00
if ( QMessageBox : : question ( this ,
2023-04-03 09:39:45 +08:00
tr ( " Correct compile settings for debug " ) ,
tr ( " The executable doesn't have symbol table, and can't be debugged. " )
+ " <BR /><BR /> "
+ tr ( " If you are using the Release compiler set, please use choose the Debug version from toolbar. " )
+ " <BR /><BR /> "
+ tr ( " Or you can manually change the following settings in the options dialog's compiler set page: " )
+ " <BR /> "
+ tr ( " - Turned on the \" Generate debug info (-g3) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Strip executable (-s) \" option. " )
+ " <BR /> "
+ tr ( " - Turned off the \" Optimization level (-O) \" option or set it to \" Debug (-Og) \" . " )
+ " <BR /><BR /> "
+ tr ( " You should recompile after change the compiler set or it's settings. " )
+ " <BR /><BR /> "
+ tr ( " You should recompile after change the compiler set or it's settings. " )
+ " <BR /><BR /> "
2023-04-02 22:53:02 +08:00
+ tr ( " Do you want to mannually change the compiler set settings now? " )
) = = QMessageBox : : Yes ) {
2023-04-03 09:39:45 +08:00
on_actionCompiler_Options_triggered ( ) ;
// Editor * editor = mEditorList->getEditor();
// if (!mProject || (editor && !editor->inProject())) {
// changeOptions(
// SettingsDialog::tr("Compiler Set"),
// SettingsDialog::tr("Compiler")
// );
// } else {
// changeProjectOptions(
// SettingsDialog::tr("Compiler Set"),
// SettingsDialog::tr("Project")
// );
// }
2023-04-02 22:53:02 +08:00
}
2023-02-18 12:08:03 +08:00
}
2022-10-22 23:29:12 +08:00
void MainWindow : : onTodoParsingFile ( const QString & filename )
{
mTodoModel . removeTodosForFile ( filename ) ;
}
2022-11-07 21:44:12 +08:00
2022-10-22 23:29:12 +08:00
void MainWindow : : onTodoParseStarted ( )
2021-10-03 17:18:43 +08:00
{
mTodoModel . clear ( ) ;
}
2022-10-22 23:29:12 +08:00
void MainWindow : : onTodoFound ( const QString & filename , int lineNo , int ch , const QString & line )
2021-10-03 17:18:43 +08:00
{
mTodoModel . addItem ( filename , lineNo , ch , line ) ;
}
void MainWindow : : onTodoParseFinished ( )
{
}
2023-03-03 17:20:33 +08:00
void MainWindow : : onWatchpointHitted ( const QString & var , const QString & oldVal , const QString & newVal )
{
QMessageBox : : information ( this ,
tr ( " Watchpoint hitted " ) ,
tr ( " Value of \" %1 \" has changed: " ) . arg ( var )
+ " <br /> "
+ tr ( " Old value: %1 " ) . arg ( oldVal )
+ " <br /> "
+ tr ( " New value: %1 " ) . arg ( newVal ) ) ;
}
2021-09-17 21:33:19 +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 ) ;
} ) ;
2022-10-21 12:43:02 +08:00
//save all files
2021-09-11 18:42:49 +08:00
// TODO: should we save watches?
2023-03-19 20:51:12 +08:00
if ( fileExists ( mProject - > directory ( ) ) ) {
if ( mEditorList - > projectEditorsModified ( ) ) {
QString s ;
if ( mProject - > name ( ) . isEmpty ( ) ) {
s = mProject - > filename ( ) ;
} else {
s = mProject - > name ( ) ;
}
if ( mSystemTurnedOff ) {
2021-09-11 18:42:49 +08:00
mProject - > saveAll ( ) ;
2022-10-21 12:43:02 +08:00
mEditorList - > saveAllForProject ( ) ;
2023-03-19 20:51:12 +08:00
} 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 ( ) ;
mEditorList - > saveAllForProject ( ) ;
break ;
case QMessageBox : : No :
mEditorList - > clearProjectEditorsModified ( ) ;
mProject - > setModified ( false ) ;
mProject - > saveLayout ( ) ;
break ;
case QMessageBox : : Cancel :
mProject - > saveLayout ( ) ;
return ;
}
2021-09-11 18:42:49 +08:00
}
2023-03-19 20:51:12 +08:00
} else
mProject - > saveAll ( ) ; // always save layout, but not when SaveAll has been called
}
2021-09-11 18:42:49 +08:00
2022-10-24 22:53:46 +08:00
mClosingProject = true ;
2022-10-11 21:51:33 +08:00
2023-03-19 20:51:12 +08:00
if ( fileExists ( mProject - > directory ( ) ) ) {
mBookmarkModel - > saveProjectBookmarks (
changeFileExt ( mProject - > filename ( ) , PROJECT_BOOKMARKS_EXT ) ,
mProject - > directory ( ) ) ;
mDebugger - > saveForProject (
changeFileExt ( mProject - > filename ( ) , PROJECT_DEBUG_EXT ) ,
mProject - > directory ( ) ) ;
}
2022-10-16 23:10:57 +08:00
2021-09-11 18:42:49 +08:00
mClassBrowserModel . beginUpdate ( ) ;
2022-10-11 21:51:33 +08:00
// Remember it
2022-10-17 23:23:05 +08:00
mVisitHistoryManager - > addProject ( mProject - > filename ( ) ) ;
2021-09-11 18:42:49 +08:00
2022-10-11 21:51:33 +08:00
mEditorList - > beginUpdate ( ) ;
mProject . reset ( ) ;
2021-09-11 18:42:49 +08:00
2022-10-11 21:51:33 +08:00
if ( ! mQuitting & & refreshEditor ) {
//reset Class browsing
ui - > tabExplorer - > setCurrentWidget ( ui - > tabStructure ) ;
Editor * e = mEditorList - > getEditor ( ) ;
updateClassBrowserForEditor ( e ) ;
} else {
mClassBrowserModel . setParser ( nullptr ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
2021-09-11 18:42:49 +08:00
}
2022-10-11 21:51:33 +08:00
mEditorList - > endUpdate ( ) ;
mClassBrowserModel . endUpdate ( ) ;
2021-09-11 18:42:49 +08:00
if ( ! mQuitting ) {
2022-10-23 00:39:24 +08:00
mBookmarkModel - > clear ( true ) ;
2022-10-11 21:51:33 +08:00
mBookmarkModel - > setIsForProject ( false ) ;
2022-10-23 00:39:24 +08:00
mDebugger - > clearForProject ( ) ;
2022-10-16 23:10:57 +08:00
mDebugger - > setIsForProject ( false ) ;
2022-10-23 00:39:24 +08:00
mTodoModel . clear ( true ) ;
2022-10-22 23:29:12 +08:00
mTodoModel . setIsForProject ( false ) ;
2021-09-11 18:42:49 +08:00
// Clear error browser
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-09-11 18:42:49 +08:00
}
2022-12-07 09:48:10 +08:00
updateProjectView ( ) ;
2022-10-24 22:53:46 +08:00
mClosingProject = false ;
2021-09-11 18:42:49 +08:00
}
2023-01-12 16:53:00 +08:00
if ( refreshEditor )
on_cbSearchHistory_currentIndexChanged ( ui - > cbSearchHistory - > currentIndex ( ) ) ;
2021-09-11 18:42:49 +08:00
}
2021-09-17 09:56:52 +08:00
void MainWindow : : updateProjectView ( )
{
if ( mProject ) {
2022-01-08 08:52:50 +08:00
if ( mProjectProxyModel - > sourceModel ( ) ! = mProject - > model ( ) ) {
mProjectProxyModel - > setSourceModel ( mProject - > model ( ) ) ;
mProjectProxyModel - > sort ( 0 ) ;
2022-10-08 23:30:30 +08:00
connect ( mProject . get ( ) , & Project : : nodeRenamed ,
this , & MainWindow : : onProjectViewNodeRenamed ) ;
2022-10-02 17:23:27 +08:00
// this, &MainWindow::invalidateProjectProxyModel);
// connect(mProject->model(), &ProjectModel::rowsInserted,
// this, &MainWindow::invalidateProjectProxyModel);
// connect(mProject->model(), &QAbstractItemModel::modelReset,
// ui->projectView,&QTreeView::expandAll);
2022-01-08 08:52:50 +08:00
} else
mProjectProxyModel - > invalidate ( ) ;
2022-10-02 13:29:51 +08:00
//ui->projectView->expandAll();
2022-05-23 22:36:22 +08:00
stretchExplorerPanel ( true ) ;
2021-09-17 09:56:52 +08:00
ui - > tabProject - > setVisible ( true ) ;
2022-10-17 23:23:05 +08:00
//ui->tabExplorer->setCurrentWidget(ui->tabProject);
2021-09-17 09:56:52 +08:00
} else {
// Clear project browser
2022-01-08 08:52:50 +08:00
mProjectProxyModel - > setSourceModel ( nullptr ) ;
2021-09-17 09:56:52 +08:00
ui - > tabProject - > setVisible ( false ) ;
}
updateProjectActions ( ) ;
}
2021-08-31 14:40:41 +08:00
void MainWindow : : onFileChanged ( const QString & path )
{
2022-06-08 16:18:06 +08:00
if ( mFilesChangedNotifying . contains ( path ) )
return ;
mFilesChangedNotifying . insert ( path ) ;
2021-08-31 14:40:41 +08:00
Editor * e = mEditorList - > getOpenedEditorByFilename ( path ) ;
if ( e ) {
2021-09-07 10:28:40 +08:00
if ( fileExists ( path ) ) {
2021-08-31 14:40:41 +08:00
e - > activate ( ) ;
2021-11-17 23:21:53 +08:00
if ( QMessageBox : : question ( this , tr ( " File Changed " ) ,
2021-08-31 14:40:41 +08:00
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 ( ) ) ;
}
2022-06-12 18:26:39 +08:00
} else {
e - > setModified ( true ) ;
2021-08-31 14:40:41 +08:00
}
} else {
2022-03-30 23:19:51 +08:00
mFileSystemWatcher . removePath ( path ) ;
2021-11-17 23:21:53 +08:00
if ( QMessageBox : : question ( this , tr ( " File Changed " ) ,
2021-08-31 14:40:41 +08:00
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 ) ;
}
}
}
2022-06-08 16:18:06 +08:00
mFilesChangedNotifying . remove ( path ) ;
2021-08-31 14:40:41 +08:00
}
2023-03-19 20:51:12 +08:00
void MainWindow : : onDirChanged ( const QString & path )
{
if ( mFilesChangedNotifying . contains ( path ) )
return ;
mFilesChangedNotifying . insert ( path ) ;
if ( mProject & & QString : : compare ( mProject - > directory ( ) , path , PATH_SENSITIVITY ) = = 0
& & ! fileExists ( path ) ) {
QMessageBox : : information ( this , tr ( " Project folder removed. " ) ,
tr ( " Folder for project '%1' was removed. " ) . arg ( path )
+ " <BR /><BR /> "
+ tr ( " It will be closed. " ) ) ;
closeProject ( false ) ;
}
mFilesChangedNotifying . remove ( path ) ;
}
2022-02-11 20:19:48 +08:00
void MainWindow : : onFilesViewPathChanged ( )
{
QString filesPath = ui - > cbFilesPath - > currentText ( ) ;
QFileInfo fileInfo ( filesPath ) ;
2022-02-11 20:29:02 +08:00
ui - > cbFilesPath - > blockSignals ( true ) ;
2022-02-11 20:19:48 +08:00
if ( fileInfo . exists ( ) & & fileInfo . isDir ( ) ) {
setFilesViewRoot ( filesPath ) ;
} else {
ui - > cbFilesPath - > setCurrentText ( pSettings - > environment ( ) . currentFolder ( ) ) ;
}
2022-02-11 20:29:02 +08:00
ui - > cbFilesPath - > blockSignals ( false ) ;
2022-02-11 20:19:48 +08:00
}
2021-08-29 10:29:56 +08:00
const std : : shared_ptr < HeaderCompletionPopup > & MainWindow : : headerCompletionPopup ( ) const
{
return mHeaderCompletionPopup ;
}
2021-09-24 11:41:14 +08:00
const std : : shared_ptr < FunctionTooltipWidget > & MainWindow : : functionTip ( ) const
{
return mFunctionTip ;
}
2021-08-29 10:29:56 +08:00
const std : : shared_ptr < CodeCompletionPopup > & MainWindow : : completionPopup ( ) const
{
return mCompletionPopup ;
2021-07-23 13:22:05 +08:00
}
2022-11-11 21:20:57 +08:00
SearchInFileDialog * MainWindow : : searchInFilesDialog ( ) const
2021-08-03 23:55:57 +08:00
{
2022-11-11 21:20:57 +08:00
return mSearchInFilesDialog ;
2021-08-03 23:55:57 +08:00
}
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
{
2022-10-10 18:05:18 +08:00
return mDebugger . get ( ) ;
2021-08-01 09:13:38 +08:00
}
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-11-15 22:08:35 +08:00
if ( mProject ) {
if ( QMessageBox : : question ( this ,
tr ( " New Project File? " ) ,
tr ( " Do you want to add the new file to the project? " ) ,
2023-10-23 19:24:23 +08:00
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
2023-02-12 22:33:34 +08:00
if ( mProject - > options ( ) . isCpp )
newProjectUnitFile ( " cpp " ) ;
else
newProjectUnitFile ( " c " ) ;
2021-11-15 22:08:35 +08:00
return ;
}
}
2021-10-03 09:57:19 +08:00
newEditor ( ) ;
2021-04-07 21:13:15 +08:00
}
2021-04-07 22:44:08 +08:00
void MainWindow : : on_EditorTabsLeft_tabCloseRequested ( int index )
{
2021-09-02 19:36:16 +08:00
Editor * editor = mEditorList - > getEditor ( index , ui - > EditorTabsLeft ) ;
2021-04-08 10:29:21 +08:00
mEditorList - > closeEditor ( editor ) ;
}
2021-10-13 11:32:59 +08:00
void MainWindow : : on_EditorTabsRight_tabCloseRequested ( int index )
{
Editor * editor = mEditorList - > getEditor ( index , ui - > EditorTabsRight ) ;
mEditorList - > closeEditor ( editor ) ;
}
2022-07-06 19:44:44 +08:00
void MainWindow : : onFileSystemModelLayoutChanged ( )
{
ui - > treeFiles - > scrollTo ( ui - > treeFiles - > currentIndex ( ) , QTreeView : : PositionAtCenter ) ;
}
2021-04-08 10:29:21 +08:00
void MainWindow : : on_actionOpen_triggered ( )
{
2021-06-20 09:27:37 +08:00
try {
2021-08-30 18:36:44 +08:00
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 ) ;
2021-11-06 14:49:11 +08:00
if ( ! files . isEmpty ( ) ) {
QDir : : setCurrent ( extractFileDir ( files [ 0 ] ) ) ;
}
2021-06-20 09:27:37 +08:00
openFiles ( files ) ;
} catch ( FileError e ) {
2021-06-21 11:21:26 +08:00
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 ) {
2021-10-09 11:33:23 +08:00
mQuitting = true ;
2021-10-08 20:01:29 +08:00
if ( ! mShouldRemoveAllSettings ) {
2022-12-02 10:19:03 +08:00
if ( mCPUDialog )
mCPUDialog - > close ( ) ;
2021-10-08 20:01:29 +08:00
Settings : : UI & settings = pSettings - > ui ( ) ;
2023-01-12 16:53:00 +08:00
settings . setOpenEditorsWhenReplace ( ui - > chkOpenFileInEditors - > isChecked ( ) ) ;
2021-10-08 20:01:29 +08:00
settings . setMainWindowState ( saveState ( ) ) ;
settings . setMainWindowGeometry ( saveGeometry ( ) ) ;
settings . setBottomPanelIndex ( ui - > tabMessages - > currentIndex ( ) ) ;
2022-05-22 14:31:13 +08:00
settings . setLeftPanelIndex ( ui - > tabExplorer - > currentIndex ( ) ) ;
2022-10-17 23:23:05 +08:00
settings . setDebugPanelIndex ( ui - > debugViews - > currentIndex ( ) ) ;
2021-11-09 21:22:50 +08:00
settings . setShowStatusBar ( ui - > actionStatus_Bar - > isChecked ( ) ) ;
settings . setShowToolWindowBars ( ui - > actionTool_Window_Bars - > isChecked ( ) ) ;
settings . setShowProject ( ui - > actionProject - > isChecked ( ) ) ;
settings . setShowWatch ( ui - > actionWatch - > isChecked ( ) ) ;
settings . setShowStructure ( ui - > actionStructure - > isChecked ( ) ) ;
settings . setShowFiles ( ui - > actionFiles - > isChecked ( ) ) ;
settings . setShowProblemSet ( ui - > actionProblem_Set - > isChecked ( ) ) ;
settings . setShowIssues ( ui - > actionIssues - > isChecked ( ) ) ;
2022-05-21 10:44:39 +08:00
settings . setShowCompileLog ( ui - > actionTools_Output - > isChecked ( ) ) ;
2021-11-09 21:22:50 +08:00
settings . setShowDebug ( ui - > actionDebug_Window - > isChecked ( ) ) ;
settings . setShowSearch ( ui - > actionSearch - > isChecked ( ) ) ;
settings . setShowTODO ( ui - > actionTODO - > isChecked ( ) ) ;
settings . setShowBookmark ( ui - > actionBookmark - > isChecked ( ) ) ;
settings . setShowProblem ( ui - > actionProblem - > isChecked ( ) ) ;
2022-05-22 14:31:13 +08:00
settings . setMessagesTabsSize ( ui - > tabMessages - > currentSize ( ) ) ;
settings . setExplorerTabsSize ( ui - > tabExplorer - > currentSize ( ) ) ;
settings . setShrinkExplorerTabs ( ui - > tabExplorer - > isShrinked ( ) ) ;
settings . setShrinkMessagesTabs ( ui - > tabMessages - > isShrinked ( ) ) ;
2021-10-08 20:01:29 +08:00
settings . save ( ) ;
2021-10-22 15:02:54 +08:00
2023-03-12 09:19:02 +08:00
if ( pSettings - > sync ( ) ! = QSettings : : NoError ) {
QMessageBox : : warning ( nullptr ,
tr ( " Save Error " ) ,
tr ( " Save settings failed! " ) ) ;
}
2021-10-22 15:02:54 +08:00
//save current folder ( for files view )
2021-11-10 10:42:33 +08:00
pSettings - > environment ( ) . setDefaultOpenFolder ( QDir : : currentPath ( ) ) ;
2021-10-22 15:02:54 +08:00
pSettings - > environment ( ) . save ( ) ;
2023-03-12 09:19:02 +08:00
2021-10-22 07:42:51 +08:00
try {
2022-10-11 21:51:33 +08:00
mBookmarkModel - > saveBookmarks ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
2021-10-21 17:31:25 +08:00
+ DEV_BOOKMARK_FILE ) ;
2021-10-22 07:42:51 +08:00
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Save Error " ) ,
e . reason ( ) ) ;
}
2022-11-14 19:10:32 +08:00
try {
int currentIndex = - 1 ;
if ( ui - > lstProblemSet - > currentIndex ( ) . isValid ( ) )
currentIndex = ui - > lstProblemSet - > currentIndex ( ) . row ( ) ;
mOJProblemSetModel . save ( currentIndex ) ;
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Save Error " ) ,
e . reason ( ) ) ;
}
2022-10-16 23:10:57 +08:00
if ( pSettings - > debugger ( ) . autosave ( ) ) {
2021-10-22 07:42:51 +08:00
try {
2022-10-16 23:10:57 +08:00
mDebugger - > saveForNonproject ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_DEBUGGER_FILE ) ;
2021-10-22 07:42:51 +08:00
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Save Error " ) ,
e . reason ( ) ) ;
}
} else
2021-10-21 19:33:11 +08:00
removeFile ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
2022-10-16 23:10:57 +08:00
+ DEV_DEBUGGER_FILE ) ;
2021-10-08 20:01:29 +08:00
}
if ( ! mShouldRemoveAllSettings & & pSettings - > editor ( ) . autoLoadLastFiles ( ) ) {
2023-02-12 22:33:34 +08:00
if ( ! saveLastOpens ( ) ) { //canceled
mClosingAll = false ;
mQuitting = false ;
event - > ignore ( ) ;
return ;
}
2022-10-02 23:32:33 +08:00
} /*else {
2023-07-24 18:38:58 +08:00
//if don't save last open files, close project before editors, to save project opened editors;
2022-10-02 23:32:33 +08:00
} */
if ( mProject ) {
closeProject ( false ) ;
2021-09-27 13:01:01 +08:00
}
2022-08-24 17:05:16 +08:00
mClosingAll = true ;
2021-06-10 09:34:59 +08:00
if ( ! mEditorList - > closeAll ( false ) ) {
2022-08-24 17:05:16 +08:00
mClosingAll = false ;
2021-10-09 11:33:23 +08:00
mQuitting = false ;
2021-04-09 17:48:25 +08:00
event - > ignore ( ) ;
return ;
}
2022-08-24 17:05:16 +08:00
mClosingAll = false ;
2021-04-09 17:48:25 +08:00
2022-10-02 23:32:33 +08:00
// if (!mShouldRemoveAllSettings && pSettings->editor().autoLoadLastFiles()) {
// if (mProject) {
// closeProject(false);
// }
// }
2021-09-27 20:17:24 +08:00
2021-11-02 13:12:36 +08:00
mTcpServer . close ( ) ;
2021-12-29 22:03:18 +08:00
mCompilerManager - > stopAllRunners ( ) ;
2021-09-26 19:40:52 +08:00
mCompilerManager - > stopCompile ( ) ;
mCompilerManager - > stopRun ( ) ;
2021-10-08 20:01:29 +08:00
if ( ! mShouldRemoveAllSettings )
mSymbolUsageManager - > save ( ) ;
2022-03-01 22:03:54 +08:00
if ( mCPUDialog ! = nullptr )
cleanUpCPUDialog ( ) ;
2021-04-09 17:48:25 +08:00
event - > accept ( ) ;
return ;
}
2021-04-11 12:39:22 +08:00
2021-10-20 18:05:43 +08:00
void MainWindow : : showEvent ( QShowEvent * )
2021-09-02 19:36:16 +08:00
{
2023-01-04 09:08:58 +08:00
if ( mFullInitialized )
return ;
mFullInitialized = true ;
2022-01-26 21:36:31 +08:00
applySettings ( ) ;
2021-09-02 19:36:16 +08:00
const Settings : : UI & settings = pSettings - > ui ( ) ;
ui - > tabMessages - > setCurrentIndex ( settings . bottomPanelIndex ( ) ) ;
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setCurrentIndex ( settings . leftPanelIndex ( ) ) ;
2022-10-17 23:23:05 +08:00
ui - > debugViews - > setCurrentIndex ( settings . debugPanelIndex ( ) ) ;
2021-09-02 19:36:16 +08:00
}
2021-10-31 09:21:38 +08:00
void MainWindow : : hideEvent ( QHideEvent * )
{
2022-10-17 23:23:05 +08:00
// Settings::UI& settings = pSettings->ui();
// settings.setBottomPanelIndex(ui->tabMessages->currentIndex());
// settings.setLeftPanelIndex(ui->tabExplorer->currentIndex());
2021-10-31 09:21:38 +08:00
}
2022-02-20 22:36:12 +08:00
bool MainWindow : : event ( QEvent * event )
{
if ( event - > type ( ) = = DPI_CHANGED_EVENT ) {
2022-03-02 15:17:09 +08:00
applySettings ( ) ;
2022-02-20 22:36:12 +08:00
event - > accept ( ) ;
return true ;
}
return QMainWindow : : event ( event ) ;
}
2021-10-23 23:10:34 +08:00
//void MainWindow::dragEnterEvent(QDragEnterEvent *event)
//{
// if (event->mimeData()->hasUrls()){
// event->acceptProposedAction();
// }
//}
2021-09-05 21:17:33 +08:00
2021-10-23 23:10:34 +08:00
//void MainWindow::dropEvent(QDropEvent *event)
//{
// if (event->mimeData()->hasUrls()) {
// foreach(const QUrl& url, event->mimeData()->urls()){
// if (!url.isLocalFile())
// continue;
// 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);
// }
// }
//}
2021-09-05 21:17:33 +08:00
2021-04-11 12:39:22 +08:00
void MainWindow : : on_actionSave_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2023-02-24 12:17:30 +08:00
if ( editor - > inProject ( ) & & mCompileIssuesState = = CompileIssuesState : : ProjectCompilationResultFilled )
mCompileIssuesState = CompileIssuesState : : None ;
2023-01-15 09:43:54 +08:00
editor - > save ( ) ;
2022-10-11 21:51:33 +08:00
// if (editor->inProject() && (mProject))
// mProject->saveAll();
2021-06-20 09:27:37 +08:00
}
2021-04-11 12:39:22 +08:00
}
void MainWindow : : on_actionSaveAs_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2023-01-15 09:43:54 +08:00
editor - > saveAs ( ) ;
2021-04-11 12:39:22 +08:00
}
}
2021-04-16 22:04:48 +08:00
void MainWindow : : on_actionOptions_triggered ( )
{
2021-10-24 17:31:20 +08:00
changeOptions ( ) ;
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 ;
2022-10-18 12:24:59 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
2022-12-13 15:58:27 +08:00
updateCompileActions ( ) ;
2022-10-26 08:45:18 +08:00
if ( mProject & & ( ! e | | e - > inProject ( ) )
) {
if ( index = = mProject - > options ( ) . compilerSet )
return ;
2022-10-18 12:24:59 +08:00
if ( QMessageBox : : warning (
e ,
tr ( " Change Project Compiler Set " ) ,
tr ( " Change the project's compiler set will lose all custom compiler set options. " )
+ " <br /> "
+ tr ( " Do you really want to do that? " ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : No ) ! = QMessageBox : : Yes ) {
2022-10-26 08:45:18 +08:00
mCompilerSet - > setCurrentIndex ( mProject - > options ( ) . compilerSet ) ;
2022-12-11 19:47:43 +08:00
//ui->actionRebuild->trigger();
2021-09-19 14:28:30 +08:00
return ;
}
2022-10-30 11:58:42 +08:00
mProject - > setCompilerSet ( index ) ;
2022-10-18 12:24:59 +08:00
mProject - > saveOptions ( ) ;
scanActiveProject ( true ) ;
return ;
2021-09-19 14:28:30 +08:00
}
2022-10-18 12:24:59 +08:00
2021-04-18 11:41:41 +08:00
pSettings - > compilerSets ( ) . setDefaultIndex ( index ) ;
pSettings - > compilerSets ( ) . saveDefaultIndex ( ) ;
2022-10-18 12:24:59 +08:00
reparseNonProjectEditors ( ) ;
2021-04-18 11:41:41 +08:00
}
2021-04-20 22:24:33 +08:00
2022-02-10 12:03:56 +08:00
void MainWindow : : logToolsOutput ( const QString & msg )
2021-04-20 22:24:33 +08:00
{
2022-02-10 12:03:56 +08:00
ui - > txtToolsOutput - > appendPlainText ( msg ) ;
ui - > txtToolsOutput - > moveCursor ( QTextCursor : : End ) ;
ui - > txtToolsOutput - > moveCursor ( QTextCursor : : StartOfLine ) ;
ui - > txtToolsOutput - > 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
{
2023-02-24 12:17:30 +08:00
if ( issue - > filename . isEmpty ( ) )
return ;
if ( issue - > filename . contains ( " * " ) )
return ;
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 ;
2022-04-19 21:18:41 +08:00
if ( line > e - > document ( ) - > count ( ) )
2021-06-23 22:38:02 +08:00
return ;
2023-01-11 17:06:32 +08:00
int col = std : : min ( issue - > column , e - > document ( ) - > getLine ( line - 1 ) . length ( ) + 1 ) ;
2021-06-24 16:05:19 +08:00
if ( col < 1 )
2023-01-11 17:06:32 +08:00
col = e - > document ( ) - > getLine ( line - 1 ) . length ( ) + 1 ;
2021-06-24 16:05:19 +08:00
e - > addSyntaxIssues ( line , col , issue - > endColumn , issue - > type , issue - > description ) ;
2021-06-23 22:38:02 +08:00
}
}
}
2022-02-10 12:03:56 +08:00
void MainWindow : : clearToolsOutput ( )
{
ui - > txtToolsOutput - > clear ( ) ;
}
2022-10-21 12:43:02 +08:00
void MainWindow : : clearTodos ( )
{
mTodoModel . clear ( ) ;
}
2021-09-19 14:28:30 +08:00
void MainWindow : : onCompileStarted ( )
{
2023-02-24 12:17:30 +08:00
mCompileIssuesState = CompileIssuesState : : Compiling ;
}
void MainWindow : : onProjectCompileStarted ( )
{
mCompileIssuesState = CompileIssuesState : : ProjectCompiling ;
}
void MainWindow : : onSyntaxCheckStarted ( )
{
mCompileIssuesState = CompileIssuesState : : SyntaxChecking ;
2021-09-19 14:28:30 +08:00
}
2022-12-25 12:00:09 +08:00
void MainWindow : : onCompileFinished ( QString filename , bool isCheckSyntax )
2021-06-23 22:38:02 +08:00
{
2021-10-09 11:33:23 +08:00
if ( mQuitting ) {
if ( isCheckSyntax )
mCheckSyntaxInBack = false ;
else
mCompileSuccessionTask = nullptr ;
return ;
}
2023-02-24 12:17:30 +08:00
2021-06-23 22:38:02 +08:00
// Update tab caption
int i = ui - > tabMessages - > indexOf ( ui - > tabIssues ) ;
2021-10-23 16:18:02 +08:00
if ( i ! = - 1 ) {
if ( isCheckSyntax ) {
if ( mCompilerManager - > syntaxCheckIssueCount ( ) > 0 ) {
ui - > tabMessages - > setTabText ( i , tr ( " Issues " ) +
QString ( " (%1) " ) . arg ( mCompilerManager - > syntaxCheckIssueCount ( ) ) ) ;
} else {
ui - > tabMessages - > setTabText ( i , tr ( " Issues " ) ) ;
}
} else {
if ( mCompilerManager - > compileIssueCount ( ) > 0 ) {
ui - > tabMessages - > setTabText ( i , tr ( " Issues " ) +
QString ( " (%1) " ) . arg ( mCompilerManager - > compileIssueCount ( ) ) ) ;
} else {
ui - > tabMessages - > setTabText ( i , tr ( " Issues " ) ) ;
}
}
2021-10-09 11:33:23 +08:00
}
2021-06-23 22:38:02 +08:00
2023-02-24 12:17:30 +08:00
switch ( mCompileIssuesState ) {
case CompileIssuesState : : Compiling :
mCompileIssuesState = CompileIssuesState : : CompilationResultFilled ;
break ;
case CompileIssuesState : : ProjectCompiling :
mCompileIssuesState = CompileIssuesState : : ProjectCompilationResultFilled ;
break ;
case CompileIssuesState : : SyntaxChecking :
mCompileIssuesState = CompileIssuesState : : SyntaxCheckResultFilled ;
break ;
default :
break ;
}
2021-10-09 11:33:23 +08:00
if ( isCheckSyntax ) {
2022-12-25 12:00:09 +08:00
if ( ! CompilerInfoManager : : supportSyntaxCheck ( pSettings - > compilerSets ( ) . defaultSet ( ) - > compilerType ( ) ) ) {
QDir dir ( extractFileDir ( filename ) ) ;
2022-12-25 12:01:51 +08:00
# ifdef Q_OS_WIN
2022-12-25 12:00:09 +08:00
QFile : : remove ( dir . absoluteFilePath ( " a.exe " ) ) ;
2022-12-25 12:01:51 +08:00
# else
QFile : : remove ( dir . absoluteFilePath ( " a.out " ) ) ;
# endif
2022-12-25 12:00:09 +08:00
}
2021-06-23 22:38:02 +08:00
// check syntax in back, don't change message panel
2022-04-07 21:35:09 +08:00
} else if ( ui - > tableIssues - > count ( ) = = 0 ) {
// Close it if there's nothing to show
if ( ui - > tabMessages - > currentIndex ( ) = = i )
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( false ) ;
2021-06-23 22:38:02 +08:00
} else {
2022-04-07 21:35:09 +08:00
if ( ui - > tabMessages - > currentIndex ( ) ! = i ) {
ui - > tabMessages - > setCurrentIndex ( i ) ;
2021-06-23 22:38:02 +08:00
}
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( 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
}
2021-10-09 11:33:23 +08:00
if ( ! isCheckSyntax ) {
//run succession task if there aren't any errors
if ( mCompileSuccessionTask & & mCompilerManager - > compileErrorCount ( ) = = 0 ) {
2023-02-14 23:42:11 +08:00
if ( ! fileExists ( mCompileSuccessionTask - > execName ) ) {
QMessageBox : : critical ( this , tr ( " Compile Failed " ) ,
tr ( " Failed to generate the executable. " ) + " <BR/><BR/> "
+ tr ( " Please check detail info in \" Tools Output \" panel. " ) ) ;
return ;
}
2022-10-12 19:48:35 +08:00
if ( ! mCompileSuccessionTask - > isExecutable ) {
2023-02-14 23:42:11 +08:00
Editor * editor ;
2022-10-12 19:48:35 +08:00
switch ( mCompileSuccessionTask - > type ) {
case MainWindow : : CompileSuccessionTaskType : : RunNormal :
2023-02-14 23:42:11 +08:00
editor = openFile ( mCompileSuccessionTask - > execName ) ;
if ( e & & editor ) {
int line = e - > caretY ( ) ;
int startLine = 1 ;
2023-03-01 19:39:09 +08:00
QString s = " # " + e - > filename ( ) + " : " ;
2023-02-14 23:42:11 +08:00
for ( int i = 0 ; i < editor - > document ( ) - > count ( ) ; i + + ) {
2023-03-01 19:39:09 +08:00
QString t = editor - > document ( ) - > getLine ( i ) . trimmed ( ) ;
2023-02-14 23:42:11 +08:00
if ( t . startsWith ( s , PATH_SENSITIVITY ) ) {
t = t . mid ( s . length ( ) ) ;
int pos = t . indexOf ( " : " ) ;
if ( pos > 0 ) {
QString numstring = t . mid ( 0 , pos ) ;
bool isOk ;
int l = numstring . toInt ( & isOk ) ;
if ( isOk ) {
if ( l < = line )
startLine = i + 1 ;
if ( l > = line )
break ;
2023-01-12 21:58:04 +08:00
}
}
}
}
2023-02-14 23:42:11 +08:00
editor - > setCaretPositionAndActivate ( startLine , 1 ) ;
2023-01-12 21:58:04 +08:00
}
2022-10-12 19:48:35 +08:00
break ;
case MainWindow : : CompileSuccessionTaskType : : RunProblemCases :
case MainWindow : : CompileSuccessionTaskType : : RunCurrentProblemCase :
QMessageBox : : critical ( this , tr ( " Wrong Compiler Settings " ) ,
tr ( " Compiler is set not to generate executable. " ) + " <BR/><BR/> "
+ tr ( " We need the executabe to run problem case. " ) ) ;
break ;
case MainWindow : : CompileSuccessionTaskType : : Debug :
QMessageBox : : critical (
this ,
tr ( " Wrong Compiler Settings " ) ,
tr ( " Compiler is set not to generate executable. " ) + " <BR /><BR /> "
+ tr ( " Please correct this before start debugging " ) ) ;
compile ( ) ;
return ;
break ;
default :
break ;
}
} else {
switch ( mCompileSuccessionTask - > type ) {
case MainWindow : : CompileSuccessionTaskType : : RunNormal :
runExecutable ( mCompileSuccessionTask - > execName , QString ( ) , RunType : : Normal , mCompileSuccessionTask - > binDirs ) ;
break ;
case MainWindow : : CompileSuccessionTaskType : : RunProblemCases :
runExecutable ( mCompileSuccessionTask - > execName , QString ( ) , RunType : : ProblemCases , mCompileSuccessionTask - > binDirs ) ;
break ;
case MainWindow : : CompileSuccessionTaskType : : RunCurrentProblemCase :
runExecutable ( mCompileSuccessionTask - > execName , QString ( ) , RunType : : CurrentProblemCase , mCompileSuccessionTask - > binDirs ) ;
break ;
case MainWindow : : CompileSuccessionTaskType : : Debug :
debug ( ) ;
break ;
default :
break ;
}
2021-06-23 22:38:02 +08:00
}
2021-10-09 11:33:23 +08:00
mCompileSuccessionTask . reset ( ) ;
// Jump to problem location, sorted by significance
} else if ( ( mCompilerManager - > compileIssueCount ( ) > 0 ) & & ( ! mCheckSyntaxInBack ) ) {
2022-04-07 21:35:09 +08:00
bool hasError = false ;
2021-10-09 11:33:23 +08:00
// 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 ) {
ui - > tableIssues - > selectRow ( i ) ;
2022-04-07 21:35:09 +08:00
hasError = true ;
2021-10-09 11:33:23 +08:00
break ;
}
}
2022-04-07 21:35:09 +08:00
if ( ! hasError ) {
// 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 ) {
ui - > tableIssues - > selectRow ( i ) ;
break ;
}
2021-10-09 11:33:23 +08:00
}
2021-06-23 22:38:02 +08:00
}
}
2021-10-09 11:33:23 +08:00
} else {
mCheckSyntaxInBack = false ;
2021-06-23 22:38:02 +08:00
}
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
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onCompileErrorOccured ( const QString & reason )
2021-06-21 11:21:26 +08:00
{
QMessageBox : : critical ( this , tr ( " Compile Failed " ) , reason ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onRunErrorOccured ( const QString & reason )
2021-06-25 12:40:11 +08:00
{
2021-11-01 09:18:23 +08:00
mCompilerManager - > stopRun ( ) ;
2021-06-25 12:40:11 +08:00
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-12-23 17:07:27 +08:00
void MainWindow : : onRunPausingForFinish ( )
{
updateCompileActions ( ) ;
}
2021-11-01 20:44:08 +08:00
void MainWindow : : onRunProblemFinished ( )
{
2022-01-01 17:24:18 +08:00
updateProblemTitle ( ) ;
2021-11-02 01:07:37 +08:00
ui - > pbProblemCases - > setVisible ( false ) ;
2021-11-01 20:44:08 +08:00
updateCompileActions ( ) ;
updateAppTitle ( ) ;
}
void MainWindow : : onOJProblemCaseStarted ( const QString & id , int current , int total )
{
2021-11-02 01:07:37 +08:00
ui - > pbProblemCases - > setVisible ( true ) ;
2021-11-01 20:44:08 +08:00
ui - > pbProblemCases - > setMaximum ( total ) ;
ui - > pbProblemCases - > setValue ( current ) ;
int row = mOJProblemModel . getCaseIndexById ( id ) ;
if ( row > = 0 ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( row ) ;
problemCase - > testState = ProblemCaseTestState : : Testing ;
mOJProblemModel . update ( row ) ;
2022-03-29 18:06:24 +08:00
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
2022-02-04 19:14:10 +08:00
if ( ! idx . isValid ( ) | | row ! = idx . row ( ) ) {
2022-03-29 18:06:24 +08:00
ui - > tblProblemCases - > setCurrentIndex ( mOJProblemModel . index ( row , 0 ) ) ;
2022-02-04 18:51:46 +08:00
}
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseOutput - > clearAll ( ) ;
if ( ui - > txtProblemCaseExpected - > document ( ) - > blockCount ( ) < = 5000 ) {
ui - > txtProblemCaseExpected - > clearFormat ( ) ;
}
2021-11-01 20:44:08 +08:00
}
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onOJProblemCaseFinished ( const QString & id , int current , int total )
2021-11-01 20:44:08 +08:00
{
int row = mOJProblemModel . getCaseIndexById ( id ) ;
if ( row > = 0 ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( row ) ;
ProblemCaseValidator validator ;
2023-08-19 18:01:16 +08:00
problemCase - > testState = validator . validate ( problemCase , pSettings - > executor ( ) . problemCaseValidateType ( ) ) ?
2021-11-01 20:44:08 +08:00
ProblemCaseTestState : : Passed :
ProblemCaseTestState : : Failed ;
mOJProblemModel . update ( row ) ;
2022-02-04 18:51:46 +08:00
updateProblemCaseOutput ( problemCase ) ;
2021-11-01 20:44:08 +08:00
}
ui - > pbProblemCases - > setMaximum ( total ) ;
ui - > pbProblemCases - > setValue ( current ) ;
2022-01-01 17:24:18 +08:00
updateProblemTitle ( ) ;
2021-12-15 19:12:16 +08:00
}
2022-02-08 00:24:08 +08:00
void MainWindow : : onOJProblemCaseNewOutputGetted ( const QString & /* id */ , const QString & line )
2021-12-15 19:12:16 +08:00
{
2022-01-28 00:31:11 +08:00
ui - > txtProblemCaseOutput - > appendPlainText ( line ) ;
2021-11-01 20:44:08 +08:00
}
2022-04-16 20:39:09 +08:00
void MainWindow : : onOJProblemCaseResetOutput ( const QString & /* id */ , const QString & line )
2022-03-27 11:44:52 +08:00
{
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseOutput - > clearAll ( ) ;
2022-03-27 11:44:52 +08:00
ui - > txtProblemCaseOutput - > setPlainText ( line ) ;
}
2021-08-01 23:24:37 +08:00
void MainWindow : : cleanUpCPUDialog ( )
{
2022-03-01 22:03:54 +08:00
disconnect ( mCPUDialog , & CPUDialog : : closed ,
this , & MainWindow : : cleanUpCPUDialog ) ;
2021-08-01 23:24:37 +08:00
CPUDialog * ptr = mCPUDialog ;
mCPUDialog = nullptr ;
ptr - > deleteLater ( ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onDebugCommandInput ( const QString & command )
2021-08-01 23:24:37 +08:00
{
if ( mDebugger - > executing ( ) ) {
2024-03-10 21:25:24 +08:00
mDebugger - > runClientCommand ( command , " " , DebugCommandSource : : Console ) ;
2021-08-01 23:24:37 +08:00
}
}
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
}
2021-04-21 18:58:35 +08:00
void MainWindow : : on_actionRun_triggered ( )
{
2021-06-25 12:40:11 +08:00
runExecutable ( ) ;
2021-04-21 18:58:35 +08:00
}
2021-04-21 23:06:55 +08:00
void MainWindow : : on_actionUndo_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > undo ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionRedo_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > redo ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionCut_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > cutToClipboard ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionSelectAll_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > selectAll ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionCopy_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > copyToClipboard ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionPaste_triggered ( )
{
2021-10-04 20:05:24 +08:00
QClipboard * clipboard = QGuiApplication : : clipboard ( ) ;
const QMimeData * data = clipboard - > mimeData ( ) ;
if ( ! data )
return ;
2022-06-16 09:11:45 +08:00
if ( data - > hasText ( ) ) {
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2022-06-16 09:11:45 +08:00
editor - > pasteFromClipboard ( ) ;
editor - > activate ( ) ;
}
} else if ( data - > hasUrls ( ) ) {
2021-10-04 20:05:24 +08:00
QStringList filesToOpen ;
foreach ( const QUrl & url , data - > urls ( ) ) {
QString s = url . toLocalFile ( ) ;
if ( ! s . isEmpty ( ) ) {
filesToOpen . append ( s ) ;
}
}
if ( ! filesToOpen . isEmpty ( ) )
openFiles ( filesToOpen ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionIndent_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-07 11:02:03 +08:00
editor - > tab ( ) ;
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionUnIndent_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-10-06 23:35:45 +08:00
editor - > shifttab ( ) ;
2021-04-21 23:06:55 +08:00
}
}
2021-04-24 15:57:45 +08:00
void MainWindow : : on_actionToggleComment_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-06-21 11:21:26 +08:00
editor - > toggleComment ( ) ;
2021-04-24 15:57:45 +08:00
}
}
void MainWindow : : on_actionUnfoldAll_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-11-13 17:41:16 +08:00
editor - > unCollpaseAll ( ) ;
2021-04-24 15:57:45 +08:00
}
}
void MainWindow : : on_actionFoldAll_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2021-11-13 17:41:16 +08:00
editor - > collapseAll ( ) ;
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 ;
2022-10-18 12:46:51 +08:00
Editor * editor = openFile ( issue - > filename ) ;
2021-04-29 20:54:44 +08:00
if ( editor = = nullptr )
return ;
2021-06-24 16:05:19 +08:00
editor - > setCaretPositionAndActivate ( issue - > line , issue - > column ) ;
2021-04-29 20:54:44 +08:00
}
2021-06-12 22:36:23 +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 ) {
2021-06-21 11:21:26 +08:00
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
2021-06-20 09:27:37 +08:00
}
2021-06-12 22:36:23 +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 ) {
2021-06-21 11:21:26 +08:00
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
2021-06-20 09:27:37 +08:00
}
2021-06-12 22:36:23 +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 ;
2021-06-21 11:21:26 +08:00
if ( QMessageBox : : warning ( this , tr ( " Confirm Convertion " ) ,
2021-06-12 22:36:23 +08:00
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 ;
2021-06-21 11:21:26 +08:00
if ( QMessageBox : : warning ( this , tr ( " Confirm Convertion " ) ,
2021-06-12 22:36:23 +08:00
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 )
{
2022-05-22 14:31:13 +08:00
if ( index = = ui - > tabMessages - > currentIndex ( ) & & ! ui - > tabMessages - > isShrinked ( ) ) {
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( false ) ;
2022-05-22 14:31:13 +08:00
} else {
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( true ) ;
2021-06-24 16:05:19 +08:00
}
}
2021-06-25 12:40:11 +08:00
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 ;
2022-10-16 23:10:57 +08:00
for ( const PBreakpoint & breakpoint : mDebugger - > breakpointModel ( ) - > breakpoints ( e - > inProject ( ) ) ) {
if ( e - > filename ( ) = = breakpoint - > filename ) {
return true ;
2021-07-25 13:03:46 +08:00
}
}
return false ;
}
2021-07-31 14:04:43 +08:00
void MainWindow : : on_actionStep_Over_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2024-03-10 11:15:10 +08:00
mDebugger - > stepOver ( ) ;
2021-07-31 14:04:43 +08:00
}
}
void MainWindow : : on_actionStep_Into_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2024-03-10 11:15:10 +08:00
mDebugger - > stepInto ( ) ;
2021-07-31 14:04:43 +08:00
}
}
void MainWindow : : on_actionStep_Out_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2024-03-10 11:15:10 +08:00
mDebugger - > stepOut ( ) ;
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();
2024-03-10 11:15:10 +08:00
mDebugger - > runTo ( e - > filename ( ) , e - > caretY ( ) ) ;
2021-07-31 14:04:43 +08:00
}
}
}
void MainWindow : : on_actionContinue_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2024-03-10 11:15:10 +08:00
mDebugger - > resume ( ) ;
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 ( ) ;
2021-09-19 17:59:03 +08:00
if ( e ! = nullptr ) {
if ( e - > selAvail ( ) ) {
s = e - > selText ( ) ;
} else {
2021-09-20 15:57:48 +08:00
s = e - > wordAtCursor ( ) ;
2021-09-19 17:59:03 +08:00
}
2021-08-01 01:06:43 +08:00
}
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 ( )
{
2021-11-25 09:05:45 +08:00
showCPUInfoDialog ( ) ;
2021-08-01 23:24:37 +08:00
}
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 ( ) ) {
2022-10-10 18:05:18 +08:00
connect ( mDebugger . get ( ) , & Debugger : : evalValueReady ,
2021-08-29 22:08:43 +08:00
this , & MainWindow : : onEvalValueReady ) ;
2024-03-10 09:56:20 +08:00
mDebugger - > evalExpression ( s ) ;
2022-01-11 22:29:03 +08:00
pMainWindow - > debugger ( ) - > refreshAll ( ) ;
2021-08-02 21:58:39 +08:00
}
2021-08-02 10:08:25 +08:00
}
2021-08-03 23:55:57 +08:00
2021-09-29 22:55:53 +08:00
void MainWindow : : onDebugMemoryAddressInput ( )
{
QString s = ui - > cbMemoryAddress - > currentText ( ) . trimmed ( ) ;
if ( ! s . isEmpty ( ) ) {
2022-01-11 22:29:03 +08:00
// connect(mDebugger, &Debugger::memoryExamineReady,
// this, &MainWindow::onMemoryExamineReady);
2024-03-10 11:15:10 +08:00
mDebugger - > readMemory ( s ,
pSettings - > debugger ( ) . memoryViewRows ( ) ,
pSettings - > debugger ( ) . memoryViewColumns ( )
2022-07-21 15:28:07 +08:00
) ;
2021-09-29 22:55:53 +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-11-24 10:07:35 +08:00
void MainWindow : : onEvalValueReady ( const QString & value )
2021-08-29 22:08:43 +08:00
{
updateDebugEval ( value ) ;
2022-10-10 18:05:18 +08:00
disconnect ( mDebugger . get ( ) , & Debugger : : evalValueReady ,
2021-08-29 22:08:43 +08:00
this , & MainWindow : : onEvalValueReady ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onLocalsReady ( const QStringList & value )
2021-09-29 22:55:53 +08:00
{
ui - > txtLocals - > clear ( ) ;
foreach ( QString s , value ) {
ui - > txtLocals - > appendPlainText ( s ) ;
}
ui - > txtLocals - > moveCursor ( QTextCursor : : Start ) ;
}
2021-08-03 23:55:57 +08:00
void MainWindow : : on_actionFind_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( ! e )
return ;
2023-02-26 08:31:13 +08:00
hideAllSearchDialogs ( ) ;
2022-11-11 21:20:57 +08:00
prepareSearchDialog ( ) ;
2023-02-28 16:17:56 +08:00
if ( e - > selAvail ( ) )
mSearchDialog - > find ( e - > selText ( ) ) ;
else
mSearchDialog - > find ( e - > wordAtCursor ( ) ) ;
2021-08-03 23:55:57 +08:00
}
void MainWindow : : on_actionFind_in_files_triggered ( )
{
2023-02-26 08:31:13 +08:00
hideAllSearchDialogs ( ) ;
prepareSearchInFilesDialog ( ) ;
2021-08-05 19:58:32 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
2023-02-28 16:17:56 +08:00
if ( e - > selAvail ( ) )
mSearchInFilesDialog - > findInFiles ( e - > selText ( ) ) ;
else
mSearchInFilesDialog - > findInFiles ( e - > wordAtCursor ( ) ) ;
2021-08-05 19:58:32 +08:00
} else {
2022-11-11 21:20:57 +08:00
mSearchInFilesDialog - > findInFiles ( " " ) ;
2021-08-05 19:58:32 +08:00
}
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 ;
2022-11-11 21:20:57 +08:00
2023-02-26 08:31:13 +08:00
hideAllSearchDialogs ( ) ;
2023-02-28 16:17:56 +08:00
prepareSearchDialog ( ) ;
if ( e - > selAvail ( ) )
mSearchDialog - > replace ( e - > selText ( ) ) ;
else
mSearchDialog - > replace ( e - > wordAtCursor ( ) ) ;
2021-08-03 23:55:57 +08:00
}
void MainWindow : : on_actionFind_Next_triggered ( )
{
2021-08-04 00:17:38 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( e = = nullptr )
return ;
if ( mSearchDialog = = nullptr )
return ;
2021-08-03 23:55:57 +08:00
2021-08-04 00:17:38 +08:00
mSearchDialog - > findNext ( ) ;
2021-08-03 23:55:57 +08:00
}
void MainWindow : : on_actionFind_Previous_triggered ( )
{
2021-08-04 00:17:38 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( e = = nullptr )
return ;
if ( mSearchDialog = = nullptr )
return ;
2021-08-03 23:55:57 +08:00
2021-08-04 00:17:38 +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 ) ;
2021-09-03 16:39:20 +08:00
PSearchResults results = mSearchResultModel . results ( index ) ;
2021-11-05 10:44:23 +08:00
if ( results ) {
2023-01-12 16:53:00 +08:00
if ( results - > searchType = = SearchType : : Search
& & results - > scope = = SearchFileScope : : wholeProject
& & pMainWindow - > project ( ) = = nullptr )
ui - > btnSearchAgain - > setEnabled ( false ) ;
else
ui - > btnSearchAgain - > setEnabled ( true ) ;
2021-09-03 16:39:20 +08:00
} else {
2021-11-05 10:44:23 +08:00
ui - > btnSearchAgain - > setEnabled ( false ) ;
2021-09-03 16:39:20 +08:00
}
2021-08-05 19:58:32 +08:00
}
2021-11-05 10:44:23 +08:00
void MainWindow : : on_btnSearchAgain_clicked ( )
2021-08-05 19:58:32 +08:00
{
2023-02-26 08:31:13 +08:00
hideAllSearchDialogs ( ) ;
2021-08-05 19:58:32 +08:00
PSearchResults results = mSearchResultModel . currentResults ( ) ;
2021-11-05 10:44:23 +08:00
if ( ! results )
return ;
if ( results - > searchType = = SearchType : : Search ) {
2023-01-12 16:53:00 +08:00
if ( results - > scope = = SearchFileScope : : wholeProject
& & pMainWindow - > project ( ) = = nullptr )
return ;
2023-07-05 15:02:39 +08:00
mSearchInFilesDialog - > findInFiles (
results - > keyword ,
results - > scope ,
results - > options ,
results - > folder ,
results - > filters ,
results - > searchSubfolders ) ;
2021-11-05 10:44:23 +08:00
} else if ( results - > searchType = = SearchType : : FindOccurences ) {
CppRefacter refactor ;
refactor . findOccurence ( results - > statementFullname , results - > scope ) ;
2021-08-05 19:58:32 +08:00
}
}
2021-08-31 11:13:12 +08:00
void MainWindow : : on_actionRemove_Watch_triggered ( )
{
2022-04-22 14:28:53 +08:00
QModelIndexList lst = ui - > watchView - > selectionModel ( ) - > selectedRows ( ) ;
if ( lst . count ( ) < = 1 ) {
QModelIndex index = ui - > watchView - > currentIndex ( ) ;
QModelIndex parent ;
while ( true ) {
parent = ui - > watchView - > model ( ) - > parent ( index ) ;
if ( parent . isValid ( ) ) {
index = parent ;
} else {
break ;
}
2021-08-31 11:13:12 +08:00
}
2022-04-22 14:28:53 +08:00
mDebugger - > removeWatchVar ( index ) ;
} else {
QModelIndexList filteredList ;
foreach ( const QModelIndex & index , lst ) {
if ( ! index . parent ( ) . isValid ( ) )
filteredList . append ( index ) ;
} ;
std : : sort ( filteredList . begin ( ) , filteredList . end ( ) , [ ] ( const QModelIndex & index1 ,
const QModelIndex & index2 ) {
return index1 . row ( ) > index2 . row ( ) ;
} ) ;
foreach ( const QModelIndex & index , filteredList ) {
mDebugger - > removeWatchVar ( index ) ;
} ;
2021-08-31 11:13:12 +08:00
}
}
void MainWindow : : on_actionRemove_All_Watches_triggered ( )
{
mDebugger - > removeWatchVars ( true ) ;
}
void MainWindow : : on_actionModify_Watch_triggered ( )
{
2022-05-30 16:40:45 +08:00
QModelIndexList lst = ui - > watchView - > selectionModel ( ) - > selectedRows ( ) ;
if ( lst . count ( ) < = 1 ) {
QModelIndex index = ui - > watchView - > currentIndex ( ) ;
QModelIndex parent ;
parent = ui - > watchView - > model ( ) - > parent ( index ) ;
if ( parent . isValid ( ) )
return ;
PWatchVar var = mDebugger - > watchVarAt ( index ) ;
if ( ! var )
return ;
bool isOk ;
QString newExpr = QInputDialog : : getText (
this , tr ( " Modify Watch " ) ,
tr ( " Watch Expression " ) ,
QLineEdit : : Normal ,
var - > expression ,
& isOk ) ;
if ( isOk ) {
mDebugger - > modifyWatchVarExpression ( var - > expression , newExpr ) ;
}
}
2021-08-31 11:13:12 +08:00
}
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 ( ) ;
}
2021-09-02 19:36:16 +08:00
2022-05-22 14:31:13 +08:00
void MainWindow : : on_tabExplorer_tabBarClicked ( int index )
2021-09-02 19:36:16 +08:00
{
2022-05-22 14:31:13 +08:00
if ( index = = ui - > tabExplorer - > currentIndex ( ) & & ! ui - > tabExplorer - > isShrinked ( ) ) {
2022-05-23 22:36:22 +08:00
stretchExplorerPanel ( false ) ;
2022-05-22 14:31:13 +08:00
} else {
2022-05-23 22:36:22 +08:00
stretchExplorerPanel ( true ) ;
2021-09-02 19:36:16 +08:00
}
}
2021-10-20 18:05:43 +08:00
void MainWindow : : on_EditorTabsLeft_tabBarDoubleClicked ( int )
2021-09-02 19:36:16 +08:00
{
2021-09-02 20:12:16 +08:00
maximizeEditor ( ) ;
2021-09-02 19:36:16 +08:00
}
2021-10-20 18:05:43 +08:00
void MainWindow : : on_EditorTabsRight_tabBarDoubleClicked ( int )
2021-10-13 11:32:59 +08:00
{
maximizeEditor ( ) ;
}
2021-09-02 19:36:16 +08:00
void MainWindow : : on_actionClose_triggered ( )
{
mClosing = true ;
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
mEditorList - > closeEditor ( e ) ;
}
2021-09-02 20:12:16 +08:00
mClosing = false ;
}
void MainWindow : : on_actionClose_All_triggered ( )
{
2022-08-24 17:05:16 +08:00
mClosingAll = true ;
2021-09-02 20:12:16 +08:00
mClosing = true ;
mEditorList - > closeAll ( mSystemTurnedOff ) ;
mClosing = false ;
2022-08-24 17:05:16 +08:00
mClosingAll = false ;
2021-09-02 20:12:16 +08:00
}
void MainWindow : : on_actionMaximize_Editor_triggered ( )
{
maximizeEditor ( ) ;
2021-09-02 19:36:16 +08:00
}
2021-09-03 00:26:49 +08:00
void MainWindow : : on_actionNext_Editor_triggered ( )
{
mEditorList - > selectNextPage ( ) ;
}
void MainWindow : : on_actionPrevious_Editor_triggered ( )
{
mEditorList - > selectPreviousPage ( ) ;
}
2021-09-03 10:30:08 +08:00
void MainWindow : : on_actionToggle_Breakpoint_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
2021-09-20 15:57:48 +08:00
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) )
2021-09-03 10:30:08 +08:00
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 ;
2021-09-20 15:57:48 +08:00
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
2021-09-03 10:30:08 +08:00
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 ( ) ;
2022-03-18 23:13:43 +08:00
if ( editor ) {
editor - > gotoDeclaration ( editor - > caretXY ( ) ) ;
2021-09-03 11:50:04 +08:00
}
}
void MainWindow : : on_actionGoto_Definition_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-03-18 23:13:43 +08:00
if ( editor ) {
editor - > gotoDefinition ( editor - > caretXY ( ) ) ;
2021-09-03 11:50:04 +08:00
}
}
2021-09-03 16:39:20 +08:00
void MainWindow : : on_actionFind_references_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-09-25 09:55:18 +08:00
QSynedit : : BufferCoord pos ;
2021-09-20 15:57:48 +08:00
if ( editor & & editor - > pointToCharLine ( mEditorContextMenuPos , pos ) ) {
2021-09-03 16:39:20 +08:00
CppRefacter refactor ;
refactor . findOccurence ( editor , pos ) ;
2023-07-02 23:41:32 +08:00
showSearchPanel ( false ) ;
2021-09-03 16:39:20 +08:00
}
}
void MainWindow : : on_actionOpen_Containing_Folder_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
2023-03-23 22:33:04 +08:00
openFileFolderInExplorer ( editor - > filename ( ) ) ;
// QFileInfo info(editor->filename());
// if (!info.path().isEmpty()) {
// QDesktopServices::openUrl(
// QUrl("file:///"+
// includeTrailingPathDelimiter(info.path()),QUrl::TolerantMode));
// }
2021-09-03 16:39:20 +08:00
}
}
void MainWindow : : on_actionOpen_Terminal_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
QFileInfo info ( editor - > filename ( ) ) ;
if ( ! info . path ( ) . isEmpty ( ) ) {
2021-12-28 08:49:31 +08:00
# ifdef Q_OS_WIN
2022-06-16 21:34:31 +08:00
openShell ( info . path ( ) , " cmd.exe " , getBinDirsForCurrentEditor ( ) ) ;
2021-12-28 08:49:31 +08:00
# else
2023-09-25 10:15:07 +08:00
openShell ( info . path ( ) , pSettings - > environment ( ) . terminalPath ( ) , getBinDirsForCurrentEditor ( ) ) ;
2021-12-28 08:49:31 +08:00
# endif
2021-09-03 16:39:20 +08:00
}
}
}
2021-09-04 00:13:42 +08:00
void MainWindow : : on_actionFile_Properties_triggered ( )
{
2021-09-05 05:01:31 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
FilePropertiesDialog dialog ( editor , this ) ;
dialog . exec ( ) ;
dialog . setParent ( nullptr ) ;
}
2021-09-04 00:13:42 +08:00
}
2021-09-05 21:05:38 +08:00
void MainWindow : : on_searchView_doubleClicked ( const QModelIndex & index )
{
QString filename ;
int line ;
int start ;
if ( mSearchResultTreeModel - > getItemFileAndLineChar (
index , filename , line , start ) ) {
2022-10-18 12:46:51 +08:00
Editor * e = openFile ( filename ) ;
2021-09-05 21:05:38 +08:00
if ( e ) {
e - > setCaretPositionAndActivate ( line , start ) ;
}
}
}
void MainWindow : : on_tblStackTrace_doubleClicked ( const QModelIndex & index )
{
2023-03-03 17:20:33 +08:00
switchCurrentStackTrace ( index . row ( ) ) ;
2021-09-05 21:05:38 +08:00
}
void MainWindow : : on_tblBreakpoints_doubleClicked ( const QModelIndex & index )
{
2022-10-16 23:10:57 +08:00
PBreakpoint breakpoint = mDebugger - > breakpointModel ( ) - > breakpoint (
index . row ( ) ,
mDebugger - > isForProject ( ) ) ;
2021-09-05 21:05:38 +08:00
if ( breakpoint ) {
2022-10-18 12:46:51 +08:00
Editor * e = openFile ( breakpoint - > filename ) ;
2021-09-05 21:05:38 +08:00
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 )
{
2022-01-08 08:52:50 +08:00
QModelIndex sourceIndex = mProjectProxyModel - > mapToSource ( index ) ;
if ( ! sourceIndex . isValid ( ) )
2021-09-12 00:17:15 +08:00
return ;
2022-02-08 00:24:08 +08:00
ProjectModelNode * node = static_cast < ProjectModelNode * > ( sourceIndex . internalPointer ( ) ) ;
2021-09-12 00:17:15 +08:00
if ( ! node )
return ;
2022-10-08 23:30:30 +08:00
if ( node - > isUnit ) {
PProjectUnit unit = node - > pUnit . lock ( ) ;
mProject - > openUnit ( unit ) ;
2021-09-12 00:17:15 +08:00
}
}
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 ;
2022-12-11 19:47:43 +08:00
// int oldCompilerSet = mProject->options().compilerSet;
2021-09-14 17:33:47 +08:00
QString oldName = mProject - > name ( ) ;
PSettingsDialog dialog = SettingsDialog : : projectOptionDialog ( ) ;
dialog - > exec ( ) ;
2021-10-25 21:59:01 +08:00
updateCompilerSet ( ) ;
2022-12-11 19:47:43 +08:00
// if (oldCompilerSet != mProject->options().compilerSet)
// ui->actionRebuild->trigger();
2021-09-14 17:33:47 +08:00
}
2021-09-16 23:51:05 +08:00
void MainWindow : : on_actionNew_Project_triggered ( )
{
NewProjectDialog dialog ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
2021-12-03 21:36:12 +08:00
if ( dialog . makeDefaultLanguage ( ) ) {
pSettings - > editor ( ) . setDefaultFileCpp ( dialog . isCppProject ( ) ) ;
pSettings - > editor ( ) . save ( ) ;
}
2021-11-18 21:25:28 +08:00
if ( dialog . useAsDefaultProjectDir ( ) ) {
pSettings - > dirs ( ) . setProjectDir ( dialog . getLocation ( ) ) ;
pSettings - > dirs ( ) . save ( ) ;
}
2021-09-16 23:51:05 +08:00
// 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
2021-11-18 21:25:28 +08:00
QString location = includeTrailingPathDelimiter ( dialog . getLocation ( ) ) + dialog . getProjectName ( ) ;
QDir dir ( location ) ;
2021-09-16 23:51:05 +08:00
if ( ! dir . exists ( ) ) {
if ( QMessageBox : : question ( this ,
tr ( " Folder not exist " ) ,
2021-11-18 21:25:28 +08:00
tr ( " Folder '%1' doesn't exist. Create it now? " ) . arg ( location ) ,
2021-09-16 23:51:05 +08:00
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) ! = QMessageBox : : Yes ) {
return ;
}
2021-11-18 21:25:28 +08:00
if ( ! dir . mkpath ( location ) ) {
2021-09-16 23:51:05 +08:00
QMessageBox : : critical ( this ,
tr ( " Can't create folder " ) ,
2021-11-18 21:25:28 +08:00
tr ( " Failed to create folder '%1'. " ) . arg ( location ) ,
2021-09-16 23:51:05 +08:00
QMessageBox : : Yes ) ;
return ;
}
}
// if cbDefault.Checked then
// devData.DefCpp := rbCpp.Checked;
2023-10-08 19:58:04 +08:00
QDir projectDir = QDir ( location ) ;
if ( ! projectDir . isEmpty ( ) ) {
if ( QMessageBox : : question (
nullptr ,
tr ( " Folder Not Empty " ) ,
tr ( " The project folder is not empty, existing files may be overwritten. " )
+ " <br/><br/> "
+ tr ( " Do you want to proceed? " ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : No
) = = QMessageBox : : No ) {
return ;
}
}
2021-11-18 21:25:28 +08:00
s = includeTrailingPathDelimiter ( location )
2021-09-16 23:51:05 +08:00
+ dialog . getProjectName ( ) + " . " + DEV_PROJECT_EXT ;
if ( fileExists ( s ) ) {
QString saveName = QFileDialog : : getSaveFileName (
this ,
tr ( " Save new project as " ) ,
2021-11-18 21:25:28 +08:00
location ,
2021-12-30 19:25:47 +08:00
tr ( " Red Panda C++ project file (*.dev) " ) ) ;
2021-09-16 23:51:05 +08:00
if ( ! saveName . isEmpty ( ) ) {
s = saveName ;
}
}
2022-10-09 22:19:18 +08:00
mProject = Project : : create ( s , dialog . getProjectName ( ) ,
2022-03-21 09:08:05 +08:00
mEditorList ,
2022-10-09 22:19:18 +08:00
& mFileSystemWatcher ,
dialog . getTemplate ( ) , dialog . isCppProject ( ) ) ;
if ( ! mProject ) {
2021-09-16 23:51:05 +08:00
QMessageBox : : critical ( this ,
tr ( " New project fail " ) ,
tr ( " Can't assign project template " ) ,
QMessageBox : : Ok ) ;
2023-10-08 19:58:04 +08:00
return ;
2021-09-16 23:51:05 +08:00
}
mProject - > saveAll ( ) ;
2021-09-17 09:56:52 +08:00
updateProjectView ( ) ;
2022-10-23 18:39:15 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
updateClassBrowserForEditor ( editor ) ;
2022-10-24 19:23:43 +08:00
if ( editor ) {
PProjectUnit unit = mProject - > findUnit ( editor ) ;
if ( unit ) {
QModelIndex index = mProject - > model ( ) - > getNodeIndex ( unit - > node ( ) . get ( ) ) ;
index = mProjectProxyModel - > mapFromSource ( index ) ;
ui - > projectView - > expand ( index ) ;
ui - > projectView - > setCurrentIndex ( index ) ;
}
}
2022-11-07 21:44:12 +08:00
scanActiveProject ( true ) ;
if ( pSettings - > editor ( ) . parseTodos ( ) )
mTodoParser - > parseFiles ( mProject - > unitFiles ( ) ) ;
2022-10-24 19:23:43 +08:00
if ( pSettings - > ui ( ) . showProject ( ) )
ui - > tabExplorer - > setCurrentWidget ( ui - > tabProject ) ;
2022-11-07 21:44:12 +08:00
setupSlotsForProject ( ) ;
2021-09-16 23:51:05 +08:00
}
2022-01-08 21:23:20 +08:00
pSettings - > ui ( ) . setNewProjectDialogWidth ( dialog . width ( ) ) ;
pSettings - > ui ( ) . setNewProjectDialogHeight ( dialog . height ( ) ) ;
2021-09-16 23:51:05 +08:00
}
2021-09-17 09:56:52 +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 ) {
2023-02-24 12:17:30 +08:00
if ( mCompileIssuesState = = CompileIssuesState : : ProjectCompilationResultFilled )
mCompileIssuesState = CompileIssuesState : : None ;
2021-09-17 13:35:50 +08:00
mProject - > saveAll ( ) ;
}
// Make changes to files
2022-10-21 12:43:02 +08:00
mEditorList - > saveAll ( ) ;
2021-09-17 13:35:50 +08:00
updateAppTitle ( ) ;
}
2021-09-17 09:56:52 +08:00
2021-09-17 13:35:50 +08:00
void MainWindow : : on_actionProject_New_File_triggered ( )
{
2021-11-15 22:08:35 +08:00
newProjectUnitFile ( ) ;
2021-09-17 13:35:50 +08:00
}
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 ) ;
2021-10-19 22:41:38 +08:00
dialog . setAcceptMode ( QFileDialog : : AcceptOpen ) ;
2021-09-17 13:35:50 +08:00
if ( dialog . exec ( ) ) {
2022-01-08 08:52:50 +08:00
QModelIndex current = mProjectProxyModel - > mapToSource ( ui - > projectView - > currentIndex ( ) ) ;
2022-02-08 00:24:08 +08:00
ProjectModelNode * node = nullptr ;
2021-09-17 13:35:50 +08:00
if ( current . isValid ( ) ) {
2022-02-08 00:24:08 +08:00
node = static_cast < ProjectModelNode * > ( current . internalPointer ( ) ) ;
2021-09-17 13:35:50 +08:00
}
2022-02-08 00:24:08 +08:00
PProjectModelNode folderNode = mProject - > pointerToNode ( node ) ;
2021-09-17 13:35:50 +08:00
foreach ( const QString & filename , dialog . selectedFiles ( ) ) {
2022-10-02 13:29:51 +08:00
PProjectUnit newUnit = mProject - > addUnit ( filename , folderNode ) ;
2022-11-07 11:24:23 +08:00
mProject - > cppParser ( ) - > addProjectFile ( filename , true ) ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-16 16:27:09 +08:00
QString branch ;
if ( pSettings - > vcs ( ) . gitOk ( ) & & mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasRepository ( branch ) ) {
2022-02-25 11:07:30 +08:00
QString output ;
2022-02-16 16:27:09 +08:00
mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > add (
2022-02-25 11:07:30 +08:00
extractRelativePath ( mProject - > folder ( ) , filename ) ,
output
2022-02-16 16:27:09 +08:00
) ;
}
2023-08-08 14:41:23 +08:00
# endif
2022-10-02 13:29:51 +08:00
if ( newUnit ) {
QModelIndex index = mProject - > model ( ) - > getNodeIndex ( newUnit - > node ( ) . get ( ) ) ;
index = mProjectProxyModel - > mapFromSource ( index ) ;
if ( index . isValid ( ) ) {
2022-10-24 20:01:46 +08:00
ui - > projectView - > expand ( index ) ;
2022-10-02 13:29:51 +08:00
ui - > projectView - > setCurrentIndex ( index ) ;
}
}
2021-09-17 13:35:50 +08:00
}
2022-10-02 13:29:51 +08:00
mProject - > saveAll ( ) ;
2022-10-02 17:23:27 +08:00
updateProjectView ( ) ;
2021-09-17 13:35:50 +08:00
parseFileList ( mProject - > cppParser ( ) ) ;
}
2021-09-17 09:56:52 +08:00
}
2021-09-17 17:15:35 +08:00
void MainWindow : : on_actionRemove_from_project_triggered ( )
{
if ( ! mProject )
return ;
if ( ! ui - > projectView - > selectionModel ( ) - > hasSelection ( ) )
return ;
2022-10-01 08:54:44 +08:00
bool removeFile = ( QMessageBox : : question ( this , tr ( " Remove file " ) ,
tr ( " Remove the file from disk? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) ;
2023-03-24 17:55:02 +08:00
QList < PProjectUnit > units ;
2021-09-17 17:15:35 +08:00
foreach ( const QModelIndex & index , ui - > projectView - > selectionModel ( ) - > selectedIndexes ( ) ) {
if ( ! index . isValid ( ) )
continue ;
2022-01-08 08:52:50 +08:00
QModelIndex realIndex = mProjectProxyModel - > mapToSource ( index ) ;
2022-02-08 00:24:08 +08:00
ProjectModelNode * node = static_cast < ProjectModelNode * > ( realIndex . internalPointer ( ) ) ;
PProjectModelNode folderNode = mProject - > pointerToNode ( node ) ;
2021-09-17 19:58:37 +08:00
if ( ! folderNode )
2021-09-17 17:15:35 +08:00
continue ;
2022-10-08 23:30:30 +08:00
PProjectUnit unit = folderNode - > pUnit . lock ( ) ;
2023-03-24 17:55:02 +08:00
units . append ( unit ) ;
}
for ( PProjectUnit & unit : units ) {
2022-10-08 23:30:30 +08:00
mProject - > removeUnit ( unit , true , removeFile ) ;
2023-03-24 17:55:02 +08:00
}
2022-11-06 22:51:14 +08:00
mClassBrowserModel . beginUpdate ( ) ;
mClassBrowserModel . endUpdate ( ) ;
2022-10-02 17:23:27 +08:00
ui - > projectView - > selectionModel ( ) - > clearSelection ( ) ;
mProject - > saveAll ( ) ;
updateProjectView ( ) ;
2021-09-17 17:15:35 +08:00
}
2021-09-17 19:58:37 +08:00
void MainWindow : : on_actionView_Makefile_triggered ( )
{
if ( ! mProject )
return ;
2021-09-17 21:33:19 +08:00
prepareProjectForCompile ( ) ;
2021-09-17 19:58:37 +08:00
mCompilerManager - > buildProjectMakefile ( mProject ) ;
openFile ( mProject - > makeFileName ( ) ) ;
2021-09-17 21:33:19 +08:00
}
2021-09-17 19:58:37 +08:00
2021-09-17 21:33:19 +08:00
void MainWindow : : on_actionMakeClean_triggered ( )
{
if ( ! mProject )
return ;
prepareProjectForCompile ( ) ;
mCompilerManager - > cleanProject ( mProject ) ;
2021-09-17 19:58:37 +08:00
}
2021-09-18 10:47:35 +08:00
void MainWindow : : on_actionProject_Open_Folder_In_Explorer_triggered ( )
{
if ( ! mProject )
return ;
2021-09-18 11:08:30 +08:00
QDesktopServices : : openUrl (
QUrl ( " file:/// " + includeTrailingPathDelimiter ( mProject - > directory ( ) ) , QUrl : : TolerantMode ) ) ;
2021-09-18 10:47:35 +08:00
}
void MainWindow : : on_actionProject_Open_In_Terminal_triggered ( )
{
if ( ! mProject )
return ;
2021-12-28 08:49:31 +08:00
# ifdef Q_OS_WIN
2022-06-16 21:34:31 +08:00
openShell ( mProject - > directory ( ) , " cmd.exe " , mProject - > binDirs ( ) ) ;
2021-12-28 08:49:31 +08:00
# else
2023-09-25 10:15:07 +08:00
openShell ( mProject - > directory ( ) , pSettings - > environment ( ) . terminalPath ( ) , mProject - > binDirs ( ) ) ;
2021-12-28 08:49:31 +08:00
# endif
2021-09-18 10:47:35 +08:00
}
2021-10-10 21:23:25 +08:00
const std : : shared_ptr < QHash < StatementKind , std : : shared_ptr < ColorSchemeItem > > > & MainWindow : : statementColors ( ) const
2021-09-25 23:12:36 +08:00
{
return mStatementColors ;
}
2021-09-26 12:19:46 +08:00
void MainWindow : : on_classBrowser_doubleClicked ( const QModelIndex & index )
{
2021-09-26 16:25:17 +08:00
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 ;
2022-10-23 15:22:26 +08:00
Editor * currentEditor = mEditorList - > getEditor ( ) ;
if ( currentEditor ) {
if ( statement - > fileName = = currentEditor - > filename ( )
& & statement - > definitionFileName ! = currentEditor - > filename ( ) ) {
filename = statement - > definitionFileName ;
line = statement - > definitionLine ;
} else if ( statement - > fileName ! = currentEditor - > filename ( )
& & statement - > definitionFileName = = currentEditor - > filename ( ) ) {
filename = statement - > fileName ;
line = statement - > line ;
} else if ( currentEditor - > caretY ( ) = = statement - > line ) {
filename = statement - > definitionFileName ;
line = statement - > definitionLine ;
} else {
filename = statement - > fileName ;
line = statement - > line ;
}
} else {
filename = statement - > fileName ;
line = statement - > line ;
}
2022-10-18 12:46:51 +08:00
Editor * e = openFile ( filename ) ;
2021-09-26 16:25:17 +08:00
if ( e ) {
e - > setCaretPositionAndActivate ( line , 1 ) ;
}
2021-09-26 12:19:46 +08:00
}
2021-10-03 17:18:43 +08:00
const PTodoParser & MainWindow : : todoParser ( ) const
{
return mTodoParser ;
}
2021-09-30 12:52:22 +08:00
PCodeSnippetManager & MainWindow : : codeSnippetManager ( )
{
return mCodeSnippetManager ;
}
2021-09-30 11:20:43 +08:00
PSymbolUsageManager & MainWindow : : symbolUsageManager ( )
{
return mSymbolUsageManager ;
}
2021-10-03 17:18:43 +08:00
2021-11-09 21:22:50 +08:00
void MainWindow : : showHideInfosTab ( QWidget * widget , bool show )
{
2022-05-22 14:31:13 +08:00
int idx = findTabIndex ( ui - > tabExplorer , widget ) ;
2021-11-09 21:22:50 +08:00
if ( idx > = 0 ) {
if ( ! show ) {
2022-05-21 10:44:39 +08:00
if ( mTabInfosData . contains ( widget ) ) {
PTabWidgetInfo info = mTabInfosData [ widget ] ;
2022-05-22 14:31:13 +08:00
info - > icon = ui - > tabExplorer - > tabIcon ( idx ) ;
info - > text = ui - > tabExplorer - > tabText ( idx ) ;
2022-05-21 10:44:39 +08:00
}
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > removeTab ( idx ) ;
2021-11-09 21:22:50 +08:00
}
} else {
if ( show & & mTabInfosData . contains ( widget ) ) {
PTabWidgetInfo info = mTabInfosData [ widget ] ;
int insert = - 1 ;
2022-05-22 14:31:13 +08:00
for ( int i = 0 ; i < ui - > tabExplorer - > count ( ) ; i + + ) {
QWidget * w = ui - > tabExplorer - > widget ( i ) ;
2021-11-09 21:22:50 +08:00
PTabWidgetInfo infoW = mTabInfosData [ w ] ;
if ( infoW - > order > info - > order ) {
insert = i ;
break ;
}
}
if ( insert > = 0 ) {
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > insertTab ( insert , widget , info - > icon , info - > text ) ;
2021-11-09 21:22:50 +08:00
} else {
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > addTab ( widget , info - > icon , info - > text ) ;
2021-11-09 21:22:50 +08:00
}
}
}
}
void MainWindow : : showHideMessagesTab ( QWidget * widget , bool show )
{
int idx = findTabIndex ( ui - > tabMessages , widget ) ;
if ( idx > = 0 ) {
if ( ! show ) {
2022-05-21 10:44:39 +08:00
if ( mTabMessagesData . contains ( widget ) ) {
PTabWidgetInfo info = mTabMessagesData [ widget ] ;
info - > icon = ui - > tabMessages - > tabIcon ( idx ) ;
info - > text = ui - > tabMessages - > tabText ( idx ) ;
}
2021-11-09 21:22:50 +08:00
ui - > tabMessages - > removeTab ( idx ) ;
}
} else {
if ( show & & mTabMessagesData . contains ( widget ) ) {
PTabWidgetInfo info = mTabMessagesData [ widget ] ;
int insert = - 1 ;
for ( int i = 0 ; i < ui - > tabMessages - > count ( ) ; i + + ) {
QWidget * w = ui - > tabMessages - > widget ( i ) ;
PTabWidgetInfo infoW = mTabMessagesData [ w ] ;
if ( infoW - > order > info - > order ) {
insert = i ;
break ;
}
}
if ( insert > = 0 ) {
ui - > tabMessages - > insertTab ( insert , widget , info - > icon , info - > text ) ;
} else {
ui - > tabMessages - > addTab ( widget , info - > icon , info - > text ) ;
}
}
}
}
void MainWindow : : prepareTabInfosData ( )
{
2022-10-24 19:23:43 +08:00
// QHash<int,QWidget*> tabOrders;
// tabOrders.insert(pSettings->ui().projectOrder(), ui->tabProject);
// tabOrders.insert(pSettings->ui().watchOrder(), ui->tabWatch);
// tabOrders.insert(pSettings->ui().structureOrder(), ui->tabStructure);
// tabOrders.insert(pSettings->ui().filesOrder(), ui->tabFiles);
// tabOrders.insert(pSettings->ui().problemSetOrder(), ui->tabProblemSet);
// for (int i=1;i<tabOrders.count();i++) {
// }
2022-05-22 14:31:13 +08:00
for ( int i = 0 ; i < ui - > tabExplorer - > count ( ) ; i + + ) {
QWidget * widget = ui - > tabExplorer - > widget ( i ) ;
2021-11-09 21:22:50 +08:00
PTabWidgetInfo info = std : : make_shared < TabWidgetInfo > ( ) ;
info - > order = i ;
2022-05-22 14:31:13 +08:00
info - > text = ui - > tabExplorer - > tabText ( i ) ;
info - > icon = ui - > tabExplorer - > tabIcon ( i ) ;
2021-11-09 21:22:50 +08:00
mTabInfosData [ widget ] = info ;
}
}
void MainWindow : : prepareTabMessagesData ( )
{
2022-10-24 19:23:43 +08:00
// QHash<int,QWidget*> tabOrders;
// tabOrders.insert(pSettings->ui().issuesOrder(), ui->tabIssues);
// tabOrders.insert(pSettings->ui().compileLogOrder(), ui->tabToolsOutput);
// tabOrders.insert(pSettings->ui().debugOrder(), ui->tabDebug);
// tabOrders.insert(pSettings->ui().searchOrder(), ui->tabSearch);
// tabOrders.insert(pSettings->ui().TODOOrder(), ui->tabTODO);
// tabOrders.insert(pSettings->ui().bookmarkOrder(), ui->tabBookmark);
2021-11-09 21:22:50 +08:00
for ( int i = 0 ; i < ui - > tabMessages - > count ( ) ; i + + ) {
QWidget * widget = ui - > tabMessages - > widget ( i ) ;
PTabWidgetInfo info = std : : make_shared < TabWidgetInfo > ( ) ;
info - > order = i ;
info - > text = ui - > tabMessages - > tabText ( i ) ;
info - > icon = ui - > tabMessages - > tabIcon ( i ) ;
mTabMessagesData [ widget ] = info ;
}
}
2021-11-15 22:08:35 +08:00
2023-02-12 22:33:34 +08:00
void MainWindow : : newProjectUnitFile ( const QString & suffix )
2021-11-15 22:08:35 +08:00
{
if ( ! mProject )
return ;
2022-01-08 08:52:50 +08:00
QModelIndex current = mProjectProxyModel - > mapToSource ( ui - > projectView - > currentIndex ( ) ) ;
2022-02-08 00:24:08 +08:00
ProjectModelNode * node = nullptr ;
2021-11-15 22:08:35 +08:00
if ( current . isValid ( ) ) {
2022-02-08 00:24:08 +08:00
node = static_cast < ProjectModelNode * > ( current . internalPointer ( ) ) ;
2021-11-15 22:08:35 +08:00
}
2022-04-08 17:22:24 +08:00
PProjectModelNode pNode = mProject - > pointerToNode ( node ) ;
2022-10-08 23:30:30 +08:00
while ( pNode & & pNode - > isUnit ) {
2022-04-08 17:22:24 +08:00
pNode = pNode - > parent . lock ( ) ;
}
if ( ! pNode ) {
pNode = mProject - > rootNode ( ) ;
}
2021-11-15 22:08:35 +08:00
QString newFileName ;
2022-04-08 17:22:24 +08:00
PProjectUnit newUnit ;
if ( mProject - > modelType ( ) = = ProjectModelType : : FileSystem ) {
2022-04-08 18:12:40 +08:00
PProjectModelNode modelTypeNode = pNode ;
2022-09-30 17:51:26 +08:00
while ( modelTypeNode & & modelTypeNode - > folderNodeType = = ProjectModelNodeType : : Folder ) {
2022-04-08 18:12:40 +08:00
modelTypeNode = modelTypeNode - > parent . lock ( ) ;
}
2022-05-19 17:57:31 +08:00
if ( ! modelTypeNode ) {
modelTypeNode = mProject - > rootNode ( ) ;
}
2022-04-08 17:22:24 +08:00
NewProjectUnitDialog newProjectUnitDialog ;
2023-02-12 22:33:34 +08:00
if ( ! suffix . isEmpty ( ) ) {
newProjectUnitDialog . setSuffix ( suffix ) ;
2022-05-19 17:57:31 +08:00
} else {
2023-02-12 22:33:34 +08:00
if ( modelTypeNode = = mProject - > rootNode ( ) ) {
2022-05-19 17:57:31 +08:00
if ( mProject - > options ( ) . isCpp )
newProjectUnitDialog . setSuffix ( " cpp " ) ;
else
newProjectUnitDialog . setSuffix ( " c " ) ;
2023-02-12 22:33:34 +08:00
} else {
switch ( modelTypeNode - > folderNodeType ) {
case ProjectModelNodeType : : DUMMY_HEADERS_FOLDER :
newProjectUnitDialog . setSuffix ( " h " ) ;
break ;
case ProjectModelNodeType : : DUMMY_SOURCES_FOLDER :
if ( mProject - > options ( ) . isCpp )
newProjectUnitDialog . setSuffix ( " cpp " ) ;
else
newProjectUnitDialog . setSuffix ( " c " ) ;
break ;
default :
newProjectUnitDialog . setSuffix ( " txt " ) ;
}
2022-05-19 17:57:31 +08:00
}
2022-04-08 17:22:24 +08:00
}
2022-04-08 18:12:40 +08:00
QString folder = mProject - > fileSystemNodeFolderPath ( pNode ) ;
2022-05-19 17:57:31 +08:00
// qDebug()<<folder;
2022-04-08 18:12:40 +08:00
newProjectUnitDialog . setFolder ( folder ) ;
2022-04-08 17:22:24 +08:00
if ( newProjectUnitDialog . exec ( ) ! = QDialog : : Accepted ) {
return ;
}
2022-11-16 09:24:42 +08:00
newFileName = generateAbsolutePath ( newProjectUnitDialog . folder ( ) , newProjectUnitDialog . filename ( ) ) ;
2022-04-08 17:22:24 +08:00
if ( newFileName . isEmpty ( ) )
return ;
} else {
2022-04-08 18:12:40 +08:00
do {
2022-10-30 11:58:42 +08:00
newFileName = QString ( " untitled " ) + QString ( " %1 " ) . arg ( getNewFileNumber ( ) ) ;
2023-02-12 22:33:34 +08:00
if ( ! suffix . isEmpty ( ) ) {
newFileName + = " . " + suffix ;
} else {
if ( mProject - > options ( ) . isCpp )
newFileName + = " .cpp " ;
else
newFileName + = " .c " ;
}
2022-04-08 18:12:40 +08:00
} while ( QDir ( mProject - > directory ( ) ) . exists ( newFileName ) ) ;
2022-04-08 17:22:24 +08:00
newFileName = QInputDialog : : getText (
this ,
tr ( " New Project File Name " ) ,
tr ( " File Name: " ) ,
QLineEdit : : Normal ,
newFileName ) ;
if ( newFileName . isEmpty ( ) )
return ;
2022-11-16 09:24:42 +08:00
newFileName = generateAbsolutePath ( mProject - > directory ( ) , newFileName ) ;
2022-04-08 18:12:40 +08:00
}
if ( fileExists ( newFileName ) ) {
QMessageBox : : critical ( this , tr ( " File Already Exists! " ) ,
tr ( " File '%1' already exists! " ) . arg ( newFileName ) ) ;
return ;
2022-10-21 12:43:02 +08:00
} else {
//create an empty file
createFile ( newFileName ) ;
2021-11-15 22:08:35 +08:00
}
2022-04-08 17:22:24 +08:00
newUnit = mProject - > newUnit (
pNode , newFileName ) ;
2022-10-02 17:23:27 +08:00
setProjectViewCurrentUnit ( newUnit ) ;
2022-02-16 16:27:09 +08:00
mProject - > saveAll ( ) ;
2022-11-07 11:24:23 +08:00
parseFileList ( mProject - > cppParser ( ) ) ;
2022-10-08 23:30:30 +08:00
Editor * editor = mProject - > openUnit ( newUnit , false ) ;
2022-09-23 10:27:44 +08:00
if ( editor )
editor - > activate ( ) ;
2022-02-16 16:27:09 +08:00
QString branch ;
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-16 16:27:09 +08:00
if ( pSettings - > vcs ( ) . gitOk ( ) & & mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasRepository ( branch ) ) {
2022-02-25 11:07:30 +08:00
QString output ;
mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > add ( newFileName , output ) ;
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcon ( newFileName ) ;
2022-02-16 16:27:09 +08:00
}
2023-08-08 14:41:23 +08:00
# endif
2022-10-02 17:23:27 +08:00
updateProjectView ( ) ;
2021-11-15 22:08:35 +08:00
}
2022-01-02 10:37:00 +08:00
2022-03-29 18:06:24 +08:00
void MainWindow : : fillProblemCaseInputAndExpected ( const POJProblemCase & problemCase )
{
ui - > btnProblemCaseInputFileName - > setEnabled ( true ) ;
if ( fileExists ( problemCase - > inputFileName ) ) {
ui - > txtProblemCaseInput - > setReadOnly ( true ) ;
ui - > txtProblemCaseInput - > setPlainText ( readFileToByteArray ( problemCase - > inputFileName ) ) ;
ui - > btnProblemCaseClearInputFileName - > setVisible ( true ) ;
ui - > txtProblemCaseInputFileName - > setText ( extractFileName ( problemCase - > inputFileName ) ) ;
ui - > txtProblemCaseInputFileName - > setToolTip ( problemCase - > inputFileName ) ;
} else {
ui - > txtProblemCaseInput - > setReadOnly ( false ) ;
ui - > txtProblemCaseInput - > setPlainText ( problemCase - > input ) ;
ui - > btnProblemCaseClearInputFileName - > setVisible ( false ) ;
ui - > txtProblemCaseInputFileName - > clear ( ) ;
ui - > txtProblemCaseInputFileName - > setToolTip ( " " ) ;
}
ui - > btnProblemCaseExpectedOutputFileName - > setEnabled ( true ) ;
if ( fileExists ( problemCase - > expectedOutputFileName ) ) {
ui - > txtProblemCaseExpected - > setReadOnly ( true ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseExpected - > clearAll ( ) ;
2022-03-29 18:06:24 +08:00
ui - > txtProblemCaseExpected - > setPlainText ( readFileToByteArray ( problemCase - > expectedOutputFileName ) ) ;
ui - > btnProblemCaseClearExpectedOutputFileName - > setVisible ( true ) ;
ui - > txtProblemCaseExpectedOutputFileName - > setText ( extractFileName ( problemCase - > expectedOutputFileName ) ) ;
ui - > txtProblemCaseExpectedOutputFileName - > setToolTip ( problemCase - > inputFileName ) ;
} else {
ui - > txtProblemCaseExpected - > setReadOnly ( false ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseExpected - > clearAll ( ) ;
2022-03-29 18:06:24 +08:00
ui - > txtProblemCaseExpected - > setPlainText ( problemCase - > expected ) ;
ui - > btnProblemCaseClearExpectedOutputFileName - > setVisible ( false ) ;
ui - > txtProblemCaseExpectedOutputFileName - > clear ( ) ;
ui - > txtProblemCaseExpectedOutputFileName - > setToolTip ( " " ) ;
}
}
2022-02-08 16:48:50 +08:00
void MainWindow : : doFilesViewRemoveFile ( const QModelIndex & index )
{
if ( ! index . isValid ( ) )
return ;
if ( mFileSystemModel . isDir ( index ) ) {
QDir dir ( mFileSystemModel . fileInfo ( index ) . absoluteFilePath ( ) ) ;
if ( ! dir . isEmpty ( ) & &
QMessageBox : : question ( ui - > treeFiles
, tr ( " Delete " )
, tr ( " Folder %1 is not empty. " ) . arg ( mFileSystemModel . fileName ( index ) )
+ tr ( " Do you really want to delete it? " ) ,
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2023-06-29 00:27:06 +08:00
# if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
if ( ! QFile : : moveToTrash ( dir . absolutePath ( ) ) )
dir . removeRecursively ( ) ;
# else
2022-02-08 16:48:50 +08:00
dir . removeRecursively ( ) ;
2023-06-29 00:27:06 +08:00
# endif
2022-02-08 16:48:50 +08:00
} else {
2023-06-29 00:27:06 +08:00
# if QT_VERSION >= QT_VERSION_CHECK(5,15,2)
if ( ! QFile : : moveToTrash ( mFileSystemModel . filePath ( index ) ) )
QFile : : remove ( mFileSystemModel . filePath ( index ) ) ;
# else
2022-02-08 16:48:50 +08:00
QFile : : remove ( mFileSystemModel . filePath ( index ) ) ;
2023-06-29 00:27:06 +08:00
# endif
2022-02-08 16:48:50 +08:00
}
}
2022-10-02 23:32:33 +08:00
void MainWindow : : setProjectViewCurrentUnit ( std : : shared_ptr < ProjectUnit > unit ) {
2022-10-02 17:23:27 +08:00
if ( unit ) {
2022-10-02 23:32:33 +08:00
setProjectViewCurrentNode ( unit - > node ( ) ) ;
}
}
2022-10-18 12:24:59 +08:00
void MainWindow : : reparseNonProjectEditors ( )
{
2023-01-19 11:08:32 +08:00
if ( pSettings - > codeCompletion ( ) . shareParser ( ) ) {
bool hasC = false ;
bool hasCpp = false ;
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( ! e - > inProject ( ) & & e - > parser ( ) ) {
if ( e - > parser ( ) - > language ( ) = = ParserLanguage : : C ) {
hasC = true ;
} else if ( e - > parser ( ) - > language ( ) = = ParserLanguage : : CPlusPlus ) {
hasCpp = true ;
}
}
}
if ( hasC ) {
PCppParser parser { Editor : : sharedParser ( ParserLanguage : : C ) } ;
if ( parser )
resetCppParser ( parser ) ;
}
if ( hasCpp ) {
PCppParser parser { Editor : : sharedParser ( ParserLanguage : : CPlusPlus ) } ;
if ( parser )
resetCppParser ( parser ) ;
}
}
2022-10-18 12:24:59 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( ! e - > inProject ( ) ) {
2023-08-11 13:49:09 +08:00
// if (!pSettings->codeCompletion().clearWhenEditorHidden() || e->isVisible()) {
if ( e - > isVisible ( ) ) {
2022-10-18 12:24:59 +08:00
e - > reparse ( true ) ;
e - > checkSyntaxInBack ( ) ;
}
}
}
}
2022-11-05 19:39:33 +08:00
QString MainWindow : : switchHeaderSourceTarget ( Editor * editor )
{
QString filename = editor - > filename ( ) ;
if ( getFileType ( filename ) = = FileType : : CHeader
| | getFileType ( filename ) = = FileType : : CppHeader ) {
QStringList lst ;
lst . push_back ( " c " ) ;
lst . push_back ( " cc " ) ;
lst . push_back ( " cpp " ) ;
lst . push_back ( " cxx " ) ;
lst . push_back ( " C " ) ;
lst . push_back ( " CC " ) ;
foreach ( const QString & suffix , lst ) {
QString newFile = changeFileExt ( filename , suffix ) ;
if ( fileExists ( newFile ) ) {
return newFile ;
}
}
} else if ( getFileType ( filename ) = = FileType : : CSource ) {
QStringList lst ;
lst . push_back ( " h " ) ;
foreach ( const QString & suffix , lst ) {
QString newFile = changeFileExt ( filename , suffix ) ;
if ( fileExists ( newFile ) ) {
return newFile ;
}
}
} else if ( getFileType ( filename ) = = FileType : : CppSource ) {
QStringList lst ;
lst . push_back ( " h " ) ;
lst . push_back ( " hpp " ) ;
lst . push_back ( " hxx " ) ;
lst . push_back ( " HH " ) ;
lst . push_back ( " H " ) ;
foreach ( const QString & suffix , lst ) {
QString newFile = changeFileExt ( filename , suffix ) ;
if ( fileExists ( newFile ) ) {
return newFile ;
}
}
}
return QString ( ) ;
}
2022-11-07 21:44:12 +08:00
void MainWindow : : setupSlotsForProject ( )
{
connect ( mProject . get ( ) , & Project : : unitAdded ,
this , & MainWindow : : onProjectUnitAdded ) ;
connect ( mProject . get ( ) , & Project : : unitRemoved ,
this , & MainWindow : : onProjectUnitRemoved ) ;
connect ( mProject . get ( ) , & Project : : unitRenamed ,
this , & MainWindow : : onProjectUnitRenamed ) ;
}
void MainWindow : : onProjectUnitAdded ( const QString & filename )
{
mProject - > cppParser ( ) - > addProjectFile ( filename , true ) ;
if ( pSettings - > editor ( ) . parseTodos ( ) ) {
mTodoParser - > parseFile ( filename , true ) ;
}
}
void MainWindow : : onProjectUnitRemoved ( const QString & filename )
{
mProject - > cppParser ( ) - > invalidateFile ( filename ) ;
mProject - > cppParser ( ) - > removeProjectFile ( filename ) ;
if ( pSettings - > editor ( ) . parseTodos ( ) ) {
mTodoModel . removeTodosForFile ( filename ) ;
}
mDebugger - > breakpointModel ( ) - > removeBreakpointsInFile ( filename , true ) ;
mBookmarkModel - > removeBookmarks ( filename , true ) ;
}
void MainWindow : : onProjectUnitRenamed ( const QString & oldFilename , const QString & newFilename )
{
mProject - > cppParser ( ) - > invalidateFile ( oldFilename ) ;
mProject - > cppParser ( ) - > removeProjectFile ( oldFilename ) ;
mProject - > cppParser ( ) - > addProjectFile ( newFilename , true ) ;
parseFileList ( mProject - > cppParser ( ) ) ;
if ( pSettings - > editor ( ) . parseTodos ( ) ) {
mTodoModel . removeTodosForFile ( oldFilename ) ;
mTodoParser - > parseFile ( newFilename , true ) ;
}
mBookmarkModel - > renameBookmarkFile ( oldFilename , newFilename , true ) ;
mDebugger - > breakpointModel ( ) - > renameBreakpointFilenames ( oldFilename , newFilename , true ) ;
}
2022-10-08 23:30:30 +08:00
void MainWindow : : onProjectViewNodeRenamed ( )
{
updateProjectView ( ) ;
}
2022-10-02 23:32:33 +08:00
void MainWindow : : setProjectViewCurrentNode ( PProjectModelNode node )
{
if ( node ) {
QModelIndex index = mProject - > model ( ) - > getNodeIndex ( node . get ( ) ) ;
2022-10-02 17:23:27 +08:00
index = mProjectProxyModel - > mapFromSource ( index ) ;
if ( index . isValid ( ) ) {
2022-10-24 20:01:46 +08:00
ui - > projectView - > expand ( index ) ;
2022-10-02 17:23:27 +08:00
ui - > projectView - > setCurrentIndex ( index ) ;
}
}
}
2022-05-22 14:31:13 +08:00
static void setDockTitlebarLocation ( QDockWidget * dock , const Qt : : DockWidgetArea & area ) {
switch ( area ) {
case Qt : : DockWidgetArea : : BottomDockWidgetArea :
case Qt : : DockWidgetArea : : TopDockWidgetArea :
dock - > setFeatures ( dock - > features ( ) | QDockWidget : : DockWidgetVerticalTitleBar ) ;
break ;
default :
dock - > setFeatures ( dock - > features ( ) & ~ QDockWidget : : DockWidgetVerticalTitleBar ) ;
}
}
static void setTabsInDockLocation ( QTabWidget * tabs , const Qt : : DockWidgetArea & area ) {
switch ( area ) {
case Qt : : DockWidgetArea : : BottomDockWidgetArea :
case Qt : : DockWidgetArea : : TopDockWidgetArea :
tabs - > setTabPosition ( QTabWidget : : TabPosition : : South ) ;
break ;
case Qt : : DockWidgetArea : : LeftDockWidgetArea :
tabs - > setTabPosition ( QTabWidget : : TabPosition : : West ) ;
break ;
case Qt : : DockWidgetArea : : RightDockWidgetArea :
tabs - > setTabPosition ( QTabWidget : : TabPosition : : East ) ;
break ;
default :
break ;
}
}
static void setSplitterInDockLocation ( QSplitter * splitter , const Qt : : DockWidgetArea & area ) {
switch ( area ) {
case Qt : : DockWidgetArea : : BottomDockWidgetArea :
case Qt : : DockWidgetArea : : TopDockWidgetArea :
splitter - > setOrientation ( Qt : : Orientation : : Horizontal ) ;
break ;
default :
splitter - > setOrientation ( Qt : : Orientation : : Vertical ) ;
}
}
void MainWindow : : setDockExplorerToArea ( const Qt : : DockWidgetArea & area )
{
ui - > dockMessages - > setAllowedAreas (
( Qt : : DockWidgetArea : : LeftDockWidgetArea |
Qt : : DockWidgetArea : : BottomDockWidgetArea |
Qt : : DockWidgetArea : : RightDockWidgetArea )
& ~ area ) ;
2022-06-17 18:18:12 +08:00
if ( area = = Qt : : DockWidgetArea : : NoDockWidgetArea )
return ;
setDockTitlebarLocation ( ui - > dockExplorer , area ) ;
setTabsInDockLocation ( ui - > tabExplorer , area ) ;
2022-05-22 14:31:13 +08:00
}
void MainWindow : : setDockMessagesToArea ( const Qt : : DockWidgetArea & area )
{
2022-06-17 18:18:12 +08:00
ui - > dockExplorer - > setAllowedAreas (
( Qt : : DockWidgetArea : : LeftDockWidgetArea |
Qt : : DockWidgetArea : : BottomDockWidgetArea |
Qt : : DockWidgetArea : : RightDockWidgetArea )
& ~ area ) ;
2022-06-17 12:12:12 +08:00
Qt : : DockWidgetArea effectiveArea ;
if ( area = = Qt : : DockWidgetArea : : NoDockWidgetArea ) {
switch ( mMessagesDockLocation ) {
case Qt : : DockWidgetArea : : BottomDockWidgetArea :
case Qt : : DockWidgetArea : : TopDockWidgetArea :
effectiveArea = Qt : : DockWidgetArea : : RightDockWidgetArea ;
break ;
default :
if ( dockWidgetArea ( ui - > dockExplorer ) ! = Qt : : DockWidgetArea : : BottomDockWidgetArea )
effectiveArea = Qt : : DockWidgetArea : : BottomDockWidgetArea ;
else
effectiveArea = Qt : : DockWidgetArea : : LeftDockWidgetArea ;
}
} else {
effectiveArea = area ;
mMessagesDockLocation = area ;
setDockTitlebarLocation ( ui - > dockMessages , effectiveArea ) ;
}
setTabsInDockLocation ( ui - > tabMessages , effectiveArea ) ;
setSplitterInDockLocation ( ui - > splitterDebug , effectiveArea ) ;
setSplitterInDockLocation ( ui - > splitterProblem , effectiveArea ) ;
2022-06-15 11:27:12 +08:00
QGridLayout * layout = ( QGridLayout * ) ui - > panelProblemCase - > layout ( ) ;
layout - > removeWidget ( ui - > widgetProblemCaseInputCaption ) ;
2022-06-15 14:13:11 +08:00
layout - > removeWidget ( ui - > widgetProblemCaseOutputCaption ) ;
2022-06-15 11:27:12 +08:00
layout - > removeWidget ( ui - > widgetProblemCaseExpectedCaption ) ;
layout - > removeWidget ( ui - > txtProblemCaseInput ) ;
layout - > removeWidget ( ui - > txtProblemCaseOutput ) ;
layout - > removeWidget ( ui - > txtProblemCaseExpected ) ;
layout - > removeWidget ( ui - > lblProblemCaseInput ) ;
layout - > removeWidget ( ui - > lblProblemCaseOutput ) ;
layout - > removeWidget ( ui - > lblProblemCaseExpected ) ;
2022-06-17 12:12:12 +08:00
switch ( effectiveArea ) {
2022-06-15 11:27:12 +08:00
case Qt : : DockWidgetArea : : BottomDockWidgetArea :
case Qt : : DockWidgetArea : : TopDockWidgetArea :
layout - > addWidget ( ui - > widgetProblemCaseInputCaption , 0 , 0 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseInput , 1 , 0 , 1 , 1 ) ;
2022-06-15 14:13:11 +08:00
// layout->addWidget(ui->lblProblemCaseInput, 2, 0, 1, 1);
2022-06-15 11:27:12 +08:00
2022-08-05 16:20:50 +08:00
layout - > addWidget ( ui - > widgetProblemCaseOutputCaption , 0 , 1 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseOutput , 1 , 1 , 1 , 1 ) ;
// layout->addWidget(ui->lblProblemCaseOutput, 2, 1, 1, 1);
layout - > addWidget ( ui - > widgetProblemCaseExpectedCaption , 0 , 2 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseExpected , 1 , 2 , 1 , 1 ) ;
// layout->addWidget(ui->lblProblemCaseExpected, 2, 2, 1, 1);
2022-06-15 14:13:11 +08:00
2022-06-15 11:27:12 +08:00
break ;
default :
layout - > addWidget ( ui - > widgetProblemCaseInputCaption , 0 , 0 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseInput , 1 , 0 , 1 , 1 ) ;
2022-06-15 14:13:11 +08:00
//layout->addWidget(ui->lblProblemCaseInput, 2, 0, 1, 1);
2022-06-15 11:27:12 +08:00
2022-08-05 16:20:50 +08:00
layout - > addWidget ( ui - > widgetProblemCaseOutputCaption , 3 , 0 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseOutput , 4 , 0 , 1 , 1 ) ;
//layout->addWidget(ui->lblProblemCaseOutput, 5, 0, 1, 1);
layout - > addWidget ( ui - > widgetProblemCaseExpectedCaption , 6 , 0 , 1 , 1 ) ;
layout - > addWidget ( ui - > txtProblemCaseExpected , 7 , 0 , 1 , 1 ) ;
//layout->addWidget(ui->lblProblemCaseExpected, 8, 0, 1, 1);
2022-06-15 11:27:12 +08:00
}
2022-05-22 14:31:13 +08:00
}
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
void MainWindow : : updateVCSActions ( )
{
bool hasRepository = false ;
bool shouldEnable = false ;
2022-02-20 21:47:57 +08:00
bool canBranch = false ;
2022-02-15 17:22:44 +08:00
if ( ui - > projectView - > isVisible ( ) & & mProject ) {
2022-02-21 11:37:29 +08:00
mProject - > model ( ) - > iconProvider ( ) - > update ( ) ;
2022-02-15 00:01:50 +08:00
QString branch ;
2022-02-21 11:37:29 +08:00
hasRepository = mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasRepository ( branch ) ;
2022-02-15 00:01:50 +08:00
shouldEnable = true ;
2022-02-20 21:47:57 +08:00
canBranch = ! mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasChangedFiles ( )
2022-02-21 09:48:04 +08:00
& & ! mProject - > model ( ) - > iconProvider ( ) - > VCSRepository ( ) - > hasStagedFiles ( ) ;
2022-02-15 00:01:50 +08:00
} else if ( ui - > treeFiles - > isVisible ( ) ) {
2022-02-21 11:37:29 +08:00
mFileSystemModelIconProvider . update ( ) ;
2022-02-15 00:01:50 +08:00
QString branch ;
2022-02-21 11:37:29 +08:00
hasRepository = mFileSystemModelIconProvider . VCSRepository ( ) - > hasRepository ( branch ) ;
2022-02-15 00:01:50 +08:00
shouldEnable = true ;
2022-02-20 21:47:57 +08:00
canBranch = ! mFileSystemModelIconProvider . VCSRepository ( ) - > hasChangedFiles ( )
2022-02-21 09:48:04 +08:00
& & ! mFileSystemModelIconProvider . VCSRepository ( ) - > hasStagedFiles ( ) ;
2022-02-15 00:01:50 +08:00
}
2023-03-03 17:20:33 +08:00
2022-02-24 11:07:37 +08:00
ui - > actionGit_Remotes - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-15 00:01:50 +08:00
ui - > actionGit_Create_Repository - > setEnabled ( ! hasRepository & & shouldEnable ) ;
2023-03-03 17:20:33 +08:00
ui - > actionGit_Push - > setEnabled ( hasRepository & & shouldEnable ) ;
ui - > actionGit_Pull - > setEnabled ( hasRepository & & shouldEnable ) ;
ui - > actionGit_Fetch - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-21 23:35:28 +08:00
ui - > actionGit_Log - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-15 00:01:50 +08:00
ui - > actionGit_Commit - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-20 21:47:57 +08:00
ui - > actionGit_Branch - > setEnabled ( hasRepository & & shouldEnable & & canBranch ) ;
ui - > actionGit_Merge - > setEnabled ( hasRepository & & shouldEnable & & canBranch ) ;
2022-02-15 00:01:50 +08:00
ui - > actionGit_Reset - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-19 20:38:08 +08:00
ui - > actionGit_Restore - > setEnabled ( hasRepository & & shouldEnable ) ;
2022-02-15 00:01:50 +08:00
ui - > actionGit_Revert - > setEnabled ( hasRepository & & shouldEnable ) ;
}
2023-08-08 14:41:23 +08:00
# endif
2022-02-15 00:01:50 +08:00
2022-01-08 08:52:50 +08:00
void MainWindow : : invalidateProjectProxyModel ( )
{
mProjectProxyModel - > invalidate ( ) ;
}
2022-01-02 10:37:00 +08:00
void MainWindow : : onEditorRenamed ( const QString & oldFilename , const QString & newFilename , bool firstSave )
{
if ( firstSave )
mOJProblemSetModel . updateProblemAnswerFilename ( oldFilename , newFilename ) ;
2022-11-07 21:44:12 +08:00
Editor * editor = mEditorList - > getOpenedEditorByFilename ( newFilename ) ;
if ( editor & & ! editor - > inProject ( ) ) {
mBookmarkModel - > renameBookmarkFile ( oldFilename , newFilename , false ) ;
mDebugger - > breakpointModel ( ) - > renameBreakpointFilenames ( oldFilename , newFilename , false ) ;
}
2022-01-02 10:37:00 +08:00
}
2021-10-20 18:05:43 +08:00
void MainWindow : : on_EditorTabsLeft_currentChanged ( int )
2021-10-03 17:18:43 +08:00
{
}
2021-10-20 18:05:43 +08:00
void MainWindow : : on_EditorTabsRight_currentChanged ( int )
2021-10-03 17:18:43 +08:00
{
}
void MainWindow : : on_tableTODO_doubleClicked ( const QModelIndex & index )
{
PTodoItem item = mTodoModel . getItem ( index ) ;
if ( item ) {
Editor * editor = mEditorList - > getOpenedEditorByFilename ( item - > filename ) ;
if ( editor ) {
editor - > setCaretPositionAndActivate ( item - > lineNo , item - > ch + 1 ) ;
}
}
}
2021-10-03 23:12:20 +08:00
void MainWindow : : on_actionAbout_triggered ( )
{
AboutDialog dialog ;
dialog . exec ( ) ;
}
2021-10-04 11:07:35 +08:00
void MainWindow : : on_actionRename_Symbol_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! editor )
return ;
2022-07-04 11:39:06 +08:00
if ( ! editor - > parser ( ) )
return ;
2023-02-17 17:33:48 +08:00
editor - > beginEditing ( ) ;
2022-09-25 09:55:18 +08:00
QSynedit : : BufferCoord oldCaretXY = editor - > caretXY ( ) ;
2022-03-17 20:28:03 +08:00
// mClassBrowserModel.beginUpdate();
2021-10-04 11:07:35 +08:00
QCursor oldCursor = editor - > cursor ( ) ;
editor - > setCursor ( Qt : : CursorShape : : WaitCursor ) ;
2021-10-20 18:05:43 +08:00
auto action = finally ( [ oldCursor , editor ] {
2023-02-17 17:33:48 +08:00
editor - > endEditing ( ) ;
2021-10-04 11:07:35 +08:00
// mClassBrowserModel.EndTreeUpdate;
editor - > setCursor ( oldCursor ) ;
} ) ;
2022-07-04 11:39:06 +08:00
QStringList expression = editor - > getExpressionAtPosition ( oldCaretXY ) ;
if ( expression . isEmpty ( ) & & oldCaretXY . ch > 1 ) {
2022-09-25 09:55:18 +08:00
QSynedit : : BufferCoord coord = oldCaretXY ;
2022-07-04 11:39:06 +08:00
coord . ch - - ;
expression = editor - > getExpressionAtPosition ( coord ) ;
2021-10-04 11:07:35 +08:00
}
2021-10-04 12:49:55 +08:00
if ( editor - > inProject ( ) & & mProject ) {
2022-03-17 20:28:03 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( e - > modified ( ) ) {
mProject - > cppParser ( ) - > parseFile ( editor - > filename ( ) , editor - > inProject ( ) , false , false ) ;
}
}
2022-07-04 11:39:06 +08:00
// Find it's definition
2021-10-04 12:49:55 +08:00
PStatement oldStatement = editor - > parser ( ) - > findStatementOf (
2022-06-12 18:26:39 +08:00
editor - > filename ( ) ,
expression ,
2022-07-04 10:01:40 +08:00
oldCaretXY . line ) ;
2021-10-04 12:49:55 +08:00
// definition of the symbol not found
if ( ! oldStatement )
return ;
// found but not in this file
if ( editor - > filename ( ) ! = oldStatement - > fileName
| | editor - > filename ( ) ! = oldStatement - > definitionFileName ) {
// it's defined in system header, dont rename
if ( mProject - > cppParser ( ) - > isSystemHeaderFile ( oldStatement - > fileName ) ) {
QMessageBox : : critical ( editor ,
tr ( " Rename Error " ) ,
tr ( " Symbol '%1' is defined in system header. " )
. arg ( oldStatement - > fullName ) ) ;
return ;
}
CppRefacter refactor ;
refactor . findOccurence ( editor , oldCaretXY ) ;
showSearchPanel ( true ) ;
return ;
}
}
2022-07-04 11:39:06 +08:00
//not in project
PStatement oldStatement = editor - > parser ( ) - > findStatementOf (
editor - > filename ( ) ,
expression ,
oldCaretXY . line ) ;
if ( ! oldStatement )
return ;
QString word = oldStatement - > command ;
if ( word . isEmpty ( ) )
return ;
if ( isCppKeyword ( word ) ) {
return ;
}
2021-10-04 12:49:55 +08:00
2021-10-04 11:07:35 +08:00
bool ok ;
QString newWord = QInputDialog : : getText ( editor ,
tr ( " Rename Symbol " ) ,
tr ( " New Name " ) ,
QLineEdit : : Normal , word , & ok ) ;
if ( ! ok )
return ;
if ( word = = newWord )
return ;
2022-03-17 20:28:03 +08:00
if ( ! editor - > inProject ( ) & & editor - > modified ( ) ) {
PCppParser parser = editor - > parser ( ) ;
//here we must reparse the file in sync, or rename may fail
parser - > parseFile ( editor - > filename ( ) , editor - > inProject ( ) , false , false ) ;
}
2021-10-04 11:07:35 +08:00
CppRefacter refactor ;
2022-06-12 22:54:34 +08:00
2022-07-04 11:39:06 +08:00
refactor . renameSymbol ( editor , oldCaretXY , newWord ) ;
2022-10-18 12:24:59 +08:00
editor - > reparse ( true ) ;
editor - > checkSyntaxInBack ( ) ;
2023-08-11 13:49:09 +08:00
editor - > reparseTodo ( ) ;
2021-10-04 11:07:35 +08:00
}
2021-10-04 12:49:55 +08:00
void MainWindow : : showSearchReplacePanel ( bool show )
{
ui - > replacePanel - > setVisible ( show ) ;
ui - > cbSearchHistory - > setDisabled ( show ) ;
if ( show & & mSearchResultModel . currentResults ( ) ) {
ui - > cbReplaceInHistory - > setCurrentText (
mSearchResultModel . currentResults ( ) - > keyword ) ;
}
mSearchResultTreeModel - > setSelectable ( show ) ;
}
2022-03-10 20:28:01 +08:00
void MainWindow : : setFilesViewRoot ( const QString & path , bool setOpenFolder )
2021-10-22 15:02:54 +08:00
{
2022-02-15 00:01:50 +08:00
mFileSystemModelIconProvider . setRootFolder ( path ) ;
2022-02-16 16:27:09 +08:00
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
2021-10-22 15:02:54 +08:00
mFileSystemModel . setRootPath ( path ) ;
ui - > treeFiles - > setRootIndex ( mFileSystemModel . index ( path ) ) ;
pSettings - > environment ( ) . setCurrentFolder ( path ) ;
2022-03-10 20:28:01 +08:00
if ( setOpenFolder )
QDir : : setCurrent ( path ) ;
2022-02-11 20:19:48 +08:00
int pos = ui - > cbFilesPath - > findText ( path ) ;
if ( pos < 0 ) {
ui - > cbFilesPath - > addItem ( mFileSystemModel . iconProvider ( ) - > icon ( QFileIconProvider : : Folder ) , path ) ;
pos = ui - > cbFilesPath - > findText ( path ) ;
} else if ( ui - > cbFilesPath - > itemIcon ( pos ) . isNull ( ) ) {
ui - > cbFilesPath - > setItemIcon ( pos , mFileSystemModel . iconProvider ( ) - > icon ( QFileIconProvider : : Folder ) ) ;
}
ui - > cbFilesPath - > setCurrentIndex ( pos ) ;
ui - > cbFilesPath - > lineEdit ( ) - > setCursorPosition ( 1 ) ;
2021-10-22 15:02:54 +08:00
}
2021-10-25 09:31:58 +08:00
void MainWindow : : clearIssues ( )
{
int i = ui - > tabMessages - > indexOf ( ui - > tabIssues ) ;
if ( i ! = - 1 ) {
ui - > tabMessages - > setTabText ( i , tr ( " Issues " ) ) ;
}
ui - > tableIssues - > clearIssues ( ) ;
2023-02-24 12:17:30 +08:00
mCompileIssuesState = CompileIssuesState : : None ;
2021-10-25 09:31:58 +08:00
}
2021-11-01 23:14:17 +08:00
void MainWindow : : doCompileRun ( RunType runType )
{
2022-06-16 21:34:31 +08:00
CompileTarget target = getCompileTarget ( ) ;
QStringList binDirs ;
QString execName ;
if ( target = = CompileTarget : : Project ) {
binDirs = mProject - > binDirs ( ) ;
execName = mProject - > executable ( ) ;
} else {
binDirs = getDefaultCompilerSetBinDirs ( ) ;
}
2021-11-01 23:14:17 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
2022-06-16 21:34:31 +08:00
mCompileSuccessionTask - > binDirs = binDirs ;
2023-03-26 12:34:11 +08:00
mCompileSuccessionTask - > type = runTypeToCompileSuccessionTaskType ( runType ) ;
2021-11-01 23:14:17 +08:00
compile ( ) ;
}
2022-12-01 22:10:44 +08:00
void MainWindow : : doGenerateAssembly ( )
{
CompileTarget target = getCompileTarget ( ) ;
QString execName ;
2022-12-28 16:39:18 +08:00
if ( target ! = CompileTarget : : File
& & target ! = CompileTarget : : Project ) {
return ;
2022-12-01 22:10:44 +08:00
}
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
2022-12-28 16:39:18 +08:00
//mCompileSuccessionTask->binDirs="";
2022-12-01 22:10:44 +08:00
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : RunNormal ;
compile ( false , CppCompileType : : GenerateAssemblyOnly ) ;
}
2021-11-02 19:26:11 +08:00
void MainWindow : : updateProblemCaseOutput ( POJProblemCase problemCase )
{
if ( problemCase - > testState = = ProblemCaseTestState : : Failed ) {
2023-07-12 12:08:26 +08:00
int diffLine = - 1 ;
if ( problemCase - > firstDiffLine ! = - 1 ) {
2022-03-29 21:41:02 +08:00
diffLine = problemCase - > firstDiffLine ;
2023-07-12 12:08:26 +08:00
} else
return ;
2022-03-29 21:41:02 +08:00
if ( diffLine < problemCase - > outputLineCounts ) {
2023-07-13 10:08:01 +08:00
ui - > txtProblemCaseOutput - > highlightLine ( diffLine , mErrorColor ) ;
2023-07-12 12:08:26 +08:00
} else {
2022-03-29 21:41:02 +08:00
ui - > txtProblemCaseOutput - > moveCursor ( QTextCursor : : MoveOperation : : End ) ;
2023-07-12 12:08:26 +08:00
ui - > txtProblemCaseOutput - > moveCursor ( QTextCursor : : MoveOperation : : StartOfLine ) ;
}
if ( diffLine < problemCase - > expectedLineCounts ) {
if ( ui - > txtProblemCaseExpected - > document ( ) - > blockCount ( ) < = 5000 ) {
2023-07-13 10:08:01 +08:00
ui - > txtProblemCaseExpected - > highlightLine ( diffLine , mErrorColor ) ;
} else {
ui - > txtProblemCaseExpected - > locateLine ( diffLine ) ;
2023-07-12 12:08:26 +08:00
}
} else {
ui - > txtProblemCaseExpected - > moveCursor ( QTextCursor : : MoveOperation : : End ) ;
ui - > txtProblemCaseExpected - > moveCursor ( QTextCursor : : MoveOperation : : StartOfLine ) ;
2021-11-02 19:26:11 +08:00
}
2023-07-12 12:08:26 +08:00
} else {
ui - > txtProblemCaseOutput - > moveCursor ( QTextCursor : : MoveOperation : : Start ) ;
ui - > txtProblemCaseExpected - > moveCursor ( QTextCursor : : MoveOperation : : Start ) ;
2021-11-02 19:26:11 +08:00
}
}
void MainWindow : : applyCurrentProblemCaseChanges ( )
{
2022-03-29 18:06:24 +08:00
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
2021-11-02 19:26:11 +08:00
if ( idx . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( problemCase ) {
2022-03-29 18:06:24 +08:00
if ( ! fileExists ( problemCase - > inputFileName ) )
problemCase - > input = ui - > txtProblemCaseInput - > toPlainText ( ) ;
2021-11-02 19:26:11 +08:00
problemCase - > expected = ui - > txtProblemCaseExpected - > toPlainText ( ) ;
}
}
}
2021-10-04 12:49:55 +08:00
void MainWindow : : on_btnReplace_clicked ( )
{
//select all items by default
PSearchResults results = mSearchResultModel . currentResults ( ) ;
if ( ! results ) {
return ;
}
QString newWord = ui - > cbReplaceInHistory - > currentText ( ) ;
foreach ( const PSearchResultTreeItem & file , results - > results ) {
2023-01-12 16:53:00 +08:00
QVector < PSearchResultTreeItem > selections ;
foreach ( const PSearchResultTreeItem & item , file - > results ) {
if ( item - > selected ) {
selections . push_back ( item ) ;
}
}
if ( selections . isEmpty ( ) )
continue ;
Editor * editor = nullptr ;
if ( ui - > chkOpenFileInEditors - > isChecked ( ) ) {
editor = openFile ( file - > filename ) ;
if ( ! editor ) {
QMessageBox : : critical ( this ,
tr ( " Replace Error " ) ,
tr ( " Can't open file '%1' for replace! " ) . arg ( file - > filename ) ) ;
return ;
}
} else {
editor = mEditorList - > getOpenedEditorByFilename ( file - > filename ) ;
}
bool needSave = false ;
std : : shared_ptr < Editor > pEditor ;
if ( editor ) {
editor - > clearSelection ( ) ;
editor - > addGroupBreak ( ) ;
2023-02-17 17:33:48 +08:00
editor - > beginEditing ( ) ;
2023-01-12 16:53:00 +08:00
} else {
needSave = true ;
pEditor = std : : make_shared < Editor > ( nullptr ) ;
editor = pEditor . get ( ) ;
QByteArray encoding ;
editor - > setSyntaxer ( syntaxerManager . getSyntaxer ( QSynedit : : ProgrammingLanguage : : CPP ) ) ;
try {
editor - > document ( ) - > loadFromFile ( file - > filename , ENCODING_AUTO_DETECT , encoding ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this ,
tr ( " Replace Error " ) ,
e . reason ( ) ) ;
return ;
}
2021-10-04 12:49:55 +08:00
}
2023-01-12 16:53:00 +08:00
while ( ! selections . isEmpty ( ) ) {
const PSearchResultTreeItem & item = selections . back ( ) ;
selections . pop_back ( ) ;
2023-01-12 12:07:22 +08:00
QString line = editor - > document ( ) - > getLine ( item - > line - 1 ) ;
2021-10-04 12:49:55 +08:00
if ( line . mid ( item - > start - 1 , results - > keyword . length ( ) ) ! = results - > keyword ) {
QMessageBox : : critical ( editor ,
tr ( " Replace Error " ) ,
tr ( " Contents has changed since last search! " ) ) ;
2023-01-12 16:53:00 +08:00
if ( ! needSave )
2023-02-17 17:33:48 +08:00
editor - > endEditing ( ) ;
2021-10-04 12:49:55 +08:00
return ;
}
line . remove ( item - > start - 1 , results - > keyword . length ( ) ) ;
line . insert ( item - > start - 1 , newWord ) ;
2023-01-12 12:07:22 +08:00
editor - > replaceLine ( item - > line , line ) ;
}
2023-01-12 16:53:00 +08:00
if ( ! needSave ) {
2023-02-17 17:33:48 +08:00
editor - > endEditing ( ) ;
2023-01-12 16:53:00 +08:00
} else {
QByteArray realEncoding ;
QFile toFile ( file - > filename ) ;
try {
editor - > document ( ) - > saveToFile ( toFile , ENCODING_AUTO_DETECT ,
pSettings - > editor ( ) . defaultEncoding ( ) ,
realEncoding ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this ,
tr ( " Replace Error " ) ,
e . reason ( ) ) ;
return ;
}
}
2021-10-04 12:49:55 +08:00
}
showSearchReplacePanel ( false ) ;
2022-05-23 22:36:22 +08:00
stretchMessagesPanel ( false ) ;
2021-10-04 12:49:55 +08:00
}
2021-10-04 14:03:22 +08:00
void MainWindow : : on_btnCancelReplace_clicked ( )
{
showSearchReplacePanel ( false ) ;
}
2021-10-07 07:52:20 +08:00
void MainWindow : : on_actionPrint_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! editor )
return ;
editor - > print ( ) ;
}
2021-10-08 20:01:29 +08:00
bool MainWindow : : shouldRemoveAllSettings ( ) const
{
return mShouldRemoveAllSettings ;
}
2021-10-08 00:06:41 +08:00
const PToolsManager & MainWindow : : toolsManager ( ) const
{
return mToolsManager ;
}
2021-10-12 09:47:58 +08:00
void MainWindow : : on_actionExport_As_RTF_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! editor )
return ;
QString rtfFile = QFileDialog : : getSaveFileName ( editor ,
tr ( " Export As RTF " ) ,
extractFilePath ( editor - > filename ( ) ) ,
tr ( " Rich Text Format Files (*.rtf) " )
) ;
if ( rtfFile . isEmpty ( ) )
return ;
try {
editor - > exportAsRTF ( rtfFile ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( editor ,
" Error " ,
e . reason ( ) ) ;
}
}
void MainWindow : : on_actionExport_As_HTML_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! editor )
return ;
QString htmlFile = QFileDialog : : getSaveFileName ( editor ,
tr ( " Export As HTML " ) ,
extractFilePath ( editor - > filename ( ) ) ,
tr ( " HTML Files (*.html) " )
) ;
if ( htmlFile . isEmpty ( ) )
return ;
try {
editor - > exportAsHTML ( htmlFile ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( editor ,
" Error " ,
e . reason ( ) ) ;
}
}
2021-10-13 11:32:59 +08:00
void MainWindow : : on_actionMove_To_Other_View_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
mEditorList - > swapEditor ( editor ) ;
}
}
2021-10-15 12:17:14 +08:00
void MainWindow : : on_actionC_C_Reference_triggered ( )
{
2023-01-20 12:17:04 +08:00
QFileInfo fileInfo ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString ( " cppreference-%1.chm " ) . arg ( pSettings - > environment ( ) . language ( ) ) ) ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
fileInfo = QFileInfo ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString ( " cppreference.chm " ) ) ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2021-10-15 12:17:14 +08:00
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
2023-01-20 12:17:04 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://zh.cppreference.com/w/cpp " ) ) ;
2021-10-15 12:17:14 +08:00
} else {
QDesktopServices : : openUrl ( QUrl ( " https://en.cppreference.com/w/cpp " ) ) ;
}
}
2021-10-18 23:44:02 +08:00
void MainWindow : : on_actionEGE_Manual_triggered ( )
{
QDesktopServices : : openUrl ( QUrl ( " https://xege.org/ege-open-source " ) ) ;
}
2021-10-21 17:31:25 +08:00
const PBookmarkModel & MainWindow : : bookmarkModel ( ) const
{
return mBookmarkModel ;
}
2022-10-22 23:29:12 +08:00
TodoModel * MainWindow : : todoModel ( )
{
return & mTodoModel ;
}
2021-10-21 17:31:25 +08:00
void MainWindow : : on_actionAdd_bookmark_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
2022-04-19 21:18:41 +08:00
if ( editor - > document ( ) - > count ( ) < = 0 )
2021-10-21 17:31:25 +08:00
return ;
QString desc = QInputDialog : : getText ( editor , tr ( " Bookmark Description " ) ,
tr ( " Description: " ) , QLineEdit : : Normal ,
2023-01-11 17:06:32 +08:00
editor - > document ( ) - > getLine ( line - 1 ) . trimmed ( ) ) ;
2021-10-21 17:31:25 +08:00
desc = desc . trimmed ( ) ;
2022-10-11 21:51:33 +08:00
editor - > addBookmark ( line ) ;
mBookmarkModel - > addBookmark ( editor - > filename ( ) , line , desc , editor - > inProject ( ) ) ;
2021-10-21 17:31:25 +08:00
}
}
void MainWindow : : on_actionRemove_Bookmark_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
editor - > removeBookmark ( line ) ;
2022-10-11 21:51:33 +08:00
mBookmarkModel - > removeBookmark ( editor - > filename ( ) , line , editor - > inProject ( ) ) ;
2021-10-21 17:31:25 +08:00
}
}
void MainWindow : : on_tableBookmark_doubleClicked ( const QModelIndex & index )
{
if ( ! index . isValid ( ) )
return ;
PBookmark bookmark = mBookmarkModel - > bookmark ( index . row ( ) ) ;
if ( bookmark ) {
2022-10-18 12:46:51 +08:00
Editor * editor = openFile ( bookmark - > filename ) ;
2021-10-21 17:31:25 +08:00
if ( editor ) {
editor - > setCaretPositionAndActivate ( bookmark - > line , 1 ) ;
}
}
}
void MainWindow : : on_actionModify_Bookmark_Description_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
PBookmark bookmark = mBookmarkModel - > bookmark ( editor - > filename ( ) , line ) ;
if ( bookmark ) {
QString desc = QInputDialog : : getText ( editor , tr ( " Bookmark Description " ) ,
tr ( " Description: " ) , QLineEdit : : Normal ,
bookmark - > description ) ;
desc = desc . trimmed ( ) ;
mBookmarkModel - > updateDescription ( editor - > filename ( ) , line , desc ) ;
}
}
}
2021-10-22 15:02:54 +08:00
void MainWindow : : on_actionLocate_in_Files_View_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
2022-03-10 20:28:01 +08:00
QFileInfo fileInfo ( editor - > filename ( ) ) ;
2022-10-10 18:05:18 +08:00
//qDebug()<<fileInfo.absoluteFilePath();
//qDebug()<<includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath());
2022-03-10 20:28:01 +08:00
if ( ! fileInfo . absoluteFilePath ( ) . startsWith (
2022-03-30 23:19:51 +08:00
includeTrailingPathDelimiter ( mFileSystemModel . rootDirectory ( ) . absolutePath ( ) ) ,
2022-03-10 20:28:01 +08:00
PATH_SENSITIVITY
) ) {
2022-03-10 12:15:44 +08:00
QString fileDir = extractFileDir ( editor - > filename ( ) ) ;
2022-03-10 20:28:01 +08:00
if ( QMessageBox : : question ( this ,
tr ( " Change working folder " ) ,
tr ( " File '%1' is not in the current working folder. " )
. arg ( extractFileName ( editor - > filename ( ) ) )
+ " <br /> "
+ tr ( " Do you want to change working folder to '%1'? " )
. arg ( fileDir ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes
) ! = QMessageBox : : Yes ) {
return ;
}
2022-03-10 12:15:44 +08:00
if ( ! fileDir . isEmpty ( ) )
2022-03-10 20:28:01 +08:00
setFilesViewRoot ( fileDir , true ) ;
2022-03-10 12:15:44 +08:00
else
return ;
2021-10-22 15:02:54 +08:00
}
2022-03-10 20:28:01 +08:00
QModelIndex index = mFileSystemModel . index ( editor - > filename ( ) ) ;
2022-03-10 12:15:44 +08:00
ui - > treeFiles - > setCurrentIndex ( index ) ;
ui - > treeFiles - > scrollTo ( index , QAbstractItemView : : PositionAtCenter ) ;
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setCurrentWidget ( ui - > tabFiles ) ;
2022-05-23 22:36:22 +08:00
stretchExplorerPanel ( true ) ;
2021-10-22 15:02:54 +08:00
}
}
void MainWindow : : on_treeFiles_doubleClicked ( const QModelIndex & index )
{
2022-06-12 15:48:19 +08:00
if ( index ! = ui - > treeFiles - > currentIndex ( ) )
return ;
2021-10-22 15:02:54 +08:00
QString filepath = mFileSystemModel . filePath ( index ) ;
QFileInfo file ( filepath ) ;
if ( file . isFile ( ) ) {
2022-07-07 20:08:58 +08:00
switch ( getFileType ( filepath ) ) {
case FileType : : Project :
2021-11-15 22:08:35 +08:00
openProject ( filepath ) ;
2022-07-07 20:08:58 +08:00
break ;
case FileType : : Other :
{
QMimeDatabase db ;
QMimeType mimeType = db . mimeTypeForFile ( file ) ;
if ( mimeType . isValid ( ) & & mimeType . name ( ) . startsWith ( " text/ " ) ) {
openFile ( filepath ) ;
} else {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( file . absoluteFilePath ( ) ) ) ;
}
}
break ;
default :
2021-11-15 22:08:35 +08:00
openFile ( filepath ) ;
2021-10-22 15:02:54 +08:00
}
}
}
void MainWindow : : on_actionOpen_Folder_triggered ( )
{
2022-02-24 16:47:05 +08:00
QString folder = QFileDialog : : getExistingDirectory ( this , tr ( " Choose Working Folder " ) ,
2021-10-22 15:02:54 +08:00
pSettings - > environment ( ) . currentFolder ( ) ) ;
if ( ! folder . isEmpty ( ) ) {
2022-03-10 20:28:01 +08:00
setFilesViewRoot ( folder , true ) ;
2021-10-22 15:02:54 +08:00
}
}
2021-10-24 17:31:20 +08:00
void MainWindow : : on_actionRun_Parameters_triggered ( )
{
changeOptions (
SettingsDialog : : tr ( " General " ) ,
SettingsDialog : : tr ( " Program Runner " )
) ;
}
2021-11-01 00:40:11 +08:00
2022-12-17 11:37:33 +08:00
void MainWindow : : onNewProblemSet ( )
2021-11-01 00:40:11 +08:00
{
2021-11-01 09:18:23 +08:00
if ( mOJProblemSetModel . count ( ) > 0 ) {
if ( QMessageBox : : warning ( this ,
tr ( " New Problem Set " ) ,
tr ( " The current problem set is not empty. " )
+ " <br /> "
+ tr ( " Do you want to save it? " ) ,
2021-11-02 09:29:35 +08:00
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) {
2022-12-17 11:37:33 +08:00
onSaveProblemSet ( ) ;
2021-11-02 09:29:35 +08:00
}
2021-11-01 09:18:23 +08:00
}
2021-11-01 00:40:11 +08:00
mOJProblemSetNameCounter + + ;
mOJProblemSetModel . create ( tr ( " Problem Set %1 " ) . arg ( mOJProblemSetNameCounter ) ) ;
2021-11-01 09:18:23 +08:00
ui - > lblProblemSet - > setText ( mOJProblemSetModel . name ( ) ) ;
2022-12-15 16:33:17 +08:00
onProblemSetIndexChanged ( QModelIndex ( ) , QModelIndex ( ) ) ;
2021-11-01 00:40:11 +08:00
}
2022-12-17 11:37:33 +08:00
void MainWindow : : onAddProblem ( )
2021-11-01 00:40:11 +08:00
{
int startCount = mOJProblemSetModel . count ( ) ;
QString name ;
while ( true ) {
2022-03-29 18:06:24 +08:00
name = tr ( " Problem %1 " ) . arg ( startCount + 1 ) ;
2021-11-01 00:40:11 +08:00
if ( ! mOJProblemSetModel . problemNameUsed ( name ) )
break ;
}
POJProblem problem = std : : make_shared < OJProblem > ( ) ;
problem - > name = name ;
mOJProblemSetModel . addProblem ( problem ) ;
ui - > lstProblemSet - > setCurrentIndex ( mOJProblemSetModel . index ( mOJProblemSetModel . count ( ) - 1 ) ) ;
2022-12-24 12:08:13 +08:00
mProblem_Properties - > trigger ( ) ;
2021-11-01 00:40:11 +08:00
}
2022-12-17 11:37:33 +08:00
void MainWindow : : onRemoveProblem ( )
2021-11-01 00:40:11 +08:00
{
2022-12-17 17:20:33 +08:00
if ( ui - > lstProblemSet - > selectionModel ( ) - > selectedIndexes ( ) . isEmpty ( ) ) {
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( idx . isValid ( ) )
mOJProblemSetModel . removeProblem ( idx . row ( ) ) ;
} else {
QList < int > idxList ;
foreach ( const QModelIndex idx , ui - > lstProblemSet - > selectionModel ( ) - > selectedIndexes ( ) ) {
idxList . append ( idx . row ( ) ) ;
}
if ( idxList . isEmpty ( ) )
return ;
std : : sort ( idxList . begin ( ) , idxList . end ( ) , [ ] ( int i1 , int i2 ) {
return i1 > i2 ;
} ) ;
bool oldBlock = ui - > lstProblemSet - > selectionModel ( ) - > blockSignals ( true ) ;
for ( int i = 0 ; i < idxList . count ( ) ; i + + ) {
mOJProblemSetModel . removeProblem ( idxList [ i ] ) ;
}
ui - > lstProblemSet - > selectionModel ( ) - > blockSignals ( oldBlock ) ;
onProblemSetIndexChanged ( ui - > lstProblemSet - > currentIndex ( ) , QModelIndex ( ) ) ;
2022-12-15 16:33:17 +08:00
}
2021-11-01 00:40:11 +08:00
}
2022-12-17 11:37:33 +08:00
void MainWindow : : onSaveProblemSet ( )
2021-11-01 00:40:11 +08:00
{
2022-04-11 17:38:57 +08:00
QFileDialog dialog ( this ) ;
dialog . setWindowTitle ( tr ( " Save Problem Set " ) ) ;
if ( ! mOJProblemSetModel . exportFilename ( ) . isEmpty ( ) ) {
dialog . setDirectory ( mOJProblemSetModel . exportFilename ( ) ) ;
dialog . selectFile ( mOJProblemSetModel . exportFilename ( ) ) ;
} else {
dialog . setDirectory ( QDir ( ) . absolutePath ( ) ) ;
}
dialog . setNameFilter ( tr ( " Problem Set Files (*.pbs) " ) ) ;
dialog . setDefaultSuffix ( " pbs " ) ;
dialog . setFileMode ( QFileDialog : : AnyFile ) ;
dialog . setAcceptMode ( QFileDialog : : AcceptSave ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
QString fileName = dialog . selectedFiles ( ) [ 0 ] ;
2022-02-04 18:51:46 +08:00
QFileInfo fileInfo ( fileName ) ;
if ( fileInfo . suffix ( ) . isEmpty ( ) ) {
fileName . append ( " .pbs " ) ;
}
2021-11-06 14:49:11 +08:00
QDir : : setCurrent ( extractFileDir ( fileName ) ) ;
2021-11-01 00:40:11 +08:00
try {
2021-11-02 19:26:11 +08:00
applyCurrentProblemCaseChanges ( ) ;
2022-11-14 19:10:32 +08:00
int currentIndex = - 1 ;
if ( ui - > lstProblemSet - > currentIndex ( ) . isValid ( ) )
currentIndex = ui - > lstProblemSet - > currentIndex ( ) . row ( ) ;
mOJProblemSetModel . saveToFile ( fileName , currentIndex ) ;
2021-11-01 00:40:11 +08:00
} catch ( FileError & error ) {
QMessageBox : : critical ( this , tr ( " Save Error " ) ,
error . reason ( ) ) ;
}
}
}
2022-12-17 11:37:33 +08:00
void MainWindow : : onLoadProblemSet ( )
2021-11-01 00:40:11 +08:00
{
QString fileName = QFileDialog : : getOpenFileName (
this ,
tr ( " Load Problem Set " ) ,
2021-11-06 14:49:11 +08:00
QString ( ) ,
2021-11-01 00:40:11 +08:00
tr ( " Problem Set Files (*.pbs) " ) ) ;
if ( ! fileName . isEmpty ( ) ) {
2021-11-06 14:49:11 +08:00
QDir : : setCurrent ( extractFileDir ( fileName ) ) ;
2021-11-01 00:40:11 +08:00
try {
2022-11-14 19:10:32 +08:00
int currentIndex ;
mOJProblemSetModel . loadFromFile ( fileName , currentIndex ) ;
if ( currentIndex > = 0 ) {
if ( currentIndex > = 0 ) {
QModelIndex index = mOJProblemSetModel . index ( currentIndex , 0 ) ;
ui - > lstProblemSet - > setCurrentIndex ( index ) ;
ui - > lstProblemSet - > scrollTo ( index ) ;
}
}
2021-11-01 00:40:11 +08:00
} catch ( FileError & error ) {
QMessageBox : : critical ( this , tr ( " Load Error " ) ,
error . reason ( ) ) ;
}
}
2021-11-01 09:18:23 +08:00
ui - > lblProblemSet - > setText ( mOJProblemSetModel . name ( ) ) ;
2021-11-02 01:07:37 +08:00
ui - > lstProblemSet - > setCurrentIndex ( mOJProblemSetModel . index ( 0 , 0 ) ) ;
2021-11-01 00:40:11 +08:00
}
2022-12-17 13:34:11 +08:00
void MainWindow : : onAddProblemCase ( )
2021-11-01 00:40:11 +08:00
{
int startCount = mOJProblemModel . count ( ) ;
QString name ;
while ( true ) {
2022-03-29 18:06:24 +08:00
name = tr ( " Problem Case %1 " ) . arg ( startCount + 1 ) ;
2021-11-01 00:40:11 +08:00
if ( ! mOJProblemSetModel . problemNameUsed ( name ) )
break ;
}
POJProblemCase problemCase = std : : make_shared < OJProblemCase > ( ) ;
problemCase - > name = name ;
2021-11-02 09:29:35 +08:00
problemCase - > testState = ProblemCaseTestState : : NotTested ;
2021-11-01 00:40:11 +08:00
mOJProblemModel . addCase ( problemCase ) ;
2022-03-29 18:06:24 +08:00
ui - > tblProblemCases - > setCurrentIndex ( mOJProblemModel . index ( mOJProblemModel . count ( ) - 1 , 0 ) ) ;
2021-11-01 00:40:11 +08:00
}
2022-12-31 09:36:50 +08:00
void MainWindow : : onProblemRunAllCases ( )
2022-06-13 16:31:41 +08:00
{
if ( mOJProblemModel . count ( ) < = 0 )
return ;
showHideMessagesTab ( ui - > tabProblem , ui - > actionProblem ) ;
2021-11-02 19:26:11 +08:00
applyCurrentProblemCaseChanges ( ) ;
2021-11-01 20:44:08 +08:00
runExecutable ( RunType : : ProblemCases ) ;
}
2021-11-02 23:47:51 +08:00
void MainWindow : : on_actionC_Reference_triggered ( )
{
2023-01-20 12:17:04 +08:00
QFileInfo fileInfo ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString ( " cppreference-%1.chm " ) . arg ( pSettings - > environment ( ) . language ( ) ) ) ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
fileInfo = QFileInfo ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString ( " cppreference.chm " ) ) ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2021-11-02 23:47:51 +08:00
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
2023-01-16 15:42:03 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://zh.cppreference.com/w/c " ) ) ;
2021-11-02 23:47:51 +08:00
} else {
QDesktopServices : : openUrl ( QUrl ( " https://en.cppreference.com/w/c " ) ) ;
}
}
2022-12-17 13:34:11 +08:00
void MainWindow : : onRemoveProblemCases ( )
2021-11-02 23:47:51 +08:00
{
2022-03-29 18:06:24 +08:00
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
2021-11-02 23:47:51 +08:00
if ( idx . isValid ( ) ) {
mOJProblemModel . removeCase ( idx . row ( ) ) ;
}
}
2021-11-06 14:49:11 +08:00
2022-12-17 13:34:11 +08:00
void MainWindow : : onOpenProblemAnswerFile ( )
2021-11-06 14:49:11 +08:00
{
POJProblem problem = mOJProblemModel . problem ( ) ;
if ( ! problem | | problem - > answerProgram . isEmpty ( ) )
return ;
2022-10-18 12:46:51 +08:00
Editor * e = openFile ( problem - > answerProgram ) ;
2021-11-06 14:49:11 +08:00
if ( e ) {
e - > activate ( ) ;
}
}
2021-11-08 21:19:48 +08:00
bool MainWindow : : openningFiles ( ) const
{
return mOpenningFiles ;
}
2022-06-13 09:38:32 +08:00
QList < QAction * > MainWindow : : listShortCutableActions ( )
{
QList < QAction * > actions = findChildren < QAction * > ( QString ( ) , Qt : : FindDirectChildrenOnly ) ;
return actions ;
}
2023-03-03 17:20:33 +08:00
void MainWindow : : switchCurrentStackTrace ( int idx )
{
PTrace trace = mDebugger - > backtraceModel ( ) - > backtrace ( idx ) ;
if ( trace ) {
Editor * e = openFile ( trace - > filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( trace - > line , 1 ) ;
}
2024-03-10 21:25:24 +08:00
mDebugger - > selectFrame ( trace ) ;
2024-03-10 12:57:50 +08:00
mDebugger - > refreshStackVariables ( ) ;
mDebugger - > refreshWatchVars ( ) ;
2023-03-03 17:20:33 +08:00
if ( this - > mCPUDialog ) {
this - > mCPUDialog - > updateInfo ( ) ;
}
if ( idx ! = ui - > tblStackTrace - > currentIndex ( ) . row ( ) ) {
ui - > tblStackTrace - > setCurrentIndex ( ui - > tblStackTrace - > model ( ) - > index ( idx , 0 ) ) ;
}
}
}
2023-03-26 12:34:11 +08:00
MainWindow : : CompileSuccessionTaskType MainWindow : : runTypeToCompileSuccessionTaskType ( RunType runType )
{
switch ( runType ) {
case RunType : : CurrentProblemCase :
return CompileSuccessionTaskType : : RunCurrentProblemCase ;
case RunType : : ProblemCases :
return CompileSuccessionTaskType : : RunProblemCases ;
default :
return CompileSuccessionTaskType : : RunNormal ;
}
}
2022-06-13 09:38:32 +08:00
2021-11-09 21:22:50 +08:00
void MainWindow : : on_actionTool_Window_Bars_triggered ( )
{
2022-05-22 14:31:13 +08:00
bool state = ui - > tabExplorer - > isVisible ( ) ;
2021-11-09 21:22:50 +08:00
state = ! state ;
2022-05-22 14:31:13 +08:00
ui - > tabExplorer - > setVisible ( state ) ;
2021-11-09 21:22:50 +08:00
ui - > tabMessages - > setVisible ( state ) ;
ui - > actionTool_Window_Bars - > setChecked ( state ) ;
}
void MainWindow : : on_actionStatus_Bar_triggered ( )
{
bool state = ui - > statusbar - > isVisible ( ) ;
state = ! state ;
ui - > statusbar - > setVisible ( state ) ;
ui - > actionStatus_Bar - > setChecked ( state ) ;
}
void MainWindow : : on_actionProject_triggered ( )
{
bool state = ui - > actionProject - > isChecked ( ) ;
ui - > actionProject - > setChecked ( state ) ;
showHideInfosTab ( ui - > tabProject , state ) ;
}
void MainWindow : : on_actionWatch_triggered ( )
{
bool state = ui - > actionWatch - > isChecked ( ) ;
ui - > actionWatch - > setChecked ( state ) ;
showHideInfosTab ( ui - > tabWatch , state ) ;
}
void MainWindow : : on_actionStructure_triggered ( )
{
bool state = ui - > actionStructure - > isChecked ( ) ;
ui - > actionStructure - > setChecked ( state ) ;
showHideInfosTab ( ui - > tabStructure , state ) ;
}
void MainWindow : : on_actionFiles_triggered ( )
{
bool state = ui - > actionFiles - > isChecked ( ) ;
ui - > actionFiles - > setChecked ( state ) ;
showHideInfosTab ( ui - > tabFiles , state ) ;
}
void MainWindow : : on_actionProblem_Set_triggered ( )
{
bool state = ui - > actionProblem_Set - > isChecked ( ) ;
ui - > actionProblem_Set - > setChecked ( state ) ;
2021-11-09 21:32:23 +08:00
showHideInfosTab ( ui - > tabProblemSet , state ) ;
2021-11-09 21:22:50 +08:00
}
void MainWindow : : on_actionIssues_triggered ( )
{
bool state = ui - > actionIssues - > isChecked ( ) ;
ui - > actionIssues - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabIssues , state ) ;
}
2022-02-10 12:03:56 +08:00
void MainWindow : : on_actionTools_Output_triggered ( )
2021-11-09 21:22:50 +08:00
{
2022-02-10 12:03:56 +08:00
bool state = ui - > actionTools_Output - > isChecked ( ) ;
ui - > actionTools_Output - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabToolsOutput , state ) ;
2021-11-09 21:22:50 +08:00
}
void MainWindow : : on_actionDebug_Window_triggered ( )
{
2022-02-10 12:03:56 +08:00
bool state = ui - > actionDebug_Window - > isChecked ( ) ;
2021-11-09 21:22:50 +08:00
ui - > actionDebug_Window - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabDebug , state ) ;
}
void MainWindow : : on_actionSearch_triggered ( )
{
bool state = ui - > actionSearch - > isChecked ( ) ;
ui - > actionSearch - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabSearch , state ) ;
}
void MainWindow : : on_actionTODO_triggered ( )
{
bool state = ui - > actionTODO - > isChecked ( ) ;
ui - > actionTODO - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabTODO , state ) ;
}
void MainWindow : : on_actionBookmark_triggered ( )
{
bool state = ui - > actionBookmark - > isChecked ( ) ;
ui - > actionBookmark - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabBookmark , state ) ;
}
void MainWindow : : on_actionProblem_triggered ( )
{
bool state = ui - > actionProblem - > isChecked ( ) ;
ui - > actionProblem - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabProblem , state ) ;
}
2021-11-22 16:16:58 +08:00
void MainWindow : : on_actionDelete_Line_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteLine ( ) ;
}
}
void MainWindow : : on_actionDuplicate_Line_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > duplicateLine ( ) ;
}
}
void MainWindow : : on_actionDelete_Word_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteWord ( ) ;
}
}
void MainWindow : : on_actionDelete_to_EOL_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteToEOL ( ) ;
}
}
void MainWindow : : on_actionDelete_to_BOL_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteToBOL ( ) ;
}
}
2021-11-27 15:43:47 +08:00
2022-12-17 13:34:11 +08:00
void MainWindow : : onOpenCaseValidationOptions ( )
2021-11-27 15:43:47 +08:00
{
changeOptions (
SettingsDialog : : tr ( " Problem Set " ) ,
SettingsDialog : : tr ( " Program Runner " )
) ;
}
2021-12-27 10:59:04 +08:00
void MainWindow : : on_actionInterrupt_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
mDebugger - > interrupt ( ) ;
}
}
2022-01-24 11:23:30 +08:00
void MainWindow : : on_actionDelete_Last_Word_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteToWordStart ( ) ;
}
}
void MainWindow : : on_actionDelete_to_Word_End_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > deleteToWordEnd ( ) ;
}
}
2022-01-27 18:34:18 +08:00
2022-02-01 16:17:28 +08:00
void MainWindow : : on_actionNew_Header_triggered ( )
{
if ( ! mProject )
return ;
NewHeaderDialog dialog ;
dialog . setPath ( mProject - > folder ( ) ) ;
2022-10-02 13:29:51 +08:00
QString newFileName ;
2022-10-02 17:23:27 +08:00
int i = 1 ;
2022-10-02 13:29:51 +08:00
do {
2022-10-25 21:49:35 +08:00
newFileName = QString ( " untitled%1 " ) . arg ( i ) ;
2022-10-02 13:29:51 +08:00
newFileName + = " .h " ;
i + + ;
} while ( QDir ( mProject - > directory ( ) ) . exists ( newFileName ) ) ;
dialog . setHeaderName ( newFileName ) ;
2022-02-01 16:17:28 +08:00
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
QDir dir ( dialog . path ( ) ) ;
if ( dialog . headerName ( ) . isEmpty ( )
| | ! dir . exists ( ) )
return ;
QString headerFilename = includeTrailingPathDelimiter ( dialog . path ( ) ) + dialog . headerName ( ) ;
if ( fileExists ( headerFilename ) ) {
QMessageBox : : critical ( this ,
tr ( " Header Exists " ) ,
tr ( " Header file \" %1 \" already exists! " ) . arg ( headerFilename ) ) ;
return ;
}
QString header_macro = QFileInfo ( dialog . headerName ( ) ) . baseName ( ) . toUpper ( ) + " _H " ;
QStringList header ;
QString indents ;
if ( pSettings - > editor ( ) . tabToSpaces ( ) ) {
indents = QString ( pSettings - > editor ( ) . tabWidth ( ) , ' ' ) ;
} else {
indents = " \t " ;
}
header . append ( QString ( " #ifndef %1 " ) . arg ( header_macro ) ) ;
header . append ( QString ( " #define %1 " ) . arg ( header_macro ) ) ;
header . append ( " " ) ;
header . append ( " #endif " ) ;
stringsToFile ( header , headerFilename ) ;
2022-10-02 17:23:27 +08:00
PProjectUnit newUnit = mProject - > addUnit ( headerFilename , mProject - > rootNode ( ) ) ;
mProject - > saveAll ( ) ;
2022-11-06 22:51:14 +08:00
2022-02-01 16:17:28 +08:00
parseFileList ( mProject - > cppParser ( ) ) ;
2022-10-02 17:23:27 +08:00
setProjectViewCurrentUnit ( newUnit ) ;
updateProjectView ( ) ;
2022-02-01 16:17:28 +08:00
2022-10-18 12:46:51 +08:00
openFile ( headerFilename ) ;
2022-02-01 16:17:28 +08:00
}
pSettings - > ui ( ) . setNewClassDialogWidth ( dialog . width ( ) ) ;
pSettings - > ui ( ) . setNewClassDialogHeight ( dialog . height ( ) ) ;
}
2022-01-27 18:46:37 +08:00
void MainWindow : : on_actionNew_Class_triggered ( )
2022-01-27 18:34:18 +08:00
{
if ( ! mProject )
return ;
2022-11-05 23:35:15 +08:00
NewClassDialog dialog ( mProject - > cppParser ( ) ) ;
2022-01-27 18:34:18 +08:00
dialog . setPath ( mProject - > folder ( ) ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
QDir dir ( dialog . path ( ) ) ;
if ( dialog . className ( ) . isEmpty ( )
| | dialog . sourceName ( ) . isEmpty ( )
| | dialog . headerName ( ) . isEmpty ( )
| | ! dir . exists ( ) )
return ;
2022-02-01 16:17:28 +08:00
QString headerFilename = includeTrailingPathDelimiter ( dialog . path ( ) ) + dialog . headerName ( ) ;
QString sourceFilename = includeTrailingPathDelimiter ( dialog . path ( ) ) + dialog . sourceName ( ) ;
if ( fileExists ( headerFilename ) ) {
QMessageBox : : critical ( this ,
tr ( " Header Exists " ) ,
tr ( " Header file \" %1 \" already exists! " ) . arg ( headerFilename ) ) ;
return ;
}
if ( fileExists ( sourceFilename ) ) {
QMessageBox : : critical ( this ,
tr ( " Source Exists " ) ,
tr ( " Source file \" %1 \" already exists! " ) . arg ( sourceFilename ) ) ;
return ;
}
2022-01-27 18:34:18 +08:00
QString header_macro = dialog . className ( ) . toUpper ( ) + " _H " ;
QStringList header ;
QString indents ;
if ( pSettings - > editor ( ) . tabToSpaces ( ) ) {
indents = QString ( pSettings - > editor ( ) . tabWidth ( ) , ' ' ) ;
} else {
indents = " \t " ;
}
header . append ( QString ( " #ifndef %1 " ) . arg ( header_macro ) ) ;
header . append ( QString ( " #define %1 " ) . arg ( header_macro ) ) ;
header . append ( " " ) ;
2022-11-05 23:35:15 +08:00
if ( dialog . baseClass ( ) ) {
header . append ( QString ( " #include \" %1 \" " ) . arg ( extractRelativePath ( mProject - > directory ( ) ,
dialog . baseClass ( ) - > fileName ) ) ) ;
header . append ( " " ) ;
header . append ( QString ( " class %1 : public %2 { " ) . arg ( dialog . className ( ) ,
dialog . baseClass ( ) - > fullName ) ) ;
} else
header . append ( QString ( " class %1 { " ) . arg ( dialog . className ( ) ) ) ;
2022-01-27 18:34:18 +08:00
header . append ( " public: " ) ;
header . append ( " " ) ;
header . append ( " private: " ) ;
header . append ( " " ) ;
header . append ( " }; " ) ;
header . append ( " " ) ;
header . append ( " #endif " ) ;
stringsToFile ( header , headerFilename ) ;
QStringList source ;
2022-01-27 20:31:44 +08:00
source . append ( QString ( " #include \" %1 \" " ) . arg ( dialog . headerName ( ) ) ) ;
2022-01-27 18:34:18 +08:00
source . append ( " " ) ;
source . append ( " " ) ;
stringsToFile ( source , sourceFilename ) ;
2022-10-02 17:23:27 +08:00
PProjectUnit newUnit = mProject - > addUnit ( headerFilename , mProject - > rootNode ( ) ) ;
2022-11-06 22:51:14 +08:00
2022-10-02 17:23:27 +08:00
setProjectViewCurrentUnit ( newUnit ) ;
newUnit = mProject - > addUnit ( sourceFilename , mProject - > rootNode ( ) ) ;
setProjectViewCurrentUnit ( newUnit ) ;
mProject - > saveAll ( ) ;
2022-01-27 18:34:18 +08:00
parseFileList ( mProject - > cppParser ( ) ) ;
2022-10-02 17:23:27 +08:00
updateProjectView ( ) ;
2022-02-01 16:17:28 +08:00
2022-10-18 12:46:51 +08:00
openFile ( headerFilename ) ;
openFile ( sourceFilename , false ) ;
2022-01-27 18:34:18 +08:00
}
2022-02-01 16:17:28 +08:00
pSettings - > ui ( ) . setNewHeaderDialogWidth ( dialog . width ( ) ) ;
pSettings - > ui ( ) . setNewHeaderDialogHeight ( dialog . height ( ) ) ;
2022-01-27 18:34:18 +08:00
}
2023-08-08 14:41:23 +08:00
# ifdef ENABLE_VCS
2022-02-15 00:01:50 +08:00
void MainWindow : : on_actionGit_Create_Repository_triggered ( )
{
if ( ui - > treeFiles - > isVisible ( ) ) {
GitManager vcsManager ;
vcsManager . createRepository ( pSettings - > environment ( ) . currentFolder ( ) ) ;
2022-02-15 21:39:17 +08:00
//update files view;
2022-02-15 00:01:50 +08:00
int pos = ui - > cbFilesPath - > findText ( pSettings - > environment ( ) . currentFolder ( ) ) ;
if ( pos > = 0 ) {
ui - > cbFilesPath - > setItemIcon ( pos , pIconsManager - > getIcon ( IconsManager : : FILESYSTEM_GIT ) ) ;
}
2022-02-16 20:00:03 +08:00
mFileSystemModelIconProvider . setRootFolder ( pSettings - > environment ( ) . currentFolder ( ) ) ;
2022-02-15 21:39:17 +08:00
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
//update project view
if ( mProject & & mProject - > folder ( ) = = mFileSystemModel . rootPath ( ) ) {
2022-10-02 13:29:51 +08:00
mProject - > addUnit ( includeTrailingPathDelimiter ( mProject - > folder ( ) ) + " .gitignore " , mProject - > rootNode ( ) ) ;
2022-02-15 21:39:17 +08:00
} else if ( mProject & & mFileSystemModel . index ( mProject - > folder ( ) ) . isValid ( ) ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-15 21:39:17 +08:00
}
2022-02-15 17:22:44 +08:00
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
2022-02-15 00:01:50 +08:00
GitManager vcsManager ;
vcsManager . createRepository ( mProject - > folder ( ) ) ;
2022-02-25 11:07:30 +08:00
QString output ;
vcsManager . add ( mProject - > folder ( ) , extractFileName ( mProject - > filename ( ) ) , output ) ;
vcsManager . add ( mProject - > folder ( ) , extractFileName ( mProject - > options ( ) . icon ) , output ) ;
2022-10-01 08:54:44 +08:00
foreach ( PProjectUnit pUnit , mProject - > unitList ( ) ) {
2022-02-25 11:07:30 +08:00
vcsManager . add ( mProject - > folder ( ) , extractRelativePath ( mProject - > folder ( ) , pUnit - > fileName ( ) ) , output ) ;
2022-02-16 13:02:56 +08:00
}
2022-02-15 21:39:17 +08:00
//update project view
2022-10-21 12:43:02 +08:00
QString ignoreFile = includeTrailingPathDelimiter ( mProject - > folder ( ) ) + " .gitignore " ;
mProject - > addUnit ( ignoreFile , mProject - > rootNode ( ) ) ;
createFile ( ignoreFile ) ;
2022-02-15 21:39:17 +08:00
mProject - > saveAll ( ) ;
if ( mProject - > folder ( ) = = mFileSystemModel . rootPath ( )
| | mFileSystemModel . rootPath ( ) . startsWith ( includeTrailingPathDelimiter ( mProject - > folder ( ) ) , PATH_SENSITIVITY ) ) {
//update files view;
int pos = ui - > cbFilesPath - > findText ( pSettings - > environment ( ) . currentFolder ( ) ) ;
if ( pos > = 0 ) {
ui - > cbFilesPath - > setItemIcon ( pos , pIconsManager - > getIcon ( IconsManager : : FILESYSTEM_GIT ) ) ;
}
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
}
2022-02-15 00:01:50 +08:00
}
}
void MainWindow : : on_actionGit_Add_Files_triggered ( )
{
if ( ui - > treeFiles - > isVisible ( ) ) {
GitManager vcsManager ;
QModelIndexList indices = ui - > treeFiles - > selectionModel ( ) - > selectedRows ( ) ;
2022-02-25 11:07:30 +08:00
QString output ;
2022-02-15 00:01:50 +08:00
foreach ( const QModelIndex index , indices ) {
QFileInfo info = mFileSystemModel . fileInfo ( index ) ;
2022-02-25 11:07:30 +08:00
vcsManager . add ( info . absolutePath ( ) , info . fileName ( ) , output ) ;
2022-02-15 00:01:50 +08:00
}
//update icons in files view
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
2022-02-15 17:22:44 +08:00
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
2022-02-15 00:01:50 +08:00
GitManager vcsManager ;
QModelIndexList indices = ui - > projectView - > selectionModel ( ) - > selectedRows ( ) ;
foreach ( const QModelIndex index , indices ) {
QModelIndex realIndex = mProjectProxyModel - > mapToSource ( index ) ;
ProjectModelNode * node = static_cast < ProjectModelNode * > ( realIndex . internalPointer ( ) ) ;
PProjectModelNode folderNode = mProject - > pointerToNode ( node ) ;
if ( ! folderNode )
continue ;
2022-10-08 23:30:30 +08:00
if ( folderNode - > isUnit ) {
PProjectUnit unit = folderNode - > pUnit . lock ( ) ;
2022-02-15 00:01:50 +08:00
QFileInfo info ( unit - > fileName ( ) ) ;
2022-02-25 11:07:30 +08:00
QString output ;
vcsManager . add ( info . absolutePath ( ) , info . fileName ( ) , output ) ;
2022-02-15 00:01:50 +08:00
}
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcon ( index ) ;
2022-02-15 00:01:50 +08:00
}
2022-02-15 17:22:44 +08:00
}
2022-10-24 17:23:37 +08:00
2022-02-15 17:22:44 +08:00
//update icons in files view too
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
}
void MainWindow : : on_actionGit_Commit_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
2022-02-21 11:37:29 +08:00
GitManager vcsManager ;
QStringList conflicts = vcsManager . listConflicts ( folder ) ;
if ( ! conflicts . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . setMessage (
tr ( " Can't commit! " ) + " <br /> "
+ tr ( " The following files are in conflicting: " ) + " <br /> "
+ linesToText ( conflicts ) ) ;
infoBox . exec ( ) ;
return ;
}
2022-02-21 11:39:24 +08:00
QString message = QInputDialog : : getText ( this , tr ( " Commit Message " ) , tr ( " Commit Message: " ) ) ;
2022-02-15 21:39:17 +08:00
if ( message . isEmpty ( ) ) {
QMessageBox : : critical ( this ,
tr ( " Commit Failed " ) ,
tr ( " Commit message shouldn't be empty! " )
) ;
return ;
}
2022-02-25 11:07:30 +08:00
QString output ;
QString userName = vcsManager . getUserName ( folder ) ;
QString userEmail = vcsManager . getUserEmail ( folder ) ;
if ( userName . isEmpty ( ) | | userEmail . isEmpty ( ) ) {
GitUserConfigDialog dialog ( folder ) ;
if ( dialog . exec ( ) ! = QDialog : : Accepted ) {
QMessageBox : : critical ( this ,
tr ( " Can't Commit " ) ,
tr ( " Git needs user info to commit. " ) ) ;
return ;
}
}
if ( vcsManager . commit ( folder , message , true , output ) ) {
//update project view
if ( mProject ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-25 11:07:30 +08:00
}
//update files view
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
}
if ( ! output . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
2022-02-15 21:39:17 +08:00
}
}
void MainWindow : : on_actionGit_Restore_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
2022-02-15 17:22:44 +08:00
return ;
2022-02-15 21:39:17 +08:00
GitManager vcsManager ;
2022-02-25 11:07:30 +08:00
QString output ;
if ( vcsManager . restore ( folder , " " , output ) ) {
2022-02-15 17:22:44 +08:00
2022-02-25 11:07:30 +08:00
//update project view
if ( mProject ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-25 11:07:30 +08:00
}
//update files view
mFileSystemModelIconProvider . update ( ) ;
mFileSystemModel . setIconProvider ( & mFileSystemModelIconProvider ) ;
}
if ( ! output . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
2022-02-15 17:22:44 +08:00
}
2022-02-15 00:01:50 +08:00
}
2022-02-16 16:27:09 +08:00
2022-02-19 20:38:08 +08:00
void MainWindow : : on_actionGit_Branch_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitBranchDialog dialog ( folder ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
//update project view
if ( mProject ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-19 20:38:08 +08:00
}
//update files view
setFilesViewRoot ( pSettings - > environment ( ) . currentFolder ( ) ) ;
}
}
2022-02-20 21:47:57 +08:00
void MainWindow : : on_actionGit_Merge_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitMergeDialog dialog ( folder ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
//update project view
if ( mProject ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-20 21:47:57 +08:00
}
//update files view
setFilesViewRoot ( pSettings - > environment ( ) . currentFolder ( ) ) ;
}
}
2022-02-21 23:35:28 +08:00
void MainWindow : : on_actionGit_Log_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitLogDialog dialog ( folder ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
//update project view
if ( mProject ) {
2022-10-24 17:23:37 +08:00
mProject - > model ( ) - > refreshIcons ( ) ;
2022-02-21 23:35:28 +08:00
}
//update files view
setFilesViewRoot ( pSettings - > environment ( ) . currentFolder ( ) ) ;
}
return ;
}
2022-02-24 11:07:37 +08:00
void MainWindow : : on_actionGit_Remotes_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitRemoteDialog dialog ( folder ) ;
dialog . exec ( ) ;
}
2022-02-24 23:31:48 +08:00
void MainWindow : : on_actionGit_Fetch_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitManager manager ;
QString output ;
if ( ! manager . fetch ( folder , output ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
}
}
void MainWindow : : on_actionGit_Pull_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitManager manager ;
QString branch ;
if ( ! manager . hasRepository ( folder , branch ) )
return ;
QString remote = manager . getBranchRemote ( folder , branch ) ;
QString output ;
if ( remote . isEmpty ( ) ) {
GitRemoteDialog dialog ( folder ) ;
QString remote = dialog . chooseRemote ( ) ;
if ( remote . trimmed ( ) . isEmpty ( ) )
return ;
if ( ! manager . setBranchUpstream ( folder , branch , remote , output ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
return ;
}
}
manager . pull ( folder , output ) ;
if ( ! output . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
}
}
void MainWindow : : on_actionGit_Push_triggered ( )
{
QString folder ;
if ( ui - > treeFiles - > isVisible ( ) ) {
folder = pSettings - > environment ( ) . currentFolder ( ) ;
} else if ( ui - > projectView - > isVisible ( ) & & mProject ) {
folder = mProject - > folder ( ) ;
}
if ( folder . isEmpty ( ) )
return ;
GitManager manager ;
QString branch ;
if ( ! manager . hasRepository ( folder , branch ) )
return ;
QString remote = manager . getBranchRemote ( folder , branch ) ;
QString output ;
if ( remote . isEmpty ( ) ) {
GitRemoteDialog dialog ( folder ) ;
QString remote = dialog . chooseRemote ( ) ;
if ( remote . trimmed ( ) . isEmpty ( ) )
return ;
manager . push ( folder , remote , branch , output ) ;
if ( ! output . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
}
} else {
if ( ! output . isEmpty ( ) ) {
InfoMessageBox infoBox ;
infoBox . showMessage ( output ) ;
}
}
}
2023-08-08 14:41:23 +08:00
# endif
void MainWindow : : on_actionWebsite_triggered ( )
{
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
2023-10-01 15:47:58 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://royqh1979.gitee.io/redpandacpp " ) ) ;
2023-08-08 14:41:23 +08:00
} else {
QDesktopServices : : openUrl ( QUrl ( " https://sourceforge.net/projects/redpanda-cpp/ " ) ) ;
}
}
2022-02-28 22:40:09 +08:00
void MainWindow : : on_actionFilesView_Hide_Non_Support_Files_toggled ( bool /* arg1 */ )
{
mFileSystemModel . setNameFilterDisables ( ! ui - > actionFilesView_Hide_Non_Support_Files - > isChecked ( ) ) ;
2022-07-07 20:08:58 +08:00
if ( ! mFileSystemModel . nameFilterDisables ( ) ) {
mFileSystemModel . setNameFilters ( pSystemConsts - > defaultFileNameFilters ( ) ) ;
} else {
mFileSystemModel . setNameFilters ( QStringList ( ) ) ;
}
2022-02-28 22:40:09 +08:00
if ( pSettings - > environment ( ) . hideNonSupportFilesInFileView ( )
! = ui - > actionFilesView_Hide_Non_Support_Files - > isChecked ( ) ) {
pSettings - > environment ( ) . setHideNonSupportFilesInFileView ( ui - > actionFilesView_Hide_Non_Support_Files - > isChecked ( ) ) ;
pSettings - > environment ( ) . save ( ) ;
}
}
2022-03-12 18:03:52 +08:00
void MainWindow : : on_actionToggle_Block_Comment_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2022-03-12 18:03:52 +08:00
editor - > toggleBlockComment ( ) ;
}
}
2022-03-13 18:45:48 +08:00
void MainWindow : : on_actionMatch_Bracket_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2022-03-13 18:45:48 +08:00
editor - > matchBracket ( ) ;
}
}
2022-03-29 18:06:24 +08:00
void MainWindow : : on_btnProblemCaseInputFileName_clicked ( )
{
QString fileName = QFileDialog : : getOpenFileName (
this ,
tr ( " Choose Input Data File " ) ,
QString ( ) ,
tr ( " All files (*.*) " ) ) ;
if ( ! fileName . isEmpty ( ) ) {
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( ! problemCase )
return ;
if ( problemCase - > inputFileName = = fileName )
return ;
problemCase - > inputFileName = fileName ;
2022-03-30 19:28:46 +08:00
if ( problemCase - > expectedOutputFileName . isEmpty ( )
& & problemCase - > expected . isEmpty ( )
& & QFileInfo ( fileName ) . suffix ( ) = = " in " ) {
2022-04-26 22:08:46 +08:00
QString expectedFileName ;
expectedFileName = fileName . mid ( 0 , fileName . length ( ) - 2 ) + " ans " ;
if ( fileExists ( expectedFileName ) ) {
2022-03-30 19:28:46 +08:00
problemCase - > expectedOutputFileName = expectedFileName ;
2022-04-26 22:08:46 +08:00
} else {
expectedFileName = fileName . mid ( 0 , fileName . length ( ) - 2 ) + " out " ;
if ( fileExists ( expectedFileName ) )
problemCase - > expectedOutputFileName = expectedFileName ;
}
2022-03-30 19:28:46 +08:00
}
2022-03-29 18:06:24 +08:00
fillProblemCaseInputAndExpected ( problemCase ) ;
}
}
void MainWindow : : on_btnProblemCaseClearExpectedOutputFileName_clicked ( )
{
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( ! problemCase )
return ;
problemCase - > expectedOutputFileName = " " ;
fillProblemCaseInputAndExpected ( problemCase ) ;
}
void MainWindow : : on_btnProblemCaseClearInputFileName_clicked ( )
{
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( ! problemCase )
return ;
problemCase - > inputFileName = " " ;
fillProblemCaseInputAndExpected ( problemCase ) ;
}
void MainWindow : : on_btnProblemCaseExpectedOutputFileName_clicked ( )
{
QString fileName = QFileDialog : : getOpenFileName (
this ,
tr ( " Choose Expected Output Data File " ) ,
QString ( ) ,
tr ( " All files (*.*) " ) ) ;
if ( ! fileName . isEmpty ( ) ) {
QModelIndex idx = ui - > tblProblemCases - > currentIndex ( ) ;
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( ! problemCase )
return ;
if ( problemCase - > expectedOutputFileName = = fileName )
return ;
problemCase - > expectedOutputFileName = fileName ;
fillProblemCaseInputAndExpected ( problemCase ) ;
}
}
void MainWindow : : on_txtProblemCaseOutput_cursorPositionChanged ( )
{
QTextCursor cursor = ui - > txtProblemCaseOutput - > textCursor ( ) ;
int val = ui - > txtProblemCaseOutput - > verticalScrollBar ( ) - > value ( ) ;
2022-03-29 21:41:02 +08:00
int line = cursor . block ( ) . firstLineNumber ( ) ;
2022-06-15 14:13:11 +08:00
//ui->lblProblemCaseOutput->setText(tr("Line %1").arg(cursor.block().firstLineNumber()+1));
2022-03-29 21:41:02 +08:00
QTextBlock block = ui - > txtProblemCaseExpected - > document ( ) - > findBlockByLineNumber ( line ) ;
if ( ! block . isValid ( ) )
return ;
cursor = QTextCursor ( block ) ;
2022-03-29 18:06:24 +08:00
ui - > txtProblemCaseExpected - > setTextCursor ( cursor ) ;
ui - > txtProblemCaseExpected - > verticalScrollBar ( ) - > setValue ( val ) ;
}
2022-03-29 21:41:02 +08:00
void MainWindow : : on_txtProblemCaseExpected_cursorPositionChanged ( )
{
QTextCursor cursor = ui - > txtProblemCaseExpected - > textCursor ( ) ;
2022-06-15 14:13:11 +08:00
//ui->lblProblemCaseExpected->setText(tr("Line %1").arg(cursor.block().firstLineNumber()+1));
2022-03-29 21:41:02 +08:00
}
void MainWindow : : on_txtProblemCaseInput_cursorPositionChanged ( )
{
QTextCursor cursor = ui - > txtProblemCaseInput - > textCursor ( ) ;
2022-06-15 14:13:11 +08:00
//ui->lblProblemCaseInput->setText(tr("Line %1").arg(cursor.block().firstLineNumber()+1));
2022-03-29 21:41:02 +08:00
}
2022-04-01 23:10:38 +08:00
void MainWindow : : on_actionMove_Selection_Up_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2022-04-01 23:10:38 +08:00
editor - > moveSelUp ( ) ;
}
}
void MainWindow : : on_actionMove_Selection_Down_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-26 09:33:45 +08:00
if ( editor ) {
2022-04-01 23:10:38 +08:00
editor - > moveSelDown ( ) ;
}
}
2022-05-06 15:23:41 +08:00
void MainWindow : : on_actionConvert_to_UTF_8_BOM_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_BOM ) ,
QMessageBox : : Yes , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
editor - > convertToEncoding ( ENCODING_UTF8_BOM ) ;
}
void MainWindow : : on_actionEncode_in_UTF_8_BOM_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor = = nullptr )
return ;
try {
editor - > setEncodingOption ( ENCODING_UTF8_BOM ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
}
2022-05-06 15:48:17 +08:00
void MainWindow : : on_actionCompiler_Options_triggered ( )
{
2023-04-03 09:39:45 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
if ( ! mProject | | ( editor & & ! editor - > inProject ( ) ) ) {
changeOptions (
SettingsDialog : : tr ( " Compiler Set " ) ,
SettingsDialog : : tr ( " Compiler " )
) ;
} else {
changeProjectOptions (
SettingsDialog : : tr ( " Compiler Set " ) ,
SettingsDialog : : tr ( " Project " )
) ;
}
2022-05-06 15:48:17 +08:00
}
2022-05-22 14:31:13 +08:00
void MainWindow : : on_dockExplorer_dockLocationChanged ( const Qt : : DockWidgetArea & area )
2022-05-20 18:43:01 +08:00
{
2022-05-22 14:31:13 +08:00
setDockExplorerToArea ( area ) ;
2022-05-20 18:43:01 +08:00
}
void MainWindow : : on_dockMessages_dockLocationChanged ( const Qt : : DockWidgetArea & area )
{
2022-05-22 14:31:13 +08:00
setDockMessagesToArea ( area ) ;
2022-05-20 18:43:01 +08:00
}
2022-05-25 10:04:36 +08:00
void MainWindow : : on_actionToggle_Explorer_Panel_triggered ( )
{
stretchExplorerPanel ( ui - > tabExplorer - > isShrinked ( ) ) ;
}
void MainWindow : : on_actionToggle_Messages_Panel_triggered ( )
{
stretchMessagesPanel ( ui - > tabMessages - > isShrinked ( ) ) ;
}
2022-07-01 17:15:20 +08:00
void MainWindow : : on_actionRaylib_Manual_triggered ( )
{
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
QDesktopServices : : openUrl ( QUrl ( " https://zhuanlan.zhihu.com/p/458335134 " ) ) ;
} else {
QDesktopServices : : openUrl ( QUrl ( " https://www.raylib.com/ " ) ) ;
}
}
2022-07-21 15:28:07 +08:00
void MainWindow : : on_actionSelect_Word_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > selectWord ( ) ;
}
}
void MainWindow : : on_actionGo_to_Line_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( ! e )
return ;
bool ok ;
int lineNo = QInputDialog : : getInt ( e , tr ( " Go to Line " ) , tr ( " Line " ) ,
e - > caretY ( ) , 1 , e - > document ( ) - > count ( ) ,
1 , & ok ) ;
if ( ok & & lineNo ! = e - > caretY ( ) ) {
e - > setCaretPosition ( lineNo , 1 ) ;
e - > setFocus ( ) ;
}
}
2022-08-07 21:41:57 +08:00
void MainWindow : : on_actionNew_Template_triggered ( )
{
if ( ! mProject )
return ;
NewTemplateDialog dialog ( this ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
QDir folder (
includeTrailingPathDelimiter (
pSettings - > dirs ( ) . config ( Settings : : Dirs : : DataType : : Template ) )
+ dialog . getName ( ) ) ;
if ( folder . exists ( ) ) {
if ( QMessageBox : : warning ( this ,
tr ( " Template Exists " ) ,
tr ( " Template %1 already exists. Do you want to overwrite? " ) . arg ( dialog . getName ( ) ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : No
) ! = QMessageBox : : Yes )
return ;
}
mProject - > saveAsTemplate (
folder . absolutePath ( ) ,
dialog . getName ( ) ,
dialog . getDescription ( ) ,
dialog . getCategory ( )
) ;
}
}
2022-10-24 22:53:46 +08:00
bool MainWindow : : closingProject ( ) const
{
return mClosingProject ;
}
2022-10-17 23:23:05 +08:00
const std : : shared_ptr < VisitHistoryManager > & MainWindow : : visitHistoryManager ( ) const
{
return mVisitHistoryManager ;
}
2022-08-24 17:05:16 +08:00
bool MainWindow : : isQuitting ( ) const
{
return mQuitting ;
}
bool MainWindow : : isClosingAll ( ) const
{
return mClosingAll ;
}
2022-10-27 15:18:57 +08:00
void MainWindow : : on_actionGoto_block_start_triggered ( )
{
2022-11-05 19:39:33 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-27 15:18:57 +08:00
if ( editor )
editor - > gotoBlockStart ( ) ;
}
void MainWindow : : on_actionGoto_block_end_triggered ( )
{
2022-11-05 19:39:33 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
2022-10-27 15:18:57 +08:00
if ( editor )
editor - > gotoBlockEnd ( ) ;
}
2022-11-05 19:39:33 +08:00
void MainWindow : : on_actionSwitchHeaderSource_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
QString file = switchHeaderSourceTarget ( editor ) ;
if ( ! file . isEmpty ( ) ) {
openFile ( file ) ;
}
}
2022-11-11 21:20:57 +08:00
SearchDialog * MainWindow : : searchDialog ( ) const
{
return mSearchDialog ;
}
2022-12-01 22:10:44 +08:00
void MainWindow : : on_actionGenerate_Assembly_triggered ( )
{
doGenerateAssembly ( ) ;
}
2022-12-11 19:47:43 +08:00
2022-12-17 11:37:33 +08:00
void MainWindow : : onImportFPSProblemSet ( )
2022-12-11 19:47:43 +08:00
{
QString fileName = QFileDialog : : getOpenFileName (
this ,
tr ( " Import FPS Problem Set " ) ,
QString ( ) ,
2022-12-11 21:46:51 +08:00
tr ( " FPS Problem Set Files (*.fps;*.xml) " ) ) ;
2022-12-11 19:47:43 +08:00
if ( ! fileName . isEmpty ( ) ) {
try {
QList < POJProblem > problems = importFreeProblemSet ( fileName ) ;
mOJProblemSetModel . addProblems ( problems ) ;
2022-12-13 08:49:20 +08:00
ui - > lblProblemSet - > setText ( mOJProblemSetModel . name ( ) ) ;
ui - > lstProblemSet - > setCurrentIndex ( mOJProblemSetModel . index ( 0 , 0 ) ) ;
2022-12-11 19:47:43 +08:00
} catch ( FileError & error ) {
QMessageBox : : critical ( this , tr ( " Load Error " ) ,
error . reason ( ) ) ;
}
}
}
2022-12-13 08:49:20 +08:00
2022-12-16 11:10:46 +08:00
void MainWindow : : on_actionTrim_trailing_spaces_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > trimTrailingSpaces ( ) ;
}
}
2022-12-16 15:54:02 +08:00
2022-12-17 11:37:33 +08:00
void MainWindow : : onExportFPSProblemSet ( )
2022-12-16 15:54:02 +08:00
{
QString fileName = QFileDialog : : getSaveFileName (
this ,
tr ( " Export FPS Problem Set " ) ,
QString ( ) ,
tr ( " FPS Problem Set Files (*.fps) " ) ) ;
if ( ! fileName . isEmpty ( ) ) {
try {
exportFreeProblemSet ( mOJProblemSetModel . problems ( ) , fileName ) ;
} catch ( FileError & error ) {
QMessageBox : : critical ( this , tr ( " Export Error " ) ,
error . reason ( ) ) ;
}
}
}
2023-01-02 16:50:30 +08:00
void MainWindow : : on_actionToggle_Readonly_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & ! editor - > modified ( ) ) {
editor - > setReadOnly ( ! editor - > readOnly ( ) ) ;
editor - > updateCaption ( ) ;
updateEditorActions ( editor ) ;
2023-01-04 11:01:34 +08:00
updateForStatusbarModeInfo ( editor ) ;
2023-01-02 16:50:30 +08:00
}
}
2023-01-16 15:42:03 +08:00
void MainWindow : : on_actionSubmit_Issues_triggered ( )
{
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
QDesktopServices : : openUrl ( QUrl ( " https://gitee.com/royqh1979/RedPanda-CPP/issues " ) ) ;
} else {
QDesktopServices : : openUrl ( QUrl ( " https://github.com/royqh1979/RedPanda-CPP/issues " ) ) ;
}
}
void MainWindow : : on_actionDocument_triggered ( )
{
2023-10-01 15:47:58 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://royqh1979.gitee.io/redpandacpp/docsy/docs/usage " ) ) ;
2023-01-16 15:42:03 +08:00
}
2023-02-12 22:33:34 +08:00
void MainWindow : : on_actionNew_GAS_File_triggered ( )
{
if ( mProject ) {
if ( QMessageBox : : question ( this ,
tr ( " New Project File? " ) ,
tr ( " Do you want to add the new file to the project? " ) ,
2023-10-23 19:24:23 +08:00
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
2023-02-12 22:33:34 +08:00
newProjectUnitFile ( " s " ) ;
return ;
}
}
newEditor ( " s " ) ;
}
2023-02-15 16:24:24 +08:00
void MainWindow : : on_actionGNU_Assembler_Manual_triggered ( )
{
2023-03-05 08:56:11 +08:00
QFileInfo fileInfo { includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString { " Using GNU Assembler.pdf " } } ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2023-02-15 16:24:24 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://sourceware.org/binutils/docs/as/index.html " ) ) ;
}
2023-02-26 17:50:03 +08:00
2023-03-05 08:56:11 +08:00
# ifdef ARCH_X86_64
2023-02-26 17:50:03 +08:00
void MainWindow : : on_actionx86_Assembly_Language_Reference_Manual_triggered ( )
{
2023-03-05 08:56:11 +08:00
QFileInfo fileInfo { includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString { " x86 Assembly Language Reference Manual.pdf " } } ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2023-03-04 12:47:49 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://docs.oracle.com/cd/E53394_01/html/E54851/index.html " ) ) ;
2023-02-26 17:50:03 +08:00
}
2023-03-05 08:56:11 +08:00
# endif
2023-02-26 17:50:03 +08:00
2023-03-05 08:56:11 +08:00
# ifdef ARCH_X86
2023-02-26 17:50:03 +08:00
void MainWindow : : on_actionIA_32_Assembly_Language_Reference_Manual_triggered ( )
{
2023-03-05 08:56:11 +08:00
QFileInfo fileInfo { includeTrailingPathDelimiter ( pSettings - > dirs ( ) . appDir ( ) ) +
QString { " IA-32 Assembly Language Reference Manual.pdf " } } ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
return ;
}
2023-02-26 17:50:03 +08:00
QDesktopServices : : openUrl ( QUrl ( " https://docs.oracle.com/cd/E19455-01/806-3773/index.html " ) ) ;
}
2023-03-05 08:56:11 +08:00
# endif
2023-03-03 17:20:33 +08:00
void MainWindow : : on_actionAdd_Watchpoint_triggered ( )
{
QString s = " " ;
bool isOk ;
s = QInputDialog : : getText ( this ,
tr ( " Watchpoint variable name " ) ,
tr ( " Stop execution when the following variable is modified (it must be visible from the currect scope): " ) ,
QLineEdit : : Normal ,
s , & isOk ) ;
if ( ! isOk )
return ;
s = s . trimmed ( ) ;
mDebugger - > addWatchpoint ( s ) ;
}
2023-03-04 12:47:49 +08:00
void MainWindow : : on_actionNew_Text_File_triggered ( )
{
if ( mProject ) {
if ( QMessageBox : : question ( this ,
tr ( " New Project File? " ) ,
tr ( " Do you want to add the new file to the project? " ) ,
2023-10-23 19:24:23 +08:00
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
2023-03-04 12:47:49 +08:00
newProjectUnitFile ( " txt " ) ;
return ;
}
}
newEditor ( " txt " ) ;
}
2023-05-31 08:52:59 +08:00
void MainWindow : : on_actionPage_Up_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : PageUp ) ;
}
}
void MainWindow : : on_actionPage_Down_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : PageDown ) ;
}
}
void MainWindow : : on_actionGoto_Line_Start_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : LineStart ) ;
}
}
void MainWindow : : on_actionGoto_Line_End_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : LineEnd ) ;
}
}
void MainWindow : : on_actionGoto_File_Start_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : EditorStart ) ;
}
}
void MainWindow : : on_actionGoto_File_End_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : EditorEnd ) ;
}
}
void MainWindow : : on_actionPage_Up_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelPageUp ) ;
}
}
void MainWindow : : on_actionPage_Down_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelPageDown ) ;
}
}
void MainWindow : : on_actionGoto_Page_Start_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : PageTop ) ;
}
}
void MainWindow : : on_actionGoto_Page_End_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : PageBottom ) ;
}
}
void MainWindow : : on_actionGoto_Page_Start_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelPageTop ) ;
}
}
void MainWindow : : on_actionGoto_Page_End_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelPageBottom ) ;
}
}
void MainWindow : : on_actionGoto_Line_Start_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelLineStart ) ;
}
}
void MainWindow : : on_actionGoto_Line_End_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelLineEnd ) ;
}
}
void MainWindow : : on_actionGoto_File_Start_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelEditorStart ) ;
}
}
void MainWindow : : on_actionGoto_File_End_and_Select_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor & & editor - > hasFocus ( ) ) {
editor - > processCommand ( QSynedit : : EditCommand : : SelEditorEnd ) ;
}
}
2023-06-13 17:16:09 +08:00
void MainWindow : : on_actionClose_Others_triggered ( )
{
mClosing = true ;
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
mEditorList - > closeOthers ( e ) ;
}
mClosing = false ;
}
2023-07-02 11:09:34 +08:00
void MainWindow : : on_actionOI_Wiki_triggered ( )
{
QDesktopServices : : openUrl ( QUrl ( " https://oi-wiki.org/ " ) ) ;
}
void MainWindow : : on_actionTurtle_Graphics_Manual_triggered ( )
{
QDesktopServices : : openUrl ( QUrl ( " https://zhuanlan.zhihu.com/p/538666844 " ) ) ;
}
2023-08-11 13:49:09 +08:00
bool MainWindow : : openingProject ( ) const
{
return mOpeningProject ;
}
bool MainWindow : : openingFiles ( ) const
{
return mOpeningFiles ;
}
2023-08-19 18:01:16 +08:00
void MainWindow : : on_cbProblemCaseValidateType_currentIndexChanged ( int index )
{
pSettings - > executor ( ) . setProblemCaseValidateType ( ( ProblemCaseValidateType ) index ) ;
pSettings - > executor ( ) . save ( ) ;
}