Rewrite list view movement key handlers in file management mode

This resolves Bug 1961
pull/16/head
Timothy Pearson 10 years ago
parent 5c1caefb49
commit 4ffab32f5f

@ -2,6 +2,7 @@
Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
Copyright (C) 2000,2003 Charles Samuels <charles@kde.org> Copyright (C) 2000,2003 Charles Samuels <charles@kde.org>
Copyright (C) 2000 Peter Putzer Copyright (C) 2000 Peter Putzer
Copyright (C) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
@ -94,6 +95,7 @@ public:
tabRename(true), tabRename(true),
sortColumn(0), sortColumn(0),
selectionDirection(0), selectionDirection(0),
selectionRegion(0),
tooltipColumn (0), tooltipColumn (0),
selectionMode (Single), selectionMode (Single),
contextMenuKey (TDEGlobalSettings::contextMenuKey()), contextMenuKey (TDEGlobalSettings::contextMenuKey()),
@ -103,7 +105,8 @@ public:
paintCurrent (0), paintCurrent (0),
paintBelow (0), paintBelow (0),
painting (false), painting (false),
shadeSortColumn(TDEGlobalSettings::shadeSortColumn()) shadeSortColumn(TDEGlobalSettings::shadeSortColumn()),
initialFileManagerItem(0)
{ {
renameable.append(0); renameable.append(0);
connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int))); connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int)));
@ -156,6 +159,7 @@ public:
//+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX
int selectionDirection; int selectionDirection;
int selectionRegion;
int tooltipColumn; int tooltipColumn;
SelectionModeExt selectionMode; SelectionModeExt selectionMode;
@ -175,6 +179,8 @@ public:
bool shadeSortColumn:1; bool shadeSortColumn:1;
TQColor alternateBackground; TQColor alternateBackground;
TQListViewItem *initialFileManagerItem;
}; };
@ -1548,22 +1554,24 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
//don't care whether it's on the keypad or not //don't care whether it's on the keypad or not
int e_state=(e->state() & ~Keypad); int e_state=(e->state() & ~Keypad);
int oldSelectionDirection(d->selectionDirection); // Handle non-control keypresses
if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) if ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
&& (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) {
{ if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) {
if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove))
selectAll(false); selectAll(false);
d->selectionRegion = 0;
d->initialFileManagerItem = NULL;
}
d->selectionDirection=0; d->selectionDirection=0;
d->wasShiftEvent = (e_state == ShiftButton); d->wasShiftEvent = (e_state == ShiftButton);
}; }
//d->wasShiftEvent = (e_state == ShiftButton); //d->wasShiftEvent = (e_state == ShiftButton);
TQListViewItem* item = currentItem(); TQListViewItem* item = currentItem();
if (!item) return; if (!item) {
return;
}
TQListViewItem* repaintItem1 = item; TQListViewItem* repaintItem1 = item;
TQListViewItem* repaintItem2 = 0L; TQListViewItem* repaintItem2 = 0L;
@ -1574,8 +1582,9 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton));
int selectedItems(0); int selectedItems(0);
for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling()) for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling()) {
if (tmpItem->isSelected()) selectedItems++; if (tmpItem->isSelected()) selectedItems++;
}
if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse))) if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse)))
&& (e_state==Qt::NoButton) && (e_state==Qt::NoButton)
@ -1584,18 +1593,17 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
|| (e->key()==Key_Next) || (e->key()==Key_Next)
|| (e->key()==Key_Prior) || (e->key()==Key_Prior)
|| (e->key()==Key_Home) || (e->key()==Key_Home)
|| (e->key()==Key_End))) || (e->key()==Key_End))) {
{
d->selectedBySimpleMove=true; d->selectedBySimpleMove=true;
d->selectedUsingMouse=false; d->selectedUsingMouse=false;
} }
else if (selectedItems>1) else if (selectedItems>1) {
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
}
bool emitSelectionChanged(false); bool emitSelectionChanged(false);
switch (e->key()) switch (e->key()) {
{
case Key_Escape: case Key_Escape:
selectAll(false); selectAll(false);
emitSelectionChanged=true; emitSelectionChanged=true;
@ -1603,120 +1611,178 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
case Key_Space: case Key_Space:
//toggle selection of current item //toggle selection of current item
if (d->selectedBySimpleMove) if (d->selectedBySimpleMove) {
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
}
item->setSelected(!item->isSelected()); item->setSelected(!item->isSelected());
emitSelectionChanged=true; emitSelectionChanged=true;
break; break;
case Key_Insert: case Key_Insert:
//toggle selection of current item and move to the next item //toggle selection of current item and move to the next item
if (d->selectedBySimpleMove) if (d->selectedBySimpleMove) {
{
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
if (!item->isSelected()) item->setSelected(true); if (!item->isSelected()) item->setSelected(true);
} }
else else {
{
item->setSelected(!item->isSelected()); item->setSelected(!item->isSelected());
}; }
nextItem=item->itemBelow(); nextItem=item->itemBelow();
if (nextItem) if (nextItem) {
{
repaintItem2=nextItem; repaintItem2=nextItem;
visItem=nextItem; visItem=nextItem;
setCurrentItem(nextItem); setCurrentItem(nextItem);
}; }
d->selectionDirection=1; d->selectionDirection=1;
emitSelectionChanged=true; emitSelectionChanged=true;
break; break;
case Key_Down: case Key_Down:
nextItem=item->itemBelow(); nextItem=item->itemBelow();
//toggle selection of current item and move to the next item if (shiftOrCtrl) {
if (shiftOrCtrl)
{
d->selectionDirection=1; d->selectionDirection=1;
if (d->selectedBySimpleMove)
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
else if (!d->initialFileManagerItem) {
{ d->initialFileManagerItem = item;
if (oldSelectionDirection!=-1) item->setSelected(true);
{ if (nextItem) {
item->setSelected(!item->isSelected()); nextItem->setSelected(true);
}
emitSelectionChanged=true; emitSelectionChanged=true;
}; d->selectionRegion=1;
};
} }
else if ((d->selectedBySimpleMove) && (nextItem)) else {
{ if (item == d->initialFileManagerItem) {
item->setSelected(true);
if (nextItem) {
nextItem->setSelected(true);
}
emitSelectionChanged=true;
d->selectionRegion=1;
}
else {
if (d->selectionRegion == 1) {
if (nextItem) {
nextItem->setSelected(true);
}
emitSelectionChanged=true;
}
else if (d->selectionRegion == -1) {
item->setSelected(false); item->setSelected(false);
emitSelectionChanged=true; emitSelectionChanged=true;
}; }
}
}
}
else if ((d->selectedBySimpleMove) && (nextItem)) {
item->setSelected(false);
emitSelectionChanged=true;
}
if (nextItem) if (nextItem) {
{ if (d->selectedBySimpleMove) {
if (d->selectedBySimpleMove)
nextItem->setSelected(true); nextItem->setSelected(true);
}
repaintItem2=nextItem; repaintItem2=nextItem;
visItem=nextItem; visItem=nextItem;
setCurrentItem(nextItem); setCurrentItem(nextItem);
}; }
break; break;
case Key_Up: case Key_Up:
nextItem=item->itemAbove(); nextItem=item->itemAbove();
if (shiftOrCtrl) {
d->selectionDirection=-1; d->selectionDirection=-1;
//move to the prev. item and toggle selection of this one
// => No, can't select the last item, with this. For symmetry, let's
// toggle selection and THEN move up, just like we do in down (David)
if (shiftOrCtrl)
{
if (d->selectedBySimpleMove)
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
else if (!d->initialFileManagerItem) {
{ d->initialFileManagerItem = item;
if (oldSelectionDirection!=1) item->setSelected(true);
{ if (nextItem) {
item->setSelected(!item->isSelected()); nextItem->setSelected(true);
}
emitSelectionChanged=true; emitSelectionChanged=true;
}; d->selectionRegion=-1;
}
else {
if (item == d->initialFileManagerItem) {
item->setSelected(true);
if (nextItem) {
nextItem->setSelected(true);
} }
emitSelectionChanged=true;
d->selectionRegion=-1;
} }
else if ((d->selectedBySimpleMove) && (nextItem)) else {
{ if (d->selectionRegion == -1) {
if (nextItem) {
nextItem->setSelected(true);
}
emitSelectionChanged=true;
}
else if (d->selectionRegion == 1) {
item->setSelected(false); item->setSelected(false);
emitSelectionChanged=true; emitSelectionChanged=true;
}; }
}
}
}
else if ((d->selectedBySimpleMove) && (nextItem)) {
item->setSelected(false);
emitSelectionChanged=true;
}
if (nextItem) if (nextItem) {
{ if (d->selectedBySimpleMove) {
if (d->selectedBySimpleMove)
nextItem->setSelected(true); nextItem->setSelected(true);
}
repaintItem2=nextItem; repaintItem2=nextItem;
visItem=nextItem; visItem=nextItem;
setCurrentItem(nextItem); setCurrentItem(nextItem);
}; }
break; break;
case Key_End: case Key_End:
//move to the last item and toggle selection of all items inbetween // move to the last item and toggle selection of all items in-between
nextItem=item; nextItem=item;
if (d->selectedBySimpleMove) if (d->selectedBySimpleMove) {
item->setSelected(false); item->setSelected(false);
if (shiftOrCtrl) }
if (shiftOrCtrl) {
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
}
while(nextItem) while (nextItem) {
{ if (shiftOrCtrl) {
if (shiftOrCtrl) if (!d->initialFileManagerItem) {
nextItem->setSelected(!nextItem->isSelected()); d->initialFileManagerItem = nextItem;
if (!nextItem->itemBelow()) nextItem->setSelected(true);
{ emitSelectionChanged=true;
if (d->selectedBySimpleMove) d->selectionRegion=1;
}
else {
if (nextItem == d->initialFileManagerItem) {
nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=1;
}
else {
if (d->selectionRegion == 1) {
nextItem->setSelected(true); nextItem->setSelected(true);
emitSelectionChanged=true;
}
else if (d->selectionRegion == -1) {
nextItem->setSelected(false);
emitSelectionChanged=true;
}
}
}
}
if (!nextItem->itemBelow()) {
if (d->selectedBySimpleMove) {
nextItem->setSelected(true);
}
repaintItem2=nextItem; repaintItem2=nextItem;
visItem=nextItem; visItem=nextItem;
setCurrentItem(nextItem); setCurrentItem(nextItem);
@ -1727,55 +1793,105 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
break; break;
case Key_Home: case Key_Home:
// move to the first item and toggle selection of all items inbetween // move to the first item and toggle selection of all items in-between
nextItem = firstChild(); nextItem=item;
visItem = nextItem; if (d->selectedBySimpleMove) {
repaintItem2 = visItem;
if (d->selectedBySimpleMove)
item->setSelected(false); item->setSelected(false);
if (shiftOrCtrl) }
{ if (shiftOrCtrl) {
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
}
while ( nextItem != item ) while (nextItem) {
{ if (shiftOrCtrl) {
nextItem->setSelected( !nextItem->isSelected() ); if (!d->initialFileManagerItem) {
nextItem = nextItem->itemBelow(); d->initialFileManagerItem = nextItem;
nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=-1;
} }
item->setSelected( !item->isSelected() ); else {
if (nextItem == d->initialFileManagerItem) {
nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=-1;
}
else {
if (d->selectionRegion == -1) {
nextItem->setSelected(true);
emitSelectionChanged=true;
}
else if (d->selectionRegion == 1) {
nextItem->setSelected(false);
emitSelectionChanged=true;
}
}
}
}
if (!nextItem->itemAbove()) {
if (d->selectedBySimpleMove) {
nextItem->setSelected(true);
}
repaintItem2=nextItem;
visItem=nextItem;
setCurrentItem(nextItem);
}
nextItem=nextItem->itemAbove();
} }
setCurrentItem( firstChild() );
emitSelectionChanged=true; emitSelectionChanged=true;
break; break;
case Key_Next: case Key_Next:
items=visibleHeight()/item->height(); items=visibleHeight()/item->height();
nextItem=item; nextItem=item;
if (d->selectedBySimpleMove) if (d->selectedBySimpleMove) {
item->setSelected(false); item->setSelected(false);
if (shiftOrCtrl) }
{ if (shiftOrCtrl) {
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
d->selectionDirection=1; d->selectionDirection=1;
}; }
for (int i=0; i<items; i++)
{
if (shiftOrCtrl)
nextItem->setSelected(!nextItem->isSelected());
//the end
if ((i==items-1) || (!nextItem->itemBelow()))
{ for (int i=0; i<items; i++) {
if (shiftOrCtrl) if (shiftOrCtrl) {
nextItem->setSelected(!nextItem->isSelected()); if (!d->initialFileManagerItem) {
if (d->selectedBySimpleMove) d->initialFileManagerItem = nextItem;
nextItem->setSelected(true); nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=1;
}
else {
if (nextItem == d->initialFileManagerItem) {
nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=1;
}
else {
if (d->selectionRegion == 1) {
nextItem->setSelected(true);
emitSelectionChanged=true;
}
else if (d->selectionRegion == -1) {
if (i==items-1) {
nextItem->setSelected(true);
}
else {
nextItem->setSelected(false);
}
emitSelectionChanged=true;
}
}
}
}
// last item
if ((i==items-1) || (!nextItem->itemBelow())) {
if (d->selectedBySimpleMove) {
nextItem->setSelected(true);
}
ensureItemVisible(nextItem); ensureItemVisible(nextItem);
setCurrentItem(nextItem); setCurrentItem(nextItem);
update(); update();
if ((shiftOrCtrl) || (d->selectedBySimpleMove)) if ((shiftOrCtrl) || (d->selectedBySimpleMove)) {
{
emit selectionChanged(); emit selectionChanged();
} }
return; return;
@ -1787,29 +1903,54 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
case Key_Prior: case Key_Prior:
items=visibleHeight()/item->height(); items=visibleHeight()/item->height();
nextItem=item; nextItem=item;
if (d->selectedBySimpleMove) if (d->selectedBySimpleMove) {
item->setSelected(false); item->setSelected(false);
if (shiftOrCtrl) }
{ if (shiftOrCtrl) {
d->selectionDirection=-1; d->selectionDirection=-1;
d->selectedBySimpleMove=false; d->selectedBySimpleMove=false;
}; }
for (int i=0; i<items; i++)
{
if ((nextItem!=item) &&(shiftOrCtrl))
nextItem->setSelected(!nextItem->isSelected());
//the end
if ((i==items-1) || (!nextItem->itemAbove()))
{ for (int i=0; i<items; i++) {
if (d->selectedBySimpleMove) if (shiftOrCtrl) {
if (!d->initialFileManagerItem) {
d->initialFileManagerItem = nextItem;
nextItem->setSelected(true); nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=-1;
}
else {
if (nextItem == d->initialFileManagerItem) {
nextItem->setSelected(true);
emitSelectionChanged=true;
d->selectionRegion=-1;
}
else {
if (d->selectionRegion == -1) {
nextItem->setSelected(true);
emitSelectionChanged=true;
}
else if (d->selectionRegion == 1) {
if (i==items-1) {
nextItem->setSelected(true);
}
else {
nextItem->setSelected(false);
}
emitSelectionChanged=true;
}
}
}
}
// last item
if ((i==items-1) || (!nextItem->itemAbove())) {
if (d->selectedBySimpleMove) {
nextItem->setSelected(true);
}
ensureItemVisible(nextItem); ensureItemVisible(nextItem);
setCurrentItem(nextItem); setCurrentItem(nextItem);
update(); update();
if ((shiftOrCtrl) || (d->selectedBySimpleMove)) if ((shiftOrCtrl) || (d->selectedBySimpleMove)) {
{
emit selectionChanged(); emit selectionChanged();
} }
return; return;
@ -1819,59 +1960,70 @@ void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e)
break; break;
case Key_Minus: case Key_Minus:
if ( item->isOpen() ) if ( item->isOpen() ) {
setOpen( item, false ); setOpen( item, false );
}
break; break;
case Key_Plus: case Key_Plus:
if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) {
setOpen( item, true ); setOpen( item, true );
}
break; break;
default: default:
bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
&& (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); && (e->key()!=Key_Meta) && (e->key()!=Key_Alt));
bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected());
if (realKey && selectCurrentItem) if (realKey && selectCurrentItem) {
item->setSelected(false); item->setSelected(false);
}
//this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX)
TQListView::SelectionMode oldSelectionMode = selectionMode(); TQListView::SelectionMode oldSelectionMode = selectionMode();
setSelectionMode (TQListView::Multi); setSelectionMode (TQListView::Multi);
TQListView::keyPressEvent (e); TQListView::keyPressEvent (e);
setSelectionMode (oldSelectionMode); setSelectionMode (oldSelectionMode);
if (realKey && selectCurrentItem) if (realKey && selectCurrentItem) {
{
currentItem()->setSelected(true); currentItem()->setSelected(true);
emitSelectionChanged=true; emitSelectionChanged=true;
} }
repaintItem2=currentItem(); repaintItem2=currentItem();
if (realKey) if (realKey) {
visItem=currentItem(); visItem=currentItem();
}
break; break;
} }
if (visItem) if (visItem) {
ensureItemVisible(visItem); ensureItemVisible(visItem);
}
TQRect ir; TQRect ir;
if (repaintItem1) if (repaintItem1) {
ir = ir.unite( itemRect(repaintItem1) ); ir = ir.unite( itemRect(repaintItem1) );
if (repaintItem2) }
if (repaintItem2) {
ir = ir.unite( itemRect(repaintItem2) ); ir = ir.unite( itemRect(repaintItem2) );
}
if ( !ir.isEmpty() ) if ( !ir.isEmpty() ) {
{ // rectangle to be repainted // rectangle to be repainted
if ( ir.x() < 0 ) if ( ir.x() < 0 ) {
ir.moveBy( -ir.x(), 0 ); ir.moveBy( -ir.x(), 0 );
}
viewport()->repaint( ir, false ); viewport()->repaint( ir, false );
} }
/*if (repaintItem1) /*if (repaintItem1) {
repaintItem1->repaint(); repaintItem1->repaint();
if (repaintItem2) }
repaintItem2->repaint();*/ if (repaintItem2) {
repaintItem2->repaint();
}*/
update(); update();
if (emitSelectionChanged) if (emitSelectionChanged) {
emit selectionChanged(); emit selectionChanged();
} }
}
void TDEListView::setSelectionModeExt (SelectionModeExt mode) void TDEListView::setSelectionModeExt (SelectionModeExt mode)
{ {

Loading…
Cancel
Save