CustomActionDialog::CustomActionDialog(QWidget* parent, Qt::WFlags fl) : QDialog(parent, fl) { setWindowTitle(tr("MantidPlot") + " - " + tr("Add Custom Action")); itemsList = new QListWidget(); itemsList->setSelectionMode(QAbstractItemView::SingleSelection); itemsList->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); itemsList->setSpacing(2); QGroupBox *gb1 = new QGroupBox(); gb1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); QGridLayout *gl1 = new QGridLayout(gb1); gl1->addWidget(new QLabel(tr("Folder")), 0, 0); folderBox = new QLineEdit(); gl1->addWidget(folderBox, 0, 1); folderBtn = new QPushButton(tr("Choose &Folder")); gl1->addWidget(folderBtn, 0, 2); gl1->addWidget(new QLabel(tr("Script File")), 1, 0); fileBox = new QLineEdit(); gl1->addWidget(fileBox, 1, 1); fileBtn = new QPushButton(tr("Choose &Script")); gl1->addWidget(fileBtn, 1, 2); gl1->addWidget(new QLabel(tr("Icon")), 2, 0); iconBox = new QLineEdit(); gl1->addWidget(iconBox, 2, 1); iconBtn = new QPushButton(tr("Choose &Icon")); gl1->addWidget(iconBtn, 2, 2); gl1->addWidget(new QLabel(tr("Text")), 3, 0); textBox = new QLineEdit(); gl1->addWidget(textBox, 3, 1); gl1->addWidget(new QLabel(tr("Tool Tip Text")), 4, 0); toolTipBox = new QLineEdit(); gl1->addWidget(toolTipBox, 4, 1); gl1->addWidget(new QLabel(tr("Shortcut")), 5, 0); shortcutBox = new QLineEdit(); gl1->addWidget(shortcutBox, 5, 1); menuBtn = new QRadioButton(tr("&Menu")); gl1->addWidget(menuBtn, 6, 0); menuBox = new QComboBox(); gl1->addWidget(menuBox, 6, 1); toolBarBtn = new QRadioButton(tr("&Tool Bar")); toolBarBtn->setChecked(true); gl1->addWidget(toolBarBtn, 7, 0); toolBarBox = new QComboBox(); gl1->addWidget(toolBarBox, 7, 1); gl1->setRowStretch(8, 1); gl1->setColumnStretch(1, 10); QHBoxLayout * bottomButtons = new QHBoxLayout(); bottomButtons->addStretch(); buttonSave = new QPushButton(tr("&Save")); buttonSave->setAutoDefault( true ); bottomButtons->addWidget(buttonSave); buttonAdd = new QPushButton(tr("&Add")); buttonAdd->setAutoDefault( true ); bottomButtons->addWidget(buttonAdd); buttonRemove = new QPushButton(tr("&Remove")); buttonRemove->setAutoDefault(true); bottomButtons->addWidget(buttonRemove); buttonCancel = new QPushButton(tr("&Close")); buttonCancel->setAutoDefault( true ); bottomButtons->addWidget( buttonCancel ); QHBoxLayout *vl = new QHBoxLayout(); vl->addWidget(itemsList); vl->addWidget(gb1); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addLayout(vl); mainLayout->addLayout(bottomButtons); init(); QShortcut *accelRemove = new QShortcut(QKeySequence(Qt::Key_Delete), this); connect(accelRemove, SIGNAL(activated()), this, SLOT(removeAction())); connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveCurrentAction())); connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addAction())); connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeAction())); connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(iconBtn, SIGNAL(clicked()), this, SLOT(chooseIcon())); connect(fileBtn, SIGNAL(clicked()), this, SLOT(chooseFile())); connect(folderBtn, SIGNAL(clicked()), this, SLOT(chooseFolder())); connect(itemsList, SIGNAL(currentRowChanged(int)), this, SLOT(setCurrentAction(int))); }
void ActionConfigDialog::slotApply() { saveCurrentAction(); buttonApply->setEnabled(false); }
void ActionConfigDialog::accept() { if (buttonApply->isEnabled()) saveCurrentAction(); ActionConfigDialogS::accept(); }
void ActionConfigDialog::reject() { if (buttonApply->isEnabled() && KMessageBox::questionYesNo(this, i18n("Do you want to save the changes made to this action?"), QString::null, KStdGuiItem::save(), KStdGuiItem::discard()) == KMessageBox::Yes ) saveCurrentAction(); ActionConfigDialogS::reject(); }
void ActionConfigDialog::slotSelectionChanged(QListViewItem *item) { if (currentAction && currentAction->inherits("TagAction")) { if ( buttonApply->isEnabled() && KMessageBox::questionYesNo(this, i18n("Do you want to save the changes made to this action?"), QString::null, KStdGuiItem::save(), KStdGuiItem::discard()) == KMessageBox::Yes ) { saveCurrentAction(); } buttonApply->setEnabled(false); currentAction = 0L; } if (item && item->depth() > 0) { TagAction *action = 0L; KActionCollection *ac = m_mainWindow->actionCollection(); uint acCount = ac->count(); //find the corresponding action for (uint i = 0; i < acCount; i++) { KAction *a = ac->action(i); QString actionName = a->name(); if (a && actionName == item->text(2) && a->inherits("TagAction")) { action = static_cast<TagAction*>(a); actionProperties->setEnabled(true); deleteAction->setEnabled(true); break; } else { actionProperties->setEnabled(false); deleteAction->setEnabled(false); } } //if we found the action, load the action details if (action) { currentAction = action; QDomElement el = action->data(); if ( el.hasAttribute("icon") ) { QString s = el.attribute("icon"); if (!QFileInfo(s).exists()) s = QFileInfo(s).fileName(); actionIcon->setIcon(s); } QString actionText = el.attribute("text"); actionText.replace(QRegExp("\\&(?!\\&)"),""); lineText->setText(actionText); lineToolTip->setText( el.attribute("tooltip") ); selectedShortcut = action->shortcut(); QString shortcutText = action->shortcut().toString(); if (shortcutText.isEmpty()) { noShortcut->setChecked(true); shortcutKeyButton->setText(i18n("None")); } else { customShortcut->setChecked(true); shortcutKeyButton->setShortcut(action->shortcut(), false); shortcutKeyButton->setText(shortcutText); } //find the container toolbars of this action and add them to the container listbox toolbarListBox->clear(); int current = 0; int count = 0; ToolbarTabWidget *tb = ToolbarTabWidget::ref(); for (int i = 0; i < tb->count(); i++) { QString toolbarName = tb->label(i); QString toolbarId = tb->id(i); ToolbarEntry *p_toolbar = m_toolbarList[toolbarId]; if (p_toolbar) { QDomNode node = p_toolbar->guiClient->domDocument().firstChild().firstChild().firstChild(); while (!node.isNull()) { if (node.nodeName() == "Action" && node.toElement().attribute("name") == el.attribute("name")) { toolbarListBox->insertItem(toolbarName); if (item->parent()->text(0) == toolbarName) current = count; count++; } node = node.nextSibling(); } } } toolbarListBox->setCurrentItem(current); toolbarListBox->setSelected(current, true); toolbarListBox->sort(); //set the detailed settings pages to their defaults lineTag->clear(); lineClosingTag->clear(); useClosingTag->setChecked(false); useActionDialog->setChecked(false); scriptPath->setText(""); inputBox->setCurrentItem(0); outputBox->setCurrentItem(5); errorBox->setCurrentItem(5); textEdit->clear(); //set the detailed settings according to the type of the action QString type = el.attribute("type", "tag"); if (type == "tag") { QDomElement eltag = el.namedItem("tag").toElement(); lineTag->setText( eltag.text() ); useActionDialog->setChecked(eltag.attribute("useDialog","false") == "true"); eltag = el.namedItem("xtag").toElement(); lineClosingTag->setText( eltag.text() ); useClosingTag->setChecked( eltag.attribute("use","false") == "true" ); typeCombo->setCurrentItem(0); } else if (type == "script") { QDomElement elScript = el.namedItem("script").toElement(); scriptPath->setText( elScript.text() ); QString s; s = elScript.attribute("input","none"); if (s == "current") { inputBox->setCurrentItem(1); } else if (s == "selected") { inputBox->setCurrentItem(2); } else { inputBox->setCurrentItem(0); } s = elScript.attribute("output","none"); if (s == "cursor") { outputBox->setCurrentItem(1); } else if (s == "selection") { outputBox->setCurrentItem(2); } else if (s == "replace") { outputBox->setCurrentItem(3); } else if (s == "new") { outputBox->setCurrentItem(4); } else if (s == "message") { outputBox->setCurrentItem(5); } else { outputBox->setCurrentItem(0); } s = elScript.attribute("error","none"); if (s == "cursor") { errorBox->setCurrentItem(1); } else if (s == "selection") { errorBox->setCurrentItem(2); } else if (s == "replace") { errorBox->setCurrentItem(3); } else if (s == "new") { errorBox->setCurrentItem(4); } else if (s == "message") { errorBox->setCurrentItem(5); } else { errorBox->setCurrentItem(0); } typeCombo->setCurrentItem(1); } else if (type == "text") { textEdit->setText( el.namedItem("text").toElement().text() ); typeCombo->setCurrentItem(2); } buttonApply->setEnabled(false); } } else { actionProperties->setEnabled(false); deleteAction->setEnabled(false); } }