summaryrefslogtreecommitdiffstats
path: root/kxmleditor
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2016-03-26 13:50:43 +0100
committerSlávek Banko <slavek.banko@axis.cz>2016-03-26 13:50:43 +0100
commitd62c8c002c51fb7c36487839eeeb4ac89f044dee (patch)
treebb4d1f5c631ab1f22a3018ba39e6a806035f80fd /kxmleditor
downloadkxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.tar.gz
kxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.zip
Initial import of kxmleditor 1.1.4
Diffstat (limited to 'kxmleditor')
-rw-r--r--kxmleditor/Makefile.am51
-rw-r--r--kxmleditor/dcopiface_shell.cpp39
-rw-r--r--kxmleditor/dcopiface_shell.h70
-rw-r--r--kxmleditor/kxeshellmanager.cpp55
-rw-r--r--kxmleditor/kxeshellmanager.h65
-rw-r--r--kxmleditor/kxmleditor.desktop12
-rw-r--r--kxmleditor/kxmleditorshell.cpp495
-rw-r--r--kxmleditor/kxmleditorshell.h178
-rw-r--r--kxmleditor/kxmleditorshell.rc31
-rw-r--r--kxmleditor/main.cpp139
10 files changed, 1135 insertions, 0 deletions
diff --git a/kxmleditor/Makefile.am b/kxmleditor/Makefile.am
new file mode 100644
index 0000000..58a534c
--- /dev/null
+++ b/kxmleditor/Makefile.am
@@ -0,0 +1,51 @@
+####### kdevelop will overwrite this part!!! (begin)##########
+
+bin_PROGRAMS = kxmleditor
+
+kxmleditor_SOURCES = dcopiface_shell.skel dcopiface_shell.cpp kxmleditorshell.cpp main.cpp kxeshellmanager.cpp
+kxmleditor_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kxmleditor_LDADD = $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
+
+EXTRA_DIST = main.cpp \
+ kxmleditor.desktop \
+ kxmleditorshell.cpp kxmleditorshell.h kxmleditorshell.rc \
+ dcopiface_shell.cpp dcopiface_shell.h
+
+install-data-local:
+ $(mkinstalldirs) $(kde_appsdir)/Applications/
+ $(INSTALL_DATA) $(srcdir)/kxmleditor.desktop $(kde_appsdir)/Applications/kxmleditor.desktop
+
+uninstall-local:
+ -rm -f $(kde_appsdir)/Applications/kxmleditor.desktop
+ -rmdir $(kde_appsdir)/Applications
+
+####### kdevelop will overwrite this part!!! (end)############
+# this 10 paths are KDE specific. Use them:
+# kde_htmldir Where your docs should go to. (contains lang subdirs)
+# kde_appsdir Where your application file (.kdelnk) should go to.
+# kde_icondir Where your icon should go to.
+# kde_minidir Where your mini icon should go to.
+# kde_datadir Where you install application data. (Use a subdir)
+# kde_locale Where translation files should go to.(contains lang subdirs)
+# kde_cgidir Where cgi-bin executables should go to.
+# kde_confdir Where config files should go to.
+# kde_mimedir Where mimetypes should go to.
+# kde_toolbardir Where general toolbar icons should go to.
+# kde_wallpaperdir Where general wallpapers should go to.
+
+# set the include path for X, qt and KDE
+INCLUDES= $(all_includes)
+
+METASOURCES = AUTO
+
+rcdir = $(kde_datadir)/kxmleditor
+rc_DATA = kxmleditorshell.rc
+
+messages: rc.cpp
+ LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \
+ if test -n "$$LIST"; then \
+ if ! test -e $(podir)/kxmleditor.pot; then touch $(podir)/kxmleditor.pot; fi; \
+ $(XGETTEXT) -j $$LIST -o $(podir)/kxmleditor.pot; \
+ fi
+
+noinst_HEADERS = kxeshellmanager.h
diff --git a/kxmleditor/dcopiface_shell.cpp b/kxmleditor/dcopiface_shell.cpp
new file mode 100644
index 0000000..a03d149
--- /dev/null
+++ b/kxmleditor/dcopiface_shell.cpp
@@ -0,0 +1,39 @@
+/***************************************************************************
+ dcopiface_shell.cpp - description
+ -------------------
+ begin : Tue Oct 23 2001
+ copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team
+ email : lvanek@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "dcopiface_shell.h"
+#include "kxmleditorshell.h"
+
+QString
+KXMLEditorShellIface::Quit()
+{
+// m_pKXEShell->close();
+ m_KXEShell.close();
+ return "";
+
+}
+
+
+void
+KXMLEditorShellIface::FileOpen()
+{
+ m_KXEShell.slotFileOpen();
+}
+
+
+
+
diff --git a/kxmleditor/dcopiface_shell.h b/kxmleditor/dcopiface_shell.h
new file mode 100644
index 0000000..63a0f8c
--- /dev/null
+++ b/kxmleditor/dcopiface_shell.h
@@ -0,0 +1,70 @@
+/***************************************************************************
+ dcopiface_shell.h - description
+ -------------------
+ begin : Tue Oct 23 2001
+ copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team
+ email : lvanek@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef DCOPIFACE_SHELL_H
+#define DCOPIFACE_SHELL_H
+
+#include <dcopobject.h>
+#include <kurl.h>
+
+/**
+ *@short DCOP inteface for Kpart based kxmleditor shell.
+ *@author The KXMLEditor Team
+ * See the shell iface as an user, who can perform the _shell_ actions a live user can.
+ * This means opening a file via an fileopen dialog and not by giving a filename/url (this is up to the part's iface - but read on, I'll come back to it later). This means your openURL function should simply "open" and should show the file open dialog.
+ */
+class KXMLEditorShell;
+
+class KXMLEditorShellIface
+ :virtual public DCOPObject
+{
+ K_DCOP
+protected:
+ /**
+ Pointer to @ref KXMLEditorShell which iface manages.
+ **/
+ KXMLEditorShell & m_KXEShell;
+public:
+ /**
+ * Default constructor with default name of DCOP object used by @ref KXMLEditorShell
+ **/
+ KXMLEditorShellIface(KXMLEditorShell & KXEShell, const char * szDCOPObjectName = "KXMLEditorShellIface")
+ :DCOPObject(szDCOPObjectName)
+ ,m_KXEShell(KXEShell)
+ {
+// m_pKXEShell = pKXEShell;
+ }
+k_dcop:
+
+ /**
+ * Closes entire KXMLEditor.
+ *
+ * @returns Error description or empty string if program closed.
+ **/
+ QString Quit();
+
+
+ /**
+ * Calls and shows open file dialog.
+ **/
+
+ ASYNC FileOpen();
+
+
+};
+
+#endif // DCOPIFACE_SHELL_H
+
diff --git a/kxmleditor/kxeshellmanager.cpp b/kxmleditor/kxeshellmanager.cpp
new file mode 100644
index 0000000..b20b1af
--- /dev/null
+++ b/kxmleditor/kxeshellmanager.cpp
@@ -0,0 +1,55 @@
+//
+// C++ Implementation: kxeshellmanager
+//
+// Description:
+//
+//
+// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "kxeshellmanager.h"
+#include "kxmleditorshell.h"
+
+#include <qptrlist.h>
+
+KXEShellManager::KXEShellManager()
+{
+}
+
+KXEShellManager::~KXEShellManager()
+{
+}
+
+void KXEShellManager::addShell(KXMLEditorShell* pShell)
+{
+/*
+ for (unsigned int i=0; i<m_shells.count();i++)
+ {
+ m_shells.at(i)->slotShellAdded(pShell);
+ pShell->slotShellAdded(m_shells.at(i));
+ }
+ */
+ m_shells.append(pShell);
+}
+
+void KXEShellManager::removeShell(KXMLEditorShell* pShell)
+{
+ m_shells.remove(pShell);
+ /*
+ for (unsigned int i=0; i<m_shells.count();i++)
+ {
+ m_shells.at(i)->slotShellRemoved(pShell);
+ }
+ */
+}
+
+
+/*!
+ \fn KXEShellManager::shells()
+ */
+QPtrList<KXMLEditorShell>* KXEShellManager::shells()
+{
+ return &m_shells;
+}
diff --git a/kxmleditor/kxeshellmanager.h b/kxmleditor/kxeshellmanager.h
new file mode 100644
index 0000000..0eeff8e
--- /dev/null
+++ b/kxmleditor/kxeshellmanager.h
@@ -0,0 +1,65 @@
+//
+// C++ Interface: kxeshellmanager
+//
+// Description:
+//
+//
+// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef KXESHELLMANAGER_H
+#define KXESHELLMANAGER_H
+/**
+@file
+*/
+
+#include <qptrlist.h>
+
+class KXMLEditorShell;
+
+/**
+@short Available shell list
+
+Stores and dispatches informations about all KXMLEditorShell windows currently opened.
+Only one instance of this class is created. Eeach shell adds itself into this manager.
+
+@sa KXMLEditorShell
+
+@author Adam Charytoniuk
+*/
+class KXEShellManager{
+public:
+ /** @short Constructor */
+ KXEShellManager();
+
+ /** @short Destructor */
+ ~KXEShellManager();
+
+ /** @short Adds given part to the manager.
+
+ All opened Shells will be informed about that event by KXMLEditorShell::slotShellAdded()
+ method. In addition, newly added shell will be informed about presence of each of all existing
+ shells with the same method.
+ @param pShell newly added shell
+ */
+ void addShell(KXMLEditorShell* pShell);
+
+ /** @short Removes given part from manager.
+
+ All opened Shells will be informed about that event by KXMLEditorShell::slotShellRemoved()
+ method.
+ @param pShell to be removed (closed)
+ */
+ void removeShell(KXMLEditorShell* pShell);
+
+ /** @short Returns list of currently opened shells. */
+ QPtrList<KXMLEditorShell> *shells();
+
+private:
+ /** @short Internally stores list of available shells. */
+ QPtrList<KXMLEditorShell> m_shells;
+};
+
+#endif
diff --git a/kxmleditor/kxmleditor.desktop b/kxmleditor/kxmleditor.desktop
new file mode 100644
index 0000000..556f62a
--- /dev/null
+++ b/kxmleditor/kxmleditor.desktop
@@ -0,0 +1,12 @@
+[Desktop Entry]
+Type=Application
+Exec=kxmleditor -caption "%c" %i %m
+Icon=kxmleditor.png
+DocPath=kxmleditor/index.html
+Comment=XML editor
+Comment[fi]=XML-editori
+Terminal=false
+Name=KXML Editor
+MimeType=text/xml;
+Encoding=UTF-8
+Categories=Application;Development;TextEditor;KDE;
diff --git a/kxmleditor/kxmleditorshell.cpp b/kxmleditor/kxmleditorshell.cpp
new file mode 100644
index 0000000..bbb6f02
--- /dev/null
+++ b/kxmleditor/kxmleditorshell.cpp
@@ -0,0 +1,495 @@
+/***************************************************************************
+ kxmleditorshell.cpp - description
+ -------------------
+ begin : Thu Oct 18 2001
+ copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team
+ email : lvanek@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+ /**
+ @file
+ */
+
+#include "kxmleditorshell.h"
+#include "kxeshellmanager.h"
+#include "../part/kxmleditorpart.h"
+#include "../part/kxedocument.h"
+
+#include <klibloader.h>
+#include <kstdaction.h>
+#include <kapplication.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kfiledialog.h>
+#include <kkeydialog.h>
+#include <kedittoolbar.h>
+#include <kstatusbar.h>
+#include <kparts/browserextension.h>
+#include <kparts/partmanager.h>
+#include <kmessagebox.h>
+
+#include <kpopupmenu.h>
+
+#include <qevent.h>
+
+#include "dcopiface_shell.h"
+
+
+KXEShellManager *KXMLEditorShell::s_manager=0L;
+
+KXMLEditorShell::KXMLEditorShell( const char * name, WFlags f )
+ : KParts::MainWindow( name, f ),
+ m_pPart(0),
+ m_pKXEShellIface(0)
+{
+ //////////////////////////////
+ // CREATE ACTIONS
+ //////////////////////////////
+
+ setXMLFile("kxmleditorshell.rc");
+
+ KStdAction::openNew( this,SLOT(slotActFileNew()),actionCollection() );
+ KStdAction::open( this, SLOT(slotFileOpen()), actionCollection() );
+ m_pActFileOpenRecent = KStdAction::openRecent( this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection() );
+ m_pActFileOpenRecent->loadEntries( instance()->config() );
+ m_pActReload = new KAction( i18n("Reloa&d"), "reload", Key_F5, this, SLOT(slotFileReload()), actionCollection(), "reload" );
+
+ KToggleAction * pActToggleMainToolBar = KStdAction::showToolbar( this, SLOT(slotToggleMainToolBar()), actionCollection() );
+ KToggleAction * pActToggleStatusBar = KStdAction::showStatusbar( this, SLOT(slotToggleStatusBar()), actionCollection() );
+ KStdAction::keyBindings( this, SLOT(slotConfigureKeys()), actionCollection() );
+ KStdAction::configureToolbars( this, SLOT(slotConfigureToolbars()), actionCollection() );
+
+ KStdAction::mail( this, SLOT(mail()), actionCollection() );
+ KStdAction::close( this, SLOT(slotActClose()), actionCollection() );
+ KStdAction::quit( this, SLOT(close()), actionCollection());
+
+ // L.V. moved to part pActPrint = KStdAction::print( 0, 0, actionCollection(), "print" );
+
+ pActCloseW = new KAction( i18n("&Close"), 0, 0, this,SLOT(slotActWindowClose()), actionCollection(), "window_close" );
+ pActCloseAllW = new KAction( i18n("Close &all"), 0, 0, this,SLOT(slotActWindowCloseAll()), actionCollection(), "window_close_all" );
+ pActCloseAllO = new KAction( i18n("Close all &others"), 0, 0, this,SLOT(slotActWindowCloseAllOthers()), actionCollection(), "window_close_all_others" );
+
+ //////////////////////////////
+ // CREATE STATUSBAR
+ //////////////////////////////
+ statusBar()->message( i18n("Ready.") );
+
+ //////////////////////////////
+ // MISC. INITIALIZATION
+ //////////////////////////////
+
+ manager()->addShell(this);
+
+ setAutoSaveSettings();
+ pActToggleMainToolBar->setChecked( ! toolBar()->isHidden() );
+ pActToggleStatusBar->setChecked( ! statusBar()->isHidden() );
+
+ m_pKXEShellIface = new KXMLEditorShellIface(*this);
+
+ statusBar()->setSizeGripEnabled(true);
+
+ setPart(0L); // start empty
+
+}
+
+KXMLEditorShell::~KXMLEditorShell()
+{
+ if (m_pKXEShellIface)
+ delete m_pKXEShellIface;
+
+ manager()->removeShell(this);
+}
+
+/////////////////////////////////////////////////////////////////////
+// ACTION SLOTS
+/////////////////////////////////////////////////////////////////////
+
+void KXMLEditorShell::slotFileOpen()
+{
+ statusBar()->message( i18n("Opening file...") );
+
+ KURL url = KFileDialog::getOpenURL( QString::null,
+ i18n(FILE_DIALOG_FILTER),
+ this );
+ openURL(url);
+
+ // L.V.: tried to meve save functionality to Part
+ //m_pActFileSave->setEnabled(true); // TODO: L.V. Why File Save ? Why not Save as... ?
+
+ statusBar()->message( i18n("Ready.") );
+}
+
+void KXMLEditorShell::slotFileOpenRecent(const KURL & url)
+{
+ statusBar()->message( i18n("Opening file...") );
+
+ openURL(url);
+
+ statusBar()->message( i18n("Ready.") );
+}
+
+void KXMLEditorShell::slotFileReload()
+{
+ statusBar()->message( i18n("Reloading file...") );
+
+ // Try to (re)open the file.
+ // In case the file is modified, a Save/Discard/Cancel message box pops up.
+ if ( part() && ! part()->url().isEmpty() )
+ part()->openURL( part()->url() );
+
+ statusBar()->message( i18n("Ready.") );
+}
+
+void KXMLEditorShell::slotToggleMainToolBar()
+{
+ statusBar()->message( i18n("Toggle the toolbar...") );
+
+ if( toolBar()->isHidden() )
+ toolBar()->show();
+ else
+ toolBar()->hide();
+
+ statusBar()->message( i18n("Ready.") );
+}
+
+
+void KXMLEditorShell::slotToggleStatusBar()
+{
+ statusBar()->message( i18n("Toggle the statusbar...") );
+
+ if( statusBar()->isHidden() )
+ statusBar()->show();
+ else
+ statusBar()->hide();
+
+ statusBar()->message( i18n("Ready.") );
+}
+
+void KXMLEditorShell::slotConfigureKeys()
+{
+ KKeyDialog dlg;
+ dlg.insert(part()->actionCollection());
+ dlg.insert(actionCollection());
+ dlg.configure();
+}
+
+void KXMLEditorShell::slotConfigureToolbars()
+{
+ KEditToolbar dlg( factory() );
+ if ( dlg.exec() )
+ createGUI( part() );
+}
+
+/////////////////////////////////////////////////////////////////////
+// ADDITIONAL FUNCTIONS
+/////////////////////////////////////////////////////////////////////
+
+bool KXMLEditorShell::openURL( const KURL & url )
+{
+ if ( url.isEmpty() )
+ return false;
+
+ // About this function, the style guide (
+ // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
+ // says that it should open a new window if the document is _not_
+ // in its initial state. This is what we do here.
+
+ // If there is no part yet created, create new one...
+ if (!part())
+ {
+ setPart(createXMLPart(this));
+ }
+
+ // We have to differenciate, if this shell could
+ // be used or a new one has to be created.
+ if ( part()->url().isEmpty() && ! part()->isModified() )
+ {
+ // this one can be used - try to open the file in it
+ if ( ! part()->openURL(url) )
+ return false;
+ }
+ else
+ {
+ // a new one has to be created
+ KXMLEditorShell * pShell = new KXMLEditorShell;
+ // and a new part too...
+ pShell->setPart(createXMLPart(pShell));
+
+ // try to open the file in the shell
+ if ( ! pShell->part()->openURL(url) )
+ return false;
+
+ // show the new shell
+ pShell->show();
+ }
+
+ // on success, the URL could be added to our list of recent files
+ m_pActFileOpenRecent->addURL(url);
+
+ return true;
+}
+
+bool KXMLEditorShell::queryClose()
+{
+ if ( part() && ! part()->closeURL() )
+ return false;
+
+ m_pActFileOpenRecent->saveEntries( instance()->config() );
+
+ return KParts::MainWindow::queryClose();
+}
+
+void KXMLEditorShell::saveProperties( KConfig * pConfig )
+{
+ if (part())
+ {
+ pConfig->writeEntry( "CurrentURL", part()->url().url() );
+ }
+ KParts::MainWindow::saveProperties(pConfig);
+}
+
+void KXMLEditorShell::readProperties( KConfig * pConfig )
+{
+ KParts::MainWindow::readProperties(pConfig);
+
+/// @todo Check if ths is a deadcode
+// QString strURL = pConfig->readEntry( "CurrentURL", "" );
+// if ( strURL.isEmpty())
+// part()->openURL( strURL );
+}
+
+void KXMLEditorShell::slotEnableBrowserExtActions( const char * pszName, bool bEnabled )
+{
+ KAction * pAct = actionCollection()->action( pszName );
+ if ( pAct )
+ pAct->setEnabled( bEnabled );
+ else
+ kdDebug() << "KXMLEditor " << k_funcinfo << " unknown action (" << pszName << ")" << endl;
+}
+
+// Set main window caption (by using the base class functionality),
+// Enables/disables Save button (corresponding to the parts modified status)
+void KXMLEditorShell::setCaption( const QString & strCaption )
+{
+ if (part())
+ {
+ KParts::MainWindow::setCaption( strCaption, part()->isModified() ); // base class functionality
+ }
+}
+
+
+//
+// Called when creating new file is requested.
+//
+void KXMLEditorShell::slotActFileNew()
+{
+
+ // About this function, the style guide (
+ // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
+ // says that it should open a new window if the document is _not_
+ // in its initial state. This is what we do here..
+ KXMLEditorShell * pShell;
+ KParts::ReadWritePart* pPart;
+
+ // 1. This shell is empty
+ if (!part())
+ {
+ pPart = createXMLPart(this);
+ pShell=this;
+ }
+ // 2. The shell contains modified part
+ else if (! part()->url().isEmpty() || part()->isModified() )
+ {
+ pShell = new KXMLEditorShell;
+ pPart = createXMLPart(pShell);
+ pShell->show();
+ }
+ // 3. The shell contains part, and it is empty and not modified
+ else
+ {
+ pPart=part();
+ pShell=this;
+ }
+
+ pShell->setPart(pPart);
+ // if there is a way to determine in KXMLEditorPart that it was created "for new file" then
+ // this part should be changed.
+ ((KXMLEditorPart *)pPart)->document()->newFile();
+}
+
+void KXMLEditorShell::mail()
+{
+ // L.V.: tried to meve save functionality to Part
+ //slotFileSave();
+
+ // first - our XML file have to be saved.
+ part()->save();
+
+ if (!part()->url().isEmpty())
+ {
+ QStringList urls(part()->url().url()); // we can prepare then list of attachments (1 element in the list)
+ QString theSubject(part()->url().fileName(false)); // and set the mail subject
+ kapp->invokeMailer(QString::null, // finally we can compose e-mail (addressed to no-one) out of that
+ QString::null,
+ QString::null,
+ theSubject, // subject
+ QString::null, // body
+ QString::null,
+ urls); // attachments
+ }
+}
+
+void KXMLEditorShell::setPart(KParts::ReadWritePart* pPart)
+{
+ if (pPart==m_pPart)
+ return; // nothing to do here...
+ else
+ {
+ if(pPart)
+ {
+ connect(static_cast <KXMLEditorPart *> (pPart), SIGNAL(sigAddRecentURL(const KURL &)),
+ this, SLOT(slotAddRecentURL(const KURL &)) );
+ }
+ }
+
+ if (m_pPart)
+ {
+ factory()->removeClient(m_pPart);
+ delete m_pPart;
+ }
+ m_pPart = pPart;
+ if (pPart)
+ {
+ // get the parts browser extension and connect additional actions to it
+ KParts::BrowserExtension * pBrowserExt = 0;
+ if ( (pBrowserExt = KParts::BrowserExtension::childObject(pPart)) ) // if there is one
+ {
+ connect( pBrowserExt, SIGNAL(enableAction( const char *, bool )), this, SLOT(slotEnableBrowserExtActions( const char *, bool )) );
+
+ // L.V. moved to part. connect(pActPrint,SIGNAL(activated()),pBrowserExt, SLOT(print()));
+ //pActPrint->setEnabled(pBrowserExt->isActionEnabled("print"));
+ }
+
+ createGUI(pPart);
+ setCentralWidget(pPart->widget() );
+ pPart->widget()->show();
+ stateChanged("part");
+ }
+ else
+ {
+ createGUI(0L);
+ setCentralWidget(0L);
+ stateChanged("empty");
+ }
+
+ // keep pointer to window menu
+ m_windowMenu = static_cast<KPopupMenu*>(factory()->container("window", this));
+ if(!m_windowMenu)
+ kdDebug() << "KXMLEditorShell::setPart - m_windowMenu is NULL" << endl;
+ else
+ connect(m_windowMenu,SIGNAL(aboutToShow()),this,SLOT(slotBeforeWindowMenuShown()));
+}
+
+KParts::ReadWritePart* KXMLEditorShell::createXMLPart(QObject *parent)
+{
+ return createPart(parent,"libkxmleditorpart", "KParts::ReadWritePart");
+}
+
+KParts::ReadWritePart* KXMLEditorShell::createPart(QObject *parent, const QString& libName, const QString& className)
+{
+ KParts::ReadWritePart* newPart = 0L;
+ KLibFactory * pFactory = KLibLoader::self()->factory(libName);
+ if (pFactory)
+ newPart = static_cast <KParts::ReadWritePart*> ( pFactory->create( parent, "KXMLEditor view", className ) );
+ else
+ kdFatal() << "KXMLEditorShell::KXMLEditorShell no " << libName << " found" << endl;
+ return newPart;
+}
+
+void KXMLEditorShell::slotActClose()
+{
+ if (part() && part()->queryClose())
+ setPart(0L);
+}
+
+void KXMLEditorShell::close()
+{
+ if (queryClose())
+ {
+ if (KMainWindow::memberList->count()==1)
+ kapp->deref();
+ delete this;
+ }
+}
+
+void KXMLEditorShell::slotActWindowCloseAllOthers()
+{
+ QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
+ for (it.toFirst();it.current();++it)
+ {
+ if (it.current()!=this)
+ it.current()->close();
+ }
+}
+
+ void KXMLEditorShell::slotActWindowClose()
+{
+ this->close();
+}
+
+void KXMLEditorShell::slotActWindowCloseAll()
+{
+ slotActWindowCloseAllOthers();
+ slotActWindowClose();
+}
+
+KXEShellManager* KXMLEditorShell::manager()
+{
+ if (!s_manager)
+ {
+ s_manager = new KXEShellManager();
+ }
+ return s_manager;
+}
+
+void KXMLEditorShell::slotBeforeWindowMenuShown()
+{
+ // first we have to clean all shell items...
+ m_windowMenu->clear();
+
+ // then we plug-in neccessary actions...
+ pActCloseW->plug(m_windowMenu);
+ pActCloseAllW->plug(m_windowMenu);
+ pActCloseAllO->plug(m_windowMenu);
+ m_windowMenu->insertSeparator();
+
+ // and then we can add entries for all shells
+ // that are registered in Shell Manager...
+ QPtrListIterator<KXMLEditorShell> it (*(manager()->shells()));
+ for (it.toFirst(); it.current();++it)
+ {
+ int id = m_windowMenu->insertItem(it.current()->caption(),it.current(),SLOT(slotActivate()));
+ m_windowMenu->setItemChecked(id,it.current()==this);
+ }
+}
+
+void KXMLEditorShell::slotActivate()
+{
+ /// @todo windows have to be activated over EWMH
+ showNormal(); // show it if it's minimized
+ raise(); // bring that to front
+}
+
+// Add URL to recent file list
+void KXMLEditorShell::slotAddRecentURL(const KURL &url)
+{
+ m_pActFileOpenRecent->addURL(url);
+}
diff --git a/kxmleditor/kxmleditorshell.h b/kxmleditor/kxmleditorshell.h
new file mode 100644
index 0000000..848e47a
--- /dev/null
+++ b/kxmleditor/kxmleditorshell.h
@@ -0,0 +1,178 @@
+/***************************************************************************
+ kxmleditorshell.h - description
+ -------------------
+ begin : Thu Oct 18 2001
+ copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team
+ email : lvanek@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+ /**
+ @file
+ */
+
+
+#ifndef KXMLEDITORSHELL_H
+#define KXMLEDITORSHELL_H
+
+#include <kparts/mainwindow.h>
+
+class KParts::ReadWritePart;
+class KXMLEditorShellIface;
+class KAction;
+class KXEShellManager;
+
+
+/**
+ @short The shell, which can contain our #KXMLEditorPart.
+
+ It is the window that owns main user interface elements.
+*/
+class KXMLEditorShell : public KParts::MainWindow
+{
+ Q_OBJECT
+ public:
+ /** @short Constructor
+
+ Creates shell and adds it into one global instance of KXEShellManager.
+ @sa KXEShellManager
+ */
+ KXMLEditorShell( const char * name = 0L, WFlags f = WDestructiveClose );
+
+ /** @short Destructor
+
+ Destroys shell. Performs also removing given shell from global instance
+ of KXEShellManager.
+ */
+ virtual ~KXMLEditorShell();
+
+ /** @short Opens new file and shows it in the current shell. */
+ bool openURL( const KURL & url ) ;
+
+ /** @short Closes this shell. */
+ virtual void close();
+
+ /** @short Returns part manager object */
+ KXEShellManager* manager();
+
+ /** @short Creates new part which can be shown in the shell.
+ @param parent parent object for the part*/
+ static KParts::ReadWritePart* createXMLPart(QObject *parent) ;
+
+ static KParts::ReadWritePart* createPart(QObject *parent, const QString& libName, const QString& className);
+
+ /** @short Changes currenly shown part. */
+ void setPart(KParts::ReadWritePart* pPart);
+
+ public slots:
+ /** @short Slot connected to File->New action. */
+ void slotActFileNew();
+
+ /** @short Slot connected to File->Open action. */
+ void slotFileOpen();
+
+ void slotFileOpenRecent( const KURL & url );
+
+ /** @short Slot connected to File->Reload action. */
+ void slotFileReload();
+
+ /** @short Slot connected to action responsible for showing and hiding main toolbar.*/
+ void slotToggleMainToolBar();
+
+ /** @short Slot connected to action responsible for showing and hiding status bar.*/
+ void slotToggleStatusBar();
+
+ /** @short Slot connected to action. Shows shortcut configuration dialog.*/
+ void slotConfigureKeys();
+
+ /** @short Slot connected to action. Shows toolbar configuration dialog.*/
+ void slotConfigureToolbars();
+
+ /** @short Changes shell caption.*/
+ virtual void setCaption( const QString & strCaption );
+
+ /** @short Sends currently opened XML file over e-mail.
+
+ The application will try to start default mail client and prepare
+ new empty mail with currently opened file as an attachment.
+ The file have to be saved first on a disc.
+ @sa KApplication::invokeMailer()
+ */
+ void mail();
+
+ /** @short Connected to File->Close action
+
+ Closes currently opened file, but not the shell itself. The shell
+ remaines empty but active, so it's possible for the user
+ to open another file in it.*/
+ void slotActClose();
+
+ /** @short slot connected to Window->Close action.
+ @sa close() */
+ void slotActWindowClose();
+
+ /** @short slot connected to Window->Close All action. */
+ void slotActWindowCloseAll();
+
+ /** @short slot connected to Window->Close All Others action. */
+ void slotActWindowCloseAllOthers();
+
+ void slotActivate();
+
+ protected:
+ virtual bool queryClose();
+ virtual void saveProperties( KConfig * );
+ virtual void readProperties( KConfig * );
+
+ /** @short Stores pointer to currenly shown part. */
+ KParts::ReadWritePart * m_pPart;
+
+ /** @short Action for recently opened files. */
+ KRecentFilesAction * m_pActFileOpenRecent;
+
+ /** @short Action for reloading the document currently open. */
+ KAction * m_pActReload;
+
+ /** @short Action for printing complete XML files.*/
+ // L.V. moved to part. KAction* pActPrint;
+
+ KAction* pActCloseW;
+ KAction* pActCloseAllW;
+ KAction* pActCloseAllO;
+
+ /** @short DCOP interface pointer (if no such iface pointer == 0).*/
+ KXMLEditorShellIface * m_pKXEShellIface;
+
+ /** @short Stores pointer to window menu.
+
+ This menu is expanded everytime new shell is shown. */
+ KPopupMenu* m_windowMenu;
+
+ /** @short Returns currently shown part. */
+ KParts::ReadWritePart* part() const {return m_pPart;}
+
+ /** @short Adds this shell window to part manager for monitoring */
+// void addToManager();
+
+ protected slots:
+ /** To enable/disable actions, the way the parts browser extension wishes. */
+ void slotEnableBrowserExtActions( const char * pszName, bool bEnabled );
+
+ void slotBeforeWindowMenuShown();
+
+ // Add URL to recent file list
+ void slotAddRecentURL(const KURL &);
+
+ private:
+ /** @short Stores pointer to global instance of #KParts::PartManager */
+ static KXEShellManager *s_manager;
+};
+
+#endif
diff --git a/kxmleditor/kxmleditorshell.rc b/kxmleditor/kxmleditorshell.rc
new file mode 100644
index 0000000..2ddfba2
--- /dev/null
+++ b/kxmleditor/kxmleditorshell.rc
@@ -0,0 +1,31 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="kxmleditorshell" version="2">
+
+<MenuBar>
+ <Menu name="file"><text>&amp;File</text>
+ <Action name="reload"/>
+ <Separator lineSeparator="true"/>
+
+ <Merge/>
+
+ </Menu>
+ <Merge/>
+ <Menu name="window"><text>&amp;Window</text>
+ <Action name="window_close"/>
+ <Action name="window_close_all"/>
+ <Action name="window_close_all_others"/>
+ </Menu>
+ <Menu name="help"><text>&amp;Help</text>
+ </Menu>
+</MenuBar>
+
+<ToolBar fullWidth="true" name="mainToolBar" newline="true" position="top"><text>Main Toolbar</text>
+ <DefineGroup name="file_operations" />
+ <Action name="new" group="file_operations" />
+ <Action name="open" group="file_operations" />
+ <Merge/>
+ <Separator/>
+ <Merge/>
+</ToolBar>
+
+</kpartgui>
diff --git a/kxmleditor/main.cpp b/kxmleditor/main.cpp
new file mode 100644
index 0000000..23b1f8a
--- /dev/null
+++ b/kxmleditor/main.cpp
@@ -0,0 +1,139 @@
+/***************************************************************************
+ main.cpp - description
+ -------------------
+ begin : � �c 10 12:39:26 CEST 2001
+ copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team
+ email : lvanek@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+#include <dcopclient.h>
+
+//#include "kxmleditor.h"
+#include "../part/kxmleditorabout.h"
+#include "kxmleditorshell.h"
+
+
+static KCmdLineOptions options[] =
+{
+ { "+[File(s)]", I18N_NOOP("XML file(s) to open"), 0 },
+ { 0, 0, 0 }
+};
+
+#define USE_KPART 1
+ // if set to true makes kxmleditor to be kpart based (currently developement version only)
+
+/** @short Main application function that starts-up the application */
+int main(int argc, char *argv[])
+{
+ KCmdLineArgs::init( argc, argv, new KXMLEditorAboutData() );
+ KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
+
+ KApplication app;
+
+ // comment the following lines to use KXMLEditorShell instead of KXMLEditorApp
+#if ! USE_KPART
+ if (app.isRestored())
+ { RESTORE(KXMLEditorApp);
+ }
+ else
+ {
+ KXMLEditorApp *kxmleditor = new KXMLEditorApp();
+ kxmleditor->show();
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if(args->count())
+ { QString strPath;
+
+ if(args->count() > 1)
+ { strPath = args->arg(1);
+ }
+ KURL url(args->arg(0));
+ if ( ! url.isValid() )
+ { // probably user entered just filename
+ url.setProtocol("file");
+ url.setPath(args->arg(0));
+ }
+ kxmleditor->openDocumentFile(url, strPath);
+ }
+ else
+ { kxmleditor->openDocumentFile();
+ }
+ args->clear();
+ }
+#else // USE_KPART
+
+ if (app.isRestored())
+ {
+ RESTORE(KXMLEditorShell);
+ }
+ else
+ {
+ KCmdLineArgs * pArgs = KCmdLineArgs::parsedArgs();
+ KXMLEditorShell * pShell;
+ bool bNoCorrectInstance = true;
+ if ( pArgs->count() > 0 )
+ {
+ for( int i = 0; i < pArgs->count(); i++ )
+ {
+ KURL url(pArgs->arg(i));
+ if ( ! url.isValid() )
+ {
+ url.setProtocol("file");
+ url.setPath(pArgs->arg(i));
+ }
+ pShell = new KXMLEditorShell();
+ if ( pShell->openURL(url) )
+ {
+ pShell->show();
+ bNoCorrectInstance = false;
+ }
+ else
+ {
+ kdDebug() << "Couldn't open file " << url.path() << endl;
+ KMessageBox::sorry(0, i18n("Couldn't open file !") + "\n" + url.path());
+ delete pShell;
+ }
+ }
+ }
+ else
+ {
+ pShell = new KXMLEditorShell();
+ KParts::ReadWritePart* pPart = KXMLEditorShell::createXMLPart(pShell);
+ pShell->setPart(pPart);
+ pShell->show();
+ bNoCorrectInstance = false;
+ }
+ pArgs->clear();
+
+ if ( bNoCorrectInstance )
+ return FALSE;
+ }
+
+ // registration as multi-instance DCOP client
+ DCOPClient *client = app.dcopClient();
+ client->attach();
+ client->registerAs(kapp->name());
+
+ // uncomment end
+#endif // USE_KPART
+
+ int iRetVal = app.exec();
+ return iRetVal;
+}
+