kword

KWCreateBookmarkDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Montel Laurent <lmontel@mandrakesoft.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tdelocale.h>
21#include "KWDocument.h"
22#include <tqvbox.h>
23#include <tqlayout.h>
24#include <tqlineedit.h>
25#include <tqpushbutton.h>
26#include <tqlistbox.h>
27#include <tdemessagebox.h>
28#include "KWCommand.h"
29#include "KWCreateBookmarkDia.h"
30#include "KWCreateBookmarkDiaBase.h"
31#include "KWFrame.h"
32#include "KWFrameSet.h"
33
34KWCreateBookmarkDia::KWCreateBookmarkDia( const TQStringList & _list, TQWidget *parent, const char *name )
35 : KDialogBase( parent, name , true, "", Ok|Cancel, Ok, true )
36{
37 setCaption( i18n("Create New Bookmark") );
38 listBookMark = _list;
39 init();
40}
41
42KWCreateBookmarkDia::KWCreateBookmarkDia( const TQStringList & _list, const TQString & _name, TQWidget *parent, const char *name )
43 : KDialogBase( parent, name , true, "", Ok|Cancel, Ok, true )
44{
45 setCaption( i18n("Rename Bookmark") );
46 listBookMark = _list;
47 init();
48 m_bookmarkName->setText(_name);
49}
50
51void KWCreateBookmarkDia::init()
52{
53 KWCreateBookmarkDiaBase *dia = new KWCreateBookmarkDiaBase( this );
54 m_bookmarkName = dia->m_bookmarkName;
55 enableButtonOK( false );
56 connect( m_bookmarkName, TQ_SIGNAL(textChanged ( const TQString & )), this, TQ_SLOT(nameChanged( const TQString &)));
57 setMainWidget( dia );
58 m_bookmarkName->setFocus();
59}
60
61void KWCreateBookmarkDia::slotOk()
62{
63 if ( listBookMark.findIndex(m_bookmarkName->text() ) != -1 )
64 {
65 KMessageBox::error(this, i18n("That name already exists, please choose another name."));
66 }
67 else
68 KDialogBase::slotOk();
69}
70
71TQString KWCreateBookmarkDia::bookmarkName()const
72{
73 return m_bookmarkName->text();
74}
75
76void KWCreateBookmarkDia::nameChanged( const TQString &text)
77{
78 enableButtonOK( !text.isEmpty() );
79}
80
81
82/* **************************** */
83KWSelectBookmarkDia::KWSelectBookmarkDia( const TQStringList & _list, KWDocument *_doc, TQWidget *parent, const char *name )
84 : KDialogBase( parent, name , true, "", Ok|Cancel, Ok, true )
85{
86 m_doc=_doc;
87 setCaption( i18n("Select Bookmark") );
88 TQWidget *page = new TQWidget( this );
89 setMainWidget(page);
90
91 TQGridLayout * grid = new TQGridLayout(page, 5, 2, KDialog::marginHint(), KDialog::spacingHint());
92 m_bookmarkList = new TQListBox( page );
93 grid->addMultiCellWidget(m_bookmarkList, 0, 4, 0, 0);
94 m_bookmarkList->insertStringList(_list);
95
96 connect(m_bookmarkList, TQ_SIGNAL( selectionChanged ()), this, TQ_SLOT(slotSelectionChanged()));
97 connect(m_bookmarkList, TQ_SIGNAL(doubleClicked ( TQListBoxItem * )), this, TQ_SLOT(slotOk()));
98 connect(m_bookmarkList, TQ_SIGNAL(returnPressed ( TQListBoxItem * )), this, TQ_SLOT(slotOk()));
99
100 m_pbRename = new TQPushButton( i18n("Rename Bookmark"), page );
101 grid->addWidget( m_pbRename, 0, 1);
102 connect( m_pbRename, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotRenameBookmark()));
103
104 m_pbDelete = new TQPushButton( i18n("Delete Bookmark"), page );
105 grid->addWidget( m_pbDelete, 1, 1);
106
107 connect( m_pbDelete, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotDeleteBookmark()));
108
109 m_bookmarkList->setFocus();
110 slotSelectionChanged();
111}
112
113void KWSelectBookmarkDia::slotRenameBookmark()
114{
115 TQString tmp =m_bookmarkList->currentText();
116 if ( tmp.isEmpty() )
117 return;
118 //all bookmark name
119 TQStringList lst =m_doc->listOfBookmarkName(0L);
120 lst.remove( tmp );
121 KWCreateBookmarkDia dia( lst, tmp, this, 0 );
122 if ( dia.exec() ) {
123 TQString newName = dia.bookmarkName();
124 KWRenameBookmarkCommand *cmd = new KWRenameBookmarkCommand( i18n("Rename Bookmark"), tmp, newName, m_doc);
125 m_doc->addCommand( cmd );
126 cmd->execute();
127 m_bookmarkList->changeItem ( newName, m_bookmarkList->currentItem() );
128 }
129}
130
131void KWSelectBookmarkDia::slotDeleteBookmark()
132{
133 TQString tmp =m_bookmarkList->currentText();
134 if ( !tmp.isEmpty())
135 {
136 m_doc->deleteBookmark(tmp);
137 m_bookmarkList->removeItem(m_bookmarkList->currentItem());
138 }
139}
140
141
142TQString KWSelectBookmarkDia::bookmarkSelected()const
143{
144 return m_bookmarkList->currentText();
145}
146
147void KWSelectBookmarkDia::slotSelectionChanged()
148{
149 bool state =!m_bookmarkList->currentText().isEmpty();
150 enableButtonOK( state );
151 m_pbRename->setEnabled( state);
152 m_pbDelete->setEnabled( state && m_doc->isReadWrite());
153}
154
155#include "KWCreateBookmarkDia.moc"