fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kparts / tests / normalktm.cpp
blob5e49f6650dfe9668e77802eab6a311818a5b40bf
2 #include "normalktm.h"
3 #include "parts.h"
4 #include "notepad.h"
6 #include <QtGui/QSplitter>
7 #include <QtGui/QCheckBox>
8 #include <QtCore/QDir>
9 #include <QtGui/QMenu>
11 #include <kiconloader.h>
12 #include <kstandarddirs.h>
13 #include <kapplication.h>
14 #include <kmessagebox.h>
15 #include <kaction.h>
16 #include <kactioncollection.h>
17 #include <klocale.h>
18 #include <kcmdlineargs.h>
19 #include <kmenubar.h>
20 #include <kicon.h>
22 Shell::Shell()
23 : KXmlGuiWindow()
25 // We can do this "switch active part" because we have a splitter with
26 // two items in it.
27 // I wonder what kdevelop uses/will use to embed kedit, BTW.
28 m_splitter = new QSplitter( this );
30 m_part1 = new Part1(this, m_splitter);
31 m_part2 = new Part2(this, m_splitter);
33 QMenu * pFile = new QMenu( "File", menuBar() );
34 KActionCollection * coll = actionCollection();
35 KAction * paLocal = new KAction( "&View local file", this );
36 coll->addAction( "open_local_file", paLocal );
37 connect(paLocal, SIGNAL(triggered()), this, SLOT(slotFileOpen()));
38 // No XML: we need to add our actions to the menus ourselves
39 pFile->addAction(paLocal);
41 KAction * paRemote = new KAction( "&View remote file", this );
42 coll->addAction( "open_remote_file", paRemote );
43 connect(paRemote, SIGNAL(triggered()), this, SLOT(slotFileOpenRemote()));
44 pFile->addAction(paRemote);
46 m_paEditFile = new KAction( "&Edit file", this );
47 coll->addAction( "edit_file", m_paEditFile );
48 connect(m_paEditFile, SIGNAL(triggered()), this, SLOT(slotFileEdit()));
49 pFile->addAction(m_paEditFile);
51 m_paCloseEditor = new KAction( "&Close file editor", this );
52 coll->addAction( "close_editor", m_paCloseEditor );
53 connect(m_paCloseEditor, SIGNAL(triggered()), this, SLOT(slotFileCloseEditor()));
54 m_paCloseEditor->setEnabled(false);
55 pFile->addAction(m_paCloseEditor);
57 KAction * paQuit = new KAction( "&Quit", this );
58 coll->addAction( "shell_quit", paQuit );
59 connect(paQuit, SIGNAL(triggered()), this, SLOT(close()));
60 paQuit->setIcon(KIcon("application-exit"));
61 pFile->addAction(paQuit);
63 setCentralWidget( m_splitter );
64 m_splitter->setMinimumSize( 400, 300 );
66 m_splitter->show();
68 m_editorpart = 0;
71 Shell::~Shell()
75 void Shell::slotFileOpen()
77 if ( !m_part1->openUrl( KStandardDirs::locate("data", KGlobal::mainComponent().componentName()+"/kpartstest_shell.rc" ) ) )
78 KMessageBox::error(this, "Couldn't open file !");
81 void Shell::slotFileOpenRemote()
83 KUrl u ( "http://www.kde.org/index.html" );
84 if ( !m_part1->openUrl( u ) )
85 KMessageBox::error(this, "Couldn't open file !");
88 void Shell::embedEditor()
90 // replace part2 with the editor part
91 delete m_part2;
92 m_part2 = 0;
93 m_editorpart = new NotepadPart( m_splitter, this );
94 m_editorpart->setReadWrite(); // read-write mode
95 ////// m_manager->addPart( m_editorpart );
96 m_editorpart->widget()->show(); //// we need to do this in a normal KTM....
97 m_paEditFile->setEnabled(false);
98 m_paCloseEditor->setEnabled(true);
101 void Shell::slotFileCloseEditor()
103 delete m_editorpart;
104 m_editorpart = 0;
105 m_part2 = new Part2(this, m_splitter);
106 ////// m_manager->addPart( m_part2 );
107 m_part2->widget()->show(); //// we need to do this in a normal KTM....
108 m_paEditFile->setEnabled(true);
109 m_paCloseEditor->setEnabled(false);
112 void Shell::slotFileEdit()
114 if ( !m_editorpart )
115 embedEditor();
116 // TODO use KFileDialog to allow testing remote files
117 if ( ! m_editorpart->openUrl( QDir::current().absolutePath()+"/kpartstest_shell.rc" ) )
118 KMessageBox::error(this,"Couldn't open file !");
121 int main( int argc, char **argv )
123 // we cheat and call ourselves kpartstest for Shell::slotFileOpen()
124 KCmdLineArgs::init( argc, argv, "kpartstest", 0, ki18n("kpartstest"), 0);
125 KApplication app;
127 Shell *shell = new Shell;
128 shell->show();
130 app.exec();
132 return 0;
135 #include "normalktm.moc"