Author: gs
Date: Wed Feb 2 14:41:56 2011
New Revision: 63305
URL: http://svn.opensuse.org/viewcvs/yast?rev=63305&view=rev
Log:
support multi selection (checkboxes added)
Modified:
trunk/ncurses/src/NCTree.cc
trunk/ncurses/src/NCTree.h
Modified: trunk/ncurses/src/NCTree.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTree.cc?rev=63305&r1=63304&r2=63305&view=diff
==============================================================================
--- trunk/ncurses/src/NCTree.cc (original)
+++ trunk/ncurses/src/NCTree.cc Wed Feb 2 14:41:56 2011
@@ -37,12 +37,12 @@
NCTreeLine * fchild;
mutable chtype * prefix;
-
+ bool multiSel;
unsigned prefixLen() const { return level + 3; }
public:
- NCTreeLine( NCTreeLine * p, YTreeItem * item )
+ NCTreeLine( NCTreeLine * p, YTreeItem * item, bool multiSelection )
: NCTableLine( 0 )
, yitem( item )
, level( p ? p->level + 1 : 0 )
@@ -50,6 +50,7 @@
, nsibling( 0 )
, fchild( 0 )
, prefix( 0 )
+ , multiSel( multiSelection )
{
if ( parent )
{
@@ -73,9 +74,16 @@
}
}
- Append( new NCTableCol( NCstring( string( prefixLen(), ' ' )
-
+ if ( !multiSel )
+ {
+ Append( new NCTableCol( NCstring( string( prefixLen(), ' ' )
+ yitem->label() ) ) );
+ }
+ else
+ {
+ Append( new NCTableCol( NCstring( string( prefixLen(), ' ' ) + "[ ] "
+ + yitem->label() ) ) );
+ }
}
virtual ~NCTreeLine() { delete [] prefix; }
@@ -132,13 +140,14 @@
switch ( key )
{
case KEY_IC:
-
+ case '+':
if ( fchild->isVisible() )
return 0;
break;
case KEY_DC:
+ case '-':
if ( !fchild->isVisible() )
return 0;
@@ -147,8 +156,6 @@
case KEY_SPACE:
// case KEY_RETURN: see bug 67350
- case '+':
- case '-':
break;
default:
@@ -238,6 +245,7 @@
NCTree::NCTree( YWidget * parent, const string & nlabel, bool multiselection )
: YTree( parent, nlabel, multiselection )
, NCPadWidget( parent )
+ , multiSel ( multiselection )
{
yuiDebug() << endl;
setLabel( nlabel );
@@ -344,21 +352,52 @@
{
if ( !myPad() )
return;
-
+
YTreeItem * treeItem = dynamic_cast( item );
YUI_CHECK_PTR( treeItem );
YTreeItem *citem = getCurrentItem();
+
+ //retrieve position of item
+ int at = treeItem->index();
+
+ NCTreeLine * cline = 0; // current line
+ NCTableCol * ccol = 0; // current column
+
+ if ( multiSel )
+ {
+ cline = modifyTreeLine( at );
+ if ( cline )
+ {
+ ccol = cline->GetCol(0);
+ }
+ }
if ( !selected && ( treeItem == citem ) )
{
- YTree::deselectAllItems();
+ if ( !multiSel )
+ {
+ YTree::deselectAllItems();
+ }
+ else
+ {
+ YTree::selectItem ( treeItem, false );
+ if ( ccol )
+ {
+ ccol->SetLabel( NCstring( string( cline->Level() + 3, ' ' ) + "[ ] "
+ + item->label() ) );
+ }
+ }
}
else
{
- //retrieve position of item
- int at = treeItem->index();
-
YTree::selectItem( treeItem, selected );
+
+ if ( multiSel && ccol )
+ {
+ ccol->SetLabel( NCstring( string( cline->Level() + 3, ' ' ) + "[x] "
+ + item->label() ) );
+ }
+
//this highlights selected item, possibly unpacks the tree
//should it be in currently hidden branch
myPad()->ShowItem( getTreeLine( at ) );
@@ -422,7 +461,7 @@
YTreeItem * treeItem = dynamic_cast( item );
YUI_CHECK_PTR( treeItem );
- NCTreeLine * line = new NCTreeLine( parentLine, treeItem );
+ NCTreeLine * line = new NCTreeLine( parentLine, treeItem, multiSel );
pad->Append( line );
// iterate over children
@@ -463,36 +502,66 @@
NCursesEvent ret = NCursesEvent::none;
YTreeItem * oldCurrentItem = getCurrentItem();
- if ( ! handleInput( key ) ) // NCTreePad::handleInput()
+ if ( multiSel )
{
- switch ( key )
+ if ( ! handleInput( key ) ) // NCTreePad::handleInput()
{
- case KEY_SPACE: // KEY_SPACE is handled in NCTreeLine::handleInput
- case KEY_RETURN:
+ const YItem * currentItem = getCurrentItem();
- if ( notify() )
- {
- return NCursesEvent::Activated;
- }
- break;
+ if ( !currentItem )
+ return ret;
+
+ switch ( key )
+ {
+ case KEY_SPACE: // KEY_SPACE is handled in NCTreeLine::handleInput
+ case KEY_RETURN:
+
+ if ( currentItem->selected() )
+ selectItem( const_cast(currentItem), false );
+ else
+ selectItem( const_cast(currentItem), true );
+
+ if ( notify() )
+ {
+ ret = NCursesEvent::ValueChanged;
+ }
+ break;
+ }
}
}
+ else
+ {
+ if ( ! handleInput( key ) ) // NCTreePad::handleInput()
+ {
+ switch ( key )
+ {
+ case KEY_SPACE: // KEY_SPACE is handled in NCTreeLine::handleInput
+ case KEY_RETURN:
- const YItem * currentItem = getCurrentItem();
+ if ( notify() )
+ {
+ return NCursesEvent::Activated;
+ }
+ break;
+ }
+ }
- if ( !currentItem )
- return ret;
+ const YItem * currentItem = getCurrentItem();
- YTree::selectItem( const_cast( currentItem ), true );
+ if ( !currentItem )
+ return ret;
- yuiDebug() << "Old item: " << oldCurrentItem->label() << " Current: " << currentItem->label() << endl;
+ YTree::selectItem( const_cast( currentItem ), true );
- if ( notify() && immediateMode() && ( oldCurrentItem != currentItem ) )
- ret = NCursesEvent::SelectionChanged;
+ yuiDebug() << "Old item: " << oldCurrentItem->label() << " Current: " << currentItem->label() << endl;
+ if ( notify() && immediateMode() && ( oldCurrentItem != currentItem ) )
+ ret = NCursesEvent::SelectionChanged;
- yuiDebug() << "Notify: " << ( notify() ? "true" : "false" ) << " Return event: " << ret << endl;
+ yuiDebug() << "Notify: " << ( notify() ? "true" : "false" ) << " Return event: " << ret << endl;
+ }
+
return ret;
}
Modified: trunk/ncurses/src/NCTree.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ncurses/src/NCTree.h?rev=63305&r1=63304&r2=63305&view=diff
==============================================================================
--- trunk/ncurses/src/NCTree.h (original)
+++ trunk/ncurses/src/NCTree.h Wed Feb 2 14:41:56 2011
@@ -24,6 +24,7 @@
#include "YTree.h"
#include "NCPadWidget.h"
#include "NCTreePad.h"
+#include "NCTablePad.h"
class NCTreeLine;
@@ -37,6 +38,8 @@
NCTree( const NCTree & );
int idx;
+ bool multiSel;
+
void CreateTreeLines( NCTreeLine * p, NCTreePad * pad, YItem * item );
protected:
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org