r23856 by jghali - Use same preference contexts when saving text from story editor or main window, also store selected text encoding

scribus-commit scribus-commit at lists.scribus.net
Fri May 29 20:34:34 UTC 2020


Author: jghali
Date: Fri May 29 20:34:34 2020
New Revision: 23856

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23856
Log:
Use same preference contexts when saving text from story editor or main window, also store selected text encoding

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/customfdialog.cpp
    trunk/Scribus/scribus/ui/customfdialog.h
    trunk/Scribus/scribus/ui/storyeditor.cpp

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23856&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Fri May 29 20:34:34 2020
@@ -5361,20 +5361,25 @@
 void ScribusMainWindow::SaveText()
 {
 	PrefsContext* dirsContext = m_prefsManager.prefsFile->getContext("dirs");
+	PrefsContext* textContext = m_prefsManager.prefsFile->getContext("textsave_dialog");
 	QString prefsDocDir = m_prefsManager.documentDir();
 	QString workingDir = dirsContext->get("save_text", prefsDocDir.isEmpty() ? "." : prefsDocDir);
+	QString textEncoding = textContext->get("encoding");
 
 	CustomFDialog dia(this, workingDir, tr("Save as"), tr("Text Files (*.txt);;All Files (*)"), fdShowCodecs|fdHidePreviewCheckBox);
+	dia.setTextCodec(textEncoding);
 	if (dia.exec() != QDialog::Accepted)
 		return;
-	QString fn = dia.selectedFile();
-	if (fn.isEmpty())
-		return;
-	QString loadEnc = dia.optionCombo->currentText();
-
-	m_prefsManager.prefsFile->getContext("dirs")->set("save_text", fn.left(fn.lastIndexOf("/")));
+
+	QString fileName = dia.selectedFile();
+	if (fileName.isEmpty())
+		return;
+	textEncoding = dia.textCodec();
+
+	dirsContext->set("save_text", fileName.left(fileName.lastIndexOf("/")));
+	textContext->set("encoding", dia.textCodec());
 	const StoryText& story (doc->m_Selection->itemAt(0)->itemText);
-	Serializer::writeWithEncoding(fn, loadEnc, story.plainText());
+	Serializer::writeWithEncoding(fileName, textEncoding, story.plainText());
 }
 
 void ScribusMainWindow::applyNewMaster(const QString& name)

Modified: trunk/Scribus/scribus/ui/customfdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23856&path=/trunk/Scribus/scribus/ui/customfdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.cpp	Fri May 29 20:34:34 2020
@@ -593,7 +593,7 @@
 	m_ext = e;
 }
 
-QString CustomFDialog::extension()
+const QString&  CustomFDialog::extension() const
 {
 	return m_ext;
 }
@@ -603,7 +603,33 @@
 	m_extZip = e;
 }
 
-QString CustomFDialog::zipExtension()
+const QString& CustomFDialog::zipExtension() const
 {
 	return m_extZip;
 }
+
+void CustomFDialog::setTextCodec(const QString& textCodec)
+{
+	if ((m_optionFlags & fdShowCodecs) == 0)
+		return;
+	if (!optionCombo)
+		return;
+
+	QString textEncoding = textCodec;
+	if (textCodec.isEmpty())
+		textEncoding = "System";
+
+	int index = optionCombo->findText(textEncoding, Qt::MatchFixedString);
+	if (index < 0)
+		return;
+	optionCombo->setCurrentIndex(index);
+}
+
+QString CustomFDialog::textCodec() const
+{
+	if ((m_optionFlags & fdShowCodecs) == 0)
+		return QString();
+	if (optionCombo)
+		return optionCombo->currentText();
+	return QString();
+}

Modified: trunk/Scribus/scribus/ui/customfdialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23856&path=/trunk/Scribus/scribus/ui/customfdialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.h	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.h	Fri May 29 20:34:34 2020
@@ -106,27 +106,31 @@
 	void setExtension(const QString& e);
 	/*! \brief Get the file extension
 	\retval QString see setExtension(QString e) */
