From b4d35ab97d008c3b24a109640d90dba73215631b Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 8 Apr 2023 14:41:17 +0900 Subject: [PATCH] Settings for syntax highlighting, showing whitespaces and loading last open file are now saved and restored across executions Signed-off-by: Michele Calgaro --- CHANGELOG.txt | 4 +- src/MainWindow.cpp | 286 +++++++++++++++++--------------- src/MainWindow.h | 15 +- src/MainWindowBase.ui | 4 +- src/ToolBarWidget.ui | 2 +- src/UiGuiSettings.cpp | 49 +++++- src/UiGuiSettings.h | 11 +- src/__TODO/UiGuiHighlighter.cpp | 8 +- src/__TODO/UiGuiHighlighter.h | 2 +- 9 files changed, 218 insertions(+), 163 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2e49704..1ff0c82 100755 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -174,7 +174,7 @@ [fix] The editors column showing the line numbers did not adapt its width to the maximum line number. 2007-03-19 Version 0.5.1 Beta -[add] Supporting syntax highlightning for the programming language D. +[add] Supporting syntax highlighting for the programming language D. [change] The live typing and indenting feature was not adapted to QScintilla. Now works again (depending on the used indenter). [fix] Bug ID 1678783 : Files other encoded than ascii were not displayed correctly. Now allways displaying files using UTF-8 encoding. [fix] Bug ID 1678783 : The new syntax highlighter selection menu was not translated. @@ -182,7 +182,7 @@ 2007-03-14 Version 0.5.0 Beta [add/change] Using QScintilla as editing component, which is by far more mighty than the before uses QTextEdit. Have a look inside the development area for details. -[add] Because of QScintilla, added syntax highlightning for bash, batch, cpp, csharp, css, diff, html, idl, java, javascript, lua, makefile, perl, pov, ini, python, ruby, sql and tex. +[add] Because of QScintilla, added syntax highlighting for bash, batch, cpp, csharp, css, diff, html, idl, java, javascript, lua, makefile, perl, pov, ini, python, ruby, sql and tex. [add] Also added code folding for previously mentioned languages. [add] Added support for the indenter "phpCB" phpCodeBeatufier. (Thanks to Nelson Tai) The executable is not included in the UiGui release, because I am not sure about the license of phpCB right now. [add] The output of an indenter can now be read from stdout, by setting "stdout" for "outputFileParameter". diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 38e893b..496636d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -58,7 +58,7 @@ ///-- #include ///-- #include ///-- -///-- #include +#include ///-- #include ///-- ///-- using namespace tschweitzer; @@ -79,16 +79,15 @@ \brief Constructs the main window. */ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : - MainWindowBase(parent), m_aboutDialog(NULL) -///- _mainWindowForm(NULL), _qSciSourceCodeEditor(NULL), _settings(NULL), + MainWindowBase(parent), m_aboutDialog(NULL), m_qSciSourceCodeEditor(NULL) +///- _mainWindowForm(NULL), _settings(NULL), ///- _highlighter(NULL), _textEditVScrollBar(NULL), _aboutDialogGraphicsView( ///- NULL), _settingsDialog(NULL), _encodingActionGroup(NULL), _saveEncodedActionGroup(NULL), ///- _highlighterActionGroup(NULL), _uiGuiTranslator(NULL), _qTTranslator(NULL), _toolBarWidget( ///- NULL), _indentHandler(NULL), _textEditLineColumnInfoLabel(NULL) { -///-- // Init of some variables. -///-- _sourceCodeChanged = false; -///-- _scrollPositionChanged = false; + // Init of some variables. + m_sourceCodeChanged = false; // Create the _settings object, which loads all UiGui settings from a file. m_settings = UiGuiSettings::getInstance(); @@ -197,22 +196,39 @@ void MainWindow::initMainWindow() showMaximized(); } -///-- // Get last selected file encoding -///-- // ------------------------------- -///-- _currentEncoding = _settings->getValueByName("encoding").toString(); -///-- -///-- // Register the load last file setting in the menu to the _settings object. -///-- _settings->registerObjectProperty(actionLoadLastOpenedFileOnStartup, "checked", -///-- "loadLastSourceCodeFileOnStartup"); -///-- -///-- // Tell the TQScintilla editor if it has to show white space. -///-- connect(_mainWindowForm->actionWhiteSpaceIsVisible, SIGNAL(acivated(bool)), this, -///-- SLOT(setWhiteSpaceVisibility(bool))); -///-- // Register the white space setting in the menu to the _settings object. -///-- _settings->registerObjectProperty(actionWhiteSpaceIsVisible, "checked", -///-- "whiteSpaceIsVisible"); -///-- -///-- // Connect the remaining menu items. + // Get last selected file encoding + // ------------------------------- + m_currentEncoding = m_settings->getValueByName("FileEncoding").toString(); + + // Register the syntax highlighting setting in the menu to the settings object. + connect(actionEnableSyntaxHighlighting, SIGNAL(toggled(bool)), + m_settings, SLOT(handleValueChangeFromExtern(bool))); + connect(m_settings, SIGNAL(syntaxHighlightingEnabled(bool)), + actionEnableSyntaxHighlighting, SLOT(setOn(bool))); + actionEnableSyntaxHighlighting->setOn( + m_settings->getValueByName("SyntaxHighlightingEnabled").toBool()); + // Tell the highlighter if it has to be enabled or disabled. + connect(m_settings, SIGNAL(syntaxHighlightingEnabled(bool)), this, SLOT(turnHighlightOnOff(bool))); + + // Register the load last file setting in the menu to the settings object + connect(actionLoadLastOpenedFileOnStartup, SIGNAL(toggled(bool)), + m_settings, SLOT(handleValueChangeFromExtern(bool))); + connect(m_settings, SIGNAL(loadLastOpenedFileOnStartup(bool)), + actionLoadLastOpenedFileOnStartup, SLOT(setOn(bool))); + actionLoadLastOpenedFileOnStartup->setOn( + m_settings->getValueByName("LoadLastOpenedFileOnStartup").toBool()); + + // Register the white space setting in the menu to the settings object. + connect(actionWhiteSpaceIsVisible, SIGNAL(toggled(bool)), + m_settings, SLOT(handleValueChangeFromExtern(bool))); + connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)), + actionWhiteSpaceIsVisible, SLOT(setOn(bool))); + actionWhiteSpaceIsVisible->setOn(m_settings->getValueByName("WhiteSpaceIsVisible").toBool()); + + // Tell the TQScintilla editor if it has to show white space. + connect(m_settings, SIGNAL(whiteSpaceIsVisible(bool)), this, SLOT(setWhiteSpaceVisibility(bool))); + + // Connect the remaining menu items. connect(actionOpenSourceFile, SIGNAL(activated()), this, SLOT(openSourceFileDialog())); connect(actionSaveSourceFile, SIGNAL(activated()), this, SLOT(saveSourceFile())); connect(actionSaveSourceFileAs, SIGNAL(activated()), this, SLOT(saveasSourceFileDialog())); @@ -278,7 +294,7 @@ void MainWindow::initToolBar() ///-- // TQScintilla debug lib and the other way around. ///-- try ///-- { -///-- _qSciSourceCodeEditor = new QsciScintilla(this); +///-- m_qSciSourceCodeEditor = new QsciScintilla(this); ///-- } ///-- catch (...) ///-- { @@ -286,17 +302,17 @@ void MainWindow::initToolBar() ///-- "During trying to create the text editor component, that is based on TQScintilla, an error occurred. Please make sure that you have installed TQScintilla and not mixed release and debug versions."); ///-- exit(1); ///-- } -///-- _mainWindowForm->hboxLayout1->addWidget(_qSciSourceCodeEditor); +///-- _mainWindowForm->hboxLayout1->addWidget(m_qSciSourceCodeEditor); ///-- ///-- // Make some _settings for the TQScintilla widget. -///-- _qSciSourceCodeEditor->setUtf8(true); -///-- _qSciSourceCodeEditor->setMarginLineNumbers(1, true); -///-- _qSciSourceCodeEditor->setMarginWidth(1, TQString("10000")); -///-- _qSciSourceCodeEditor->setBraceMatching(_qSciSourceCodeEditor->SloppyBraceMatch); -///-- _qSciSourceCodeEditor->setMatchedBraceForegroundColor(TQColor("red")); -///-- _qSciSourceCodeEditor->setFolding(QsciScintilla::BoxedTreeFoldStyle); -///-- _qSciSourceCodeEditor->setAutoCompletionSource(QsciScintilla::AcsAll); -///-- _qSciSourceCodeEditor->setAutoCompletionThreshold(3); +///-- m_qSciSourceCodeEditor->setUtf8(true); +///-- m_qSciSourceCodeEditor->setMarginLineNumbers(1, true); +///-- m_qSciSourceCodeEditor->setMarginWidth(1, TQString("10000")); +///-- m_qSciSourceCodeEditor->setBraceMatching(m_qSciSourceCodeEditor->SloppyBraceMatch); +///-- m_qSciSourceCodeEditor->setMatchedBraceForegroundColor(TQColor("red")); +///-- m_qSciSourceCodeEditor->setFolding(QsciScintilla::BoxedTreeFoldStyle); +///-- m_qSciSourceCodeEditor->setAutoCompletionSource(QsciScintilla::AcsAll); +///-- m_qSciSourceCodeEditor->setAutoCompletionThreshold(3); ///-- ///-- // Handle if white space is set to be visible ///-- bool whiteSpaceIsVisible = _settings->getValueByName("whiteSpaceIsVisible").toBool(); @@ -304,24 +320,24 @@ void MainWindow::initToolBar() ///-- ///-- // Handle the width of tabs in spaces ///-- int tabWidth = _settings->getValueByName("tabWidth").toInt(); -///-- _qSciSourceCodeEditor->setTabWidth(tabWidth); +///-- m_qSciSourceCodeEditor->setTabWidth(tabWidth); ///-- ///-- // Remember a pointer to the scrollbar of the TQScintilla widget used to keep ///-- // on the same line as before when turning preview on/off. -///-- _textEditVScrollBar = _qSciSourceCodeEditor->verticalScrollBar(); +///-- _textEditVScrollBar = m_qSciSourceCodeEditor->verticalScrollBar(); ///-- ///-- // Add a column row indicator to the status bar. ///-- _textEditLineColumnInfoLabel = new TQLabel(tr("Line %1, Column %2").arg(1).arg(1)); ///-- _mainWindowForm->statusbar->addPermanentWidget(_textEditLineColumnInfoLabel); -///-- connect(_qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int,int)), this, +///-- connect(m_qSciSourceCodeEditor, SIGNAL(cursorPositionChanged(int,int)), this, ///-- SLOT(setStatusBarCursorPosInfo(int, int))); ///-- ///-- // Connect the text editor to dependent functions. -///-- connect(_qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot())); -///-- connect(_qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged())); -///-- //connect( _settings, SIGNAL(tabWidth(int)), _qSciSourceCodeEditor, SLOT(setTabWidth(int)) ); -///-- _settings->registerObjectSlot(_qSciSourceCodeEditor, "setTabWidth(int)", "tabWidth"); -///-- _qSciSourceCodeEditor->setTabWidth(_settings->getValueByName("tabWidth").toInt()); +///-- connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, SLOT(sourceCodeChangedHelperSlot())); +///-- connect(m_qSciSourceCodeEditor, SIGNAL(linesChanged()), this, SLOT(numberOfLinesChanged())); +///-- //connect( _settings, SIGNAL(tabWidth(int)), m_qSciSourceCodeEditor, SLOT(setTabWidth(int)) ); +///-- _settings->registerObjectSlot(m_qSciSourceCodeEditor, "setTabWidth(int)", "tabWidth"); +///-- m_qSciSourceCodeEditor->setTabWidth(_settings->getValueByName("tabWidth").toInt()); ///-- } ///-- ///-- /* @@ -330,7 +346,7 @@ void MainWindow::initToolBar() ///-- void MainWindow::initSyntaxHighlighter() ///-- { ///-- // Create the _highlighter. -///-- _highlighter = new UiGuiHighlighter(_qSciSourceCodeEditor); +///-- _highlighter = new UiGuiHighlighter(m_qSciSourceCodeEditor); ///-- ///-- // Connect the syntax highlighting setting in the menu to the turnHighlightOnOff function. ///-- connect(actionEnableSyntaxHighlighting, SIGNAL(activated(bool)), this, @@ -457,7 +473,7 @@ void MainWindow::initToolBar() ///-- { ///-- TQTextStream inSrcStrm(&inSrcFile); ///-- TQApplication::setOverrideCursor(TQt::WaitCursor); -///-- inSrcStrm.setCodec(TQTextCodec::codecForName(_currentEncoding.toAscii())); +///-- inSrcStrm.setCodec(TQTextCodec::codecForName(m_currentEncoding.toAscii())); ///-- fileContent = inSrcStrm.readAll(); ///-- TQApplication::restoreOverrideCursor(); ///-- inSrcFile.close(); @@ -506,7 +522,7 @@ void MainWindow::openSourceFileDialog(TQString fileName) ///-- { ///-- callIndenter(); ///-- } -///-- _sourceCodeChanged = true; +///-- m_sourceCodeChanged = true; ///-- _previewToggled = true; ///-- updateSourceView(); ///-- updateWindowTitle(); @@ -515,7 +531,7 @@ void MainWindow::openSourceFileDialog(TQString fileName) ///-- _textEditVScrollBar->setValue(_textEditLastScrollPos); ///-- ///-- _savedSourceContent = openedSourceFileContent; -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- } } @@ -541,7 +557,7 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- return false; ///-- } ///-- -///-- _savedSourceContent = _qSciSourceCodeEditor->text(); +///-- _savedSourceContent = m_qSciSourceCodeEditor->text(); ///-- ///-- _currentSourceFile = fileName; ///-- TQFile::remove(fileName); @@ -565,7 +581,7 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) ///-- TQFileInfo fileInfo(fileName); ///-- _currentSourceFileExtension = fileInfo.suffix(); ///-- -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- ///-- updateWindowTitle(); @@ -587,17 +603,17 @@ bool MainWindow::saveSourceFile() ///-- { ///-- TQFile::remove(_currentSourceFile); ///-- TQFile outSrcFile(_currentSourceFile); -///-- _savedSourceContent = _qSciSourceCodeEditor->text(); +///-- _savedSourceContent = m_qSciSourceCodeEditor->text(); ///-- outSrcFile.open(TQFile::ReadWrite | TQFile::Text); ///-- ///-- // Get current encoding. -///-- TQString _currentEncoding = _encodingActionGroup->checkedAction()->text(); +///-- TQString m_currentEncoding = _encodingActionGroup->checkedAction()->text(); ///-- TQTextStream outSrcStrm(&outSrcFile); -///-- outSrcStrm.setCodec(TQTextCodec::codecForName(_currentEncoding.toAscii())); +///-- outSrcStrm.setCodec(TQTextCodec::codecForName(m_currentEncoding.toAscii())); ///-- outSrcStrm << _savedSourceContent; ///-- outSrcFile.close(); ///-- -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- } return true; @@ -646,13 +662,13 @@ bool MainWindow::saveSourceFile() ///-- ///-- if (_previewToggled) ///-- { -///-- disconnect(_qSciSourceCodeEditor, SIGNAL(textChanged()), this, +///-- disconnect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, ///-- SLOT(sourceCodeChangedHelperSlot())); ///-- bool textIsModified = isWindowModified(); -///-- _qSciSourceCodeEditor->setText(_sourceViewContent); +///-- m_qSciSourceCodeEditor->setText(_sourceViewContent); ///-- setWindowModified(textIsModified); ///-- _previewToggled = false; -///-- connect(_qSciSourceCodeEditor, SIGNAL(textChanged()), this, +///-- connect(m_qSciSourceCodeEditor, SIGNAL(textChanged()), this, ///-- SLOT(sourceCodeChangedHelperSlot())); ///-- } ///-- @@ -672,12 +688,12 @@ bool MainWindow::saveSourceFile() ///-- //updateSourceView(); ///-- TQApplication::restoreOverrideCursor(); ///-- } -///-- -///-- /* -///-- \brief Switches the syntax highlighting corresponding to the value \a turnOn either on or off. -///-- */ -///-- void MainWindow::turnHighlightOnOff(bool turnOn) -///-- { + +/* + \brief Switches the syntax highlighting corresponding to the value \a turnOn either on or off. + */ +void MainWindow::turnHighlightOnOff(bool turnOn) +{ ///-- if (turnOn) ///-- { ///-- _highlighter->turnHighlightOn(); @@ -688,8 +704,8 @@ bool MainWindow::saveSourceFile() ///-- } ///-- _previewToggled = true; ///-- updateSourceView(); -///-- } -///-- +} + ///-- /* ///-- \brief Added this slot to avoid multiple calls because of changed text. ///-- */ @@ -708,14 +724,10 @@ bool MainWindow::saveSourceFile() ///-- int cursorPos, cursorPosAbsolut, cursorLine; ///-- TQString text; ///-- -///-- _sourceCodeChanged = true; -///-- if (_scrollPositionChanged) -///-- { -///-- _scrollPositionChanged = false; -///-- } +///-- m_sourceCodeChanged = true; ///-- ///-- // Get the content text of the text editor. -///-- _sourceFileContent = _qSciSourceCodeEditor->text(); +///-- _sourceFileContent = m_qSciSourceCodeEditor->text(); ///-- ///-- // Get the position of the cursor in the unindented text. ///-- if (_sourceFileContent.isEmpty()) @@ -729,9 +741,9 @@ bool MainWindow::saveSourceFile() ///-- } ///-- else ///-- { -///-- _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); -///-- cursorPosAbsolut = _qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); -///-- text = _qSciSourceCodeEditor->text(cursorLine); +///-- m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); +///-- cursorPosAbsolut = m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_GETCURRENTPOS); +///-- text = m_qSciSourceCodeEditor->text(cursorLine); ///-- if (cursorPosAbsolut > 0) ///-- { ///-- cursorPosAbsolut--; @@ -765,10 +777,10 @@ bool MainWindow::saveSourceFile() ///-- ///-- // Search forward ///-- for (cursorLine = saveCursorLine; -///-- cursorLine - saveCursorLine < 6 && cursorLine < _qSciSourceCodeEditor->lines(); +///-- cursorLine - saveCursorLine < 6 && cursorLine < m_qSciSourceCodeEditor->lines(); ///-- cursorLine++) ///-- { -///-- text = _qSciSourceCodeEditor->text(cursorLine); +///-- text = m_qSciSourceCodeEditor->text(cursorLine); ///-- while (cursorPos < text.count() && enteredCharacter != text.at(cursorPos)) ///-- { ///-- cursorPos++; @@ -787,7 +799,7 @@ bool MainWindow::saveSourceFile() ///-- // If foward search did not find the character, search backward ///-- if (!charFound) ///-- { -///-- text = _qSciSourceCodeEditor->text(saveCursorLine); +///-- text = m_qSciSourceCodeEditor->text(saveCursorLine); ///-- cursorPos = saveCursorPos; ///-- if (cursorPos >= text.count()) ///-- { @@ -797,14 +809,14 @@ bool MainWindow::saveSourceFile() ///-- for (cursorLine = saveCursorLine; saveCursorLine - cursorLine < 6 && cursorLine >= 0; ///-- cursorLine--) ///-- { -///-- text = _qSciSourceCodeEditor->text(cursorLine); +///-- text = m_qSciSourceCodeEditor->text(cursorLine); ///-- while (cursorPos >= 0 && enteredCharacter != text.at(cursorPos)) ///-- { ///-- cursorPos--; ///-- } ///-- if (cursorPos < 0) ///-- { -///-- cursorPos = _qSciSourceCodeEditor->lineLength(cursorLine - 1) - 1; +///-- cursorPos = m_qSciSourceCodeEditor->lineLength(cursorLine - 1) - 1; ///-- } ///-- else ///-- { @@ -817,39 +829,39 @@ bool MainWindow::saveSourceFile() ///-- // If the character was found set its new cursor position... ///-- if (charFound) ///-- { -///-- _qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos + 1); +///-- m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos + 1); ///-- } ///-- // ...if it was not found, set the previous cursor position. ///-- else ///-- { -///-- _qSciSourceCodeEditor->setCursorPosition(saveCursorLine, saveCursorPos + 1); +///-- m_qSciSourceCodeEditor->setCursorPosition(saveCursorLine, saveCursorPos + 1); ///-- } ///-- } ///-- // set the previous cursor position. ///-- else if (enteredCharacter == 10) ///-- { -///-- _qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos); +///-- m_qSciSourceCodeEditor->setCursorPosition(cursorLine, cursorPos); ///-- } ///-- ///-- if (m_toolBarWidget->cbLivePreview->isChecked()) ///-- { -///-- _sourceCodeChanged = false; +///-- m_sourceCodeChanged = false; ///-- } ///-- -///-- if (_savedSourceContent == _qSciSourceCodeEditor->text()) +///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- } ///-- else ///-- { -///-- _qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. +///-- m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. ///-- setWindowModified(true); ///-- } ///-- ///-- // Could set cursor this way and use normal linear search in text instead of columns and rows. -///-- //_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, 50); -///-- //_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, 50); +///-- //m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETCURRENTPOS, 50); +///-- //m_qSciSourceCodeEditor->SendScintilla(QsciScintillaBase::SCI_SETANCHOR, 50); ///-- } ///-- ///-- /* @@ -863,7 +875,7 @@ bool MainWindow::saveSourceFile() ///-- _indentSettingsChanged = true; ///-- ///-- int cursorLine, cursorPos; -///-- _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); +///-- m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); ///-- ///-- if (m_toolBarWidget->cbLivePreview->isChecked()) ///-- { @@ -871,16 +883,16 @@ bool MainWindow::saveSourceFile() ///-- _previewToggled = true; ///-- ///-- updateSourceView(); -///-- if (_sourceCodeChanged) +///-- if (m_sourceCodeChanged) ///-- { -///-- /* savedCursor = _qSciSourceCodeEditor->textCursor(); -///-- if ( cursorPos >= _qSciSourceCodeEditor->text().count() ) { -///-- cursorPos = _qSciSourceCodeEditor->text().count() - 1; +///-- /* savedCursor = m_qSciSourceCodeEditor->textCursor(); +///-- if ( cursorPos >= m_qSciSourceCodeEditor->text().count() ) { +///-- cursorPos = m_qSciSourceCodeEditor->text().count() - 1; ///-- } ///-- savedCursor.setPosition( cursorPos ); -///-- _qSciSourceCodeEditor->setTextCursor( savedCursor ); +///-- m_qSciSourceCodeEditor->setTextCursor( savedCursor ); ///-- */ -///-- _sourceCodeChanged = false; +///-- m_sourceCodeChanged = false; ///-- } ///-- _indentSettingsChanged = false; ///-- } @@ -889,14 +901,14 @@ bool MainWindow::saveSourceFile() ///-- updateSourceView(); ///-- } ///-- -///-- if (_savedSourceContent == _qSciSourceCodeEditor->text()) +///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- } ///-- else ///-- { -///-- _qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. +///-- m_qSciSourceCodeEditor->setModified(true); // Has no effect according to TQScintilla docs. ///-- setWindowModified(true); ///-- } ///-- } @@ -912,34 +924,34 @@ void MainWindow::previewTurnedOnOff(bool turnOn) ///-- _previewToggled = true; ///-- ///-- int cursorLine, cursorPos; -///-- _qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); +///-- m_qSciSourceCodeEditor->getCursorPosition(&cursorLine, &cursorPos); ///-- -///-- if (turnOn && (_indentSettingsChanged || _sourceCodeChanged)) +///-- if (turnOn && (_indentSettingsChanged || m_sourceCodeChanged)) ///-- { ///-- callIndenter(); ///-- } ///-- updateSourceView(); -///-- if (_sourceCodeChanged) +///-- if (m_sourceCodeChanged) ///-- { -///-- /* savedCursor = _qSciSourceCodeEditor->textCursor(); -///-- if ( cursorPos >= _qSciSourceCodeEditor->text().count() ) { -///-- cursorPos = _qSciSourceCodeEditor->text().count() - 1; +///-- /* savedCursor = m_qSciSourceCodeEditor->textCursor(); +///-- if ( cursorPos >= m_qSciSourceCodeEditor->text().count() ) { +///-- cursorPos = m_qSciSourceCodeEditor->text().count() - 1; ///-- } ///-- savedCursor.setPosition( cursorPos ); -///-- _qSciSourceCodeEditor->setTextCursor( savedCursor ); +///-- m_qSciSourceCodeEditor->setTextCursor( savedCursor ); ///-- */ -///-- _sourceCodeChanged = false; +///-- m_sourceCodeChanged = false; ///-- } ///-- _indentSettingsChanged = false; ///-- -///-- if (_savedSourceContent == _qSciSourceCodeEditor->text()) +///-- if (_savedSourceContent == m_qSciSourceCodeEditor->text()) ///-- { -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- setWindowModified(false); ///-- } ///-- else ///-- { -///-- _qSciSourceCodeEditor->setModified(true); +///-- m_qSciSourceCodeEditor->setModified(true); ///-- setWindowModified(true); ///-- } ///-- } @@ -974,7 +986,7 @@ void MainWindow::exportToPDF() ///-- QsciPrinter printer(TQPrinter::HighResolution); ///-- printer.setOutputFormat(TQPrinter::PdfFormat); ///-- printer.setOutputFileName(fileName); -///-- printer.printRange(_qSciSourceCodeEditor); +///-- printer.printRange(m_qSciSourceCodeEditor); ///-- } } @@ -996,7 +1008,7 @@ void MainWindow::exportToHTML() ///-- if (!fileName.isEmpty()) ///-- { ///-- // Create a document from which HTML code can be generated. -///-- TQTextDocument sourceCodeDocument(_qSciSourceCodeEditor->text()); +///-- TQTextDocument sourceCodeDocument(m_qSciSourceCodeEditor->text()); ///-- sourceCodeDocument.setDefaultFont(TQFont("Courier", 12, TQFont::Normal)); ///-- TQString sourceCodeAsHTML = sourceCodeDocument.toHtml(); ///-- // To ensure that empty lines are kept in the HTML code make this replacement. @@ -1073,14 +1085,14 @@ void MainWindow::exportToHTML() */ void MainWindow::saveSettings() { -///-- m_settings->setValueByName("encoding", _currentEncoding); -///-- m_settings->setValueByName("version", PROGRAM_VERSION_STRING); + m_settings->setValueByName("VersionInSettingsFile", PROGRAM_VERSION_STRING); m_settings->setValueByName("WindowIsMaximized", isMaximized()); if (!isMaximized()) { m_settings->setValueByName("WindowPosition", pos()); m_settings->setValueByName("WindowSize", size()); } + m_settings->setValueByName("FileEncoding", m_currentEncoding); ///-- m_settings->setValueByName("MainWindowState", saveState()); ///-- ///-- // Also save the syntax highlight style for all lexers. @@ -1216,7 +1228,7 @@ bool MainWindow::maybeSave() ///-- "Reopen the currently opened source code file by using the text encoding scheme ") + ///-- encodingName); ///-- encodingAction->setCheckable(true); -///-- if (encodingName == _currentEncoding) +///-- if (encodingName == m_currentEncoding) ///-- { ///-- encodingAction->setChecked(true); ///-- } @@ -1281,13 +1293,13 @@ bool MainWindow::maybeSave() ///-- TQTextStream inSrcStrm(&inSrcFile); ///-- TQApplication::setOverrideCursor(TQt::WaitCursor); ///-- TQString encodingName = encodingAction->text(); -///-- _currentEncoding = encodingName; +///-- m_currentEncoding = encodingName; ///-- inSrcStrm.setCodec(TQTextCodec::codecForName(encodingName.toAscii())); ///-- fileContent = inSrcStrm.readAll(); ///-- TQApplication::restoreOverrideCursor(); ///-- inSrcFile.close(); -///-- _qSciSourceCodeEditor->setText(fileContent); -///-- _qSciSourceCodeEditor->setModified(false); +///-- m_qSciSourceCodeEditor->setText(fileContent); +///-- m_qSciSourceCodeEditor->setModified(false); ///-- } ///-- } ///-- } @@ -1306,7 +1318,7 @@ bool MainWindow::maybeSave() ///-- foreach(highlighterName, _highlighter->getAvailableHighlighters()) ///-- { ///-- highlighterAction = new TQAction(highlighterName, _highlighterActionGroup); -///-- highlighterAction->setStatusTip(tr("Set the syntax highlightning to ") + highlighterName); +///-- highlighterAction->setStatusTip(tr("Set the syntax highlighting to ") + highlighterName); ///-- highlighterAction->setCheckable(true); ///-- } ///-- _mainWindowForm->popupMenuHighlighter->addActions(_highlighterActionGroup->actions()); @@ -1316,25 +1328,25 @@ bool MainWindow::maybeSave() ///-- connect(_highlighterActionGroup, SIGNAL(triggered(TQAction*)), _highlighter, ///-- SLOT(setHighlighterByAction(TQAction*))); ///-- } -///-- -///-- /* -///-- \brief Is called whenever the white space visibility is being changed in the menu. -///-- */ -///-- void MainWindow::setWhiteSpaceVisibility(bool visible) -///-- { -///-- if (_qSciSourceCodeEditor != NULL) -///-- { -///-- if (visible) -///-- { -///-- _qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsVisible); -///-- } -///-- else -///-- { -///-- _qSciSourceCodeEditor->setWhitespaceVisibility(QsciScintilla::WsInvisible); -///-- } -///-- } -///-- } -///-- + +/* + \brief Is called whenever the white space visibility is being changed in the menu. + */ +void MainWindow::setWhiteSpaceVisibility(bool visible) +{ + if (m_qSciSourceCodeEditor) + { + if (visible) + { + m_qSciSourceCodeEditor->setWhitespaceVisibility(TQextScintilla::WsVisible); + } + else + { + m_qSciSourceCodeEditor->setWhitespaceVisibility(TQextScintilla::WsInvisible); + } + } +} + ///-- /* ///-- \brief This slot is called whenever the number of lines in the editor changes ///-- and adapts the margin for the displayed line numbers. @@ -1342,8 +1354,8 @@ bool MainWindow::maybeSave() ///-- void MainWindow::numberOfLinesChanged() ///-- { ///-- TQString lineNumbers; -///-- lineNumbers.setNum(_qSciSourceCodeEditor->lines() * 10); -///-- _qSciSourceCodeEditor->setMarginWidth(1, lineNumbers); +///-- lineNumbers.setNum(m_qSciSourceCodeEditor->lines() * 10); +///-- m_qSciSourceCodeEditor->setMarginWidth(1, lineNumbers); ///-- } ///-- ///-- /* @@ -1391,13 +1403,13 @@ bool MainWindow::maybeSave() ///-- foreach(TQString highlighterName, _highlighter->getAvailableHighlighters()) ///-- { ///-- TQAction *highlighterAction = actionList.at(i); -///-- highlighterAction->setStatusTip(tr("Set the syntax highlightning to ") + highlighterName); +///-- highlighterAction->setStatusTip(tr("Set the syntax highlighting to ") + highlighterName); ///-- i++; ///-- } ///-- ///-- // Translate the line and column indicators in the statusbar. ///-- int line, column; -///-- _qSciSourceCodeEditor->getCursorPosition(&line, &column); +///-- m_qSciSourceCodeEditor->getCursorPosition(&line, &column); ///-- setStatusBarCursorPosInfo(line, column); ///-- } ///-- else diff --git a/src/MainWindow.h b/src/MainWindow.h index 7326c5c..8453399 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -37,7 +37,7 @@ class ToolBarWidget; /// class TQActionGroup; /// class TQTranslator; /// -/// class QsciScintilla; +class TQextScintilla; class MainWindow : public MainWindowBase @@ -60,8 +60,8 @@ class MainWindow : public MainWindowBase ///-- void saveAsOtherEncoding(TQAction *chosenEncodingAction); ///-- void callIndenter(); ///-- void updateSourceView(); -///-- void turnHighlightOnOff(bool turnOn); -///-- void setWhiteSpaceVisibility(bool visible); + void turnHighlightOnOff(bool turnOn); + void setWhiteSpaceVisibility(bool visible); ///-- void sourceCodeChangedHelperSlot(); ///-- void sourceCodeChangedSlot(); ///-- void indentSettingsChangedSlot(); @@ -96,10 +96,10 @@ class MainWindow : public MainWindowBase ///-- void dragEnterEvent(TQDragEnterEvent *event); ///-- void dropEvent(TQDropEvent *event); ///-- -///-- QsciScintilla *_qSciSourceCodeEditor; - UiGuiSettings *m_settings; + TQextScintilla *m_qSciSourceCodeEditor; + UiGuiSettings *m_settings; ///-- -///-- TQString _currentEncoding; + TQString m_currentEncoding; ///-- TQString _sourceFileContent; ///-- TQString _sourceFormattedContent; ///-- TQString _sourceViewContent; @@ -121,8 +121,7 @@ class MainWindow : public MainWindowBase ///-- TQTranslator *_uiGuiTranslator; ///-- TQTranslator *_qTTranslator; ///-- -///-- bool _sourceCodeChanged; -///-- bool _scrollPositionChanged; + bool m_sourceCodeChanged; ///-- bool _indentSettingsChanged; ///-- bool _previewToggled; ///-- TQStringList _encodingsList; diff --git a/src/MainWindowBase.ui b/src/MainWindowBase.ui index 9d478b4..676b6f1 100755 --- a/src/MainWindowBase.ui +++ b/src/MainWindowBase.ui @@ -289,7 +289,7 @@ Enables or disables diplaying of white space characters in the editor. - false + true @@ -340,7 +340,7 @@ If selected opens last source code file on startup. - false + true diff --git a/src/ToolBarWidget.ui b/src/ToolBarWidget.ui index 19f3259..25663c2 100755 --- a/src/ToolBarWidget.ui +++ b/src/ToolBarWidget.ui @@ -58,7 +58,7 @@ Syntax Highlight - Enables and disables the highlightning of the source + Enables and disables the highlighting of the source Ctrl+H diff --git a/src/UiGuiSettings.cpp b/src/UiGuiSettings.cpp index baea1d9..e4ab510 100644 --- a/src/UiGuiSettings.cpp +++ b/src/UiGuiSettings.cpp @@ -53,6 +53,11 @@ UiGuiSettings::UiGuiSettings() : TQObject() m_qsettings->beginGroup("universalindentgui/UniversalIndentGUI"); m_indenterDirectoryStr = SettingsPaths::getGlobalFilesPath() + "/indenters"; + + m_actionSettings["actionEnableSyntaxHighlighting"] = "SyntaxHighlightingEnabled"; + m_actionSettings["actionLoadLastOpenedFileOnStartup"] = "LoadLastOpenedFileOnStartup"; + m_actionSettings["actionWhiteSpaceIsVisible"] = "WhiteSpaceIsVisible"; + readAvailableTranslations(); loadSettings(); } @@ -229,8 +234,8 @@ void UiGuiSettings::loadSettings() m_settings["SelectedIndenter"] = selectedIndenter; // Read if syntax highlighting is enabled. - m_settings["SyntaxHighlightningEnabled"] = m_qsettings->readBoolEntry( - "SyntaxHighlightningEnabled", true); + m_settings["SyntaxHighlightingEnabled"] = m_qsettings->readBoolEntry( + "SyntaxHighlightingEnabled", true); // Read if white space characters should be displayed. m_settings["WhiteSpaceIsVisible"] = m_qsettings->readBoolEntry("whiteSpaceIsVisible", false); @@ -297,8 +302,8 @@ void UiGuiSettings::saveSettings() m_qsettings->writeEntry("selectedIndenter", m_settings["SelectedIndenter"].toInt()); // Write if syntax highlighting is enabled. - m_qsettings->writeEntry("SyntaxHighlightningEnabled", - m_settings["SyntaxHighlightningEnabled"].toBool()); + m_qsettings->writeEntry("SyntaxHighlightingEnabled", + m_settings["SyntaxHighlightingEnabled"].toBool()); // Write if white space characters should be displayed. m_qsettings->writeEntry("whiteSpaceIsVisible", m_settings["WhiteSpaceIsVisible"].toBool()); @@ -318,8 +323,44 @@ void UiGuiSettings::saveSettings() //m_qsettings->writeEntry("MainWindowState", m_settings["MainWindowState"].toByteArray()); } +/* + \brief Extern widgets can connect to this slot to change settings. + + According to the objects property "connectedSettingName" the corresponding + setting is known and set. + */ +void UiGuiSettings::handleValueChangeFromExtern(bool value) +{ + if (sender()) + { + // Get the corresponding setting name from the sender objects property + TQString senderName = TQString(sender()->name()); + if (m_actionSettings.contains(senderName)) + { + TQString settingName = m_actionSettings[senderName]; + + // Set the value of the setting to the objects value. + setValueByName(settingName, value); + tqWarning("MIKE set="+settingName); + } + } +} + void UiGuiSettings::emitSignalForSetting(TQString settingName) { + // Emit the signal for the changed value. + if (settingName == "LoadLastOpenedFileOnStartup") + { + emit loadLastOpenedFileOnStartup(m_settings[settingName].toBool()); + } + else if (settingName == "SyntaxHighlightingEnabled") + { + emit syntaxHighlightingEnabled(m_settings[settingName].toBool()); + } + else if (settingName == "WhiteSpaceIsVisible") + { + emit whiteSpaceIsVisible(m_settings[settingName].toBool()); + } } /* diff --git a/src/UiGuiSettings.h b/src/UiGuiSettings.h index de5ddad..6fd6428 100644 --- a/src/UiGuiSettings.h +++ b/src/UiGuiSettings.h @@ -74,7 +74,7 @@ class UiGuiSettings : public TQObject // [--] private slots: // [--] void handleObjectPropertyChange(); // [++] void handleValueChangeFromExtern(int value); -// [++] void handleValueChangeFromExtern(bool value); + void handleValueChangeFromExtern(bool value); // [++] void handleValueChangeFromExtern(TQDate value); // [++] void handleValueChangeFromExtern(TQByteArray value); @@ -87,11 +87,11 @@ class UiGuiSettings : public TQObject // [++] void windowSize(TQSize value); // [++] void fileEncoding(TQString value); // [++] void recentlyOpenedListSize(int value); -// [++] void loadLastOpenedFileOnStartup(bool value); + void loadLastOpenedFileOnStartup(bool value); // [++] void lastOpenedFiles(TQString value); // [++] void selectedIndenter(int value); -// [++] void syntaxHighlightningEnabled(bool value); -// [++] void whiteSpaceIsVisible(bool value); + void syntaxHighlightingEnabled(bool value); + void whiteSpaceIsVisible(bool value); // [++] void indenterParameterTooltipsEnabled(bool value); // [++] void tabWidth(int value); // [++] void language(int value); @@ -111,6 +111,9 @@ class UiGuiSettings : public TQObject // This map holds all possible settings defined by their name as TQString. TQMap m_settings; + // This map holds the relationship between action widgets and settings entries + TQMap m_actionSettings; + // The path where the indenters are located TQString m_indenterDirectoryStr; }; diff --git a/src/__TODO/UiGuiHighlighter.cpp b/src/__TODO/UiGuiHighlighter.cpp index cfbf299..cfb99c9 100644 --- a/src/__TODO/UiGuiHighlighter.cpp +++ b/src/__TODO/UiGuiHighlighter.cpp @@ -95,7 +95,7 @@ UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) : SettingsPaths::getSettingsPath() + "/UiGuiSyntaxHighlightConfig.ini", TQSettings::IniFormat, this); - _highlightningIsOn = true; + _highlightingIsOn = true; _mapHighlighternameToExtension["Bash"] = TQStringList() << "sh"; _mapHighlighternameToExtension["Batch"] = TQStringList() << "bat"; @@ -187,7 +187,7 @@ void UiGuiHighlighter::setHighlighterByAction(TQAction *highlighterAction) */ void UiGuiHighlighter::turnHighlightOn() { - _highlightningIsOn = true; + _highlightingIsOn = true; _qsciEditorParent->setLexer(_lexer); readCurrentSettings(""); } @@ -197,7 +197,7 @@ void UiGuiHighlighter::turnHighlightOn() */ void UiGuiHighlighter::turnHighlightOff() { - _highlightningIsOn = false; + _highlightingIsOn = false; _qsciEditorParent->setLexer(); _qsciEditorParent->setFont(TQFont("Monospace", 10, TQFont::Normal)); _qsciEditorParent->setMarginsFont(TQFont("Monospace", 10, TQFont::Normal)); @@ -583,7 +583,7 @@ int UiGuiHighlighter::setLexerForExtension(TQString extension) } // Set the _lexer for the TQScintilla widget. - if (_highlightningIsOn) + if (_highlightingIsOn) { _qsciEditorParent->setLexer(_lexer); } diff --git a/src/__TODO/UiGuiHighlighter.h b/src/__TODO/UiGuiHighlighter.h index 025219e..3dd8200 100644 --- a/src/__TODO/UiGuiHighlighter.h +++ b/src/__TODO/UiGuiHighlighter.h @@ -63,7 +63,7 @@ class UiGuiHighlighter : public TQObject void setHighlighterByAction(TQAction *highlighterAction); private: - bool _highlightningIsOn; + bool _highlightingIsOn; QsciScintilla *_qsciEditorParent; TQMap _fontForStyles; TQMap _colorForStyles;