changeset 480:e9038a8e8e1f

Redesigned the user interface and code a bit. The indenter selection combo box along with the manual button are now placed in docking widget where all indenter parameters are placed. This is done in preparation to pull out the complete indent handler, so it can be used as plugin for Notepad++ or Eclipse etc. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@720 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Tue, 10 Jun 2008 09:53:07 +0000
parents 4f7041de0d0e
children d2b86d544678
files src/indenthandler.cpp src/indenthandler.h src/mainwindow.cpp src/mainwindow.h src/mainwindow.ui src/toolBarWidget.ui
diffstat 6 files changed, 104 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/indenthandler.cpp	Tue Jun 10 09:53:07 2008 +0000
@@ -45,6 +45,8 @@
 {
     Q_ASSERT_X( indenterID >= 0, "IndentHandler", "the selected indenterID is < 0" );
 
+    setObjectName(QString::fromUtf8("indentHandler"));
+
     this->mainWindow = mainWindow;
 
     indenterSettings = NULL;
@@ -57,6 +59,26 @@
     vboxLayout = new QVBoxLayout(this);
     vboxLayout->setMargin(2);
 
+    // Create horizontal layout for indenter selector and help button.
+    QHBoxLayout *hboxLayout = new QHBoxLayout(this);
+    //hboxLayout->setMargin(2);
+    vboxLayout->addLayout( hboxLayout );
+
+    // Create the indenter selection combo box.
+    indenterSelectionComboBox = new QComboBox(this);
+    indenterSelectionComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
+    indenterSelectionComboBox->setMinimumContentsLength(20);
+    connect( indenterSelectionComboBox, SIGNAL(activated(int)), this, SLOT(setIndenter(int)) );
+    hboxLayout->addWidget( indenterSelectionComboBox );
+
+    // Create the indenter parameter help button.
+    indenterParameterHelpButton = new QToolButton(this);
+    indenterParameterHelpButton->setObjectName(QString::fromUtf8("indenterParameterHelpButton"));
+    indenterParameterHelpButton->setIcon(QIcon(QString::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
     toolBox = new QToolBox(this);
     toolBox->setObjectName(QString::fromUtf8("toolBox"));
@@ -93,10 +115,18 @@
 
         // 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 );
+        }
     }
     else {
         errorMessageDialog->showMessage(tr("No indenter ini files"), tr("There exists no indenter ini files in the directory \"") + QDir(indenterDirctoryStr).absolutePath() + "\".");
-    }    
+    }
+
+    retranslateUi();
 }
 
 
@@ -964,6 +994,14 @@
  */
 void IndentHandler::setIndenter(int indenterID) {
     // TODO: This function is never called because out of the mainwindow object a new indenthandler object is created if another indenter is selected.
+    
+    QApplication::setOverrideCursor(Qt::WaitCursor);
+
+    // Generate the parameter string that will be saved to the indenters config file.
+    QString parameterString = getParameterString();
+    if ( !indenterFileName.isEmpty() ) {
+        writeConfigFile( settingsDirctoryStr + "/" + indenterFileName + ".cfg", parameterString );
+    }
 
     // Take care if the selected indenterID is smaller or greater than the number of existing indenters
     if ( indenterID < 0 ) {
@@ -988,9 +1026,20 @@
     paramStrings.clear();
     paramNumerics.clear();
     paramBooleans.clear();
+    paramMultiples.clear();
     delete indenterSettings;
 
     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" );
+
+    emit( indenterSettingsChanged() );
+
+    QApplication::restoreOverrideCursor();
 }
 
 
@@ -1156,3 +1205,37 @@
         return "";
     }
 }
