From 175d89ad25b11cc918f2689aed0e3e913655c044 Mon Sep 17 00:00:00 2001 From: Jakob Leben Date: Mon, 26 Sep 2011 18:51:05 +0200 Subject: [PATCH] qt gui: add QDialog*openPanel The difference between *getPaths and *openPanel is that the latter has multiple selection disabled by default, and will return an array of paths only if multiple selection is enabled, or else the selected path directly. *openPanel should be implemented in other GUI kits as well, and *getPaths should be deprecated. --- SCClassLibrary/QtCollider/QDialog.sc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/SCClassLibrary/QtCollider/QDialog.sc b/SCClassLibrary/QtCollider/QDialog.sc index 37dd71fe9..19b6771f5 100644 --- a/SCClassLibrary/QtCollider/QDialog.sc +++ b/SCClassLibrary/QtCollider/QDialog.sc @@ -1,13 +1,22 @@ QFileDialog : QObject { - *new { arg okFunc, cancelFunc, fileMode, acceptMode; + *new { arg okFunc, cancelFunc, fileMode, acceptMode, stripResult = false; + var me = super.new("QcFileDialog", [fileMode, acceptMode] ); + if( okFunc.notNil ) { - me.connectFunction( 'accepted(VariantList)', { |me, result| okFunc.value(result) } ); + me.connectFunction( 'accepted(VariantList)', { + |me, result| + if( stripResult && (fileMode != 3) ) { result = result[0]; }; + okFunc.value(result) + }); }; + if( cancelFunc.notNil ) { me.connectFunction( 'rejected()', { cancelFunc.value() } ); }; + me.invokeMethod('show', synchronous:false); + ^me; } } @@ -19,6 +28,12 @@ QDialog { ^QFileDialog.new( okFunc, cancelFunc, fileMode, 0 ); } + *openPanel { arg okFunc, cancelFunc, multipleSelection=false; + var fileMode; + if( multipleSelection ) { fileMode = 3 } { fileMode = 1 }; + ^QFileDialog.new( okFunc, cancelFunc, fileMode, 0, stripResult:true ); + } + *savePanel { arg okFunc, cancelFunc; ^QFileDialog.new( okFunc, cancelFunc, 0, 1 ); } -- 2.11.4.GIT