diff options
Diffstat (limited to 'src/MainWindow.cpp')
-rw-r--r-- | src/MainWindow.cpp | 393 |
1 files changed, 198 insertions, 195 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a3480c7..ab3040d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -37,6 +37,9 @@ #include <tqaction.h> #include <tqapplication.h> #include <tqcheckbox.h> +#include <tqcursor.h> +#include <tqfile.h> +#include <tqfileinfo.h> #include <tqlabel.h> #include <tqlocale.h> #include <tqmessagebox.h> @@ -44,6 +47,7 @@ #include <tqpopupmenu.h> #include <tqpushbutton.h> #include <tqstatusbar.h> +#include <tqtextcodec.h> #include <tqtranslator.h> ///-- #include <tqwidget.h> ///-- #include <tqstring.h> @@ -57,7 +61,6 @@ ///-- #include <tqcloseevent.h> ///-- #include <tqhelpevent.h> ///-- #include <tqtooltip.h> -///-- #include <tqtextcodec.h> ///-- #include <tqdate.h> ///-- #include <tqurl.h> ///-- #include <tqtdebug.h> @@ -87,7 +90,8 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : MainWindowBase(parent), m_aboutDialog(nullptr), m_qSciSourceCodeEditor(nullptr), m_qTranslator(nullptr), m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr), m_oldLinesNumber(0), m_encodingsList(), m_encodingActionGroup(nullptr), - m_saveEncodedActionGroup(nullptr), m_highlighterActionGroup(nullptr) + m_saveEncodedActionGroup(nullptr), m_highlighterActionGroup(nullptr), + m_documentModified(false) ///- _mainWindowForm(nullptr), _settings(nullptr) ///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr), _settingsDialog(nullptr) ///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr), _indentHandler(nullptr) @@ -131,21 +135,20 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : ///-- _settingsDialog = new UiGuiSettingsDialog(this, _settings); ///-- connect(actionShowSettings, SIGNAL(activated()), _settingsDialog, ///-- SLOT(showDialog())); -///-- -///-- // If a file that should be opened on start has been handed over to the constructor exists, load -///-- // it -///-- if (TQFile::exists(file2OpenOnStart)) -///-- { -///-- openSourceFileDialog(file2OpenOnStart); -///-- } -///-- // Otherwise load the last opened file, if this is enabled in the settings. -///-- else -///-- { -///-- loadLastOpenedFile(); -///-- } -///-- -///-- updateSourceView(); -///-- + + if (TQFile::exists(file2OpenOnStart)) + { + // If a file that should be opened on start exists, load it + openSourceFileDialog(file2OpenOnStart); + } + else + { + // Otherwise load the last opened file, if this is enabled in the settings. + loadLastOpenedFile(); + } + + updateSourceView(); + ///-- // Enable accept dropping of files. ///-- setAcceptDrops(true); } @@ -249,6 +252,8 @@ void MainWindow::initMainWindow() ///-- //connect( _settings, SIGNAL(recentlyOpenedListSize(int)), this, SLOT(updateRecentlyOpenedList()) ///-- // ); ///-- _settings->registerObjectSlot(this, "updateRecentlyOpenedList()", "recentlyOpenedListSize"); + + updateWindowTitle(); } /* @@ -455,7 +460,7 @@ void MainWindow::initIndenter() ///-- ///-- // Set this true, so the indenter is called at first program start ///-- _indentSettingsChanged = true; -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- ///-- // Handle if indenter parameter tool tips are enabled ///-- _settings->registerObjectProperty(actionIndenterParameterTooltipsEnabled, @@ -465,37 +470,37 @@ void MainWindow::initIndenter() ///-- _mainWindowForm->menuIndenter->addActions(_indentHandler->getIndenterMenuActions()); } -///-- /* -///-- \brief Tries to load the by \a filePath defined file and returns its content as TQString. -///-- -///-- If the file could not be loaded a error dialog will be shown. -///-- */ -///-- TQString MainWindow::loadFile(TQString filePath) -///-- { -///-- TQFile inSrcFile(filePath); -///-- TQString fileContent = ""; -///-- -///-- if (!inSrcFile.open(TQFile::ReadOnly | TQFile::Text)) -///-- { -///-- TQMessageBox::warning(NULL, tr("Error opening file"), tr( -///-- "Cannot read the file ") + "\"" + filePath + "\"."); -///-- } -///-- else -///-- { -///-- TQTextStream inSrcStrm(&inSrcFile); -///-- TQApplication::setOverrideCursor(TQt::WaitCursor); -///-- inSrcStrm.setCodec(TQTextCodec::codecForName(m_currentEncoding.toAscii())); -///-- fileContent = inSrcStrm.readAll(); -///-- TQApplication::restoreOverrideCursor(); -///-- inSrcFile.close(); -///-- -///-- TQFileInfo fileInfo(filePath); -///-- _currentSourceFileExtension = fileInfo.suffix(); -///-- int indexOfHighlighter = _highlighter->setLexerForExtension(_currentSourceFileExtension); +/* + \brief Tries to load the by \a filePath defined file and returns its content as TQString. + + If the file could not be loaded a error dialog will be shown. + */ +TQString MainWindow::loadFile(const TQString &filePath) +{ + TQFile inSrcFile(filePath); + TQString fileContent = ""; + + if (!inSrcFile.open(IO_ReadOnly | IO_Translate)) + { + TQMessageBox::warning(nullptr, tr("Error opening file"), + tr("Cannot read the file ") + "\"" + filePath + "\"."); + } + else + { + TQTextStream inSrcStream(&inSrcFile); + TQApplication::setOverrideCursor(TQt::WaitCursor); + inSrcStream.setCodec(TQTextCodec::codecForName(m_currentEncoding.ascii())); + fileContent = inSrcStream.read(); + TQApplication::restoreOverrideCursor(); + inSrcFile.close(); + + TQFileInfo fileInfo(filePath); + m_currentSourceFileExtension = fileInfo.extension(false); +///-- int indexOfHighlighter = _highlighter->setLexerForExtension(m_currentSourceFileExtension); ///-- m_highlighterActionGroup->actions().at(indexOfHighlighter)->setChecked(true); -///-- } -///-- return fileContent; -///-- } + } + return fileContent; +} /* \brief Calls the source file open dialog to load a source file for the formatting preview. @@ -518,32 +523,32 @@ void MainWindow::openSourceFileDialog(TQString fileName) ///-- if (fileName.isEmpty()) ///-- { ///-- fileName = TQFileDialog::getOpenFileName(this, tr( -///-- "Choose source code file"), _currentSourceFile, fileExtensions); +///-- "Choose source code file"), m_currentSourceFile, fileExtensions); ///-- } ///-- ///-- if (fileName != "") ///-- { -///-- _currentSourceFile = fileName; +///-- m_currentSourceFile = fileName; ///-- TQFileInfo fileInfo(fileName); -///-- _currentSourceFileExtension = fileInfo.suffix(); +///-- m_currentSourceFileExtension = fileInfo.suffix(); ///-- ///-- openedSourceFileContent = loadFile(fileName); -///-- _sourceFileContent = openedSourceFileContent; +///-- m_sourceFileContent = openedSourceFileContent; ///-- if (m_toolBarWidget->cbLivePreview->isChecked()) ///-- { ///-- callIndenter(); ///-- } ///-- m_sourceCodeChanged = true; -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- updateSourceView(); ///-- updateWindowTitle(); ///-- updateRecentlyOpenedList(); ///-- _textEditLastScrollPos = 0; ///-- m_textEditVScrollBar->setValue(_textEditLastScrollPos); ///-- -///-- _savedSourceContent = openedSourceFileContent; +///-- m_savedSourceContent = openedSourceFileContent; ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- } } @@ -560,7 +565,7 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- //TQString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", ///-- // fileExtensions ); ///-- TQString fileName = TQFileDialog::getSaveFileName(this, tr( -///-- "Save source code file"), _currentSourceFile, fileExtensions); +///-- "Save source code file"), m_currentSourceFile, fileExtensions); ///-- ///-- // Saving has been canceled if the filename is empty ///-- if (fileName.isEmpty()) @@ -568,9 +573,9 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- return false; ///-- } ///-- -///-- _savedSourceContent = m_qSciSourceCodeEditor->text(); +///-- m_savedSourceContent = m_qSciSourceCodeEditor->text(); ///-- -///-- _currentSourceFile = fileName; +///-- m_currentSourceFile = fileName; ///-- TQFile::remove(fileName); ///-- TQFile outSrcFile(fileName); ///-- outSrcFile.open(TQFile::ReadWrite | TQFile::Text); @@ -586,16 +591,16 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- } ///-- TQTextStream outSrcStrm(&outSrcFile); ///-- outSrcStrm.setCodec(TQTextCodec::codecForName(encoding.toAscii())); -///-- outSrcStrm << _savedSourceContent; +///-- outSrcStrm << m_savedSourceContent; ///-- outSrcFile.close(); ///-- ///-- TQFileInfo fileInfo(fileName); -///-- _currentSourceFileExtension = fileInfo.suffix(); +///-- m_currentSourceFileExtension = fileInfo.suffix(); ///-- ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- -///-- updateWindowTitle(); + updateWindowTitle(); return true; } @@ -606,26 +611,26 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) */ bool MainWindow::saveSourceFile() { -///-- if (_currentSourceFile.isEmpty()) +///-- if (m_currentSourceFile.isEmpty()) ///-- { ///-- return saveasSourceFileDialog(); ///-- } ///-- else ///-- { -///-- TQFile::remove(_currentSourceFile); -///-- TQFile outSrcFile(_currentSourceFile); -///-- _savedSourceContent = m_qSciSourceCodeEditor->text(); +///-- TQFile::remove(m_currentSourceFile); +///-- TQFile outSrcFile(m_currentSourceFile); +///-- m_savedSourceContent = m_qSciSourceCodeEditor->text(); ///-- outSrcFile.open(TQFile::ReadWrite | TQFile::Text); ///-- ///-- // Get current encoding. ///-- TQString m_currentEncoding = m_encodingActionGroup->checkedAction()->text(); ///-- TQTextStream outSrcStrm(&outSrcFile); ///-- outSrcStrm.setCodec(TQTextCodec::codecForName(m_currentEncoding.toAscii())); -///-- outSrcStrm << _savedSourceContent; +///-- outSrcStrm << m_savedSourceContent; ///-- outSrcFile.close(); ///-- ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- } return true; } @@ -650,42 +655,40 @@ bool MainWindow::saveSourceFile() ///-- ///-- return fileContent; ///-- } -///-- -///-- /* -///-- \brief Updates the displaying of the source code. -///-- -///-- Updates the text edit field, which is showing the loaded, and if preview is enabled formatted, source code. -///-- Reassigns the line numbers and in case of switch between preview and none preview keeps the text field -///-- at the same line number. -///-- */ -///-- void MainWindow::updateSourceView() -///-- { + +/* + \brief Updates the displaying of the source code. + + Updates the text edit field, which is showing the loaded, and if preview is enabled formatted, source code. + Reassigns the line numbers and in case of switch between preview and none preview keeps the text field + at the same line number. + */ +void MainWindow::updateSourceView() +{ ///-- _textEditLastScrollPos = m_textEditVScrollBar->value(); -///-- -///-- if (m_toolBarWidget->cbLivePreview->isChecked()) -///-- { -///-- _sourceViewContent = _sourceFormattedContent; -///-- } -///-- else -///-- { -///-- _sourceViewContent = _sourceFileContent; -///-- } -///-- -///-- if (_previewToggled) -///-- { -///-- disconnect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, -///-- SLOT(sourceCodeChangedHelperSlot())); -///-- bool textIsModified = isWindowModified(); -///-- m_qSciSourceCodeEditor->setText(_sourceViewContent); -///-- setWindowModified(textIsModified); -///-- _previewToggled = false; -///-- connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, -///-- SLOT(sourceCodeChangedHelperSlot())); -///-- } -///-- + + if (m_toolBarWidget->cbLivePreview->isOn()) + { + m_sourceViewContent = m_sourceFormattedContent; + } + else + { + m_sourceViewContent = m_sourceFileContent; + } + + if (m_previewToggled) + { + disconnect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), + this, SLOT(sourceCodeChangedHelperSlot())); + m_qSciSourceCodeEditor->setText(m_sourceViewContent); + m_previewToggled = false; + connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), + this, SLOT(sourceCodeChangedHelperSlot())); + } + ///-- m_textEditVScrollBar->setValue(_textEditLastScrollPos); -///-- } -///-- +} + ///-- /* ///-- \brief Calls the selected indenter with the currently loaded source code to retrieve the formatted source code. ///-- @@ -694,8 +697,8 @@ bool MainWindow::saveSourceFile() ///-- void MainWindow::callIndenter() ///-- { ///-- TQApplication::setOverrideCursor(TQCursor(TQt::WaitCursor)); -///-- _sourceFormattedContent = _indentHandler->callIndenter(_sourceFileContent, -///-- _currentSourceFileExtension); +///-- m_sourceFormattedContent = _indentHandler->callIndenter(m_sourceFileContent, +///-- m_currentSourceFileExtension); ///-- //updateSourceView(); ///-- TQApplication::restoreOverrideCursor(); ///-- } @@ -713,7 +716,7 @@ void MainWindow::turnHighlightOnOff(bool turnOn) ///-- { ///-- _highlighter->turnHighlightOff(); ///-- } -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- updateSourceView(); } @@ -738,17 +741,17 @@ void MainWindow::sourceCodeChangedSlot() ///-- m_sourceCodeChanged = true; ///-- ///-- // Get the content text of the text editor. -///-- _sourceFileContent = m_qSciSourceCodeEditor->text(); +///-- m_sourceFileContent = m_qSciSourceCodeEditor->text(); ///-- ///-- // Get the position of the cursor in the unindented text. -///-- if (_sourceFileContent.isEmpty()) +///-- if (m_sourceFileContent.isEmpty()) ///-- { ///-- // Add this line feed, because AStyle has problems with a totally emtpy file. -///-- _sourceFileContent += "\n"; +///-- m_sourceFileContent += "\n"; ///-- cursorPosAbsolut = 0; ///-- cursorPos = 0; ///-- cursorLine = 0; -///-- enteredCharacter = _sourceFileContent.at(cursorPosAbsolut); +///-- enteredCharacter = m_sourceFileContent.at(cursorPosAbsolut); ///-- } ///-- else ///-- { @@ -763,14 +766,14 @@ void MainWindow::sourceCodeChangedSlot() ///-- { ///-- cursorPos--; ///-- } -///-- enteredCharacter = _sourceFileContent.at(cursorPosAbsolut); +///-- enteredCharacter = m_sourceFileContent.at(cursorPosAbsolut); ///-- } ///-- ///-- // Call the indenter to reformat the text. ///-- if (m_toolBarWidget->cbLivePreview->isChecked()) ///-- { ///-- callIndenter(); -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- } ///-- ///-- // Update the text editor. @@ -859,15 +862,15 @@ void MainWindow::sourceCodeChangedSlot() ///-- m_sourceCodeChanged = false; ///-- } ///-- -///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) +///-- if (m_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- } ///-- else ///-- { ///-- m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. -///-- setWindowModified(true); +///-- m_documentModified = true; ///-- } ///-- ///-- // Could set cursor this way and use normal linear search in text instead of columns and rows. @@ -891,7 +894,7 @@ void MainWindow::sourceCodeChangedSlot() ///-- if (m_toolBarWidget->cbLivePreview->isChecked()) ///-- { ///-- callIndenter(); -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- ///-- updateSourceView(); ///-- if (m_sourceCodeChanged) @@ -912,15 +915,15 @@ void MainWindow::sourceCodeChangedSlot() ///-- updateSourceView(); ///-- } ///-- -///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) +///-- if (m_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- } ///-- else ///-- { ///-- m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. -///-- setWindowModified(true); +///-- m_documentModified = true; ///-- } ///-- } @@ -932,7 +935,7 @@ void MainWindow::sourceCodeChangedSlot() */ void MainWindow::previewTurnedOnOff(bool turnOn) { -///-- _previewToggled = true; +///-- m_previewToggled = true; ///-- ///-- int cursorLine, cursorPos; ///-- m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); @@ -955,26 +958,26 @@ void MainWindow::previewTurnedOnOff(bool turnOn) ///-- } ///-- _indentSettingsChanged = false; ///-- -///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) +///-- if (m_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { ///-- m_qSciSourceCodeEditor->setModified(false); -///-- setWindowModified(false); +///-- m_documentModified = false; ///-- } ///-- else ///-- { ///-- m_qSciSourceCodeEditor->setModified(true); -///-- setWindowModified(true); +///-- m_documentModified = true; ///-- } -///-- } -///-- -///-- /* -///-- \brief This slot updates the main window title to show the currently opened -///-- source code filename. -///-- */ -///-- void MainWindow::updateWindowTitle() -///-- { -///-- this->setWindowTitle("UniversalIndentGUI " + TQString( -///-- PROGRAM_VERSION_STRING) + " [*]" + _currentSourceFile); +} + +/* + \brief This slot updates the main window title to show the currently opened + source code filename. + */ +void MainWindow::updateWindowTitle() +{ + setCaption("UniversalIndentGUI (TQt) " + TQString(PROGRAM_VERSION_STRING) + + " [*] " + m_currentSourceFile); } /* @@ -984,7 +987,7 @@ void MainWindow::exportToPDF() { ///-- TQString fileExtensions = tr("PDF Document") + " (*.pdf)"; ///-- -///-- TQString fileName = _currentSourceFile; +///-- TQString fileName = m_currentSourceFile; ///-- TQFileInfo fileInfo(fileName); ///-- TQString fileExtension = fileInfo.suffix(); ///-- @@ -1008,7 +1011,7 @@ void MainWindow::exportToHTML() { ///-- TQString fileExtensions = tr("HTML Document") + " (*.html)"; ///-- -///-- TQString fileName = _currentSourceFile; +///-- TQString fileName = m_currentSourceFile; ///-- TQFileInfo fileInfo(fileName); ///-- TQString fileExtension = fileInfo.suffix(); ///-- @@ -1034,60 +1037,60 @@ void MainWindow::exportToHTML() ///-- } } -///-- /* -///-- \brief Loads the last opened file if this option is enabled in the _settings. -///-- -///-- If the file does not exist, the default example file is tried to be loaded. If even that -///-- fails a very small code example is shown. -///-- If the setting for opening the last file is disabled, the editor is empty on startup. -///-- */ -///-- void MainWindow::loadLastOpenedFile() -///-- { -///-- // Get setting for last opened source code file. -///-- _loadLastSourceCodeFileOnStartup = -///-- _settings->getValueByName("loadLastSourceCodeFileOnStartup").toBool(); -///-- -///-- // Only load last source code file if set to do so -///-- if (_loadLastSourceCodeFileOnStartup) -///-- { -///-- // From the list of last opened files get the first one. -///-- _currentSourceFile = -///-- _settings->getValueByName("lastSourceCodeFile").toString().split("|").first(); -///-- -///-- // If source file exist load it. -///-- if (TQFile::exists(_currentSourceFile)) -///-- { -///-- TQFileInfo fileInfo(_currentSourceFile); -///-- _currentSourceFile = fileInfo.absoluteFilePath(); -///-- _sourceFileContent = loadFile(_currentSourceFile); -///-- } -///-- // If the last opened source code file does not exist, try to load the default example.cpp file. -///-- else if (TQFile::exists(SettingsPaths::getIndenterPath() + "/example.cpp")) -///-- { -///-- TQFileInfo fileInfo(SettingsPaths::getIndenterPath() + "/example.cpp"); -///-- _currentSourceFile = fileInfo.absoluteFilePath(); -///-- _sourceFileContent = loadFile(_currentSourceFile); -///-- } -///-- // If neither the example source code file exists show some small code example. -///-- else -///-- { -///-- _currentSourceFile = "untitled.cpp"; -///-- _currentSourceFileExtension = "cpp"; -///-- _sourceFileContent = "if(x==\"y\"){x=z;}"; -///-- } -///-- } -///-- // if last opened source file should not be loaded make some default _settings. -///-- else -///-- { -///-- _currentSourceFile = "untitled.cpp"; -///-- _currentSourceFileExtension = "cpp"; -///-- _sourceFileContent = ""; -///-- } -///-- _savedSourceContent = _sourceFileContent; -///-- -///-- // Update the mainwindow title to show the name of the loaded source code file. -///-- updateWindowTitle(); -///-- } +/* + \brief Loads the last opened file if this option is enabled in the settings. + + If the file does not exist, the default example file is tried to be loaded. + If even that fails, a very small code example is shown. + If the setting for opening the last file is disabled, the editor is empty on startup. +*/ +void MainWindow::loadLastOpenedFile() +{ + // Get setting for last opened source code file. + m_loadLastSourceCodeFileOnStartup = + m_settings->getValueByName("LoadLastOpenedFileOnStartup").toBool(); + + // Only load last source code file if set to do so + if (m_loadLastSourceCodeFileOnStartup) + { + // From the list of last opened files get the first one. + TQString sourceFiles = m_settings->getValueByName("LastOpenedFiles").toString(); + m_currentSourceFile = TQStringList::split("|", sourceFiles).first(); + + if (TQFile::exists(m_currentSourceFile)) + { + // If source file exist load it. + TQFileInfo fileInfo(m_currentSourceFile); + m_currentSourceFile = fileInfo.absFilePath(); + m_sourceFileContent = loadFile(m_currentSourceFile); + } + else if (TQFile::exists(SettingsPaths::getIndenterPath() + "/example.cpp")) + { + // If the last opened source code file does not exist, try to load the default example.cpp file. + TQFileInfo fileInfo(SettingsPaths::getIndenterPath() + "/example.cpp"); + m_currentSourceFile = fileInfo.absFilePath(); + m_sourceFileContent = loadFile(m_currentSourceFile); + } + else + { + // If neither the example source code file exists show some small code example. + m_currentSourceFile = "untitled.cpp"; + m_currentSourceFileExtension = "cpp"; + m_sourceFileContent = "if(x==\"y\"){x=z;}"; + } + } + else + { + // if last opened source file should not be loaded make some default settings. + m_currentSourceFile = "untitled.cpp"; + m_currentSourceFileExtension = "cpp"; + m_sourceFileContent = ""; + } + m_savedSourceContent = m_sourceFileContent; + + // Update the mainwindow title to show the name of the loaded source code file. + updateWindowTitle(); +} /* \brief Saves the m_settings for the main application to the file "UniversalIndentGUI.ini". @@ -1290,13 +1293,13 @@ void MainWindow::encodingChanged(TQAction *encodingAction) { ///-- if (maybeSave()) ///-- { -///-- TQFile inSrcFile(_currentSourceFile); +///-- TQFile inSrcFile(m_currentSourceFile); ///-- TQString fileContent = ""; ///-- ///-- if (!inSrcFile.open(TQFile::ReadOnly | TQFile::Text)) ///-- { ///-- TQMessageBox::warning(NULL, tr("Error opening file"), tr( -///-- "Cannot read the file ") + "\"" + _currentSourceFile + "\"."); +///-- "Cannot read the file ") + "\"" + m_currentSourceFile + "\"."); ///-- } ///-- else ///-- { @@ -1449,7 +1452,7 @@ void MainWindow::updateRecentlyOpenedList() ///-- _mainWindowForm->menuRecently_Opened_Files->actions(); ///-- ///-- // Check if the currently open file is in the list of recently opened. -///-- int indexOfCurrentFile = recentlyOpenedList.indexOf(_currentSourceFile); +///-- int indexOfCurrentFile = recentlyOpenedList.indexOf(m_currentSourceFile); ///-- ///-- // If it is in the list of recently opened files and not at the first position, move it to the ///-- // first pos. @@ -1459,12 +1462,12 @@ void MainWindow::updateRecentlyOpenedList() ///-- recentlyOpenedActionList.move(indexOfCurrentFile, 0); ///-- } ///-- // Put the current file at the first position if it not already is and is not empty. -///-- else if (indexOfCurrentFile == -1 && !_currentSourceFile.isEmpty()) +///-- else if (indexOfCurrentFile == -1 && !m_currentSourceFile.isEmpty()) ///-- { -///-- recentlyOpenedList.insert(0, _currentSourceFile); +///-- recentlyOpenedList.insert(0, m_currentSourceFile); ///-- TQAction *recentlyOpenedAction = new TQAction(TQFileInfo( -///-- _currentSourceFile).fileName(), _mainWindowForm->menuRecently_Opened_Files); -///-- recentlyOpenedAction->setStatusTip(_currentSourceFile); +///-- m_currentSourceFile).fileName(), _mainWindowForm->menuRecently_Opened_Files); +///-- recentlyOpenedAction->setStatusTip(m_currentSourceFile); ///-- recentlyOpenedActionList.insert(0, recentlyOpenedAction); ///-- } ///-- |