+
+
+/*!
+    \brief This slot gets the reference to the indenters manual and opens it.
+ */
+void IndentHandler::showIndenterManual() {
+    QString manualReference = getManual();
+    QDesktopServices::openUrl( manualReference );
+}
+
+
+/*!
+    \brief Can be called to update all widgets text to the currently selected language.
+ */
+void IndentHandler::retranslateUi() {
+    indenterSelectionComboBox->setToolTip( tr("<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Shows the currently chosen indenters name and lets you choose other available indenters</p></body></html>") );
+    indenterParameterHelpButton->setToolTip( tr("Brings you to the online manual of the currently selected indenter, where you can get further help on the possible parameters.") );
+}
+
+
+/*!
+    \brief Returns the name of the currently selected indenter.
+ */
+QString IndentHandler::getCurrentIndenterName() {
+    QString 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;
+}
\ No newline at end of file
--- a/src/indenthandler.h	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/indenthandler.h	Tue Jun 10 09:53:07 2008 +0000
@@ -26,6 +26,7 @@
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
+#include <QToolButton>
 #include <QFile>
 #include <QProcess>
 #include <QSettings>
@@ -39,7 +40,8 @@
 #include <QMainWindow>
 #include <QTextStream>
 #include <QTextCodec>
-#include <QtScript> 
+#include <QtScript>
+#include <QDesktopServices>
 
 #include "uiguierrormessage.h"
 #include "templateBatchScript.h"
@@ -62,12 +64,15 @@
     QString getParameterString();
     QString getIndenterCfgFile();
     QString getManual();
+    void retranslateUi();
+    QString getCurrentIndenterName();
 
 signals:
     void indenterSettingsChanged();
     
 private slots:
     void setIndenter(int indenterID);
+    void showIndenterManual();
 
 private:
     QString callExecutableIndenter(QString sourceCode, QString inputFileExtension);
@@ -123,6 +128,8 @@
     };
     QVector<ParamMultiple> paramMultiples;
 
+    QComboBox *indenterSelectionComboBox;
+    QToolButton *indenterParameterHelpButton;
     QVBoxLayout *vboxLayout;
     QToolBox *toolBox;
     UiguiIniFileParser *indenterSettings;
--- a/src/mainwindow.cpp	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/mainwindow.cpp	Tue Jun 10 09:53:07 2008 +0000
@@ -263,7 +263,6 @@
     toolBarWidget->uiGuiSyntaxHighlightningEnabled->hide();
     connect( toolBarWidget->pbOpen_Source_File, SIGNAL(clicked()), this, SLOT(openSourceFileDialog()) );
     connect( toolBarWidget->pbExit, SIGNAL(clicked()), this, SLOT(close()));
-    connect( toolBarWidget->cmbBoxIndenters, SIGNAL(activated(int)), this, SLOT(selectIndenter(int)) );
     connect( toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), this, SLOT(previewTurnedOnOff(bool)) );
     connect( toolBarWidget->cbLivePreview, SIGNAL(toggled(bool)), actionLive_Indent_Preview, SLOT(setChecked(bool)) );
     connect( actionLive_Indent_Preview, SIGNAL(toggled(bool)), toolBarWidget->cbLivePreview, SLOT(setChecked(bool)) );
@@ -390,22 +389,6 @@
     indentHandler = new IndentHandler(indenterDirctoryStr, settingsDirctoryStr, tempDirctoryStr, currentIndenterID, this, centralwidget);
     vboxLayout->addWidget(indentHandler);
 
-    // Check whether indenters are available.
-	if ( !indentHandler->getAvailableIndenters().isEmpty() ) {
-		toolBarWidget->cmbBoxIndenters->addItems( indentHandler->getAvailableIndenters() );
-		// Take care if the selected indenterID is greater than the number of existing indenters
-		if ( currentIndenterID >= indentHandler->getAvailableIndenters().count() ) {
-			currentIndenterID = indentHandler->getAvailableIndenters().count() - 1;
-		}
-	}
-    // If no indenter are found, show a warning message.
-	else {
-		currentIndenterID = 0;
-	}
-
-    // Set the combobox in the toolbar to show the selected indenter.
-    toolBarWidget->cmbBoxIndenters->setCurrentIndex( currentIndenterID );
-
     // If settings for the indenter have changed, let the main window know aboud it.
     connect(indentHandler, SIGNAL(indenterSettingsChanged()), this, SLOT(indentSettingsChangedSlot()));
 
