void Core::setupShourtcutTips(KXMLGUIClient * client) { QPtrList<KXMLGUIClient> clients; if (client != 0) clients.append(client); else clients = TopLevel::getInstance()->main()->guiFactory()->clients(); for( QPtrListIterator<KXMLGUIClient> it(clients); it.current(); ++it ) { KActionCollection *actionCollection = (*it)->actionCollection(); for (int i = 0; i < actionCollection->count(); i++) { KAction *action = actionCollection->action(i); QString tooltip = action->toolTip(); if (tooltip.isEmpty()) tooltip = action->text().remove('&'); else { int i = tooltip.findRev('('); if (i > 0) tooltip = tooltip.left(i).stripWhiteSpace(); } QString shortcut = action->shortcutText(); if (!shortcut.isEmpty()) tooltip += " (" + shortcut + ")"; action->setToolTip(tooltip); } } }
void MainWindow::initContextMenu() { m_contextMenu->clear(); //load helper actions (copied from kdetraystatus.cpp, with slight modification) //TODO: add a new function in m_defaultActionCollection to handle this? KActionCollection * helperActioncol = m_defaultActionCollection->helperActionCollection(); if ( helperActioncol->count() ) { for(size_t i=0; i<helperActioncol->count();i++) { helperActioncol->action(i)->plug(m_contextMenu); } m_contextMenu->insertSeparator(); } m_toggleDockingAction->plug(m_contextMenu); KAction* configureaction = m_defaultActionCollection->action( "configure" ); if(configureaction) configureaction->plug(m_contextMenu); KAction* helpAction = m_defaultActionCollection->action( "help" ); if(helpAction) helpAction->plug(m_contextMenu); }
void ActionConfigDialog::slotShortcutCaptured(const KShortcut &shortcut) { QString shortcutText = shortcut.toString(); QString shortcutText2; int pos = shortcutText.find(';'); if (pos != -1) { shortcutText2 = shortcutText.mid(pos + 1); shortcutText = shortcutText.left(pos); } QString s = shortcutText; s.replace('+', "\\+"); QRegExp shortcutRx("\\(" + s + "\\)|" + s + "$|" + s + ";"); s = shortcutText2; s.replace('+', "\\+"); QRegExp shortcutRx2("\\(" + s + "\\)|" + s + "$|" + s + ";"); QString global; //check for conflicting global shortcuts QMap<QString, QString>::Iterator it; for ( it = globalShortcuts.begin(); it != globalShortcuts.end(); ++it ) { if (it.data().contains(shortcutRx)) { global = it.key(); break; } if (!shortcutText2.isEmpty() && it.data().contains(shortcutRx2)) { shortcutText = shortcutText2; global = it.key(); break; } } if (global.isEmpty()) { QPtrList<KXMLGUIClient> clients = m_mainWindow->guiFactory()->clients(); for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it ) { KActionCollection *ac = (*it)->actionCollection(); for (uint i = 0; i < ac->count(); i++) { KAction *action = ac->action(i); if (action != currentAction && action->shortcut().toString().contains(shortcutRx)) { global = action->text(); break; } if (!shortcutText2.isEmpty() && action != currentAction && action->shortcut().toString().contains(shortcutRx)) { shortcutText = shortcutText2; global = action->text(); break; } } if (!global.isEmpty()) break; } } if (global.isEmpty()) { shortcutKeyButton->setText(shortcutText); buttonApply->setEnabled(true); selectedShortcut = shortcut; } else { global.replace('&',""); QString s = i18n("The '%1' key combination has already been allocated " "to the \"%2\" action.\n" "Please choose a unique key combination."). arg(shortcutText).arg(global); KMessageBox::sorry( this, s, i18n("Conflicting Shortcuts")); } }
ActionConfigDialog::ActionConfigDialog(const QDict<ToolbarEntry> &toolbarList, KMainWindow* parent, const char* name, bool modal, WFlags fl, const QString& defaultAction ) :ActionConfigDialogS( parent, name, modal, fl ) { m_mainWindow = parent; m_toolbarList = toolbarList; buttonOk->setIconSet(SmallIconSet("button_ok")); buttonCancel->setIconSet(SmallIconSet("button_cancel")); buttonApply->setIconSet(SmallIconSet("apply")); //buttonHelp->setIconSet(SmallIconSet("help")); currentAction = 0L; m_toolbarItem = 0L; connect(actionTreeView, SIGNAL(contextMenu(KListView *,QListViewItem *,const QPoint &)), SLOT(slotContextMenu(KListView *,QListViewItem *,const QPoint &))); connect(actionTreeView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotSelectionChanged(QListViewItem *))); connect(shortcutKeyButton, SIGNAL(capturedShortcut(const KShortcut &)), SLOT(slotShortcutCaptured(const KShortcut &))); connect(scriptPath, SIGNAL(activated(const QString&)), SLOT(slotTextChanged(const QString&))); connect(this, SIGNAL(addToolbar()), m_mainWindow, SLOT(slotAddToolbar())); connect(this, SIGNAL(removeToolbar(const QString&)), m_mainWindow, SLOT(slotRemoveToolbar(const QString&))); connect(this, SIGNAL(deleteUserAction(KAction*)), m_mainWindow, SLOT(slotDeleteAction(KAction*))); connect(this, SIGNAL(configureToolbars(const QString&)), m_mainWindow, SLOT(slotConfigureToolbars(const QString&))); //fill up the tree view with the toolbars and actions actionTreeView->setSorting(-1); allActionsItem = new KListViewItem(actionTreeView, i18n("All")); actionTreeView->insertItem(allActionsItem); QListViewItem *item, *oldItem = allActionsItem; KAction *action; QString toolbarName; QString toolbarId; ToolbarTabWidget *tb = ToolbarTabWidget::ref(); QRegExp r("\\&(?!\\&)"); KActionCollection *ac = m_mainWindow->actionCollection(); for (int i = 0; i < tb->count(); i++) { toolbarName = tb->label(i); toolbarName.replace(r, ""); item = new KListViewItem(actionTreeView, oldItem, i18n(toolbarName.utf8())); actionTreeView->insertItem(item); toolbarId = tb->id(i); QListViewItem *oldActionItem = 0L; 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") { action = ac->action(node.toElement().attribute("name")); if (action) { oldActionItem = new KListViewItem(item, oldActionItem, action->text().replace(r,""), action->shortcut().toString(), action->name()); oldActionItem->setPixmap(0, SmallIcon(action->icon()) ); } } node = node.nextSibling(); } if (tb->label(tb->currentPageIndex()).replace(r, "") == toolbarName) { item->setOpen(true); if (item->firstChild()) { if (defaultAction.isEmpty()) { actionTreeView->setCurrentItem(item->firstChild()); } else { QListViewItem *actionItem = item->firstChild(); while (actionItem && actionItem->depth() > 0) { if (actionItem->text(0) == defaultAction || actionItem->text(0) == defaultAction + "...") { actionTreeView->setCurrentItem(actionItem); break; } actionItem = actionItem->nextSibling(); } } } } } oldItem = item; } uint acCount = ac->count(); for (uint i = 0; i < acCount; i++) { action = ac->action(i); item = new KListViewItem(allActionsItem, action->text().replace(r, ""), action->shortcut().toString(), action->name()); item->setPixmap(0, SmallIcon(action->icon()) ); } allActionsItem->sortChildItems(0, true); treeMenu = new KPopupMenu(actionTreeView); treeMenu->insertItem(i18n("&Add New Toolbar"), this, SLOT(slotAddToolbar())); treeMenu->insertItem(i18n("&Remove Toolbar"), this, SLOT(slotRemoveToolbar())); treeMenu->insertItem(i18n("&Edit Toolbar"), this, SLOT(slotEditToolbar())); globalShortcuts = KGlobal::config()->entryMap( "Global Shortcuts" ); }
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); } }