[rkward-cvs] SF.net SVN: rkward:[2784] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Mar 11 15:18:24 UTC 2010


Revision: 2784
          http://rkward.svn.sourceforge.net/rkward/?rev=2784&view=rev
Author:   tfry
Date:     2010-03-11 15:18:24 +0000 (Thu, 11 Mar 2010)

Log Message:
-----------
Allow specification of character encoding when opening script files

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/agents/showedittextfileagent.cpp
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/rkward.h
    trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
    trunk/rkward/rkward/windows/rkcommandeditorwindow.h
    trunk/rkward/rkward/windows/rkworkplace.cpp
    trunk/rkward/rkward/windows/rkworkplace.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/ChangeLog	2010-03-11 15:18:24 UTC (rev 2784)
@@ -1,3 +1,4 @@
+- File->Open R Script File now allows to specify the character encoding to use
 - Fixed: No entries were added the recent script/workspaces actions after "save as"
 - Initialize the output file with an appropriate encoding specification
 - Add SVG support to export (graphics) plugin

Modified: trunk/rkward/rkward/agents/showedittextfileagent.cpp
===================================================================
--- trunk/rkward/rkward/agents/showedittextfileagent.cpp	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/agents/showedittextfileagent.cpp	2010-03-11 15:18:24 UTC (rev 2784)
@@ -2,7 +2,7 @@
                           showedittextfileagent  -  description
                              -------------------
     begin                : Tue Sep 13 2005
-    copyright            : (C) 2005, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2005, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -108,7 +108,7 @@
 
 		message.append (title + "\n");
 
-		bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromLocalFile (files[n]), r_highlighting, read_only, title);
+		bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromLocalFile (files[n]), QString (), r_highlighting, read_only, title);
 
 		if (!ok)  {
 			bad_files_list.append ("- ").append (title).append (" (").append (files[n]).append (")\n");

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/rkward.cpp	2010-03-11 15:18:24 UTC (rev 2784)
@@ -30,7 +30,7 @@
 // include files for KDE
 #include <kiconloader.h>
 #include <kmessagebox.h>
-#include <kfiledialog.h>
+#include <kencodingfiledialog.h>
 #include <kmenubar.h>
 #include <kstatusbar.h>
 #include <klocale.h>
@@ -671,26 +671,26 @@
 	if (!url.isEmpty ()) fileOpenRecent->addUrl (url);
 }
 
