changeset 483:1ce0ba4e86d6

Prepared the indenter specific context menu. It already shows up when right clicking on the widget. Now the indent handler needs to implement the load and save functions and the main window needs to get the menu from the IndentHandler. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@723 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 12 Jun 2008 09:41:46 +0000
parents 6dda59f4cc5a
children da38faef3eb8
files src/indenthandler.cpp src/indenthandler.h
diffstat 2 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Thu Jun 12 09:15:02 2008 +0000
+++ b/src/indenthandler.cpp	Thu Jun 12 09:41:46 2008 +0000
@@ -50,6 +50,11 @@
     this->mainWindow = mainWindow;
 
     indenterSettings = NULL;
+    menuIndenter = NULL;
+    actionLoad_Indenter_Config_File = NULL;
+    actionSave_Indenter_Config_File = NULL;
+    actionCreateShellScript = NULL;
+    initIndenterMenu();
 
     // define this widgets size and resize behavior
     //this->setMaximumWidth(263);
@@ -142,6 +147,46 @@
 
 
 /*!
+    \brief Initializes the context menu used for some actions like saving the indenter config file.
+ */
+void IndentHandler::initIndenterMenu() {
+    if ( menuIndenter == NULL ) {
+        actionLoad_Indenter_Config_File = new QAction(this);
+        actionLoad_Indenter_Config_File->setObjectName(QString::fromUtf8("actionLoad_Indenter_Config_File"));
+        actionLoad_Indenter_Config_File->setIcon(QIcon(QString::fromUtf8(":/mainWindow/load_indent_cfg.png")));
+        actionSave_Indenter_Config_File = new QAction(this);
+        actionSave_Indenter_Config_File->setObjectName(QString::fromUtf8("actionSave_Indenter_Config_File"));
+        actionSave_Indenter_Config_File->setIcon(QIcon(QString::fromUtf8(":/mainWindow/save_indent_cfg.png")));
+        actionCreateShellScript = new QAction(this);
+        actionCreateShellScript->setObjectName(QString::fromUtf8("actionCreateShellScript"));
+        actionCreateShellScript->setIcon(QIcon(QString::fromUtf8(":/mainWindow/shell.png")));
+
+        menuIndenter = new QMenu(this);
+        menuIndenter->setObjectName(QString::fromUtf8("menuIndenter"));
+        menuIndenter->addAction(actionLoad_Indenter_Config_File);
+        menuIndenter->addAction(actionSave_Indenter_Config_File);
+        menuIndenter->addAction(actionCreateShellScript);
+    }
+}
+
+
+/*!
+    \brief Returns the context menu used for some actions like saving the indenter config file.
+ */
+QMenu* IndentHandler::getIndenterMenu() {
+    return menuIndenter;
+}
+
+
+/*!
+    \brief Opens the context menu, used for some actions like saving the indenter config file, at the event position.
+ */
+void IndentHandler::contextMenuEvent( QContextMenuEvent *event ) {
+    getIndenterMenu()->exec( event->globalPos() );
+}
+
+
+/*!
     \brief Creates the content for a shell script that can be used as a external too call
     to indent a as parameter defined file.
  */
@@ -1216,6 +1261,16 @@
 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.") );
+
+    actionLoad_Indenter_Config_File->setText(QApplication::translate("MainWindowUi", "Load Indenter Config File", 0, QApplication::UnicodeUTF8));
+    actionLoad_Indenter_Config_File->setStatusTip(QApplication::translate("MainWindowUi", "Opens a file dialog to load the original config file of the indenter.", 0, QApplication::UnicodeUTF8));
+    actionLoad_Indenter_Config_File->setShortcut(QApplication::translate("MainWindowUi", "Alt+O", 0, QApplication::UnicodeUTF8));
+    actionSave_Indenter_Config_File->setText(QApplication::translate("MainWindowUi", "Save Indenter Config File", 0, QApplication::UnicodeUTF8));
+    actionSave_Indenter_Config_File->setStatusTip(QApplication::translate("MainWindowUi", "Opens a dialog to save the current indenter configuration to a file.", 0, QApplication::UnicodeUTF8));
+    actionSave_Indenter_Config_File->setShortcut(QApplication::translate("MainWindowUi", "Alt+S", 0, QApplication::UnicodeUTF8));
+    actionCreateShellScript->setText(QApplication::translate("MainWindowUi", "Create Indenter Call Shell Script", 0, QApplication::UnicodeUTF8));
+    actionCreateShellScript->setToolTip(QApplication::translate("MainWindowUi", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings", 0, QApplication::UnicodeUTF8));
+    actionCreateShellScript->setStatusTip(QApplication::translate("MainWindowUi", "Create a shell script that calls the current selected indenter for formatting an as parameter given file with the current indent settings", 0, QApplication::UnicodeUTF8));
 }
 
 
--- a/src/indenthandler.h	Thu Jun 12 09:15:02 2008 +0000
+++ b/src/indenthandler.h	Thu Jun 12 09:41:46 2008 +0000
@@ -42,6 +42,9 @@
 #include <QTextCodec>
 #include <QtScript>
 #include <QDesktopServices>
+#include <QMenu>
+#include <QAction>
+#include <QContextMenuEvent>
 
 #include "uiguierrormessage.h"
 #include "templateBatchScript.h"
@@ -66,6 +69,8 @@
     QString getManual();
     void retranslateUi();
     QString getCurrentIndenterName();
+    QMenu* getIndenterMenu();
+    void contextMenuEvent( QContextMenuEvent *event );
 
 signals:
     void indenterSettingsChanged();
@@ -80,6 +85,7 @@
     void writeConfigFile(QString filePathName, QString parameterString);
     void readIndentIniFile(QString iniFilePath);
     bool createIndenterCallString();
+    void initIndenterMenu();
 
     //! Holds a reference to all created pages of the toolbox and the pages boxlayout
     struct ToolBoxPage {
@@ -157,6 +163,11 @@
     UiGuiErrorMessage *errorMessageDialog;
     QString indenterExecutableCallString;
     QString indenterExecutableSuffix;
+
+    QMenu *menuIndenter;
+    QAction *actionLoad_Indenter_Config_File;
+    QAction *actionSave_Indenter_Config_File;
+    QAction *actionCreateShellScript;
 };
 
 #endif // INDENTHANDLER_H