[rkward-cvs] SF.net SVN: rkward:[2794] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Thu Mar 18 21:29:09 UTC 2010
Revision: 2794
http://rkward.svn.sourceforge.net/rkward/?rev=2794&view=rev
Author: tfry
Date: 2010-03-18 21:29:09 +0000 (Thu, 18 Mar 2010)
Log Message:
-----------
Replace tcl-tk menus with our own
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/dialogs/CMakeLists.txt
trunk/rkward/rkward/rbackend/rinterface.cpp
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
trunk/rkward/rkward/rbackend/rthread.cpp
trunk/rkward/rkward/resource.ver
trunk/rkward/rkward/rkward.cpp
trunk/rkward/rkward/version.h
Added Paths:
-----------
trunk/rkward/rkward/dialogs/rkselectlistdialog.cpp
trunk/rkward/rkward/dialogs/rkselectlistdialog.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/ChangeLog 2010-03-18 21:29:09 UTC (rev 2794)
@@ -1,3 +1,4 @@
+- Use a native menu, instead of the default TclTk-menu TODO: sizing, test, discuss the settings page, again
- Fixed: Newly created variables were not properly updated when closing and re-opening the editor
- Added "paste special" action to script editor and console for pasting R vectors and matrices from spreadsheets
- Fix order of menus for detached windows
@@ -10,7 +11,7 @@
- Fixed: Frequent crashes while running automated plugintests
- Fixed: Filenames without extension would not be shown in file dialogs
- Fixed: Calling "fix(my.fun)" would remove comments
-- Fixed: Removing "@CRAN@" from the repositories would break package installation
+- Fixed: Removing "@CRAN@" from the repositories would break package installation TODO: doesn't it still? Investigate.
--- Version 0.5.2 - Oct-26-2009
- Add Stata data file import plugin (by Michael Ash)
Modified: trunk/rkward/rkward/dialogs/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/dialogs/CMakeLists.txt 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/dialogs/CMakeLists.txt 2010-03-18 21:29:09 UTC (rev 2794)
@@ -8,6 +8,7 @@
rkloadlibsdialog.cpp
rkreadlinedialog.cpp
rkimportdialog.cpp
+ rkselectlistdialog.cpp
)
QT4_AUTOMOC(${dialogs_STAT_SRCS})
Added: trunk/rkward/rkward/dialogs/rkselectlistdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkselectlistdialog.cpp (rev 0)
+++ trunk/rkward/rkward/dialogs/rkselectlistdialog.cpp 2010-03-18 21:29:09 UTC (rev 2794)
@@ -0,0 +1,86 @@
+/***************************************************************************
+ rkselectlistdialog - description
+ -------------------
+ begin : Thu Mar 18 2010
+ copyright : (C) 2010 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "rkselectlistdialog.h"
+
+#include <QListWidget>
+#include <QLabel>
+//#include <QApplication>
+//#include <QDesktopWidget>
+
+#include <klocale.h>
+#include <kvbox.h>
+
+#include "../debug.h"
+
+RKSelectListDialog::RKSelectListDialog (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple) : KDialog (parent) {
+ RK_TRACE (DIALOGS);
+
+ setModal (true);
+ setCaption (caption);
+ setButtons (KDialog::Ok | KDialog::Cancel);
+
+ KVBox *page = new KVBox ();
+ setMainWidget (page);
+
+ new QLabel (caption, page);
+
+// int screen_height = qApp->desktop ()->height () - 2*marginHint() - 2*spacingHint ();
+
+ input = new QListWidget (page);
+ input->addItems (choices);
+ if (multiple) input->setSelectionMode (QAbstractItemView::MultiSelection);
+ else input->setSelectionMode (QAbstractItemView::SingleSelection);
+ for (int i = 0; i < preselected.length (); ++i) {
+ int pos = choices.indexOf (preselected[i]);
+ if (pos >= 0) input->item (pos)->setSelected (true);
+ }
+
+ connect (input, SIGNAL (itemSelectionChanged()), this, SLOT (updateState()));
+ updateState ();
+}
+
+RKSelectListDialog::~RKSelectListDialog () {
+ RK_TRACE (DIALOGS);
+}
+
+void RKSelectListDialog::updateState () {
+ RK_TRACE (DIALOGS);
+
+ // TODO is there no QListWidget::hasSelection()?
+ if (input->selectedItems ().isEmpty ()) enableButtonOk (false);
+ else enableButtonOk (true);
+}
+
+//static
+QStringList RKSelectListDialog::doSelect (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple) {
+ RK_TRACE (DIALOGS);
+
+ RKSelectListDialog *dialog = new RKSelectListDialog (parent, caption, choices, preselected, multiple);
+ int res = dialog->exec ();
+ if (res != QDialog::Accepted) return QStringList ();
+
+ QStringList list;
+ QList<QListWidgetItem*> selected = dialog->input->selectedItems ();
+ for (int i = 0; i < selected.length (); ++i) {
+ list.append (selected[i]->text ());
+ }
+
+ return (list);
+}
+
+#include "rkselectlistdialog.moc"
Added: trunk/rkward/rkward/dialogs/rkselectlistdialog.h
===================================================================
--- trunk/rkward/rkward/dialogs/rkselectlistdialog.h (rev 0)
+++ trunk/rkward/rkward/dialogs/rkselectlistdialog.h 2010-03-18 21:29:09 UTC (rev 2794)
@@ -0,0 +1,52 @@
+/***************************************************************************
+ rkselectlistdialog - description
+ -------------------
+ begin : Thu Mar 18 2010
+ copyright : (C) 2010 by Thomas Friedrichsmeier
+ email : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef RKSELECTLISTDIALOG_H
+#define RKSELECTLISTDIALOG_H
+
+#include <kdialog.h>
+
+class QListWidget;
+class QWidget;
+
+/** This class represent a dialog asking for a choice among several optiosn. It is used, when the backend calls select.list() / menu().
+
+ at author Thomas Friedrichsmeier
+*/
+class RKSelectListDialog : public KDialog {
+ Q_OBJECT
+public:
+ /** Construct and run modal RKSelectListDialog.
+ @param parent QWidget to center the modal dialog on (0 for application)
+ @param caption Dialog title
+ @param choices The list of available choices
+ @param preselected The preselected choices (QStringList ()) for no preselects
+ @param multiple Whether multiple items may be selected
+ @returns The selected option(s). An empty list, if cancel was pressed. */
+ static QStringList doSelect (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple);
+protected:
+ /** ctor. Use the doSelect() instead. */
+ RKSelectListDialog (QWidget *parent, const QString &caption, const QStringList& choices, const QStringList& preselected, bool multiple);
+ /** destructor */
+ ~RKSelectListDialog ();
+private slots:
+ void updateState ();
+private:
+ QListWidget *input;
+};
+
+#endif
Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp 2010-03-18 21:29:09 UTC (rev 2794)
@@ -2,7 +2,7 @@
rinterface.cpp - description
-------------------
begin : Fri Nov 1 2002
- copyright : (C) 2002, 2004, 2005, 2006, 2007, 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2002, 2004, 2005, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -26,6 +26,7 @@
#include "../core/renvironmentobject.h"
#include "../core/rkmodificationtracker.h"
#include "../dialogs/rkloadlibsdialog.h"
+#include "../dialogs/rkselectlistdialog.h"
#include "../dialogs/rkreadlinedialog.h"
#include "../agents/showedittextfileagent.h"
#include "../agents/rkeditobjectagent.h"
@@ -415,6 +416,24 @@
} else {
RK_ASSERT (false);
}
+ } else if (call == "select.list") {
+ QString title = request->call[1];
+ bool multiple = (request->call[2] == "multi");
+ int num_preselects = request->call[3].toInt ();
+ QStringList preselects = request->call.mid (4, num_preselects);
+ QStringList choices = request->call.mid (4 + num_preselects);
+
+ QStringList results = RKSelectListDialog::doSelect (0, title, choices, preselects, multiple);
+ if (results.isEmpty ()) results.append (""); // R wants to have it that way
+
+ QString command = ".rk.set.reply (c (";
+ for (int i = 0; i < results.length (); ++i) {
+ if (i > 0) command.append (", ");
+ command.append (RObject::rQuote (results[i]));
+ }
+ command.append ("))");
+
+ issueCommand (command, RCommand::App | RCommand::Sync, QString::null, 0, 0, request->in_chain);
} else if (call == "recordCommands") {
if (request->call.count () == 3) {
QString filename = request->call[1];
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R 2010-03-18 21:29:09 UTC (rev 2794)
@@ -445,3 +445,35 @@
show (res)
invisible (TRUE)
}
+
+".rk.select.list.proxy" <- function () {
+ # the "graphics" parameter was introduced in R 2.11.0, so we cannot rely on its existance
+ if (!exists ("graphics", inherits=FALSE)) graphics <- TRUE
+ if (graphics) {
+ return (rk.select.list (list, preselect, multiple, title))
+ }
+
+ # for text list, use the default implementation
+ eval (body (.rk.select.list.default))
+}
+formals (.rk.select.list.proxy) <- formals (utils::select.list)
+.rk.select.list.default <- utils::select.list
+
+".rk.menu.proxy" <- function () {
+ if (graphics) {
+ res <- rk.select.list (choices, multiple=FALSE, title=title)
+ return (match(res, choices, nomatch = 0L))
+ }
+
+ # for text menus, use the default implementation
+ eval (body (.rk.menu.default))
+}
+formals (.rk.menu.proxy) <- formals (utils::menu)
+.rk.menu.default <- utils::menu
+
+# where masking is not enough, we need to assign in the namespace. This can only be done after package loading,
+# so we have a separate function for that.
+".rk.fix.assignments" <- function () {
+ assignInNamespace ("menu", .rk.menu.proxy, envir=as.environment ("package:utils"))
+ assignInNamespace ("select.list", .rk.select.list.proxy, envir=as.environment ("package:utils"))
+}
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R 2010-03-18 21:29:09 UTC (rev 2794)
@@ -413,3 +413,31 @@
invisible (TRUE)
}
+
+# drop-in-replacement for tk_select.list()
+"rk.select.list" <- function (list, preselect = NULL, multiple = FALSE, title = NULL) {
+ preselect <- as.character (preselect)
+ preselect.len = length (preselect)
+ list <- as.character (list)
+ list.len <- length (list)
+ params <- list ()
+
+ # serialize all parameters
+ params[1] <- as.character (title)
+ if (multiple) params[2] <- "multi"
+ else params[2] <- "single"
+ params[3] <- as.character (preselect.len)
+ if (preselect.len) {
+ for (i in 1:preselect.len) {
+ params[3+i] <- preselect[i]
+ }
+ }
+ if (list.len) { # we should hope, the list is not empty...
+ for (i in 1:list.len) {
+ params[3+preselect.len+i] <- list[i]
+ }
+ }
+
+ .rk.do.call ("select.list", params)
+}
+
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R 2010-03-18 21:29:09 UTC (rev 2794)
@@ -1 +1 @@
-".rk.app.version" <- "0.5.3-test2"
+".rk.app.version" <- "0.5.3-test3"
Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rbackend/rthread.cpp 2010-03-18 21:29:09 UTC (rev 2794)
@@ -2,7 +2,7 @@
rthread - description
-------------------
begin : Mon Aug 2 2004
- copyright : (C) 2004, 2006, 2007, 2008, 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2004, 2006, 2007, 2008, 2009, 2010 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -495,6 +495,8 @@
if (error) status |= LibLoadFail;
runCommandInternal (QString ("stopifnot(.rk.app.version==\"%1\")\n").arg (VERSION), &error);
if (error) status |= LibLoadFail;
+ runCommandInternal (".rk.fix.assignments ()\n", &error);
+ if (error) status |= LibLoadFail;
// find out about standard library locations
unsigned int c;
Modified: trunk/rkward/rkward/resource.ver
===================================================================
--- trunk/rkward/rkward/resource.ver 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/resource.ver 2010-03-18 21:29:09 UTC (rev 2794)
@@ -1 +1 @@
-0.5.3-test2
+0.5.3-test3
Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/rkward.cpp 2010-03-18 21:29:09 UTC (rev 2794)
@@ -85,6 +85,7 @@
#include "agents/showedittextfileagent.h" // TODO: see below: needed purely for linking!
#include "dialogs/rkreadlinedialog.h" // TODO: see below: needed purely for linking!
+#include "dialogs/rkselectlistdialog.h" // TODO: see below: needed purely for linking!
#include "windows/detachedwindowcontainer.h" // TODO: see below: needed purely for linking!
#include "dataeditor/rkeditordataframe.h" // TODO: see below: needed purely for linking!
#include "agents/rkeditobjectagent.h" // TODO: see below: needed purely for linking!
@@ -93,6 +94,7 @@
void bogusCalls () {
ShowEditTextFileAgent::showEditFiles (0); // TODO: AAAAAAAARGGGH!!!! It won't link without this bogus line!!!
RKReadLineDialog::readLine (0, QString(), QString(), 0, 0); // TODO: see above
+ RKSelectListDialog::doSelect (0, QString(), QStringList(), QStringList(), false); // TODO: see above
new RKEditorDataFrame (0, 0);
DetachedWindowContainer (0);
new RKWorkplaceView (0);
Modified: trunk/rkward/rkward/version.h
===================================================================
--- trunk/rkward/rkward/version.h 2010-03-18 11:19:30 UTC (rev 2793)
+++ trunk/rkward/rkward/version.h 2010-03-18 21:29:09 UTC (rev 2794)
@@ -1,2 +1,2 @@
/* Version number of package */
-#define VERSION "0.5.3-test2"
+#define VERSION "0.5.3-test3"
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