14 #include "snippetdlg.h"
17 #include <klineedit.h>
18 #include <tdelocale.h>
22 #include <kpushbutton.h>
23 #include <ktextedit.h>
24 #include "kkeybutton.h"
25 #include "tdeactioncollection.h"
26 #include "tdemessagebox.h"
35 SnippetDlg::SnippetDlg( TDEActionCollection* ac, TQWidget* parent,
const char* name,
bool modal, WFlags fl )
36 : SnippetDlgBase( parent, name, modal, fl ), actionCollection( ac )
39 setName(
"SnippetDlg" );
41 textLabel3 =
new TQLabel(
this,
"textLabel3" );
42 keyButton =
new KKeyButton(
this );
43 connect( keyButton, TQ_SIGNAL( capturedShortcut(
const TDEShortcut& ) ),
44 this, TQ_SLOT( slotCapturedShortcut(
const TDEShortcut& ) ) );
46 btnAdd->setEnabled(
false );
47 connect( snippetName, TQ_SIGNAL(textChanged(
const TQString &)),
48 this, TQ_SLOT(slotTextChanged(
const TQString &)) );
49 connect( snippetName, TQ_SIGNAL(returnPressed()),
50 this, TQ_SLOT(slotReturnPressed()) );
52 layout3->addWidget( textLabel3, 7, 0 );
53 layout3->addWidget( keyButton, 7, 1 );
56 setTabOrder( snippetText, keyButton );
57 setTabOrder( keyButton, btnAdd );
58 setTabOrder( btnAdd, btnCancel );
60 textLabel3->setBuddy( keyButton );
67 SnippetDlg::~SnippetDlg()
76 void SnippetDlg::languageChange()
78 textLabel3->setText( i18n(
"Sh&ortcut:" ) );
81 static bool shortcutIsValid(
const TDEActionCollection* actionCollection,
const TDEShortcut &sc )
83 TDEActionPtrList actions = actionCollection->actions();
84 TDEActionPtrList::Iterator it( actions.begin() );
85 for ( ; it != actions.end(); it++ ) {
86 if ( (*it)->shortcut() == sc )
return false;
91 void SnippetDlg::slotCapturedShortcut(
const TDEShortcut& sc )
94 if ( sc == keyButton->shortcut() )
return;
95 if ( sc.toString().isNull() ) {
97 keyButton->setShortcut( TDEShortcut::null(),
false );
99 if( !shortcutIsValid( actionCollection, sc ) ) {
100 TQString msg( i18n(
"The selected shortcut is already used, "
101 "please select a different one." ) );
102 KMessageBox::sorry(
this, msg );
104 keyButton->setShortcut( sc,
false );
109 void SnippetDlg::setShowShortcut(
bool show )
111 textLabel3->setShown( show );
112 keyButton->setShown( show );
115 void SnippetDlg::slotTextChanged(
const TQString &text )
117 btnAdd->setEnabled( !text.isEmpty() );
120 void SnippetDlg::slotReturnPressed()
122 if ( !snippetName->text().isEmpty() ) {
127 #include "snippetdlg.moc"