Author: gs
Date: Tue May 24 12:22:42 2011
New Revision: 64101
URL: http://svn.opensuse.org/viewcvs/yast?rev=64101&view=rev
Log:
feature NCTree multi selection added (needed for
snapper feature #303699)
Modified:
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.cc
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.h
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.cc
branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.h
Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.cc?rev=64101&r1=64100&r2=64101&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.cc Tue May 24 12:22:42 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:
@@ -235,11 +242,18 @@
-NCTree::NCTree( YWidget * parent, const string & nlabel )
- : YTree( parent, nlabel )
+NCTree::NCTree( YWidget * parent, const string & nlabel, bool multiselection, bool recursiveselection )
+ : YTree( parent, nlabel, multiselection, recursiveselection )
, NCPadWidget( parent )
+ , multiSel ( multiselection )
{
yuiDebug() << endl;
+
+ if ( multiselection && recursiveselection )
+ yuiMilestone() << "NCTree recursive multi selection ON" << endl;
+ else if ( multiselection )
+ yuiMilestone() << "NCTree multi selection ON" << endl;
+
setLabel( nlabel );
}
@@ -336,7 +350,20 @@
return yitem;
}
+void NCTree::deselectAllItems()
+{
+ if ( multiSel)
+ {
+ YItemCollection selectedItems = YTree::selectedItems();
+ for ( YItemConstIterator it = selectedItems.begin(); it != selectedItems.end(); ++it )
+ {
+ selectItem( *it, false );
+ }
+ }
+
+ YTree::deselectAllItems();
+}
// Set current item (under the cursor) to selected
@@ -348,17 +375,48 @@
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 ) )
+ if ( !selected )
{
- YTree::deselectAllItems();
+ if ( !multiSel && (treeItem == citem) )
+ {
+ 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 +480,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
@@ -433,15 +491,18 @@
}
}
-
-
+// Returns current item (pure virtual in YTree)
+YTreeItem * NCTree::currentItem()
+{
+ return getCurrentItem();
+}
// Fills TreePad with lines (uses CreateTreeLines to create them)
void NCTree::DrawPad()
{
if ( !myPad() )
{
- yuiWarning() << "PadWidget not valid" << endl;
+ yuiWarning() << "PadWidget not yet created" << endl;
return;
}
@@ -463,36 +524,60 @@
NCursesEvent ret = NCursesEvent::none;
YTreeItem * oldCurrentItem = getCurrentItem();
- if ( ! handleInput( key ) ) // NCTreePad::handleInput()
- {
- switch ( key )
- {
- case KEY_SPACE: // KEY_SPACE is handled in NCTreeLine::handleInput
- case KEY_RETURN:
-
- if ( notify() )
- {
- return NCursesEvent::Activated;
- }
- break;
- }
- }
-
+ bool handled = handleInput( key ); // NCTreePad::handleInput()
const YItem * currentItem = getCurrentItem();
if ( !currentItem )
return ret;
- YTree::selectItem( const_cast( currentItem ), true );
+ if ( multiSel )
+ {
+ if ( ! handled )
+ {
+ switch ( key )
+ {
+ // KEY_SPACE is handled in NCTreeLine::handleInput
+ case KEY_RETURN:
- yuiDebug() << "Old item: " << oldCurrentItem->label() << " Current: " << currentItem->label() << endl;
+ if ( currentItem->selected() )
+ selectItem( const_cast(currentItem), false );
+ else
+ selectItem( const_cast(currentItem), true );
+
+ if ( notify() )
+ {
+ return NCursesEvent::ValueChanged;
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ if ( ! handled )
+ {
+ switch ( key )
+ {
+ // KEY_SPACE is handled in NCTreeLine::handleInput
+ case KEY_RETURN:
- if ( notify() && immediateMode() && ( oldCurrentItem != currentItem ) )
- ret = NCursesEvent::SelectionChanged;
+ if ( notify() )
+ {
+ return NCursesEvent::Activated;
+ }
+ break;
+ }
+ }
+ YTree::selectItem( const_cast( currentItem ), true );
+ }
- yuiDebug() << "Notify: " << ( notify() ? "true" : "false" ) << " Return event: " << ret << endl;
+ if ( notify() && immediateMode() && ( oldCurrentItem != currentItem ) )
+ ret = NCursesEvent::SelectionChanged;
+ yuiDebug() << "Notify: " << ( notify() ? "true" : "false" ) <<
+ " Return event: " << ret.reason << endl;
+
return ret;
}
Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.h?rev=64101&r1=64100&r2=64101&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCTree.h Tue May 24 12:22:42 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:
@@ -57,7 +60,7 @@
public:
- NCTree( YWidget * parent, const string & label );
+ NCTree( YWidget * parent, const string & label, bool multiselection=false, bool recursiveselection=false );
virtual ~NCTree();
virtual int preferredWidth();
@@ -70,6 +73,10 @@
virtual YTreeItem * getCurrentItem() const;
+ virtual YTreeItem * currentItem();
+
+ virtual void deselectAllItems();
+
virtual void selectItem( YItem *item, bool selected );
virtual void selectItem( int index );
Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.cc?rev=64101&r1=64100&r2=64101&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.cc Tue May 24 12:22:42 2011
@@ -153,9 +153,9 @@
NCTree *
-NCWidgetFactory::createTree( YWidget * parent, const string & label )
+NCWidgetFactory::createTree( YWidget * parent, const string & label, bool multiselection, bool recursiveselection )
{
- NCTree * tree = new NCTree( parent, label );
+ NCTree * tree = new NCTree( parent, label, multiselection, recursiveselection );
YUI_CHECK_NEW( tree );
return tree;
Modified: branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.h?rev=64101&r1=64100&r2=64101&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/ncurses/src/NCWidgetFactory.h Tue May 24 12:22:42 2011
@@ -93,7 +93,7 @@
virtual NCRadioButton * createRadioButton ( YWidget * parent, const string & label, bool isChecked = false );
virtual NCComboBox * createComboBox ( YWidget * parent, const string & label, bool editable = false );
virtual NCSelectionBox * createSelectionBox ( YWidget * parent, const string & label );
- virtual NCTree * createTree ( YWidget * parent, const string & label );
+ virtual NCTree * createTree ( YWidget * parent, const string & label, bool multiselection = false, bool recursiveselection = false );
virtual NCTable * createTable ( YWidget * parent, YTableHeader * tableHeader, bool multiSelection = false );
virtual NCProgressBar * createProgressBar ( YWidget * parent, const string & label, int maxValue = 100 );
virtual NCRichText * createRichText ( YWidget * parent, const string & text = string(), bool plainTextMode = false );
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org