-	QString extension();
+	const QString& extension() const;
+
 	/*! \brief Set the "compress" extension of the resulting file name.
 	\param e string extension without any "."
 	*/
 	void setZipExtension(const QString& e);
 	/*! \brief Get the zipped file extension
 	\retval QString see setZipExtension(QString e) */
-	QString zipExtension();
+	const QString& zipExtension() const;
 
-	QCheckBox* saveZip;
-	QCheckBox* withFonts;
-	QCheckBox* withProfiles;
-	QFrame* Layout;
-	QFrame* LayoutC;
-	QComboBox *optionCombo;
-	QLabel *optionLabel;
-	ScFileWidget *fileDialog;
-	FDialogPreview *filePreview;
-	QCheckBox *showPreview;
-	QPushButton* okButton;
-	QPushButton* cancelButton;
+	void setTextCodec(const QString& textCodec);
+	QString textCodec() const;
+
+	QCheckBox* saveZip { nullptr };
+	QCheckBox* withFonts { nullptr };
+	QCheckBox* withProfiles { nullptr };
+	QFrame* Layout { nullptr };
+	QFrame* LayoutC { nullptr };
+	QComboBox *optionCombo { nullptr };
+	QLabel *optionLabel { nullptr };
+	ScFileWidget *fileDialog { nullptr };
+	FDialogPreview *filePreview { nullptr };
+	QCheckBox *showPreview { nullptr };
+	QPushButton* okButton { nullptr };
+	QPushButton* cancelButton { nullptr };
 
 	void setSelection(const QString& );
 	QString selectedFile();

Modified: trunk/Scribus/scribus/ui/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23856&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp	(original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp	Fri May 29 20:34:34 2020
@@ -47,6 +47,7 @@
 #include <QShowEvent>
 #include <QSignalBlocker>
 #include <QScopedPointer>
+#include <QScopedValueRollback>
 #include <QScrollBar>
 #include <QTextBlock>
 #include <QTextCodec>
@@ -3484,26 +3485,26 @@
 
 void StoryEditor::SaveTextFile()
 {
-	m_blockUpdate = true;
-	PrefsContext* dirs = prefsManager.prefsFile->getContext("dirs");
-	QString wdir = dirs->get("story_save", prefsManager.appPrefs.pathPrefs.documents);
-	CustomFDialog dia(this, wdir, tr("Save as"), tr("Text Files (*.txt);;All Files (*)"), fdShowCodecs|fdHidePreviewCheckBox);
-	qApp->processEvents();
+	QScopedValueRollback<bool> blockUpdateRollback(m_blockUpdate);
+	PrefsContext* dirsContext = prefsManager.prefsFile->getContext("dirs");
+	PrefsContext* textContext = prefsManager.prefsFile->getContext("textsave_dialog");
+	QString prefsDocDir = prefsManager.documentDir();
+	QString workingDir = dirsContext->get("save_text", prefsDocDir.isEmpty() ? "." : prefsDocDir);
+	QString textEncoding = textContext->get("encoding");
+
+	CustomFDialog dia(this, workingDir, tr("Save as"), tr("Text Files (*.txt);;All Files (*)"), fdShowCodecs|fdHidePreviewCheckBox);
+	dia.setTextCodec(textEncoding);
 	if (dia.exec() != QDialog::Accepted)
-	{
-		m_blockUpdate = false;
 		return;
-	}
-	QString loadEnc = dia.optionCombo->currentText();
-	if (loadEnc == "UTF-16")
-		loadEnc = "ISO-10646-UCS-2";
+	
 	QString fileName = dia.selectedFile();
-	if (!fileName.isEmpty())
-	{
-		dirs->set("story_save", fileName.left(fileName.lastIndexOf("/")));
-		Serializer::writeWithEncoding(fileName, loadEnc, Editor->StyledText.plainText());
-	}
-	m_blockUpdate = false;
+	if (fileName.isEmpty())
+		return;
+	textEncoding = dia.textCodec();
+
+	dirsContext->set("save_text", fileName.left(fileName.lastIndexOf("/")));
+	textContext->set("encoding", dia.textCodec());
+	Serializer::writeWithEncoding(fileName, textEncoding, Editor->StyledText.plainText());
 }
 
 bool StoryEditor::textDataChanged() const




More information about the scribus-commit mailing list