summaryrefslogtreecommitdiffstats
path: root/tdeparts/tests/notepad.cpp
blob: 547cab520352e64d9882513280614a71cececff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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 <kaboutdata.h>
#include <kapplication.h>
#include <kdebug.h>
#include <tdeaction.h>
#include <klocale.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"