diff options
author | Darrell Anderson <humanreadable@yahoo.com> | 2013-03-02 15:57:34 -0600 |
---|---|---|
committer | Darrell Anderson <humanreadable@yahoo.com> | 2013-03-02 15:57:34 -0600 |
commit | 7c0b0c9dc9fcbe9c198925bdc7ee18ac6be49f4f (patch) | |
tree | c76702a7f6310fbe9d437e347535422e836e94e9 /tdeparts/tests/notepad.cpp | |
parent | a2a38be7600e2a2c2b49c66902d912ca036a2c0f (diff) | |
parent | 27bbee9a5f9dcda53d8eb23863ee670ad1360e41 (diff) | |
download | tdelibs-7c0b0c9dc9fcbe9c198925bdc7ee18ac6be49f4f.tar.gz tdelibs-7c0b0c9dc9fcbe9c198925bdc7ee18ac6be49f4f.zip |
Merge branch 'master' of http://scm.trinitydesktop.org/scm/git/tdelibs
Diffstat (limited to 'tdeparts/tests/notepad.cpp')
-rw-r--r-- | tdeparts/tests/notepad.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tdeparts/tests/notepad.cpp b/tdeparts/tests/notepad.cpp new file mode 100644 index 000000000..ad81b91b3 --- /dev/null +++ b/tdeparts/tests/notepad.cpp @@ -0,0 +1,101 @@ + +#include "notepad.h" +#include <tdeparts/partmanager.h> +#include <tdeparts/mainwindow.h> + +#include <tqsplitter.h> +#include <tqfile.h> +#include <tqtextstream.h> +#include <tqmultilineedit.h> + +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <kdebug.h> +#include <tdeaction.h> +#include <tdelocale.h> +#include <kstatusbar.h> +#include <kstandarddirs.h> + +NotepadPart::NotepadPart( TQWidget* parentWidget, const char*, + TQObject* parent, const char* name, + const TQStringList& ) + : KParts::ReadWritePart( parent, name ) +{ + setInstance( NotepadFactory::instance() ); + + m_edit = new TQMultiLineEdit( parentWidget, "NotepadPart's multiline edit" ); + setWidget( m_edit ); + + (void)new TDEAction( "Search and replace", 0, this, TQT_SLOT( slotSearchReplace() ), actionCollection(), "searchreplace" ); + setXMLFile( "notepadpart.rc" ); + setReadWrite( true ); +} + +NotepadPart::~NotepadPart() +{ +} + +void NotepadPart::setReadWrite( bool rw ) +{ + m_edit->setReadOnly( !rw ); + if (rw) + connect( m_edit, TQT_SIGNAL( textChanged() ), this, TQT_SLOT( setModified() ) ); + else + disconnect( m_edit, TQT_SIGNAL( textChanged() ), this, TQT_SLOT( setModified() ) ); + + ReadWritePart::setReadWrite( rw ); +} + +TDEAboutData* NotepadPart::createAboutData() +{ + return new TDEAboutData( "notepadpart", I18N_NOOP( "Notepad" ), "2.0" ); +} + +bool NotepadPart::openFile() +{ + kdDebug() << "NotepadPart: opening " << m_file << endl; + // Hehe this is from a tutorial I did some time ago :) + TQFile f(m_file); + TQString s; + if ( f.open(IO_ReadOnly) ) { + TQTextStream t( &f ); + while ( !t.eof() ) { + s += t.readLine() + "\n"; + } + f.close(); + } + m_edit->setText(s); + + emit setStatusBarText( m_url.prettyURL() ); + + return true; +} + +bool NotepadPart::saveFile() +{ + if ( !isReadWrite() ) + return false; + TQFile f(m_file); + TQString s; + if ( f.open(IO_WriteOnly) ) { + TQTextStream t( &f ); + t << m_edit->text(); + f.close(); + return true; + } else + return false; +} + +void NotepadPart::slotSearchReplace() +{ + // What's this ? (David) +/* + TQValueList<KParts::XMLGUIServant *> plugins = KParts::Plugin::pluginServants( this ); + TQValueList<KParts::XMLGUIServant *>::ConstIterator it = plugins.begin(); + TQValueList<KParts::XMLGUIServant *>::ConstIterator end = plugins.end(); + for (; it != end; ++it ) + factory()->removeServant( *it ); +*/ +} + +#include "notepad.moc" |