-void RKWardMainWindow::slotOpenCommandEditor (const KUrl &url) {
+void RKWardMainWindow::slotOpenCommandEditor (const KUrl &url, const QString &encoding) {
 	RK_TRACE (APP);
 
-	RKWorkplace::mainWorkplace ()->openScriptEditor (url);
+	RKWorkplace::mainWorkplace ()->openScriptEditor (url, encoding);
 }
 
 void RKWardMainWindow::slotOpenCommandEditor () {
 	RK_TRACE (APP);
-	KUrl::List urls;
+	KEncodingFileDialog::Result res;
 	KUrl::List::const_iterator it;
 
 #ifdef Q_WS_WIN
 	// getOpenUrls(KUrl("kfiledialog:///<rfiles>"), ...) causes a hang on windows (KDElibs 4.2.3).
 #	warning Track this bug down and/or report it
-	urls = KFileDialog::getOpenUrls (KUrl (), "*.R *.r *.S *.s *.q|R Script Files (*.R *.r *.S *.s *.q)\n*|All Files (*)", this, i18n ("Open command file(s)"));
+	res = KEncodingFileDialog::getOpenUrlsAndEncoding (QString (), QString (), "*.R *.r *.S *.s *.q|R Script Files (*.R *.r *.S *.s *.q)\n*|All Files (*)", this, i18n ("Open script file(s)"));
 #else
-	urls = KFileDialog::getOpenUrls (KUrl ("kfiledialog:///<rfiles>"), "*.R *.r *.S *.s *.q|R Script Files (*.R *.r *.S *.s *.q)\n*|All Files (*)", this, i18n ("Open command file(s)"));
+	res = KEncodingFileDialog::getOpenUrlsAndEncoding (QString (), "kfiledialog:///<rfiles>", "*.R *.r *.S *.s *.q|R Script Files (*.R *.r *.S *.s *.q)\n*|All Files (*)", this, i18n ("Open script file(s)"));
 #endif
-	for (it = urls.begin() ; it != urls.end() ; ++it) {
-		slotOpenCommandEditor (*it);
+	for (it = res.URLs.begin() ; it != res.URLs.end() ; ++it) {
+		slotOpenCommandEditor (*it, res.encoding);
 	}
 };
 

Modified: trunk/rkward/rkward/rkward.h
===================================================================
--- trunk/rkward/rkward/rkward.h	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/rkward.h	2010-03-11 15:18:24 UTC (rev 2784)
@@ -137,7 +137,7 @@
 /** open a new command editor (ask for file to open) */
 	void slotOpenCommandEditor ();
 /** open a new command editor (load given url) */
-	void slotOpenCommandEditor (const KUrl &url);
+	void slotOpenCommandEditor (const KUrl &url, const QString& encoding = QString ());
 
 /** close current window (Windows->Close). */
 	void slotCloseWindow ();

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp	2010-03-11 15:18:24 UTC (rev 2784)
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -311,8 +311,11 @@
 	m_doc->setReadWrite (!ro);
 }
 
-bool RKCommandEditorWindow::openURL (const KUrl &url, bool use_r_highlighting, bool read_only){
+bool RKCommandEditorWindow::openURL (const KUrl &url, const QString& encoding, bool use_r_highlighting, bool read_only){
 	RK_TRACE (COMMANDEDITOR);
+
+	// encoding must be set *before* loading the file
+	if (!encoding.isEmpty ()) m_doc->setEncoding (encoding);
 	if (m_doc->openUrl (url)){
 		if (use_r_highlighting) setRHighlighting ();
 		setReadOnly (read_only);

Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h	2010-03-11 15:18:24 UTC (rev 2784)
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004, 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -135,8 +135,9 @@
 	~RKCommandEditorWindow ();
 /** open given URL. 
 @param use_r_highlighting Initialize the view to use R syntax highlighting. Use, if you're going to edit an R syntax file
+ at param encoding encoding to use. If QString (), the default encoding is used.
 @param read_only Open the file in read-only mode */
-	bool openURL (const KUrl &url, bool use_r_highlighting=true, bool read_only=false);
+	bool openURL (const KUrl &url, const QString& encoding=QString (), bool use_r_highlighting=true, bool read_only=false);
 /** returns, whether the document was modified since the last save */
 	bool isModified ();
 /** insert the given text into the document at the current cursor position. Additionally, focuses the view */

Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp	2010-03-11 15:18:24 UTC (rev 2784)
@@ -2,7 +2,7 @@
                           rkworkplace  -  description
                              -------------------
     begin                : Thu Sep 21 2006
-    copyright            : (C) 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -205,7 +205,7 @@
 		return true;	// TODO
 	}
 	if (mimetype->name ().startsWith ("text")) {
-		return (openScriptEditor (url, false));
+		return (openScriptEditor (url, QString (), false));
 	}
 
 	if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file or the filetype is not supported by RKWard. Do you want to open the url in the default application?", url.prettyUrl ()), i18n ("Open in default application?")) != KMessageBox::Yes) {
@@ -216,7 +216,7 @@
 	return false;
 }
 
-bool RKWorkplace::openScriptEditor (const KUrl &url, bool use_r_highlighting, bool read_only, const QString &force_caption) {
+bool RKWorkplace::openScriptEditor (const KUrl &url, const QString& encoding, bool use_r_highlighting, bool read_only, const QString &force_caption) {
 	RK_TRACE (APP);
 
 // is this url already opened?
@@ -233,9 +233,9 @@
 	}
 
 	RKCommandEditorWindow *editor = new RKCommandEditorWindow (view (), use_r_highlighting);
-
+  
 	if (!url.isEmpty ()) {
-		if (!editor->openURL (url, use_r_highlighting, read_only)) {
+		if (!editor->openURL (url, encoding, use_r_highlighting, read_only)) {
 			delete editor;
 			KMessageBox::messageBox (view (), KMessageBox::Error, i18n ("Unable to open \"%1\"", url.prettyUrl ()), i18n ("Could not open command file"));
 			return false;

Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h	2010-03-11 14:50:46 UTC (rev 2783)
+++ trunk/rkward/rkward/windows/rkworkplace.h	2010-03-11 15:18:24 UTC (rev 2784)
@@ -2,7 +2,7 @@
                           rkworkplace  -  description
                              -------------------
     begin                : Thu Sep 21 2006
-    copyright            : (C) 2006, 2007, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -95,11 +95,12 @@
 
 /** Opens a new script editor
 @param url URL to load. Default option is to open an empty document
+ at param encoding encoding to use. If QString (), the default encoding is used.
 @param use_r_highlighting Set R highlighting mode (vs. no highlighting)? Default is yes
 @param read_only Open the document read only? Default is false, i.e. Read-write
 @param force_caption Usually the caption is determined from the url of the file. If you specify a non-empty string here, that is used instead.
 @returns false if a local url could not be opened, true for all remote urls, and on success */
-	bool openScriptEditor (const KUrl &url=KUrl (), bool use_r_highlighting=true, bool read_only=false, const QString &force_caption = QString::null);
+	bool openScriptEditor (const KUrl &url=KUrl (), const QString& encoding=QString (), bool use_r_highlighting=true, bool read_only=false, const QString &force_caption = QString::null);
 /** Opens a new help window, starting at the given url
 @param url URL to open
 @param only_once if true, checks whether any help window already shows this URL. If so, raise it, but do not open a new window. Else show the new window */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list