Mercurial > hg > forks > UniversalIndentGUI
changeset 411:94cd0d754e8a
[add] Feature Request ID 1901935 : From now on files are save with the same encoding as they were opened and no longer always UTF-8. Also it is possible to save the file with any other encoding. http://universalindent.sf.net/issue/1901935
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@641 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Wed, 19 Mar 2008 16:20:52 +0000 |
parents | 1a70e855d535 |
children | 9d96b1887948 |
files | src/UniversalIndentGUI.vcproj src/indentgui.ui src/mainwindow.cpp src/mainwindow.h |
diffstat | 4 files changed, 65 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/UniversalIndentGUI.vcproj Wed Mar 19 12:41:59 2008 +0000 +++ b/src/UniversalIndentGUI.vcproj Wed Mar 19 16:20:52 2008 +0000 @@ -216,13 +216,7 @@ > <FileConfiguration Name="Debug|Win32" - > - <Tool - Name="VCCLCompilerTool" - /> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32" + ExcludedFromBuild="true" > <Tool Name="VCCLCompilerTool" @@ -276,13 +270,7 @@ > <FileConfiguration Name="Debug|Win32" - > - <Tool - Name="MOC" - /> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32" + ExcludedFromBuild="true" > <Tool Name="MOC" @@ -368,13 +356,7 @@ > <FileConfiguration Name="Debug|Win32" - > - <Tool - Name="VCCLCompilerTool" - /> - </FileConfiguration> - <FileConfiguration - Name="Release|Win32" + ExcludedFromBuild="true" > <Tool Name="VCCLCompilerTool"
--- a/src/indentgui.ui Wed Mar 19 12:41:59 2008 +0000 +++ b/src/indentgui.ui Wed Mar 19 16:20:52 2008 +0000 @@ -95,12 +95,18 @@ <string>Reopen File with other Encoding</string> </property> </widget> + <widget class="QMenu" name="saveEncodedMenu" > + <property name="title" > + <string>Save Source File As with other Encoding</string> + </property> + </widget> <addaction name="actionOpen_Source_File" /> <addaction name="menuRecently_Opened_Files" /> <addaction name="encodingMenu" /> <addaction name="separator" /> <addaction name="actionSave_Source_File" /> <addaction name="actionSave_Source_File_As" /> + <addaction name="saveEncodedMenu" /> <addaction name="separator" /> <addaction name="menuExport" /> <addaction name="actionExit" />
--- a/src/mainwindow.cpp Wed Mar 19 12:41:59 2008 +0000 +++ b/src/mainwindow.cpp Wed Mar 19 16:20:52 2008 +0000 @@ -544,7 +544,8 @@ If the file already exists and it should be overwritten, a warning is shown before. */ -bool MainWindow::saveasSourceFileDialog() { +bool MainWindow::saveasSourceFileDialog(QAction *chosenEncodingAction) { + QString encoding; QString fileExtensions = tr("Supported by indenter")+" ("+indentHandler->getPossibleIndenterFileExtensions()+ ");;"+tr("All files")+" (*.*)"; @@ -562,7 +563,17 @@ QFile::remove(fileName); QFile outSrcFile(fileName); outSrcFile.open( QFile::ReadWrite | QFile::Text ); - outSrcFile.write( savedSourceContent.toUtf8() ); + + // Get current encoding. + if ( chosenEncodingAction != NULL ) { + encoding = chosenEncodingAction->text(); + } + else { + encoding = encodingActionGroup->checkedAction()->text(); + } + QTextStream outSrcStrm(&outSrcFile); + outSrcStrm.setCodec( QTextCodec::codecForName(encoding.toAscii()) ); + outSrcStrm << savedSourceContent; outSrcFile.close(); QFileInfo fileInfo(fileName); @@ -591,17 +602,14 @@ QFile outSrcFile(currentSourceFile); savedSourceContent = txtedSourceCode->text(); outSrcFile.open( QFile::ReadWrite | QFile::Text ); - outSrcFile.write( savedSourceContent.toUtf8() ); - outSrcFile.close(); // Get current encoding. - /* QString currentEncoding = encodingActionGroup->checkedAction()->text(); QTextStream outSrcStrm(&outSrcFile); outSrcStrm.setCodec( QTextCodec::codecForName(currentEncoding.toAscii()) ); outSrcStrm << savedSourceContent; outSrcFile.close(); - */ + txtedSourceCode->setModified( false ); setWindowModified( txtedSourceCode->isModified() ); } @@ -1179,33 +1187,62 @@ /*! - \brief Creates a menu entry under the settings menu for all available text encodings. + \brief Creates a menu entries in the file menu for opening and saving a file with different encodings. */ void MainWindow::createEncodingMenu() { QAction *encodingAction; QString encodingName; - encodingActionGroup = new QActionGroup(this); - encodingsList = QStringList() << "UTF-8" << "UTF-16" << "UTF-16BE" << "UTF-16LE" << "Apple Roman" << "Big5" << "Big5-HKSCS" << "EUC-JP" << "EUC-KR" << "GB18030-0" << "IBM 850" << "IBM 866" << "IBM 874" << "ISO 2022-JP" << "ISO 8859-1" << "ISO 8859-13" << "Iscii-Bng" << "JIS X 0201" << "JIS X 0208" << "KOI8-R" << "KOI8-U" << "MuleLao-1" << "ROMAN8" << "Shift-JIS" << "TIS-620" << "TSCII" << "Windows-1250" << "WINSAMI2"; + encodingActionGroup = new QActionGroup(this); + saveEncodedActionGroup = new QActionGroup(this); + // Loop for each available encoding foreach ( encodingName, encodingsList ) { - encodingAction = new QAction(encodingName, encodingActionGroup); - encodingAction->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingName ); - encodingAction->setCheckable(true); - if ( encodingName == currentEncoding ) { - encodingAction->setChecked(true); - } + // Create actions for the "reopen" menu + encodingAction = new QAction(encodingName, encodingActionGroup); + encodingAction->setStatusTip( tr("Reopen the currently opened source code file by using the text encoding scheme ") + encodingName ); + encodingAction->setCheckable(true); + if ( encodingName == currentEncoding ) { + encodingAction->setChecked(true); + } + + // Create actions for the "save as encoded" menu + encodingAction = new QAction(encodingName, saveEncodedActionGroup); + encodingAction->setStatusTip( tr("Save the currently opened source code file by using the text encoding scheme ") + encodingName ); } encodingMenu->addActions( encodingActionGroup->actions() ); + connect( encodingActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(encodingChanged(QAction*)) ); - connect( encodingActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(encodingChanged(QAction*)) ); + saveEncodedMenu->addActions( saveEncodedActionGroup->actions() ); + connect( saveEncodedActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(saveAsOtherEncoding(QAction*)) ); +} + + +/*! + \brief This slot calls the save dialog to save the current source file with another encoding. + + If the saving is successul and not aborted, the currently used encoding, visible in the + "reopen" menu, is also changed to the new encoding. +*/ +void MainWindow::saveAsOtherEncoding(QAction *chosenEncodingAction) { + bool fileWasSaved = saveasSourceFileDialog(chosenEncodingAction); + + // If the file was save with another encoding, change the selected encoding in the reopen menu. + if ( fileWasSaved ) { + foreach ( QAction *action, encodingActionGroup->actions() ) { + if ( action->text() == chosenEncodingAction->text() ) { + action->setChecked(true); + return; + } + } + } }
--- a/src/mainwindow.h Wed Mar 19 12:41:59 2008 +0000 +++ b/src/mainwindow.h Wed Mar 19 16:20:52 2008 +0000 @@ -20,8 +20,6 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -//#include "arthurwidgets.h" - #include "ui_indentgui.h" #include "ui_toolBarWidget.h" #include "aboutdialog.h" @@ -108,6 +106,7 @@ QString currentSourceFileExtension; QString savedSourceContent; QActionGroup *encodingActionGroup; + QActionGroup *saveEncodedActionGroup; QActionGroup *highlighterActionGroup; QTranslator *uiGuiTranslator; QTranslator *qTTranslator; @@ -130,7 +129,8 @@ private slots: void openConfigFileDialog(); void openSourceFileDialog(QString fileName = ""); - bool saveasSourceFileDialog(); + bool saveasSourceFileDialog(QAction *chosenEncodingAction = NULL); + void saveAsOtherEncoding(QAction *chosenEncodingAction); bool saveSourceFile(); void saveasIndentCfgFileDialog(); void callIndenter();