@@ -417,59 +400,6 @@
     connect( uiGuiIndenterParameterTooltipsEnabled, SIGNAL(toggled(bool)), settings, SLOT(handleValueChangeFromExtern(bool)) );
     connect( settings, SIGNAL(indenterParameterTooltipsEnabled(bool)), uiGuiIndenterParameterTooltipsEnabled, SLOT(setChecked(bool)) );
     uiGuiIndenterParameterTooltipsEnabled->setChecked( settings->getValueByName("IndenterParameterTooltipsEnabled").toBool() );
-
-    // Handle if the indenter help/manual button is pressed
-    connect( toolBarWidget->indenterManualButton, SIGNAL(clicked()), this, SLOT(showIndenterManual()) );
-}
-
-
-/*!
-    \brief Creates the by \a indenterID selected indent handler object and adds the indent widget to its layout.
- */
-void MainWindow::selectIndenter(int indenterID) {
-    IndentHandler *oldIndentHandler = indentHandler;
-
-    // Prevent unnecessary updates if same indenter as current has been selected
-    if ( indenterID == currentIndenterID ) {
-        return;
-    }
-
-    // Disconnect the old indent handler from the settings changed slot, because he will be deleted.
-    disconnect(oldIndentHandler, SIGNAL(indenterSettingsChanged()), this, SLOT(indentSettingsChangedSlot()));
-
-    QApplication::setOverrideCursor(Qt::WaitCursor);
-
-    indentHandler = new IndentHandler(indenterDirctoryStr, settingsDirctoryStr, tempDirctoryStr, indenterID, this, centralwidget);
-    indentHandler->hide();
-    vboxLayout->insertWidget(0, indentHandler);
-    oldIndentHandler->hide();
-    indentHandler->show();
-    vboxLayout->removeWidget(oldIndentHandler);
-    delete oldIndentHandler;
-
-    // Take care if the selected indenterID is smaller or greater than the number of existing indenters
-    if ( indenterID < 0 ) {
-        indenterID = 0;
-    }
-    if ( indenterID >= indentHandler->getAvailableIndenters().count() ) {
-        indenterID = indentHandler->getAvailableIndenters().count() - 1;
-    }
-
-    // Set the combobox in the toolbar to show the selected indenter.
-    toolBarWidget->cmbBoxIndenters->setCurrentIndex(indenterID);
-
-    // If settings for the indenter have changed, let the main window know aboud it.
-    connect(indentHandler, SIGNAL(indenterSettingsChanged()), this, SLOT(indentSettingsChangedSlot()));
-
-    currentIndenterID = indenterID;
-    if ( toolBarWidget->cbLivePreview->isChecked() ) {
-        callIndenter();
-    }
-
-    previewToggled = true;
-    indentSettingsChanged = true;
-    updateSourceView();
-    QApplication::restoreOverrideCursor();
 }
 
 
@@ -1356,12 +1286,21 @@
         // Translate the toolbar.
         toolBarWidget->retranslateUi(toolBar);
 
-         // Translate the encoding menu.
+        // Translate the indent handler widget.
+        indentHandler->retranslateUi();
+
+         // Translate the load encoding menu.
         QList<QAction *> encodingActionList = encodingActionGroup->actions();
         for ( i = 0; i < encodingActionList.size(); i++ ) {
             encodingActionList.at(i)->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingsList.at(i) );
         }
 
