3 #include <kparts/partmanager.h>
4 #include <kparts/mainwindow.h>
6 #include <QtGui/QSplitter>
7 #include <QtCore/QFile>
8 #include <QtCore/QTextStream>
9 #include <QtGui/QTextEdit>
11 #include <kaboutdata.h>
12 #include <kapplication.h>
15 #include <kactioncollection.h>
17 #include <kstatusbar.h>
18 #include <kstandarddirs.h>
19 #include <kpluginfactory.h>
21 K_PLUGIN_FACTORY(NotepadFactory
, registerPlugin
<NotepadPart
>();)
22 K_EXPORT_PLUGIN(NotepadFactory("notepadpart"))
24 NotepadPart::NotepadPart( QWidget
* parentWidget
,
27 : KParts::ReadWritePart( parent
)
29 setComponentData(NotepadFactory::componentData(), false);
31 m_edit
= new QTextEdit( parentWidget
);
32 m_edit
->setPlainText( "NotepadPart's multiline edit" );
35 KAction
* searchReplace
= new KAction( "Search and replace", this );
36 actionCollection()->addAction( "searchreplace", searchReplace
);
37 connect(searchReplace
, SIGNAL(triggered()), this, SLOT(slotSearchReplace()));
39 // KXMLGUIClient looks in the "data" resource for the .rc files
40 // This line is for test programs only!
41 componentData().dirs()->addResourceDir( "data", KDESRCDIR
);
42 setXMLFile( "notepadpart.rc" );
46 // Always write this as the last line of your constructor
50 NotepadPart::~NotepadPart()
54 void NotepadPart::setReadWrite( bool rw
)
56 m_edit
->setReadOnly( !rw
);
58 connect( m_edit
, SIGNAL( textChanged() ), this, SLOT( setModified() ) );
60 disconnect( m_edit
, SIGNAL( textChanged() ), this, SLOT( setModified() ) );
62 ReadWritePart::setReadWrite( rw
);
65 KAboutData
* NotepadPart::createAboutData()
67 return new KAboutData( "notepadpart", 0, ki18n( "Notepad" ), "2.0" );
70 bool NotepadPart::openFile()
72 kDebug() << "NotepadPart: opening " << localFilePath();
73 QFile
f(localFilePath());
75 if ( f
.open(QIODevice::ReadOnly
) ) {
77 t
.setCodec( "UTF-8" );
81 m_edit
->setPlainText(s
);
83 emit
setStatusBarText( url().prettyUrl() );
88 bool NotepadPart::saveFile()
92 QFile
f(localFilePath());
94 if ( f
.open(QIODevice::WriteOnly
) ) {
96 t
.setCodec( "UTF-8" );
97 t
<< m_edit
->toPlainText();
104 void NotepadPart::slotSearchReplace()
106 // What's this ? (David)
108 QValueList<KParts::XMLGUIServant *> plugins = KParts::Plugin::pluginServants( this );
109 QValueList<KParts::XMLGUIServant *>::ConstIterator it = plugins.begin();
110 QValueList<KParts::XMLGUIServant *>::ConstIterator end = plugins.end();
111 for (; it != end; ++it )
112 factory()->removeServant( *it );
116 #include "notepad.moc"