Mercurial > hg > forks > UniversalIndentGUI
changeset 484:da38faef3eb8
[change] Feature Request ID 1989585 : Added a context menu in indenter parameters widget and moved all functions handling these actions from the main window to the indent handler. http://universalindent.sf.net/issue/1989585
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@724 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 12 Jun 2008 22:22:38 +0000 |
parents | 1ce0ba4e86d6 |
children | b50b445acb47 |
files | src/indenthandler.cpp src/indenthandler.h src/mainwindow.cpp src/mainwindow.h src/mainwindow.ui |
diffstat | 5 files changed, 184 insertions(+), 190 deletions(-) [+] |
line wrap: on
line diff
--- a/src/indenthandler.cpp Thu Jun 12 09:41:46 2008 +0000 +++ b/src/indenthandler.cpp Thu Jun 12 22:22:38 2008 +0000 @@ -56,6 +56,10 @@ actionCreateShellScript = NULL; initIndenterMenu(); + connect( actionLoad_Indenter_Config_File, SIGNAL(activated()), this, SLOT(openConfigFileDialog()) ); + connect( actionSave_Indenter_Config_File, SIGNAL(activated()), this, SLOT(saveasIndentCfgFileDialog()) ); + connect( actionCreateShellScript, SIGNAL(activated()), this, SLOT(createIndenterCallShellScript()) ); + // define this widgets size and resize behavior //this->setMaximumWidth(263); this->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); @@ -179,6 +183,16 @@ /*! + \brief Returns the actions of the context menu used for some actions like saving the indenter config file. +*/ +QList<QAction*> IndentHandler::getIndenterMenuActions() { + QList<QAction*> actionList; + actionList << actionLoad_Indenter_Config_File << actionSave_Indenter_Config_File << actionCreateShellScript; + return actionList; +} + + +/*! \brief Opens the context menu, used for some actions like saving the indenter config file, at the event position. */ void IndentHandler::contextMenuEvent( QContextMenuEvent *event ) { @@ -1287,4 +1301,88 @@ } return currentIndenterName; -} \ No newline at end of file +} + + +/*! +\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() { + QString configFilePath; + + configFilePath = QFileDialog::getOpenFileName( NULL, tr("Choose indenter config file"), getIndenterCfgFile(), "All files (*.*)" ); + + if (configFilePath != "") { + loadConfigFile(configFilePath); + } +} + + +/*! +\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() { + QString fileExtensions = tr("All files")+" (*.*)"; + + //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); + QString fileName = QFileDialog::getSaveFileName( this, tr("Save indent config file"), getIndenterCfgFile(), fileExtensions); + + if (fileName != "") { + QFile::remove(fileName); + QFile outCfgFile(fileName); + outCfgFile.open( QFile::ReadWrite | QFile::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() { + //QString indenterCallShellScript = generateCommandlineCall(currentSourceFileExtension); + //TODO: Should be like previous call + QString indenterCallShellScript = generateCommandlineCall(""); + + QString shellScriptExtension; +#if defined(Q_OS_WIN32) + shellScriptExtension = "bat"; +#else + shellScriptExtension = "sh"; +#endif + + QString fileExtensions = tr("Shell Script")+" (*."+shellScriptExtension+");;"+tr("All files")+" (*.*)"; + + QString currentIndenterName = getCurrentIndenterName(); + currentIndenterName = currentIndenterName.replace(" ", "_"); + + //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); + QString fileName = QFileDialog::getSaveFileName( this, tr("Save shell script"), "call_"+currentIndenterName+"."+shellScriptExtension, fileExtensions); + + // Saving has been canceled if the filename is empty + if ( fileName.isEmpty() ) { + return; + } + + // Replace placeholder for script name in script template. + indenterCallShellScript = indenterCallShellScript.replace( "__INDENTERCALLSTRINGSCRIPTNAME__", QFileInfo(fileName).fileName() ); + + // Delete any old file, write the new contents and set executable permissions. + QFile::remove(fileName); + QFile outSrcFile(fileName); + outSrcFile.open( QFile::ReadWrite | QFile::Text ); + outSrcFile.write( indenterCallShellScript.toAscii() ); +#if !defined(Q_OS_WIN32) + // For none Windows systems the files executable flag + outSrcFile.setPermissions( outSrcFile.permissions() | QFile::ExeOwner | QFile::ExeUser| QFile::ExeGroup ); +#endif + outSrcFile.close(); +}
--- a/src/indenthandler.h Thu Jun 12 09:41:46 2008 +0000 +++ b/src/indenthandler.h Thu Jun 12 22:22:38 2008 +0000 @@ -45,6 +45,7 @@ #include <QMenu> #include <QAction> #include <QContextMenuEvent> +#include <QFileDialog> #include "uiguierrormessage.h" #include "templateBatchScript.h" @@ -70,6 +71,7 @@ void retranslateUi(); QString getCurrentIndenterName(); QMenu* getIndenterMenu(); + QList<QAction*> getIndenterMenuActions(); void contextMenuEvent( QContextMenuEvent *event ); signals: @@ -78,6 +80,9 @@ private slots: void setIndenter(int indenterID); void showIndenterManual(); + void openConfigFileDialog(); + void saveasIndentCfgFileDialog(); + void createIndenterCallShellScript(); private: QString callExecutableIndenter(QString sourceCode, QString inputFileExtension);
--- a/src/mainwindow.cpp Thu Jun 12 09:41:46 2008 +0000 +++ b/src/mainwindow.cpp Thu Jun 12 22:22:38 2008 +0000 @@ -233,9 +233,6 @@ connect( actionSave_Source_File, SIGNAL(activated()), this, SLOT(saveSourceFile()) ); connect( actionExportPDF, SIGNAL(activated()), this, SLOT(exportToPDF()) ); connect( actionExportHTML, SIGNAL(activated()), this, SLOT(exportToHTML()) ); - connect( actionLoad_Indenter_Config_File, SIGNAL(activated()), this, SLOT(openConfigFileDialog()) ); - connect( actionSave_Indenter_Config_File, SIGNAL(activated()), this, SLOT(saveasIndentCfgFileDialog()) ); - connect( actionCreateShellScript, SIGNAL(activated()), this, SLOT(createIndenterCallShellScript()) ); connect( actionCheck_for_update, SIGNAL(activated()), updateCheckDialog, SLOT(checkForUpdateAndShowDialog()) ); // Init the menu for selecting one of the recently opened files. @@ -400,6 +397,10 @@ connect( uiGuiIndenterParameterTooltipsEnabled, SIGNAL(toggled(bool)), settings, SLOT(handleValueChangeFromExtern(bool)) ); connect( settings, SIGNAL(indenterParameterTooltipsEnabled(bool)), uiGuiIndenterParameterTooltipsEnabled, SLOT(setChecked(bool)) ); uiGuiIndenterParameterTooltipsEnabled->setChecked( settings->getValueByName("IndenterParameterTooltipsEnabled").toBool() ); + + // Add the indenters context menu to the mainwindows menu. + menuIndenter->addActions( indentHandler->getIndenterMenuActions() ); + } @@ -557,43 +558,6 @@ /*! - \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 MainWindow::saveasIndentCfgFileDialog() { - QString fileExtensions = tr("All files")+" (*.*)"; - - //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); - QString fileName = QFileDialog::getSaveFileName( this, tr("Save indent config file"), indentHandler->getIndenterCfgFile(), fileExtensions); - - if (fileName != "") { - QFile::remove(fileName); - QFile outCfgFile(fileName); - outCfgFile.open( QFile::ReadWrite | QFile::Text ); - outCfgFile.write( indentHandler->getParameterString().toAscii() ); - outCfgFile.close(); - } -} - - -/*! - \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 MainWindow::openConfigFileDialog() { - QString configFilePath; - - configFilePath = QFileDialog::getOpenFileName( NULL, tr("Choose indenter config file"), indentHandler->getIndenterCfgFile(), "All files (*.*)" ); - - if (configFilePath != "") { - indentHandler->loadConfigFile(configFilePath); - } -} - - -/*! \brief Shows a file open dialog. Shows a file open dialog with the title \a dialogHeaderStr starting in the directory \a startPath @@ -1316,50 +1280,6 @@ } -/*! - \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 MainWindow::createIndenterCallShellScript() { - QString indenterCallShellScript = indentHandler->generateCommandlineCall(currentSourceFileExtension); - - QString shellScriptExtension; -#if defined(Q_OS_WIN32) - shellScriptExtension = "bat"; -#else - shellScriptExtension = "sh"; -#endif - - QString fileExtensions = tr("Shell Script")+" (*."+shellScriptExtension+");;"+tr("All files")+" (*.*)"; - - QString currentIndenterName = indentHandler->getCurrentIndenterName(); - currentIndenterName = currentIndenterName.replace(" ", "_"); - - //QString openedSourceFileContent = openFileDialog( tr("Choose source code file"), "./", fileExtensions ); - QString fileName = QFileDialog::getSaveFileName( this, tr("Save shell script"), "call_"+currentIndenterName+"."+shellScriptExtension, fileExtensions); - - // Saving has been canceled if the filename is empty - if ( fileName.isEmpty() ) { - return; - } - - // Replace placeholder for script name in script template. - indenterCallShellScript = indenterCallShellScript.replace( "__INDENTERCALLSTRINGSCRIPTNAME__", QFileInfo(fileName).fileName() ); - - // Delete any old file, write the new contents and set executable permissions. - QFile::remove(fileName); - QFile outSrcFile(fileName); - outSrcFile.open( QFile::ReadWrite | QFile::Text ); - outSrcFile.write( indenterCallShellScript.toAscii() ); -#if !defined(Q_OS_WIN32) -// For none Windows systems the files executable flag - outSrcFile.setPermissions( outSrcFile.permissions() | QFile::ExeOwner | QFile::ExeUser| QFile::ExeGroup ); -#endif - outSrcFile.close(); -} - /*! \brief Updates the list of recently opened files.
--- a/src/mainwindow.h Thu Jun 12 09:41:46 2008 +0000 +++ b/src/mainwindow.h Thu Jun 12 22:22:38 2008 +0000 @@ -129,12 +129,10 @@ bool eventFilter(QObject *obj, QEvent *event); private slots: - void openConfigFileDialog(); void openSourceFileDialog(QString fileName = ""); bool saveasSourceFileDialog(QAction *chosenEncodingAction = NULL); void saveAsOtherEncoding(QAction *chosenEncodingAction); bool saveSourceFile(); - void saveasIndentCfgFileDialog(); void callIndenter(); void updateSourceView(); void turnHighlightOnOff(bool turnOn); @@ -149,7 +147,6 @@ void encodingChanged(QAction *encodingAction); void highlighterChanged(QAction* highlighterAction); void numberOfLinesChanged(); - void createIndenterCallShellScript(); void updateRecentlyOpenedList(); void openFileFromRecentlyOpenedList(QAction* recentlyOpenedAction); void clearRecentlyOpenedList();
--- a/src/mainwindow.ui Thu Jun 12 09:41:46 2008 +0000 +++ b/src/mainwindow.ui Thu Jun 12 22:22:38 2008 +0000 @@ -14,23 +14,23 @@ <string>UniversalIndentGUI</string> </property> <property name="windowIcon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/icon2.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/icon2.png</normaloff>:/mainWindow/icon2.png</iconset> </property> <widget class="QWidget" name="centralwidget" > + <property name="geometry" > + <rect> + <x>66</x> + <y>33</y> + <width>883</width> + <height>581</height> + </rect> + </property> <layout class="QHBoxLayout" > <property name="spacing" > <number>6</number> </property> - <property name="leftMargin" > - <number>0</number> - </property> - <property name="topMargin" > - <number>0</number> - </property> - <property name="rightMargin" > - <number>0</number> - </property> - <property name="bottomMargin" > + <property name="margin" > <number>0</number> </property> <item> @@ -38,23 +38,23 @@ <property name="spacing" > <number>0</number> </property> - <property name="leftMargin" > - <number>2</number> - </property> - <property name="topMargin" > - <number>2</number> - </property> - <property name="rightMargin" > - <number>2</number> - </property> - <property name="bottomMargin" > + <property name="margin" > <number>2</number> </property> </layout> </item> </layout> </widget> - <widget class="QStatusBar" name="statusbar" /> + <widget class="QStatusBar" name="statusbar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>614</y> + <width>949</width> + <height>19</height> + </rect> + </property> + </widget> <widget class="QMenuBar" name="menuBar" > <property name="geometry" > <rect> @@ -68,9 +68,6 @@ <property name="title" > <string>Indenter</string> </property> - <addaction name="actionLoad_Indenter_Config_File" /> - <addaction name="actionSave_Indenter_Config_File" /> - <addaction name="actionCreateShellScript" /> </widget> <widget class="QMenu" name="menuFile" > <property name="title" > @@ -142,6 +139,14 @@ <addaction name="menuHelp" /> </widget> <widget class="QDockWidget" name="dockWidget" > + <property name="geometry" > + <rect> + <x>0</x> + <y>33</y> + <width>62</width> + <height>581</height> + </rect> + </property> <property name="sizePolicy" > <sizepolicy vsizetype="Preferred" hsizetype="MinimumExpanding" > <horstretch>0</horstretch> @@ -149,10 +154,10 @@ </sizepolicy> </property> <property name="features" > - <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable|QDockWidget::NoDockWidgetFeatures</set> + <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set> </property> <property name="allowedAreas" > - <set>Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea</set> + <set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> </property> <property name="windowTitle" > <string>Indenter Settings</string> @@ -161,20 +166,19 @@ <number>1</number> </attribute> <widget class="QWidget" name="dockWidgetContents" > + <property name="geometry" > + <rect> + <x>0</x> + <y>22</y> + <width>62</width> + <height>559</height> + </rect> + </property> <layout class="QHBoxLayout" > <property name="spacing" > <number>6</number> </property> - <property name="leftMargin" > - <number>0</number> - </property> - <property name="topMargin" > - <number>0</number> - </property> - <property name="rightMargin" > - <number>0</number> - </property> - <property name="bottomMargin" > + <property name="margin" > <number>0</number> </property> <item> @@ -182,16 +186,7 @@ <property name="spacing" > <number>0</number> </property> - <property name="leftMargin" > - <number>0</number> - </property> - <property name="topMargin" > - <number>0</number> - </property> - <property name="rightMargin" > - <number>0</number> - </property> - <property name="bottomMargin" > + <property name="margin" > <number>0</number> </property> </layout> @@ -200,6 +195,14 @@ </widget> </widget> <widget class="QToolBar" name="toolBar" > + <property name="geometry" > + <rect> + <x>0</x> + <y>21</y> + <width>949</width> + <height>12</height> + </rect> + </property> <property name="contextMenuPolicy" > <enum>Qt::PreventContextMenu</enum> </property> @@ -227,7 +230,8 @@ </widget> <action name="actionOpen_Source_File" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/document-open.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/document-open.png</normaloff>:/mainWindow/document-open.png</iconset> </property> <property name="text" > <string>Open Source File</string> @@ -241,7 +245,8 @@ </action> <action name="actionSave_Source_File" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/document-save.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/document-save.png</normaloff>:/mainWindow/document-save.png</iconset> </property> <property name="text" > <string>Save Source File</string> @@ -255,7 +260,8 @@ </action> <action name="actionSave_Source_File_As" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/document-save-as.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/document-save-as.png</normaloff>:/mainWindow/document-save-as.png</iconset> </property> <property name="text" > <string>Save Source File As</string> @@ -264,37 +270,10 @@ <string>Opens a file dialog to save the currently shown source code.</string> </property> </action> - <action name="actionLoad_Indenter_Config_File" > - <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/load_indent_cfg.png</iconset> - </property> - <property name="text" > - <string>Load Indenter Config File</string> - </property> - <property name="statusTip" > - <string>Opens a file dialog to load the original config file of the indenter.</string> - </property> - <property name="shortcut" > - <string>Alt+O</string> - </property> - </action> - <action name="actionSave_Indenter_Config_File" > - <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/save_indent_cfg.png</iconset> - </property> - <property name="text" > - <string>Save Indenter Config File</string> - </property> - <property name="statusTip" > - <string>Opens a dialog to save the current indenter configuration to a file.</string> - </property> - <property name="shortcut" > - <string>Alt+S</string> - </property> - </action> <action name="actionAbout_UniversalIndentGUI" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/info.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/info.png</normaloff>:/mainWindow/info.png</iconset> </property> <property name="text" > <string>About UniversalIndentGUI</string> @@ -305,7 +284,8 @@ </action> <action name="actionExit" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/system-log-out.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/system-log-out.png</normaloff>:/mainWindow/system-log-out.png</iconset> </property> <property name="text" > <string>Exit</string> @@ -319,7 +299,8 @@ </action> <action name="actionExportPDF" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/exportpdf.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/exportpdf.png</normaloff>:/mainWindow/exportpdf.png</iconset> </property> <property name="text" > <string>PDF</string> @@ -330,7 +311,8 @@ </action> <action name="actionExportHTML" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/exporthtml.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/exporthtml.png</normaloff>:/mainWindow/exporthtml.png</iconset> </property> <property name="text" > <string>HTML</string> @@ -347,7 +329,8 @@ <bool>true</bool> </property> <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/tooltip.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/tooltip.png</normaloff>:/mainWindow/tooltip.png</iconset> </property> <property name="text" > <string>Parameter Tooltips</string> @@ -361,7 +344,8 @@ <bool>true</bool> </property> <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/live-preview.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/live-preview.png</normaloff>:/mainWindow/live-preview.png</iconset> </property> <property name="text" > <string>Live Indent Preview</string> @@ -381,7 +365,8 @@ <bool>true</bool> </property> <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/syntax-highlight.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/syntax-highlight.png</normaloff>:/mainWindow/syntax-highlight.png</iconset> </property> <property name="text" > <string>Syntax Highlighting</string> @@ -438,7 +423,8 @@ </action> <action name="actionShowSettings" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/preferences-system.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/preferences-system.png</normaloff>:/mainWindow/preferences-system.png</iconset> </property> <property name="text" > <string>Settings</string> @@ -453,23 +439,10 @@ <string>Opens the settings dialog, to set language etc.</string> </property> </action> - <action name="actionCreateShellScript" > - <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/shell.png</iconset> - </property> - <property name="text" > - <string>Create Indenter Call Shell Script</string> - </property> - <property name="toolTip" > - <string>Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings</string> - </property> - <property name="statusTip" > - <string>Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings</string> - </property> - </action> <action name="actionCheck_for_update" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/system-software-update.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/system-software-update.png</normaloff>:/mainWindow/system-software-update.png</iconset> </property> <property name="text" > <string>Check for update</string> @@ -483,7 +456,8 @@ </action> <action name="actionClear_Recently_Opened_List" > <property name="icon" > - <iconset resource="../resources/Icons.qrc" >:/mainWindow/edit-clear.png</iconset> + <iconset resource="../resources/Icons.qrc" > + <normaloff>:/mainWindow/edit-clear.png</normaloff>:/mainWindow/edit-clear.png</iconset> </property> <property name="text" > <string>Clear Recently Opened List</string>