2021-09-03 16:39:20 +08:00
# include <windows.h>
2021-04-06 23:10:57 +08:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
2021-04-07 21:13:15 +08:00
# include "editorlist.h"
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"
2021-06-24 20:43:09 +08:00
# include "qsynedit/Constants.h"
2021-07-23 13:22:05 +08:00
# include "debugger.h"
2021-08-01 23:24:37 +08:00
# include "widgets/cpudialog.h"
2021-09-04 00:13:42 +08:00
# include "widgets/filepropertiesdialog.h"
2021-09-11 11:42:20 +08:00
# include "project.h"
2021-09-16 23:51:05 +08:00
# include "projecttemplate.h"
# include "widgets/newprojectdialog.h"
2021-09-28 22:26:12 +08:00
# include "platform.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-11-01 20:44:08 +08:00
# include "problems/problemcasevalidator.h"
2021-11-04 09:07:06 +08:00
# include "widgets/ojproblempropertywidget.h"
2021-11-14 17:43:25 +08:00
# include "version.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>
2021-11-02 09:29:35 +08:00
# include <QTcpSocket>
2021-11-02 19:26:11 +08:00
# include <QTextBlock>
2021-06-20 09:27:37 +08:00
# include <QTranslator>
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
2021-08-03 23:55:57 +08:00
# include <widgets/searchdialog.h>
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 ;
}
return - 1 ;
}
2021-04-08 10:29:21 +08:00
MainWindow * pMainWindow ;
2021-04-06 23:10:57 +08:00
MainWindow : : MainWindow ( QWidget * parent )
2021-06-23 22:38:02 +08:00
: QMainWindow ( parent ) ,
ui ( new Ui : : MainWindow ) ,
2021-08-29 10:14:07 +08:00
mSearchDialog ( nullptr ) ,
mQuitting ( false ) ,
2021-10-08 20:01:29 +08:00
mCheckSyntaxInBack ( false ) ,
2021-09-02 19:36:16 +08:00
mOpenClosingBottomPanel ( false ) ,
mOpenClosingLeftPanel ( false ) ,
2021-10-08 20:01:29 +08:00
mShouldRemoveAllSettings ( false ) ,
2021-09-02 20:12:16 +08:00
mClosing ( false ) ,
2021-11-08 21:19:48 +08:00
mOpenningFiles ( false ) ,
2021-09-02 20:12:16 +08:00
mSystemTurnedOff ( false )
2021-04-06 23:10:57 +08:00
{
ui - > setupUi ( this ) ;
2021-04-08 10:29:21 +08:00
// status bar
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 ( ) ;
2021-04-08 10:29:21 +08:00
mFileInfoStatus - > setStyleSheet ( " margin-left:10px; margin-right:10px " ) ;
mFileEncodingStatus - > setStyleSheet ( " margin-left:10px; margin-right:10px " ) ;
2021-06-12 22:36:23 +08:00
mFileModeStatus - > setStyleSheet ( " margin-left:10px; margin-right:10px " ) ;
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 ) ;
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 ) ;
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 ;
2021-04-07 21:13:15 +08:00
setupActions ( ) ;
2021-04-07 22:44:08 +08:00
ui - > EditorTabsRight - > setVisible ( false ) ;
2021-04-18 11:41:41 +08:00
mCompilerSet = new QComboBox ( ) ;
2021-06-24 20:43:09 +08:00
mCompilerSet - > setMinimumWidth ( 200 ) ;
2021-04-18 11:41:41 +08:00
ui - > toolbarCompilerSet - > addWidget ( mCompilerSet ) ;
connect ( mCompilerSet , QOverload < int > : : of ( & QComboBox : : currentIndexChanged ) ,
this , & MainWindow : : onCompilerSetChanged ) ;
2021-11-12 02:20:13 +08:00
//updateCompilerSet();
2021-04-20 22:24:33 +08:00
mCompilerManager = new CompilerManager ( this ) ;
2021-07-23 13:22:05 +08:00
mDebugger = new Debugger ( this ) ;
2021-04-24 15:57:45 +08:00
2021-07-25 00:26:13 +08:00
ui - > tblBreakpoints - > setModel ( mDebugger - > breakpointModel ( ) ) ;
ui - > tblStackTrace - > setModel ( mDebugger - > backtraceModel ( ) ) ;
2021-08-01 01:06:43 +08:00
ui - > watchView - > setModel ( mDebugger - > watchModel ( ) ) ;
2021-07-25 00:26:13 +08:00
2021-10-22 07:42:51 +08:00
try {
mDebugger - > breakpointModel ( ) - > load ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_BREAKPOINTS_FILE ) ;
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
try {
mDebugger - > watchModel ( ) - > load ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
2021-10-21 19:33:11 +08:00
+ DEV_WATCH_FILE ) ;
2021-10-22 07:42:51 +08:00
} catch ( FileError & e ) {
QMessageBox : : warning ( nullptr ,
tr ( " Error " ) ,
e . reason ( ) ) ;
}
2021-10-21 19:33:11 +08:00
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
2021-09-16 23:51:05 +08:00
mMenuNew = new QMenu ( ) ;
mMenuNew - > setTitle ( tr ( " New " ) ) ;
mMenuNew - > addAction ( ui - > actionNew ) ;
mMenuNew - > addAction ( ui - > actionNew_Project ) ;
ui - > menuFile - > insertMenu ( ui - > actionOpen , mMenuNew ) ;
2021-09-28 22:26:12 +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 " ) ) ;
2021-10-03 09:57:19 +08:00
ui - > menuCode - > insertMenu ( ui - > actionReformat_Code , mMenuInsertCodeSnippet ) ;
ui - > menuCode - > insertSeparator ( ui - > actionReformat_Code ) ;
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-06-18 21:48:40 +08:00
applySettings ( ) ;
2021-09-02 16:35:28 +08:00
applyUISettings ( ) ;
2021-11-09 21:22:50 +08:00
updateProjectView ( ) ;
updateEditorActions ( ) ;
updateCaretActions ( ) ;
2021-06-24 16:05:19 +08:00
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 {
mBookmarkModel - > load ( 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 ( ) ) ;
}
2021-10-21 17:31:25 +08:00
ui - > tableBookmark - > setModel ( mBookmarkModel . get ( ) ) ;
2021-08-05 12:31:53 +08:00
mSearchResultTreeModel = std : : make_shared < SearchResultTreeModel > ( & mSearchResultModel ) ;
mSearchResultListModel = std : : make_shared < SearchResultListModel > ( & mSearchResultModel ) ;
mSearchViewDelegate = std : : make_shared < SearchResultTreeViewDelegate > ( mSearchResultTreeModel ) ;
2021-08-05 19:58:32 +08:00
ui - > cbSearchHistory - > setModel ( mSearchResultListModel . get ( ) ) ;
2021-08-05 12:31:53 +08:00
ui - > searchView - > setModel ( mSearchResultTreeModel . get ( ) ) ;
ui - > searchView - > setItemDelegate ( mSearchViewDelegate . get ( ) ) ;
2021-10-03 17:18:43 +08:00
ui - > tableTODO - > setModel ( & mTodoModel ) ;
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 ) ;
ui - > btnRemoveProblem - > setEnabled ( false ) ;
ui - > btnRemoveProblemCase - > 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 ) ) ;
ui - > lstProblemSet - > setModel ( & mOJProblemSetModel ) ;
ui - > lstProblemCases - > setModel ( & mOJProblemModel ) ;
connect ( ui - > lstProblemSet - > selectionModel ( ) ,
& QItemSelectionModel : : currentRowChanged ,
this , & MainWindow : : onProblemSetIndexChanged ) ;
connect ( ui - > lstProblemCases - > selectionModel ( ) ,
& 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
2021-10-22 15:02:54 +08:00
//files view
2021-10-22 07:42:51 +08:00
ui - > treeFiles - > setModel ( & mFileSystemModel ) ;
2021-10-22 15:02:54 +08:00
mFileSystemModel . setReadOnly ( true ) ;
setFilesViewRoot ( pSettings - > environment ( ) . currentFolder ( ) ) ;
for ( int i = 1 ; i < mFileSystemModel . columnCount ( ) ; i + + ) {
ui - > treeFiles - > hideColumn ( i ) ;
}
2021-08-23 17:27:17 +08:00
//class browser
ui - > classBrowser - > setModel ( & mClassBrowserModel ) ;
2021-08-29 00:48:23 +08:00
2021-08-31 14:40:41 +08:00
connect ( & mFileSystemWatcher , & QFileSystemWatcher : : fileChanged ,
this , & MainWindow : : onFileChanged ) ;
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 ) ;
2021-10-18 23:44:02 +08:00
ui - > actionEGE_Manual - > setVisible ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) ;
2021-10-03 09:57:19 +08:00
2021-11-09 21:22:50 +08:00
updateAppTitle ( ) ;
2021-08-31 11:13:12 +08:00
buildContextMenus ( ) ;
2021-09-25 23:12:36 +08:00
updateEditorColorSchemes ( ) ;
2021-09-27 20:17:24 +08:00
2021-10-06 23:19:18 +08:00
updateShortcuts ( ) ;
2021-10-08 00:06:41 +08:00
updateTools ( ) ;
2021-04-06 23:10:57 +08:00
}
MainWindow : : ~ MainWindow ( )
{
2021-09-26 19:40:52 +08:00
delete mEditorList ;
2021-04-06 23:10:57 +08:00
delete ui ;
}
2021-06-12 22:36:23 +08:00
void MainWindow : : updateForEncodingInfo ( ) {
2021-04-08 10:29:21 +08:00
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ! = NULL ) {
2021-09-28 22:26:12 +08:00
if ( editor - > encodingOption ( ) ! = editor - > fileEncoding ( ) ) {
mFileEncodingStatus - > setText (
QString ( " %1(%2) " )
. arg ( QString ( editor - > encodingOption ( ) )
, QString ( editor - > fileEncoding ( ) ) ) ) ;
} else {
mFileEncodingStatus - > setText (
QString ( " %1 " )
. arg ( QString ( editor - > encodingOption ( ) ) )
) ;
}
2021-06-12 22:36:23 +08:00
ui - > actionAuto_Detect - > setChecked ( editor - > encodingOption ( ) = = ENCODING_AUTO_DETECT ) ;
ui - > actionEncode_in_ANSI - > setChecked ( editor - > encodingOption ( ) = = ENCODING_SYSTEM_DEFAULT ) ;
ui - > actionEncode_in_UTF_8 - > setChecked ( editor - > encodingOption ( ) = = ENCODING_UTF8 ) ;
} else {
mFileEncodingStatus - > setText ( " " ) ;
ui - > actionAuto_Detect - > setChecked ( false ) ;
ui - > actionEncode_in_ANSI - > setChecked ( false ) ;
ui - > actionEncode_in_UTF_8 - > setChecked ( false ) ;
2021-04-08 10:29:21 +08:00
}
2021-04-11 13:55:31 +08:00
}
2021-06-12 22:36:23 +08:00
void MainWindow : : updateEditorSettings ( )
2021-04-11 13:55:31 +08:00
{
2021-06-12 22:36:23 +08:00
mEditorList - > applySettings ( ) ;
}
void MainWindow : : updateEditorActions ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e = = nullptr ) {
ui - > actionAuto_Detect - > setEnabled ( false ) ;
ui - > actionEncode_in_ANSI - > setEnabled ( false ) ;
ui - > actionEncode_in_UTF_8 - > setEnabled ( false ) ;
ui - > actionConvert_to_ANSI - > setEnabled ( false ) ;
ui - > actionConvert_to_UTF_8 - > setEnabled ( false ) ;
ui - > actionCopy - > setEnabled ( false ) ;
ui - > actionCut - > setEnabled ( false ) ;
ui - > actionFoldAll - > setEnabled ( false ) ;
ui - > actionIndent - > setEnabled ( false ) ;
ui - > actionPaste - > setEnabled ( false ) ;
ui - > actionRedo - > setEnabled ( false ) ;
ui - > actionSave - > setEnabled ( false ) ;
ui - > actionSaveAs - > setEnabled ( false ) ;
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 - > actionSelectAll - > setEnabled ( false ) ;
ui - > actionToggleComment - > setEnabled ( false ) ;
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 ) ;
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 ) ;
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
ui - > actionLocate_in_Files_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 ) ;
ui - > actionConvert_to_ANSI - > setEnabled ( e - > encodingOption ( ) ! = ENCODING_SYSTEM_DEFAULT & & e - > fileEncoding ( ) ! = ENCODING_SYSTEM_DEFAULT ) ;
ui - > actionConvert_to_UTF_8 - > setEnabled ( e - > encodingOption ( ) ! = ENCODING_UTF8 & & e - > fileEncoding ( ) ! = ENCODING_UTF8 ) ;
2021-07-01 19:44:38 +08:00
2021-06-12 22:36:23 +08:00
ui - > actionCopy - > setEnabled ( e - > selAvail ( ) ) ;
ui - > actionCut - > setEnabled ( e - > selAvail ( ) ) ;
ui - > actionFoldAll - > setEnabled ( e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionIndent - > setEnabled ( ! e - > readOnly ( ) ) ;
ui - > actionPaste - > setEnabled ( ! e - > readOnly ( ) & & ! QGuiApplication : : clipboard ( ) - > text ( ) . isEmpty ( ) ) ;
ui - > actionRedo - > setEnabled ( e - > canRedo ( ) ) ;
ui - > actionUndo - > setEnabled ( e - > canUndo ( ) ) ;
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 ) ;
2021-06-12 22:36:23 +08:00
ui - > actionSelectAll - > setEnabled ( e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionToggleComment - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionUnIndent - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionUnfoldAll - > setEnabled ( e - > lines ( ) - > count ( ) > 0 ) ;
2021-11-23 10:32:33 +08:00
ui - > actionDelete_Line - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_Word - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionDuplicate_Line - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_to_BOL - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
ui - > actionDelete_to_EOL - > setEnabled ( ! e - > readOnly ( ) & & e - > lines ( ) - > count ( ) > 0 ) ;
2021-07-01 19:44:38 +08:00
2021-08-05 19:58:32 +08:00
ui - > actionFind - > setEnabled ( true ) ;
ui - > actionReplace - > setEnabled ( true ) ;
ui - > actionFind_Next - > setEnabled ( true ) ;
ui - > actionFind_Previous - > setEnabled ( true ) ;
2021-09-02 12:14:02 +08:00
//code
ui - > actionReformat_Code - > setEnabled ( true ) ;
2021-09-02 20:12:16 +08:00
ui - > actionClose - > setEnabled ( true ) ;
ui - > actionClose_All - > setEnabled ( true ) ;
2021-10-21 17:31:25 +08:00
int line = e - > caretY ( ) ;
ui - > actionAdd_bookmark - > setEnabled ( e - > lines ( ) - > count ( ) > 0 & & ! e - > hasBookmark ( line ) ) ;
ui - > actionRemove_Bookmark - > setEnabled ( e - > hasBookmark ( line ) ) ;
ui - > actionModify_Bookmark_Description - > setEnabled ( e - > hasBookmark ( line ) ) ;
2021-10-22 15:02:54 +08:00
ui - > actionLocate_in_Files_View - > setEnabled ( ! e - > isNew ( ) ) ;
2021-10-21 17:31:25 +08:00
}
2021-09-02 20:12:16 +08:00
2021-09-17 09:56:52 +08:00
updateCompileActions ( ) ;
2021-11-12 02:20:13 +08:00
updateCompilerSet ( ) ;
2021-04-08 10:29:21 +08:00
}
2021-09-17 09:56:52 +08:00
void MainWindow : : updateProjectActions ( )
{
bool hasProject = ( mProject ! = nullptr ) ;
2021-09-17 20:01:11 +08:00
ui - > actionView_Makefile - > setEnabled ( hasProject ) ;
ui - > actionProject_New_File - > setEnabled ( hasProject ) ;
ui - > actionAdd_to_project - > setEnabled ( hasProject ) ;
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 ) ;
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 ( ) ;
}
2021-07-01 19:44:38 +08:00
void MainWindow : : updateCompileActions ( )
{
2021-09-17 09:56:52 +08:00
bool hasProject = ( mProject ! = nullptr ) ;
bool editorCanCompile = false ;
2021-09-04 21:54:58 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
2021-09-17 09:56:52 +08:00
if ( e ) {
FileType fileType = getFileType ( e - > filename ( ) ) ;
if ( fileType = = FileType : : CSource
2021-09-26 22:52:19 +08:00
| | fileType = = FileType : : CppSource | | e - > isNew ( ) )
2021-09-17 09:56:52 +08:00
editorCanCompile = true ;
}
2021-09-04 21:54:58 +08:00
if ( mCompilerManager - > compiling ( ) | | mCompilerManager - > running ( ) | | mDebugger - > executing ( )
2021-09-17 09:56:52 +08:00
| | ( ! hasProject & & ! editorCanCompile ) ) {
2021-07-01 19:44:38 +08:00
ui - > actionCompile - > setEnabled ( false ) ;
ui - > actionCompile_Run - > setEnabled ( false ) ;
ui - > actionRun - > setEnabled ( false ) ;
ui - > actionRebuild - > setEnabled ( false ) ;
2021-08-01 12:02:28 +08:00
ui - > actionDebug - > setEnabled ( false ) ;
2021-07-01 19:44:38 +08:00
} else {
ui - > actionCompile - > setEnabled ( true ) ;
ui - > actionCompile_Run - > setEnabled ( true ) ;
ui - > actionRun - > setEnabled ( true ) ;
ui - > actionRebuild - > setEnabled ( true ) ;
2021-08-01 12:02:28 +08:00
ui - > actionDebug - > setEnabled ( true ) ;
2021-07-01 19:44:38 +08:00
}
2021-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
//it's not a compile action, but put here for convinience
ui - > actionSaveAll - > setEnabled ( mProject ! = nullptr
| | mEditorList - > pageCount ( ) > 0 ) ;
2021-07-01 19:44:38 +08:00
}
2021-06-20 14:30:47 +08:00
void MainWindow : : updateEditorColorSchemes ( )
{
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 ;
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 ) {
2021-11-04 00:54:20 +08:00
mHeaderCompletionPopup - > setSuggestionColor ( item - > foreground ( ) ) ;
2021-10-31 08:31:46 +08:00
} else {
mHeaderCompletionPopup - > setSuggestionColor ( palette ( ) . color ( QPalette : : Text ) ) ;
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 ) ;
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 ) ;
2021-11-04 00:54:20 +08:00
}
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
//changeTheme(pSettings->environment().theme());
ThemeManager themeManager ;
PAppTheme appTheme = themeManager . theme ( pSettings - > environment ( ) . theme ( ) ) ;
if ( appTheme - > isDark ( ) )
QApplication : : setStyle ( new DarkFusionStyle ( ) ) ;
else
QApplication : : setStyle ( " fusion " ) ;
qApp - > setPalette ( appTheme - > palette ( ) ) ;
2021-11-14 17:43:25 +08:00
//fix for qstatusbar bug
mFileEncodingStatus - > setPalette ( appTheme - > palette ( ) ) ;
mFileModeStatus - > setPalette ( appTheme - > palette ( ) ) ;
mFileInfoStatus - > setPalette ( appTheme - > palette ( ) ) ;
2021-10-31 00:08:20 +08:00
updateEditorColorSchemes ( ) ;
2021-10-18 22:06:33 +08:00
2021-06-18 21:48:40 +08:00
QFont font ( pSettings - > environment ( ) . interfaceFont ( ) ,
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 ) ;
2021-11-02 09:29:35 +08:00
2021-11-02 13:12:36 +08:00
mTcpServer . close ( ) ;
int idxProblem = ui - > tabMessages - > indexOf ( ui - > tabProblem ) ;
ui - > tabMessages - > setTabEnabled ( idxProblem , pSettings - > executor ( ) . enableProblemSet ( ) ) ;
int idxProblemSet = ui - > tabInfos - > indexOf ( ui - > tabProblemSet ) ;
ui - > tabInfos - > setTabEnabled ( idxProblemSet , pSettings - > executor ( ) . enableProblemSet ( ) ) ;
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
}
}
if ( idxProblem < 0 )
ui - > tabMessages - > addTab ( ui - > tabProblem , tr ( " Problem " ) ) ;
if ( idxProblemSet < 0 )
ui - > tabInfos - > addTab ( ui - > tabProblemSet , tr ( " Problem Set " ) ) ;
} else {
if ( idxProblem > = 0 )
ui - > tabMessages - > removeTab ( idxProblem ) ;
if ( idxProblemSet > = 0 )
ui - > tabInfos - > removeTab ( idxProblemSet ) ;
2021-11-02 09:29:35 +08:00
}
2021-08-01 23:24:37 +08:00
updateDebuggerSettings ( ) ;
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 ( ) ;
restoreGeometry ( settings . mainWindowGeometry ( ) ) ;
restoreState ( settings . mainWindowState ( ) ) ;
2021-11-09 21:22:50 +08:00
ui - > actionTool_Window_Bars - > setChecked ( settings . showToolWindowBars ( ) ) ;
ui - > tabInfos - > setVisible ( settings . showToolWindowBars ( ) ) ;
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 ( ) ) ;
ui - > actionCompile_Log - > setChecked ( settings . showCompileLog ( ) ) ;
showHideMessagesTab ( ui - > tabCompilerOutput , settings . showCompileLog ( ) ) ;
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 ( ) ) ;
2021-11-09 21:22:50 +08:00
//we can't show/hide left/bottom panels here, cause mainwindow layout is not calculated
2021-09-02 16:35:28 +08:00
}
2021-08-31 14:40:41 +08:00
QFileSystemWatcher * MainWindow : : fileSystemWatcher ( )
{
return & mFileSystemWatcher ;
}
2021-07-26 00:22:08 +08:00
void MainWindow : : removeActiveBreakpoints ( )
{
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
e - > removeBreakpointFocus ( ) ;
}
}
2021-07-26 18:22:09 +08:00
void MainWindow : : setActiveBreakpoint ( QString FileName , int Line , bool setFocus )
{
removeActiveBreakpoints ( ) ;
// Then active the current line in the current file
Editor * e = mEditorList - > getEditorByFilename ( FileName ) ;
if ( e ! = nullptr ) {
e - > setActiveBreakpointFocus ( Line , setFocus ) ;
}
if ( setFocus ) {
this - > activateWindow ( ) ;
}
}
2021-07-26 00:22:08 +08:00
void MainWindow : : updateAppTitle ( )
{
2021-10-22 17:29:15 +08:00
QString appName = tr ( " Red Panda Dev-C++ " ) ;
2021-07-26 11:47:54 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
QCoreApplication * app = QApplication : : instance ( ) ;
if ( e & & ! e - > inProject ( ) ) {
2021-09-11 11:42:20 +08:00
QString str ;
2021-07-26 11:47:54 +08:00
if ( e - > modified ( ) )
str = e - > filename ( ) + " [*] " ;
else
str = e - > filename ( ) ;
if ( mDebugger - > executing ( ) ) {
2021-08-29 10:14:07 +08:00
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
2021-09-11 11:42:20 +08:00
. arg ( str , tr ( " Debugging " ) , appName , DEVCPP_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 " )
2021-09-11 11:42:20 +08:00
. arg ( str , tr ( " Running " ) , appName , DEVCPP_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 " )
2021-09-11 11:42:20 +08:00
. arg ( str , tr ( " Compiling " ) , appName , DEVCPP_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 " )
. arg ( str , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - %2 " )
. arg ( str , appName ) ) ;
2021-07-26 11:47:54 +08:00
}
2021-09-11 11:42:20 +08:00
} else if ( e & & e - > inProject ( ) & & mProject ) {
QString str , str2 ;
if ( mProject - > modified ( ) )
str = mProject - > name ( ) + " [*] " ;
else
str = mProject - > name ( ) ;
if ( e - > modified ( ) )
str2 = extractFileName ( e - > filename ( ) ) + " [*] " ;
else
str2 = extractFileName ( e - > filename ( ) ) ;
if ( mDebugger - > executing ( ) ) {
setWindowTitle ( QString ( " %1 - %2 [%3] - %4 %5 " )
. arg ( str , str2 ,
tr ( " Debugging " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Debugging " ) , appName ) ) ;
} else if ( mCompilerManager - > running ( ) ) {
setWindowTitle ( QString ( " %1 - %2 [%3] - %4 %5 " )
. arg ( str , str2 ,
tr ( " Running " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Running " ) , appName ) ) ;
} else if ( mCompilerManager - > compiling ( ) ) {
setWindowTitle ( QString ( " %1 - %2 [%3] - %4 %5 " )
. arg ( str , str2 ,
tr ( " Compiling " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Compiling " ) , appName ) ) ;
} else {
setWindowTitle ( QString ( " %1 - %2 %3 " )
. arg ( str , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - %2 " )
. arg ( str , appName ) ) ;
}
} else if ( mProject ) {
QString str , str2 ;
if ( mProject - > modified ( ) )
str = mProject - > name ( ) + " [*] " ;
else
str = mProject - > name ( ) ;
if ( mDebugger - > executing ( ) ) {
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
. arg ( str , tr ( " Debugging " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Debugging " ) , appName ) ) ;
} else if ( mCompilerManager - > running ( ) ) {
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
. arg ( str , tr ( " Running " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Running " ) , appName ) ) ;
} else if ( mCompilerManager - > compiling ( ) ) {
setWindowTitle ( QString ( " %1 - [%2] - %3 %4 " )
. arg ( str , tr ( " Compiling " ) , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - [%2] - %3 " )
. arg ( str , tr ( " Compiling " ) , appName ) ) ;
} else {
this - > setWindowTitle ( QString ( " %1 - %2 %3 " )
. arg ( str , appName , DEVCPP_VERSION ) ) ;
app - > setApplicationName ( QString ( " %1 - %2 " )
. arg ( str , appName ) ) ;
}
} else {
2021-08-29 10:14:07 +08:00
setWindowTitle ( QString ( " %1 %2 " ) . arg ( appName , DEVCPP_VERSION ) ) ;
2021-08-29 00:48:23 +08:00
app - > setApplicationName ( QString ( " %1 " ) . arg ( appName ) ) ;
2021-07-26 11:47:54 +08:00
}
}
void MainWindow : : addDebugOutput ( const QString & text )
{
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 ( ) ;
2021-08-02 10:08:25 +08:00
if ( pSettings - > history ( ) . openedFiles ( ) . size ( ) = = 0 ) {
mMenuRecentFiles - > setEnabled ( false ) ;
} else {
mMenuRecentFiles - > setEnabled ( true ) ;
2021-08-29 10:14:07 +08:00
for ( const QString & filename : pSettings - > history ( ) . openedFiles ( ) ) {
2021-10-08 00:06:41 +08:00
QAction * action = new QAction ( filename , mMenuRecentFiles ) ;
2021-08-29 10:14:07 +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
}
}
2021-09-17 21:33:19 +08:00
if ( pSettings - > history ( ) . openedProjects ( ) . size ( ) = = 0 ) {
mMenuRecentProjects - > setEnabled ( false ) ;
} else {
mMenuRecentProjects - > setEnabled ( true ) ;
for ( const QString & filename : pSettings - > history ( ) . openedProjects ( ) ) {
2021-10-08 00:06:41 +08:00
QAction * action = new QAction ( filename , mMenuRecentProjects ) ;
2021-09-17 21:33:19 +08:00
connect ( action , & QAction : : triggered , [ & filename , this ] ( bool ) {
this - > openProject ( filename ) ;
} ) ;
2021-10-08 00:06:41 +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 )
{
if ( ! editor ) {
mClassBrowserModel . setParser ( nullptr ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
2021-08-23 21:50:53 +08:00
mClassBrowserModel . clear ( ) ;
2021-08-23 17:27:17 +08:00
return ;
}
if ( mQuitting )
return ;
// if not devCodeCompletion.Enabled then
// Exit;
if ( ( mClassBrowserModel . currentFile ( ) = = editor - > filename ( ) )
& & ( mClassBrowserModel . parser ( ) = = editor - > parser ( ) ) )
return ;
mClassBrowserModel . beginUpdate ( ) ;
{
auto action = finally ( [ this ] {
mClassBrowserModel . endUpdate ( ) ;
} ) ;
mClassBrowserModel . setParser ( editor - > parser ( ) ) ;
// if e.InProject then begin
// ClassBrowser.StatementsType := devClassBrowsing.StatementsType;
// end else
// ClassBrowser.StatementsType := cbstFile;
mClassBrowserModel . setCurrentFile ( editor - > filename ( ) ) ;
}
}
2021-08-30 22:05:45 +08:00
void MainWindow : : resetAutoSaveTimer ( )
{
if ( pSettings - > editor ( ) . enableAutoSave ( ) ) {
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 ( ) ;
manager . applyTo ( findChildren < QAction * > ( ) ) ;
}
2021-08-01 10:00:27 +08:00
QPlainTextEdit * MainWindow : : txtLocals ( )
{
return ui - > txtLocals ;
}
2021-06-12 22:36:23 +08:00
void MainWindow : : updateStatusbarForLineCol ( )
2021-06-07 11:02:03 +08:00
{
2021-06-12 22:36:23 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ! = nullptr ) {
2021-08-29 22:51:23 +08:00
int col = e - > charToColumn ( e - > caretY ( ) , e - > caretX ( ) ) ;
QString msg = tr ( " Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5 " )
2021-10-15 10:23:46 +08:00
. arg ( e - > caretY ( ) )
. arg ( col )
. arg ( e - > selText ( ) . length ( ) )
. arg ( e - > lines ( ) - > count ( ) )
. arg ( e - > lines ( ) - > getTextLength ( ) ) ;
2021-06-12 22:36:23 +08:00
mFileInfoStatus - > setText ( msg ) ;
} else {
mFileInfoStatus - > setText ( " " ) ;
}
}
void MainWindow : : updateForStatusbarModeInfo ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ! = nullptr ) {
QString msg ;
if ( e - > readOnly ( ) ) {
msg = tr ( " Read Only " ) ;
} else if ( e - > insertMode ( ) ) {
msg = tr ( " Insert " ) ;
} else {
msg = tr ( " Overwrite " ) ;
}
mFileModeStatus - > setText ( msg ) ;
} else {
mFileModeStatus - > setText ( " " ) ;
}
2021-06-07 11:02:03 +08:00
}
2021-08-30 22:05:45 +08:00
void MainWindow : : updateStatusbarMessage ( const QString & s )
2021-08-27 16:38:55 +08:00
{
2021-08-27 23:51:42 +08:00
ui - > statusbar - > showMessage ( s ) ;
2021-08-27 16:38:55 +08:00
}
2021-04-11 21:33:08 +08:00
void MainWindow : : openFiles ( const QStringList & files )
{
mEditorList - > beginUpdate ( ) ;
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 ;
updateEditorParser ( ui - > EditorTabsLeft ) ;
updateEditorParser ( ui - > EditorTabsRight ) ;
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
2021-08-29 10:14:07 +08:00
for ( const QString & file : files ) {
2021-04-11 21:33:08 +08:00
openFile ( file ) ;
}
mEditorList - > endUpdate ( ) ;
}
2021-10-23 23:10:34 +08:00
void MainWindow : : openFile ( const QString & filename , QTabWidget * page )
2021-04-11 21:33:08 +08:00
{
2021-04-29 20:54:44 +08:00
Editor * editor = mEditorList - > getOpenedEditorByFilename ( filename ) ;
2021-04-11 21:33:08 +08:00
if ( editor ! = nullptr ) {
2021-04-12 00:00:29 +08:00
editor - > activate ( ) ;
2021-04-11 21:33:08 +08:00
return ;
}
2021-08-31 14:40:41 +08:00
try {
2021-09-11 11:42:20 +08:00
pSettings - > history ( ) . removeFile ( filename ) ;
2021-08-31 14:40:41 +08:00
editor = mEditorList - > newEditor ( filename , ENCODING_AUTO_DETECT ,
2021-10-23 23:10:34 +08:00
false , false , page ) ;
2021-08-31 14:40:41 +08:00
editor - > activate ( ) ;
this - > updateForEncodingInfo ( ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
2021-04-11 21:33:08 +08:00
}
2021-09-11 11:42:20 +08:00
void MainWindow : : openProject ( const QString & filename )
{
if ( ! fileExists ( filename ) ) {
return ;
}
if ( mProject ) {
QString s ;
if ( mProject - > name ( ) . isEmpty ( ) )
s = mProject - > filename ( ) ;
else
s = mProject - > name ( ) ;
if ( QMessageBox : : question ( this ,
tr ( " Close project " ) ,
tr ( " Are you sure you want to close %1? " )
. arg ( s ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
closeProject ( false ) ;
} else {
return ;
}
}
ui - > tabProject - > setVisible ( true ) ;
ui - > tabInfos - > setCurrentWidget ( ui - > tabProject ) ;
openCloseLeftPanel ( true ) ;
// {
// LeftPageControl.ActivePage := LeftProjectSheet;
// fLeftPageControlChanged := False;
// ClassBrowser.TabVisible:= False;
// }
// Only update class browser once
mClassBrowserModel . beginUpdate ( ) ;
{
auto action = finally ( [ this ] {
mClassBrowserModel . endUpdate ( ) ;
} ) ;
2021-09-11 18:42:49 +08:00
mProject = std : : make_shared < Project > ( filename , DEV_INTERNAL_OPEN ) ;
2021-09-17 09:56:52 +08:00
updateProjectView ( ) ;
2021-09-11 18:42:49 +08:00
pSettings - > history ( ) . removeProject ( filename ) ;
2021-09-11 11:42:20 +08:00
// // if project manager isn't open then open it
// if not devData.ShowLeftPages then
// actProjectManager.Execute;
2021-09-11 18:42:49 +08:00
//checkForDllProfiling();
2021-09-17 09:56:52 +08:00
updateAppTitle ( ) ;
updateCompilerSet ( ) ;
2021-09-11 11:42:20 +08:00
2021-09-17 09:56:52 +08:00
//parse the project
// UpdateClassBrowsing;
scanActiveProject ( true ) ;
mProject - > doAutoOpen ( ) ;
2021-09-11 11:42:20 +08:00
2021-09-17 09:56:52 +08:00
//update editor's inproject flag
for ( int i = 0 ; i < mProject - > units ( ) . count ( ) ; i + + ) {
PProjectUnit unit = mProject - > units ( ) [ i ] ;
Editor * e = mEditorList - > getOpenedEditorByFilename ( unit - > fileName ( ) ) ;
2021-09-11 11:42:20 +08:00
if ( e ) {
2021-09-17 09:56:52 +08:00
unit - > setEditor ( e ) ;
unit - > setEncoding ( e - > encodingOption ( ) ) ;
e - > setInProject ( true ) ;
} else {
unit - > setEditor ( nullptr ) ;
2021-09-11 11:42:20 +08:00
}
2021-09-17 09:56:52 +08:00
}
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
checkSyntaxInBack ( e ) ;
}
updateClassBrowserForEditor ( e ) ;
2021-09-11 11:42:20 +08:00
}
updateForEncodingInfo ( ) ;
}
2021-10-24 17:31:20 +08:00
void MainWindow : : changeOptions ( const QString & widgetName , const QString & groupName )
{
bool oldCodeCompletion = pSettings - > codeCompletion ( ) . enabled ( ) ;
PSettingsDialog settingsDialog = SettingsDialog : : optionDialog ( ) ;
if ( ! groupName . isEmpty ( ) ) {
settingsDialog - > setCurrentWidget ( widgetName , groupName ) ;
}
settingsDialog - > exec ( ) ;
if ( settingsDialog - > appShouldQuit ( ) ) {
mShouldRemoveAllSettings = true ;
close ( ) ;
return ;
}
bool newCodeCompletion = pSettings - > codeCompletion ( ) . enabled ( ) ;
if ( ! oldCodeCompletion & & newCodeCompletion ) {
Editor * e = mEditorList - > getEditor ( ) ;
if ( mProject & & ! e ) {
scanActiveProject ( true ) ;
} else if ( mProject & & e & & e - > inProject ( ) ) {
scanActiveProject ( true ) ;
} else if ( e ) {
e - > reparse ( ) ;
}
}
}
2021-04-07 21:13:15 +08:00
void MainWindow : : setupActions ( ) {
}
2021-04-18 11:41:41 +08:00
void MainWindow : : updateCompilerSet ( )
{
2021-09-19 14:28:30 +08:00
mCompilerSet - > blockSignals ( true ) ;
2021-04-18 11:41:41 +08:00
mCompilerSet - > clear ( ) ;
2021-06-07 11:02:03 +08:00
for ( size_t i = 0 ; i < pSettings - > compilerSets ( ) . list ( ) . size ( ) ; i + + ) {
2021-04-18 11:41:41 +08:00
mCompilerSet - > addItem ( pSettings - > compilerSets ( ) . list ( ) [ i ] - > name ( ) ) ;
}
2021-09-11 11:42:20 +08:00
int index = pSettings - > compilerSets ( ) . defaultIndex ( ) ;
if ( mProject ) {
Editor * e = mEditorList - > getEditor ( ) ;
if ( ! e | | e - > inProject ( ) ) {
index = mProject - > options ( ) . compilerSet ;
}
}
2021-04-18 11:41:41 +08:00
if ( index < 0 | | index > = mCompilerSet - > count ( ) ) {
2021-09-11 11:42:20 +08:00
index = pSettings - > compilerSets ( ) . defaultIndex ( ) ;
2021-04-18 11:41:41 +08:00
}
mCompilerSet - > setCurrentIndex ( index ) ;
2021-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-11-06 19:31:16 +08:00
QFont font ( pSettings - > debugger ( ) . fontName ( ) ,
pSettings - > debugger ( ) . fontSize ( ) ) ;
ui - > debugConsole - > setFont ( font ) ;
ui - > txtMemoryView - > setFont ( font ) ;
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-06-24 20:43:09 +08:00
void MainWindow : : checkSyntaxInBack ( Editor * e )
{
if ( e = = nullptr )
return ;
2021-09-11 11:42:20 +08:00
if ( ! pSettings - > editor ( ) . syntaxCheck ( ) ) {
return ;
}
2021-06-24 20:43:09 +08:00
// if not devEditor.AutoCheckSyntax then
// Exit;
//not c or cpp file
if ( ! e - > highlighter ( ) | | e - > highlighter ( ) - > getName ( ) ! = SYN_HIGHLIGHTER_CPP )
return ;
if ( mCompilerManager - > backgroundSyntaxChecking ( ) )
return ;
if ( mCompilerManager - > compiling ( ) )
return ;
2021-08-23 21:50:53 +08:00
if ( ! pSettings - > compilerSets ( ) . defaultSet ( ) )
return ;
2021-06-24 20:43:09 +08:00
if ( mCheckSyntaxInBack )
return ;
mCheckSyntaxInBack = true ;
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-09-12 22:45:00 +08:00
CompileTarget target = getCompileTarget ( ) ;
if ( target = = CompileTarget : : Project ) {
2021-10-07 07:52:20 +08:00
mCompilerManager - > checkSyntax ( e - > filename ( ) , e - > text ( ) ,
2021-09-12 22:45:00 +08:00
e - > fileEncoding ( ) = = ENCODING_ASCII , mProject ) ;
} else {
2021-10-07 07:52:20 +08:00
mCompilerManager - > checkSyntax ( e - > filename ( ) , e - > text ( ) ,
2021-09-12 22:45:00 +08:00
e - > fileEncoding ( ) = = ENCODING_ASCII , nullptr ) ;
}
2021-06-25 12:40:11 +08:00
}
bool MainWindow : : compile ( bool rebuild )
{
2021-09-12 22:45:00 +08:00
CompileTarget target = getCompileTarget ( ) ;
if ( target = = CompileTarget : : Project ) {
2021-11-23 10:32:33 +08:00
if ( mProject - > modified ( ) )
mProject - > 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 ) {
mCompileSuccessionTask - > filename = mProject - > executable ( ) ;
}
updateCompileActions ( ) ;
openCloseBottomPanel ( true ) ;
ui - > tabMessages - > setCurrentWidget ( ui - > tabCompilerOutput ) ;
mCompilerManager - > compileProject ( mProject , rebuild ) ;
updateAppTitle ( ) ;
2021-09-12 22:45:00 +08:00
} else {
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ! = NULL ) {
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 ) {
mCompileSuccessionTask - > filename = getCompiledExecutableName ( editor - > filename ( ) ) ;
}
updateCompileActions ( ) ;
openCloseBottomPanel ( true ) ;
ui - > tabMessages - > setCurrentWidget ( ui - > tabCompilerOutput ) ;
mCompilerManager - > compile ( editor - > filename ( ) , editor - > fileEncoding ( ) , rebuild ) ;
2021-09-13 22:45:50 +08:00
updateAppTitle ( ) ;
2021-09-12 22:45:00 +08:00
return true ;
2021-06-25 12:40:11 +08:00
}
}
return false ;
}
2021-11-01 20:44:08 +08:00
void MainWindow : : runExecutable ( const QString & exeName , const QString & filename , RunType runType )
2021-06-25 12:40:11 +08:00
{
// Check if it exists
2021-09-07 10:28:40 +08:00
if ( ! fileExists ( exeName ) ) {
2021-06-25 12:40:11 +08:00
if ( ui - > actionCompile_Run - > isEnabled ( ) ) {
2021-07-26 22:29:47 +08:00
if ( QMessageBox : : question ( this , tr ( " Confirm " ) ,
2021-06-25 12:40:11 +08:00
tr ( " Source file is not compiled. " )
+ " <br /><br /> " + tr ( " Compile now? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) {
2021-11-01 23:14:17 +08:00
doCompileRun ( runType ) ;
2021-06-25 12:40:11 +08:00
}
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 {
if ( ! filename . isEmpty ( ) & & compareFileModifiedTime ( filename , exeName ) > = 0 ) {
if ( ui - > actionCompile_Run - > isEnabled ( ) ) {
if ( QMessageBox : : warning ( this , tr ( " Confirm " ) ,
tr ( " Source file is more recent than executable. " )
+ " <br /><br /> " + tr ( " Recompile now? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) {
2021-11-01 23:14:17 +08:00
doCompileRun ( runType ) ;
2021-06-25 12:40:11 +08:00
return ;
}
2021-10-12 09:47:58 +08:00
} else {
QMessageBox : : warning ( this , " Error " ,
tr ( " Source file is more recent than executable. " ) ) ;
2021-06-25 12:40:11 +08:00
}
}
}
2021-07-01 19:44:38 +08:00
updateCompileActions ( ) ;
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 ( ) ;
}
mCompilerManager - > run ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) ) ;
} else if ( runType = = RunType : : ProblemCases ) {
POJProblem problem = mOJProblemModel . problem ( ) ;
if ( problem ) {
mCompilerManager - > runProblem ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) ,
2021-11-27 15:43:47 +08:00
problem - > cases ) ;
2021-11-02 01:07:37 +08:00
openCloseBottomPanel ( true ) ;
ui - > tabMessages - > setCurrentWidget ( ui - > tabProblem ) ;
2021-11-01 20:44:08 +08:00
}
} else if ( runType = = RunType : : CurrentProblemCase ) {
QModelIndex index = ui - > lstProblemCases - > currentIndex ( ) ;
if ( index . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( index . row ( ) ) ;
mCompilerManager - > runProblem ( exeName , params , QFileInfo ( exeName ) . absolutePath ( ) ,
problemCase ) ;
2021-11-02 01:07:37 +08:00
openCloseBottomPanel ( true ) ;
ui - > tabMessages - > setCurrentWidget ( ui - > tabProblem ) ;
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 ) {
2021-11-23 10:32:33 +08:00
if ( mProject - > modified ( ) & &
QMessageBox : : question (
this ,
tr ( " Rebuild Project " ) ,
tr ( " Project has been modified, do you want to rebuild it? " )
) = = QMessageBox : : Yes ) {
mProject - > saveAll ( ) ;
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : RunNormal ;
compile ( ) ;
return ;
}
2021-11-01 20:44:08 +08:00
runExecutable ( mProject - > executable ( ) , mProject - > filename ( ) , runType ) ;
2021-09-13 22:45:50 +08:00
} else {
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ! = NULL ) {
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 ;
}
QString exeName = getCompiledExecutableName ( editor - > filename ( ) ) ;
2021-11-01 20:44:08 +08:00
runExecutable ( exeName , editor - > filename ( ) , runType ) ;
2021-06-25 12:40:11 +08:00
}
}
2021-06-24 20:43:09 +08:00
}
2021-07-23 13:22:05 +08:00
void MainWindow : : debug ( )
{
if ( mCompilerManager - > compiling ( ) )
return ;
Settings : : PCompilerSet compilerSet = pSettings - > compilerSets ( ) . defaultSet ( ) ;
2021-07-26 22:29:47 +08:00
if ( ! compilerSet ) {
QMessageBox : : critical ( pMainWindow ,
tr ( " No compiler set " ) ,
tr ( " No compiler set is configured. " ) + " <BR/> " + tr ( " Can't start debugging. " ) ) ;
2021-07-23 13:22:05 +08:00
return ;
2021-07-26 22:29:47 +08:00
}
2021-07-23 13:22:05 +08:00
bool debugEnabled ;
bool stripEnabled ;
2021-07-25 13:03:46 +08:00
QString filePath ;
QFileInfo debugFile ;
2021-07-23 13:22:05 +08:00
switch ( getCompileTarget ( ) ) {
case CompileTarget : : Project :
2021-09-18 11:32:38 +08:00
// Check if we enabled proper options
debugEnabled = mProject - > getCompilerOption ( " -g3 " ) ! = ' 0 ' ;
stripEnabled = mProject - > getCompilerOption ( " -s " ) ! = ' 0 ' ;
// Ask the user if he wants to enable debugging...
if ( ( ( ! debugEnabled ) | | stripEnabled ) & &
( QMessageBox : : question ( this ,
tr ( " Enable debugging " ) ,
tr ( " You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now? " )
) = = QMessageBox : : Yes ) ) {
// Enable debugging, disable stripping
mProject - > setCompilerOption ( " -g3 " , ' 1 ' ) ;
mProject - > setCompilerOption ( " -s " , ' 0 ' ) ;
// Save changes to compiler set
mProject - > saveOptions ( ) ;
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
compile ( ) ;
return ;
}
2021-09-18 19:30:16 +08:00
// Did we compile?
if ( ! fileExists ( mProject - > executable ( ) ) ) {
if ( QMessageBox : : question (
this ,
tr ( " Project not built " ) ,
tr ( " Project hasn't been built. Build it now? " ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
compile ( ) ;
}
return ;
}
2021-11-23 10:32:33 +08:00
if ( mProject - > modified ( ) & &
QMessageBox : : question (
this ,
2021-11-23 12:39:32 +08:00
tr ( " Rebuild Project " ) ,
2021-11-23 10:32:33 +08:00
tr ( " Project has been modified, do you want to rebuild it? " )
) = = QMessageBox : : Yes ) {
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
compile ( ) ;
return ;
}
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
2021-09-18 19:30:16 +08:00
if ( ! mDebugger - > start ( ) )
return ;
filePath . replace ( ' \\ ' , ' / ' ) ;
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -file-exec-and-symbols " , ' " ' + filePath + ' " ' ) ;
2021-07-23 13:22:05 +08:00
2021-09-18 19:30:16 +08:00
if ( mProject - > options ( ) . type = = ProjectType : : DynamicLib ) {
QString host = mProject - > options ( ) . hostApplication ;
host . replace ( ' \\ ' , ' / ' ) ;
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -file-exec-file " , ' " ' + host + ' " ' ) ;
2021-09-18 19:30:16 +08:00
}
2021-10-09 11:33:23 +08:00
2021-09-28 14:18:51 +08:00
includeOrSkipDirs ( mProject - > options ( ) . includes ,
pSettings - > debugger ( ) . skipProjectLibraries ( ) ) ;
includeOrSkipDirs ( mProject - > options ( ) . libs ,
pSettings - > debugger ( ) . skipProjectLibraries ( ) ) ;
2021-09-18 19:30:16 +08:00
break ;
2021-10-20 18:05:43 +08:00
case CompileTarget : : File : {
// Check if we enabled proper options
debugEnabled = compilerSet - > getOptionValue ( " -g3 " ) ! = ' 0 ' ;
stripEnabled = compilerSet - > getOptionValue ( " -s " ) ! = ' 0 ' ;
// Ask the user if he wants to enable debugging...
if ( ( ( ! debugEnabled ) | | stripEnabled ) & &
( QMessageBox : : question ( this ,
tr ( " Enable debugging " ) ,
tr ( " You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now? " )
) = = QMessageBox : : Yes ) ) {
// Enable debugging, disable stripping
compilerSet - > setOption ( " -g3 " , ' 1 ' ) ;
compilerSet - > setOption ( " -s " , ' 0 ' ) ;
// Save changes to compiler set
pSettings - > compilerSets ( ) . saveSet ( pSettings - > compilerSets ( ) . defaultIndex ( ) ) ;
2021-07-23 13:22:05 +08:00
2021-10-20 18:05:43 +08:00
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
2021-07-23 13:22:05 +08:00
2021-10-20 18:05:43 +08:00
compile ( ) ;
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?
filePath = getCompiledExecutableName ( e - > filename ( ) ) ;
debugFile . setFile ( filePath ) ;
if ( ! debugFile . exists ( ) ) {
2021-07-23 13:22:05 +08:00
if ( QMessageBox : : question ( this , tr ( " Compile " ) ,
2021-10-20 18:05:43 +08:00
tr ( " Source file is not compiled. " ) + " <BR /><BR /> " + tr ( " Compile now? " ) ,
2021-07-23 13:22:05 +08:00
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
compile ( ) ;
return ;
}
2021-10-20 18:05:43 +08:00
} else {
if ( compareFileModifiedTime ( e - > filename ( ) , filePath ) > = 0 ) {
if ( QMessageBox : : question ( this , tr ( " Compile " ) ,
tr ( " Source file is more recent than executable. " ) + " <BR /><BR /> " + tr ( " Recompile? " ) ,
QMessageBox : : Yes | QMessageBox : : No ,
QMessageBox : : Yes ) = = QMessageBox : : Yes ) {
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : Debug ;
compile ( ) ;
return ;
}
}
2021-07-23 13:22:05 +08:00
}
2021-10-20 18:05:43 +08:00
prepareDebugger ( ) ;
2021-07-23 13:22:05 +08:00
2021-10-20 18:05:43 +08:00
if ( ! mDebugger - > start ( ) )
return ;
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -file-exec-and-symbols " , QString ( " \" %1 \" " ) . arg ( debugFile . filePath ( ) . replace ( ' \\ ' , ' / ' ) ) ) ;
2021-10-20 18:05:43 +08:00
}
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
// Add library folders
2021-09-28 14:18:51 +08:00
includeOrSkipDirs ( compilerSet - > libDirs ( ) , pSettings - > debugger ( ) . skipCustomLibraries ( ) ) ;
includeOrSkipDirs ( compilerSet - > CIncludeDirs ( ) , pSettings - > debugger ( ) . skipCustomLibraries ( ) ) ;
includeOrSkipDirs ( compilerSet - > CppIncludeDirs ( ) , pSettings - > debugger ( ) . skipCustomLibraries ( ) ) ;
//gcc system libraries is auto loaded by gdb
if ( pSettings - > debugger ( ) . skipSystemLibraries ( ) ) {
includeOrSkipDirs ( compilerSet - > defaultCIncludeDirs ( ) , true ) ;
includeOrSkipDirs ( compilerSet - > defaultCIncludeDirs ( ) , true ) ;
includeOrSkipDirs ( compilerSet - > defaultCppIncludeDirs ( ) , true ) ;
2021-09-04 20:49:44 +08:00
}
2021-07-23 13:22:05 +08:00
2021-07-25 13:03:46 +08:00
mDebugger - > sendAllBreakpointsToDebugger ( ) ;
2021-07-23 13:22:05 +08:00
// Run the debugger
2021-11-25 21:44:08 +08:00
mDebugger - > sendCommand ( " -enable-pretty-printing " , " " ) ;
2021-11-25 09:05:45 +08:00
mDebugger - > sendCommand ( " -data-list-register-names " , " " ) ;
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -gdb-set " , " width 0 " ) ; // don't wrap output, very annoying
mDebugger - > sendCommand ( " -gdb-set " , " new-console on " ) ;
mDebugger - > sendCommand ( " -gdb-set " , " confirm off " ) ;
mDebugger - > sendCommand ( " -gdb-set " , " print repeats 0 " ) ; // don't repeat elements
mDebugger - > sendCommand ( " -gdb-set " , " print elements 0 " ) ; // don't limit elements
mDebugger - > sendCommand ( " -environment-cd " , excludeTrailingPathDelimiter ( debugFile . path ( ) ) ) ; // restore working directory
2021-07-25 13:03:46 +08:00
if ( ! debugInferiorhasBreakpoint ( ) ) {
switch ( getCompileTarget ( ) ) {
case CompileTarget : : None :
return ;
case CompileTarget : : File :
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-run " , " --start " ) ;
2021-07-25 13:03:46 +08:00
break ;
case CompileTarget : : Project :
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-run " , " --start " ) ;
2021-07-25 13:03:46 +08:00
break ;
2021-10-20 18:05:43 +08:00
default :
break ;
2021-07-25 13:03:46 +08:00
}
} else {
switch ( getCompileTarget ( ) ) {
case CompileTarget : : None :
return ;
case CompileTarget : : File :
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-run " , " " ) ;
2021-07-25 13:03:46 +08:00
break ;
case CompileTarget : : Project :
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-run " , " " ) ;
2021-07-25 13:03:46 +08:00
break ;
2021-10-20 18:05:43 +08:00
default :
break ;
2021-07-25 13:03:46 +08:00
}
}
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
{
2021-09-02 19:36:16 +08:00
openCloseBottomPanel ( 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 ) {
mCPUDialog = new CPUDialog ( this ) ;
connect ( mCPUDialog , & CPUDialog : : closed , this , & MainWindow : : cleanUpCPUDialog ) ;
}
mCPUDialog - > show ( ) ;
}
2021-09-02 19:36:16 +08:00
void MainWindow : : openCloseBottomPanel ( bool open )
2021-06-23 22:38:02 +08:00
{
// if Assigned(fReportToolWindow) then
// Exit;
2021-09-02 19:36:16 +08:00
if ( mOpenClosingBottomPanel )
2021-06-24 16:05:19 +08:00
return ;
2021-09-02 19:36:16 +08:00
mOpenClosingBottomPanel = true ;
2021-06-24 16:05:19 +08:00
auto action = finally ( [ this ] {
2021-09-02 19:36:16 +08:00
mOpenClosingBottomPanel = false ;
2021-06-24 16:05:19 +08:00
} ) ;
2021-06-23 22:38:02 +08:00
// Switch between open and close
if ( open ) {
QList < int > sizes = ui - > splitterMessages - > sizes ( ) ;
int tabHeight = ui - > tabMessages - > tabBar ( ) - > height ( ) ;
ui - > tabMessages - > setMinimumHeight ( tabHeight + 5 ) ;
int totalSize = sizes [ 0 ] + sizes [ 1 ] ;
2021-09-02 19:36:16 +08:00
sizes [ 1 ] = mBottomPanelHeight ;
2021-06-23 22:38:02 +08:00
sizes [ 0 ] = std : : max ( 1 , totalSize - sizes [ 1 ] ) ;
ui - > splitterMessages - > setSizes ( sizes ) ;
} else {
QList < int > sizes = ui - > splitterMessages - > sizes ( ) ;
2021-09-02 19:36:16 +08:00
mBottomPanelHeight = sizes [ 1 ] ;
2021-06-23 22:38:02 +08:00
int totalSize = sizes [ 0 ] + sizes [ 1 ] ;
int tabHeight = ui - > tabMessages - > tabBar ( ) - > height ( ) ;
ui - > tabMessages - > setMinimumHeight ( tabHeight ) ;
sizes [ 1 ] = tabHeight ;
sizes [ 0 ] = std : : max ( 1 , totalSize - sizes [ 1 ] ) ;
ui - > splitterMessages - > setSizes ( sizes ) ;
}
2021-09-02 19:36:16 +08:00
mBottomPanelOpenned = open ;
2021-06-23 22:38:02 +08:00
QSplitterHandle * handle = ui - > splitterMessages - > handle ( 1 ) ;
handle - > setEnabled ( open ) ;
2021-09-02 19:36:16 +08:00
}
void MainWindow : : openCloseLeftPanel ( bool open )
{
if ( mOpenClosingLeftPanel )
return ;
mOpenClosingLeftPanel = true ;
auto action = finally ( [ this ] {
mOpenClosingLeftPanel = false ;
} ) ;
// Switch between open and close
if ( open ) {
QList < int > sizes = ui - > splitterInfos - > sizes ( ) ;
int tabWidth = ui - > tabInfos - > tabBar ( ) - > width ( ) ;
ui - > tabInfos - > setMinimumWidth ( tabWidth + 5 ) ;
int totalSize = sizes [ 0 ] + sizes [ 1 ] ;
sizes [ 0 ] = mLeftPanelWidth ;
sizes [ 1 ] = std : : max ( 1 , totalSize - sizes [ 0 ] ) ;
ui - > splitterInfos - > setSizes ( sizes ) ;
} else {
QList < int > sizes = ui - > splitterInfos - > sizes ( ) ;
mLeftPanelWidth = sizes [ 0 ] ;
int totalSize = sizes [ 0 ] + sizes [ 1 ] ;
int tabWidth = ui - > tabInfos - > tabBar ( ) - > width ( ) ;
ui - > tabInfos - > setMinimumWidth ( tabWidth ) ;
sizes [ 0 ] = tabWidth ;
sizes [ 1 ] = std : : max ( 1 , totalSize - sizes [ 0 ] ) ;
ui - > splitterInfos - > setSizes ( sizes ) ;
}
mLeftPanelOpenned = open ;
QSplitterHandle * handle = ui - > splitterInfos - > handle ( 1 ) ;
handle - > setEnabled ( open ) ;
2021-06-23 22:38:02 +08:00
}
2021-07-23 13:22:05 +08:00
void MainWindow : : prepareDebugger ( )
{
mDebugger - > stop ( ) ;
// Clear logs
ui - > debugConsole - > clear ( ) ;
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
2021-07-26 18:22:09 +08:00
mDebugger - > setLeftPageIndexBackup ( ui - > tabInfos - > currentIndex ( ) ) ;
2021-07-23 13:22:05 +08:00
// Focus on the debugging buttons
ui - > tabInfos - > setCurrentWidget ( ui - > tabWatch ) ;
ui - > tabMessages - > setCurrentWidget ( ui - > tabDebug ) ;
2021-10-27 16:58:30 +08:00
ui - > debugViews - > setCurrentWidget ( ui - > tabLocals ) ;
2021-09-02 19:36:16 +08:00
openCloseBottomPanel ( true ) ;
openCloseLeftPanel ( 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 :
e - > save ( ) ;
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
}
}
2021-09-05 13:51:07 +08:00
//static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) {
// action->setParent(scopeWidget);
// action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
//}
QAction * MainWindow : : createActionFor (
const QString & text ,
QWidget * parent ,
QKeySequence shortcut ) {
QAction * action = new QAction ( text , parent ) ;
if ( ! shortcut . isEmpty ( ) )
action - > setShortcut ( shortcut ) ;
action - > setPriority ( QAction : : HighPriority ) ;
action - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
parent - > addAction ( action ) ;
return action ;
}
2021-09-11 18:42:49 +08:00
void MainWindow : : scanActiveProject ( bool parse )
{
if ( ! mProject )
return ;
//UpdateClassBrowsing;
if ( parse ) {
resetCppParser ( mProject - > cppParser ( ) ) ;
mProject - > resetParserProjectFiles ( ) ;
parseFileList ( mProject - > cppParser ( ) ) ;
} else {
mProject - > resetParserProjectFiles ( ) ;
} ;
}
2021-09-28 14:18:51 +08:00
void MainWindow : : includeOrSkipDirs ( const QStringList & dirs , bool skip )
{
Q_ASSERT ( mDebugger ) ;
foreach ( QString dir , dirs ) {
QString dirName = dir . replace ( ' \\ ' , ' / ' ) ;
if ( skip ) {
2021-11-25 20:26:43 +08:00
mDebugger - > sendCommand (
" skip " ,
QString ( " -gfi \" %1/%2 \" " )
. arg ( dirName , " *.* " ) ) ;
2021-09-28 14:18:51 +08:00
} else {
mDebugger - > sendCommand (
2021-11-10 12:29:02 +08:00
" -environment-directory " ,
2021-09-28 14:18:51 +08:00
QString ( " \" %1 \" " ) . arg ( dirName ) ) ;
}
}
}
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 ) ) ;
}
2021-09-27 13:01:01 +08:00
void MainWindow : : saveLastOpens ( )
{
2021-09-27 20:17:24 +08:00
QString filename = includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) ) + DEV_LASTOPENS_FILE ;
if ( fileExists ( filename ) ) {
if ( ! QFile : : remove ( filename ) ) {
QMessageBox : : critical ( this ,
tr ( " Save last open info error " ) ,
tr ( " Can't remove old last open information file '%1' " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
return ;
}
2021-09-27 13:01:01 +08:00
2021-09-27 20:17:24 +08:00
}
SimpleIni lastOpenIni ;
lastOpenIni . SetLongValue ( " LastOpens " , " Count " , mEditorList - > pageCount ( ) ) ;
if ( mProject ) {
lastOpenIni . SetValue ( " LastOpens " , " Project " , mProject - > filename ( ) . toLocal8Bit ( ) ) ;
}
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * editor = ( * mEditorList ) [ i ] ;
QByteArray sectionName = QString ( " Editor_%1 " ) . arg ( i ) . toLocal8Bit ( ) ;
lastOpenIni . SetValue ( sectionName , " FileName " , editor - > filename ( ) . toLocal8Bit ( ) ) ;
2021-10-20 18:05:43 +08:00
lastOpenIni . SetBoolValue ( sectionName , " OnLeft " , editor - > pageControl ( ) ! = mEditorList - > rightPageWidget ( ) ) ;
2021-09-27 20:17:24 +08:00
lastOpenIni . SetBoolValue ( sectionName , " Focused " , editor - > hasFocus ( ) ) ;
lastOpenIni . SetLongValue ( sectionName , " CursorCol " , editor - > caretX ( ) ) ;
lastOpenIni . SetLongValue ( sectionName , " CursorRow " , editor - > caretY ( ) ) ;
lastOpenIni . SetLongValue ( sectionName , " TopLine " , editor - > topLine ( ) ) ;
lastOpenIni . SetLongValue ( sectionName , " LeftChar " , editor - > leftChar ( ) ) ;
}
if ( lastOpenIni . SaveFile ( filename . toLocal8Bit ( ) ) ! = SI_Error : : SI_OK ) {
QMessageBox : : critical ( this ,
tr ( " Save last open info error " ) ,
tr ( " Can't save last open info file '%1' " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
return ;
}
2021-09-27 13:01:01 +08:00
}
void MainWindow : : loadLastOpens ( )
{
2021-09-27 20:17:24 +08:00
QString filename = includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) ) + DEV_LASTOPENS_FILE ;
if ( ! fileExists ( filename ) )
return ;
SimpleIni lastOpenIni ;
if ( lastOpenIni . LoadFile ( filename . toLocal8Bit ( ) ) ! = SI_Error : : SI_OK ) {
QMessageBox : : critical ( this ,
tr ( " Load last open info error " ) ,
tr ( " Can't load last open info file '%1' " )
. arg ( filename ) ,
QMessageBox : : Ok ) ;
return ;
}
Editor * focusedEditor = nullptr ;
int count = lastOpenIni . GetLongValue ( " LastOpens " , " Count " , 0 ) ;
for ( int i = 0 ; i < count ; i + + ) {
QByteArray sectionName = QString ( " Editor_%1 " ) . arg ( i ) . toLocal8Bit ( ) ;
2021-09-29 19:03:22 +08:00
QString editorFilename = QString : : fromLocal8Bit ( lastOpenIni . GetValue ( sectionName , " FileName " , " " ) ) ;
2021-09-27 20:17:24 +08:00
if ( ! fileExists ( editorFilename ) )
continue ;
2021-10-23 17:32:03 +08:00
editorFilename = QFileInfo ( editorFilename ) . absoluteFilePath ( ) ;
2021-09-27 20:17:24 +08:00
bool onLeft = lastOpenIni . GetBoolValue ( sectionName , " OnLeft " , true ) ;
2021-10-20 18:05:43 +08:00
QTabWidget * page ;
if ( onLeft )
page = mEditorList - > leftPageWidget ( ) ;
else
page = mEditorList - > rightPageWidget ( ) ;
Editor * editor = mEditorList - > newEditor ( editorFilename , ENCODING_AUTO_DETECT , false , false , page ) ;
2021-09-27 20:17:24 +08:00
if ( ! editor )
continue ;
BufferCoord pos ;
pos . Char = lastOpenIni . GetLongValue ( sectionName , " CursorCol " , 1 ) ;
pos . Line = lastOpenIni . GetLongValue ( sectionName , " CursorRow " , 1 ) ;
editor - > setCaretXY ( pos ) ;
editor - > setTopLine (
lastOpenIni . GetLongValue ( sectionName , " TopLine " , 1 )
) ;
editor - > setLeftChar (
lastOpenIni . GetLongValue ( sectionName , " LeftChar " , 1 )
) ;
if ( lastOpenIni . GetBoolValue ( sectionName , " Focused " , false ) )
focusedEditor = editor ;
pSettings - > history ( ) . removeFile ( editorFilename ) ;
}
2021-09-29 19:03:22 +08:00
QString projectFilename = QString : : fromLocal8Bit ( ( lastOpenIni . GetValue ( " LastOpens " , " Project " , " " ) ) ) ;
2021-09-27 20:17:24 +08:00
if ( fileExists ( projectFilename ) ) {
2021-09-29 19:03:22 +08:00
openProject ( projectFilename ) ;
2021-09-27 20:17:24 +08:00
} else {
updateEditorActions ( ) ;
updateForEncodingInfo ( ) ;
}
2021-09-28 10:01:13 +08:00
if ( focusedEditor )
2021-09-27 20:17:24 +08:00
focusedEditor - > activate ( ) ;
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 ( ) ) {
QAction * action = new QAction ( item - > title , ui - > menuTools ) ;
connect ( action , & QAction : : triggered ,
2021-12-09 08:10:14 +08:00
[ item ] ( ) {
if ( item - > pauseAfterExit
& & programHasConsole ( parseMacros ( item - > program ) ) ) {
executeFile (
includeTrailingPathDelimiter ( pSettings - > dirs ( ) . app ( ) ) + " ConsolePauser.exe " ,
" 0 \" " + parseMacros ( item - > program ) + " \" " + parseMacros ( item - > parameters ) ,
parseMacros ( item - > workingDirectory ) ) ;
} else {
executeFile (
2021-10-08 00:06:41 +08:00
parseMacros ( item - > program ) ,
2021-12-09 08:10:14 +08:00
parseMacros ( item - > parameters ) ,
parseMacros ( item - > workingDirectory ) ) ;
}
2021-10-08 00:06:41 +08:00
} ) ;
ui - > menuTools - > addAction ( action ) ;
}
}
}
2021-10-03 09:57:19 +08:00
void MainWindow : : newEditor ( )
{
try {
2021-10-24 15:17:31 +08:00
Editor * editor = mEditorList - > newEditor ( " " ,
pSettings - > editor ( ) . useUTF8ByDefault ( ) ? ENCODING_UTF8 : ENCODING_AUTO_DETECT ,
false , true ) ;
2021-10-03 09:57:19 +08:00
editor - > activate ( ) ;
updateForEncodingInfo ( ) ;
} catch ( FileError e ) {
QMessageBox : : critical ( this , tr ( " Error " ) , e . reason ( ) ) ;
}
}
2021-08-31 11:13:12 +08:00
void MainWindow : : buildContextMenus ( )
{
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 ) ;
mProblem_Properties = createActionFor (
tr ( " Properties... " ) ,
ui - > lstProblemSet
) ;
connect ( mProblem_Properties , & QAction : : triggered ,
[ this ] ( ) {
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( ! idx . isValid ( ) )
return ;
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
if ( ! problem )
return ;
OJProblemPropertyWidget dialog ;
dialog . setName ( problem - > name ) ;
dialog . setUrl ( problem - > url ) ;
dialog . setDescription ( problem - > description ) ;
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
problem - > url = dialog . url ( ) ;
problem - > description = dialog . description ( ) ;
if ( problem = = mOJProblemModel . problem ( ) ) {
ui - > lblProblem - > setText ( mOJProblemModel . getTitle ( ) ) ;
ui - > lblProblem - > setToolTip ( mOJProblemModel . getTooltip ( ) ) ;
}
}
} ) ;
2021-09-05 13:51:07 +08:00
2021-11-06 16:22:26 +08:00
//context menu signal for the Problem Set lable
ui - > lblProblemSet - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > lblProblemSet , & QWidget : : customContextMenuRequested ,
[ this ] {
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 ( ) ) ;
}
} ) ;
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 ) ;
mBookmark_Remove = createActionFor (
tr ( " Remove " ) ,
ui - > tableBookmark ) ;
connect ( mBookmark_Remove , & QAction : : triggered ,
[ this ] ( ) {
QModelIndex index = ui - > tableBookmark - > currentIndex ( ) ;
if ( index . isValid ( ) ) {
2021-10-21 19:33:11 +08:00
PBookmark bookmark = mBookmarkModel - > bookmark ( index . row ( ) ) ;
if ( bookmark ) {
Editor * editor = mEditorList - > getOpenedEditorByFilename ( bookmark - > filename ) ;
if ( editor ) {
editor - > removeBookmark ( bookmark - > line ) ;
} else {
mBookmarkModel - > removeBookmarkAt ( index . row ( ) ) ;
}
}
2021-10-21 17:31:25 +08:00
}
} ) ;
mBookmark_RemoveAll = createActionFor (
2021-10-23 16:18:02 +08:00
tr ( " Remove All Bookmarks " ) ,
2021-10-21 17:31:25 +08:00
ui - > tableBookmark ) ;
connect ( mBookmark_RemoveAll , & QAction : : triggered ,
[ this ] ( ) {
mBookmarkModel - > clear ( ) ;
2021-10-21 19:33:11 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * editor = ( * mEditorList ) [ i ] ;
editor - > clearBookmarks ( ) ;
}
2021-10-21 17:31:25 +08:00
} ) ;
mBookmark_Modify = createActionFor (
tr ( " Modify Description " ) ,
ui - > tableBookmark ) ;
connect ( mBookmark_Modify , & QAction : : triggered ,
[ this ] ( ) {
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 ) ;
2021-10-21 19:33:11 +08:00
desc = desc . trimmed ( ) ;
mBookmarkModel - > updateDescription ( bookmark - > filename , bookmark - > line , desc ) ;
}
2021-10-21 17:31:25 +08:00
}
} ) ;
2021-10-02 17:01:08 +08:00
//context menu signal for the watch view
ui - > debugConsole - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > debugConsole , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onDebugConsoleContextMenu ) ;
2021-11-25 10:18:21 +08:00
mDebugConsole_ShowDetailLog = createActionFor (
tr ( " Show detail debug logs " ) ,
2021-10-02 17:01:08 +08:00
ui - > debugConsole ) ;
2021-11-25 10:18:21 +08:00
mDebugConsole_ShowDetailLog - > setCheckable ( true ) ;
connect ( mDebugConsole_ShowDetailLog , & QAction : : toggled ,
2021-10-02 17:01:08 +08:00
[ this ] ( ) {
2021-11-25 10:18:21 +08:00
pSettings - > debugger ( ) . setShowDetailLog ( mDebugConsole_ShowDetailLog - > isChecked ( ) ) ;
2021-10-02 17:01:08 +08:00
pSettings - > debugger ( ) . save ( ) ;
} ) ;
mDebugConsole_Copy = createActionFor (
tr ( " Copy " ) ,
ui - > debugConsole ,
QKeySequence ( " Ctrl+C " ) ) ;
connect ( mDebugConsole_Copy , & QAction : : triggered ,
[ this ] ( ) {
ui - > debugConsole - > copy ( ) ;
} ) ;
mDebugConsole_Paste = createActionFor (
tr ( " Paste " ) ,
ui - > debugConsole ,
QKeySequence ( " Ctrl+V " ) ) ;
connect ( mDebugConsole_Paste , & QAction : : triggered ,
[ this ] ( ) {
ui - > debugConsole - > paste ( ) ;
} ) ;
mDebugConsole_SelectAll = createActionFor (
tr ( " Select All " ) ,
2021-10-02 17:38:29 +08:00
ui - > debugConsole ) ;
2021-10-02 17:01:08 +08:00
connect ( mDebugConsole_SelectAll , & QAction : : triggered ,
[ this ] ( ) {
ui - > debugConsole - > selectAll ( ) ;
} ) ;
mDebugConsole_Clear = createActionFor (
tr ( " Clear " ) ,
ui - > debugConsole ) ;
connect ( mDebugConsole_Clear , & QAction : : triggered ,
[ this ] ( ) {
ui - > debugConsole - > clear ( ) ;
} ) ;
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 ) ;
mTableIssuesCopyAction = createActionFor (
tr ( " Copy " ) ,
ui - > tableIssues ,
QKeySequence ( " Ctrl+C " ) ) ;
connect ( mTableIssuesCopyAction , & QAction : : triggered ,
[ this ] ( ) {
QModelIndex index = ui - > tableIssues - > selectionModel ( ) - > currentIndex ( ) ;
PCompileIssue issue = ui - > tableIssues - > issue ( index ) ;
if ( issue ) {
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( issue - > description ) ;
}
} ) ;
mTableIssuesCopyAllAction = createActionFor (
tr ( " Copy all " ) ,
ui - > tableIssues ,
QKeySequence ( " Ctrl+Shift+C " ) ) ;
connect ( mTableIssuesCopyAllAction , & QAction : : triggered ,
[ this ] ( ) {
2021-09-05 19:10:54 +08:00
QClipboard * clipboard = QGuiApplication : : clipboard ( ) ;
QMimeData * mimeData = new QMimeData ( ) ;
mimeData - > setText ( ui - > tableIssues - > toTxt ( ) ) ;
mimeData - > setHtml ( ui - > tableIssues - > toHtml ( ) ) ;
clipboard - > clear ( ) ;
clipboard - > setMimeData ( mimeData ) ;
2021-09-05 13:51:07 +08:00
} ) ;
mTableIssuesClearAction = createActionFor (
tr ( " Clear " ) ,
ui - > tableIssues ) ;
connect ( mTableIssuesClearAction , & QAction : : triggered ,
[ this ] ( ) {
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-09-05 13:51:07 +08:00
} ) ;
2021-09-05 21:05:38 +08:00
//context menu signal for search view
ui - > searchHistoryPanel - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > searchHistoryPanel , & QWidget : : customContextMenuRequested ,
this , & MainWindow : : onSearchViewContextMenu ) ;
mSearchViewClearAction = createActionFor (
tr ( " Remove this search " ) ,
ui - > searchHistoryPanel ) ;
connect ( mSearchViewClearAction , & QAction : : triggered ,
[ this ] ( ) {
int index = ui - > cbSearchHistory - > currentIndex ( ) ;
if ( index > = 0 ) {
mSearchResultModel . removeSearchResults ( index ) ;
}
} ) ;
mSearchViewClearAllAction = createActionFor (
tr ( " Clear all searches " ) ,
ui - > searchHistoryPanel ) ;
connect ( mSearchViewClearAllAction , & QAction : : triggered ,
[ this ] ( ) {
mSearchResultModel . clear ( ) ;
} ) ;
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 ) ;
mBreakpointViewPropertyAction = createActionFor (
tr ( " Breakpoint condition... " ) ,
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewPropertyAction , & QAction : : triggered ,
[ this ] ( ) {
int index = ui - > tblBreakpoints - > selectionModel ( ) - > currentIndex ( ) . row ( ) ;
PBreakpoint breakpoint = debugger ( ) - > breakpointModel ( ) - > breakpoint (
index
) ;
if ( breakpoint ) {
bool isOk ;
QString s = QInputDialog : : getText ( this ,
tr ( " Break point condition " ) ,
tr ( " Enter the condition of the breakpoint: " ) ,
QLineEdit : : Normal ,
breakpoint - > condition , & isOk ) ;
if ( isOk ) {
pMainWindow - > debugger ( ) - > setBreakPointCondition ( index , s ) ;
}
}
} ) ;
mBreakpointViewRemoveAllAction = createActionFor (
2021-10-23 16:18:02 +08:00
tr ( " Remove All Breakpoints " ) ,
2021-09-05 22:16:54 +08:00
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewRemoveAllAction , & QAction : : triggered ,
2021-10-27 16:58:30 +08:00
[ this ] ( ) {
2021-09-05 22:16:54 +08:00
pMainWindow - > debugger ( ) - > deleteBreakpoints ( ) ;
2021-10-27 16:58:30 +08:00
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * ( mEditorList ) ) [ i ] ;
if ( e ) {
e - > resetBreakpoints ( ) ;
}
}
} ) ;
mBreakpointViewRemoveAction = createActionFor (
tr ( " Remove Breakpoint " ) ,
ui - > tblBreakpoints ) ;
connect ( mBreakpointViewRemoveAction , & QAction : : triggered ,
[ this ] ( ) {
int index = ui - > tblBreakpoints - > selectionModel ( ) - > currentIndex ( ) . row ( ) ;
PBreakpoint breakpoint = debugger ( ) - > breakpointModel ( ) - > breakpoint ( index ) ;
if ( breakpoint ) {
Editor * e = mEditorList - > getOpenedEditorByFilename ( breakpoint - > filename ) ;
if ( e ) {
if ( e - > hasBreakpoint ( breakpoint - > line ) )
e - > toggleBreakpoint ( breakpoint - > line ) ;
} else {
debugger ( ) - > breakpointModel ( ) - > removeBreakpoint ( index ) ;
}
}
2021-09-05 22:16:54 +08:00
} ) ;
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 ) ;
mProject_Rename_Unit = createActionFor (
tr ( " Rename File " ) ,
ui - > projectView ) ;
connect ( mProject_Rename_Unit , & QAction : : triggered ,
[ this ] ( ) {
2021-09-18 10:47:35 +08:00
if ( ui - > projectView - > currentIndex ( ) . isValid ( ) )
ui - > projectView - > edit ( ui - > projectView - > currentIndex ( ) ) ;
2021-09-17 22:58:58 +08:00
} ) ;
mProject_Add_Folder = createActionFor (
tr ( " Add Folder " ) ,
ui - > projectView ) ;
connect ( mProject_Add_Folder , & QAction : : triggered ,
[ this ] ( ) {
2021-09-18 10:47:35 +08:00
if ( ! mProject )
return ;
QModelIndex current = ui - > projectView - > currentIndex ( ) ;
if ( ! current . isValid ( ) ) {
return ;
}
FolderNode * node = static_cast < FolderNode * > ( current . internalPointer ( ) ) ;
PFolderNode folderNode = mProject - > pointerToNode ( node ) ;
if ( ! folderNode )
folderNode = mProject - > node ( ) ;
if ( folderNode - > unitIndex > = 0 )
return ;
QString s = tr ( " New folder " ) ;
bool ok ;
s = QInputDialog : : getText ( ui - > projectView ,
tr ( " Add Folder " ) ,
tr ( " Folder name: " ) ,
QLineEdit : : Normal , s ,
& ok ) . trimmed ( ) ;
if ( ok & & ! s . isEmpty ( ) ) {
QString path = mProject - > getFolderPath ( folderNode ) ;
if ( path . isEmpty ( ) ) {
mProject - > addFolder ( s ) ;
} else {
mProject - > addFolder ( path + ' / ' + s ) ;
}
mProject - > saveOptions ( ) ;
}
2021-09-17 22:58:58 +08:00
} ) ;
mProject_Rename_Folder = createActionFor (
2021-09-18 10:47:35 +08:00
tr ( " Rename Folder " ) ,
2021-09-17 22:58:58 +08:00
ui - > projectView ) ;
connect ( mProject_Rename_Folder , & QAction : : triggered ,
[ this ] ( ) {
2021-09-18 10:47:35 +08:00
if ( ui - > projectView - > currentIndex ( ) . isValid ( ) )
ui - > projectView - > edit ( ui - > projectView - > currentIndex ( ) ) ;
2021-09-17 22:58:58 +08:00
} ) ;
mProject_Remove_Folder = createActionFor (
2021-09-18 10:47:35 +08:00
tr ( " Remove Folder " ) ,
2021-09-17 22:58:58 +08:00
ui - > projectView ) ;
connect ( mProject_Remove_Folder , & QAction : : triggered ,
[ this ] ( ) {
2021-09-18 10:47:35 +08:00
if ( ! mProject )
return ;
QModelIndex current = ui - > projectView - > currentIndex ( ) ;
if ( ! current . isValid ( ) ) {
return ;
}
FolderNode * node = static_cast < FolderNode * > ( current . internalPointer ( ) ) ;
PFolderNode folderNode = mProject - > pointerToNode ( node ) ;
if ( ! folderNode )
return ;
if ( folderNode - > unitIndex > = 0 )
return ;
mProject - > removeFolder ( folderNode ) ;
mProject - > saveOptions ( ) ;
2021-09-17 22:58:58 +08:00
} ) ;
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 ) ;
mClassBrowser_Sort_By_Type = createActionFor (
tr ( " Sort By Type " ) ,
2021-09-26 16:25:17 +08:00
ui - > tabStructure ) ;
mClassBrowser_Sort_By_Type - > setCheckable ( true ) ;
2021-09-26 12:19:46 +08:00
mClassBrowser_Sort_By_Type - > setIcon ( QIcon ( " :/icons/images/newlook24/077-sort-type.png " ) ) ;
2021-09-26 16:25:17 +08:00
mClassBrowser_Sort_By_Name = createActionFor (
tr ( " Sort alphabetically " ) ,
ui - > tabStructure ) ;
mClassBrowser_Sort_By_Name - > setCheckable ( true ) ;
mClassBrowser_Sort_By_Name - > setIcon ( QIcon ( " :/icons/images/newlook24/076-sort-alpha.png " ) ) ;
mClassBrowser_Show_Inherited = createActionFor (
tr ( " Show inherited members " ) ,
ui - > tabStructure ) ;
mClassBrowser_Show_Inherited - > setCheckable ( true ) ;
mClassBrowser_Show_Inherited - > setIcon ( QIcon ( " :/icons/images/newlook24/075-show-inheritance.png " ) ) ;
mClassBrowser_goto_declaration = createActionFor (
tr ( " Goto declaration " ) ,
ui - > tabStructure ) ;
mClassBrowser_goto_definition = createActionFor (
tr ( " Goto definition " ) ,
ui - > tabStructure ) ;
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 ] ( ) {
pSettings - > ui ( ) . setClassBrowserSortAlpha ( mClassBrowser_Sort_By_Name - > isChecked ( ) ) ;
pSettings - > ui ( ) . save ( ) ;
mClassBrowserModel . fillStatements ( ) ;
} ) ;
connect ( mClassBrowser_Sort_By_Type , & QAction : : toggled ,
[ this ] ( ) {
pSettings - > ui ( ) . setClassBrowserSortType ( mClassBrowser_Sort_By_Type - > isChecked ( ) ) ;
pSettings - > ui ( ) . save ( ) ;
mClassBrowserModel . fillStatements ( ) ;
} ) ;
connect ( mClassBrowser_Show_Inherited , & QAction : : toggled ,
[ this ] ( ) {
pSettings - > ui ( ) . setClassBrowserShowInherited ( mClassBrowser_Show_Inherited - > isChecked ( ) ) ;
pSettings - > ui ( ) . save ( ) ;
mClassBrowserModel . fillStatements ( ) ;
} ) ;
connect ( mClassBrowser_goto_definition , & QAction : : triggered ,
[ this ] ( ) {
QModelIndex index = ui - > classBrowser - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
ClassBrowserNode * node = static_cast < ClassBrowserNode * > ( index . internalPointer ( ) ) ;
if ( ! node )
return ;
PStatement statement = node - > statement ;
if ( ! statement ) {
return ;
}
QString filename ;
int line ;
filename = statement - > definitionFileName ;
line = statement - > definitionLine ;
Editor * e = pMainWindow - > editorList ( ) - > getEditorByFilename ( filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( line , 1 ) ;
}
} ) ;
connect ( mClassBrowser_goto_declaration , & QAction : : triggered ,
[ this ] ( ) {
on_classBrowser_doubleClicked ( ui - > classBrowser - > currentIndex ( ) ) ;
} ) ;
//toolbar for class browser
mClassBrowserToolbar = new QWidget ( ) ;
2021-10-22 15:02:54 +08:00
{
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 ;
toolButton = new QToolButton ;
toolButton - > setDefaultAction ( mClassBrowser_Sort_By_Type ) ;
hlayout - > addWidget ( toolButton ) ;
toolButton = new QToolButton ;
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 - > setDefaultAction ( mClassBrowser_Show_Inherited ) ;
hlayout - > addWidget ( toolButton ) ;
hlayout - > addStretch ( ) ;
}
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 ) ;
mFilesView_Open = createActionFor (
tr ( " Open in Editor " ) ,
ui - > treeFiles ) ;
connect ( mFilesView_Open , & QAction : : triggered ,
[ this ] ( ) {
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
if ( ! path . isEmpty ( ) & & QFileInfo ( path ) . isFile ( ) ) {
Editor * editor = mEditorList - > getEditorByFilename ( path ) ;
if ( editor )
editor - > activate ( ) ;
}
} ) ;
mFilesView_OpenWithExternal = createActionFor (
tr ( " Open in External Program " ) ,
ui - > treeFiles ) ;
connect ( mFilesView_OpenWithExternal , & QAction : : triggered ,
[ this ] ( ) {
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
if ( ! path . isEmpty ( ) & & QFileInfo ( path ) . isFile ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( path ) ) ;
}
} ) ;
mFilesView_OpenInTerminal = createActionFor (
tr ( " Open in Terminal " ) ,
ui - > treeFiles ) ;
mFilesView_OpenInTerminal - > setIcon ( ui - > actionOpen_Terminal - > icon ( ) ) ;
connect ( mFilesView_OpenInTerminal , & QAction : : triggered ,
[ this ] ( ) {
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
if ( ! path . isEmpty ( ) ) {
QFileInfo fileInfo ( path ) ;
openShell ( fileInfo . path ( ) , " cmd.exe " ) ;
}
} ) ;
mFilesView_OpenInExplorer = createActionFor (
tr ( " Open in Windows Explorer " ) ,
ui - > treeFiles ) ;
mFilesView_OpenInExplorer - > setIcon ( ui - > actionOpen_Containing_Folder - > icon ( ) ) ;
connect ( mFilesView_OpenInExplorer , & QAction : : triggered ,
[ this ] ( ) {
QString path = mFileSystemModel . filePath ( ui - > treeFiles - > currentIndex ( ) ) ;
if ( ! path . isEmpty ( ) ) {
QFileInfo info ( path ) ;
if ( info . isFile ( ) ) {
QDesktopServices : : openUrl (
QUrl ( " file:/// " +
includeTrailingPathDelimiter ( info . path ( ) ) , QUrl : : TolerantMode ) ) ;
} else if ( info . isDir ( ) ) {
QDesktopServices : : openUrl (
QUrl ( " file:/// " +
includeTrailingPathDelimiter ( path ) , QUrl : : TolerantMode ) ) ;
}
}
} ) ;
//toolbar for files view
mFilesViewToolbar = new QWidget ( ) ;
{
QVBoxLayout * layout = dynamic_cast < QVBoxLayout * > ( ui - > tabFiles - > layout ( ) ) ;
layout - > insertWidget ( 0 , mFilesViewToolbar ) ;
QHBoxLayout * hlayout = new QHBoxLayout ( ) ;
hlayout - > setContentsMargins ( 2 , 2 , 2 , 2 ) ;
mFilesViewToolbar - > setLayout ( hlayout ) ;
QToolButton * toolButton ;
toolButton = new QToolButton ;
toolButton - > setDefaultAction ( ui - > actionOpen_Folder ) ;
toolButton - > setFixedSize ( 32 , 32 ) ;
hlayout - > addWidget ( toolButton ) ;
toolButton = new QToolButton ;
toolButton - > setDefaultAction ( ui - > actionLocate_in_Files_View ) ;
toolButton - > setFixedSize ( 32 , 32 ) ;
hlayout - > addWidget ( toolButton ) ;
hlayout - > addStretch ( ) ;
}
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 " ) ) ;
mMenuEncoding - > addAction ( ui - > actionAuto_Detect ) ;
mMenuEncoding - > addAction ( ui - > actionEncode_in_ANSI ) ;
mMenuEncoding - > addAction ( ui - > actionEncode_in_UTF_8 ) ;
mMenuEncoding - > addMenu ( menuCharsets ) ;
mMenuEncoding - > addSeparator ( ) ;
mMenuEncoding - > addAction ( ui - > actionConvert_to_ANSI ) ;
mMenuEncoding - > addAction ( ui - > actionConvert_to_UTF_8 ) ;
ui - > menuEdit - > insertMenu ( ui - > actionFoldAll , mMenuEncoding ) ;
ui - > menuEdit - > insertSeparator ( ui - > actionFoldAll ) ;
ui - > actionAuto_Detect - > setCheckable ( true ) ;
ui - > actionEncode_in_ANSI - > setCheckable ( true ) ;
ui - > actionEncode_in_UTF_8 - > setCheckable ( true ) ;
}
2021-09-02 20:12:16 +08:00
void MainWindow : : maximizeEditor ( )
{
if ( mLeftPanelOpenned | | mBottomPanelOpenned ) {
openCloseBottomPanel ( false ) ;
openCloseLeftPanel ( false ) ;
} else {
openCloseBottomPanel ( true ) ;
openCloseLeftPanel ( true ) ;
}
}
2021-09-03 16:39:20 +08:00
void MainWindow : : openShell ( const QString & folder , const QString & shellCommand )
{
QProcess process ;
process . setWorkingDirectory ( folder ) ;
process . setProgram ( shellCommand ) ;
process . setCreateProcessArgumentsModifier ( [ ] ( QProcess : : CreateProcessArguments * args ) {
args - > flags | = CREATE_NEW_CONSOLE ;
args - > startupInfo - > dwFlags & = ~ STARTF_USESTDHANDLES ; //
} ) ;
QProcessEnvironment env = QProcessEnvironment : : systemEnvironment ( ) ;
QString path = env . value ( " PATH " ) ;
2021-09-14 12:10:43 +08:00
QStringList pathAdded ;
2021-09-03 16:39:20 +08:00
if ( pSettings - > compilerSets ( ) . defaultSet ( ) ) {
foreach ( const QString & dir , pSettings - > compilerSets ( ) . defaultSet ( ) - > binDirs ( ) ) {
2021-09-14 12:10:43 +08:00
pathAdded . append ( dir ) ;
2021-09-03 16:39:20 +08:00
}
}
2021-09-14 12:10:43 +08:00
pathAdded . append ( pSettings - > dirs ( ) . app ( ) ) ;
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 ) ;
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 ;
int updateCount = 0 ;
switch ( pSettings - > editor ( ) . autoSaveTarget ( ) ) {
case astCurrentFile : {
Editor * e = mEditorList - > getEditor ( ) ;
doAutoSave ( e ) ;
updateCount + + ;
}
break ;
case astAllOpennedFiles :
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
doAutoSave ( e ) ;
updateCount + + ;
}
break ;
case astAllProjectFiles :
2021-10-17 21:09:50 +08:00
if ( ! mProject )
return ;
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( ! e - > inProject ( ) )
return ;
doAutoSave ( e ) ;
updateCount + + ;
}
2021-08-30 22:05:45 +08:00
//todo: auto save project files
break ;
}
updateStatusbarMessage ( tr ( " %1 files autosaved " ) . arg ( updateCount ) ) ;
}
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 ) ;
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 ;
int unitIndex = - 1 ;
QModelIndex current = ui - > projectView - > selectionModel ( ) - > currentIndex ( ) ;
if ( current . isValid ( ) & & mProject ) {
FolderNode * node = static_cast < FolderNode * > ( current . internalPointer ( ) ) ;
PFolderNode pNode = mProject - > pointerToNode ( node ) ;
if ( pNode ) {
unitIndex = pNode - > unitIndex ;
onFolder = ( unitIndex < 0 ) ;
onUnit = ( unitIndex > = 0 ) ;
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
}
}
QMenu menu ( this ) ;
updateProjectActions ( ) ;
menu . addAction ( ui - > actionProject_New_File ) ;
menu . addAction ( ui - > actionAdd_to_project ) ;
2021-09-18 10:47:35 +08:00
if ( ! onFolder ) {
menu . addAction ( ui - > actionRemove_from_project ) ;
}
2021-09-17 22:58:58 +08:00
if ( onUnit ) {
menu . addAction ( mProject_Rename_Unit ) ;
}
menu . addSeparator ( ) ;
if ( onFolder ) {
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 ( ) ;
2021-09-17 22:58:58 +08:00
menu . addAction ( ui - > actionProject_options ) ;
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 ) ;
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 )
{
QMenu menu ( this ) ;
menu . addAction ( ui - > actionOpen_Folder ) ;
menu . addSeparator ( ) ;
menu . addAction ( mFilesView_Open ) ;
menu . addAction ( mFilesView_OpenWithExternal ) ;
menu . addSeparator ( ) ;
menu . addAction ( mFilesView_OpenInTerminal ) ;
menu . addAction ( mFilesView_OpenInExplorer ) ;
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 ( ) ) ;
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 ( ) ) ;
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 ] ;
if ( e - > isNew ( ) )
continue ;
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 ] ( ) {
2021-11-14 18:48:18 +08:00
QFileDialog dialog ;
2021-11-06 14:49:11 +08:00
QString filename = QFileDialog : : getOpenFileName (
this ,
tr ( " Select Answer Source File " ) ,
QString ( ) ,
2021-11-14 18:48:18 +08:00
tr ( " C/C++Source Files (*.c *.cpp *.cc *.cxx) " ) ,
nullptr ,
dialog . options ( ) | QFileDialog : : DontUseNativeDialog ) ;
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 ) ;
}
menu . addAction ( mProblem_Properties ) ;
2021-11-04 09:07:06 +08:00
menu . exec ( ui - > lstProblemSet - > 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 ( ) ) {
ui - > btnRemoveProblem - > setEnabled ( false ) ;
2021-11-02 01:07:37 +08:00
mOJProblemModel . setProblem ( nullptr ) ;
ui - > txtProblemCaseExpected - > clear ( ) ;
ui - > txtProblemCaseInput - > clear ( ) ;
ui - > txtProblemCaseOutput - > clear ( ) ;
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 {
ui - > btnRemoveProblem - > setEnabled ( true ) ;
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
mOJProblemModel . setProblem ( problem ) ;
2021-11-02 09:29:35 +08:00
ui - > lblProblem - > setText ( mOJProblemModel . getTitle ( ) ) ;
2021-11-04 09:07:06 +08:00
ui - > lblProblem - > setToolTip ( mOJProblemModel . getTooltip ( ) ) ;
2021-11-27 15:43:47 +08:00
if ( mOJProblemModel . count ( ) > 0 ) {
ui - > lstProblemCases - > setCurrentIndex ( mOJProblemModel . index ( 0 , 0 ) ) ;
} else {
onProblemCaseIndexChanged ( QModelIndex ( ) , QModelIndex ( ) ) ;
}
2021-11-01 00:40:11 +08:00
openCloseBottomPanel ( true ) ;
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 ) {
ui - > btnRemoveProblemCase - > setEnabled ( true ) ;
ui - > txtProblemCaseInput - > setText ( problemCase - > input ) ;
ui - > txtProblemCaseInput - > setReadOnly ( false ) ;
ui - > txtProblemCaseExpected - > setText ( problemCase - > expected ) ;
ui - > txtProblemCaseExpected - > setReadOnly ( false ) ;
2021-11-02 19:26:11 +08:00
updateProblemCaseOutput ( problemCase ) ;
2021-11-01 00:40:11 +08:00
return ;
}
}
ui - > btnRemoveProblemCase - > setEnabled ( false ) ;
ui - > txtProblemCaseInput - > clear ( ) ;
ui - > txtProblemCaseInput - > setReadOnly ( true ) ;
ui - > txtProblemCaseExpected - > clear ( ) ;
ui - > txtProblemCaseExpected - > setReadOnly ( true ) ;
ui - > txtProblemCaseOutput - > clear ( ) ;
}
2021-11-02 01:07:37 +08:00
void MainWindow : : onProblemNameChanged ( int index )
{
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( idx . isValid ( ) & & index = = idx . row ( ) ) {
POJProblem problem = mOJProblemSetModel . problem ( idx . row ( ) ) ;
2021-11-02 09:29:35 +08:00
ui - > lblProblem - > setText ( mOJProblemModel . getTitle ( ) ) ;
2021-11-04 09:07:06 +08:00
ui - > lblProblem - > setToolTip ( mOJProblemModel . getTooltip ( ) ) ;
2021-11-02 01:07:37 +08:00
}
}
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 ) ;
problemCase - > input = caseObj [ " input " ] . toString ( ) ;
problemCase - > expected = caseObj [ " output " ] . toString ( ) ;
problem - > cases . append ( problemCase ) ;
}
mOJProblemSetModel . addProblem ( problem ) ;
2021-11-06 10:58:18 +08:00
ui - > tabInfos - > setCurrentWidget ( ui - > tabProblemSet ) ;
ui - > lstProblemSet - > setCurrentIndex ( mOJProblemSetModel . index (
mOJProblemSetModel . count ( ) - 1
, 0 ) ) ;
showNormal ( ) ;
raise ( ) ; // for mac OS?
activateWindow ( ) ;
2021-11-02 09:29:35 +08:00
}
}
2021-11-02 23:47:51 +08:00
void MainWindow : : onEditorClosed ( )
{
if ( mQuitting )
return ;
updateEditorActions ( ) ;
updateAppTitle ( ) ;
}
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 ;
}
}
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 ;
QMenu menu ( this ) ;
2021-09-03 10:30:08 +08:00
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 ) ) {
2021-10-21 17:31:25 +08:00
line = p . Line ;
2021-09-03 10:30:08 +08:00
//mouse on editing area
menu . addAction ( ui - > actionCompile_Run ) ;
menu . addAction ( ui - > actionDebug ) ;
menu . addSeparator ( ) ;
2021-09-03 11:50:04 +08:00
menu . addAction ( ui - > actionGoto_Declaration ) ;
menu . addAction ( ui - > actionGoto_Definition ) ;
menu . addAction ( ui - > actionFind_references ) ;
2021-09-03 16:39:20 +08:00
menu . addSeparator ( ) ;
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 ( ) ;
menu . addAction ( ui - > actionReformat_Code ) ;
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionCut ) ;
menu . addAction ( ui - > actionCopy ) ;
menu . addAction ( ui - > actionPaste ) ;
menu . addAction ( ui - > actionSelectAll ) ;
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionAdd_Watch ) ;
menu . addAction ( ui - > actionToggle_Breakpoint ) ;
menu . addAction ( ui - > actionClear_all_breakpoints ) ;
2021-09-04 00:13:42 +08:00
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 ( ) ;
2021-09-04 00:13:42 +08:00
menu . addAction ( ui - > actionFile_Properties ) ;
2021-09-03 20:55:14 +08:00
2021-09-03 16:39:20 +08:00
//these actions needs parser
ui - > actionGoto_Declaration - > setEnabled ( ! editor - > parser ( ) - > parsing ( ) ) ;
ui - > actionGoto_Definition - > setEnabled ( ! editor - > parser ( ) - > parsing ( ) ) ;
ui - > actionFind_references - > setEnabled ( ! editor - > parser ( ) - > parsing ( ) ) ;
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 ;
menu . addAction ( ui - > actionToggle_Breakpoint ) ;
menu . addAction ( ui - > actionBreakpoint_property ) ;
menu . addAction ( ui - > actionClear_all_breakpoints ) ;
2021-10-21 17:31:25 +08:00
menu . addSeparator ( ) ;
menu . addAction ( ui - > actionAdd_bookmark ) ;
menu . addAction ( ui - > actionRemove_Bookmark ) ;
menu . addAction ( ui - > actionModify_Bookmark_Description ) ;
}
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 (
line > = 0 & & editor - > lines ( ) - > 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 ( ) ;
2021-09-05 05:01:31 +08:00
menu . addAction ( ui - > actionClose ) ;
menu . addAction ( ui - > actionClose_All ) ;
menu . addSeparator ( ) ;
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-13 11:32:59 +08:00
ui - > actionMove_To_Other_View - > setEnabled (
tabWidget = = ui - > EditorTabsRight
| | tabWidget - > count ( ) > 1
) ;
2021-10-22 15:02:54 +08:00
Editor * editor = dynamic_cast < Editor * > ( tabWidget - > widget ( index ) ) ;
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 ( )
{
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 ) ;
ui - > cbEvaluate - > setEnabled ( false ) ;
2021-09-29 22:55:53 +08:00
ui - > cbMemoryAddress - > setEnabled ( false ) ;
2021-09-19 14:28:30 +08:00
}
void MainWindow : : enableDebugActions ( )
{
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 ( ) ) ;
ui - > actionContinue - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > cbEvaluate - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
ui - > cbMemoryAddress - > setEnabled ( ! mDebugger - > inferiorRunning ( ) ) ;
2021-09-19 14:28:30 +08:00
}
2021-11-02 19:26:11 +08:00
void MainWindow : : onTodoParseStarted ( const QString & )
2021-10-03 17:18:43 +08:00
{
mTodoModel . clear ( ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onTodoParsing ( 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 ( )
{
}
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 ) ;
} ) ;
// TODO: should we save watches?
if ( mProject - > modified ( ) ) {
QString s ;
if ( mProject - > name ( ) . isEmpty ( ) ) {
s = mProject - > filename ( ) ;
} else {
s = mProject - > name ( ) ;
}
if ( mSystemTurnedOff ) {
mProject - > saveAll ( ) ;
} else {
int answer = QMessageBox : : question (
this ,
tr ( " Save project " ) ,
tr ( " The project '%1' has modifications. " ) . arg ( s )
+ " <br /> "
+ tr ( " Do you want to save it? " ) ,
QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : Cancel ,
QMessageBox : : Yes ) ;
switch ( answer ) {
case QMessageBox : : Yes :
mProject - > saveAll ( ) ;
break ;
case QMessageBox : : No :
mProject - > setModified ( false ) ;
mProject - > saveLayout ( ) ;
break ;
case QMessageBox : : Cancel :
mProject - > saveLayout ( ) ;
return ;
}
}
} else
mProject - > saveLayout ( ) ; // always save layout, but not when SaveAll has been called
mClassBrowserModel . beginUpdate ( ) ;
{
auto action2 = finally ( [ this ] {
mClassBrowserModel . endUpdate ( ) ;
} ) ;
// Remember it
pSettings - > history ( ) . addToOpenedProjects ( mProject - > filename ( ) ) ;
mEditorList - > beginUpdate ( ) ;
{
auto action3 = finally ( [ this ] {
mEditorList - > endUpdate ( ) ;
} ) ;
mProject . reset ( ) ;
if ( ! mQuitting & & refreshEditor ) {
//reset Class browsing
ui - > tabInfos - > setCurrentWidget ( ui - > tabStructure ) ;
Editor * e = mEditorList - > getEditor ( ) ;
updateClassBrowserForEditor ( e ) ;
} else {
mClassBrowserModel . setParser ( nullptr ) ;
mClassBrowserModel . setCurrentFile ( " " ) ;
}
}
}
if ( ! mQuitting ) {
// Clear error browser
2021-10-25 09:31:58 +08:00
clearIssues ( ) ;
2021-09-17 09:56:52 +08:00
updateProjectView ( ) ;
2021-09-11 18:42:49 +08:00
}
}
}
2021-09-17 09:56:52 +08:00
void MainWindow : : updateProjectView ( )
{
if ( mProject ) {
ui - > projectView - > setModel ( mProject - > model ( ) ) ;
2021-09-18 10:47:35 +08:00
connect ( mProject - > model ( ) , & QAbstractItemModel : : modelReset ,
ui - > projectView , & QTreeView : : expandAll ) ;
2021-09-17 13:35:50 +08:00
ui - > projectView - > expandAll ( ) ;
2021-09-17 09:56:52 +08:00
openCloseLeftPanel ( true ) ;
ui - > tabProject - > setVisible ( true ) ;
ui - > tabInfos - > setCurrentWidget ( ui - > tabProject ) ;
} else {
// Clear project browser
ui - > projectView - > setModel ( nullptr ) ;
ui - > tabProject - > setVisible ( false ) ;
}
updateProjectActions ( ) ;
}
2021-08-31 14:40:41 +08:00
void MainWindow : : onFileChanged ( const QString & path )
{
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 ( ) ) ;
}
}
} else {
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 ) ;
e - > updateCaption ( ) ;
}
2021-11-02 01:07:37 +08:00
mFileSystemWatcher . removePath ( e - > filename ( ) ) ;
2021-08-31 14:40:41 +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
}
2021-08-03 23:55:57 +08:00
SearchDialog * MainWindow : : searchDialog ( ) const
{
return mSearchDialog ;
}
2021-08-05 12:31:53 +08:00
SearchResultModel * MainWindow : : searchResultModel ( )
{
return & mSearchResultModel ;
}
2021-08-03 23:55:57 +08:00
EditorList * MainWindow : : editorList ( ) const
{
return mEditorList ;
}
2021-08-01 09:13:38 +08:00
Debugger * MainWindow : : debugger ( ) const
{
return mDebugger ;
}
2021-07-26 18:22:09 +08:00
CPUDialog * MainWindow : : cpuDialog ( ) const
2021-07-26 11:47:54 +08:00
{
return mCPUDialog ;
}
2021-04-07 21:13:15 +08:00
void MainWindow : : on_actionNew_triggered ( )
{
2021-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? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) {
newProjectUnitFile ( ) ;
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 ) ;
}
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 ) {
Settings : : UI & settings = pSettings - > ui ( ) ;
settings . setMainWindowState ( saveState ( ) ) ;
settings . setMainWindowGeometry ( saveGeometry ( ) ) ;
settings . setBottomPanelHeight ( mBottomPanelHeight ) ;
settings . setBottomPanelIndex ( ui - > tabMessages - > currentIndex ( ) ) ;
settings . setBottomPanelOpenned ( mBottomPanelOpenned ) ;
settings . setLeftPanelWidth ( mLeftPanelWidth ) ;
settings . setLeftPanelIndex ( ui - > tabInfos - > currentIndex ( ) ) ;
settings . setLeftPanelOpenned ( mLeftPanelOpenned ) ;
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 ( ) ) ;
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 ( ) ) ;
2021-10-08 20:01:29 +08:00
settings . save ( ) ;
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 ( ) ;
2021-10-22 07:42:51 +08:00
try {
mBookmarkModel - > save ( 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 ( ) ) ;
}
if ( pSettings - > debugger ( ) . autosaveBreakpoints ( ) ) {
try {
mDebugger - > breakpointModel ( ) - > save ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_BREAKPOINTS_FILE ) ;
} 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 ( ) )
+ DEV_BREAKPOINTS_FILE ) ;
2021-10-22 07:42:51 +08:00
if ( pSettings - > debugger ( ) . autosaveWatches ( ) ) {
try {
mDebugger - > watchModel ( ) - > save ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . config ( ) )
+ DEV_WATCH_FILE ) ;
} 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 ( ) )
+ DEV_WATCH_FILE ) ;
2021-10-08 20:01:29 +08:00
}
if ( ! mShouldRemoveAllSettings & & pSettings - > editor ( ) . autoLoadLastFiles ( ) ) {
2021-09-27 20:17:24 +08:00
saveLastOpens ( ) ;
} else {
//if don't save last open files, close project before editors, to save project openned editors;
if ( mProject ) {
closeProject ( false ) ;
}
2021-09-27 13:01:01 +08:00
}
2021-06-10 09:34:59 +08:00
if ( ! mEditorList - > closeAll ( false ) ) {
2021-10-09 11:33:23 +08:00
mQuitting = false ;
2021-04-09 17:48:25 +08:00
event - > ignore ( ) ;
return ;
}
2021-10-08 20:01:29 +08:00
if ( ! mShouldRemoveAllSettings & & pSettings - > editor ( ) . autoLoadLastFiles ( ) ) {
2021-09-27 20:17:24 +08:00
if ( mProject ) {
closeProject ( false ) ;
}
}
2021-11-02 13:12:36 +08:00
mTcpServer . close ( ) ;
2021-09-26 19:40:52 +08:00
mCompilerManager - > stopCompile ( ) ;
mCompilerManager - > stopRun ( ) ;
2021-10-08 20:01:29 +08:00
if ( ! mShouldRemoveAllSettings )
mSymbolUsageManager - > save ( ) ;
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
{
const Settings : : UI & settings = pSettings - > ui ( ) ;
ui - > tabMessages - > setCurrentIndex ( settings . bottomPanelIndex ( ) ) ;
if ( settings . bottomPanelOpenned ( ) ) {
mBottomPanelHeight = settings . bottomPanelHeight ( ) ;
openCloseBottomPanel ( true ) ;
} else {
openCloseBottomPanel ( false ) ;
mBottomPanelHeight = settings . bottomPanelHeight ( ) ;
}
ui - > tabInfos - > setCurrentIndex ( settings . leftPanelIndex ( ) ) ;
if ( settings . leftPanelOpenned ( ) ) {
mLeftPanelWidth = settings . leftPanelWidth ( ) ;
openCloseLeftPanel ( true ) ;
} else {
openCloseLeftPanel ( false ) ;
mLeftPanelWidth = settings . leftPanelWidth ( ) ;
}
}
2021-10-31 09:21:38 +08:00
void MainWindow : : hideEvent ( QHideEvent * )
{
Settings : : UI & settings = pSettings - > ui ( ) ;
settings . setBottomPanelIndex ( ui - > tabMessages - > currentIndex ( ) ) ;
settings . setBottomPanelOpenned ( mBottomPanelOpenned ) ;
settings . setBottomPanelHeight ( mBottomPanelHeight ) ;
settings . setLeftPanelIndex ( ui - > tabInfos - > currentIndex ( ) ) ;
settings . setLeftPanelOpenned ( mLeftPanelOpenned ) ;
settings . setLeftPanelWidth ( mLeftPanelWidth ) ;
}
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 ( ) ;
if ( editor ! = NULL ) {
2021-06-20 09:27:37 +08:00
try {
editor - > save ( ) ;
2021-09-12 22:45:00 +08:00
if ( editor - > inProject ( ) & & ( mProject ) )
mProject - > saveAll ( ) ;
2021-06-20 09:27:37 +08:00
} catch ( FileError e ) {
2021-10-06 00:05:07 +08:00
QMessageBox : : critical ( editor , tr ( " Error " ) , e . reason ( ) ) ;
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 ( ) ;
if ( editor ! = NULL ) {
2021-06-20 09:27:37 +08:00
try {
editor - > saveAs ( ) ;
} catch ( FileError e ) {
2021-10-06 00:05:07 +08:00
QMessageBox : : critical ( editor , tr ( " Error " ) , e . reason ( ) ) ;
2021-06-20 09:27:37 +08:00
}
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 ;
2021-09-19 14:28:30 +08:00
if ( mProject ) {
Editor * e = mEditorList - > getEditor ( ) ;
if ( ! e | | e - > inProject ( ) ) {
2021-10-25 21:36:23 +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 ) {
return ;
}
mProject - > setCompilerSet ( index ) ;
2021-09-19 14:28:30 +08:00
mProject - > saveOptions ( ) ;
return ;
}
}
2021-04-18 11:41:41 +08:00
pSettings - > compilerSets ( ) . setDefaultIndex ( index ) ;
pSettings - > compilerSets ( ) . saveDefaultIndex ( ) ;
}
2021-04-20 22:24:33 +08:00
2021-11-24 10:07:35 +08:00
void MainWindow : : onCompileLog ( const QString & msg )
2021-04-20 22:24:33 +08:00
{
ui - > txtCompilerOutput - > appendPlainText ( msg ) ;
2021-10-09 11:33:23 +08:00
ui - > txtCompilerOutput - > moveCursor ( QTextCursor : : End ) ;
ui - > txtCompilerOutput - > moveCursor ( QTextCursor : : StartOfLine ) ;
2021-09-17 19:58:37 +08:00
ui - > txtCompilerOutput - > ensureCursorVisible ( ) ;
2021-04-20 22:24:33 +08:00
}
2021-04-24 15:57:45 +08:00
void MainWindow : : onCompileIssue ( PCompileIssue issue )
2021-04-20 22:24:33 +08:00
{
2021-04-24 15:57:45 +08:00
ui - > tableIssues - > addIssue ( issue ) ;
2021-06-23 22:38:02 +08:00
// Update tab caption
// if CompilerOutput.Items.Count = 1 then
// CompSheet.Caption := Lang[ID_SHEET_COMP] + ' (' + IntToStr(CompilerOutput.Items.Count) + ')';
if ( issue - > type = = CompileIssueType : : Error | | issue - > type = =
CompileIssueType : : Warning ) {
Editor * e = mEditorList - > getOpenedEditorByFilename ( issue - > filename ) ;
if ( e ! = nullptr & & ( issue - > line > 0 ) ) {
int line = issue - > line ;
if ( line > e - > lines ( ) - > count ( ) )
return ;
int col = std : : min ( issue - > column , e - > lines ( ) - > getString ( line - 1 ) . length ( ) + 1 ) ;
2021-06-24 16:05:19 +08:00
if ( col < 1 )
col = e - > lines ( ) - > getString ( line - 1 ) . length ( ) + 1 ;
e - > addSyntaxIssues ( line , col , issue - > endColumn , issue - > type , issue - > description ) ;
2021-06-23 22:38:02 +08:00
}
}
}
2021-09-19 14:28:30 +08:00
void MainWindow : : onCompileStarted ( )
{
ui - > txtCompilerOutput - > clear ( ) ;
}
2021-10-09 11:33:23 +08:00
void MainWindow : : onCompileFinished ( 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 ;
}
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
// Close it if there's nothing to show
2021-10-09 11:33:23 +08:00
if ( isCheckSyntax ) {
2021-06-23 22:38:02 +08:00
// check syntax in back, don't change message panel
} else if (
( ui - > tableIssues - > count ( ) = = 0 )
) {
2021-09-02 19:36:16 +08:00
openCloseBottomPanel ( false ) ;
2021-06-23 22:38:02 +08:00
// Or open it if there is anything to show
} else {
if ( ui - > tableIssues - > count ( ) > 0 ) {
if ( ui - > tabMessages - > currentIndex ( ) ! = i ) {
ui - > tabMessages - > setCurrentIndex ( i ) ;
}
2021-09-02 19:36:16 +08:00
openCloseBottomPanel ( true ) ;
2021-06-23 22:38:02 +08:00
}
}
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ! = nullptr ) {
2021-06-24 20:43:09 +08:00
e - > invalidate ( ) ;
2021-06-23 22:38:02 +08:00
}
2021-10-09 11:33:23 +08:00
if ( ! isCheckSyntax ) {
//run succession task if there aren't any errors
if ( mCompileSuccessionTask & & mCompilerManager - > compileErrorCount ( ) = = 0 ) {
switch ( mCompileSuccessionTask - > type ) {
2021-11-01 23:14:17 +08:00
case MainWindow : : CompileSuccessionTaskType : : RunNormal :
2021-10-09 11:33:23 +08:00
runExecutable ( mCompileSuccessionTask - > filename ) ;
break ;
2021-11-01 23:14:17 +08:00
case MainWindow : : CompileSuccessionTaskType : : RunProblemCases :
runExecutable ( mCompileSuccessionTask - > filename , QString ( ) , RunType : : ProblemCases ) ;
break ;
case MainWindow : : CompileSuccessionTaskType : : RunCurrentProblemCase :
runExecutable ( mCompileSuccessionTask - > filename , QString ( ) , RunType : : CurrentProblemCase ) ;
break ;
2021-10-09 11:33:23 +08:00
case MainWindow : : CompileSuccessionTaskType : : Debug :
debug ( ) ;
2021-09-04 21:33:10 +08:00
break ;
2021-10-20 18:05:43 +08:00
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 ) ) {
// First try to find errors
for ( int i = 0 ; i < ui - > tableIssues - > count ( ) ; i + + ) {
PCompileIssue issue = ui - > tableIssues - > issue ( i ) ;
if ( issue - > type = = CompileIssueType : : Error ) {
if ( e & & e - > filename ( ) ! = issue - > filename )
continue ;
ui - > tableIssues - > selectRow ( i ) ;
QModelIndex index = ui - > tableIssues - > model ( ) - > index ( i , 0 ) ;
emit ui - > tableIssues - > doubleClicked ( index ) ;
break ;
}
}
2021-06-23 22:38:02 +08:00
2021-10-09 11:33:23 +08:00
// Then try to find warnings
for ( int i = 0 ; i < ui - > tableIssues - > count ( ) ; i + + ) {
PCompileIssue issue = ui - > tableIssues - > issue ( i ) ;
if ( issue - > type = = CompileIssueType : : Warning ) {
if ( e & & e - > filename ( ) ! = issue - > filename )
continue ;
ui - > tableIssues - > selectRow ( i ) ;
QModelIndex index = ui - > tableIssues - > model ( ) - > index ( i , 0 ) ;
emit ui - > tableIssues - > doubleClicked ( index ) ;
}
2021-06-23 22:38:02 +08:00
}
}
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-11-01 20:44:08 +08:00
void MainWindow : : onRunProblemFinished ( )
{
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 ) ;
}
}
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 ;
2021-11-27 15:43:47 +08:00
problemCase - > testState = validator . validate ( problemCase , pSettings - > executor ( ) . ignoreSpacesWhenValidatingCases ( ) ) ?
2021-11-01 20:44:08 +08:00
ProblemCaseTestState : : Passed :
ProblemCaseTestState : : Failed ;
mOJProblemModel . update ( row ) ;
2021-11-01 23:37:54 +08:00
QModelIndex idx = ui - > lstProblemCases - > currentIndex ( ) ;
if ( idx . isValid ( ) ) {
2021-11-02 19:26:11 +08:00
if ( row = = idx . row ( ) ) {
updateProblemCaseOutput ( problemCase ) ;
}
2021-11-01 23:37:54 +08:00
}
2021-11-01 20:44:08 +08:00
}
ui - > pbProblemCases - > setMaximum ( total ) ;
ui - > pbProblemCases - > setValue ( current ) ;
2021-11-04 09:07:06 +08:00
// ui->lblProblem->setText(mOJProblemModel.getProblemTitle());
2021-11-01 20:44:08 +08:00
}
2021-08-01 23:24:37 +08:00
void MainWindow : : cleanUpCPUDialog ( )
{
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 ( ) ) {
2021-11-25 10:18:21 +08:00
mDebugger - > sendCommand ( 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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ;
if ( data - > hasUrls ( ) ) {
QStringList filesToOpen ;
foreach ( const QUrl & url , data - > urls ( ) ) {
QString s = url . toLocalFile ( ) ;
if ( ! s . isEmpty ( ) ) {
filesToOpen . append ( s ) ;
}
}
if ( ! filesToOpen . isEmpty ( ) )
openFiles ( filesToOpen ) ;
} else {
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ! = NULL ) {
editor - > pasteFromClipboard ( ) ;
2021-10-29 17:55:05 +08:00
editor - > activate ( ) ;
2021-10-04 20:05:24 +08:00
}
2021-04-21 23:06:55 +08:00
}
}
void MainWindow : : on_actionIndent_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ( ) ;
if ( editor ! = NULL ) {
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 ;
Editor * editor = mEditorList - > getEditorByFilename ( issue - > filename ) ;
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 )
{
2021-06-24 16:05:19 +08:00
if ( index = = ui - > tabMessages - > currentIndex ( ) ) {
2021-09-02 19:36:16 +08:00
openCloseBottomPanel ( ! mBottomPanelOpenned ) ;
2021-06-24 16:05:19 +08:00
}
}
2021-09-18 22:37:07 +08:00
void MainWindow : : on_tabMessages_currentChanged ( int )
2021-06-24 16:05:19 +08:00
{
2021-09-15 14:35:37 +08:00
openCloseBottomPanel ( true ) ;
2021-06-23 22:38:02 +08:00
}
2021-06-24 16:05:19 +08:00
2021-09-18 22:37:07 +08:00
void MainWindow : : on_tabMessages_tabBarDoubleClicked ( int )
2021-06-24 16:05:19 +08:00
{
}
2021-06-25 12:40:11 +08:00
void MainWindow : : on_actionCompile_Run_triggered ( )
{
2021-11-01 23:14:17 +08:00
doCompileRun ( RunType : : Normal ) ;
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 ;
if ( ! e - > inProject ( ) ) {
2021-08-29 10:14:07 +08:00
for ( const PBreakpoint & breakpoint : mDebugger - > breakpointModel ( ) - > breakpoints ( ) ) {
2021-07-25 13:03:46 +08:00
if ( e - > filename ( ) = = breakpoint - > filename ) {
return true ;
}
}
} else {
2021-08-29 10:14:07 +08:00
for ( const PBreakpoint & breakpoint : mDebugger - > breakpointModel ( ) - > breakpoints ( ) ) {
2021-07-25 13:03:46 +08:00
Editor * e1 = mEditorList - > getOpenedEditorByFilename ( breakpoint - > filename ) ;
2021-10-27 12:05:46 +08:00
if ( e1 & & e1 - > inProject ( ) ) {
2021-07-25 13:03:46 +08:00
return true ;
}
}
}
return false ;
}
2021-07-31 14:04:43 +08:00
void MainWindow : : on_actionStep_Over_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-next " , " " ) ;
2021-07-31 14:04:43 +08:00
}
}
void MainWindow : : on_actionStep_Into_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-step " , " " ) ;
2021-07-31 14:04:43 +08:00
}
}
void MainWindow : : on_actionStep_Out_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-finish " , " " ) ;
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();
2021-11-24 17:53:25 +08:00
mDebugger - > sendCommand ( " -exec-until " , QString ( " \" %1 \" :%2 " )
. arg ( e - > filename ( ) )
. arg ( e - > caretY ( ) ) ) ;
2021-07-31 14:04:43 +08:00
}
}
}
void MainWindow : : on_actionContinue_triggered ( )
{
if ( mDebugger - > executing ( ) ) {
//WatchView.Items.BeginUpdate();
2021-11-10 12:29:02 +08:00
mDebugger - > sendCommand ( " -exec-continue " , " " ) ;
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 ( ) ) {
2021-08-29 22:08:43 +08:00
connect ( mDebugger , & Debugger : : evalValueReady ,
this , & MainWindow : : onEvalValueReady ) ;
2021-11-24 22:16:40 +08:00
mDebugger - > sendCommand ( " -data-evaluate-expression " , s ) ;
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 ( ) ) {
connect ( mDebugger , & Debugger : : memoryExamineReady ,
this , & MainWindow : : onMemoryExamineReady ) ;
2021-11-24 22:16:40 +08:00
mDebugger - > sendCommand ( " -data-read-memory " , QString ( " %1 x 1 8 8 " ) . arg ( s ) ) ;
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 ) ;
disconnect ( mDebugger , & Debugger : : evalValueReady ,
this , & MainWindow : : onEvalValueReady ) ;
}
2021-11-24 10:07:35 +08:00
void MainWindow : : onMemoryExamineReady ( const QStringList & value )
2021-09-29 22:55:53 +08:00
{
ui - > txtMemoryView - > clear ( ) ;
foreach ( QString s , value ) {
s . replace ( " \t " , " " ) ;
ui - > txtMemoryView - > appendPlainText ( s ) ;
}
ui - > txtMemoryView - > moveCursor ( QTextCursor : : Start ) ;
disconnect ( mDebugger , & Debugger : : memoryExamineReady ,
this , & MainWindow : : onMemoryExamineReady ) ;
}
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 ;
if ( mSearchDialog = = nullptr ) {
mSearchDialog = new SearchDialog ( this ) ;
}
2021-09-20 15:57:48 +08:00
QString s = e - > wordAtCursor ( ) ;
2021-08-03 23:55:57 +08:00
mSearchDialog - > find ( s ) ;
}
void MainWindow : : on_actionFind_in_files_triggered ( )
{
2021-08-05 19:58:32 +08:00
if ( mSearchDialog = = nullptr ) {
mSearchDialog = new SearchDialog ( this ) ;
}
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
2021-09-20 15:57:48 +08:00
QString s = e - > wordAtCursor ( ) ;
2021-08-05 19:58:32 +08:00
mSearchDialog - > findInFiles ( s ) ;
} else {
mSearchDialog - > findInFiles ( " " ) ;
}
2021-08-03 23:55:57 +08:00
}
void MainWindow : : on_actionReplace_triggered ( )
{
2021-08-05 19:58:32 +08:00
Editor * e = mEditorList - > getEditor ( ) ;
if ( ! e )
return ;
if ( mSearchDialog = = nullptr ) {
mSearchDialog = new SearchDialog ( this ) ;
}
2021-09-20 15:57:48 +08:00
QString s = e - > wordAtCursor ( ) ;
2021-08-05 19:58:32 +08:00
mSearchDialog - > replace ( s , s ) ;
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 ) {
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
{
if ( mSearchDialog = = nullptr ) {
mSearchDialog = new SearchDialog ( this ) ;
}
PSearchResults results = mSearchResultModel . currentResults ( ) ;
2021-11-05 10:44:23 +08:00
if ( ! results )
return ;
if ( results - > searchType = = SearchType : : Search ) {
2021-08-05 19:58:32 +08:00
mSearchDialog - > findInFiles ( results - > keyword ,
results - > scope ,
results - > options ) ;
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 ( )
{
QModelIndex index = ui - > watchView - > currentIndex ( ) ;
QModelIndex parent ;
while ( true ) {
parent = ui - > watchView - > model ( ) - > parent ( index ) ;
if ( parent . isValid ( ) ) {
index = parent ;
} else {
break ;
}
}
mDebugger - > removeWatchVar ( index ) ;
}
void MainWindow : : on_actionRemove_All_Watches_triggered ( )
{
mDebugger - > removeWatchVars ( true ) ;
}
void MainWindow : : on_actionModify_Watch_triggered ( )
{
}
2021-09-02 12:14:02 +08:00
void MainWindow : : on_actionReformat_Code_triggered ( )
{
Editor * e = mEditorList - > getEditor ( ) ;
if ( e ) {
e - > reformat ( ) ;
e - > activate ( ) ;
}
}
CaretList & MainWindow : : caretList ( )
{
return mCaretList ;
}
void MainWindow : : updateCaretActions ( )
{
ui - > actionBack - > setEnabled ( mCaretList . hasPrevious ( ) ) ;
ui - > actionForward - > setEnabled ( mCaretList . hasNext ( ) ) ;
}
void MainWindow : : on_actionBack_triggered ( )
{
PEditorCaret caret = mCaretList . gotoAndGetPrevious ( ) ;
mCaretList . pause ( ) ;
if ( caret ) {
caret - > editor - > setCaretPositionAndActivate ( caret - > line , caret - > aChar ) ;
}
mCaretList . unPause ( ) ;
updateCaretActions ( ) ;
}
void MainWindow : : on_actionForward_triggered ( )
{
PEditorCaret caret = mCaretList . gotoAndGetNext ( ) ;
mCaretList . pause ( ) ;
if ( caret ) {
caret - > editor - > setCaretPositionAndActivate ( caret - > line , caret - > aChar ) ;
}
mCaretList . unPause ( ) ;
updateCaretActions ( ) ;
}
2021-09-02 19:36:16 +08:00
void MainWindow : : on_tabInfos_tabBarClicked ( int index )
{
if ( index = = ui - > tabInfos - > currentIndex ( ) ) {
openCloseLeftPanel ( ! mLeftPanelOpenned ) ;
}
}
void MainWindow : : on_splitterInfos_splitterMoved ( int , int )
{
2021-09-14 23:56:08 +08:00
QList < int > sizes = ui - > splitterInfos - > sizes ( ) ;
2021-09-02 19:36:16 +08:00
mLeftPanelWidth = sizes [ 0 ] ;
}
void MainWindow : : on_splitterMessages_splitterMoved ( int , int )
{
QList < int > sizes = ui - > splitterMessages - > sizes ( ) ;
mBottomPanelHeight = sizes [ 1 ] ;
}
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 ( )
{
mClosing = true ;
mEditorList - > closeAll ( mSystemTurnedOff ) ;
mClosing = false ;
}
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 ( ) ;
BufferCoord pos ;
2021-09-20 15:57:48 +08:00
if ( editor & & editor - > pointToCharLine ( mEditorContextMenuPos , pos ) ) {
2021-09-03 11:50:04 +08:00
editor - > gotoDeclaration ( pos ) ;
}
}
void MainWindow : : on_actionGoto_Definition_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
BufferCoord pos ;
2021-09-20 15:57:48 +08:00
if ( editor & & editor - > pointToCharLine ( mEditorContextMenuPos , pos ) ) {
2021-09-03 11:50:04 +08:00
editor - > gotoDefinition ( pos ) ;
}
}
2021-09-03 16:39:20 +08:00
void MainWindow : : on_actionFind_references_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
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 ) ;
2021-10-04 12:49:55 +08:00
showSearchPanel ( true ) ;
2021-09-03 16:39:20 +08:00
}
}
void MainWindow : : on_actionOpen_Containing_Folder_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
if ( editor ) {
QFileInfo info ( editor - > filename ( ) ) ;
if ( ! info . path ( ) . isEmpty ( ) ) {
2021-09-18 11:08:30 +08:00
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 ( ) ) {
openShell ( info . path ( ) , " cmd.exe " ) ;
}
}
}
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 ) ) {
Editor * e = mEditorList - > getEditorByFilename ( filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( line , start ) ;
}
}
}
void MainWindow : : on_tblStackTrace_doubleClicked ( const QModelIndex & index )
{
PTrace trace = mDebugger - > backtraceModel ( ) - > backtrace ( index . row ( ) ) ;
if ( trace ) {
Editor * e = mEditorList - > getEditorByFilename ( trace - > filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( trace - > line , 1 ) ;
}
}
}
void MainWindow : : on_tblBreakpoints_doubleClicked ( const QModelIndex & index )
{
PBreakpoint breakpoint = mDebugger - > breakpointModel ( ) - > breakpoint ( index . row ( ) ) ;
if ( breakpoint ) {
Editor * e = mEditorList - > getEditorByFilename ( breakpoint - > filename ) ;
if ( e ) {
e - > setCaretPositionAndActivate ( breakpoint - > line , 1 ) ;
}
}
}
2021-09-11 18:42:49 +08:00
std : : shared_ptr < Project > MainWindow : : project ( )
{
return mProject ;
}
2021-09-12 00:17:15 +08:00
void MainWindow : : on_projectView_doubleClicked ( const QModelIndex & index )
{
if ( ! index . isValid ( ) )
return ;
FolderNode * node = static_cast < FolderNode * > ( index . internalPointer ( ) ) ;
if ( ! node )
return ;
if ( node - > unitIndex > = 0 ) {
mProject - > openUnit ( node - > unitIndex ) ;
}
}
2021-09-12 01:01:34 +08:00
void MainWindow : : on_actionClose_Project_triggered ( )
{
mClosing = true ;
closeProject ( true ) ;
mClosing = false ;
}
2021-09-14 17:33:47 +08:00
void MainWindow : : on_actionProject_options_triggered ( )
{
if ( ! mProject )
return ;
QString oldName = mProject - > name ( ) ;
PSettingsDialog dialog = SettingsDialog : : projectOptionDialog ( ) ;
dialog - > exec ( ) ;
2021-10-25 21:59:01 +08:00
updateCompilerSet ( ) ;
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;
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-09-16 23:51:05 +08:00
tr ( " Red panda Dev-C++ project file (*.dev) " ) ) ;
if ( ! saveName . isEmpty ( ) ) {
s = saveName ;
}
}
// Create an empty project
mProject = std : : make_shared < Project > ( s , dialog . getProjectName ( ) ) ;
2021-12-03 21:36:12 +08:00
if ( ! mProject - > assignTemplate ( dialog . getTemplate ( ) , dialog . isCppProject ( ) ) ) {
2021-09-16 23:51:05 +08:00
mProject = nullptr ;
QMessageBox : : critical ( this ,
tr ( " New project fail " ) ,
tr ( " Can't assign project template " ) ,
QMessageBox : : Ok ) ;
}
mProject - > saveAll ( ) ;
2021-09-17 09:56:52 +08:00
updateProjectView ( ) ;
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 ) {
mProject - > saveAll ( ) ;
}
// Make changes to files
for ( int i = 0 ; i < mEditorList - > pageCount ( ) ; i + + ) {
Editor * e = ( * mEditorList ) [ i ] ;
if ( e - > modified ( ) & & ! e - > inProject ( ) ) {
if ( ! e - > save ( ) )
break ;
}
}
updateAppTitle ( ) ;
}
2021-09-17 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 ( ) ) {
QModelIndex current = ui - > projectView - > currentIndex ( ) ;
FolderNode * node = nullptr ;
if ( current . isValid ( ) ) {
node = static_cast < FolderNode * > ( current . internalPointer ( ) ) ;
}
PFolderNode folderNode = mProject - > pointerToNode ( node ) ;
foreach ( const QString & filename , dialog . selectedFiles ( ) ) {
mProject - > addUnit ( filename , folderNode , false ) ;
mProject - > cppParser ( ) - > addFileToScan ( filename ) ;
}
mProject - > rebuildNodes ( ) ;
2021-09-18 10:47:35 +08:00
mProject - > saveUnits ( ) ;
2021-09-17 13:35:50 +08:00
parseFileList ( mProject - > cppParser ( ) ) ;
updateProjectView ( ) ;
}
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 ;
mProject - > model ( ) - > beginUpdate ( ) ;
QSet < int > selected ;
foreach ( const QModelIndex & index , ui - > projectView - > selectionModel ( ) - > selectedIndexes ( ) ) {
if ( ! index . isValid ( ) )
continue ;
FolderNode * node = static_cast < FolderNode * > ( index . internalPointer ( ) ) ;
PFolderNode folderNode = mProject - > pointerToNode ( node ) ;
2021-09-17 19:58:37 +08:00
if ( ! folderNode )
2021-09-17 17:15:35 +08:00
continue ;
selected . insert ( folderNode - > unitIndex ) ;
} ;
2021-11-15 22:08:35 +08:00
bool removeFile = ( QMessageBox : : question ( this , tr ( " Remove file " ) ,
tr ( " Remove the file from disk? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : Yes ) ;
2021-09-17 17:15:35 +08:00
for ( int i = mProject - > units ( ) . count ( ) - 1 ; i > = 0 ; i - - ) {
if ( selected . contains ( i ) ) {
2021-11-15 22:08:35 +08:00
mProject - > removeUnit ( i , true , removeFile ) ;
2021-09-17 17:15:35 +08:00
}
}
2021-09-18 10:47:35 +08:00
mProject - > saveUnits ( ) ;
2021-09-17 17:15:35 +08:00
mProject - > model ( ) - > endUpdate ( ) ;
updateProjectView ( ) ;
}
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 ;
openShell ( mProject - > directory ( ) , " cmd.exe " ) ;
}
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 ;
filename = statement - > fileName ;
line = statement - > line ;
Editor * e = pMainWindow - > editorList ( ) - > getEditorByFilename ( filename ) ;
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-08 21:19:48 +08:00
void MainWindow : : updateEditorParser ( QTabWidget * tabWidget ) {
if ( mOpenningFiles )
return ;
Editor * editor = mEditorList - > getEditor ( - 1 , tabWidget ) ;
2021-11-08 09:19:50 +08:00
if ( pSettings - > codeCompletion ( ) . clearWhenEditorHidden ( ) ) {
for ( int i = 0 ; i < tabWidget - > count ( ) ; i + + ) {
Editor * e = ( Editor * ) ( tabWidget - > widget ( i ) ) ;
if ( ! e - > inProject ( ) ) {
2021-11-08 14:51:20 +08:00
if ( e ! = editor & & e - > parser ( ) & & ! e - > notParsed ( ) ) {
2021-11-08 09:19:50 +08:00
e - > parser ( ) - > reset ( ) ;
}
}
}
}
2021-11-08 14:51:20 +08:00
if ( editor & & editor - > parser ( ) & & editor - > notParsed ( ) ) {
resetCppParser ( editor - > parser ( ) ) ;
editor - > reparse ( ) ;
}
2021-11-08 09:19:50 +08:00
}
2021-11-08 14:51:20 +08:00
2021-11-08 21:19:48 +08:00
void MainWindow : : updateEditorHideTime ( QTabWidget * tabWidget ) {
Editor * editor = mEditorList - > getEditor ( - 1 , tabWidget ) ;
for ( int i = 0 ; i < tabWidget - > count ( ) ; i + + ) {
Editor * e = ( Editor * ) ( tabWidget - > widget ( i ) ) ;
if ( e ! = editor ) {
if ( ! e - > hideTime ( ) . isValid ( ) )
e - > setHideTime ( QDateTime : : currentDateTime ( ) ) ;
} else {
e - > setHideTime ( QDateTime ( ) ) ;
}
}
}
2021-11-09 21:22:50 +08:00
void MainWindow : : showHideInfosTab ( QWidget * widget , bool show )
{
int idx = findTabIndex ( ui - > tabInfos , widget ) ;
if ( idx > = 0 ) {
if ( ! show ) {
ui - > tabInfos - > removeTab ( idx ) ;
}
} else {
if ( show & & mTabInfosData . contains ( widget ) ) {
PTabWidgetInfo info = mTabInfosData [ widget ] ;
int insert = - 1 ;
for ( int i = 0 ; i < ui - > tabInfos - > count ( ) ; i + + ) {
QWidget * w = ui - > tabInfos - > widget ( i ) ;
PTabWidgetInfo infoW = mTabInfosData [ w ] ;
if ( infoW - > order > info - > order ) {
insert = i ;
break ;
}
}
if ( insert > = 0 ) {
ui - > tabInfos - > insertTab ( insert , widget , info - > icon , info - > text ) ;
} else {
ui - > tabInfos - > addTab ( widget , info - > icon , info - > text ) ;
}
}
}
}
void MainWindow : : showHideMessagesTab ( QWidget * widget , bool show )
{
int idx = findTabIndex ( ui - > tabMessages , widget ) ;
if ( idx > = 0 ) {
if ( ! show ) {
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 ( )
{
for ( int i = 0 ; i < ui - > tabInfos - > count ( ) ; i + + ) {
QWidget * widget = ui - > tabInfos - > widget ( i ) ;
PTabWidgetInfo info = std : : make_shared < TabWidgetInfo > ( ) ;
info - > order = i ;
info - > text = ui - > tabInfos - > tabText ( i ) ;
info - > icon = ui - > tabInfos - > tabIcon ( i ) ;
mTabInfosData [ widget ] = info ;
}
}
void MainWindow : : prepareTabMessagesData ( )
{
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
void MainWindow : : newProjectUnitFile ( )
{
if ( ! mProject )
return ;
int idx = - 1 ;
QModelIndex current = ui - > projectView - > currentIndex ( ) ;
FolderNode * node = nullptr ;
if ( current . isValid ( ) ) {
node = static_cast < FolderNode * > ( current . internalPointer ( ) ) ;
}
QString newFileName ;
do {
newFileName = tr ( " untitled " ) + QString ( " %1 " ) . arg ( getNewFileNumber ( ) ) ;
if ( mProject - > options ( ) . useGPP ) {
newFileName + = " .cpp " ;
} else {
newFileName + = " .c " ;
}
} while ( fileExists ( QDir ( mProject - > directory ( ) ) . absoluteFilePath ( newFileName ) ) ) ;
newFileName = QInputDialog : : getText (
this ,
tr ( " New Project File Name " ) ,
tr ( " File Name: " ) ,
QLineEdit : : Normal ,
newFileName ) ;
if ( newFileName . isEmpty ( ) )
return ;
if ( fileExists ( QDir ( mProject - > directory ( ) ) . absoluteFilePath ( newFileName ) ) ) {
QMessageBox : : critical ( this , tr ( " File Already Exists! " ) ,
tr ( " File '%1' already exists! " ) . arg ( newFileName ) ) ;
return ;
}
PProjectUnit newUnit = mProject - > newUnit (
mProject - > pointerToNode ( node ) , newFileName ) ;
idx = mProject - > units ( ) . count ( ) - 1 ;
mProject - > saveUnits ( ) ;
updateProjectView ( ) ;
Editor * editor = mProject - > openUnit ( idx ) ;
//editor->setUseCppSyntax(mProject->options().useGPP);
//editor->setModified(true);
editor - > activate ( ) ;
}
2021-10-20 18:05:43 +08:00
void MainWindow : : on_EditorTabsLeft_currentChanged ( int )
2021-10-03 17:18:43 +08:00
{
2021-10-13 11:32:59 +08:00
Editor * editor = mEditorList - > getEditor ( - 1 , ui - > EditorTabsLeft ) ;
2021-10-03 17:18:43 +08:00
if ( editor ) {
editor - > reparseTodo ( ) ;
}
2021-11-08 21:19:48 +08:00
updateEditorParser ( ui - > EditorTabsLeft ) ;
updateEditorHideTime ( ui - > EditorTabsLeft ) ;
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
{
2021-10-13 11:32:59 +08:00
Editor * editor = mEditorList - > getEditor ( - 1 , ui - > EditorTabsRight ) ;
2021-10-03 17:18:43 +08:00
if ( editor ) {
editor - > reparseTodo ( ) ;
}
2021-11-08 21:19:48 +08:00
updateEditorParser ( ui - > EditorTabsRight ) ;
updateEditorHideTime ( ui - > EditorTabsRight ) ;
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 ;
editor - > beginUpdate ( ) ;
// mClassBrowserModel.beginUpdate();
QCursor oldCursor = editor - > cursor ( ) ;
editor - > setCursor ( Qt : : CursorShape : : WaitCursor ) ;
2021-10-20 18:05:43 +08:00
auto action = finally ( [ oldCursor , editor ] {
2021-10-04 11:07:35 +08:00
editor - > endUpdate ( ) ;
// mClassBrowserModel.EndTreeUpdate;
editor - > setCursor ( oldCursor ) ;
} ) ;
QString word = editor - > wordAtCursor ( ) ;
if ( word . isEmpty ( ) )
return ;
// if (!isIdentifier(word)) {
// return;
// }
if ( isKeyword ( word ) ) {
return ;
}
2021-10-04 12:49:55 +08:00
BufferCoord oldCaretXY = editor - > caretXY ( ) ;
if ( editor - > inProject ( ) & & mProject ) {
mProject - > cppParser ( ) - > parseFileList ( ) ;
BufferCoord pBeginPos , pEndPos ;
QString phrase = getWordAtPosition ( editor , oldCaretXY , pBeginPos , pEndPos , Editor : : WordPurpose : : wpInformation ) ;
// Find it's definition
PStatement oldStatement = editor - > parser ( ) - > findStatementOf (
editor - > filename ( ) ,
phrase ,
oldCaretXY . Line ) ;
// 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 ;
}
}
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 ;
PCppParser parser = editor - > parser ( ) ;
//here we must reparse the file in sync, or rename may fail
parser - > parseFile ( editor - > filename ( ) , editor - > inProject ( ) , false , false ) ;
CppRefacter refactor ;
refactor . renameSymbol ( editor , oldCaretXY , word , newWord ) ;
editor - > reparse ( ) ;
}
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 ) ;
}
2021-10-22 15:02:54 +08:00
void MainWindow : : setFilesViewRoot ( const QString & path )
{
mFileSystemModel . setRootPath ( path ) ;
ui - > treeFiles - > setRootIndex ( mFileSystemModel . index ( path ) ) ;
pSettings - > environment ( ) . setCurrentFolder ( path ) ;
ui - > txtFilesPath - > setText ( path ) ;
ui - > txtFilesPath - > setCursorPosition ( 1 ) ;
}
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 ( ) ;
}
2021-11-01 23:14:17 +08:00
void MainWindow : : doCompileRun ( RunType runType )
{
mCompileSuccessionTask = std : : make_shared < CompileSuccessionTask > ( ) ;
switch ( runType ) {
case RunType : : CurrentProblemCase :
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : RunCurrentProblemCase ;
break ;
case RunType : : ProblemCases :
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : RunProblemCases ;
break ;
default :
mCompileSuccessionTask - > type = CompileSuccessionTaskType : : RunNormal ;
}
compile ( ) ;
}
2021-11-02 19:26:11 +08:00
void MainWindow : : updateProblemCaseOutput ( POJProblemCase problemCase )
{
ui - > txtProblemCaseOutput - > clear ( ) ;
ui - > txtProblemCaseOutput - > setText ( problemCase - > output ) ;
if ( problemCase - > testState = = ProblemCaseTestState : : Failed ) {
2021-11-12 10:51:00 +08:00
QStringList output = textToLines ( problemCase - > output ) ;
QStringList expected = textToLines ( problemCase - > expected ) ;
2021-11-02 19:26:11 +08:00
for ( int i = 0 ; i < output . count ( ) ; i + + ) {
if ( i > = expected . count ( ) | | output [ i ] ! = expected [ i ] ) {
QTextBlock block = ui - > txtProblemCaseOutput - > document ( ) - > findBlockByLineNumber ( i ) ;
QTextCursor cur ( block ) ;
cur . select ( QTextCursor : : LineUnderCursor ) ;
QTextCharFormat format = cur . charFormat ( ) ;
format . setUnderlineColor ( mErrorColor ) ;
format . setUnderlineStyle ( QTextCharFormat : : WaveUnderline ) ;
cur . setCharFormat ( format ) ;
}
}
if ( output . count ( ) < expected . count ( ) ) {
QTextBlock block = ui - > txtProblemCaseOutput - > document ( ) - > findBlockByLineNumber ( output . count ( ) - 1 ) ;
QTextCursor cur ( block ) ;
cur . select ( QTextCursor : : LineUnderCursor ) ;
QTextCharFormat format = cur . charFormat ( ) ;
format . setUnderlineColor ( mErrorColor ) ;
format . setUnderlineStyle ( QTextCharFormat : : WaveUnderline ) ;
cur . setCharFormat ( format ) ;
}
}
}
void MainWindow : : applyCurrentProblemCaseChanges ( )
{
QModelIndex idx = ui - > lstProblemCases - > currentIndex ( ) ;
if ( idx . isValid ( ) ) {
POJProblemCase problemCase = mOJProblemModel . getCase ( idx . row ( ) ) ;
if ( problemCase ) {
problemCase - > input = ui - > txtProblemCaseInput - > toPlainText ( ) ;
problemCase - > expected = ui - > txtProblemCaseExpected - > toPlainText ( ) ;
}
}
}
2021-10-06 12:19:46 +08:00
Ui : : MainWindow * MainWindow : : mainWidget ( ) const
{
return ui ;
}
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 ) {
QStringList contents ;
Editor * editor = mEditorList - > getEditorByFilename ( file - > filename ) ;
if ( ! editor ) {
QMessageBox : : critical ( this ,
tr ( " Replace Error " ) ,
tr ( " Can't open file '%1' for replace! " ) . arg ( file - > filename ) ) ;
return ;
}
2021-10-05 21:25:23 +08:00
contents = editor - > contents ( ) ;
2021-10-04 12:49:55 +08:00
for ( int i = file - > results . count ( ) - 1 ; i > = 0 ; i - - ) {
const PSearchResultTreeItem & item = file - > results [ i ] ;
QString line = contents [ item - > line - 1 ] ;
if ( line . mid ( item - > start - 1 , results - > keyword . length ( ) ) ! = results - > keyword ) {
QMessageBox : : critical ( editor ,
tr ( " Replace Error " ) ,
tr ( " Contents has changed since last search! " ) ) ;
return ;
}
line . remove ( item - > start - 1 , results - > keyword . length ( ) ) ;
line . insert ( item - > start - 1 , newWord ) ;
contents [ item - > line - 1 ] = line ;
}
editor - > selectAll ( ) ;
editor - > setSelText ( contents . join ( editor - > lineBreak ( ) ) ) ;
}
showSearchReplacePanel ( false ) ;
openCloseBottomPanel ( false ) ;
}
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 ( )
{
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
QFileInfo fileInfo ( includeTrailingPathDelimiter ( pSettings - > dirs ( ) . app ( ) ) + " cppreference-zh.chm " ) ;
if ( fileInfo . exists ( ) ) {
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( fileInfo . absoluteFilePath ( ) ) ) ;
} else {
QDesktopServices : : openUrl ( QUrl ( " https://zh.cppreference.com/w/cpp " ) ) ;
}
} 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 ;
}
void MainWindow : : on_actionAdd_bookmark_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
if ( editor - > lines ( ) - > count ( ) < = 0 )
return ;
QString desc = QInputDialog : : getText ( editor , tr ( " Bookmark Description " ) ,
tr ( " Description: " ) , QLineEdit : : Normal ,
editor - > lines ( ) - > getString ( line - 1 ) . trimmed ( ) ) ;
desc = desc . trimmed ( ) ;
editor - > addBookmark ( line , desc ) ;
}
}
void MainWindow : : on_actionRemove_Bookmark_triggered ( )
{
Editor * editor = mEditorList - > getEditor ( ) ;
int line ;
if ( editor & & editor - > pointToLine ( mEditorContextMenuPos , line ) ) {
editor - > removeBookmark ( line ) ;
}
}
void MainWindow : : on_tableBookmark_doubleClicked ( const QModelIndex & index )
{
if ( ! index . isValid ( ) )
return ;
PBookmark bookmark = mBookmarkModel - > bookmark ( index . row ( ) ) ;
if ( bookmark ) {
Editor * editor = mEditorList - > getEditorByFilename ( bookmark - > filename ) ;
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 ) {
QString fileDir = extractFileDir ( editor - > filename ( ) ) ;
if ( ! fileDir . isEmpty ( ) ) {
setFilesViewRoot ( fileDir ) ;
ui - > treeFiles - > setCurrentIndex ( mFileSystemModel . index ( editor - > filename ( ) ) ) ;
2021-10-22 16:48:19 +08:00
ui - > tabInfos - > setCurrentWidget ( ui - > tabFiles ) ;
openCloseLeftPanel ( true ) ;
2021-10-22 15:02:54 +08:00
}
}
}
void MainWindow : : on_treeFiles_doubleClicked ( const QModelIndex & index )
{
QString filepath = mFileSystemModel . filePath ( index ) ;
QFileInfo file ( filepath ) ;
if ( file . isFile ( ) ) {
2021-11-15 22:08:35 +08:00
if ( getFileType ( filepath ) = = FileType : : Project ) {
openProject ( filepath ) ;
} else {
openFile ( filepath ) ;
2021-10-22 15:02:54 +08:00
}
}
}
void MainWindow : : on_actionOpen_Folder_triggered ( )
{
QString folder = QFileDialog : : getExistingDirectory ( this , tr ( " Open Folder " ) ,
pSettings - > environment ( ) . currentFolder ( ) ) ;
if ( ! folder . isEmpty ( ) ) {
setFilesViewRoot ( folder ) ;
}
}
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
void MainWindow : : on_btnNewProblemSet_clicked ( )
{
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 ) {
on_btnSaveProblemSet_clicked ( ) ;
}
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 ( ) ) ;
2021-11-01 00:40:11 +08:00
}
void MainWindow : : on_btnAddProblem_clicked ( )
{
int startCount = mOJProblemSetModel . count ( ) ;
QString name ;
while ( true ) {
name = tr ( " Problem %1 " ) . arg ( startCount ) ;
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 ) ) ;
}
void MainWindow : : on_btnRemoveProblem_clicked ( )
{
QModelIndex idx = ui - > lstProblemSet - > currentIndex ( ) ;
if ( ! idx . isValid ( ) )
return ;
mOJProblemSetModel . removeProblem ( idx . row ( ) ) ;
}
void MainWindow : : on_btnSaveProblemSet_clicked ( )
{
QString fileName = QFileDialog : : getSaveFileName (
this ,
tr ( " Save Problem Set " ) ,
QDir ( ) . absolutePath ( ) ,
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 {
2021-11-02 19:26:11 +08:00
applyCurrentProblemCaseChanges ( ) ;
2021-11-01 00:40:11 +08:00
mOJProblemSetModel . saveToFile ( fileName ) ;
} catch ( FileError & error ) {
QMessageBox : : critical ( this , tr ( " Save Error " ) ,
error . reason ( ) ) ;
}
}
}
void MainWindow : : on_btnLoadProblemSet_clicked ( )
{
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 {
mOJProblemSetModel . loadFromFile ( fileName ) ;
} 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
}
void MainWindow : : on_btnAddProblemCase_clicked ( )
{
int startCount = mOJProblemModel . count ( ) ;
QString name ;
while ( true ) {
name = tr ( " Problem Case %1 " ) . arg ( startCount ) ;
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 ) ;
ui - > lstProblemCases - > setCurrentIndex ( mOJProblemModel . index ( mOJProblemModel . count ( ) - 1 ) ) ;
}
2021-11-01 20:44:08 +08:00
void MainWindow : : on_btnRunAllProblemCases_clicked ( )
{
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 ( )
{
if ( pSettings - > environment ( ) . language ( ) = = " zh_CN " ) {
QDesktopServices : : openUrl ( QUrl ( " https://zh.cppreference.com/w/c " ) ) ;
} else {
QDesktopServices : : openUrl ( QUrl ( " https://en.cppreference.com/w/c " ) ) ;
}
}
void MainWindow : : on_btnRemoveProblemCase_clicked ( )
{
QModelIndex idx = ui - > lstProblemCases - > currentIndex ( ) ;
if ( idx . isValid ( ) ) {
mOJProblemModel . removeCase ( idx . row ( ) ) ;
}
}
2021-11-06 14:49:11 +08:00
void MainWindow : : on_btnOpenProblemAnswer_clicked ( )
{
POJProblem problem = mOJProblemModel . problem ( ) ;
if ( ! problem | | problem - > answerProgram . isEmpty ( ) )
return ;
Editor * e = mEditorList - > getEditorByFilename ( problem - > answerProgram ) ;
if ( e ) {
e - > activate ( ) ;
}
}
2021-11-08 21:19:48 +08:00
bool MainWindow : : openningFiles ( ) const
{
return mOpenningFiles ;
}
2021-11-09 21:22:50 +08:00
void MainWindow : : on_actionTool_Window_Bars_triggered ( )
{
bool state = ui - > tabInfos - > isVisible ( ) ;
state = ! state ;
ui - > tabInfos - > setVisible ( state ) ;
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 ) ;
}
void MainWindow : : on_actionCompile_Log_triggered ( )
{
bool state = ui - > actionCompile_Log - > isChecked ( ) ;
ui - > actionCompile_Log - > setChecked ( state ) ;
showHideMessagesTab ( ui - > tabCompilerOutput , state ) ;
}
void MainWindow : : on_actionDebug_Window_triggered ( )
{
bool state = ui - > actionCompile_Log - > isChecked ( ) ;
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
void MainWindow : : on_btnCaseValidateOptions_clicked ( )
{
changeOptions (
SettingsDialog : : tr ( " Problem Set " ) ,
SettingsDialog : : tr ( " Program Runner " )
) ;
}