diff -r 053b8645e3e9 -r 67cfa6e6b863 mainwindow.cpp --- a/mainwindow.cpp Wed Oct 18 10:45:00 2006 +0000 +++ b/mainwindow.cpp Tue Oct 24 15:36:38 2006 +0000 @@ -70,6 +70,9 @@ move (settings.value( "/mainwindow/geometry/pos", QPoint(300,100)).toPoint()); + // Sometimes we may need to remember old selections + prevSelection=""; + // Create unique temporary directory bool ok; tmpVymDir=makeUniqueDir (ok,"/tmp/vym-XXXXXX"); @@ -480,16 +483,16 @@ a->setShortcut (Qt::ALT + Qt::Key_Insert ); a->setShortcutContext (Qt::WindowShortcut); addAction (a); - connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchHere() ) ); + connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) ); a->setEnabled (false); actionListBranches.append(a); - actionEditAddBranchHere=a; + actionEditAddBranchBefore=a; a = new QAction(tr( "Add branch (insert)" ),this); a->setStatusTip ( tr( "Add a branch by inserting and making selection its child" )); a->setShortcut ( Qt::ALT + Qt::Key_A ); a->setShortcutContext (Qt::WindowShortcut); addAction (a); - connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchHere() ) ); + connect( a, SIGNAL( triggered() ), this, SLOT( editNewBranchBefore() ) ); actionListBranches.append(a); // Add branch above @@ -1437,7 +1440,7 @@ branchAddContextMenu =branchContextMenu->addMenu (tr("Add")); branchAddContextMenu->addAction (actionEditPaste ); branchAddContextMenu->addAction ( actionEditAddBranch ); - branchAddContextMenu->addAction ( actionEditAddBranchHere ); + branchAddContextMenu->addAction ( actionEditAddBranchBefore ); branchAddContextMenu->addAction ( actionEditAddBranchAbove); branchAddContextMenu->addAction ( actionEditAddBranchBelow ); branchAddContextMenu->addSeparator(); @@ -2607,24 +2610,33 @@ currentMapEditor()->editFATE2URL(); } +void Main::editHeadingFinished() +{ + // only called from editHeading(), so there is a currentME + MapEditor *me=currentMapEditor(); + +#if defined(Q_OS_MACX) +#else + me->setHeading(lineedit->text()); + + lineedit->releaseKeyboard(); + lineedit->hide(); + setFocus(); +#endif + if (!prevSelection.isEmpty()) me->select(prevSelection); + prevSelection=""; +} + void Main::editHeading() { - if (lineedit->isVisible()) + if (currentMapEditor()) { - if (currentMapEditor()) - { - MapEditor *me=currentMapEditor(); - QString oldSel=me->getSelectString(); - if (me->select (editSel)) - me->setHeading(lineedit->text()); - me->select (oldSel); - } - lineedit->releaseKeyboard(); - lineedit->hide(); - setFocus(); - } else - { - if (currentMapEditor()) + MapEditor *me=currentMapEditor(); + QString oldSel=me->getSelectString(); + + if (lineedit->isVisible()) + editHeadingFinished(); + else { bool ok; QPoint p; @@ -2637,30 +2649,30 @@ QDialog *d =new QDialog(NULL); QLineEdit *le=new QLineEdit (d); d->setWindowFlags (Qt::FramelessWindowHint); - d->setGeometry(p.x(),p.y(),200,25); - le->resize (d->size()); + d->setGeometry(p.x(),p.y(),230,25); + le->resize (d->width()-10,d->height()); le->setText (s); le->selectAll(); connect (le, SIGNAL (returnPressed()), d, SLOT (accept())); d->activateWindow(); d->exec(); currentMapEditor()->setHeading (le->text()); + delete (le); + delete (d); + editHeadingFinished(); #else p = currentMapEditor()->mapTo(this, currentMapEditor()->worldMatrix().map( p)); - lineedit->setGeometry(p.x(),p.y(),200,25); + lineedit->setGeometry(p.x(),p.y(),230,25); lineedit->setText(s); lineedit->setCursorPosition(1); lineedit->selectAll(); lineedit->show(); lineedit->grabKeyboard(); lineedit->setFocus(); - - editSel=currentMapEditor()->getSelectString(); #endif - } } - } + } // currentMapEditor() } void Main::openVymLinks(const QStringList &vl) @@ -2764,34 +2776,95 @@ void Main::editUnScrollAll() { if (currentMapEditor()) + currentMapEditor()->unScrollAll(); +} + +void Main::editNewBranch() +{ + MapEditor *me=currentMapEditor(); + if (!lineedit->isVisible() && me) { - currentMapEditor()->unScrollAll(); + BranchObj *bo=(BranchObj*)me->getSelection(); + BranchObj *newbo=me->addNewBranch(0); + + if (newbo) + me->select (newbo->getSelectString()); + else + return; + + if (actionSettingsAutoEdit->isOn()) + { + if (!actionSettingsAutoSelectHeading->isOn()) + prevSelection=bo->getSelectString(); + editHeading(); + } } } -void Main::editNewBranch() +void Main::editNewBranchBefore() { - - if (!lineedit->isVisible() && currentMapEditor()) - currentMapEditor()->addNewBranch(0); -} - -void Main::editNewBranchHere() -{ - if (currentMapEditor()) - currentMapEditor()->addNewBranchHere(); + MapEditor *me=currentMapEditor(); + if (!lineedit->isVisible() && me) + { + BranchObj *bo=(BranchObj*)me->getSelection(); + BranchObj *newbo=me->addNewBranchBefore(); + + if (newbo) + me->select (newbo->getSelectString()); + else + return; + + if (actionSettingsAutoEdit->isOn()) + { + if (!actionSettingsAutoSelectHeading->isOn()) + prevSelection=bo->getSelectString(); + editHeading(); + } + } } void Main::editNewBranchAbove() { - if (currentMapEditor()) - currentMapEditor()->addNewBranch(-1); + MapEditor *me=currentMapEditor(); + if (!lineedit->isVisible() && me) + { + BranchObj *bo=(BranchObj*)me->getSelection(); + BranchObj *newbo=me->addNewBranch (-1); + + if (newbo) + me->select (newbo->getSelectString()); + else + return; + + if (actionSettingsAutoEdit->isOn()) + { + if (!actionSettingsAutoSelectHeading->isOn()) + prevSelection=bo->getSelectString(); + editHeading(); + } + } } void Main::editNewBranchBelow() { - if (currentMapEditor()) - currentMapEditor()->addNewBranch(1); + MapEditor *me=currentMapEditor(); + if (!lineedit->isVisible() && me) + { + BranchObj *bo=(BranchObj*)me->getSelection(); + BranchObj *newbo=me->addNewBranch (1); + + if (newbo) + me->select (newbo->getSelectString()); + else + return; + + if (actionSettingsAutoEdit->isOn()) + { + if (!actionSettingsAutoSelectHeading->isOn()) + prevSelection=bo->getSelectString(); + editHeading(); + } + } } void Main::editImportAdd()