Added code to load last open file or an example or an untitled file.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/3/head
Michele Calgaro 2 years ago
parent 11451cea9d
commit 425e16ad89
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -72,6 +72,7 @@ set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined"
add_subdirectory( config ) add_subdirectory( config )
add_subdirectory( icons ) add_subdirectory( icons )
add_subdirectory( indenters )
add_subdirectory( src ) add_subdirectory( src )

@ -0,0 +1,5 @@
install(
FILES
example.cpp
DESTINATION ${SHARE_INSTALL_PREFIX}/universal-indent-gui-tqt/indenters
)

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

@ -58,7 +58,7 @@ class MainWindow : public MainWindowBase
bool saveasSourceFileDialog(TQAction *chosenEncodingAction = NULL); bool saveasSourceFileDialog(TQAction *chosenEncodingAction = NULL);
void saveAsOtherEncoding(TQAction *chosenEncodingAction); void saveAsOtherEncoding(TQAction *chosenEncodingAction);
///-- void callIndenter(); ///-- void callIndenter();
///-- void updateSourceView(); void updateSourceView();
void turnHighlightOnOff(bool turnOn); void turnHighlightOnOff(bool turnOn);
void setWhiteSpaceVisibility(bool visible); void setWhiteSpaceVisibility(bool visible);
void sourceCodeChangedHelperSlot(); void sourceCodeChangedHelperSlot();
@ -75,12 +75,12 @@ class MainWindow : public MainWindowBase
void clearRecentlyOpenedList(); void clearRecentlyOpenedList();
void showAboutDialog(); void showAboutDialog();
void setStatusBarCursorPosInfo(int line, int column); void setStatusBarCursorPosInfo(int line, int column);
///--
private: private:
///-- TQString loadFile(TQString filePath); TQString loadFile(const TQString &filePath);
///-- TQString openFileDialog(TQString dialogHeaderStr, TQString startPath, TQString fileMaskStr); ///-- TQString openFileDialog(TQString dialogHeaderStr, TQString startPath, TQString fileMaskStr);
///-- void updateWindowTitle(); void updateWindowTitle();
///-- void loadLastOpenedFile(); void loadLastOpenedFile();
void saveSettings(); void saveSettings();
bool maybeSave(); bool maybeSave();
void createEncodingMenu(); void createEncodingMenu();
@ -94,41 +94,42 @@ class MainWindow : public MainWindowBase
///-- void changeEvent(TQEvent *event); ///-- void changeEvent(TQEvent *event);
///-- void dragEnterEvent(TQDragEnterEvent *event); ///-- void dragEnterEvent(TQDragEnterEvent *event);
///-- void dropEvent(TQDropEvent *event); ///-- void dropEvent(TQDropEvent *event);
///--
TQextScintilla *m_qSciSourceCodeEditor; TQextScintilla *m_qSciSourceCodeEditor;
UiGuiSettings *m_settings; UiGuiSettings *m_settings;
///--
TQString m_currentEncoding; TQString m_currentEncoding;
///-- TQString _sourceFileContent; TQString m_sourceFileContent;
///-- TQString _sourceFormattedContent; TQString m_sourceFormattedContent;
///-- TQString _sourceViewContent; TQString m_sourceViewContent;
///-- UiGuiHighlighter *m_highlighter; ///-- UiGuiHighlighter *m_highlighter;
///-- TQScrollBar *m_textEditVScrollBar; ///-- TQScrollBar *m_textEditVScrollBar;
AboutDialog *m_aboutDialog; AboutDialog *m_aboutDialog;
///-- AboutDialogGraphicsView *_aboutDialogGraphicsView; ///-- AboutDialogGraphicsView *_aboutDialogGraphicsView;
///-- UiGuiSettingsDialog *_settingsDialog; ///-- UiGuiSettingsDialog *_settingsDialog;
int m_actionClearRecentlyOpenedListId; int m_actionClearRecentlyOpenedListId;
///-- int _textEditLastScrollPos; ///-- int _textEditLastScrollPos;
///-- int _currentIndenterID; ///-- int _currentIndenterID;
int m_oldLinesNumber; int m_oldLinesNumber;
///-- bool _loadLastSourceCodeFileOnStartup; bool m_loadLastSourceCodeFileOnStartup;
///-- TQString _currentSourceFile; TQString m_currentSourceFile;
///-- TQString _currentSourceFileExtension; TQString m_currentSourceFileExtension;
///-- TQString _savedSourceContent; TQString m_savedSourceContent;
TQActionGroup *m_encodingActionGroup; TQActionGroup *m_encodingActionGroup;
TQActionGroup *m_saveEncodedActionGroup; TQActionGroup *m_saveEncodedActionGroup;
TQActionGroup *m_highlighterActionGroup; TQActionGroup *m_highlighterActionGroup;
TQTranslator *m_uiGuiTranslator; TQTranslator *m_uiGuiTranslator;
TQTranslator *m_qTranslator; TQTranslator *m_qTranslator;
///--
bool m_sourceCodeChanged; bool m_sourceCodeChanged;
///-- bool _indentSettingsChanged; ///-- bool _indentSettingsChanged;
///-- bool _previewToggled; bool m_previewToggled;
TQStringList m_encodingsList; bool m_documentModified;
TQStringList m_encodingsList;
ToolBarWidget *m_toolBarWidget; ToolBarWidget *m_toolBarWidget;
///-- IndentHandler *_indentHandler; ///-- IndentHandler *_indentHandler;
TQLabel *m_textEditLineColumnInfoLabel; TQLabel *m_textEditLineColumnInfoLabel;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

@ -13,9 +13,6 @@
<height>633</height> <height>633</height>
</rect> </rect>
</property> </property>
<property name="caption">
<string>UniversalIndentGUI (TQt)</string>
</property>
<hbox> <hbox>
<property name="name"> <property name="name">
<cstring>centralWidget</cstring> <cstring>centralWidget</cstring>

Loading…
Cancel
Save