From dfb1b9f10a0c18ace12de3323e3eea410efa3b6c Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Tue, 16 May 2023 10:38:36 +0900 Subject: [PATCH] Added initial empty GUI for the indenter Signed-off-by: Michele Calgaro --- icons/CMakeLists.txt | 5 + icons/{__TODO => }/help.png | Bin icons/{__TODO => }/load_indent_cfg.png | Bin icons/{__TODO => }/save_indent_cfg.png | Bin icons/{__TODO => }/shell.png | Bin icons/{__TODO => }/view-refresh.png | Bin src/CMakeLists.txt | 7 +- src/IndentHandler.cpp | 1741 ++++++++++++++++++++ src/IndentHandler.h | 180 +++ src/MainWindow.cpp | 54 +- src/MainWindow.h | 12 +- src/MainWindowBase.ui | 65 +- src/SettingsPaths.cpp | 4 - src/__TODO/IndentHandler.cpp | 2042 ------------------------ src/__TODO/IndentHandler.h | 195 --- src/__TODO/MainWindow.ui | 51 - src/__TODO/TemplateBatchScript.cpp | 97 -- 17 files changed, 2021 insertions(+), 2432 deletions(-) rename icons/{__TODO => }/help.png (100%) rename icons/{__TODO => }/load_indent_cfg.png (100%) rename icons/{__TODO => }/save_indent_cfg.png (100%) rename icons/{__TODO => }/shell.png (100%) rename icons/{__TODO => }/view-refresh.png (100%) create mode 100644 src/IndentHandler.cpp create mode 100644 src/IndentHandler.h delete mode 100644 src/__TODO/IndentHandler.cpp delete mode 100644 src/__TODO/IndentHandler.h delete mode 100755 src/__TODO/MainWindow.ui diff --git a/icons/CMakeLists.txt b/icons/CMakeLists.txt index 90f4bf4..9e83cf4 100644 --- a/icons/CMakeLists.txt +++ b/icons/CMakeLists.txt @@ -8,9 +8,13 @@ install( edit-clear.png exporthtml.png exportpdf.png + help.png info.png live-preview.png + load_indent_cfg.png preferences-system.png + save_indent_cfg.png + shell.png syntax-highlight.png system-log-out.png tooltip.png @@ -19,5 +23,6 @@ install( universalIndentGUI_32x32.xpm universalIndentGUI_64x64.png universalIndentGUI_512x512.png + view-refresh.png DESTINATION ${SHARE_INSTALL_PREFIX}/universal-indent-gui-tqt/icons ) diff --git a/icons/__TODO/help.png b/icons/help.png similarity index 100% rename from icons/__TODO/help.png rename to icons/help.png diff --git a/icons/__TODO/load_indent_cfg.png b/icons/load_indent_cfg.png similarity index 100% rename from icons/__TODO/load_indent_cfg.png rename to icons/load_indent_cfg.png diff --git a/icons/__TODO/save_indent_cfg.png b/icons/save_indent_cfg.png similarity index 100% rename from icons/__TODO/save_indent_cfg.png rename to icons/save_indent_cfg.png diff --git a/icons/__TODO/shell.png b/icons/shell.png similarity index 100% rename from icons/__TODO/shell.png rename to icons/shell.png diff --git a/icons/__TODO/view-refresh.png b/icons/view-refresh.png similarity index 100% rename from icons/__TODO/view-refresh.png rename to icons/view-refresh.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34b7dd8..cff46f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,17 +26,18 @@ link_directories( set( target universal-indent-gui-tqt ) set( ${target}_SRCS - #completed + # completed + MainWindowBase.ui ToolBarWidget.ui SettingsPaths.cpp UiGuiVersion.cpp - #ongoing + # ongoing AboutDialogBase.ui - MainWindowBase.ui AboutDialog.cpp + IndentHandler.cpp MainWindow.cpp main.cpp UiGuiSettings.cpp diff --git a/src/IndentHandler.cpp b/src/IndentHandler.cpp new file mode 100644 index 0000000..76033dc --- /dev/null +++ b/src/IndentHandler.cpp @@ -0,0 +1,1741 @@ +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "config.h" +#include "IndentHandler.h" + +#include "MainWindow.h" +#include "SettingsPaths.h" +//--- #include "UiGuiSettings.h" +//--- #include "UiGuiErrorMessage.h" +//--- #include "TemplateBatchScript.h" +//--- #include "UiGuiIniFileParser.h" + +#include +#include +#include +#include +#include +#include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include +//--- #include + +// \defgroup grp_Indenter All concerning handling of the indenter. + +/* + \class IndentHandler + \brief A widget for handling many indenters that are configured by an ini file. + + This is a widget that is used by the main window. It handles access to the + indenter config file and calls the chosen indenter to reformat the source text. + Calls the indenter each time a setting has been changed and informs + the main window about the reformatted source code. +*/ + + +/* + \brief Constructor of the indent handler. + + By calling this constructor the indenter to be loaded, can be selected by setting + its \a indenterID, which is the number of found indenter ini files in alphabetic + order starting at index 0. + */ +IndentHandler::IndentHandler(int indenterID, MainWindow *mainWindow, TQWidget *parent) + : TQWidget(parent), m_mainWindow(mainWindow), m_parent(parent), m_toolBoxContainerLayout(nullptr), + m_indenterSelectionCombobox(nullptr), m_indenterParameterHelpButton(nullptr), + m_indenterParameterCategoriesToolBox(nullptr) +//--- _indenterSettings(nullptr), _errorMessageDialog(nullptr) +{ + if (indenterID < 0) + { + indenterID = 0; + } + + // define this widgets resize behavior + setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding); + + if (m_mainWindow) + { + connect((TQObject*)m_mainWindow->actionLoadIndenterConfigFile, SIGNAL(activated()), + this, SLOT(openConfigFileDialog())); + connect((TQObject*)m_mainWindow->actionSaveIndenterConfigFile, SIGNAL(activated()), + this, SLOT(saveasIndentCfgFileDialog())); + connect((TQObject*)m_mainWindow->actionCreateShellScript, SIGNAL(activated()), + this, SLOT(createIndenterCallShellScript())); + connect((TQObject*)m_mainWindow->actionResetIndenterParameters, SIGNAL(activated()), + this, SLOT(resetIndenterParameter())); + } + + // create vertical layout box, into which the toolbox will be added + m_toolBoxContainerLayout = new TQVBoxLayout(this); + m_toolBoxContainerLayout->setMargin(2); + m_toolBoxContainerLayout->setSpacing(5); + + // Create horizontal layout for indenter selector and help button. + TQHBoxLayout *hboxLayout = new TQHBoxLayout(); + hboxLayout->setSpacing(5); + m_toolBoxContainerLayout->addLayout(hboxLayout); + + // Create the indenter selection combo box. + m_indenterSelectionCombobox = new TQComboBox(this); + m_indenterSelectionCombobox->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Minimum); + connect(m_indenterSelectionCombobox, SIGNAL(activated(int)), this, SLOT(setIndenter(int))); + hboxLayout->addWidget(m_indenterSelectionCombobox); + + // Create the indenter parameter help button. + m_indenterParameterHelpButton = new TQToolButton(this); + m_indenterParameterHelpButton->setIconSet(TQPixmap(TQString(APP_ICONS_PATH)+ "help.png")); + connect(m_indenterParameterHelpButton, SIGNAL(clicked()), this, SLOT(showIndenterManual())); + hboxLayout->addWidget(m_indenterParameterHelpButton); + + // create a toolbox and set its resize behavior + m_indenterParameterCategoriesToolBox = new TQToolBox(this); + m_indenterParameterCategoriesToolBox->setSizePolicy(TQSizePolicy::MinimumExpanding, + TQSizePolicy::Expanding); + m_toolBoxContainerLayout->addWidget(m_indenterParameterCategoriesToolBox); + + m_indenterExecutableCallString = ""; + m_indenterExecutableSuffix = ""; + + m_indenterDirectoryStr = SettingsPaths::getIndenterPath(); + m_tempDirectoryStr = SettingsPaths::getTempPath(); + m_settingsDirectoryStr = SettingsPaths::getSettingsPath(); + TQDir indenterDirectory = TQDir(m_indenterDirectoryStr); + +//--- if (m_mainWindow != nullptr) +//--- { +//--- _errorMessageDialog = new UiGuiErrorMessage(m_mainWindow); +//--- } +//--- else +//--- { +//--- _errorMessageDialog = new UiGuiErrorMessage(this); +//--- } + +//--- _indenterIniFileList = indenterDirectory.entryList(TQStringList("uigui_*.ini")); +//--- if (_indenterIniFileList.count() > 0) +//--- { +//--- // Take care if the selected indenterID is smaller or greater than the number of existing +//--- // indenters +//--- if (indenterID < 0) +//--- { +//--- indenterID = 0; +//--- } +//--- if (indenterID >= _indenterIniFileList.count()) +//--- { +//--- indenterID = _indenterIniFileList.count() - 1; +//--- } +//--- +//--- // Reads and parses the by indenterID defined indent ini file and creates toolbox entries +//--- readIndentIniFile(m_indenterDirectoryStr + "/" + _indenterIniFileList.at(indenterID)); +//--- +//--- // Find out how the indenter can be executed. +//--- createIndenterCallString(); +//--- +//--- // Load the users last settings made for this indenter. +//--- loadConfigFile(m_settingsDirectoryStr + "/" + _indenterFileName + ".cfg"); +//--- +//--- // Fill the indenter selection combo box with the list of available indenters. +//--- if (!getAvailableIndenters().isEmpty()) +//--- { +//--- m_indenterSelectionCombobox->addItems(getAvailableIndenters()); +//--- m_indenterSelectionCombobox->setCurrentIndex(indenterID); +//--- connect(m_indenterSelectionCombobox, SIGNAL(currentIndexChanged(int)), this, +//--- SIGNAL(selectedIndenterIndexChanged(int))); +//--- } +//--- } +//--- else +//--- { +//--- _errorMessageDialog->showMessage(tr("No indenter ini files"), +//--- tr("There exists no indenter ini files in the directory \"") + +//--- TQDir(m_indenterDirectoryStr).absolutePath() + "\"."); +//--- } +} + +/* + \brief Implicitly writes the current indenter parameters to the indenters config file. + */ +IndentHandler::~IndentHandler() +{ +//--- // Generate the parameter string that will be saved to the indenters config file. +//--- TQString parameterString = getParameterString(); +//--- if (!_indenterFileName.isEmpty()) +//--- { +//--- saveConfigFile(m_settingsDirectoryStr + "/" + _indenterFileName + ".cfg", parameterString); +//--- } +//--- +//--- delete _errorMessageDialog; +} + +/* + \brief Opens the context menu, used for some actions like saving the indenter config file, + at the event position. + */ +void IndentHandler::contextMenuEvent(TQContextMenuEvent *event) +{ + if (m_mainWindow) + { + m_mainWindow->menuIndenter->exec(event->globalPos()); + } +} + +//--- /* +//--- \brief Creates the content for a shell script that can be used as a external tool call +//--- to indent an as parameter defined file. +//--- */ +//--- TQString IndentHandler::generateShellScript(const TQString &configFilename) +//--- { +//--- TQString indenterCompleteCallString; +//--- TQString parameterInputFile; +//--- TQString parameterOuputFile; +//--- TQString parameterParameterFile; +//--- TQString replaceInputFileCommand; +//--- +//--- // Define the placeholder for parameter variables either in batch or bash programming. +//--- TQString shellParameterPlaceholder = "$1"; +//--- +//--- parameterInputFile = " " + _inputFileParameter + "\"" + shellParameterPlaceholder + "\""; +//--- +//--- if (_outputFileParameter != "none" && _outputFileParameter != "stdout") +//--- { +//--- if (_outputFileName == _inputFileName) +//--- { +//--- parameterOuputFile = " " + _outputFileParameter + "\"" + shellParameterPlaceholder + "\""; +//--- } +//--- else +//--- { +//--- parameterOuputFile = " " + _outputFileParameter + _outputFileName + ".tmp"; +//--- } +//--- } +//--- +//--- // If the config file name is empty it is assumed that all parameters are sent via command line +//--- // call +//--- if (_globalConfigFilename.isEmpty()) +//--- { +//--- parameterParameterFile = " " + getParameterString(); +//--- } +//--- // else if needed add the parameter to the indenter call string where the config file can be +//--- // found. +//--- else if (_useCfgFileParameter != "none") +//--- { +//--- parameterParameterFile = " " + _useCfgFileParameter + "\"./" + configFilename + "\""; +//--- } +//--- +//--- // Assemble indenter call string for parameters according to the set order. +//--- if (_parameterOrder == "ipo") +//--- { +//--- indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; +//--- } +//--- else if (_parameterOrder == "pio") +//--- { +//--- indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; +//--- } +//--- else if (_parameterOrder == "poi") +//--- { +//--- indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; +//--- } +//--- else +//--- { +//--- indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; +//--- } +//--- +//--- // Generate the indenter call string either for win32 or other systems. +//--- indenterCompleteCallString = "#!/bin/bash\n" + m_indenterExecutableCallString + +//--- indenterCompleteCallString; +//--- +//--- // If the indenter writes to stdout pipe the output into a file +//--- if (_outputFileParameter == "stdout") +//--- { +//--- indenterCompleteCallString = indenterCompleteCallString + " >" + _outputFileName + ".tmp"; +//--- } +//--- +//--- // If the output filename is not the same as the input filename copy the output over the input. +//--- if (_outputFileName != _inputFileName) +//--- { +//--- replaceInputFileCommand = "mv " + _outputFileName + ".tmp \"" + shellParameterPlaceholder + +//--- "\"\n"; +//--- } +//--- +//--- TQString shellScript(TemplateBatchScript::getTemplateBatchScript()); +//--- shellScript = shellScript.replace("__INDENTERCALLSTRING2__", +//--- indenterCompleteCallString + "\n" + replaceInputFileCommand); +//--- indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent"); +//--- replaceInputFileCommand = replaceInputFileCommand.replace("$1", "$file2indent"); +//--- shellScript = shellScript.replace("__INDENTERCALLSTRING1__", +//--- indenterCompleteCallString + "\n" + replaceInputFileCommand); +//--- +//--- return shellScript; +//--- } +//--- +//--- /* +//--- \brief Format \a sourceCode by calling the indenter. +//--- +//--- The \a inputFileExtension has to be given as parameter so the called indenter +//--- can identify the programming language if needed. +//--- */ +//--- TQString IndentHandler::callIndenter(TQString sourceCode, TQString inputFileExtension) +//--- { +//--- if (m_indenterExecutableSuffix == ".js") +//--- { +//--- return callJavaScriptIndenter(sourceCode); +//--- } +//--- else +//--- { +//--- return callExecutableIndenter(sourceCode, inputFileExtension); +//--- } +//--- } +//--- +//--- /* +//--- \brief Format \a sourceCode by calling the interpreted JavaScript code of the indenter. +//--- +//--- The \a inputFileExtension has to be given as parameter so the called indenter +//--- can identify the programming language if needed. +//--- */ +//--- TQString IndentHandler::callJavaScriptIndenter(TQString sourceCode) +//--- { +//--- TQScriptEngine engine; +//--- +//--- engine.globalObject().setProperty("unformattedCode", sourceCode); +//--- +//--- TQFile jsDecoderFile(m_indenterExecutableCallString); +//--- TQString jsDecoderCode; +//--- if (jsDecoderFile.open(TQFile::ReadOnly)) +//--- { +//--- jsDecoderCode = jsDecoderFile.readAll(); +//--- } +//--- jsDecoderFile.close(); +//--- +//--- TQScriptValue value = engine.evaluate(jsDecoderCode); +//--- return value.toString(); +//--- } +//--- +//--- /* +//--- \brief Format \a sourceCode by calling the binary executable of the indenter. +//--- +//--- The \a inputFileExtension has to be given as parameter so the called indenter +//--- can identify the programming language if needed. +//--- */ +//--- TQString IndentHandler::callExecutableIndenter(TQString sourceCode, TQString inputFileExtension) +//--- { +//--- Q_ASSERT_X(!_inputFileName.isEmpty(), "callIndenter", "_inputFileName is empty"); +//--- // Q_ASSERT_X( !_outputFileName.isEmpty(), "callIndenter", "_outputFileName is empty" ); +//--- Q_ASSERT_X(!_indenterFileName.isEmpty(), "callIndenter", "_indenterFileName is empty"); +//--- +//--- if (_indenterFileName.isEmpty()) +//--- { +//--- return ""; +//--- } +//--- +//--- TQString formattedSourceCode; +//--- TQString indenterCompleteCallString; +//--- TQString parameterInputFile; +//--- TQString parameterOuputFile; +//--- TQString parameterParameterFile; +//--- TQProcess indentProcess; +//--- TQString processReturnString; +//--- +//--- // Generate the parameter string that will be saved to the indenters config file +//--- TQString parameterString = getParameterString(); +//--- +//--- if (!_globalConfigFilename.isEmpty()) +//--- { +//--- saveConfigFile(m_tempDirectoryStr + "/" + _globalConfigFilename, parameterString); +//--- } +//--- +//--- // Only add a dot to file extension if the string is not empty +//--- if (!inputFileExtension.isEmpty()) +//--- { +//--- inputFileExtension = "." + inputFileExtension; +//--- } +//--- +//--- // Delete any previously used input src file and create a new input src file. +//--- TQFile::remove(m_tempDirectoryStr + "/" + _inputFileName + inputFileExtension); +//--- TQFile inputSrcFile(m_tempDirectoryStr + "/" + _inputFileName + inputFileExtension); +//--- // Write the source code to the input file for the indenter +//--- if (inputSrcFile.open(TQFile::ReadWrite | TQFile::Text)) +//--- { +//--- inputSrcFile.write(sourceCode.toUtf8()); +//--- inputSrcFile.close(); +//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Wrote to be indented source code to file " << +//--- inputSrcFile.fileName(); +//--- } +//--- else +//--- { +//--- qCritical() << __LINE__ << " " << __FUNCTION__ << +//--- ": Couldn't write to be indented source code to file " << inputSrcFile.fileName(); +//--- } +//--- +//--- // Set the input file for the to be called indenter. +//--- if (_inputFileParameter.trimmed() == "<" || _inputFileParameter == "stdin") +//--- { +//--- parameterInputFile = ""; +//--- indentProcess.setStandardInputFile(inputSrcFile.fileName()); +//--- } +//--- else +//--- { +//--- parameterInputFile = " " + _inputFileParameter + _inputFileName + inputFileExtension; +//--- } +//--- +//--- // Set the output file for the to be called indenter. +//--- if (_outputFileParameter != "none" && _outputFileParameter != "stdout") +//--- { +//--- parameterOuputFile = " " + _outputFileParameter + _outputFileName + inputFileExtension; +//--- } +//--- +//--- // If the config file name is empty it is assumed that all parameters are sent via command line +//--- // call +//--- if (_globalConfigFilename.isEmpty()) +//--- { +//--- parameterParameterFile = " " + parameterString; +//--- } +//--- // if needed add the parameter to the indenter call string where the config file can be found +//--- else if (_useCfgFileParameter != "none") +//--- { +//--- parameterParameterFile = " " + _useCfgFileParameter + "\"" + m_tempDirectoryStr + "/" + +//--- _globalConfigFilename + "\""; +//--- } +//--- +//--- // Assemble indenter call string for parameters according to the set order. +//--- if (_parameterOrder == "ipo") +//--- { +//--- indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; +//--- } +//--- else if (_parameterOrder == "pio") +//--- { +//--- indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; +//--- } +//--- else if (_parameterOrder == "poi") +//--- { +//--- indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; +//--- } +//--- else +//--- { +//--- indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; +//--- } +//--- +//--- // If no indenter executable call string could be created before, show an error message. +//--- if (m_indenterExecutableCallString.isEmpty()) +//--- { +//--- _errorMessageDialog->showMessage(tr("No indenter executable"), tr( +//--- "There exists no indenter executable with the name \"%1\" in the directory \"%2\" nor in the global environment.").arg( +//--- _indenterFileName).arg(m_indenterDirectoryStr)); +//--- return sourceCode; +//--- } +//--- +//--- // Generate the indenter call string either for win32 or other systems. +//--- indenterCompleteCallString = m_indenterExecutableCallString + indenterCompleteCallString; +//--- +//--- // errors and standard outputs from the process call are merged together +//--- //indentProcess.setReadChannelMode(TQProcess::MergedChannels); +//--- +//--- // Set the directory where the indenter will be executed for the process' environment as PWD. +//--- TQStringList env = indentProcess.environment(); +//--- env << "PWD=" + TQFileInfo(m_tempDirectoryStr).absoluteFilePath(); +//--- indentProcess.setEnvironment(env); +//--- +//--- // Set the directory for the indenter execution +//--- indentProcess.setWorkingDirectory(TQFileInfo(m_tempDirectoryStr).absoluteFilePath()); +//--- +//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " << +//--- indentProcess.workingDirectory() << " using this commandline call: " << +//--- indenterCompleteCallString; +//--- +//--- indentProcess.start(indenterCompleteCallString); +//--- +//--- processReturnString = ""; +//--- bool calledProcessSuccessfully = indentProcess.waitForFinished(10000); +//--- // test if there was an error during starting the process of the indenter +//--- if (!calledProcessSuccessfully) +//--- { +//--- processReturnString = ""; +//--- processReturnString += tr("Returned error message: ") + indentProcess.errorString() + +//--- "
"; +//--- +//--- switch (indentProcess.error()) +//--- { +//--- case TQProcess::FailedToStart: +//--- { +//--- processReturnString += tr("Reason could be: ") + +//--- "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
"; +//--- break; +//--- } +//--- +//--- case TQProcess::Crashed: +//--- { +//--- processReturnString += "The process crashed some time after starting successfully.
"; +//--- break; +//--- } +//--- +//--- case TQProcess::Timedout: +//--- { +//--- processReturnString += +//--- "The called indenter did not response for over 10 seconds, so aborted its execution.
"; +//--- break; +//--- } +//--- +//--- case TQProcess::WriteError: +//--- { +//--- processReturnString += +//--- "An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
"; +//--- break; +//--- } +//--- +//--- case TQProcess::ReadError: +//--- { +//--- processReturnString += +//--- "An error occurred when attempting to read from the process. For example, the process may not be running.
"; +//--- break; +//--- } +//--- +//--- case TQProcess::UnknownError: +//--- { +//--- processReturnString += +//--- "An unknown error occurred. This is the default return value of error().
"; +//--- break; +//--- } +//--- +//--- default: +//--- { +//--- break; +//--- } +//--- } +//--- processReturnString += tr("
Callstring was: ") + encodeToHTML( +//--- indenterCompleteCallString); +//--- processReturnString += tr("

Indenter output was:
") + "
" + "(STDOUT):" + +//--- encodeToHTML(indentProcess.readAllStandardOutput()) + "
" + "(STDERR):" + +//--- encodeToHTML(indentProcess.readAllStandardError()) + "
" + "
"; +//--- tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; +//--- TQApplication::restoreOverrideCursor(); +//--- _errorMessageDialog->showMessage(tr("Error calling Indenter"), processReturnString); +//--- } +//--- +//--- // If the indenter returned an error code != 0 show its output. +//--- if (indentProcess.exitCode() != 0) +//--- { +//--- TQString exitCode; +//--- exitCode.setNum(indentProcess.exitCode()); +//--- processReturnString = tr("Indenter returned with exit code: ") + exitCode + "
" + tr( +//--- "Indent console output was: ") + "
" + "(STDOUT):" + encodeToHTML( +//--- indentProcess.readAllStandardOutput()) + "
" + "(STDERR):" + encodeToHTML( +//--- indentProcess.readAllStandardError()) + "
" + tr("
Callstring was: ") + +//--- encodeToHTML(indenterCompleteCallString) + ""; +//--- tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; +//--- TQApplication::restoreOverrideCursor(); +//--- _errorMessageDialog->showMessage(tr("Indenter returned error"), processReturnString); +//--- } +//--- +//--- // Only get the formatted source code, if calling the indenter did succeed. +//--- if (calledProcessSuccessfully) +//--- { +//--- // If the indenter results are written to stdout, read them from there... +//--- if (indentProcess.exitCode() == 0 && _outputFileParameter == "stdout") +//--- { +//--- formattedSourceCode = indentProcess.readAllStandardOutput(); +//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from StdOut."; +//--- } +//--- // ... else read the output file generated by the indenter call. +//--- else +//--- { +//--- TQFile outSrcFile(m_tempDirectoryStr + "/" + _outputFileName + inputFileExtension); +//--- if (outSrcFile.open(TQFile::ReadOnly | TQFile::Text)) +//--- { +//--- TQTextStream outSrcStrm(&outSrcFile); +//--- outSrcStrm.setCodec(TQTextCodec::codecForName("UTF-8")); +//--- formattedSourceCode = outSrcStrm.readAll(); +//--- outSrcFile.close(); +//--- tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from file " << +//--- outSrcFile.fileName(); +//--- } +//--- else +//--- { +//--- qCritical() << __LINE__ << " " << __FUNCTION__ << +//--- ": Couldn't read indenter output from file " << outSrcFile.fileName(); +//--- } +//--- } +//--- } +//--- else +//--- { +//--- return sourceCode; +//--- } +//--- +//--- // Delete the temporary input and output files. +//--- TQFile::remove(m_tempDirectoryStr + "/" + _outputFileName + inputFileExtension); +//--- TQFile::remove(m_tempDirectoryStr + "/" + _inputFileName + inputFileExtension); +//--- +//--- return formattedSourceCode; +//--- } +//--- +//--- /* +//--- \brief Generates and returns a string with all parameters needed to call the indenter. +//--- */ +//--- TQString IndentHandler::getParameterString() +//--- { +//--- TQString parameterString = ""; +//--- +//--- // generate parameter string for all boolean values +//--- foreach(ParamBoolean pBoolean, _paramBooleans) +//--- { +//--- if (pBoolean.checkBox->isChecked()) +//--- { +//--- if (!pBoolean.trueString.isEmpty()) +//--- { +//--- parameterString += pBoolean.trueString + _cfgFileParameterEnding; +//--- } +//--- } +//--- else +//--- { +//--- if (!pBoolean.falseString.isEmpty()) +//--- { +//--- parameterString += pBoolean.falseString + _cfgFileParameterEnding; +//--- } +//--- } +//--- } +//--- +//--- // generate parameter string for all numeric values +//--- foreach(ParamNumeric pNumeric, _paramNumerics) +//--- { +//--- if (pNumeric.valueEnabledChkBox->isChecked()) +//--- { +//--- parameterString += pNumeric.paramCallName + TQString::number(pNumeric.spinBox->value()) + +//--- _cfgFileParameterEnding; +//--- } +//--- } +//--- +//--- // generate parameter string for all string values +//--- foreach(ParamString pString, _paramStrings) +//--- { +//--- if (!pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked()) +//--- { +//--- // Create parameter definition for each value devided by a | sign. +//--- foreach(TQString paramValue, pString.lineEdit->text().split("|")) +//--- { +//--- parameterString += pString.paramCallName + paramValue + _cfgFileParameterEnding; +//--- } +//--- } +//--- } +//--- +//--- // generate parameter string for all multiple choice values +//--- foreach(ParamMultiple pMultiple, _paramMultiples) +//--- { +//--- if (pMultiple.valueEnabledChkBox->isChecked()) +//--- { +//--- parameterString += pMultiple.choicesStrings.at(pMultiple.comboBox->currentIndex()) + +//--- _cfgFileParameterEnding; +//--- } +//--- } +//--- +//--- return parameterString; +//--- } +//--- +//--- /* +//--- \brief Write settings for the indenter to a config file. +//--- */ +//--- void IndentHandler::saveConfigFile(TQString filePathName, TQString paramString) +//--- { +//--- TQFile::remove(filePathName); +//--- TQFile cfgFile(filePathName); +//--- +//--- cfgFile.open(TQFile::ReadWrite | TQFile::Text); +//--- cfgFile.write(paramString.toAscii()); +//--- cfgFile.close(); +//--- } +//--- +//--- /* +//--- \brief Load the config file for the indenter and apply the settings made there. +//--- */ +//--- bool IndentHandler::loadConfigFile(TQString filePathName) +//--- { +//--- TQFile cfgFile(filePathName); +//--- int index; +//--- int crPos; +//--- int paramValue = 0; +//--- TQString paramValueStr = ""; +//--- TQString cfgFileData = ""; +//--- +//--- // If the to be loaded config file does not exist leave all values as they are and return false. +//--- if (!cfgFile.exists()) +//--- { +//--- return false; +//--- } +//--- // else if the to be read config file exists, retrieve its whole content. +//--- else +//--- { +//--- // Open the config file and read all data +//--- cfgFile.open(TQFile::ReadOnly | TQFile::Text); +//--- cfgFileData = cfgFile.readAll(); +//--- cfgFile.close(); +//--- } +//--- +//--- // Search for name of each boolean parameter and set its value if found. +//--- foreach(ParamBoolean pBoolean, _paramBooleans) +//--- { +//--- // boolean value that will be assigned to the checkbox +//--- bool paramValue = false; +//--- +//--- // first search for the longer parameter string +//--- // the true parameter string is longer than the false string +//--- if (pBoolean.trueString.length() > pBoolean.falseString.length()) +//--- { +//--- // search for the true string +//--- index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive); +//--- // if true string found set the parameter value to true +//--- if (index != -1) +//--- { +//--- paramValue = true; +//--- } +//--- // if true string not found, search for false string +//--- else +//--- { +//--- index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive); +//--- // if false string found set the parameter value to false +//--- if (index != -1) +//--- { +//--- paramValue = false; +//--- } +//--- // neither true nor false parameter found so use default value +//--- else +//--- { +//--- paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); +//--- } +//--- } +//--- } +//--- // the false parameter string is longer than the true string +//--- else +//--- { +//--- // search for the false string +//--- index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive); +//--- // if false string found set the parameter value to false +//--- if (index != -1) +//--- { +//--- paramValue = false; +//--- } +//--- // if false string not found, search for true string +//--- else +//--- { +//--- index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive); +//--- // if true string found set the parameter value to true +//--- if (index != -1) +//--- { +//--- paramValue = true; +//--- } +//--- // neither true nor false parameter found so use default value +//--- else +//--- { +//--- paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); +//--- } +//--- } +//--- } +//--- pBoolean.checkBox->setChecked(paramValue); +//--- } +//--- +//--- // Search for name of each numeric parameter and set the value found behind it. +//--- foreach(ParamNumeric pNumeric, _paramNumerics) +//--- { +//--- index = cfgFileData.indexOf(pNumeric.paramCallName, 0, TQt::CaseInsensitive); +//--- // parameter was found in config file +//--- if (index != -1) +//--- { +//--- // set index after the parameter name, so in front of the number +//--- index += pNumeric.paramCallName.length(); +//--- +//--- // Find the end of the parameter by searching for set config file parameter ending. Most of +//--- // time this is a carriage return. +//--- crPos = cfgFileData.indexOf(_cfgFileParameterEnding, index + 1); +//--- +//--- // get the number and convert it to int +//--- TQString test = cfgFileData.mid(index, crPos - index); +//--- paramValue = cfgFileData.mid(index, crPos - index).toInt(nullptr); +//--- +//--- // disable the signal-slot connection. Otherwise signal is emmitted each time when value is +//--- // set +//--- TQObject::disconnect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, +//--- SLOT(handleChangedIndenterSettings())); +//--- pNumeric.spinBox->setValue(paramValue); +//--- pNumeric.valueEnabledChkBox->setChecked(true); +//--- TQObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, +//--- SLOT(handleChangedIndenterSettings())); +//--- } +//--- // parameter was not found in config file +//--- else +//--- { +//--- int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); +//--- pNumeric.spinBox->setValue(defaultValue); +//--- pNumeric.valueEnabledChkBox->setChecked(false); +//--- } +//--- } +//--- +//--- // Search for name of each string parameter and set it. +//--- foreach(ParamString pString, _paramStrings) +//--- { +//--- paramValueStr = ""; +//--- // The number of the found values for this parameter name. +//--- int numberOfValues = 0; +//--- index = cfgFileData.indexOf(pString.paramCallName, 0, TQt::CaseInsensitive); +//--- // If parameter was found in config file +//--- if (index != -1) +//--- { +//--- while (index != -1) +//--- { +//--- numberOfValues++; +//--- +//--- // Set index after the parameter name, so it points to the front of the string value. +//--- index += pString.paramCallName.length(); +//--- +//--- // Find the end of the parameter by searching for set config file parameter ending. Most of +//--- // time this is a carriage return. +//--- crPos = cfgFileData.indexOf(_cfgFileParameterEnding, index + 1); +//--- +//--- // Get the string and remember it. +//--- if (numberOfValues < 2) +//--- { +//--- paramValueStr = TQString(cfgFileData.mid(index, crPos - index)); +//--- } +//--- // If the same parameter has been set multiple times, concatenate the strings dvivided by a +//--- // |. +//--- else +//--- { +//--- paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index)); +//--- } +//--- +//--- // Get next value for this setting, if one exists. +//--- index = cfgFileData.indexOf(pString.paramCallName, crPos + 1, TQt::CaseInsensitive); +//--- } +//--- // Set the text for the line edit. +//--- pString.lineEdit->setText(paramValueStr); +//--- pString.valueEnabledChkBox->setChecked(true); +//--- } +//--- // Parameter was not found in config file +//--- else +//--- { +//--- paramValueStr = _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); +//--- pString.lineEdit->setText(paramValueStr); +//--- pString.valueEnabledChkBox->setChecked(false); +//--- } +//--- } +//--- +//--- // search for name of each multiple choice parameter and set it +//--- foreach(ParamMultiple pMultiple, _paramMultiples) +//--- { +//--- int i = 0; +//--- index = -1; +//--- +//--- // search for all parameter names of the multiple choice list +//--- // if one is found, set it and leave the while loop +//--- while (i < pMultiple.choicesStrings.count() && index == -1) +//--- { +//--- index = cfgFileData.indexOf(pMultiple.choicesStrings.at(i), 0, TQt::CaseInsensitive); +//--- if (index != -1) +//--- { +//--- pMultiple.comboBox->setCurrentIndex(i); +//--- pMultiple.valueEnabledChkBox->setChecked(true); +//--- } +//--- i++; +//--- } +//--- +//--- // parameter was not set in config file, so use default value +//--- if (index == -1) +//--- { +//--- int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); +//--- pMultiple.comboBox->setCurrentIndex(defaultValue); +//--- pMultiple.valueEnabledChkBox->setChecked(false); +//--- } +//--- } +//--- +//--- return true; +//--- } +//--- +//--- /* +//--- \brief Sets all indenter parameters to their default values defined in the ini file. +//--- */ +//--- void IndentHandler::resetToDefaultValues() +//--- { +//--- // Search for name of each boolean parameter and set its value if found. +//--- foreach(ParamBoolean pBoolean, _paramBooleans) +//--- { +//--- // Boolean value that will be assigned to the checkbox. +//--- bool defaultValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); +//--- pBoolean.checkBox->setChecked(defaultValue); +//--- } +//--- +//--- // Search for name of each numeric parameter and set the value found behind it. +//--- foreach(ParamNumeric pNumeric, _paramNumerics) +//--- { +//--- int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); +//--- pNumeric.spinBox->setValue(defaultValue); +//--- pNumeric.valueEnabledChkBox->setChecked(_indenterSettings->value( +//--- pNumeric.paramName + "/Enabled").toBool()); +//--- } +//--- +//--- // Search for name of each string parameter and set it. +//--- foreach(ParamString pString, _paramStrings) +//--- { +//--- TQString defaultValue = +//--- _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); +//--- pString.lineEdit->setText(defaultValue); +//--- pString.valueEnabledChkBox->setChecked(_indenterSettings->value( +//--- pString.paramName + "/Enabled").toBool()); +//--- } +//--- +//--- // Search for name of each multiple choice parameter and set it. +//--- foreach(ParamMultiple pMultiple, _paramMultiples) +//--- { +//--- int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); +//--- pMultiple.comboBox->setCurrentIndex(defaultValue); +//--- pMultiple.valueEnabledChkBox->setChecked(_indenterSettings->value(pMultiple.paramName + +//--- "/Enabled").toBool()); +//--- } +//--- } +//--- +//--- /* +//--- \brief Opens and parses the indenter ini file that is declared by \a iniFilePath. +//--- */ +//--- void IndentHandler::readIndentIniFile(TQString iniFilePath) +//--- { +//--- Q_ASSERT_X(!iniFilePath.isEmpty(), "readIndentIniFile", "iniFilePath is empty"); +//--- +//--- // open the ini-file that contains all available indenter settings with their additional infos +//--- _indenterSettings = new UiGuiIniFileParser(iniFilePath); +//--- +//--- TQStringList categories; +//--- //TQString indenterGroupString = ""; +//--- TQString paramToolTip = ""; +//--- +//--- // +//--- // parse ini file indenter header +//--- // +//--- +//--- _indenterName = _indenterSettings->value("header/indenterName").toString(); +//--- _indenterFileName = _indenterSettings->value("header/indenterFileName").toString(); +//--- _globalConfigFilename = _indenterSettings->value("header/configFilename").toString(); +//--- _useCfgFileParameter = _indenterSettings->value("header/useCfgFileParameter").toString(); +//--- _cfgFileParameterEnding = _indenterSettings->value("header/cfgFileParameterEnding").toString(); +//--- if (_cfgFileParameterEnding == "cr") +//--- { +//--- _cfgFileParameterEnding = "\n"; +//--- } +//--- _indenterShowHelpParameter = _indenterSettings->value("header/showHelpParameter").toString(); +//--- +//--- if (_indenterFileName.isEmpty()) +//--- { +//--- _errorMessageDialog->showMessage(tr("Indenter ini file header error"), tr( +//--- "The loaded indenter ini file \"%1\"has a faulty header. At least the indenters file name is not set.").arg( +//--- iniFilePath)); +//--- } +//--- +//--- // Read the parameter order. Possible values are (p=parameter[file] i=inputfile o=outputfile) +//--- // pio, ipo, iop +//--- _parameterOrder = _indenterSettings->value("header/parameterOrder", "pio").toString(); +//--- _inputFileParameter = _indenterSettings->value("header/inputFileParameter").toString(); +//--- _inputFileName = _indenterSettings->value("header/inputFileName").toString(); +//--- _outputFileParameter = _indenterSettings->value("header/outputFileParameter").toString(); +//--- _outputFileName = _indenterSettings->value("header/outputFileName").toString(); +//--- _fileTypes = _indenterSettings->value("header/fileTypes").toString(); +//--- _fileTypes.replace('|', " "); +//--- +//--- // read the categories names which are separated by "|" +//--- TQString categoriesStr = _indenterSettings->value("header/categories").toString(); +//--- categories = categoriesStr.split("|"); +//--- // Assure that the category list is never empty. At least contain a "general" section. +//--- if (categories.isEmpty()) +//--- { +//--- categories.append("General"); +//--- } +//--- +//--- IndenterParameterCategoryPage categoryPage; +//--- +//--- // create a page for each category and store its references in a toolboxpage-array +//--- foreach(TQString category, categories) +//--- { +//--- categoryPage.widget = new TQWidget(); +//--- categoryPage.widget->setObjectName(category); +//--- categoryPage.widget->setSizePolicy(TQSizePolicy::MinimumExpanding, +//--- TQSizePolicy::MinimumExpanding); +//--- categoryPage.vboxLayout = new TQVBoxLayout(categoryPage.widget); +//--- categoryPage.vboxLayout->setSpacing(6); +//--- categoryPage.vboxLayout->setMargin(9); +//--- categoryPage.vboxLayout->setObjectName(category); +//--- _indenterParameterCategoryPages.append(categoryPage); +//--- m_indenterParameterCategoriesToolBox->addItem(categoryPage.widget, category); +//--- } +//--- +//--- // +//--- // parse ini file indenter parameters +//--- // +//--- +//--- // read all possible parameters written in brackets [] +//--- _indenterParameters = _indenterSettings->childGroups(); +//--- +//--- // read each parameter to create the corresponding input field +//--- foreach(TQString indenterParameter, _indenterParameters) +//--- { +//--- // if it is not the indent header definition read the parameter and add it to +//--- // the corresponding category toolbox page +//--- if (indenterParameter != "header") +//--- { +//--- // read to which category the parameter belongs +//--- int category = _indenterSettings->value(indenterParameter + "/Category").toInt(); +//--- // Assure that the category number is never greater than the available categories. +//--- if (category > _indenterParameterCategoryPages.size() - 1) +//--- { +//--- category = _indenterParameterCategoryPages.size() - 1; +//--- } +//--- // read which type of input field the parameter needs +//--- TQString editType = _indenterSettings->value(indenterParameter + "/EditorType").toString(); +//--- +//--- // edit type is numeric so create a spinbox with label +//--- if (editType == "numeric") +//--- { +//--- // read the parameter name as it is used at the command line or in its config file +//--- TQString parameterCallName = +//--- _indenterSettings->value(indenterParameter + "/CallName").toString(); +//--- +//--- // create checkbox which enables or disables the parameter +//--- TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); +//--- chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); +//--- chkBox->setToolTip( +//--- "Enables/disables the parameter. If disabled the indenters default value will be used."); +//--- chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); +//--- int left, top, right, bottom; +//--- chkBox->getContentsMargins(&left, &top, &right, &bottom); +//--- chkBox->setContentsMargins(left, top, 0, bottom); +//--- +//--- // create the spinbox +//--- TQSpinBox *spinBox = new TQSpinBox(_indenterParameterCategoryPages.at(category).widget); +//--- paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); +//--- spinBox->setToolTip(paramToolTip); +//--- spinBox->setMaximumWidth(50); +//--- spinBox->setMinimumWidth(50); +//--- if (m_mainWindow != nullptr) +//--- { +//--- spinBox->installEventFilter(m_mainWindow); +//--- } +//--- if (_indenterSettings->value(indenterParameter + "/MinVal").toString() != "") +//--- { +//--- spinBox->setMinimum(_indenterSettings->value(indenterParameter + "/MinVal").toInt()); +//--- } +//--- else +//--- { +//--- spinBox->setMinimum(0); +//--- } +//--- if (_indenterSettings->value(indenterParameter + "/MaxVal").toString() != "") +//--- { +//--- spinBox->setMaximum(_indenterSettings->value(indenterParameter + "/MaxVal").toInt()); +//--- } +//--- else +//--- { +//--- spinBox->setMaximum(2000); +//--- } +//--- +//--- // create the label +//--- TQLabel *label = new TQLabel(_indenterParameterCategoryPages.at(category).widget); +//--- label->setText(indenterParameter); +//--- label->setBuddy(spinBox); +//--- label->setToolTip(paramToolTip); +//--- if (m_mainWindow != nullptr) +//--- { +//--- label->installEventFilter(m_mainWindow); +//--- } +//--- +//--- // put all into a layout and add it to the toolbox page +//--- TQHBoxLayout *hboxLayout = new TQHBoxLayout(); +//--- hboxLayout->addWidget(chkBox); +//--- hboxLayout->addWidget(spinBox); +//--- hboxLayout->addWidget(label); +//--- _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); +//--- +//--- // remember parameter name and reference to its spinbox +//--- ParamNumeric paramNumeric; +//--- paramNumeric.paramName = indenterParameter; +//--- paramNumeric.paramCallName = parameterCallName; +//--- paramNumeric.spinBox = spinBox; +//--- paramNumeric.label = label; +//--- paramNumeric.valueEnabledChkBox = chkBox; +//--- paramNumeric.spinBox->setValue(_indenterSettings->value(paramNumeric.paramName + +//--- "/ValueDefault").toInt()); +//--- _paramNumerics.append(paramNumeric); +//--- +//--- TQObject::connect(spinBox, SIGNAL(valueChanged(int)), this, +//--- SLOT(handleChangedIndenterSettings())); +//--- TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); +//--- } +//--- // edit type is boolean so create a checkbox +//--- else if (editType == "boolean") +//--- { +//--- // create the checkbox, make its settings and add it to the toolbox page +//--- TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); +//--- chkBox->setText(indenterParameter); +//--- paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); +//--- chkBox->setToolTip(paramToolTip); +//--- if (m_mainWindow != nullptr) +//--- { +//--- chkBox->installEventFilter(m_mainWindow); +//--- } +//--- _indenterParameterCategoryPages.at(category).vboxLayout->addWidget(chkBox); +//--- +//--- // remember parameter name and reference to its checkbox +//--- ParamBoolean paramBoolean; +//--- paramBoolean.paramName = indenterParameter; +//--- paramBoolean.checkBox = chkBox; +//--- TQStringList trueFalseStrings = +//--- _indenterSettings->value(indenterParameter + "/TrueFalse").toString().split("|"); +//--- paramBoolean.trueString = trueFalseStrings.at(0); +//--- paramBoolean.falseString = trueFalseStrings.at(1); +//--- paramBoolean.checkBox->setChecked(_indenterSettings->value(paramBoolean.paramName + +//--- "/ValueDefault").toBool()); +//--- _paramBooleans.append(paramBoolean); +//--- +//--- TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); +//--- } +//--- // edit type is numeric so create a line edit with label +//--- else if (editType == "string") +//--- { +//--- // read the parameter name as it is used at the command line or in its config file +//--- TQString parameterCallName = +//--- _indenterSettings->value(indenterParameter + "/CallName").toString(); +//--- +//--- // create check box which enables or disables the parameter +//--- TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); +//--- chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); +//--- chkBox->setToolTip( +//--- "Enables/disables the parameter. If disabled the indenters default value will be used."); +//--- chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); +//--- int left, top, right, bottom; +//--- chkBox->getContentsMargins(&left, &top, &right, &bottom); +//--- chkBox->setContentsMargins(left, top, 0, bottom); +//--- +//--- // create the line edit +//--- TQLineEdit *lineEdit = new TQLineEdit(_indenterParameterCategoryPages.at(category).widget); +//--- paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); +//--- lineEdit->setToolTip(paramToolTip); +//--- lineEdit->setMaximumWidth(50); +//--- lineEdit->setMinimumWidth(50); +//--- if (m_mainWindow != nullptr) +//--- { +//--- lineEdit->installEventFilter(m_mainWindow); +//--- } +//--- +//--- // create the label +//--- TQLabel *label = new TQLabel(_indenterParameterCategoryPages.at(category).widget); +//--- label->setText(indenterParameter); +//--- label->setBuddy(lineEdit); +//--- label->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred); +//--- label->setToolTip(paramToolTip); +//--- if (m_mainWindow != nullptr) +//--- { +//--- label->installEventFilter(m_mainWindow); +//--- } +//--- +//--- // put all into a layout and add it to the toolbox page +//--- TQHBoxLayout *hboxLayout = new TQHBoxLayout(); +//--- hboxLayout->addWidget(chkBox); +//--- hboxLayout->addWidget(lineEdit); +//--- hboxLayout->addWidget(label); +//--- _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); +//--- +//--- // remember parameter name and reference to its line edit +//--- ParamString paramString; +//--- paramString.paramName = indenterParameter; +//--- paramString.paramCallName = parameterCallName; +//--- paramString.lineEdit = lineEdit; +//--- paramString.label = label; +//--- paramString.valueEnabledChkBox = chkBox; +//--- paramString.lineEdit->setText(_indenterSettings->value(paramString.paramName + +//--- "/ValueDefault").toString()); +//--- _paramStrings.append(paramString); +//--- +//--- TQObject::connect(lineEdit, SIGNAL(editingFinished()), this, +//--- SLOT(handleChangedIndenterSettings())); +//--- TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); +//--- } +//--- // edit type is multiple so create a combobox with label +//--- else if (editType == "multiple") +//--- { +//--- // read the parameter name as it is used at the command line or in its config file +//--- TQString parameterCallName = +//--- _indenterSettings->value(indenterParameter + "/CallName").toString(); +//--- +//--- // create checkbox which enables or disables the parameter +//--- TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); +//--- chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); +//--- chkBox->setToolTip( +//--- "Enables/disables the parameter. If disabled the indenters default value will be used."); +//--- chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); +//--- int left, top, right, bottom; +//--- chkBox->getContentsMargins(&left, &top, &right, &bottom); +//--- chkBox->setContentsMargins(left, top, 0, bottom); +//--- +//--- // create the combo box +//--- TQComboBox *comboBox = new TQComboBox(_indenterParameterCategoryPages.at( +//--- category).widget); +//--- TQStringList choicesStrings = +//--- _indenterSettings->value(indenterParameter + "/Choices").toString().split("|"); +//--- TQStringList choicesStringsReadable = _indenterSettings->value( +//--- indenterParameter + "/ChoicesReadable").toString().split("|", TQString::SkipEmptyParts); +//--- if (choicesStringsReadable.isEmpty()) +//--- { +//--- comboBox->addItems(choicesStrings); +//--- } +//--- else +//--- { +//--- comboBox->addItems(choicesStringsReadable); +//--- } +//--- paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); +//--- comboBox->setToolTip(paramToolTip); +//--- if (m_mainWindow != nullptr) +//--- { +//--- comboBox->installEventFilter(m_mainWindow); +//--- } +//--- +//--- // put all into a layout and add it to the toolbox page +//--- TQHBoxLayout *hboxLayout = new TQHBoxLayout(); +//--- hboxLayout->addWidget(chkBox); +//--- hboxLayout->addWidget(comboBox); +//--- _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); +//--- +//--- // remember parameter name and reference to its lineedit +//--- ParamMultiple paramMultiple; +//--- paramMultiple.paramName = indenterParameter; +//--- paramMultiple.paramCallName = parameterCallName; +//--- paramMultiple.comboBox = comboBox; +//--- paramMultiple.choicesStrings = choicesStrings; +//--- paramMultiple.choicesStringsReadable = choicesStringsReadable; +//--- paramMultiple.valueEnabledChkBox = chkBox; +//--- paramMultiple.comboBox->setCurrentIndex(_indenterSettings->value(paramMultiple.paramName + +//--- "/ValueDefault").toInt()); +//--- _paramMultiples.append(paramMultiple); +//--- +//--- TQObject::connect(comboBox, SIGNAL(activated(int)), this, +//--- SLOT(handleChangedIndenterSettings())); +//--- TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); +//--- } +//--- } +//--- } +//--- +//--- // put a spacer at each page end +//--- foreach(IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) +//--- { +//--- categoryPage.vboxLayout->addStretch(); +//--- } +//--- } +//--- +//--- /* +//--- \brief Searches and returns all indenters a configuration file is found for. +//--- +//--- Opens all uigui ini files found in the list \a _indenterIniFileList, opens each ini file +//--- and reads the there defined real name of the indenter. These names are being returned as TQStringList. +//--- */ +//--- TQStringList IndentHandler::getAvailableIndenters() +//--- { +//--- TQStringList indenterNamesList; +//--- +//--- // Loop for every existing uigui ini file +//--- foreach(TQString indenterIniFile, _indenterIniFileList) +//--- { +//--- // Open the ini file and search for the indenter name +//--- TQFile file(m_indenterDirectoryStr + "/" + indenterIniFile); +//--- if (file.open(TQIODevice::ReadOnly | TQIODevice::Text)) +//--- { +//--- int index = -1; +//--- TQByteArray line; +//--- // Search for the string "indenterName=" and get the following string until line end. +//--- while (index == -1 && !file.atEnd()) +//--- { +//--- line = file.readLine(); +//--- index = line.indexOf("indenterName=", 0); +//--- } +//--- +//--- if (index == 0) +//--- { +//--- line = line.remove(0, 13); +//--- indenterNamesList << line.trimmed(); +//--- } +//--- } +//--- } +//--- return indenterNamesList; +//--- } + +/* + \brief Deletes all elements in the toolbox and initializes the indenter selected by \a indenterID. + */ +void IndentHandler::setIndenter(int indenterID) +{ +//--- TQApplication::setOverrideCursor(TQt::WaitCursor); +//--- +//--- // Generate the parameter string that will be saved to the indenters config file. +//--- TQString parameterString = getParameterString(); +//--- if (!_indenterFileName.isEmpty()) +//--- { +//--- saveConfigFile(m_settingsDirectoryStr + "/" + _indenterFileName + ".cfg", parameterString); +//--- } +//--- +//--- // Take care if the selected indenterID is smaller or greater than the number of existing +//--- // indenters +//--- if (indenterID < 0) +//--- { +//--- indenterID = 0; +//--- } +//--- if (indenterID >= _indenterIniFileList.count()) +//--- { +//--- indenterID = _indenterIniFileList.count() - 1; +//--- } +//--- +//--- // MIKE: TODO: need to save selected indenterID into Settings +//--- +//--- // remove all pages from the toolbox +//--- for (int i = 0; i < m_indenterParameterCategoriesToolBox->count(); i++) +//--- { +//--- m_indenterParameterCategoriesToolBox->removeItem(i); +//--- } +//--- +//--- // delete all toolbox pages and by this its children +//--- foreach(IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) +//--- { +//--- delete categoryPage.widget; +//--- } +//--- +//--- // empty all lists, which stored infos for the toolbox pages and its widgets +//--- _indenterParameterCategoryPages.clear(); +//--- _paramStrings.clear(); +//--- _paramNumerics.clear(); +//--- _paramBooleans.clear(); +//--- _paramMultiples.clear(); +//--- delete _indenterSettings; +//--- +//--- readIndentIniFile(m_indenterDirectoryStr + "/" + _indenterIniFileList.at(indenterID)); +//--- +//--- // Find out how the indenter can be executed. +//--- createIndenterCallString(); +//--- +//--- // Load the users last settings made for this indenter. +//--- loadConfigFile(m_settingsDirectoryStr + "/" + _indenterFileName + ".cfg"); +//--- +//--- handleChangedIndenterSettings(); +//--- +//--- TQApplication::restoreOverrideCursor(); +} + +//--- /* +//--- \brief Returns a string containing by the indenter supported file types/extensions divided by a space. +//--- */ +//--- TQString IndentHandler::getPossibleIndenterFileExtensions() +//--- { +//--- return _fileTypes; +//--- } +//--- +//--- /* +//--- \brief Returns the path and filename of the current indenter config file. +//--- */ +//--- TQString IndentHandler::getIndenterCfgFile() +//--- { +//--- TQFileInfo fileInfo(m_indenterDirectoryStr + "/" + _globalConfigFilename); +//--- return fileInfo.absoluteFilePath(); +//--- } +//--- +//--- /* +//--- \brief Tries to create a call path string for the indenter executable. If successful returns true. +//--- */ +//--- bool IndentHandler::createIndenterCallString() +//--- { +//--- TQProcess indentProcess; +//--- +//--- if (_indenterFileName.isEmpty()) +//--- { +//--- return false; +//--- } +//--- +//--- // First try to call the indenter inside of the data dir, using some suffix +//--- // ------------------------------------------------------------------------ +//--- +//--- // Set the directory for the indenter execution +//--- indentProcess.setWorkingDirectory(TQFileInfo(m_indenterDirectoryStr).absoluteFilePath()); +//--- +//--- foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh") +//--- { +//--- m_indenterExecutableSuffix = suffix; +//--- m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" + +//--- _indenterFileName; +//--- m_indenterExecutableCallString += suffix; +//--- +//--- // Only try to call the indenter, if the file exists. +//--- if (TQFile::exists(m_indenterExecutableCallString)) +//--- { +//--- // Only try to call the indenter directly if it is no php file +//--- if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() != "php") +//--- { +//--- indentProcess.start( +//--- "\"" + m_indenterExecutableCallString + +"\" " + _indenterShowHelpParameter); +//--- if (indentProcess.waitForFinished(2000)) +//--- { +//--- m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\""; +//--- return true; +//--- } +//--- else if (indentProcess.error() == TQProcess::Timedout) +//--- { +//--- m_indenterExecutableCallString = "\"" + m_indenterExecutableCallString + "\""; +//--- return true; +//--- } +//--- } +//--- +//--- // Test for needed interpreters +//--- // ---------------------------- +//--- // If the file could not be executed, try to find a shebang at its start or test if its a php +//--- // file. +//--- TQString interpreterName = ""; +//--- TQFile indenterExecutable(m_indenterExecutableCallString); +//--- +//--- // If indenter executable file has .php as suffix, use php as default interpreter +//--- if (TQFileInfo(m_indenterExecutableCallString).suffix().toLower() == "php") +//--- { +//--- interpreterName = "php -f"; +//--- } +//--- // Else try to open the file and read the shebang. +//--- else if (indenterExecutable.open(TQFile::ReadOnly)) +//--- { +//--- // Read the first line of the file. +//--- TQTextStream indenterExecutableContent(&indenterExecutable); +//--- TQString firstLineOfIndenterExe = indenterExecutableContent.readLine(75); +//--- indenterExecutable.close(); +//--- +//--- // If the initial shebang is found, read the named intepreter. e.g. perl +//--- if (firstLineOfIndenterExe.startsWith("#!")) +//--- { +//--- // Get the rightmost word. by splitting the string into only full words. +//--- interpreterName = firstLineOfIndenterExe.split("/").last(); +//--- } +//--- } +//--- +//--- // Try to call the interpreter, if it exists. +//--- if (!interpreterName.isEmpty()) +//--- { +//--- m_indenterExecutableCallString = interpreterName + " \"" + m_indenterExecutableCallString + +//--- "\""; +//--- indentProcess.start(interpreterName + " -h"); +//--- if (indentProcess.waitForFinished(2000)) +//--- { +//--- return true; +//--- } +//--- else if (indentProcess.error() == TQProcess::Timedout) +//--- { +//--- return true; +//--- } +//--- // now we know an interpreter is needed but it could not be called, so inform the user. +//--- else +//--- { +//--- _errorMessageDialog->showMessage(tr("Interpreter needed"), tr( +//--- "To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg( +//--- interpreterName)); +//--- return true; +//--- } +//--- } +//--- } +//--- } +//--- +//--- // If unsuccessful try if the indenter executable is a JavaScript file +//--- // ------------------------------------------------------------------- +//--- m_indenterExecutableSuffix = ".js"; +//--- m_indenterExecutableCallString = TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" + +//--- _indenterFileName; +//--- m_indenterExecutableCallString += m_indenterExecutableSuffix; +//--- if (TQFile::exists(m_indenterExecutableCallString)) +//--- { +//--- return true; +//--- } +//--- +//--- // If unsuccessful try to call the indenter global, using some suffix +//--- // ------------------------------------------------------------------ +//--- foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh") +//--- { +//--- m_indenterExecutableSuffix = suffix; +//--- m_indenterExecutableCallString = _indenterFileName + suffix; +//--- indentProcess.start(m_indenterExecutableCallString + " " + _indenterShowHelpParameter); +//--- if (indentProcess.waitForFinished(2000)) +//--- { +//--- return true; +//--- } +//--- else if (indentProcess.error() == TQProcess::Timedout) +//--- { +//--- return true; +//--- } +//--- } +//--- +//--- // If even globally calling the indenter fails, try calling .com and .exe via wine +//--- // ------------------------------------------------------------------------------- +//--- m_indenterExecutableCallString = "\"" + TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/" + +//--- _indenterFileName; +//--- +//--- foreach(TQString suffix, TQStringList() << ".exe" << ".com") +//--- { +//--- m_indenterExecutableSuffix = suffix; +//--- if (TQFile::exists(m_indenterDirectoryStr + "/" + _indenterFileName + suffix)) +//--- { +//--- TQProcess wineTestProcess; +//--- wineTestProcess.start("wine --version"); +//--- // if the process of wine was not callable assume that wine is not installed +//--- if (!wineTestProcess.waitForFinished(2000)) +//--- { +//--- _errorMessageDialog->showMessage(tr("wine not installed"), tr( +//--- "There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter.")); +//--- m_indenterExecutableCallString = ""; +//--- return false; +//--- } +//--- else +//--- { +//--- m_indenterExecutableCallString = "\"" + +//--- TQFileInfo(m_indenterDirectoryStr).absoluteFilePath() + "/"; +//--- m_indenterExecutableCallString += _indenterFileName + suffix + "\""; +//--- m_indenterExecutableCallString = "wine " + m_indenterExecutableCallString; +//--- +//--- return true; +//--- } +//--- } +//--- } +//--- +//--- m_indenterExecutableCallString = ""; +//--- m_indenterExecutableSuffix = ""; +//--- return false; +//--- } +//--- +//--- /* +//--- \brief Returns a string that points to where the indenters manual can be found. +//--- */ +//--- TQString IndentHandler::getManual() +//--- { +//--- if (_indenterSettings != nullptr) +//--- { +//--- return _indenterSettings->value("header/manual").toString(); +//--- } +//--- else +//--- { +//--- return ""; +//--- } +//--- } + +/* + \brief This slot gets the reference to the indenters manual and opens it. + */ +void IndentHandler::showIndenterManual() const +{ +//--- TQString manualReference = getManual(); +//--- TQDesktopServices::openUrl(manualReference); +} + +//--- /* +//--- \brief Returns the name of the currently selected indenter. +//--- */ +//--- TQString IndentHandler::getCurrentIndenterName() +//--- { +//--- TQString currentIndenterName = m_indenterSelectionCombobox->currentText(); +//--- +//--- // Remove the supported programming languages from indenters name, which are set in braces. +//--- if (currentIndenterName.indexOf("(") > 0) +//--- { +//--- // Using index-1 to also leave out the blank before the brace. +//--- currentIndenterName = currentIndenterName.left(currentIndenterName.indexOf("(") - 1); +//--- } +//--- +//--- return currentIndenterName; +//--- } + +/* + \brief Shows a file open dialog to open an existing config file for the current indenter. + If the file was successfully opened, the indent handler is called to load the settings + and update itself. +*/ +void IndentHandler::openConfigFileDialog() +{ +//--- TQString configFilePath; +//--- +//--- configFilePath = TQFileDialog::getOpenFileName(nullptr, tr( +//--- "Choose indenter config file"), getIndenterCfgFile(), "All files (*.*)"); +//--- +//--- if (configFilePath != "") +//--- { +//--- // If the config file was loaded successfully, inform any who is interested about it. +//--- if (loadConfigFile(configFilePath)) +//--- { +//--- handleChangedIndenterSettings(); +//--- } +//--- } +} + +/* + \brief Calls the "save as" dialog to save the indenter config file under a chosen name. + If the file already exists and it should be overwritten, a warning will be shown before. +*/ +void IndentHandler::saveasIndentCfgFileDialog() +{ +//--- TQString fileExtensions = tr("All files") + " (*.*)"; +//--- +//--- //TQString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", +//--- // fileExtensions ); +//--- TQString fileName = TQFileDialog::getSaveFileName(this, tr( +//--- "Save indent config file"), getIndenterCfgFile(), fileExtensions); +//--- +//--- if (fileName != "") +//--- { +//--- TQFile::remove(fileName); +//--- TQFile outCfgFile(fileName); +//--- outCfgFile.open(TQFile::ReadWrite | TQFile::Text); +//--- outCfgFile.write(getParameterString().toAscii()); +//--- outCfgFile.close(); +//--- } +} + +/* + \brief Invokes the indenter to create a shell script. + Lets the indenter create a shell script for calling the indenter out of any + other application and open a save dialog for saving the shell script. +*/ +void IndentHandler::createIndenterCallShellScript() +{ +//--- TQString shellScriptExtension; +//--- shellScriptExtension = "sh"; +//--- +//--- TQString fileExtensions = tr("Shell Script") + " (*." + shellScriptExtension + ");;" + tr( +//--- "All files") + " (*.*)"; +//--- +//--- TQString currentIndenterName = getCurrentIndenterName(); +//--- currentIndenterName = currentIndenterName.replace(" ", "_"); +//--- +//--- TQString shellScriptFileName = TQFileDialog::getSaveFileName(this, tr( +//--- "Save shell script"), "call_" + currentIndenterName + "." + shellScriptExtension, +//--- fileExtensions); +//--- +//--- // Saving has been canceled if the filename is empty +//--- if (shellScriptFileName.isEmpty()) +//--- { +//--- return; +//--- } +//--- +//--- // Delete any old file, write the new contents and set executable permissions. +//--- TQFile::remove(shellScriptFileName); +//--- TQFile outSrcFile(shellScriptFileName); +//--- if (outSrcFile.open(TQFile::ReadWrite | TQFile::Text)) +//--- { +//--- TQString shellScriptConfigFilename = TQFileInfo(shellScriptFileName).baseName() + "." + +//--- TQFileInfo(_globalConfigFilename).suffix(); +//--- +//--- // Get the content of the shell/batch script. +//--- TQString indenterCallShellScript = generateShellScript(shellScriptConfigFilename); +//--- +//--- // Replace placeholder for script name in script template. +//--- indenterCallShellScript = indenterCallShellScript.replace("__INDENTERCALLSTRINGSCRIPTNAME__", TQFileInfo( +//--- shellScriptFileName).fileName()); +//--- +//--- outSrcFile.write(indenterCallShellScript.toAscii()); +//--- // For non Windows systems set the files executable flag +//--- outSrcFile.setPermissions( +//--- outSrcFile.permissions() | TQFile::ExeOwner | TQFile::ExeUser | TQFile::ExeGroup); +//--- outSrcFile.close(); +//--- +//--- // Save the indenter config file to the same directory, where the shell srcipt was saved to, +//--- // because the script will reference it there via "./". +//--- if (!_globalConfigFilename.isEmpty()) +//--- { +//--- saveConfigFile(TQFileInfo( +//--- shellScriptFileName).path() + "/" + shellScriptConfigFilename, +//--- getParameterString()); +//--- } +//--- } +} + +/* + \brief Resets all parameters to the indenter's default values as they are specified + in the uigui ini file, but asks the user whether to do it really. + */ +void IndentHandler::resetIndenterParameter() +{ +//--- int messageBoxAnswer = TQMessageBox::question(this, tr("Really reset parameters?"), tr( +//--- "Do you really want to reset the indenter parameters to the default values?"), +//--- TQMessageBox::Yes | TQMessageBox::Abort); +//--- if (messageBoxAnswer == TQMessageBox::Yes) +//--- { +//--- resetToDefaultValues(); +//--- } +} + +//--- /* +//--- \brief Catch some events and let some other be handled by the super class. +//--- +//--- Is needed for use as Notepad++ plugin. +//--- */ +//--- bool IndentHandler::event(TQEvent *event) +//--- { +//--- if (event->type() == TQEvent::WindowActivate) +//--- { +//--- event->accept(); +//--- return true; +//--- } +//--- else if (event->type() == TQEvent::WindowDeactivate) +//--- { +//--- event->accept(); +//--- return true; +//--- } +//--- else +//--- { +//--- event->ignore(); +//--- return TQWidget::event(event); +//--- } +//--- } +//--- +//--- /* +//--- \brief Emits the \a indenterSettingsChanged signal +//--- */ +//--- void IndentHandler::handleChangedIndenterSettings() +//--- { +//--- emit(indenterSettingsChanged()); +//--- } +//--- +//--- /* +//--- \brief Returns the id (list index) of the currently selected indenter. +//--- */ +//--- int IndentHandler::getIndenterId() +//--- { +//--- return m_indenterSelectionCombobox->currentIndex(); +//--- } +//--- +//--- htmlText.replace("&", "&"); +//--- htmlText.replace("<", "<"); +//--- htmlText.replace(">", ">"); +//--- htmlText.replace('"', """); +//--- htmlText.replace("'", "'"); +//--- htmlText.replace("^", "ˆ"); +//--- htmlText.replace("~", "˜"); +//--- htmlText.replace("€", "€"); +//--- htmlText.replace("©", "©"); +//--- return htmlText; +//--- } + +#include "IndentHandler.moc" diff --git a/src/IndentHandler.h b/src/IndentHandler.h new file mode 100644 index 0000000..d7b9239 --- /dev/null +++ b/src/IndentHandler.h @@ -0,0 +1,180 @@ +/*************************************************************************** + * Copyright (C) 2006-2012 by Thomas Schweitzer * + * thomas-schweitzer(at)arcor.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2.0 as * + * published by the Free Software Foundation. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program in the file LICENSE.GPL; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef INDENTHANDLER_H +#define INDENTHANDLER_H + +#include + +class MainWindow; +///-- class UiGuiErrorMessage; +///-- class UiGuiIniFileParser; + +class TQComboBox; +class TQToolBox; +class TQToolButton; +class TQVBoxLayout; +///-- class TQMenu; +///-- class TQLabel; +///-- class TQSpinBox; +///-- class TQCheckBox; +///-- class TQLineEdit; + + +class IndentHandler : public TQWidget +{ + Q_OBJECT + + public: + IndentHandler(int indenterID, MainWindow *mainWindow = nullptr, TQWidget *parent = nullptr); + ~IndentHandler(); + +///-- TQString generateShellScript(const TQString &configFilename); +///-- TQString callIndenter(TQString sourceCode, TQString inputFileExtension); +///-- bool loadConfigFile(TQString filePathName); +///-- void resetToDefaultValues(); +///-- TQStringList getAvailableIndenters(); +///-- TQString getPossibleIndenterFileExtensions(); +///-- TQString getParameterString(); +///-- TQString getIndenterCfgFile(); +///-- TQString getManual(); +///-- TQString getCurrentIndenterName(); + void contextMenuEvent(TQContextMenuEvent *event); +///-- int getIndenterId(); +///-- +///-- signals: +///-- void indenterSettingsChanged(); +///-- void selectedIndenterIndexChanged(int index); +///-- +///-- protected: +///-- bool event(TQEvent *event); +///-- void wheelEvent(TQWheelEvent *event); +///-- + private slots: + void setIndenter(int indenterID); + void showIndenterManual() const; + void openConfigFileDialog(); + void saveasIndentCfgFileDialog(); + void createIndenterCallShellScript(); + void resetIndenterParameter(); +///-- void handleChangedIndenterSettings(); +///-- +///-- private: +///-- TQString callExecutableIndenter(TQString sourceCode, TQString inputFileExtension); +///-- TQString callJavaScriptIndenter(TQString sourceCode); +///-- void saveConfigFile(TQString filePathName, TQString parameterString); +///-- void readIndentIniFile(TQString iniFilePath); +///-- bool createIndenterCallString(); +///-- +///-- // Holds a reference to all created pages of the parameter categories toolbox and the pages +///-- // boxlayout +///-- struct IndenterParameterCategoryPage +///-- { +///-- TQWidget *widget; +///-- TQVBoxLayout *vboxLayout; +///-- }; +///-- +///-- TQVector _indenterParameterCategoryPages; +///-- +///-- // Holds a reference to all checkboxes needed for boolean parameter setting and the parameters +///-- // name +///-- struct ParamBoolean +///-- { +///-- TQString paramName; +///-- TQString trueString; +///-- TQString falseString; +///-- TQCheckBox *checkBox; +///-- }; +///-- +///-- TQVector _paramBooleans; +///-- +///-- // Holds a reference to all line edits needed for parameter setting and the parameters name +///-- struct ParamString +///-- { +///-- TQString paramName; +///-- TQString paramCallName; +///-- TQCheckBox *valueEnabledChkBox; +///-- TQLineEdit *lineEdit; +///-- TQLabel *label; +///-- }; +///-- +///-- TQVector _paramStrings; +///-- +///-- // Hold a reference to all spin boxes needed for parameter setting and the parameters name +///-- struct ParamNumeric +///-- { +///-- TQString paramName; +///-- TQString paramCallName; +///-- TQCheckBox *valueEnabledChkBox; +///-- TQSpinBox *spinBox; +///-- TQLabel *label; +///-- }; +///-- +///-- TQVector _paramNumerics; +///-- +///-- // Hold a reference to all combo boxes needed for parameter setting and the parameters name +///-- struct ParamMultiple +///-- { +///-- TQString paramName; +///-- TQString paramCallName; +///-- TQCheckBox *valueEnabledChkBox; +///-- TQComboBox *comboBox; +///-- TQStringList choicesStrings; +///-- TQStringList choicesStringsReadable; +///-- }; +///-- +///-- TQVector _paramMultiples; +///-- + TQComboBox *m_indenterSelectionCombobox; + TQToolButton *m_indenterParameterHelpButton; +///-- // Vertical layout box, into which the toolbox will be added + TQVBoxLayout *m_toolBoxContainerLayout; + TQToolBox *m_indenterParameterCategoriesToolBox; +///-- UiGuiIniFileParser *_indenterSettings; +///-- TQStringList _indenterParameters; +///-- // The indenters name in a descriptive form +///-- TQString _indenterName; +///-- // The indenters file name (w/o extension), that is being called +///-- TQString _indenterFileName; + TQString m_indenterDirectoryStr; + TQString m_tempDirectoryStr; + TQString m_settingsDirectoryStr; +///-- TQStringList _indenterIniFileList; +///-- TQString _parameterOrder; +///-- TQString _globalConfigFilename; +///-- TQString _cfgFileParameterEnding; +///-- TQString _inputFileParameter; +///-- TQString _inputFileName; +///-- TQString _outputFileParameter; +///-- TQString _outputFileName; +///-- TQString _fileTypes; +///-- TQString _useCfgFileParameter; +///-- TQString _indenterShowHelpParameter; + MainWindow *m_mainWindow; + TQWidget *m_parent; +///-- UiGuiErrorMessage *_errorMessageDialog; + TQString m_indenterExecutableCallString; + TQString m_indenterExecutableSuffix; +///-- + +///-- //TODO: This function should go into a string helper/tool class/file. +///-- TQString encodeToHTML(const TQString &text); +}; + +#endif // INDENTHANDLER_H diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 33ec315..36700d4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -25,6 +25,7 @@ #include "stdlib.h" #include "AboutDialog.h" +#include "IndentHandler.h" #include "SettingsPaths.h" #include "UiGuiSettings.h" #include "UiGuiVersion.h" @@ -32,7 +33,6 @@ ///-- #include "AboutDialogGraphicsView.h" ///-- #include "UiGuiSettingsDialog.h" ///-- #include "UiGuiHighlighter.h" -///-- #include "IndentHandler.h" #include #include @@ -47,10 +47,11 @@ #include #include #include +#include #include #include #include -///-- #include +#include ///-- #include ///-- #include ///-- #include @@ -91,10 +92,11 @@ MainWindow::MainWindow(TQString file2OpenOnStart, TQWidget *parent) : m_qTranslator(nullptr), m_uiGuiTranslator(nullptr), m_textEditLineColumnInfoLabel(nullptr), m_oldLinesNumber(0), m_openEncodingActions(), m_saveEncodingActions(), m_encodingActionGroup(nullptr), m_saveEncodedActionGroup(nullptr), - m_highlighterActionGroup(nullptr), m_documentModified(false), m_previewToggled(true) + m_highlighterActionGroup(nullptr), m_documentModified(false), m_previewToggled(true), + m_indentHandler(nullptr), m_centralSplitter(nullptr) ///- _mainWindowForm(nullptr), _settings(nullptr) ///- m_highlighter(nullptr), _aboutDialogGraphicsView(nullptr), _settingsDialog(nullptr) -///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr), _indentHandler(nullptr) +///- m_textEditVScrollBar(nullptr), _toolBarWidget(nullptr) { // Init of some variables. m_sourceCodeChanged = false; @@ -181,6 +183,11 @@ void MainWindow::initMainWindow() actionExportPDF->setIconSet(TQPixmap(ICONS_PATH + "exportpdf.png")); actionExportHTML->setIconSet(TQPixmap(ICONS_PATH + "exporthtml.png")); actionExit->setIconSet(TQPixmap(ICONS_PATH + "system-log-out.png")); + // - Indenter menu + actionLoadIndenterConfigFile->setIconSet(TQPixmap(ICONS_PATH + "load_indent_cfg.png")); + actionSaveIndenterConfigFile->setIconSet(TQPixmap(ICONS_PATH + "save_indent_cfg.png")); + actionCreateShellScript->setIconSet(TQPixmap(ICONS_PATH + "shell.png")); + actionResetIndenterParameters->setIconSet(TQPixmap(ICONS_PATH + "view-refresh.png")); // - Setting menu actionLiveIndentPreview->setIconSet(TQPixmap(ICONS_PATH + "live-preview.png")); actionEnableSyntaxHighlighting->setIconSet(TQPixmap(ICONS_PATH + "syntax-highlight.png")); @@ -193,6 +200,11 @@ void MainWindow::initMainWindow() m_actionClearRecentlyOpenedListId = popupMenuRecentlyOpenedFiles->idAt( popupMenuRecentlyOpenedFiles->count() - 1); + // Central splitter + m_centralSplitter = new TQSplitter(this); + m_centralSplitter->setChildrenCollapsible(true); + setCentralWidget(m_centralSplitter); + // Handle last opened window size // ------------------------------ bool maximized = m_settings->getValueByName("WindowIsMaximized").toBool(); @@ -242,6 +254,7 @@ void MainWindow::initMainWindow() connect(actionSaveSourceFileAs, SIGNAL(activated()), this, SLOT(saveasSourceFileDialog())); connect(actionExportPDF, SIGNAL(activated()), this, SLOT(exportToPDF())); connect(actionExportHTML, SIGNAL(activated()), this, SLOT(exportToHTML())); + ///-- connect(actionShowLog, SIGNAL(activated()), ///-- debugging::TSLogger::getInstance(), SLOT(show())); @@ -301,7 +314,7 @@ void MainWindow::initTextEditor() // Create the TQScintilla widget and add it to the layout. try { - m_qSciSourceCodeEditor = new TQextScintilla(this); + m_qSciSourceCodeEditor = new TQextScintilla(m_centralSplitter); } catch (...) { @@ -311,7 +324,6 @@ void MainWindow::initTextEditor() "versions are not mixed."); exit(1); } - setCentralWidget(m_qSciSourceCodeEditor); // Make some _settings for the TQScintilla widget. m_qSciSourceCodeEditor->setUtf8(true); @@ -445,15 +457,15 @@ bool MainWindow::initApplicationLanguage() */ void MainWindow::initIndenter() { -///-- // Get Id of last selected indenter. -///-- _currentIndenterID = _settings->getValueByName("selectedIndenter").toInt(); -///-- -///-- // Create the indenter widget with the ID and add it to the layout. -///-- _indentHandler = new IndentHandler(_currentIndenterID, this, _mainWindowForm->centralwidget); -///-- _mainWindowForm->vboxLayout->addWidget(_indentHandler); -///-- + // Get Id of last selected indenter. + m_currentIndenterID = m_settings->getValueByName("SelectedIndenter").toInt(); + + // Create the indenter widget with the ID and add it to the layout. + m_indentHandler = new IndentHandler(m_currentIndenterID, this, m_centralSplitter); + m_centralSplitter->moveToFirst(m_indentHandler); + ///-- // If _settings for the indenter have changed, let the main window know aboud it. -///-- connect(_indentHandler, SIGNAL(indenterSettingsChanged()), this, +///-- connect(m_indentHandler, SIGNAL(indenterSettingsChanged()), this, ///-- SLOT(indentSettingsChangedSlot())); ///-- ///-- // Set this true, so the indenter is called at first program start @@ -463,9 +475,6 @@ void MainWindow::initIndenter() ///-- // Handle if indenter parameter tool tips are enabled ///-- _settings->registerObjectProperty(actionIndenterParameterTooltipsEnabled, ///-- "checked", "indenterParameterTooltipsEnabled"); -///-- -///-- // Add the indenters context menu to the mainwindows menu. -///-- _mainWindowForm->menuIndenter->addActions(_indentHandler->getIndenterMenuActions()); } /* @@ -515,7 +524,7 @@ void MainWindow::openSourceFileDialog(const TQString &fileName) TQString openedSourceFileContent = ""; TQString fileExtensions = "*.h *.c *.cpp *.*"; // Remove this line when the indenter is available ///-- TQString fileExtensions = tr("Supported by indenter") + " (" + -///-- _indentHandler->getPossibleIndenterFileExtensions() + ");;" + tr("All files") + " (*.*)"; +///-- m_indentHandler->getPossibleIndenterFileExtensions() + ");;" + tr("All files") + " (*.*)"; TQString fileToOpen = fileName; if (fileToOpen.isEmpty()) @@ -558,7 +567,7 @@ bool MainWindow::saveasSourceFileDialog(TQAction *chosenEncodingAction) { TQString fileExtensions = "*.h *.c *.cpp *.*"; // Remove this line when the indenter is available //--- TQString fileExtensions = tr("Supported by indenter") + " (" + -//--- _indentHandler->getPossibleIndenterFileExtensions() + ");;" + tr("All files") + " (*.*)"; +//--- m_indentHandler->getPossibleIndenterFileExtensions() + ");;" + tr("All files") + " (*.*)"; TQString fileName = TQFileDialog::getSaveFileName(m_currentSourceFile, fileExtensions, this, nullptr, tr("Save source code file")); @@ -674,7 +683,7 @@ void MainWindow::updateSourceView() void MainWindow::callIndenter() { TQApplication::setOverrideCursor(TQCursor(TQt::WaitCursor)); -///-- m_sourceFormattedContent = _indentHandler->callIndenter(m_sourceFileContent, +///-- m_sourceFormattedContent = m_indentHandler->callIndenter(m_sourceFileContent, ///-- m_currentSourceFileExtension); updateSourceView(); TQApplication::restoreOverrideCursor(); @@ -1112,7 +1121,7 @@ void MainWindow::closeEvent(TQCloseEvent *event) ///-- /* ///-- \brief This function is setup to capture tooltip events. ///-- -///-- All widgets that are created by the _indentHandler object and are responsible +///-- All widgets that are created by the m_indentHandler object and are responsible ///-- for indenter parameters are connected with this event filter. ///-- So depending on the _settings the tooltips can be enabled and disabled for these widgets. ///-- */ @@ -1377,9 +1386,6 @@ void MainWindow::numberOfLinesChanged() ///-- // Translate the toolbar. ///-- _toolBarWidget->retranslateUi(_mainWindowForm->toolBar); ///-- -///-- // Translate the indent handler widget. -///-- _indentHandler->retranslateUi(); -///-- ///-- // Translate the load encoding menu. ///-- TQList encodingActionList = m_encodingActionGroup->actions(); ///-- for (i = 0; i < encodingActionList.size(); i++) diff --git a/src/MainWindow.h b/src/MainWindow.h index 022f967..61a9ff9 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -30,12 +30,13 @@ class AboutDialog; /// class AboutDialogGraphicsView; /// class UiGuiHighlighter; -/// class IndentHandler +class IndentHandler; class UiGuiSettings; class ToolBarWidget; /// /// class TQActionGroup; class TQextScintilla; +class TQSplitter; class TQLabel; class TQScrollBar; class TQTranslator; @@ -50,10 +51,10 @@ class MainWindow : public MainWindowBase MainWindow(TQString file2OpenOnStart = "", TQWidget *parent = NULL); ~MainWindow(); -///-- protected: + protected: void closeEvent(TQCloseEvent *event); ///-- bool eventFilter(TQObject *obj, TQEvent *event); -///-- + private slots: void openSourceFileDialog(const TQString &fileName = TQString::null); bool saveSourceFile(); @@ -98,6 +99,7 @@ class MainWindow : public MainWindowBase ///-- void dragEnterEvent(TQDragEnterEvent *event); ///-- void dropEvent(TQDropEvent *event); + TQSplitter *m_centralSplitter; TQextScintilla *m_qSciSourceCodeEditor; UiGuiSettings *m_settings; @@ -113,7 +115,7 @@ class MainWindow : public MainWindowBase int m_actionClearRecentlyOpenedListId; int m_recentlyOpenedListMaxSize; ///-- int _textEditLastScrollPos; -///-- int _currentIndenterID; + int m_currentIndenterID; int m_oldLinesNumber; bool m_loadLastSourceCodeFileOnStartup; TQString m_currentSourceFile; @@ -134,7 +136,7 @@ class MainWindow : public MainWindowBase TQStringList m_recentlyOpenedList; ToolBarWidget *m_toolBarWidget; -///-- IndentHandler *_indentHandler; + IndentHandler *m_indentHandler; TQLabel *m_textEditLineColumnInfoLabel; }; diff --git a/src/MainWindowBase.ui b/src/MainWindowBase.ui index 6b55170..48679d6 100755 --- a/src/MainWindowBase.ui +++ b/src/MainWindowBase.ui @@ -13,17 +13,6 @@ 633 - - - centralWidget - - - 6 - - - 0 - - @@ -60,6 +49,10 @@ + + + + @@ -232,6 +225,56 @@ Ctrl+Q + + + actionLoadIndenterConfigFile + + + Load Indenter Config File + + + Opens a file dialog to load the original config file of the indenter. + + + Alt+O + + + + + actionSaveIndenterConfigFile + + + Save Indenter Config File + + + Opens a dialog to save the current indenter configuration to a file. + + + Alt+S + + + + + actionCreateShellScript + + + Create Indenter Call Shell Script + + + Create a shell script that calls the current selected indenter for formatting a given file with the current indent settings. + + + + + actionResetIndenterParameters + + + Reset indenter parameters + + + Resets all indenter parameters to the default values. + + actionLiveIndentPreview diff --git a/src/SettingsPaths.cpp b/src/SettingsPaths.cpp index 84fecb9..e5410da 100644 --- a/src/SettingsPaths.cpp +++ b/src/SettingsPaths.cpp @@ -63,10 +63,6 @@ void SettingsPaths::init() m_applicationBinaryPath.truncate(m_applicationBinaryPath.length() - 1); } -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - m_applicationBinaryPath += "/plugins/uigui"; -#endif - // If the "config" directory is a subdir of the applications binary path, use this one // (portable mode) m_settingsPath = m_applicationBinaryPath + "/config"; diff --git a/src/__TODO/IndentHandler.cpp b/src/__TODO/IndentHandler.cpp deleted file mode 100644 index 83c79ed..0000000 --- a/src/__TODO/IndentHandler.cpp +++ /dev/null @@ -1,2042 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "IndentHandler.h" - -#include "UiGuiSettings.h" -#include "UiGuiErrorMessage.h" -#include "TemplateBatchScript.h" -#include "UiGuiIniFileParser.h" -#include "SettingsPaths.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_OS_WIN32 - #include -#endif - -// Avoid unused parameter warnings by this template -template -inline void UNUSED_PARAMETER_WARNING_AVOID(T) -{ -} - -// \defgroup grp_Indenter All concerning handling of the indenter. - -/* - \class IndentHandler - \ingroup grp_Indenter - \brief A widget for handling many indenters that are configured by an ini file. - - This is a widget that is used by the main window. It handles access to the - indenter config file and calls the chosen indenter to reformat the source text. - Calls the indenter each time a setting has been changed and informs - the main window about the reformatted source code. -*/ - - -/* - \brief Constructor of the indent handler. - - By calling this constructor the indenter to be loaded, can be selected by setting - its \a indenterID, which is the number of found indenter ini files in alphabetic - order starting at index 0. - */ -IndentHandler::IndentHandler(int indenterID, TQWidget *mainWindow, TQWidget *parent) : - TQWidget(parent), _indenterSelectionCombobox(NULL), _indenterParameterHelpButton(NULL), - _toolBoxContainerLayout(NULL), _indenterParameterCategoriesToolBox(NULL), _indenterSettings( - NULL), _mainWindow(NULL), _errorMessageDialog(NULL), _menuIndenter(NULL), - _actionLoadIndenterConfigFile(NULL), _actionSaveIndenterConfigFile(NULL), - _actionCreateShellScript(NULL), _actionResetIndenterParameters(NULL), - _parameterChangedCallback(NULL), _windowClosedCallback(NULL) -{ - Q_ASSERT_X(indenterID >= 0, "IndentHandler", "the selected indenterID is < 0"); - - setObjectName(TQString::fromUtf8("indentHandler")); - - _mainWindow = mainWindow; - - initIndenterMenu(); - - connect(_actionLoadIndenterConfigFile, SIGNAL(triggered()), this, SLOT(openConfigFileDialog())); - connect(_actionSaveIndenterConfigFile, SIGNAL(triggered()), this, SLOT( - saveasIndentCfgFileDialog())); - connect(_actionCreateShellScript, SIGNAL(triggered()), this, - SLOT(createIndenterCallShellScript())); - connect(_actionResetIndenterParameters, SIGNAL(triggered()), this, - SLOT(resetIndenterParameter())); - - // define this widgets resize behavior - setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding); - - // create vertical layout box, into which the toolbox will be added - _toolBoxContainerLayout = new TQVBoxLayout(this); - _toolBoxContainerLayout->setMargin(2); - - // Create horizontal layout for indenter selector and help button. - TQHBoxLayout *hboxLayout = new TQHBoxLayout(); - //hboxLayout->setMargin(2); - _toolBoxContainerLayout->addLayout(hboxLayout); - - // Create the indenter selection combo box. - _indenterSelectionCombobox = new TQComboBox(this); - _indenterSelectionCombobox->setSizeAdjustPolicy(TQComboBox::AdjustToMinimumContentsLengthWithIcon); - _indenterSelectionCombobox->setMinimumContentsLength(20); - connect(_indenterSelectionCombobox, SIGNAL(activated(int)), this, SLOT(setIndenter(int))); - UiGuiSettings::getInstance()->registerObjectProperty(_indenterSelectionCombobox, "currentIndex", - "selectedIndenter"); - hboxLayout->addWidget(_indenterSelectionCombobox); - - // Create the indenter parameter help button. - _indenterParameterHelpButton = new TQToolButton(this); - _indenterParameterHelpButton->setObjectName(TQString::fromUtf8("indenterParameterHelpButton")); - _indenterParameterHelpButton->setIcon(TQIcon(TQString::fromUtf8(":/mainWindow/help.png"))); - hboxLayout->addWidget(_indenterParameterHelpButton); - // Handle if the indenter parameter help button is pressed. - connect(_indenterParameterHelpButton, SIGNAL(clicked()), this, SLOT(showIndenterManual())); - - // create a toolbox and set its resize behavior - _indenterParameterCategoriesToolBox = new TQToolBox(this); - _indenterParameterCategoriesToolBox->setObjectName(TQString::fromUtf8( - "_indenterParameterCategoriesToolBox")); - -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - connect(_indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, - SLOT(updateDrawing())); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS - - //_indenterParameterCategoriesToolBox->setSizePolicy( TQSizePolicy::Expanding, - // TQSizePolicy::Expanding ); - //_indenterParameterCategoriesToolBox->setMaximumSize(TQSize(16777215, 16777215)); - // insert the toolbox into the vlayout - _toolBoxContainerLayout->addWidget(_indenterParameterCategoriesToolBox); - - _indenterExecutableCallString = ""; - _indenterExecutableSuffix = ""; - - _indenterDirctoryStr = SettingsPaths::getIndenterPath(); - _tempDirctoryStr = SettingsPaths::getTempPath(); - _settingsDirctoryStr = SettingsPaths::getSettingsPath(); - TQDir indenterDirctory = TQDir(_indenterDirctoryStr); - - if (_mainWindow != NULL) - { - _errorMessageDialog = new UiGuiErrorMessage(_mainWindow); - } - else - { - _errorMessageDialog = new UiGuiErrorMessage(this); - } - - _indenterIniFileList = indenterDirctory.entryList(TQStringList("uigui_*.ini")); - if (_indenterIniFileList.count() > 0) - { - // Take care if the selected indenterID is smaller or greater than the number of existing - // indenters - if (indenterID < 0) - { - indenterID = 0; - } - if (indenterID >= _indenterIniFileList.count()) - { - indenterID = _indenterIniFileList.count() - 1; - } - - // Reads and parses the by indenterID defined indent ini file and creates toolbox entries - readIndentIniFile(_indenterDirctoryStr + "/" + _indenterIniFileList.at(indenterID)); - - // Find out how the indenter can be executed. - createIndenterCallString(); - - // Load the users last settings made for this indenter. - loadConfigFile(_settingsDirctoryStr + "/" + _indenterFileName + ".cfg"); - - // Fill the indenter selection combo box with the list of available indenters. - if (!getAvailableIndenters().isEmpty()) - { - _indenterSelectionCombobox->addItems(getAvailableIndenters()); - _indenterSelectionCombobox->setCurrentIndex(indenterID); - connect(_indenterSelectionCombobox, SIGNAL(currentIndexChanged(int)), this, - SIGNAL(selectedIndenterIndexChanged(int))); - } - } - else - { - _errorMessageDialog->showMessage(tr("No indenter ini files"), - tr("There exists no indenter ini files in the directory \"") + - TQDir(_indenterDirctoryStr).absolutePath() + "\"."); - } - - retranslateUi(); -} - -/* - \brief Implicitly writes the current indenter parameters to the indenters config file. - */ -IndentHandler::~IndentHandler() -{ - // Generate the parameter string that will be saved to the indenters config file. - TQString parameterString = getParameterString(); - if (!_indenterFileName.isEmpty()) - { - saveConfigFile(_settingsDirctoryStr + "/" + _indenterFileName + ".cfg", parameterString); - } - - delete _errorMessageDialog; -} - -/* - \brief Initializes the context menu used for some actions like saving the indenter config file. - */ -void IndentHandler::initIndenterMenu() -{ - if (_menuIndenter == NULL) - { - _actionLoadIndenterConfigFile = new TQAction(this); - _actionLoadIndenterConfigFile->setObjectName(TQString::fromUtf8("_actionLoadIndenterConfigFile")); - _actionLoadIndenterConfigFile->setIcon(TQIcon(TQString::fromUtf8( - ":/mainWindow/load_indent_cfg.png"))); - - _actionSaveIndenterConfigFile = new TQAction(this); - _actionSaveIndenterConfigFile->setObjectName(TQString::fromUtf8("_actionSaveIndenterConfigFile")); - _actionSaveIndenterConfigFile->setIcon(TQIcon(TQString::fromUtf8( - ":/mainWindow/save_indent_cfg.png"))); - - _actionCreateShellScript = new TQAction(this); - _actionCreateShellScript->setObjectName(TQString::fromUtf8("_actionCreateShellScript")); - _actionCreateShellScript->setIcon(TQIcon(TQString::fromUtf8(":/mainWindow/shell.png"))); - - _actionResetIndenterParameters = new TQAction(this); - _actionResetIndenterParameters->setObjectName(TQString::fromUtf8( - "_actionResetIndenterParameters")); - _actionResetIndenterParameters->setIcon(TQIcon(TQString::fromUtf8( - ":/mainWindow/view-refresh.png"))); - - _menuIndenter = new TQMenu(this); - _menuIndenter->setObjectName(TQString::fromUtf8("_menuIndenter")); - _menuIndenter->addAction(_actionLoadIndenterConfigFile); - _menuIndenter->addAction(_actionSaveIndenterConfigFile); - _menuIndenter->addAction(_actionCreateShellScript); - _menuIndenter->addAction(_actionResetIndenterParameters); - } -} - -/* - \brief Returns the context menu used for some actions like saving the indenter config file. - */ -TQMenu* IndentHandler::getIndenterMenu() -{ - return _menuIndenter; -} - -/* - \brief Returns the actions of the context menu used for some actions like saving the indenter config file. - */ -TQList IndentHandler::getIndenterMenuActions() -{ - TQList actionList; - actionList << _actionLoadIndenterConfigFile << _actionSaveIndenterConfigFile << - _actionCreateShellScript << _actionResetIndenterParameters; - return actionList; -} - -/* - \brief Opens the context menu, used for some actions like saving the indenter config file, at the event position. - */ -void IndentHandler::contextMenuEvent(TQContextMenuEvent *event) -{ - getIndenterMenu()->exec(event->globalPos()); -} - -/* - \brief Creates the content for a shell script that can be used as a external tool call - to indent an as parameter defined file. - */ -TQString IndentHandler::generateShellScript(const TQString &configFilename) -{ - TQString indenterCompleteCallString; - TQString parameterInputFile; - TQString parameterOuputFile; - TQString parameterParameterFile; - TQString replaceInputFileCommand; - - // Define the placeholder for parameter variables either in batch or bash programming. -#if defined (Q_OS_WIN32) - TQString shellParameterPlaceholder = "%1"; -#else - TQString shellParameterPlaceholder = "$1"; -#endif - - parameterInputFile = " " + _inputFileParameter + "\"" + shellParameterPlaceholder + "\""; - - if (_outputFileParameter != "none" && _outputFileParameter != "stdout") - { - if (_outputFileName == _inputFileName) - { - parameterOuputFile = " " + _outputFileParameter + "\"" + shellParameterPlaceholder + "\""; - } - else - { - parameterOuputFile = " " + _outputFileParameter + _outputFileName + ".tmp"; - } - } - - // If the config file name is empty it is assumed that all parameters are sent via command line - // call - if (_globalConfigFilename.isEmpty()) - { - parameterParameterFile = " " + getParameterString(); - } - // else if needed add the parameter to the indenter call string where the config file can be - // found. - else if (_useCfgFileParameter != "none") - { - parameterParameterFile = " " + _useCfgFileParameter + "\"./" + configFilename + "\""; - } - - // Assemble indenter call string for parameters according to the set order. - if (_parameterOrder == "ipo") - { - indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; - } - else if (_parameterOrder == "pio") - { - indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; - } - else if (_parameterOrder == "poi") - { - indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; - } - else - { - indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; - } - - // Generate the indenter call string either for win32 or other systems. -#if defined (Q_OS_WIN32) - indenterCompleteCallString = _indenterExecutableCallString + indenterCompleteCallString; -#else - indenterCompleteCallString = "#!/bin/bash\n" + _indenterExecutableCallString + - indenterCompleteCallString; -#endif - - // If the indenter writes to stdout pipe the output into a file - if (_outputFileParameter == "stdout") - { - indenterCompleteCallString = indenterCompleteCallString + " >" + _outputFileName + ".tmp"; - } - - // If the output filename is not the same as the input filename copy the output over the input. - if (_outputFileName != _inputFileName) - { -#if defined (Q_OS_WIN32) - replaceInputFileCommand = "move /Y " + _outputFileName + ".tmp \"" + shellParameterPlaceholder + - "\"\n"; -#else - replaceInputFileCommand = "mv " + _outputFileName + ".tmp \"" + shellParameterPlaceholder + - "\"\n"; -#endif - } - -#if defined (Q_OS_WIN32) - TQString shellScript(TemplateBatchScript::getTemplateBatchScript()); - shellScript = shellScript.replace("__INDENTERCALLSTRING2__", - indenterCompleteCallString + "\n" + replaceInputFileCommand); - indenterCompleteCallString = indenterCompleteCallString.replace("%1", "%%G"); - replaceInputFileCommand = replaceInputFileCommand.replace("%1", "%%G"); - shellScript = shellScript.replace("__INDENTERCALLSTRING1__", - indenterCompleteCallString + "\n" + replaceInputFileCommand); -#else - TQString shellScript(TemplateBatchScript::getTemplateBatchScript()); - shellScript = shellScript.replace("__INDENTERCALLSTRING2__", - indenterCompleteCallString + "\n" + replaceInputFileCommand); - indenterCompleteCallString = indenterCompleteCallString.replace("$1", "$file2indent"); - replaceInputFileCommand = replaceInputFileCommand.replace("$1", "$file2indent"); - shellScript = shellScript.replace("__INDENTERCALLSTRING1__", - indenterCompleteCallString + "\n" + replaceInputFileCommand); -#endif - - return shellScript; -} - -/* - \brief Format \a sourceCode by calling the indenter. - - The \a inputFileExtension has to be given as parameter so the called indenter - can identify the programming language if needed. - */ -TQString IndentHandler::callIndenter(TQString sourceCode, TQString inputFileExtension) -{ - if (_indenterExecutableSuffix == ".js") - { - return callJavaScriptIndenter(sourceCode); - } - else - { - return callExecutableIndenter(sourceCode, inputFileExtension); - } -} - -/* - \brief Format \a sourceCode by calling the interpreted JavaScript code of the indenter. - - The \a inputFileExtension has to be given as parameter so the called indenter - can identify the programming language if needed. - */ -TQString IndentHandler::callJavaScriptIndenter(TQString sourceCode) -{ - TQScriptEngine engine; - - engine.globalObject().setProperty("unformattedCode", sourceCode); - - TQFile jsDecoderFile(_indenterExecutableCallString); - TQString jsDecoderCode; - if (jsDecoderFile.open(TQFile::ReadOnly)) - { - jsDecoderCode = jsDecoderFile.readAll(); - } - jsDecoderFile.close(); - - TQScriptValue value = engine.evaluate(jsDecoderCode); - return value.toString(); -} - -/* - \brief Format \a sourceCode by calling the binary executable of the indenter. - - The \a inputFileExtension has to be given as parameter so the called indenter - can identify the programming language if needed. - */ -TQString IndentHandler::callExecutableIndenter(TQString sourceCode, TQString inputFileExtension) -{ - Q_ASSERT_X(!_inputFileName.isEmpty(), "callIndenter", "_inputFileName is empty"); - // Q_ASSERT_X( !_outputFileName.isEmpty(), "callIndenter", "_outputFileName is empty" ); - Q_ASSERT_X(!_indenterFileName.isEmpty(), "callIndenter", "_indenterFileName is empty"); - - if (_indenterFileName.isEmpty()) - { - return ""; - } - - TQString formattedSourceCode; - TQString indenterCompleteCallString; - TQString parameterInputFile; - TQString parameterOuputFile; - TQString parameterParameterFile; - TQProcess indentProcess; - TQString processReturnString; - - // Generate the parameter string that will be saved to the indenters config file - TQString parameterString = getParameterString(); - - if (!_globalConfigFilename.isEmpty()) - { - saveConfigFile(_tempDirctoryStr + "/" + _globalConfigFilename, parameterString); - } - - // Only add a dot to file extension if the string is not empty - if (!inputFileExtension.isEmpty()) - { - inputFileExtension = "." + inputFileExtension; - } - - // Delete any previously used input src file and create a new input src file. - TQFile::remove(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); - TQFile inputSrcFile(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); - // Write the source code to the input file for the indenter - if (inputSrcFile.open(TQFile::ReadWrite | TQFile::Text)) - { - inputSrcFile.write(sourceCode.toUtf8()); - inputSrcFile.close(); - tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Wrote to be indented source code to file " << - inputSrcFile.fileName(); - } - else - { - qCritical() << __LINE__ << " " << __FUNCTION__ << - ": Couldn't write to be indented source code to file " << inputSrcFile.fileName(); - } - - // Set the input file for the to be called indenter. - if (_inputFileParameter.trimmed() == "<" || _inputFileParameter == "stdin") - { - parameterInputFile = ""; - indentProcess.setStandardInputFile(inputSrcFile.fileName()); - } - else - { - parameterInputFile = " " + _inputFileParameter + _inputFileName + inputFileExtension; - } - - // Set the output file for the to be called indenter. - if (_outputFileParameter != "none" && _outputFileParameter != "stdout") - { - parameterOuputFile = " " + _outputFileParameter + _outputFileName + inputFileExtension; - } - -#ifdef Q_OS_WIN32 - // Paths may contain Unicode or other foreign characters. Windows commands line tools will - // receive als falsely encoded path string by TQProcess or they connot correctly handle - // the Unicode path on their own. - // Because of this the path gets converted to Windows short paths using the 8.3 notation. - - tqDebug() << __LINE__ << " " << __FUNCTION__ << - ": Temp dir before trying to convert it to short Windows path is" << _tempDirctoryStr; - - // At first convert the temp path to Windows like separators. - TQString tempDirctoryStrHelper = - TQDir::toNativeSeparators(_tempDirctoryStr).replace("\\", "\\\\"); - // Then convert the TQString to a WCHAR array and NULL terminate it. - WCHAR *tempDirctoryWindowsStr = new WCHAR[tempDirctoryStrHelper.length() + 1]; - tempDirctoryStrHelper.toWCharArray(tempDirctoryWindowsStr); - tempDirctoryWindowsStr[tempDirctoryStrHelper.length()] = (WCHAR)NULL; - - // Get the length of the resulting short path. - long length = 0; - TCHAR *buffer = NULL; - length = GetShortPathName((LPCTSTR)tempDirctoryWindowsStr, NULL, 0); - - // If the short path could be retrieved, create a correct sized buffer, store the - // short path in it and convert all back to TQString. - if (length != 0) - { - #ifdef UNICODE - buffer = new WCHAR[length]; - length = GetShortPathName((LPCTSTR)tempDirctoryWindowsStr, buffer, length); - tempDirctoryStrHelper = TQString::fromWCharArray(buffer); - #else - buffer = new TCHAR[length]; - length = GetShortPathName((LPCTSTR)tempDirctoryWindowsStr, buffer, length); - tempDirctoryStrHelper = buffer; - #endif - _tempDirctoryStr = TQDir::fromNativeSeparators(tempDirctoryStrHelper).replace("//", "/"); - delete[] buffer; - - // Check whether the short path still contains some kind of non ascii characters. - if (_tempDirctoryStr.length() != _tempDirctoryStr.toAscii().length()) - { - tqWarning() << __LINE__ << " " << __FUNCTION__ << - ": Shortened path still contains non ascii characters. Could cause some indenters not to work properly!"; - } - } - else - { - tqWarning() << __LINE__ << " " << __FUNCTION__ << - ": Couldn't retrieve a short version of the temporary path!"; - } - - tqDebug() << __LINE__ << " " << __FUNCTION__ << - ": Temp dir after trying to convert it to short Windows path is " << _tempDirctoryStr; - - delete[] tempDirctoryWindowsStr; -#endif - - // If the config file name is empty it is assumed that all parameters are sent via command line - // call - if (_globalConfigFilename.isEmpty()) - { - parameterParameterFile = " " + parameterString; - } - // if needed add the parameter to the indenter call string where the config file can be found - else if (_useCfgFileParameter != "none") - { - parameterParameterFile = " " + _useCfgFileParameter + "\"" + _tempDirctoryStr + "/" + - _globalConfigFilename + "\""; - } - - // Assemble indenter call string for parameters according to the set order. - if (_parameterOrder == "ipo") - { - indenterCompleteCallString = parameterInputFile + parameterParameterFile + parameterOuputFile; - } - else if (_parameterOrder == "pio") - { - indenterCompleteCallString = parameterParameterFile + parameterInputFile + parameterOuputFile; - } - else if (_parameterOrder == "poi") - { - indenterCompleteCallString = parameterParameterFile + parameterOuputFile + parameterInputFile; - } - else - { - indenterCompleteCallString = parameterInputFile + parameterOuputFile + parameterParameterFile; - } - - // If no indenter executable call string could be created before, show an error message. - if (_indenterExecutableCallString.isEmpty()) - { - _errorMessageDialog->showMessage(tr("No indenter executable"), tr( - "There exists no indenter executable with the name \"%1\" in the directory \"%2\" nor in the global environment.").arg( - _indenterFileName).arg(_indenterDirctoryStr)); - return sourceCode; - } - - // Generate the indenter call string either for win32 or other systems. - indenterCompleteCallString = _indenterExecutableCallString + indenterCompleteCallString; - - // errors and standard outputs from the process call are merged together - //indentProcess.setReadChannelMode(TQProcess::MergedChannels); - - // Set the directory where the indenter will be executed for the process' environment as PWD. - TQStringList env = indentProcess.environment(); - env << "PWD=" + TQFileInfo(_tempDirctoryStr).absoluteFilePath(); - indentProcess.setEnvironment(env); - - // Set the directory for the indenter execution - indentProcess.setWorkingDirectory(TQFileInfo(_tempDirctoryStr).absoluteFilePath()); - - tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Will call the indenter in the directory " << - indentProcess.workingDirectory() << " using this commandline call: " << - indenterCompleteCallString; - - indentProcess.start(indenterCompleteCallString); - - processReturnString = ""; - bool calledProcessSuccessfully = indentProcess.waitForFinished(10000); - // test if there was an error during starting the process of the indenter - if (!calledProcessSuccessfully) - { - processReturnString = ""; - processReturnString += tr("Returned error message: ") + indentProcess.errorString() + - "
"; - - switch (indentProcess.error()) - { - case TQProcess::FailedToStart: - { - processReturnString += tr("Reason could be: ") + - "The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
"; - break; - } - - case TQProcess::Crashed: - { - processReturnString += "The process crashed some time after starting successfully.
"; - break; - } - - case TQProcess::Timedout: - { - processReturnString += - "The called indenter did not response for over 10 seconds, so aborted its execution.
"; - break; - } - - case TQProcess::WriteError: - { - processReturnString += - "An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.
"; - break; - } - - case TQProcess::ReadError: - { - processReturnString += - "An error occurred when attempting to read from the process. For example, the process may not be running.
"; - break; - } - - case TQProcess::UnknownError: - { - processReturnString += - "An unknown error occurred. This is the default return value of error().
"; - break; - } - - default: - { - break; - } - } - processReturnString += tr("
Callstring was: ") + encodeToHTML( - indenterCompleteCallString); - processReturnString += tr("

Indenter output was:
") + "
" + "(STDOUT):" + - encodeToHTML(indentProcess.readAllStandardOutput()) + "
" + "(STDERR):" + - encodeToHTML(indentProcess.readAllStandardError()) + "
" + "
"; - tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; - TQApplication::restoreOverrideCursor(); - _errorMessageDialog->showMessage(tr("Error calling Indenter"), processReturnString); - } - - // If the indenter returned an error code != 0 show its output. - if (indentProcess.exitCode() != 0) - { - TQString exitCode; - exitCode.setNum(indentProcess.exitCode()); - processReturnString = tr("Indenter returned with exit code: ") + exitCode + "
" + tr( - "Indent console output was: ") + "
" + "(STDOUT):" + encodeToHTML( - indentProcess.readAllStandardOutput()) + "
" + "(STDERR):" + encodeToHTML( - indentProcess.readAllStandardError()) + "
" + tr("
Callstring was: ") + - encodeToHTML(indenterCompleteCallString) + ""; - tqWarning() << __LINE__ << " " << __FUNCTION__ << processReturnString; - TQApplication::restoreOverrideCursor(); - _errorMessageDialog->showMessage(tr("Indenter returned error"), processReturnString); - } - - // Only get the formatted source code, if calling the indenter did succeed. - if (calledProcessSuccessfully) - { - // If the indenter results are written to stdout, read them from there... - if (indentProcess.exitCode() == 0 && _outputFileParameter == "stdout") - { - formattedSourceCode = indentProcess.readAllStandardOutput(); - tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from StdOut."; - } - // ... else read the output file generated by the indenter call. - else - { - TQFile outSrcFile(_tempDirctoryStr + "/" + _outputFileName + inputFileExtension); - if (outSrcFile.open(TQFile::ReadOnly | TQFile::Text)) - { - TQTextStream outSrcStrm(&outSrcFile); - outSrcStrm.setCodec(TQTextCodec::codecForName("UTF-8")); - formattedSourceCode = outSrcStrm.readAll(); - outSrcFile.close(); - tqDebug() << __LINE__ << " " << __FUNCTION__ << ": Read indenter output from file " << - outSrcFile.fileName(); - } - else - { - qCritical() << __LINE__ << " " << __FUNCTION__ << - ": Couldn't read indenter output from file " << outSrcFile.fileName(); - } - } - } - else - { - return sourceCode; - } - - // Delete the temporary input and output files. - TQFile::remove(_tempDirctoryStr + "/" + _outputFileName + inputFileExtension); - TQFile::remove(_tempDirctoryStr + "/" + _inputFileName + inputFileExtension); - - return formattedSourceCode; -} - -/* - \brief Generates and returns a string with all parameters needed to call the indenter. - */ -TQString IndentHandler::getParameterString() -{ - TQString parameterString = ""; - - // generate parameter string for all boolean values - foreach(ParamBoolean pBoolean, _paramBooleans) - { - if (pBoolean.checkBox->isChecked()) - { - if (!pBoolean.trueString.isEmpty()) - { - parameterString += pBoolean.trueString + _cfgFileParameterEnding; - } - } - else - { - if (!pBoolean.falseString.isEmpty()) - { - parameterString += pBoolean.falseString + _cfgFileParameterEnding; - } - } - } - - // generate parameter string for all numeric values - foreach(ParamNumeric pNumeric, _paramNumerics) - { - if (pNumeric.valueEnabledChkBox->isChecked()) - { - parameterString += pNumeric.paramCallName + TQString::number(pNumeric.spinBox->value()) + - _cfgFileParameterEnding; - } - } - - // generate parameter string for all string values - foreach(ParamString pString, _paramStrings) - { - if (!pString.lineEdit->text().isEmpty() && pString.valueEnabledChkBox->isChecked()) - { - // Create parameter definition for each value devided by a | sign. - foreach(TQString paramValue, pString.lineEdit->text().split("|")) - { - parameterString += pString.paramCallName + paramValue + _cfgFileParameterEnding; - } - } - } - - // generate parameter string for all multiple choice values - foreach(ParamMultiple pMultiple, _paramMultiples) - { - if (pMultiple.valueEnabledChkBox->isChecked()) - { - parameterString += pMultiple.choicesStrings.at(pMultiple.comboBox->currentIndex()) + - _cfgFileParameterEnding; - } - } - - return parameterString; -} - -/* - \brief Write settings for the indenter to a config file. - */ -void IndentHandler::saveConfigFile(TQString filePathName, TQString paramString) -{ - TQFile::remove(filePathName); - TQFile cfgFile(filePathName); - - cfgFile.open(TQFile::ReadWrite | TQFile::Text); - cfgFile.write(paramString.toAscii()); - cfgFile.close(); -} - -/* - \brief Load the config file for the indenter and apply the settings made there. - */ -bool IndentHandler::loadConfigFile(TQString filePathName) -{ - TQFile cfgFile(filePathName); - int index; - int crPos; - int paramValue = 0; - TQString paramValueStr = ""; - TQString cfgFileData = ""; - - // If the to be loaded config file does not exist leave all values as they are and return false. - if (!cfgFile.exists()) - { - return false; - } - // else if the to be read config file exists, retrieve its whole content. - else - { - // Open the config file and read all data - cfgFile.open(TQFile::ReadOnly | TQFile::Text); - cfgFileData = cfgFile.readAll(); - cfgFile.close(); - } - - // Search for name of each boolean parameter and set its value if found. - foreach(ParamBoolean pBoolean, _paramBooleans) - { - // boolean value that will be assigned to the checkbox - bool paramValue = false; - - // first search for the longer parameter string - // the true parameter string is longer than the false string - if (pBoolean.trueString.length() > pBoolean.falseString.length()) - { - // search for the true string - index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive); - // if true string found set the parameter value to true - if (index != -1) - { - paramValue = true; - } - // if true string not found, search for false string - else - { - index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive); - // if false string found set the parameter value to false - if (index != -1) - { - paramValue = false; - } - // neither true nor false parameter found so use default value - else - { - paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); - } - } - } - // the false parameter string is longer than the true string - else - { - // search for the false string - index = cfgFileData.indexOf(pBoolean.falseString, 0, TQt::CaseInsensitive); - // if false string found set the parameter value to false - if (index != -1) - { - paramValue = false; - } - // if false string not found, search for true string - else - { - index = cfgFileData.indexOf(pBoolean.trueString, 0, TQt::CaseInsensitive); - // if true string found set the parameter value to true - if (index != -1) - { - paramValue = true; - } - // neither true nor false parameter found so use default value - else - { - paramValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); - } - } - } - pBoolean.checkBox->setChecked(paramValue); - } - - // Search for name of each numeric parameter and set the value found behind it. - foreach(ParamNumeric pNumeric, _paramNumerics) - { - index = cfgFileData.indexOf(pNumeric.paramCallName, 0, TQt::CaseInsensitive); - // parameter was found in config file - if (index != -1) - { - // set index after the parameter name, so in front of the number - index += pNumeric.paramCallName.length(); - - // Find the end of the parameter by searching for set config file parameter ending. Most of - // time this is a carriage return. - crPos = cfgFileData.indexOf(_cfgFileParameterEnding, index + 1); - - // get the number and convert it to int - TQString test = cfgFileData.mid(index, crPos - index); - paramValue = cfgFileData.mid(index, crPos - index).toInt(NULL); - - // disable the signal-slot connection. Otherwise signal is emmitted each time when value is - // set - TQObject::disconnect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, - SLOT(handleChangedIndenterSettings())); - pNumeric.spinBox->setValue(paramValue); - pNumeric.valueEnabledChkBox->setChecked(true); - TQObject::connect(pNumeric.spinBox, SIGNAL(valueChanged(int)), this, - SLOT(handleChangedIndenterSettings())); - } - // parameter was not found in config file - else - { - int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); - pNumeric.spinBox->setValue(defaultValue); - pNumeric.valueEnabledChkBox->setChecked(false); - } - } - - // Search for name of each string parameter and set it. - foreach(ParamString pString, _paramStrings) - { - paramValueStr = ""; - // The number of the found values for this parameter name. - int numberOfValues = 0; - index = cfgFileData.indexOf(pString.paramCallName, 0, TQt::CaseInsensitive); - // If parameter was found in config file - if (index != -1) - { - while (index != -1) - { - numberOfValues++; - - // Set index after the parameter name, so it points to the front of the string value. - index += pString.paramCallName.length(); - - // Find the end of the parameter by searching for set config file parameter ending. Most of - // time this is a carriage return. - crPos = cfgFileData.indexOf(_cfgFileParameterEnding, index + 1); - - // Get the string and remember it. - if (numberOfValues < 2) - { - paramValueStr = TQString(cfgFileData.mid(index, crPos - index)); - } - // If the same parameter has been set multiple times, concatenate the strings dvivided by a - // |. - else - { - paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index)); - } - - // Get next value for this setting, if one exists. - index = cfgFileData.indexOf(pString.paramCallName, crPos + 1, TQt::CaseInsensitive); - } - // Set the text for the line edit. - pString.lineEdit->setText(paramValueStr); - pString.valueEnabledChkBox->setChecked(true); - } - // Parameter was not found in config file - else - { - paramValueStr = _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); - pString.lineEdit->setText(paramValueStr); - pString.valueEnabledChkBox->setChecked(false); - } - } - - // search for name of each multiple choice parameter and set it - foreach(ParamMultiple pMultiple, _paramMultiples) - { - int i = 0; - index = -1; - - // search for all parameter names of the multiple choice list - // if one is found, set it and leave the while loop - while (i < pMultiple.choicesStrings.count() && index == -1) - { - index = cfgFileData.indexOf(pMultiple.choicesStrings.at(i), 0, TQt::CaseInsensitive); - if (index != -1) - { - pMultiple.comboBox->setCurrentIndex(i); - pMultiple.valueEnabledChkBox->setChecked(true); - } - i++; - } - - // parameter was not set in config file, so use default value - if (index == -1) - { - int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); - pMultiple.comboBox->setCurrentIndex(defaultValue); - pMultiple.valueEnabledChkBox->setChecked(false); - } - } - - return true; -} - -/* - \brief Sets all indenter parameters to their default values defined in the ini file. - */ -void IndentHandler::resetToDefaultValues() -{ - // Search for name of each boolean parameter and set its value if found. - foreach(ParamBoolean pBoolean, _paramBooleans) - { - // Boolean value that will be assigned to the checkbox. - bool defaultValue = _indenterSettings->value(pBoolean.paramName + "/ValueDefault").toBool(); - pBoolean.checkBox->setChecked(defaultValue); - } - - // Search for name of each numeric parameter and set the value found behind it. - foreach(ParamNumeric pNumeric, _paramNumerics) - { - int defaultValue = _indenterSettings->value(pNumeric.paramName + "/ValueDefault").toInt(); - pNumeric.spinBox->setValue(defaultValue); - pNumeric.valueEnabledChkBox->setChecked(_indenterSettings->value( - pNumeric.paramName + "/Enabled").toBool()); - } - - // Search for name of each string parameter and set it. - foreach(ParamString pString, _paramStrings) - { - TQString defaultValue = - _indenterSettings->value(pString.paramName + "/ValueDefault").toString(); - pString.lineEdit->setText(defaultValue); - pString.valueEnabledChkBox->setChecked(_indenterSettings->value( - pString.paramName + "/Enabled").toBool()); - } - - // Search for name of each multiple choice parameter and set it. - foreach(ParamMultiple pMultiple, _paramMultiples) - { - int defaultValue = _indenterSettings->value(pMultiple.paramName + "/ValueDefault").toInt(); - pMultiple.comboBox->setCurrentIndex(defaultValue); - pMultiple.valueEnabledChkBox->setChecked(_indenterSettings->value(pMultiple.paramName + - "/Enabled").toBool()); - } -} - -/* - \brief Opens and parses the indenter ini file that is declared by \a iniFilePath. - */ -void IndentHandler::readIndentIniFile(TQString iniFilePath) -{ - Q_ASSERT_X(!iniFilePath.isEmpty(), "readIndentIniFile", "iniFilePath is empty"); - - // open the ini-file that contains all available indenter settings with their additional infos - _indenterSettings = new UiGuiIniFileParser(iniFilePath); - - TQStringList categories; - //TQString indenterGroupString = ""; - TQString paramToolTip = ""; - - // - // parse ini file indenter header - // - - _indenterName = _indenterSettings->value("header/indenterName").toString(); - _indenterFileName = _indenterSettings->value("header/indenterFileName").toString(); - _globalConfigFilename = _indenterSettings->value("header/configFilename").toString(); - _useCfgFileParameter = _indenterSettings->value("header/useCfgFileParameter").toString(); - _cfgFileParameterEnding = _indenterSettings->value("header/cfgFileParameterEnding").toString(); - if (_cfgFileParameterEnding == "cr") - { - _cfgFileParameterEnding = "\n"; - } - _indenterShowHelpParameter = _indenterSettings->value("header/showHelpParameter").toString(); - - if (_indenterFileName.isEmpty()) - { - _errorMessageDialog->showMessage(tr("Indenter ini file header error"), tr( - "The loaded indenter ini file \"%1\"has a faulty header. At least the indenters file name is not set.").arg( - iniFilePath)); - } - - // Read the parameter order. Possible values are (p=parameter[file] i=inputfile o=outputfile) - // pio, ipo, iop - _parameterOrder = _indenterSettings->value("header/parameterOrder", "pio").toString(); - _inputFileParameter = _indenterSettings->value("header/inputFileParameter").toString(); - _inputFileName = _indenterSettings->value("header/inputFileName").toString(); - _outputFileParameter = _indenterSettings->value("header/outputFileParameter").toString(); - _outputFileName = _indenterSettings->value("header/outputFileName").toString(); - _fileTypes = _indenterSettings->value("header/fileTypes").toString(); - _fileTypes.replace('|', " "); - - // read the categories names which are separated by "|" - TQString categoriesStr = _indenterSettings->value("header/categories").toString(); - categories = categoriesStr.split("|"); - // Assure that the category list is never empty. At least contain a "general" section. - if (categories.isEmpty()) - { - categories.append("General"); - } - - IndenterParameterCategoryPage categoryPage; - - // create a page for each category and store its references in a toolboxpage-array - foreach(TQString category, categories) - { - categoryPage.widget = new TQWidget(); - categoryPage.widget->setObjectName(category); - categoryPage.widget->setSizePolicy(TQSizePolicy::MinimumExpanding, - TQSizePolicy::MinimumExpanding); - categoryPage.vboxLayout = new TQVBoxLayout(categoryPage.widget); - categoryPage.vboxLayout->setSpacing(6); - categoryPage.vboxLayout->setMargin(9); - categoryPage.vboxLayout->setObjectName(category); - _indenterParameterCategoryPages.append(categoryPage); - _indenterParameterCategoriesToolBox->addItem(categoryPage.widget, category); - } - - // - // parse ini file indenter parameters - // - - // read all possible parameters written in brackets [] - _indenterParameters = _indenterSettings->childGroups(); - - // read each parameter to create the corresponding input field - foreach(TQString indenterParameter, _indenterParameters) - { - // if it is not the indent header definition read the parameter and add it to - // the corresponding category toolbox page - if (indenterParameter != "header") - { - // read to which category the parameter belongs - int category = _indenterSettings->value(indenterParameter + "/Category").toInt(); - // Assure that the category number is never greater than the available categories. - if (category > _indenterParameterCategoryPages.size() - 1) - { - category = _indenterParameterCategoryPages.size() - 1; - } - // read which type of input field the parameter needs - TQString editType = _indenterSettings->value(indenterParameter + "/EditorType").toString(); - - // edit type is numeric so create a spinbox with label - if (editType == "numeric") - { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - _indenterSettings->value(indenterParameter + "/CallName").toString(); - - // create checkbox which enables or disables the parameter - TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); - chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); - chkBox->setToolTip( - "Enables/disables the parameter. If disabled the indenters default value will be used."); - chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); - int left, top, right, bottom; - chkBox->getContentsMargins(&left, &top, &right, &bottom); - chkBox->setContentsMargins(left, top, 0, bottom); - - // create the spinbox - TQSpinBox *spinBox = new TQSpinBox(_indenterParameterCategoryPages.at(category).widget); - paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); - spinBox->setToolTip(paramToolTip); - spinBox->setMaximumWidth(50); - spinBox->setMinimumWidth(50); - if (_mainWindow != NULL) - { - spinBox->installEventFilter(_mainWindow); - } - if (_indenterSettings->value(indenterParameter + "/MinVal").toString() != "") - { - spinBox->setMinimum(_indenterSettings->value(indenterParameter + "/MinVal").toInt()); - } - else - { - spinBox->setMinimum(0); - } - if (_indenterSettings->value(indenterParameter + "/MaxVal").toString() != "") - { - spinBox->setMaximum(_indenterSettings->value(indenterParameter + "/MaxVal").toInt()); - } - else - { - spinBox->setMaximum(2000); - } - - // create the label - TQLabel *label = new TQLabel(_indenterParameterCategoryPages.at(category).widget); - label->setText(indenterParameter); - label->setBuddy(spinBox); - label->setToolTip(paramToolTip); - if (_mainWindow != NULL) - { - label->installEventFilter(_mainWindow); - } - - // put all into a layout and add it to the toolbox page - TQHBoxLayout *hboxLayout = new TQHBoxLayout(); - hboxLayout->addWidget(chkBox); - hboxLayout->addWidget(spinBox); - hboxLayout->addWidget(label); - _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); - - // remember parameter name and reference to its spinbox - ParamNumeric paramNumeric; - paramNumeric.paramName = indenterParameter; - paramNumeric.paramCallName = parameterCallName; - paramNumeric.spinBox = spinBox; - paramNumeric.label = label; - paramNumeric.valueEnabledChkBox = chkBox; - paramNumeric.spinBox->setValue(_indenterSettings->value(paramNumeric.paramName + - "/ValueDefault").toInt()); - _paramNumerics.append(paramNumeric); - - TQObject::connect(spinBox, SIGNAL(valueChanged(int)), this, - SLOT(handleChangedIndenterSettings())); - TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(updateDrawing())); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS - } - // edit type is boolean so create a checkbox - else if (editType == "boolean") - { - // create the checkbox, make its settings and add it to the toolbox page - TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); - chkBox->setText(indenterParameter); - paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); - chkBox->setToolTip(paramToolTip); - if (_mainWindow != NULL) - { - chkBox->installEventFilter(_mainWindow); - } - _indenterParameterCategoryPages.at(category).vboxLayout->addWidget(chkBox); - - // remember parameter name and reference to its checkbox - ParamBoolean paramBoolean; - paramBoolean.paramName = indenterParameter; - paramBoolean.checkBox = chkBox; - TQStringList trueFalseStrings = - _indenterSettings->value(indenterParameter + "/TrueFalse").toString().split("|"); - paramBoolean.trueString = trueFalseStrings.at(0); - paramBoolean.falseString = trueFalseStrings.at(1); - paramBoolean.checkBox->setChecked(_indenterSettings->value(paramBoolean.paramName + - "/ValueDefault").toBool()); - _paramBooleans.append(paramBoolean); - - TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); - } - // edit type is numeric so create a line edit with label - else if (editType == "string") - { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - _indenterSettings->value(indenterParameter + "/CallName").toString(); - - // create check box which enables or disables the parameter - TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); - chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); - chkBox->setToolTip( - "Enables/disables the parameter. If disabled the indenters default value will be used."); - chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); - int left, top, right, bottom; - chkBox->getContentsMargins(&left, &top, &right, &bottom); - chkBox->setContentsMargins(left, top, 0, bottom); - - // create the line edit - TQLineEdit *lineEdit = new TQLineEdit(_indenterParameterCategoryPages.at(category).widget); - paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); - lineEdit->setToolTip(paramToolTip); - lineEdit->setMaximumWidth(50); - lineEdit->setMinimumWidth(50); - if (_mainWindow != NULL) - { - lineEdit->installEventFilter(_mainWindow); - } - - // create the label - TQLabel *label = new TQLabel(_indenterParameterCategoryPages.at(category).widget); - label->setText(indenterParameter); - label->setBuddy(lineEdit); - label->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred); - label->setToolTip(paramToolTip); - if (_mainWindow != NULL) - { - label->installEventFilter(_mainWindow); - } - - // put all into a layout and add it to the toolbox page - TQHBoxLayout *hboxLayout = new TQHBoxLayout(); - hboxLayout->addWidget(chkBox); - hboxLayout->addWidget(lineEdit); - hboxLayout->addWidget(label); - _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); - - // remember parameter name and reference to its line edit - ParamString paramString; - paramString.paramName = indenterParameter; - paramString.paramCallName = parameterCallName; - paramString.lineEdit = lineEdit; - paramString.label = label; - paramString.valueEnabledChkBox = chkBox; - paramString.lineEdit->setText(_indenterSettings->value(paramString.paramName + - "/ValueDefault").toString()); - _paramStrings.append(paramString); - - TQObject::connect(lineEdit, SIGNAL(editingFinished()), this, - SLOT(handleChangedIndenterSettings())); - TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - connect(lineEdit, SIGNAL(textChanged(const TQString)), this, SLOT(updateDrawing())); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS - } - // edit type is multiple so create a combobox with label - else if (editType == "multiple") - { - // read the parameter name as it is used at the command line or in its config file - TQString parameterCallName = - _indenterSettings->value(indenterParameter + "/CallName").toString(); - - // create checkbox which enables or disables the parameter - TQCheckBox *chkBox = new TQCheckBox(_indenterParameterCategoryPages.at(category).widget); - chkBox->setChecked(_indenterSettings->value(indenterParameter + "/Enabled").toBool()); - chkBox->setToolTip( - "Enables/disables the parameter. If disabled the indenters default value will be used."); - chkBox->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed); - int left, top, right, bottom; - chkBox->getContentsMargins(&left, &top, &right, &bottom); - chkBox->setContentsMargins(left, top, 0, bottom); - - // create the combo box - TQComboBox *comboBox = new TQComboBox(_indenterParameterCategoryPages.at( - category).widget); - TQStringList choicesStrings = - _indenterSettings->value(indenterParameter + "/Choices").toString().split("|"); - TQStringList choicesStringsReadable = _indenterSettings->value( - indenterParameter + "/ChoicesReadable").toString().split("|", TQString::SkipEmptyParts); - if (choicesStringsReadable.isEmpty()) - { - comboBox->addItems(choicesStrings); - } - else - { - comboBox->addItems(choicesStringsReadable); - } - paramToolTip = _indenterSettings->value(indenterParameter + "/Description").toString(); - comboBox->setToolTip(paramToolTip); - if (_mainWindow != NULL) - { - comboBox->installEventFilter(_mainWindow); - } - - // put all into a layout and add it to the toolbox page - TQHBoxLayout *hboxLayout = new TQHBoxLayout(); - hboxLayout->addWidget(chkBox); - hboxLayout->addWidget(comboBox); - _indenterParameterCategoryPages.at(category).vboxLayout->addLayout(hboxLayout); - - // remember parameter name and reference to its lineedit - ParamMultiple paramMultiple; - paramMultiple.paramName = indenterParameter; - paramMultiple.paramCallName = parameterCallName; - paramMultiple.comboBox = comboBox; - paramMultiple.choicesStrings = choicesStrings; - paramMultiple.choicesStringsReadable = choicesStringsReadable; - paramMultiple.valueEnabledChkBox = chkBox; - paramMultiple.comboBox->setCurrentIndex(_indenterSettings->value(paramMultiple.paramName + - "/ValueDefault").toInt()); - _paramMultiples.append(paramMultiple); - - TQObject::connect(comboBox, SIGNAL(activated(int)), this, - SLOT(handleChangedIndenterSettings())); - TQObject::connect(chkBox, SIGNAL(clicked()), this, SLOT(handleChangedIndenterSettings())); -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - connect(comboBox, SIGNAL(activated(int)), this, SLOT(updateDrawing())); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS - } - } - } - - // put a spacer at each page end - foreach(IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) - { - categoryPage.vboxLayout->addStretch(); - } -} - -/* - \brief Searches and returns all indenters a configuration file is found for. - - Opens all uigui ini files found in the list \a _indenterIniFileList, opens each ini file - and reads the there defined real name of the indenter. These names are being returned as TQStringList. - */ -TQStringList IndentHandler::getAvailableIndenters() -{ - TQStringList indenterNamesList; - - // Loop for every existing uigui ini file - foreach(TQString indenterIniFile, _indenterIniFileList) - { - // Open the ini file and search for the indenter name - TQFile file(_indenterDirctoryStr + "/" + indenterIniFile); - if (file.open(TQIODevice::ReadOnly | TQIODevice::Text)) - { - int index = -1; - TQByteArray line; - // Search for the string "indenterName=" and get the following string until line end. - while (index == -1 && !file.atEnd()) - { - line = file.readLine(); - index = line.indexOf("indenterName=", 0); - } - - if (index == 0) - { - line = line.remove(0, 13); - indenterNamesList << line.trimmed(); - } - } - } - return indenterNamesList; -} - -/* - \brief Deletes all elements in the toolbox and initializes the indenter selected by \a indenterID. - */ -void IndentHandler::setIndenter(int indenterID) -{ - TQApplication::setOverrideCursor(TQt::WaitCursor); - -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - disconnect(_indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, - SLOT(updateDrawing())); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS - - // Generate the parameter string that will be saved to the indenters config file. - TQString parameterString = getParameterString(); - if (!_indenterFileName.isEmpty()) - { - saveConfigFile(_settingsDirctoryStr + "/" + _indenterFileName + ".cfg", parameterString); - } - - // Take care if the selected indenterID is smaller or greater than the number of existing - // indenters - if (indenterID < 0) - { - indenterID = 0; - } - if (indenterID >= _indenterIniFileList.count()) - { - indenterID = _indenterIniFileList.count() - 1; - } - - // remove all pages from the toolbox - for (int i = 0; i < _indenterParameterCategoriesToolBox->count(); i++) - { - _indenterParameterCategoriesToolBox->removeItem(i); - } - - // delete all toolbox pages and by this its children - foreach(IndenterParameterCategoryPage categoryPage, _indenterParameterCategoryPages) - { - delete categoryPage.widget; - } - - // empty all lists, which stored infos for the toolbox pages and its widgets - _indenterParameterCategoryPages.clear(); - _paramStrings.clear(); - _paramNumerics.clear(); - _paramBooleans.clear(); - _paramMultiples.clear(); - delete _indenterSettings; - -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - TQWidget dummyWidget; - _indenterParameterCategoriesToolBox->addItem(&dummyWidget, "dummyText"); -#endif - - readIndentIniFile(_indenterDirctoryStr + "/" + _indenterIniFileList.at(indenterID)); - - // Find out how the indenter can be executed. - createIndenterCallString(); - - // Load the users last settings made for this indenter. - loadConfigFile(_settingsDirctoryStr + "/" + _indenterFileName + ".cfg"); - - handleChangedIndenterSettings(); - - TQApplication::restoreOverrideCursor(); - -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - connect(_indenterParameterCategoriesToolBox, SIGNAL(currentChanged(int)), this, - SLOT(updateDrawing())); - _indenterParameterCategoriesToolBox->removeItem(_indenterParameterCategoriesToolBox->indexOf(& - dummyWidget)); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS -} - -/* - \brief Returns a string containing by the indenter supported file types/extensions divided by a space. - */ -TQString IndentHandler::getPossibleIndenterFileExtensions() -{ - return _fileTypes; -} - -/* - \brief Returns the path and filename of the current indenter config file. - */ -TQString IndentHandler::getIndenterCfgFile() -{ - TQFileInfo fileInfo(_indenterDirctoryStr + "/" + _globalConfigFilename); - return fileInfo.absoluteFilePath(); -} - -/* - \brief Tries to create a call path string for the indenter executable. If successful returns true. - */ -bool IndentHandler::createIndenterCallString() -{ - TQProcess indentProcess; - - if (_indenterFileName.isEmpty()) - { - return false; - } - - // First try to call the indenter inside of the data dir, using some suffix - // ------------------------------------------------------------------------ - - // Set the directory for the indenter execution - indentProcess.setWorkingDirectory(TQFileInfo(_indenterDirctoryStr).absoluteFilePath()); - - foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh") - { - _indenterExecutableSuffix = suffix; - _indenterExecutableCallString = TQFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + - _indenterFileName; - _indenterExecutableCallString += suffix; - - // Only try to call the indenter, if the file exists. - if (TQFile::exists(_indenterExecutableCallString)) - { - // Only try to call the indenter directly if it is no php file - if (TQFileInfo(_indenterExecutableCallString).suffix().toLower() != "php") - { - indentProcess.start( - "\"" + _indenterExecutableCallString + +"\" " + _indenterShowHelpParameter); - if (indentProcess.waitForFinished(2000)) - { - _indenterExecutableCallString = "\"" + _indenterExecutableCallString + "\""; - return true; - } - else if (indentProcess.error() == TQProcess::Timedout) - { - _indenterExecutableCallString = "\"" + _indenterExecutableCallString + "\""; - return true; - } - } - - // Test for needed interpreters - // ---------------------------- - // If the file could not be executed, try to find a shebang at its start or test if its a php - // file. - TQString interpreterName = ""; - TQFile indenterExecutable(_indenterExecutableCallString); - - // If indenter executable file has .php as suffix, use php as default interpreter - if (TQFileInfo(_indenterExecutableCallString).suffix().toLower() == "php") - { - interpreterName = "php -f"; - } - // Else try to open the file and read the shebang. - else if (indenterExecutable.open(TQFile::ReadOnly)) - { - // Read the first line of the file. - TQTextStream indenterExecutableContent(&indenterExecutable); - TQString firstLineOfIndenterExe = indenterExecutableContent.readLine(75); - indenterExecutable.close(); - - // If the initial shebang is found, read the named intepreter. e.g. perl - if (firstLineOfIndenterExe.startsWith("#!")) - { - // Get the rightmost word. by splitting the string into only full words. - interpreterName = firstLineOfIndenterExe.split("/").last(); - } - } - - // Try to call the interpreter, if it exists. - if (!interpreterName.isEmpty()) - { - _indenterExecutableCallString = interpreterName + " \"" + _indenterExecutableCallString + - "\""; - indentProcess.start(interpreterName + " -h"); - if (indentProcess.waitForFinished(2000)) - { - return true; - } - else if (indentProcess.error() == TQProcess::Timedout) - { - return true; - } - // now we know an interpreter is needed but it could not be called, so inform the user. - else - { - _errorMessageDialog->showMessage(tr("Interpreter needed"), tr( - "To use the selected indenter the program \"%1\" needs to be available in the global environment. You should add an entry to your path settings.").arg( - interpreterName)); - return true; - } - } - } - } - - // If unsuccessful try if the indenter executable is a JavaScript file - // ------------------------------------------------------------------- - _indenterExecutableSuffix = ".js"; - _indenterExecutableCallString = TQFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + - _indenterFileName; - _indenterExecutableCallString += _indenterExecutableSuffix; - if (TQFile::exists(_indenterExecutableCallString)) - { - return true; - } - - // If unsuccessful try to call the indenter global, using some suffix - // ------------------------------------------------------------------ - foreach(TQString suffix, TQStringList() << "" << ".exe" << ".bat" << ".com" << ".sh") - { - _indenterExecutableSuffix = suffix; - _indenterExecutableCallString = _indenterFileName + suffix; - indentProcess.start(_indenterExecutableCallString + " " + _indenterShowHelpParameter); - if (indentProcess.waitForFinished(2000)) - { - return true; - } - else if (indentProcess.error() == TQProcess::Timedout) - { - return true; - } - } - - // If even globally calling the indenter fails, try calling .com and .exe via wine - // ------------------------------------------------------------------------------- - _indenterExecutableCallString = "\"" + TQFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/" + - _indenterFileName; - - foreach(TQString suffix, TQStringList() << ".exe" << ".com") - { - _indenterExecutableSuffix = suffix; - if (TQFile::exists(_indenterDirctoryStr + "/" + _indenterFileName + suffix)) - { - TQProcess wineTestProcess; - wineTestProcess.start("wine --version"); - // if the process of wine was not callable assume that wine is not installed - if (!wineTestProcess.waitForFinished(2000)) - { - _errorMessageDialog->showMessage(tr("wine not installed"), tr( - "There exists only a win32 executable of the indenter and wine does not seem to be installed. Please install wine to be able to run the indenter.")); - _indenterExecutableCallString = ""; - return false; - } - else - { - _indenterExecutableCallString = "\"" + - TQFileInfo(_indenterDirctoryStr).absoluteFilePath() + "/"; - _indenterExecutableCallString += _indenterFileName + suffix + "\""; - _indenterExecutableCallString = "wine " + _indenterExecutableCallString; - - return true; - } - } - } - - _indenterExecutableCallString = ""; - _indenterExecutableSuffix = ""; - return false; -} - -/* - \brief Returns a string that points to where the indenters manual can be found. - */ -TQString IndentHandler::getManual() -{ - if (_indenterSettings != NULL) - { - return _indenterSettings->value("header/manual").toString(); - } - else - { - return ""; - } -} - -/* - \brief This slot gets the reference to the indenters manual and opens it. - */ -void IndentHandler::showIndenterManual() -{ - TQString manualReference = getManual(); - TQDesktopServices::openUrl(manualReference); -} - -/* - \brief Can be called to update all widgets text to the currently selected language. - */ -void IndentHandler::retranslateUi() -{ - _indenterSelectionCombobox->setToolTip(tr( - "

Shows the currently chosen indenters name and lets you choose other available indenters

")); - _indenterParameterHelpButton->setToolTip(tr( - "Brings you to the online manual of the currently selected indenter, where you can get further help on the possible parameters.")); - - _actionLoadIndenterConfigFile->setText(TQApplication::translate("IndentHandler", - "Load Indenter Config File", 0, TQApplication::UnicodeUTF8)); - _actionLoadIndenterConfigFile->setStatusTip(TQApplication::translate("IndentHandler", - "Opens a file dialog to load the original config file of the indenter.", 0, - TQApplication::UnicodeUTF8)); - _actionLoadIndenterConfigFile->setShortcut(TQApplication::translate("IndentHandler", "Alt+O", 0, - TQApplication::UnicodeUTF8)); - - _actionSaveIndenterConfigFile->setText(TQApplication::translate("IndentHandler", - "Save Indenter Config File", 0, TQApplication::UnicodeUTF8)); - _actionSaveIndenterConfigFile->setStatusTip(TQApplication::translate("IndentHandler", - "Opens a dialog to save the current indenter configuration to a file.", 0, - TQApplication::UnicodeUTF8)); - _actionSaveIndenterConfigFile->setShortcut(TQApplication::translate("IndentHandler", "Alt+S", 0, - TQApplication::UnicodeUTF8)); - - _actionCreateShellScript->setText(TQApplication::translate("IndentHandler", - "Create Indenter Call Shell Script", 0, TQApplication::UnicodeUTF8)); - _actionCreateShellScript->setToolTip(TQApplication::translate("IndentHandler", - "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", - 0, TQApplication::UnicodeUTF8)); - _actionCreateShellScript->setStatusTip(TQApplication::translate("IndentHandler", - "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings.", - 0, TQApplication::UnicodeUTF8)); - - _actionResetIndenterParameters->setText(TQApplication::translate("IndentHandler", - "Reset indenter parameters", 0, TQApplication::UnicodeUTF8)); - _actionResetIndenterParameters->setToolTip(TQApplication::translate("IndentHandler", - "Resets all indenter parameters to the default values.", 0, TQApplication::UnicodeUTF8)); - _actionResetIndenterParameters->setStatusTip(TQApplication::translate("IndentHandler", - "Resets all indenter parameters to the default values.", 0, TQApplication::UnicodeUTF8)); -} - -/* - \brief Returns the name of the currently selected indenter. - */ -TQString IndentHandler::getCurrentIndenterName() -{ - TQString currentIndenterName = _indenterSelectionCombobox->currentText(); - - // Remove the supported programming languages from indenters name, which are set in braces. - if (currentIndenterName.indexOf("(") > 0) - { - // Using index-1 to also leave out the blank before the brace. - currentIndenterName = currentIndenterName.left(currentIndenterName.indexOf("(") - 1); - } - - return currentIndenterName; -} - -/* - \brief Shows a file open dialog to open an existing config file for the currently selected indenter. - - If the file was successfully opened the indent handler is called to load the settings and update itself. -*/ -void IndentHandler::openConfigFileDialog() -{ - TQString configFilePath; - - configFilePath = TQFileDialog::getOpenFileName(NULL, tr( - "Choose indenter config file"), getIndenterCfgFile(), "All files (*.*)"); - - if (configFilePath != "") - { - // If the config file was loaded successfully, inform any who is interested about it. - if (loadConfigFile(configFilePath)) - { - handleChangedIndenterSettings(); - } - } -} - -/* - \brief Calls the indenter config file save as dialog to save the config file under a chosen name. - - If the file already exists and it should be overwritten, a warning is shown before. -*/ -void IndentHandler::saveasIndentCfgFileDialog() -{ - TQString fileExtensions = tr("All files") + " (*.*)"; - - TQString fileName = TQFileDialog::getSaveFileName(this, tr( - "Save indent config file"), getIndenterCfgFile(), fileExtensions); - - if (fileName != "") - { - TQFile::remove(fileName); - TQFile outCfgFile(fileName); - outCfgFile.open(TQFile::ReadWrite | TQFile::Text); - outCfgFile.write(getParameterString().toAscii()); - outCfgFile.close(); - } -} - -/* - \brief Invokes the indenter to create a shell script. - - Lets the indenter create a shell script for calling the indenter out of any - other application and open a save dialog for saving the shell script. -*/ -void IndentHandler::createIndenterCallShellScript() -{ - TQString shellScriptExtension; -#if defined (Q_OS_WIN32) - shellScriptExtension = "bat"; -#else - shellScriptExtension = "sh"; -#endif - - TQString fileExtensions = tr("Shell Script") + " (*." + shellScriptExtension + ");;" + tr( - "All files") + " (*.*)"; - - TQString currentIndenterName = getCurrentIndenterName(); - currentIndenterName = currentIndenterName.replace(" ", "_"); - - TQString shellScriptFileName = TQFileDialog::getSaveFileName(this, tr( - "Save shell script"), "call_" + currentIndenterName + "." + shellScriptExtension, - fileExtensions); - - // Saving has been canceled if the filename is empty - if (shellScriptFileName.isEmpty()) - { - return; - } - - // Delete any old file, write the new contents and set executable permissions. - TQFile::remove(shellScriptFileName); - TQFile outSrcFile(shellScriptFileName); - if (outSrcFile.open(TQFile::ReadWrite | TQFile::Text)) - { - TQString shellScriptConfigFilename = TQFileInfo(shellScriptFileName).baseName() + "." + - TQFileInfo(_globalConfigFilename).suffix(); - - // Get the content of the shell/batch script. - TQString indenterCallShellScript = generateShellScript(shellScriptConfigFilename); - - // Replace placeholder for script name in script template. - indenterCallShellScript = indenterCallShellScript.replace("__INDENTERCALLSTRINGSCRIPTNAME__", TQFileInfo( - shellScriptFileName).fileName()); - - outSrcFile.write(indenterCallShellScript.toAscii()); -#if !defined (Q_OS_WIN32) - // For none Windows systems set the files executable flag - outSrcFile.setPermissions( - outSrcFile.permissions() | TQFile::ExeOwner | TQFile::ExeUser | TQFile::ExeGroup); -#endif - outSrcFile.close(); - - // Save the indenter config file to the same directory, where the shell srcipt was saved to, - // because the script will reference it there via "./". - if (!_globalConfigFilename.isEmpty()) - { - saveConfigFile(TQFileInfo( - shellScriptFileName).path() + "/" + shellScriptConfigFilename, - getParameterString()); - } - } -} - -/* - \brief Resets all parameters to the indenters default values as they are specified in the uigui ini file - but asks the user whether to do it really. - */ -void IndentHandler::resetIndenterParameter() -{ - int messageBoxAnswer = TQMessageBox::question(this, tr("Really reset parameters?"), tr( - "Do you really want to reset the indenter parameters to the default values?"), - TQMessageBox::Yes | TQMessageBox::Abort); - if (messageBoxAnswer == TQMessageBox::Yes) - { - resetToDefaultValues(); - } -} - -/* - \brief Catch some events and let some other be handled by the super class. - - Is needed for use as Notepad++ plugin. - */ -bool IndentHandler::event(TQEvent *event) -{ - if (event->type() == TQEvent::WindowActivate) - { - event->accept(); - return true; - } - else if (event->type() == TQEvent::WindowDeactivate) - { - event->accept(); - return true; - } - else - { - event->ignore(); - return TQWidget::event(event); - } -} - -/* - \brief Sets the function pointer \a _parameterChangedCallback to the given callback - function \a paramChangedCallback. - - Is needed for use as Notepad++ plugin. - */ -void IndentHandler::setParameterChangedCallback(void (*paramChangedCallback)(void)) -{ - _parameterChangedCallback = paramChangedCallback; -} - -/* - \brief Emits the \a indenterSettingsChanged signal and if set executes the \a _parameterChangedCallback function. - - Is needed for use as Notepad++ plugin. - */ -void IndentHandler::handleChangedIndenterSettings() -{ - emit(indenterSettingsChanged()); - - if (_parameterChangedCallback != NULL) - { - _parameterChangedCallback(); - } -} - -/* - \brief Sets a callback function that shall be called, when the this indenter parameter window gets closed. - - Is needed for use as Notepad++ plugin. - */ -void IndentHandler::setWindowClosedCallback(void (*winClosedCallback)(void)) -{ - _windowClosedCallback = winClosedCallback; -} - -/* - \brief Is called on this indenter parameter window close and if set calls the function \a _windowClosedCallback. - - Is needed for use as Notepad++ plugin. - */ -void IndentHandler::closeEvent(TQCloseEvent *event) -{ - if (_windowClosedCallback != NULL) - { - _windowClosedCallback(); - } - event->accept(); -} - -/* - \brief Returns the id (list index) of the currently selected indenter. - */ -int IndentHandler::getIndenterId() -{ - return _indenterSelectionCombobox->currentIndex(); -} - -void IndentHandler::updateDrawing() -{ -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - if (isVisible()) - { - TQRect savedGeometry = geometry(); - setGeometry(savedGeometry.adjusted(0, 0, 0, 1)); - repaint(); - setGeometry(savedGeometry); - } -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS -} - -void IndentHandler::wheelEvent(TQWheelEvent *event) -{ - UNUSED_PARAMETER_WARNING_AVOID(event); -#ifdef UNIVERSALINDENTGUI_NPP_EXPORTS - TQWidget::wheelEvent(event); - updateDrawing(); -#endif // UNIVERSALINDENTGUI_NPP_EXPORTS -} - -/* - \brief Converts characters < > and & in the \a text to HTML codes < > and &. - */ - -//TODO: This function should go into a string helper/tool class/file. -TQString IndentHandler::encodeToHTML(const TQString &text) -{ - TQString htmlText = text; - htmlText.replace("&", "&"); - htmlText.replace("<", "<"); - htmlText.replace(">", ">"); - htmlText.replace('"', """); - htmlText.replace("'", "'"); - htmlText.replace("^", "ˆ"); - htmlText.replace("~", "˜"); - htmlText.replace("€", "€"); - htmlText.replace("©", "©"); - return htmlText; -} diff --git a/src/__TODO/IndentHandler.h b/src/__TODO/IndentHandler.h deleted file mode 100644 index 579807d..0000000 --- a/src/__TODO/IndentHandler.h +++ /dev/null @@ -1,195 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2012 by Thomas Schweitzer * - * thomas-schweitzer(at)arcor.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2.0 as * - * published by the Free Software Foundation. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program in the file LICENSE.GPL; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef INDENTHANDLER_H -#define INDENTHANDLER_H - -#include - -class UiGuiErrorMessage; -class UiGuiIniFileParser; - -class TQMenu; -class TQVBoxLayout; -class TQLabel; -class TQSpinBox; -class TQComboBox; -class TQCheckBox; -class TQLineEdit; -class TQToolButton; -class TQToolBox; - - -class IndentHandler : public TQWidget -{ - Q_OBJECT - - public: - IndentHandler(int indenterID, TQWidget *mainWindow = NULL, TQWidget *parent = NULL); - ~IndentHandler(); - - TQString generateShellScript(const TQString &configFilename); - TQString callIndenter(TQString sourceCode, TQString inputFileExtension); - bool loadConfigFile(TQString filePathName); - void resetToDefaultValues(); - TQStringList getAvailableIndenters(); - TQString getPossibleIndenterFileExtensions(); - TQString getParameterString(); - TQString getIndenterCfgFile(); - TQString getManual(); - void retranslateUi(); - TQString getCurrentIndenterName(); - TQMenu* getIndenterMenu(); - TQList getIndenterMenuActions(); - void contextMenuEvent(TQContextMenuEvent *event); - void setParameterChangedCallback(void (*paramChangedCallback)(void)); - void setWindowClosedCallback(void (*winClosedCallback)(void)); - int getIndenterId(); - - signals: - void indenterSettingsChanged(); - void selectedIndenterIndexChanged(int index); - - protected: - bool event(TQEvent *event); - void closeEvent(TQCloseEvent *event); - void wheelEvent(TQWheelEvent *event); - - private slots: - void setIndenter(int indenterID); - void showIndenterManual(); - void openConfigFileDialog(); - void saveasIndentCfgFileDialog(); - void createIndenterCallShellScript(); - void resetIndenterParameter(); - void handleChangedIndenterSettings(); - void updateDrawing(); - - private: - TQString callExecutableIndenter(TQString sourceCode, TQString inputFileExtension); - TQString callJavaScriptIndenter(TQString sourceCode); - void saveConfigFile(TQString filePathName, TQString parameterString); - void readIndentIniFile(TQString iniFilePath); - bool createIndenterCallString(); - void initIndenterMenu(); - - // Holds a reference to all created pages of the parameter categories toolbox and the pages - // boxlayout - struct IndenterParameterCategoryPage - { - TQWidget *widget; - TQVBoxLayout *vboxLayout; - }; - - TQVector _indenterParameterCategoryPages; - - // Holds a reference to all checkboxes needed for boolean parameter setting and the parameters - // name - struct ParamBoolean - { - TQString paramName; - TQString trueString; - TQString falseString; - TQCheckBox *checkBox; - }; - - TQVector _paramBooleans; - - // Holds a reference to all line edits needed for parameter setting and the parameters name - struct ParamString - { - TQString paramName; - TQString paramCallName; - TQCheckBox *valueEnabledChkBox; - TQLineEdit *lineEdit; - TQLabel *label; - }; - - TQVector _paramStrings; - - // Hold a reference to all spin boxes needed for parameter setting and the parameters name - struct ParamNumeric - { - TQString paramName; - TQString paramCallName; - TQCheckBox *valueEnabledChkBox; - TQSpinBox *spinBox; - TQLabel *label; - }; - - TQVector _paramNumerics; - - // Hold a reference to all combo boxes needed for parameter setting and the parameters name - struct ParamMultiple - { - TQString paramName; - TQString paramCallName; - TQCheckBox *valueEnabledChkBox; - TQComboBox *comboBox; - TQStringList choicesStrings; - TQStringList choicesStringsReadable; - }; - - TQVector _paramMultiples; - - TQComboBox *_indenterSelectionCombobox; - TQToolButton *_indenterParameterHelpButton; - // Vertical layout box, into which the toolbox will be added - TQVBoxLayout *_toolBoxContainerLayout; - TQToolBox *_indenterParameterCategoriesToolBox; - UiGuiIniFileParser *_indenterSettings; - TQStringList _indenterParameters; - // The indenters name in a descriptive form - TQString _indenterName; - // The indenters file name (w/o extension), that is being called - TQString _indenterFileName; - TQString _indenterDirctoryStr; - TQString _tempDirctoryStr; - TQString _settingsDirctoryStr; - TQStringList _indenterIniFileList; - TQString _parameterOrder; - TQString _globalConfigFilename; - TQString _cfgFileParameterEnding; - TQString _inputFileParameter; - TQString _inputFileName; - TQString _outputFileParameter; - TQString _outputFileName; - TQString _fileTypes; - TQString _useCfgFileParameter; - TQString _indenterShowHelpParameter; - TQWidget *_mainWindow; - UiGuiErrorMessage *_errorMessageDialog; - TQString _indenterExecutableCallString; - TQString _indenterExecutableSuffix; - - TQMenu *_menuIndenter; - TQAction *_actionLoadIndenterConfigFile; - TQAction *_actionSaveIndenterConfigFile; - TQAction *_actionCreateShellScript; - TQAction *_actionResetIndenterParameters; - // Needed for the NPP plugin. - void (*_parameterChangedCallback)(void); - // Needed for the NPP plugin. - void (*_windowClosedCallback)(void); - - //TODO: This function should go into a string helper/tool class/file. - TQString encodeToHTML(const TQString &text); -}; - -#endif // INDENTHANDLER_H diff --git a/src/__TODO/MainWindow.ui b/src/__TODO/MainWindow.ui deleted file mode 100755 index 73200d1..0000000 --- a/src/__TODO/MainWindow.ui +++ /dev/null @@ -1,51 +0,0 @@ - - Thomas_-_S - MainWindowUi - - - MainWindowUi - - - - - - - 0 - 0 - - - - TQDockWidget::DockWidgetFloatable|TQDockWidget::DockWidgetMovable - - - TQt::LeftDockWidgetArea|TQt::RightDockWidgetArea - - - Indenter Settings - - - 1 - - - - - 6 - - - 0 - - - - - 0 - - - 0 - - - - - - - - diff --git a/src/__TODO/TemplateBatchScript.cpp b/src/__TODO/TemplateBatchScript.cpp index cdbf42a..56215e1 100644 --- a/src/__TODO/TemplateBatchScript.cpp +++ b/src/__TODO/TemplateBatchScript.cpp @@ -19,9 +19,6 @@ #include "TemplateBatchScript.h" -// Need to include TQObject here so that platform specific defines like Q_OS_WIN32 are set. -#include - /* \brief The only and static function of this class returns a batch or shell script as string that can be used to call an indenter with the current settings from @@ -36,51 +33,6 @@ const char* TemplateBatchScript::getTemplateBatchScript() { static const char *templateBatchScript = -#if defined (Q_OS_WIN32) - "@echo off\n" - "\n" - "IF (%1)==() GOTO error\n" - "dir /b /ad %1 >nul 2>nul && GOTO indentDir\n" - "IF NOT EXIST %1 GOTO error\n" - "goto indentFile\n" - "\n" - ":indentDir\n" - "set searchdir=%1\n" - "\n" - "IF (%2)==() GOTO assignDefaultSuffix\n" - "set filesuffix=%2\n" - "\n" - "GOTO run\n" - "\n" - ":assignDefaultSuffix\n" - "::echo !!!!DEFAULT SUFFIX!!!\n" - "set filesuffix=*\n" - "\n" - ":run\n" - "FOR /F \"tokens=*\" %%G IN ('DIR /B /S %searchdir%\\*.%filesuffix%') DO (\n" - "echo Indenting file \"%%G\"\n" - "__INDENTERCALLSTRING1__\n" - ")\n" - "GOTO ende\n" - "\n" - ":indentFile\n" - "echo Indenting one file %1\n" - "__INDENTERCALLSTRING2__\n" - "\n" - "GOTO ende\n" - "\n" - ":error\n" - "echo .\n" - "echo ERROR: As parameter given directory or file does not exist!\n" - "echo Syntax is: __INDENTERCALLSTRINGSCRIPTNAME__ dirname filesuffix\n" - "echo Syntax is: __INDENTERCALLSTRINGSCRIPTNAME__ filename\n" - "echo Example: __INDENTERCALLSTRINGSCRIPTNAME__ temp cpp\n" - "echo .\n" - "\n" - ":ende\n"; - -#else - "#!/bin/sh \n" "\n" "if [ ! -n \"$1\" ]; then\n" @@ -118,54 +70,5 @@ const char* TemplateBatchScript::getTemplateBatchScript() "exit 1\n" "fi\n" "fi\n"; -#endif // #if defined(Q_OS_WIN32) return templateBatchScript; } - -/* Here comes the original batch script without the c++ markup -@echo off - -IF (%1)==() GOTO error -dir /b /ad %1 >nul 2>nul && GOTO indentDir -IF NOT EXIST %1 GOTO error -goto indentFile - -:indentDir -set searchdir=%1 - -IF (%2)==() GOTO assignDefaultSuffix -set filesuffix=%2 - -GOTO run - -:assignDefaultSuffix -::echo !!!!DEFAULT SUFFIX!!! -set filesuffix=* - -:run -FOR /F "tokens=*" %%G IN ('DIR /B /S %searchdir%\*.%filesuffix%') DO ( - echo Indenting file "%%G" - ::call call_CSSTidy.bat "%%G" - "C:/Dokumente und Einstellungen/ts/Eigene Dateien/Visual Studio 2005/Projects/UiGuixy/indenters/csstidy.exe" "%%G" --timestamp=true --allow_html_in_templates=false --compress_colors=true --compress_font=true --lowercase_s=false --preserve_css=false --remove_last_;=false --remove_bslash=true --sort_properties=false --sort_selectors=false indentoutput.css - move /Y indentoutput.css "%%G" -) -GOTO ende - -:indentFile -echo Indenting one file %1 -"C:/Dokumente und Einstellungen/ts/Eigene Dateien/Visual Studio 2005/Projects/UiGuixy/indenters/csstidy.exe" %1 --timestamp=true --allow_html_in_templates=false --compress_colors=true --compress_font=true --lowercase_s=false --preserve_css=false --remove_last_;=false --remove_bslash=true --sort_properties=false --sort_selectors=false indentoutput.css -move /Y indentoutput.css %1 - -GOTO ende - -:error -echo . -echo ERROR: As parameter given directory or file does not exist! -echo Syntax is: recurse.bat dirname filesuffix -echo Syntax is: recurse.bat filename -echo Example: recurse.bat temp cpp -echo . - -:ende - -*/