38 #include "templatemanagementdialog.h"
40 #include <tqstringlist.h>
43 #include <kpushbutton.h>
44 #include <kinputdialog.h>
45 #include <tdelocale.h>
46 #include <tdemessagebox.h>
48 TemplateManagementDialog::TemplateManagementDialog(TQWidget *parent,
const TQStringList &templates )
49 :KDialogBase( parent,
"template_management_dialog", true,
50 i18n(
"Manage Templates"), Ok|Cancel, Ok, true , i18n(
"Apply Template")),
51 m_templates( templates ), m_newTemplate( TQString() ), m_changed( false )
53 m_base =
new TemplateManagementDialog_base(
this,
"template_management_dialog_base" );
54 setMainWidget( m_base );
55 connect( m_base->m_buttonAdd, TQ_SIGNAL( clicked() ),
56 TQ_SLOT( slotAddTemplate() ) );
57 connect( m_base->m_buttonDelete, TQ_SIGNAL( clicked() ),
58 TQ_SLOT( slotDeleteTemplate() ) );
59 m_base->m_listBox->insertStringList( m_templates );
60 connect( m_base->m_listBox, TQ_SIGNAL( selectionChanged( TQListBoxItem * ) ),
61 TQ_SLOT( slotUpdateDeleteButton( TQListBoxItem * ) ) );
62 connect( m_base->m_buttonApply, TQ_SIGNAL( clicked() ),
63 TQ_SLOT( slotApplyTemplate() ) );
67 void TemplateManagementDialog::slotAddTemplate()
70 bool duplicate =
false;
71 const TQString newTemplate = KInputDialog::getText( i18n(
"Template Name"),
72 i18n(
"Please enter a name for the new template:"),
73 i18n(
"New Template"), &ok );
74 if ( newTemplate.isEmpty() || !ok )
return;
75 if ( m_templates.find( newTemplate) != m_templates.end() ) {
76 int rc = KMessageBox::warningContinueCancel(
this, i18n(
"A template with that name already exists, do you want to overwrite it?."), i18n(
"Duplicate Template Name"), i18n(
"Overwrite"));
77 if ( rc == KMessageBox::Cancel ) {
78 TQTimer::singleShot(0,
this, TQ_SLOT( slotAddTemplate() ) );
84 m_templates.append( newTemplate );
85 m_base->m_listBox->clear();
86 m_base->m_listBox->insertStringList( m_templates );
88 m_newTemplate = newTemplate;
92 m_base->m_buttonApply->setEnabled(
false );
94 m_base->m_buttonAdd->setEnabled(
false );
97 void TemplateManagementDialog::slotDeleteTemplate()
99 TQListBoxItem *
const item = m_base->m_listBox->selectedItem();
101 unsigned int current = m_base->m_listBox->index(item);
102 m_templates.remove( item->text() );
103 m_base->m_listBox->removeItem( m_base->m_listBox->currentItem() );
105 m_base->m_listBox->setSelected(TQMAX(current -1, 0),
true);
108 void TemplateManagementDialog::slotUpdateDeleteButton( TQListBoxItem *item )
110 m_base->m_buttonDelete->setEnabled( item != 0 );
113 void TemplateManagementDialog::slotApplyTemplate()
116 m_base->m_buttonAdd->setEnabled(
false );
117 const TQString &cur = m_base->m_listBox->currentText();
118 if ( !cur.isEmpty() && cur != m_newTemplate )
119 emit loadTemplate( cur );
122 void TemplateManagementDialog::slotOk()
125 if ( !m_newTemplate.isEmpty() )
126 emit saveTemplate( m_newTemplate );
128 emit templatesChanged( m_templates );
129 KDialogBase::slotOk();
133 #include "templatemanagementdialog.moc"