+        // Translate the save encoding menu.
+        encodingActionList = saveEncodedActionGroup->actions();
+        for ( i = 0; i < encodingActionList.size(); i++ ) {
+            encodingActionList.at(i)->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + encodingsList.at(i) );
+        }
+
         // Translate the highlighter menu.
         QList<QAction *> actionList = highlighterMenu->actions();
         i = 0;
@@ -1395,12 +1334,7 @@
 
     QString fileExtensions = tr("Shell Script")+" (*."+shellScriptExtension+");;"+tr("All files")+" (*.*)";
 
-    QString currentIndenterName = toolBarWidget->cmbBoxIndenters->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 );
-    }
+    QString currentIndenterName = indentHandler->getCurrentIndenterName();
     currentIndenterName = currentIndenterName.replace(" ", "_");
 
     //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions );
@@ -1565,15 +1499,6 @@
 
 
 /*!
-    \brief This slot gets the reference to the indenters manual from the indenter handler and opens it.
- */
-void MainWindow::showIndenterManual() {
-    QString manualReference = indentHandler->getManual();
-    QDesktopServices::openUrl( manualReference );
-}
-
-
-/*!
     \brief If the dragged in object contains urls/paths to a file, accept the drag.
  */
 void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
--- a/src/mainwindow.h	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/mainwindow.h	Tue Jun 10 09:53:07 2008 +0000
@@ -139,7 +139,6 @@
     void updateSourceView();
     void turnHighlightOnOff(bool turnOn);
 	void setWhiteSpaceVisibility(bool visible);
-    void selectIndenter(int indenterID);
 	void sourceCodeChangedHelperSlot();
     void sourceCodeChangedSlot();
     void indentSettingsChangedSlot();
@@ -154,7 +153,6 @@
     void updateRecentlyOpenedList();
     void openFileFromRecentlyOpenedList(QAction* recentlyOpenedAction);
     void clearRecentlyOpenedList();
-    void showIndenterManual();
 };
 
 #endif // MAINWINDOW_H
--- a/src/mainwindow.ui	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/mainwindow.ui	Tue Jun 10 09:53:07 2008 +0000
@@ -155,7 +155,7 @@
     <set>Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea</set>
    </property>
    <property name="windowTitle" >
-    <string>Indenter Parameter</string>
+    <string>Indenter Settings</string>
    </property>
    <attribute name="dockWidgetArea" >
     <number>1</number>
--- a/src/toolBarWidget.ui	Fri Jun 06 10:41:35 2008 +0000
+++ b/src/toolBarWidget.ui	Tue Jun 10 09:53:07 2008 +0000
@@ -42,29 +42,6 @@
     </widget>
    </item>
    <item>
-    <widget class="QComboBox" name="cmbBoxIndenters" >
-     <property name="toolTip" >
-      <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Shows the currently chosen indenters name and lets you choose other available indenters&lt;/p>&lt;/body>&lt;/html></string>
-     </property>
-     <property name="sizeAdjustPolicy" >
-      <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
-     </property>
-     <property name="minimumContentsLength" >
-      <number>20</number>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QToolButton" name="indenterManualButton" >
-     <property name="toolTip" >
-      <string>Brings you to the online manual of the currently selected indenter, where you can get further help on the possible parameters.</string>
-     </property>
-     <property name="icon" >
-      <iconset resource="../resources/Icons.qrc" >:/mainWindow/help.png</iconset>
-     </property>
-    </widget>
-   </item>
-   <item>
     <widget class="QCheckBox" name="cbLivePreview" >
      <property name="toolTip" >
       <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;/head>&lt;body style=" white-space: pre-wrap; font-family:MS Shell Dlg 2; font-size:8.25pt; font-weight:400; font-style:normal; text-decoration:none;">&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:MS Shell Dlg; font-size:8pt;">Turns the preview of the reformatted source code on and off.&lt;/p>&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:MS Shell Dlg; font-size:8pt;">In other words it switches between formatted and nonformatted code. (Ctrl+L)&lt;/p>&lt;/body>&lt;/html></string>