void DOMTreeView::slotAddTextDlg() { DOMListViewItem *item = static_cast<DOMListViewItem *>(m_listView->currentItem()); if (!item) return; QString text; SignalReceiver addBefore; { TextEditDialog dlg(this, "TextEditDialog", true); connect(dlg.insBeforeBtn, SIGNAL(clicked()), &addBefore, SLOT(slot())); if (dlg.exec() != QDialog::Accepted) return; text = dlg.textPane->text(); } DOM::Node curNode = item->node(); try { DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; DOM::Node after = addBefore() ? curNode : 0; DOM::Node newNode = curNode.ownerDocument().createTextNode(text); ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); mainWindow()->executeAndAddCommand(cmd); if (cmd->isValid()) activateNode(newNode); } catch (DOM::DOMException &ex) { mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); } }
void DOMTreeView::slotAddElementDlg() { DOMListViewItem *item = static_cast<DOMListViewItem *>(m_listView->currentItem()); if (!item) return; QString qname; QString namespc; SignalReceiver addBefore; { ElementEditDialog dlg(this); dlg.setModal(true); connect(dlg.button(KDialog::User2), SIGNAL(clicked()), &addBefore, SLOT(slot())); // ### activate when namespaces are supported dlg.elemNamespace->setEnabled(false); if (dlg.exec() != QDialog::Accepted) return; qname = dlg.elemName->text(); namespc = dlg.elemNamespace->currentText(); } DOM::Node curNode = item->node(); try { DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; DOM::Node after = addBefore() ? curNode : 0; // ### take namespace into account DOM::Node newNode = curNode.ownerDocument().createElement(qname); ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); mainWindow()->executeAndAddCommand(cmd); if (cmd->isValid()) activateNode(newNode); } catch (DOM::DOMException &ex) { mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); } }