From 425e16ad894fd23d7c5b061acffba6cd04a1b1db Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 18 Apr 2023 20:47:44 +0900 Subject: [PATCH] Added code to load last open file or an example or an untitled file. Signed-off-by: Michele Calgaro --- CMakeLists.txt | 1 + indenters/CMakeLists.txt | 5 + indenters/{ => __TODO}/JsDecoder.js | 0 indenters/{ => __TODO}/example.cbl | 0 indenters/{ => __TODO}/example.css | 0 indenters/{ => __TODO}/example.f90 | 0 indenters/{ => __TODO}/example.html | 0 indenters/{ => __TODO}/example.js | 0 indenters/{ => __TODO}/example.php | 0 indenters/{ => __TODO}/example.pl | 0 indenters/{ => __TODO}/example.py | 0 indenters/{ => __TODO}/example.rb | 0 indenters/{ => __TODO}/example.sh | 0 indenters/{ => __TODO}/example.sql | 0 indenters/{ => __TODO}/example.vb | 0 indenters/{ => __TODO}/example.xml | 0 indenters/{ => __TODO}/hindent | 0 indenters/{ => __TODO}/hindent.html | 0 indenters/{ => __TODO}/perltidy | 0 indenters/{ => __TODO}/phpStylist.php | 0 indenters/{ => __TODO}/phpStylist.txt | 0 indenters/{ => __TODO}/pindent.py | 0 indenters/{ => __TODO}/pindent.txt | 0 indenters/{ => __TODO}/rbeautify.rb | 0 indenters/{ => __TODO}/ruby_formatter.rb | 0 indenters/{ => __TODO}/shellindent.awk | 0 indenters/{ => __TODO}/uigui_CblBeau.ini | 0 indenters/{ => __TODO}/uigui_astyle.ini | 0 indenters/{ => __TODO}/uigui_bcpp.ini | 0 indenters/{ => __TODO}/uigui_csstidy.ini | 0 indenters/{ => __TODO}/uigui_f90ppr.ini | 0 indenters/{ => __TODO}/uigui_gnuindent.ini | 0 indenters/{ => __TODO}/uigui_greatcode.ini | 0 indenters/{ => __TODO}/uigui_hindent.ini | 0 indenters/{ => __TODO}/uigui_htb.ini | 0 indenters/{ => __TODO}/uigui_jsdecoder.ini | 0 indenters/{ => __TODO}/uigui_jsppp.ini | 0 indenters/{ => __TODO}/uigui_perltidy.ini | 0 indenters/{ => __TODO}/uigui_phpCB.ini | 0 indenters/{ => __TODO}/uigui_phpStylist.ini | 0 .../{ => __TODO}/uigui_php_Beautifier.ini | 0 indenters/{ => __TODO}/uigui_pindent.ini | 0 indenters/{ => __TODO}/uigui_psti.ini | 0 indenters/{ => __TODO}/uigui_rbeautify.ini | 0 .../{ => __TODO}/uigui_rubyformatter.ini | 0 indenters/{ => __TODO}/uigui_shellindent.ini | 0 indenters/{ => __TODO}/uigui_tidy.ini | 0 indenters/{ => __TODO}/uigui_uncrustify.ini | 0 indenters/{ => __TODO}/uigui_vbsbeaut.ini | 0 indenters/{ => __TODO}/uigui_xmlindent.ini | 0 src/MainWindow.cpp | 393 +++++++++--------- src/MainWindow.h | 57 +-- src/MainWindowBase.ui | 3 - 53 files changed, 233 insertions(+), 226 deletions(-) create mode 100644 indenters/CMakeLists.txt rename indenters/{ => __TODO}/JsDecoder.js (100%) rename indenters/{ => __TODO}/example.cbl (100%) rename indenters/{ => __TODO}/example.css (100%) rename indenters/{ => __TODO}/example.f90 (100%) rename indenters/{ => __TODO}/example.html (100%) rename indenters/{ => __TODO}/example.js (100%) rename indenters/{ => __TODO}/example.php (100%) rename indenters/{ => __TODO}/example.pl (100%) rename indenters/{ => __TODO}/example.py (100%) rename indenters/{ => __TODO}/example.rb (100%) rename indenters/{ => __TODO}/example.sh (100%) rename indenters/{ => __TODO}/example.sql (100%) rename indenters/{ => __TODO}/example.vb (100%) rename indenters/{ => __TODO}/example.xml (100%) rename indenters/{ => __TODO}/hindent (100%) rename indenters/{ => __TODO}/hindent.html (100%) rename indenters/{ => __TODO}/perltidy (100%) rename indenters/{ => __TODO}/phpStylist.php (100%) rename indenters/{ => __TODO}/phpStylist.txt (100%) rename indenters/{ => __TODO}/pindent.py (100%) rename indenters/{ => __TODO}/pindent.txt (100%) rename indenters/{ => __TODO}/rbeautify.rb (100%) rename indenters/{ => __TODO}/ruby_formatter.rb (100%) rename indenters/{ => __TODO}/shellindent.awk (100%) rename indenters/{ => __TODO}/uigui_CblBeau.ini (100%) rename indenters/{ => __TODO}/uigui_astyle.ini (100%) rename indenters/{ => __TODO}/uigui_bcpp.ini (100%) rename indenters/{ => __TODO}/uigui_csstidy.ini (100%) rename indenters/{ => __TODO}/uigui_f90ppr.ini (100%) rename indenters/{ => __TODO}/uigui_gnuindent.ini (100%) rename indenters/{ => __TODO}/uigui_greatcode.ini (100%) rename indenters/{ => __TODO}/uigui_hindent.ini (100%) rename indenters/{ => __TODO}/uigui_htb.ini (100%) rename indenters/{ => __TODO}/uigui_jsdecoder.ini (100%) rename indenters/{ => __TODO}/uigui_jsppp.ini (100%) rename indenters/{ => __TODO}/uigui_perltidy.ini (100%) rename indenters/{ => __TODO}/uigui_phpCB.ini (100%) rename indenters/{ => __TODO}/uigui_phpStylist.ini (100%) rename indenters/{ => __TODO}/uigui_php_Beautifier.ini (100%) rename indenters/{ => __TODO}/uigui_pindent.ini (100%) rename indenters/{ => __TODO}/uigui_psti.ini (100%) rename indenters/{ => __TODO}/uigui_rbeautify.ini (100%) rename indenters/{ => __TODO}/uigui_rubyformatter.ini (100%) rename indenters/{ => __TODO}/uigui_shellindent.ini (100%) rename indenters/{ => __TODO}/uigui_tidy.ini (100%) rename indenters/{ => __TODO}/uigui_uncrustify.ini (100%) rename indenters/{ => __TODO}/uigui_vbsbeaut.ini (100%) rename indenters/{ => __TODO}/uigui_xmlindent.ini (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f8fac1..d4000d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" add_subdirectory( config ) add_subdirectory( icons ) +add_subdirectory( indenters ) add_subdirectory( src ) diff --git a/indenters/CMakeLists.txt b/indenters/CMakeLists.txt new file mode 100644 index 0000000..c0ae4b6 --- /dev/null +++ b/indenters/CMakeLists.txt @@ -0,0 +1,5 @@ +install( + FILES + example.cpp + DESTINATION ${SHARE_INSTALL_PREFIX}/universal-indent-gui-tqt/indenters +) diff --git a/indenters/JsDecoder.js b/indenters/__TODO/JsDecoder.js similarity index 100% rename from indenters/JsDecoder.js rename to indenters/__TODO/JsDecoder.js diff --git a/indenters/example.cbl b/indenters/__TODO/example.cbl similarity index 100% rename from indenters/example.cbl rename to indenters/__TODO/example.cbl diff --git a/indenters/example.css b/indenters/__TODO/example.css similarity index 100% rename from indenters/example.css rename to indenters/__TODO/example.css diff --git a/indenters/example.f90 b/indenters/__TODO/example.f90 similarity index 100% rename from indenters/example.f90 rename to indenters/__TODO/example.f90 diff --git a/indenters/example.html b/indenters/__TODO/example.html similarity index 100% rename from indenters/example.html rename to indenters/__TODO/example.html diff --git a/indenters/example.js b/indenters/__TODO/example.js similarity index 100% rename from indenters/example.js rename to indenters/__TODO/example.js diff --git a/indenters/example.php b/indenters/__TODO/example.php similarity index 100% rename from indenters/example.php rename to indenters/__TODO/example.php diff --git a/indenters/example.pl b/indenters/__TODO/example.pl similarity index 100% rename from indenters/example.pl rename to indenters/__TODO/example.pl diff --git a/indenters/example.py b/indenters/__TODO/example.py similarity index 100% rename from indenters/example.py rename to indenters/__TODO/example.py diff --git a/indenters/example.rb b/indenters/__TODO/example.rb similarity index 100% rename from indenters/example.rb rename to indenters/__TODO/example.rb diff --git a/indenters/example.sh b/indenters/__TODO/example.sh similarity index 100% rename from indenters/example.sh rename to indenters/__TODO/example.sh diff --git a/indenters/example.sql b/indenters/__TODO/example.sql similarity index 100% rename from indenters/example.sql rename to indenters/__TODO/example.sql diff --git a/indenters/example.vb b/indenters/__TODO/example.vb similarity index 100% rename from indenters/example.vb rename to indenters/__TODO/example.vb diff --git a/indenters/example.xml b/indenters/__TODO/example.xml similarity index 100% rename from indenters/example.xml rename to indenters/__TODO/example.xml diff --git a/indenters/hindent b/indenters/__TODO/hindent similarity index 100% rename from indenters/hindent rename to indenters/__TODO/hindent diff --git a/indenters/hindent.html b/indenters/__TODO/hindent.html similarity index 100% rename from indenters/hindent.html rename to indenters/__TODO/hindent.html diff --git a/indenters/perltidy b/indenters/__TODO/perltidy similarity index 100% rename from indenters/perltidy rename to indenters/__TODO/perltidy diff --git a/indenters/phpStylist.php b/indenters/__TODO/phpStylist.php similarity index 100% rename from indenters/phpStylist.php rename to indenters/__TODO/phpStylist.php diff --git a/indenters/phpStylist.txt b/indenters/__TODO/phpStylist.txt similarity index 100% rename from indenters/phpStylist.txt rename to indenters/__TODO/phpStylist.txt diff --git a/indenters/pindent.py b/indenters/__TODO/pindent.py similarity index 100% rename from indenters/pindent.py rename to indenters/__TODO/pindent.py diff --git a/indenters/pindent.txt b/indenters/__TODO/pindent.txt similarity index 100% rename from indenters/pindent.txt rename to indenters/__TODO/pindent.txt diff --git a/indenters/rbeautify.rb b/indenters/__TODO/rbeautify.rb similarity index 100% rename from indenters/rbeautify.rb rename to indenters/__TODO/rbeautify.rb diff --git a/indenters/ruby_formatter.rb b/indenters/__TODO/ruby_formatter.rb similarity index 100% rename from indenters/ruby_formatter.rb rename to indenters/__TODO/ruby_formatter.rb diff --git a/indenters/shellindent.awk b/indenters/__TODO/shellindent.awk similarity index 100% rename from indenters/shellindent.awk rename to indenters/__TODO/shellindent.awk diff --git a/indenters/uigui_CblBeau.ini b/indenters/__TODO/uigui_CblBeau.ini similarity index 100% rename from indenters/uigui_CblBeau.ini rename to indenters/__TODO/uigui_CblBeau.ini diff --git a/indenters/uigui_astyle.ini b/indenters/__TODO/uigui_astyle.ini similarity index 100% rename from indenters/uigui_astyle.ini rename to indenters/__TODO/uigui_astyle.ini diff --git a/indenters/uigui_bcpp.ini b/indenters/__TODO/uigui_bcpp.ini similarity index 100% rename from indenters/uigui_bcpp.ini rename to indenters/__TODO/uigui_bcpp.ini diff --git a/indenters/uigui_csstidy.ini b/indenters/__TODO/uigui_csstidy.ini similarity index 100% rename from indenters/uigui_csstidy.ini rename to indenters/__TODO/uigui_csstidy.ini diff --git a/indenters/uigui_f90ppr.ini b/indenters/__TODO/uigui_f90ppr.ini similarity index 100% rename from indenters/uigui_f90ppr.ini rename to indenters/__TODO/uigui_f90ppr.ini diff --git a/indenters/uigui_gnuindent.ini b/indenters/__TODO/uigui_gnuindent.ini similarity index 100% rename from indenters/uigui_gnuindent.ini rename to indenters/__TODO/uigui_gnuindent.ini diff --git a/indenters/uigui_greatcode.ini b/indenters/__TODO/uigui_greatcode.ini similarity index 100% rename from indenters/uigui_greatcode.ini rename to indenters/__TODO/uigui_greatcode.ini diff --git a/indenters/uigui_hindent.ini b/indenters/__TODO/uigui_hindent.ini similarity index 100% rename from indenters/uigui_hindent.ini rename to indenters/__TODO/uigui_hindent.ini diff --git a/indenters/uigui_htb.ini b/indenters/__TODO/uigui_htb.ini similarity index 100% rename from indenters/uigui_htb.ini rename to indenters/__TODO/uigui_htb.ini diff --git a/indenters/uigui_jsdecoder.ini b/indenters/__TODO/uigui_jsdecoder.ini similarity index 100% rename from indenters/uigui_jsdecoder.ini rename to indenters/__TODO/uigui_jsdecoder.ini diff --git a/indenters/uigui_jsppp.ini b/indenters/__TODO/uigui_jsppp.ini similarity index 100% rename from indenters/uigui_jsppp.ini rename to indenters/__TODO/uigui_jsppp.ini diff --git a/indenters/uigui_perltidy.ini b/indenters/__TODO/uigui_perltidy.ini similarity index 100% rename from indenters/uigui_perltidy.ini rename to indenters/__TODO/uigui_perltidy.ini diff --git a/indenters/uigui_phpCB.ini b/indenters/__TODO/uigui_phpCB.ini similarity index 100% rename from indenters/uigui_phpCB.ini rename to indenters/__TODO/uigui_phpCB.ini diff --git a/indenters/uigui_phpStylist.ini b/indenters/__TODO/uigui_phpStylist.ini similarity index 100% rename from indenters/uigui_phpStylist.ini rename to indenters/__TODO/uigui_phpStylist.ini diff --git a/indenters/uigui_php_Beautifier.ini b/indenters/__TODO/uigui_php_Beautifier.ini similarity index 100% rename from indenters/uigui_php_Beautifier.ini rename to indenters/__TODO/uigui_php_Beautifier.ini diff --git a/indenters/uigui_pindent.ini b/indenters/__TODO/uigui_pindent.ini similarity index 100% rename from indenters/uigui_pindent.ini rename to indenters/__TODO/uigui_pindent.ini diff --git a/indenters/uigui_psti.ini b/indenters/__TODO/uigui_psti.ini similarity index 100% rename from indenters/uigui_psti.ini rename to indenters/__TODO/uigui_psti.ini diff --git a/indenters/uigui_rbeautify.ini b/indenters/__TODO/uigui_rbeautify.ini similarity index 100% rename from indenters/uigui_rbeautify.ini rename to indenters/__TODO/uigui_rbeautify.ini diff --git a/indenters/uigui_rubyformatter.ini b/indenters/__TODO/uigui_rubyformatter.ini similarity index 100% rename from indenters/uigui_rubyformatter.ini rename to indenters/__TODO/uigui_rubyformatter.ini diff --git a/indenters/uigui_shellindent.ini b/indenters/__TODO/uigui_shellindent.ini similarity index 100% rename from indenters/uigui_shellindent.ini rename to indenters/__TODO/uigui_shellindent.ini diff --git a/indenters/uigui_tidy.ini b/indenters/__TODO/uigui_tidy.ini similarity index 100% rename from indenters/uigui_tidy.ini rename to indenters/__TODO/uigui_tidy.ini diff --git a/indenters/uigui_uncrustify.ini b/indenters/__TODO/uigui_uncrustify.ini similarity index 100% rename from indenters/uigui_uncrustify.ini rename to indenters/__TODO/uigui_uncrustify.ini diff --git a/indenters/uigui_vbsbeaut.ini b/indenters/__TODO/uigui_vbsbeaut.ini similarity index 100% rename from indenters/uigui_vbsbeaut.ini rename to indenters/__TODO/uigui_vbsbeaut.ini diff --git a/indenters/uigui_xmlindent.ini b/indenters/__TODO/uigui_xmlindent.ini similarity index 100% rename from indenters/uigui_xmlindent.ini rename to indenters/__TODO/uigui_xmlindent.ini 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 #include #include +#include +#include +#include #include #include #include @@ -44,6 +47,7 @@ #include #include #include +#include #include ///-- #include ///-- #include @@ -57,7 +61,6 @@ ///-- #include ///-- #include ///-- #include -///-- #include ///-- #include ///-- #include ///-- #include @@ -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); ///-- } ///-- diff --git a/src/MainWindow.h b/src/MainWindow.h index d00e141..773c1ec 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -58,7 +58,7 @@ class MainWindow : public MainWindowBase bool saveasSourceFileDialog(TQAction *chosenEncodingAction = NULL); void saveAsOtherEncoding(TQAction *chosenEncodingAction); ///-- void callIndenter(); -///-- void updateSourceView(); + void updateSourceView(); void turnHighlightOnOff(bool turnOn); void setWhiteSpaceVisibility(bool visible); void sourceCodeChangedHelperSlot(); @@ -75,12 +75,12 @@ class MainWindow : public MainWindowBase void clearRecentlyOpenedList(); void showAboutDialog(); void setStatusBarCursorPosInfo(int line, int column); -///-- + private: -///-- TQString loadFile(TQString filePath); + TQString loadFile(const TQString &filePath); ///-- TQString openFileDialog(TQString dialogHeaderStr, TQString startPath, TQString fileMaskStr); -///-- void updateWindowTitle(); -///-- void loadLastOpenedFile(); + void updateWindowTitle(); + void loadLastOpenedFile(); void saveSettings(); bool maybeSave(); void createEncodingMenu(); @@ -94,41 +94,42 @@ class MainWindow : public MainWindowBase ///-- void changeEvent(TQEvent *event); ///-- void dragEnterEvent(TQDragEnterEvent *event); ///-- void dropEvent(TQDropEvent *event); -///-- + TQextScintilla *m_qSciSourceCodeEditor; UiGuiSettings *m_settings; -///-- - TQString m_currentEncoding; -///-- TQString _sourceFileContent; -///-- TQString _sourceFormattedContent; -///-- TQString _sourceViewContent; + + TQString m_currentEncoding; + TQString m_sourceFileContent; + TQString m_sourceFormattedContent; + TQString m_sourceViewContent; ///-- UiGuiHighlighter *m_highlighter; ///-- TQScrollBar *m_textEditVScrollBar; - AboutDialog *m_aboutDialog; + AboutDialog *m_aboutDialog; ///-- AboutDialogGraphicsView *_aboutDialogGraphicsView; ///-- UiGuiSettingsDialog *_settingsDialog; int m_actionClearRecentlyOpenedListId; ///-- int _textEditLastScrollPos; ///-- int _currentIndenterID; - int m_oldLinesNumber; -///-- bool _loadLastSourceCodeFileOnStartup; -///-- TQString _currentSourceFile; -///-- TQString _currentSourceFileExtension; -///-- TQString _savedSourceContent; - TQActionGroup *m_encodingActionGroup; - TQActionGroup *m_saveEncodedActionGroup; - TQActionGroup *m_highlighterActionGroup; - TQTranslator *m_uiGuiTranslator; - TQTranslator *m_qTranslator; -///-- - bool m_sourceCodeChanged; + int m_oldLinesNumber; + bool m_loadLastSourceCodeFileOnStartup; + TQString m_currentSourceFile; + TQString m_currentSourceFileExtension; + TQString m_savedSourceContent; + TQActionGroup *m_encodingActionGroup; + TQActionGroup *m_saveEncodedActionGroup; + TQActionGroup *m_highlighterActionGroup; + TQTranslator *m_uiGuiTranslator; + TQTranslator *m_qTranslator; + + bool m_sourceCodeChanged; ///-- bool _indentSettingsChanged; -///-- bool _previewToggled; - TQStringList m_encodingsList; + bool m_previewToggled; + bool m_documentModified; + TQStringList m_encodingsList; - ToolBarWidget *m_toolBarWidget; + ToolBarWidget *m_toolBarWidget; ///-- IndentHandler *_indentHandler; - TQLabel *m_textEditLineColumnInfoLabel; + TQLabel *m_textEditLineColumnInfoLabel; }; #endif // MAINWINDOW_H diff --git a/src/MainWindowBase.ui b/src/MainWindowBase.ui index 676b6f1..6b55170 100755 --- a/src/MainWindowBase.ui +++ b/src/MainWindowBase.ui @@ -13,9 +13,6 @@ 633 - - UniversalIndentGUI (TQt) - centralWidget